From 5fa69176899300acac7b201232edc77637d7333c Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Wed, 28 Dec 2022 14:52:12 -0600 Subject: [PATCH] fix: respond to `@addWithOverflow` changes in latest zig --- src/core/cpu/arm/data_processing.zig | 20 +++++++++++--------- src/core/cpu/thumb/alu.zig | 7 ++++++- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/core/cpu/arm/data_processing.zig b/src/core/cpu/arm/data_processing.zig index 7bc3f44..d8ce6e0 100644 --- a/src/core/cpu/arm/data_processing.zig +++ b/src/core/cpu/arm/data_processing.zig @@ -62,7 +62,9 @@ pub fn dataProcessing(comptime I: bool, comptime S: bool, comptime kind: u4) Ins if (rd == 0xF) return undefinedTestBehaviour(cpu); - overflow = @addWithOverflow(u32, op1, op2, &result); + const tmp = @addWithOverflow(op1, op2); + result = tmp[0]; + overflow = tmp[1] == 0b1; }, 0xC => result = op1 | op2, // ORR 0xD => result = op2, // MOV @@ -163,18 +165,18 @@ pub fn sbc(left: u32, right: u32, old_carry: u1) u32 { } pub fn add(overflow: *bool, left: u32, right: u32) u32 { - var ret: u32 = undefined; - overflow.* = @addWithOverflow(u32, left, right, &ret); - return ret; + const ret = @addWithOverflow(left, right); + overflow.* = ret[1] == 0b1; + + return ret[0]; } pub fn adc(overflow: *bool, left: u32, right: u32, old_carry: u1) u32 { - var ret: u32 = undefined; - const first = @addWithOverflow(u32, left, right, &ret); - const second = @addWithOverflow(u32, ret, old_carry, &ret); + const tmp = @addWithOverflow(left, right); + const ret = @addWithOverflow(tmp[0], old_carry); + overflow.* = (tmp[1] | ret[1]) == 0b1; - overflow.* = first or second; - return ret; + return ret[0]; } fn undefinedTestBehaviour(cpu: *Arm7tdmi) void { diff --git a/src/core/cpu/thumb/alu.zig b/src/core/cpu/thumb/alu.zig index 778da99..43c43e7 100644 --- a/src/core/cpu/thumb/alu.zig +++ b/src/core/cpu/thumb/alu.zig @@ -34,7 +34,12 @@ pub fn fmt4(comptime op: u4) InstrFn { 0x8 => result = op1 & op2, // TST 0x9 => result = 0 -% op2, // NEG 0xA => result = op1 -% op2, // CMP - 0xB => overflow = @addWithOverflow(u32, op1, op2, &result), // CMN + 0xB => { + // CMN + const tmp = @addWithOverflow(op1, op2); + result = tmp[0]; + overflow = tmp[1] == 0b1; + }, 0xC => result = op1 | op2, // ORR 0xD => result = @truncate(u32, @as(u64, op2) * @as(u64, op1)), 0xE => result = op1 & ~op2,