From 8bbb70f61fadd5890c05f17addcf1d2f8b9dea6b Mon Sep 17 00:00:00 2001 From: Brendan Fletcher Date: Mon, 19 Aug 2024 19:02:35 -0400 Subject: [PATCH] Fix signed overflow calculation in ADCS/SBCS when using overflow builtins --- core/arm/armcpu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/arm/armcpu.c b/core/arm/armcpu.c index ecf856e44..d3697e8af 100644 --- a/core/arm/armcpu.c +++ b/core/arm/armcpu.c @@ -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); @@ -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);