From c865da67e0bf8f15d803ab1a9caf50b48a0a984f Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 2 Mar 2024 15:12:03 -0500 Subject: [PATCH] Introduce further barrel-shifter tests. --- .../Mac/Clock SignalTests/ARMDecoderTests.mm | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/OSBindings/Mac/Clock SignalTests/ARMDecoderTests.mm b/OSBindings/Mac/Clock SignalTests/ARMDecoderTests.mm index dc96c0ccf..352de1907 100644 --- a/OSBindings/Mac/Clock SignalTests/ARMDecoderTests.mm +++ b/OSBindings/Mac/Clock SignalTests/ARMDecoderTests.mm @@ -50,6 +50,29 @@ struct Memory { // InstructionSet::ARM::dispatch(0xEAE06900, scheduler); //} +- (void)testBarrelShifterLogicalLeft { + uint32_t value; + uint32_t carry; + + // Test a shift by 1 into carry. + value = 0x8000'0000; + shift(value, 1, carry); + XCTAssertEqual(value, 0); + XCTAssertNotEqual(carry, 0); + + // Test a shift by 18 into carry. + value = 0x0000'4001; + shift(value, 18, carry); + XCTAssertEqual(value, 0x4'0000); + XCTAssertNotEqual(carry, 0); + + // Test a shift by 17, not generating carry. + value = 0x0000'4001; + shift(value, 17, carry); + XCTAssertEqual(value, 0x8002'0000); + XCTAssertEqual(carry, 0); +} + - (void)testBarrelShifterLogicalRight { uint32_t value; uint32_t carry; @@ -94,4 +117,82 @@ struct Memory { XCTAssertNotEqual(carry, 0); } +- (void)testBarrelShifterArithmeticRight { + uint32_t value; + uint32_t carry; + + // Test a short negative shift. + value = 0x8000'0030; + shift(value, 1, carry); + XCTAssertEqual(value, 0xc000'0018); + XCTAssertEqual(carry, 0); + + // Test a medium negative shift without carry. + value = 0xffff'0000; + shift(value, 11, carry); + XCTAssertEqual(value, 0xffff'ffe0); + XCTAssertEqual(carry, 0); + + // Test a medium negative shift with carry. + value = 0xffc0'0000; + shift(value, 23, carry); + XCTAssertEqual(value, 0xffff'ffff); + XCTAssertNotEqual(carry, 0); + + // Test a long negative shift. + value = 0x8000'0000; + shift(value, 32, carry); + XCTAssertEqual(value, 0xffff'ffff); + XCTAssertNotEqual(carry, 0); + + // Test a positive shift. + value = 0x0123'0031; + shift(value, 3, carry); + XCTAssertEqual(value, 0x24'6006); + XCTAssertEqual(carry, 0); +} + +- (void)testBarrelShifterRotateRight { + uint32_t value; + uint32_t carry; + + // Test a short rotate by one hex digit. + value = 0xabcd'1234; + shift(value, 4, carry); + XCTAssertEqual(value, 0x4abc'd123); + XCTAssertEqual(carry, 0); + + // Test a longer rotate, with carry. + value = 0xa5f9'6342; + shift(value, 17, carry); + XCTAssertEqual(value, 0xb1a1'52fc); + XCTAssertNotEqual(carry, 0); + + // Test a rotate by 32 without carry. + value = 0x385f'7dce; + shift(value, 32, carry); + XCTAssertEqual(value, 0x385f'7dce); + XCTAssertEqual(carry, 0); + + // Test a rotate by 32 with carry. + value = 0xfecd'ba12; + shift(value, 32, carry); + XCTAssertEqual(value, 0xfecd'ba12); + XCTAssertNotEqual(carry, 0); + + // Test a rotate through carry, carry not set. + value = 0x123f'abcf; + carry = 0; + shift(value, 0, carry); + XCTAssertEqual(value, 0x091f'd5e7); + XCTAssertNotEqual(carry, 0); + + // Test a rotate through carry, carry set. + value = 0x123f'abce; + carry = 1; + shift(value, 0, carry); + XCTAssertEqual(value, 0x891f'd5e7); + XCTAssertEqual(carry, 0); +} + @end