fix: respond to `@addWithOverflow` changes in latest zig

This commit is contained in:
Rekai Nyangadzayi Musuka 2022-12-28 14:52:12 -06:00
parent 0cec779545
commit 5fa6917689
2 changed files with 17 additions and 10 deletions

View File

@ -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 {

View File

@ -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,