Skip to content

Commit 4839a98

Browse files
calc84maniacmateoconlechuga
authored andcommitted
Combine overlapping and/or/xor implementations to save executable space
1 parent 092c7fb commit 4839a98

15 files changed

+111
-180
lines changed

src/crt/iand.src renamed to src/crt/and.src

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,30 @@
11
assume adl=1
22

33
section .text
4+
public __land
5+
6+
if PREFER_OS_CRT
7+
8+
__land := 0001A4h
9+
10+
else
11+
12+
__land:
13+
; CC: 28*r(PC)+11*r(SPL)+10*w(SPL)+1
14+
push af
15+
and a, e
16+
ld e, a
17+
; jr __iand.hijack_land
18+
virtual
19+
ld a, 0
20+
load .ld_a: byte from $$
21+
end virtual
22+
db .ld_a ; push af -> ld a,*
23+
require __iand
24+
25+
end if
26+
27+
section .text
428
public __iand
529

630
if PREFER_OS_CRT
@@ -12,7 +36,7 @@ else
1236
__iand:
1337
; CC: 24*r(PC)+11*r(SPL)+10*w(SPL)+1
1438
push af
15-
public __iand.hijack_land
39+
private __iand.hijack_land
1640
.hijack_land:
1741
push hl
1842
scf

src/crt/land_fast.src renamed to src/crt/and_fast.src

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ __land_fast:
66
; CC: 24*r(PC)+8*r(SPL)+7*w(SPL)+1
77
and a, e
88
ld e, a
9+
require __iand_fast
10+
11+
section .text
12+
public __iand_fast
13+
__iand_fast:
14+
; CC: 22*r(PC)+8*r(SPL)+7*w(SPL)+1
915
push hl
1016
scf
1117
sbc hl, hl
@@ -19,6 +25,12 @@ __land_fast:
1925
and a, (hl)
2026
ld (hl), a
2127
pop hl
28+
require __sand_fast
29+
30+
section .text
31+
public __sand_fast
32+
__sand_fast:
33+
; CC: 8*r(PC)+3*r(SPL)+1
2234
ld a, h
2335
and a, b
2436
ld h, a

src/crt/iand_fast.src

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/crt/ior_fast.src

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/crt/ixor_fast.src

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/crt/land.src

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/crt/lor.src

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/crt/lxor.src

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/crt/ior.src renamed to src/crt/or.src

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
11
assume adl=1
22

3+
section .text
4+
public __lor
5+
6+
if PREFER_OS_CRT
7+
8+
__lor := 0001D8h
9+
10+
else
11+
12+
__lor:
13+
; CC: 28*r(PC)+11*r(SPL)+10*w(SPL)+1
14+
push af
15+
or a, e
16+
ld e, a
17+
; jr __ior.hijack_lor
18+
virtual
19+
ld a, 0
20+
load .ld_a: byte from $$
21+
end virtual
22+
db .ld_a ; push af -> ld a,*
23+
require __ior
24+
25+
end if
26+
327
section .text
428
public __ior
529

@@ -12,7 +36,7 @@ else
1236
__ior:
1337
; CC: 24*r(PC)+11*r(SPL)+10*w(SPL)+1
1438
push af
15-
public __ior.hijack_lor
39+
private __ior.hijack_lor
1640
.hijack_lor:
1741
push hl
1842
scf

src/crt/lor_fast.src renamed to src/crt/or_fast.src

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ __lor_fast:
66
; CC: 24*r(PC)+8*r(SPL)+7*w(SPL)+1
77
or a, e
88
ld e, a
9+
require __ior_fast
10+
11+
section .text
12+
public __ior_fast
13+
__ior_fast:
14+
; CC: 22*r(PC)+8*r(SPL)+7*w(SPL)+1
915
push hl
1016
scf
1117
sbc hl, hl
@@ -19,6 +25,12 @@ __lor_fast:
1925
or a, (hl)
2026
ld (hl), a
2127
pop hl
28+
require __sor_fast
29+
30+
section .text
31+
public __sor_fast
32+
__sor_fast:
33+
; CC: 8*r(PC)+3*r(SPL)+1
2234
ld a, h
2335
or a, b
2436
ld h, a

src/crt/sand_fast.src

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/crt/sor_fast.src

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/crt/sxor_fast.src

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/crt/ixor.src renamed to src/crt/xor.src

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
11
assume adl=1
22

3+
section .text
4+
public __lxor
5+
6+
if PREFER_OS_CRT
7+
8+
__lxor := 0001FCh
9+
10+
else
11+
12+
__lxor:
13+
; CC: 28*r(PC)+11*r(SPL)+10*w(SPL)+1
14+
push af
15+
xor a, e
16+
ld e, a
17+
; jr __ixor.hijack_lxor
18+
virtual
19+
ld a, 0
20+
load .ld_a: byte from $$
21+
end virtual
22+
db .ld_a ; push af -> ld a,*
23+
require __ixor
24+
25+
end if
26+
327
section .text
428
public __ixor
529

@@ -12,7 +36,7 @@ else
1236
__ixor:
1337
; CC: 24*r(PC)+11*r(SPL)+10*w(SPL)+1
1438
push af
15-
public __ixor.hijack_lxor
39+
private __ixor.hijack_lxor
1640
.hijack_lxor:
1741
push hl
1842
scf

src/crt/lxor_fast.src renamed to src/crt/xor_fast.src

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ __lxor_fast:
66
; CC: 24*r(PC)+8*r(SPL)+7*w(SPL)+1
77
xor a, e
88
ld e, a
9+
require __ixor_fast
10+
11+
section .text
12+
public __ixor_fast
13+
__ixor_fast:
14+
; CC: 22*r(PC)+8*r(SPL)+7*w(SPL)+1
915
push hl
1016
scf
1117
sbc hl, hl
@@ -19,6 +25,12 @@ __lxor_fast:
1925
xor a, (hl)
2026
ld (hl), a
2127
pop hl
28+
require __sxor_fast
29+
30+
section .text
31+
public __sxor_fast
32+
__sxor_fast:
33+
; CC: 8*r(PC)+3*r(SPL)+1
2234
ld a, h
2335
xor a, b
2436
ld h, a

0 commit comments

Comments
 (0)