Skip to content

Commit 442de0d

Browse files
calc84maniacadriweb
authored andcommitted
Fix signed overflow calculation in ADCS/SBCS when using overflow builtins
1 parent de7ef90 commit 442de0d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

core/arm/armcpu.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ static uint32_t arm_adcs(arm_cpu_t *cpu, uint32_t x, uint32_t y) {
317317
bool carry = cpu->c;
318318
int32_t res;
319319
cpu->v = __builtin_add_overflow(x, y, &res);
320-
cpu->v |= __builtin_add_overflow(res, carry, &res);
320+
cpu->v ^= __builtin_add_overflow(res, carry, &res);
321321
cpu->c = __builtin_add_overflow(x, y, &x);
322322
cpu->c |= __builtin_add_overflow(x, carry, &x);
323323
return arm_movs(cpu, x);
@@ -347,7 +347,7 @@ static uint32_t arm_sbcs(arm_cpu_t *cpu, uint32_t x, uint32_t y) {
347347
bool borrow = !cpu->c;
348348
int32_t res;
349349
cpu->v = __builtin_sub_overflow(x, y, &res);
350-
cpu->v |= __builtin_sub_overflow(res, borrow, &res);
350+
cpu->v ^= __builtin_sub_overflow(res, borrow, &res);
351351
cpu->c = !__builtin_sub_overflow(x, y, &x);
352352
cpu->c &= !__builtin_sub_overflow(x, borrow, &x);
353353
return arm_movs(cpu, x);

0 commit comments

Comments
 (0)