Helper to produce the lui+addi sequence for a 32-bit constant
(rd: Reg, val32: i32)
| 419 | let lo12_signed = if lo12 >= 0x800 { lo12 - 0x1000 } else { lo12 }; |
| 420 | let hi20 = val32.wrapping_sub(lo12_signed); |
| 421 | let mut seq = vec![RealInstruction::Lui(Lui::new(rd, hi20))]; |
| 422 | if lo12_signed != 0 { |
| 423 | seq.push(RealInstruction::Addi(Addi::new(rd, rd, lo12_signed))); |
| 424 | } |
| 425 | seq |
| 426 | } |
| 427 | |
| 428 | let mut seq = Vec::new(); |
| 429 | |
| 430 | // Load the high 32 bits into t1 and shift them left by 32. |
| 431 | seq.append(&mut load32(T1, high32)); // T1 = sign_ext(high32) |
| 432 | seq.push(RealInstruction::Slli(Slli::new(T1, T1, 32))); // T1 = high32 << 32 |
| 433 |