Skip to content

Commit 092c7fb

Browse files
calc84maniacmateoconlechuga
authored andcommitted
Optimize 24-bit and 32-bit implementations of and/or/xor
1 parent 454b406 commit 092c7fb

File tree

12 files changed

+81
-117
lines changed

12 files changed

+81
-117
lines changed

src/crt/iand.src

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,23 @@ __iand := 000134h
1010
else
1111

1212
__iand:
13+
; CC: 24*r(PC)+11*r(SPL)+10*w(SPL)+1
1314
push af
14-
push bc
15-
inc sp
16-
inc sp
15+
public __iand.hijack_land
16+
.hijack_land:
1717
push hl
18-
ld hl, 2
18+
scf
19+
sbc hl, hl
1920
add hl, sp
21+
push bc
2022
ld a, (hl)
2123
inc hl
24+
ld sp, hl
25+
inc hl
26+
inc hl
2227
and a, (hl)
23-
dec hl
2428
ld (hl), a
2529
pop hl
26-
inc sp
2730
ld a, h
2831
and a, b
2932
ld h, a

src/crt/iand_fast.src

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@
33
section .text
44
public __iand_fast
55
__iand_fast:
6-
push bc
7-
inc sp
8-
inc sp
6+
; CC: 22*r(PC)+8*r(SPL)+7*w(SPL)+1
97
push hl
10-
ld hl, 2
8+
scf
9+
sbc hl, hl
1110
add hl, sp
11+
push bc
1212
ld a, (hl)
1313
inc hl
14+
ld sp, hl
15+
inc hl
16+
inc hl
1417
and a, (hl)
15-
dec hl
1618
ld (hl), a
1719
pop hl
18-
inc sp
1920
ld a, h
2021
and a, b
2122
ld h, a

src/crt/ior.src

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,23 @@ __ior := 000168h
1010
else
1111

1212
__ior:
13+
; CC: 24*r(PC)+11*r(SPL)+10*w(SPL)+1
1314
push af
14-
push bc
15-
inc sp
16-
inc sp
15+
public __ior.hijack_lor
16+
.hijack_lor:
1717
push hl
18-
ld hl, 2
18+
scf
19+
sbc hl, hl
1920
add hl, sp
21+
push bc
2022
ld a, (hl)
2123
inc hl
24+
ld sp, hl
25+
inc hl
26+
inc hl
2227
or a, (hl)
23-
dec hl
2428
ld (hl), a
2529
pop hl
26-
inc sp
2730
ld a, h
2831
or a, b
2932
ld h, a

src/crt/ior_fast.src

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@
33
section .text
44
public __ior_fast
55
__ior_fast:
6-
push bc
7-
inc sp
8-
inc sp
6+
; CC: 22*r(PC)+8*r(SPL)+7*w(SPL)+1
97
push hl
10-
ld hl, 2
8+
scf
9+
sbc hl, hl
1110
add hl, sp
11+
push bc
1212
ld a, (hl)
1313
inc hl
14+
ld sp, hl
15+
inc hl
16+
inc hl
1417
or a, (hl)
15-
dec hl
1618
ld (hl), a
1719
pop hl
18-
inc sp
1920
ld a, h
2021
or a, b
2122
ld h, a

src/crt/ixor.src

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,23 @@ __ixor := 000198h
1010
else
1111

1212
__ixor:
13+
; CC: 24*r(PC)+11*r(SPL)+10*w(SPL)+1
1314
push af
14-
push bc
15-
inc sp
16-
inc sp
15+
public __ixor.hijack_lxor
16+
.hijack_lxor:
1717
push hl
18-
ld hl, 2
18+
scf
19+
sbc hl, hl
1920
add hl, sp
21+
push bc
2022
ld a, (hl)
2123
inc hl
24+
ld sp, hl
25+
inc hl
26+
inc hl
2227
xor a, (hl)
23-
dec hl
2428
ld (hl), a
2529
pop hl
26-
inc sp
2730
ld a, h
2831
xor a, b
2932
ld h, a

src/crt/ixor_fast.src

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@
33
section .text
44
public __ixor_fast
55
__ixor_fast:
6-
push bc
7-
inc sp
8-
inc sp
6+
; CC: 22*r(PC)+8*r(SPL)+7*w(SPL)+1
97
push hl
10-
ld hl, 2
8+
scf
9+
sbc hl, hl
1110
add hl, sp
11+
push bc
1212
ld a, (hl)
1313
inc hl
14+
ld sp, hl
15+
inc hl
16+
inc hl
1417
xor a, (hl)
15-
dec hl
1618
ld (hl), a
1719
pop hl
18-
inc sp
1920
ld a, h
2021
xor a, b
2122
ld h, a

src/crt/land.src

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,12 @@ __land := 0001A4h
1010
else
1111

1212
__land:
13+
; CC: 30*r(PC)+11*r(SPL)+10*w(SPL)+2
1314
push af
1415
and a, e
1516
ld e, a
16-
push bc
17-
inc sp
18-
inc sp
19-
push hl
20-
ld hl, 2
21-
add hl, sp
22-
ld a, (hl)
23-
inc hl
24-
and a, (hl)
25-
dec hl
26-
ld (hl), a
27-
pop hl
28-
inc sp
29-
ld a, h
30-
and a, b
31-
ld h, a
32-
ld a, l
33-
and a, c
34-
ld l, a
35-
pop af
36-
ret
17+
jp __iand.hijack_land
18+
19+
extern __iand.hijack_land
3720

3821
end if

src/crt/land_fast.src

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,22 @@
33
section .text
44
public __land_fast
55
__land_fast:
6+
; CC: 24*r(PC)+8*r(SPL)+7*w(SPL)+1
67
and a, e
78
ld e, a
8-
push bc
9-
inc sp
10-
inc sp
119
push hl
12-
ld hl, 2
10+
scf
11+
sbc hl, hl
1312
add hl, sp
13+
push bc
1414
ld a, (hl)
1515
inc hl
16+
ld sp, hl
17+
inc hl
18+
inc hl
1619
and a, (hl)
17-
dec hl
1820
ld (hl), a
1921
pop hl
20-
inc sp
2122
ld a, h
2223
and a, b
2324
ld h, a

src/crt/lor.src

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,12 @@ __lor := 0001D8h
1010
else
1111

1212
__lor:
13+
; CC: 30*r(PC)+11*r(SPL)+10*w(SPL)+2
1314
push af
1415
or a, e
1516
ld e, a
16-
push bc
17-
inc sp
18-
inc sp
19-
push hl
20-
ld hl, 2
21-
add hl, sp
22-
ld a, (hl)
23-
inc hl
24-
or a, (hl)
25-
dec hl
26-
ld (hl), a
27-
pop hl
28-
inc sp
29-
ld a, h
30-
or a, b
31-
ld h, a
32-
ld a, l
33-
or a, c
34-
ld l, a
35-
pop af
36-
ret
17+
jp __ior.hijack_lor
18+
19+
extern __ior.hijack_lor
3720

3821
end if

src/crt/lor_fast.src

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,22 @@
33
section .text
44
public __lor_fast
55
__lor_fast:
6+
; CC: 24*r(PC)+8*r(SPL)+7*w(SPL)+1
67
or a, e
78
ld e, a
8-
push bc
9-
inc sp
10-
inc sp
119
push hl
12-
ld hl, 2
10+
scf
11+
sbc hl, hl
1312
add hl, sp
13+
push bc
1414
ld a, (hl)
1515
inc hl
16+
ld sp, hl
17+
inc hl
18+
inc hl
1619
or a, (hl)
17-
dec hl
1820
ld (hl), a
1921
pop hl
20-
inc sp
2122
ld a, h
2223
or a, b
2324
ld h, a

0 commit comments

Comments
 (0)