Skip to content

Commit b8e5c1c

Browse files
committed
added abs_crt routines that use the LIBCALL calling convention
1 parent b740355 commit b8e5c1c

File tree

14 files changed

+822
-0
lines changed

14 files changed

+822
-0
lines changed

src/crt/babs_crt.src

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
assume adl=1
2+
3+
section .text
4+
5+
public __babs_crt
6+
7+
; A = abs(A)
8+
__babs_crt:
9+
or a, a
10+
ret p
11+
neg
12+
ret

src/crt/i48abs_crt.src

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
assume adl=1
2+
3+
section .text
4+
5+
public __i48abs_crt
6+
7+
; UDE:UHL = abs(UDE:UHL)
8+
__i48abs_crt:
9+
ex de, hl
10+
push hl
11+
add hl, hl
12+
pop hl
13+
ex de, hl
14+
jq c, __i48neg
15+
ret
16+
17+
extern __i48neg

src/crt/iabs_crt.src

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
assume adl=1
2+
3+
section .text
4+
5+
public __iabs_crt
6+
7+
; UHL = abs(UHL)
8+
__iabs_crt:
9+
push hl
10+
add hl, hl
11+
pop hl
12+
jq c, __ineg
13+
ret
14+
15+
extern __ineg

src/crt/iabs_crt_fast.src

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
assume adl=1
2+
3+
section .text
4+
5+
public __iabs_crt_fast
6+
7+
if 1
8+
9+
; UHL = abs(UHL)
10+
; 9 bytes
11+
; positive: 10F + 3R + 2
12+
; negative: 8F + 3R + 2
13+
__iabs_crt_fast:
14+
or a, a
15+
ex de, hl
16+
sbc hl, hl
17+
sbc hl, de
18+
ret p
19+
ex de, hl
20+
ret
21+
22+
else
23+
24+
; UHL = abs(UHL)
25+
; 11 bytes
26+
; positive: 6F + 3R + 2
27+
; negative: 12F + 3R + 2
28+
__iabs_crt_fast:
29+
add hl, de
30+
or a, a
31+
sbc hl, de
32+
ret p
33+
; __ineg_fast
34+
add hl, de ; uhl=UHL+UDE
35+
ex de, hl ; ude=UHL+UDE, uhl=UDE
36+
or a, a
37+
sbc hl, de ; uhl=UDE-(UHL+UDE)
38+
; =UDE-UHL-UDE
39+
; =-UHL
40+
ret
41+
42+
end if

src/crt/labs_crt.src

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
assume adl=1
2+
3+
section .text
4+
5+
public __labs_crt
6+
7+
; E:UHL = abs(E:UHL)
8+
__labs_crt:
9+
bit 7, e
10+
jq nz, __lneg
11+
ret
12+
13+
extern __lneg

src/crt/labs_crt_fast.src

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
assume adl=1
2+
3+
section .text
4+
5+
public __labs_crt_fast
6+
7+
; E:UHL = abs(E:UHL)
8+
__labs_crt_fast:
9+
bit 7, e
10+
jq nz, __lneg_fast
11+
ret
12+
13+
extern __lneg_fast

src/crt/llabs_crt.src

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
assume adl=1
2+
3+
section .text
4+
5+
public __llabs_crt
6+
7+
; BC:UDE:UHL = abs(BC:UDE:UHL)
8+
__llabs_crt:
9+
bit 7, b
10+
jq nz, __llneg
11+
ret
12+
13+
extern __llneg

src/crt/llabs_crt_fast.src

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
assume adl=1
2+
3+
section .text
4+
5+
public __llabs_crt_fast
6+
7+
; BC:UDE:UHL = abs(BC:UDE:UHL)
8+
__llabs_crt_fast:
9+
bit 7, b
10+
jq nz, __llneg_fast
11+
ret
12+
13+
extern __llneg_fast

src/crt/sabs_crt.src

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
assume adl=1
2+
3+
section .text
4+
5+
public __sabs_crt
6+
7+
; HL = abs(HL)
8+
__sabs_crt:
9+
bit 7, h
10+
jq nz, __sneg
11+
ret
12+
13+
extern __sneg

src/crt/sabs_crt_fast.src

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
assume adl=1
2+
3+
section .text
4+
5+
public __sabs_crt_fast
6+
7+
; HL = abs(HL)
8+
; 9 bytes
9+
; positive: 4F + 3R + 2
10+
; negative: 10F + 3R + 2
11+
__sabs_crt_fast:
12+
bit 7, h
13+
ret z
14+
; __sneg_fast
15+
add hl, de ; uhl=UHL+UDE
16+
ex de, hl ; ude=UHL+UDE, uhl=UDE
17+
or a, a
18+
sbc hl, de ; uhl=UDE-(UHL+UDE)
19+
ret

0 commit comments

Comments
 (0)