Skip to content

Commit

Permalink
Fix signed overflow calculation in ADCS/SBCS when using overflow buil…
Browse files Browse the repository at this point in the history
…tins
  • Loading branch information
calc84maniac committed Aug 19, 2024
1 parent d74e293 commit ad69900
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions core/arm/armcpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ static uint32_t arm_adcs(arm_cpu_t *cpu, uint32_t x, uint32_t y) {
bool carry = cpu->c;
int32_t res;
cpu->v = __builtin_add_overflow(x, y, &res);
cpu->v |= __builtin_add_overflow(res, carry, &res);
cpu->v ^= __builtin_add_overflow(res, carry, &res);
cpu->c = __builtin_add_overflow(x, y, &x);
cpu->c |= __builtin_add_overflow(x, carry, &x);
return arm_movs(cpu, x);
Expand Down Expand Up @@ -347,7 +347,7 @@ static uint32_t arm_sbcs(arm_cpu_t *cpu, uint32_t x, uint32_t y) {
bool borrow = !cpu->c;
int32_t res;
cpu->v = __builtin_sub_overflow(x, y, &res);
cpu->v |= __builtin_sub_overflow(res, borrow, &res);
cpu->v ^= __builtin_sub_overflow(res, borrow, &res);
cpu->c = !__builtin_sub_overflow(x, y, &x);
cpu->c &= !__builtin_sub_overflow(x, borrow, &x);
return arm_movs(cpu, x);
Expand Down

0 comments on commit ad69900

Please sign in to comment.