From f3ad5e90ff73c3fea87c98d73f0553dd868e22de Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Fri, 21 Oct 2022 05:11:58 -0300 Subject: [PATCH] feat(cpu): implement RRX for Barrel Shifter --- src/cpu/arm/barrel_shifter.zig | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/cpu/arm/barrel_shifter.zig b/src/cpu/arm/barrel_shifter.zig index a7f28d4..b1827f1 100644 --- a/src/cpu/arm/barrel_shifter.zig +++ b/src/cpu/arm/barrel_shifter.zig @@ -91,3 +91,12 @@ pub fn rotateRight(comptime S: bool, cpsr: *CPSR, rm: u32, amount: u8) u32 { return result; } + +pub fn rotateRightExtended(comptime S: bool, cpsr: *CPSR, rm: u32) u32 { + if (!S) std.debug.panic("[BarrelShifter] Turns out I don't know how RRX works", .{}); + + const carry: u32 = @boolToInt(cpsr.c.read()); + cpsr.c.write(rm & 1 == 1); + + return (carry << 31) | (rm >> 1); +}