| 6 | |
| 7 | #[test] |
| 8 | fn decode_lui() { |
| 9 | // Lui::new(rd, imm), imm is the full 32-bit value whose upper 20 bits are used. |
| 10 | // Lui::new(5, 0x12345 << 12) would put 0x12345 in upper bits. |
| 11 | // But the u_inst! macro takes imm as i32 and masks lower 12 bits during encode. |
| 12 | // Pass the already-shifted value so upper 20 bits = 0x12345. |
| 13 | let encoded = Lui::new(5, 0x12345_000u32 as i32).encode(); |
| 14 | let decoded = decode(encoded).expect("should decode LUI"); |
| 15 | if let DecodedInsn::Lui { rd, imm } = decoded { |
| 16 | assert_eq!(rd, 5); |
| 17 | // The decoded imm is the full sign-extended 32-bit upper-immediate. |
| 18 | // 0x12345000 as i32 = 0x12345000 (positive, fits in i32). |
| 19 | let expected_imm = 0x12345_000i32 as i64; |
| 20 | assert_eq!( |
| 21 | imm, expected_imm, |
| 22 | "LUI immediate mismatch: got {imm:#x}, expected {expected_imm:#x}" |
| 23 | ); |
| 24 | } else { |
| 25 | panic!("expected DecodedInsn::Lui, got {decoded:?}"); |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | #[test] |
| 30 | fn decode_addi() { |