Skip to content

Commit

Permalink
Merge pull request #144 from DrXiao/fix-arm-sra
Browse files Browse the repository at this point in the history
Fix Arm outputs for right shift operations
  • Loading branch information
jserv authored Aug 3, 2024
2 parents aab5755 + 6973f99 commit 6615b6c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/arm-codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ void emit_ph2_ir(ph2_ir_t *ph2_ir)
emit(__sll(__AL, rd, rn, rm));
return;
case OP_rshift:
emit(__srl(__AL, rd, rn, rm));
emit(__sra(__AL, rd, rn, rm));
return;
case OP_eq:
case OP_neq:
Expand Down
6 changes: 6 additions & 0 deletions src/arm.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,12 @@ int __sll_amt(arm_cond_t cond,
rm + (0 << 4) + (shift << 5) + (amt << 7));
}

int __sra(arm_cond_t cond, arm_reg rd, arm_reg rm, arm_reg rs)
{
return arm_encode(cond, 0 + (arm_mov << 1) + (0 << 5), 0, rd,
rm + (5 << 4) + (rs << 8));
}

int __add_i(arm_cond_t cond, arm_reg rd, arm_reg rs, int imm)
{
if (imm >= 0)
Expand Down
6 changes: 6 additions & 0 deletions tests/driver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ expr 1 "1 && 1"

expr 16 "2 << 3"
expr 32 "256 >> 3"
try_output 0 "128 59926 -6 -4 -500283" << EOF
int main() {
printf("%d %d %d %d %d", 32768 >> 8, 245458999 >> 12, -11 >> 1, -16 >> 2, -1000565 >> 1);
return 0;
}
EOF
expr 239 "237 | 106"
expr 135 "237 ^ 106"
expr 104 "237 & 106"
Expand Down

0 comments on commit 6615b6c

Please sign in to comment.