Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Arm outputs for right shift operations #144

Merged
merged 1 commit into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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