mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-22 12:33:29 +00:00
Introduce further barrel-shifter tests.
This commit is contained in:
parent
e6f77a9b80
commit
c865da67e0
@ -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<ShiftType::LogicalLeft, true>(value, 1, carry);
|
||||
XCTAssertEqual(value, 0);
|
||||
XCTAssertNotEqual(carry, 0);
|
||||
|
||||
// Test a shift by 18 into carry.
|
||||
value = 0x0000'4001;
|
||||
shift<ShiftType::LogicalLeft, true>(value, 18, carry);
|
||||
XCTAssertEqual(value, 0x4'0000);
|
||||
XCTAssertNotEqual(carry, 0);
|
||||
|
||||
// Test a shift by 17, not generating carry.
|
||||
value = 0x0000'4001;
|
||||
shift<ShiftType::LogicalLeft, true>(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<ShiftType::ArithmeticRight, true>(value, 1, carry);
|
||||
XCTAssertEqual(value, 0xc000'0018);
|
||||
XCTAssertEqual(carry, 0);
|
||||
|
||||
// Test a medium negative shift without carry.
|
||||
value = 0xffff'0000;
|
||||
shift<ShiftType::ArithmeticRight, true>(value, 11, carry);
|
||||
XCTAssertEqual(value, 0xffff'ffe0);
|
||||
XCTAssertEqual(carry, 0);
|
||||
|
||||
// Test a medium negative shift with carry.
|
||||
value = 0xffc0'0000;
|
||||
shift<ShiftType::ArithmeticRight, true>(value, 23, carry);
|
||||
XCTAssertEqual(value, 0xffff'ffff);
|
||||
XCTAssertNotEqual(carry, 0);
|
||||
|
||||
// Test a long negative shift.
|
||||
value = 0x8000'0000;
|
||||
shift<ShiftType::ArithmeticRight, true>(value, 32, carry);
|
||||
XCTAssertEqual(value, 0xffff'ffff);
|
||||
XCTAssertNotEqual(carry, 0);
|
||||
|
||||
// Test a positive shift.
|
||||
value = 0x0123'0031;
|
||||
shift<ShiftType::ArithmeticRight, true>(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<ShiftType::RotateRight, true>(value, 4, carry);
|
||||
XCTAssertEqual(value, 0x4abc'd123);
|
||||
XCTAssertEqual(carry, 0);
|
||||
|
||||
// Test a longer rotate, with carry.
|
||||
value = 0xa5f9'6342;
|
||||
shift<ShiftType::RotateRight, true>(value, 17, carry);
|
||||
XCTAssertEqual(value, 0xb1a1'52fc);
|
||||
XCTAssertNotEqual(carry, 0);
|
||||
|
||||
// Test a rotate by 32 without carry.
|
||||
value = 0x385f'7dce;
|
||||
shift<ShiftType::RotateRight, true>(value, 32, carry);
|
||||
XCTAssertEqual(value, 0x385f'7dce);
|
||||
XCTAssertEqual(carry, 0);
|
||||
|
||||
// Test a rotate by 32 with carry.
|
||||
value = 0xfecd'ba12;
|
||||
shift<ShiftType::RotateRight, true>(value, 32, carry);
|
||||
XCTAssertEqual(value, 0xfecd'ba12);
|
||||
XCTAssertNotEqual(carry, 0);
|
||||
|
||||
// Test a rotate through carry, carry not set.
|
||||
value = 0x123f'abcf;
|
||||
carry = 0;
|
||||
shift<ShiftType::RotateRight, true>(value, 0, carry);
|
||||
XCTAssertEqual(value, 0x091f'd5e7);
|
||||
XCTAssertNotEqual(carry, 0);
|
||||
|
||||
// Test a rotate through carry, carry set.
|
||||
value = 0x123f'abce;
|
||||
carry = 1;
|
||||
shift<ShiftType::RotateRight, true>(value, 0, carry);
|
||||
XCTAssertEqual(value, 0x891f'd5e7);
|
||||
XCTAssertEqual(carry, 0);
|
||||
}
|
||||
|
||||
@end
|
||||
|
Loading…
Reference in New Issue
Block a user