chore: replace unnecessarily complex sign extension implementation

This commit is contained in:
2022-02-28 20:38:50 -04:00
parent ddb68a7952
commit cb4d3a9a51
6 changed files with 19 additions and 41 deletions

View File

@@ -14,7 +14,7 @@ pub fn format6(comptime rd: u3) InstrFn {
}.inner;
}
const u32SignExtend = @import("../../util.zig").u32SignExtend;
const sext = @import("../../util.zig").sext;
pub fn format78(comptime op: u2, comptime T: bool) InstrFn {
return struct {
@@ -34,7 +34,7 @@ pub fn format78(comptime op: u2, comptime T: bool) InstrFn {
},
0b01 => {
// LDSB
cpu.r[rd] = u32SignExtend(8, bus.read8(address));
cpu.r[rd] = sext(8, bus.read8(address));
},
0b10 => {
// LDRH
@@ -44,9 +44,9 @@ pub fn format78(comptime op: u2, comptime T: bool) InstrFn {
0b11 => {
// LDRSH
const value = if (address & 1 == 1) blk: {
break :blk u32SignExtend(8, bus.read8(address));
break :blk sext(8, bus.read8(address));
} else blk: {
break :blk u32SignExtend(16, bus.read16(address));
break :blk sext(16, bus.read16(address));
};
cpu.r[rd] = std.math.rotr(u32, value, 8 * (address & 1));