Skip to content

Commit

Permalink
Merge pull request #809 from bartsanchez/bart/move-bor16-to-a-class
Browse files Browse the repository at this point in the history
ref: move bor16 function into a class (Bits16)
  • Loading branch information
boriel authored Sep 3, 2024
2 parents a152daa + b99c393 commit b295400
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 28 deletions.
50 changes: 25 additions & 25 deletions src/arch/z80/backend/_16bit.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,38 +665,38 @@ def or16(cls, ins: Quad) -> list[str]:
output.append("push af")
return output

@classmethod
def bor16(cls, ins: Quad) -> list[str]:
"""Pops top 2 operands out of the stack, and performs
1st operand OR (bitwise) 2nd operand (top of the stack),
pushes result (16 bit in HL).
def _bor16(ins: Quad) -> list[str]:
"""Pops top 2 operands out of the stack, and performs
1st operand OR (bitwise) 2nd operand (top of the stack),
pushes result (16 bit in HL).
16 bit un/signed version
16 bit un/signed version
Optimizations:
Optimizations:
If any of the operators are constants: Returns either 0 or
the other operand
"""
op1, op2 = tuple(ins[2:])
If any of the operators are constants: Returns either 0 or
the other operand
"""
op1, op2 = tuple(ins[2:])

if _int_ops(op1, op2) is not None:
op1, op2 = _int_ops(op1, op2)
if _int_ops(op1, op2) is not None:
op1, op2 = _int_ops(op1, op2)

output = Bits16.get_oper(op1)
if op2 == 0: # X | 0 = X
output.append("push hl")
return output
output = Bits16.get_oper(op1)
if op2 == 0: # X | 0 = X
output.append("push hl")
return output

if op2 == 0xFFFF: # X & 0xFFFF = 0xFFFF
output.append("ld hl, 0FFFFh")
output.append("push hl")
return output
if op2 == 0xFFFF: # X & 0xFFFF = 0xFFFF
output.append("ld hl, 0FFFFh")
output.append("push hl")
return output

output = Bits16.get_oper(op1, op2)
output.append(runtime_call(RuntimeLabel.BOR16))
output.append("push hl")
return output
output = Bits16.get_oper(op1, op2)
output.append(runtime_call(RuntimeLabel.BOR16))
output.append("push hl")
return output


def _xor16(ins: Quad) -> list[str]:
Expand Down
5 changes: 2 additions & 3 deletions src/arch/z80/backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
_and16,
_band16,
_bnot16,
_bor16,
_bxor16,
_fparam16,
_jgezeroi16,
Expand Down Expand Up @@ -612,8 +611,8 @@ def _set_quad_table(self):
ICInstruction.BNOTU8: ICInfo(2, Bits8.bnot8), # x = !A
ICInstruction.BANDU16: ICInfo(3, _band16), # x = A & B
ICInstruction.BANDI16: ICInfo(3, _band16), # x = A & B
ICInstruction.BORU16: ICInfo(3, _bor16), # x = A | B
ICInstruction.BORI16: ICInfo(3, _bor16), # x = A | B
ICInstruction.BORU16: ICInfo(3, Bits16.bor16), # x = A | B
ICInstruction.BORI16: ICInfo(3, Bits16.bor16), # x = A | B
ICInstruction.BXORU16: ICInfo(3, _bxor16), # x = A ^ B
ICInstruction.BXORI16: ICInfo(3, _bxor16), # x = A ^ B
ICInstruction.BNOTU16: ICInfo(2, _bnot16), # x = A ^ B
Expand Down

0 comments on commit b295400

Please sign in to comment.