Skip to content

Commit 6335d08

Browse files
committed
fix: bxor16 with 0xFFFF was wrongly optimized.
1 parent 856c479 commit 6335d08

File tree

2 files changed

+5
-25
lines changed

2 files changed

+5
-25
lines changed

src/arch/z80/backend/_16bit.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -752,11 +752,6 @@ def bxor16(cls, ins: Quad) -> list[str]:
752752
output.append("push hl")
753753
return output
754754

755-
if op2 == 0xFFFF: # X ^ 0xFFFF = bNOT X
756-
output.append(runtime_call(RuntimeLabel.NEGHL))
757-
output.append("push hl")
758-
return output
759-
760755
output = cls.get_oper(op1, op2)
761756
output.append(runtime_call(RuntimeLabel.BXOR16))
762757
output.append("push hl")

tests/functional/arch/zx48k/bxor16.asm

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ _b:
3030
call .core.__BXOR16
3131
ld a, l
3232
ld (_b), a
33+
ld de, 65535
3334
ld hl, (_a)
34-
call .core.__NEGHL
35+
call .core.__BXOR16
3536
ld a, l
3637
ld (_b), a
3738
ld hl, (_a)
@@ -42,8 +43,9 @@ _b:
4243
call .core.__BXOR16
4344
ld a, l
4445
ld (_b), a
46+
ld de, 65535
4547
ld hl, (_a)
46-
call .core.__NEGHL
48+
call .core.__BXOR16
4749
ld a, l
4850
ld (_b), a
4951
ld de, (_a)
@@ -84,22 +86,5 @@ __BXOR16:
8486
ld l, a
8587
ret
8688
pop namespace
87-
#line 46 "arch/zx48k/bxor16.bas"
88-
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/neg16.asm"
89-
; Negates HL value (16 bit)
90-
push namespace core
91-
__ABS16:
92-
bit 7, h
93-
ret z
94-
__NEGHL:
95-
ld a, l ; HL = -HL
96-
cpl
97-
ld l, a
98-
ld a, h
99-
cpl
100-
ld h, a
101-
inc hl
102-
ret
103-
pop namespace
104-
#line 47 "arch/zx48k/bxor16.bas"
89+
#line 48 "arch/zx48k/bxor16.bas"
10590
END

0 commit comments

Comments
 (0)