1pub const J20 = packed struct(u32) { b0_4: u5, j20: u20, b25_31: u7 };
2pub const K12 = packed struct(u32) { b0_9: u10, k12: u12, b22_31: u10 };
3pub const K16 = packed struct(u32) { b0_9: u10, k16: u16, b26_31: u6 };
4pub const D5K16 = packed struct(u32) { d5: u5, b5_9: u5, k16: u16, b26_31: u6 };
5pub const D10K16 = packed struct(u32) { d10: u10, k16: u16, b26_31: u6 };
6
7pub fn pcalaHi20(target: u64, pc: u64) u20 {
8 return @truncate(((target +% 0x800) >> 12) -% (pc >> 12));
9}
10
11pub fn pcala64Lo20(target: u64, pc: u64) u20 {
12 const fixup = if (target & 0x800 != 0) (@as(u64, 0x1000) -% @as(u64, 0x100000000)) else 0;
13 const hi32 = (((target +% 0x80000000 +% fixup) >> 12) -% ((pc -% 8) >> 12)) >> 20;
14 return @truncate(hi32);
15}
16
17pub fn pcala64Hi12(target: u64, pc: u64) u12 {
18 const fixup = if (target & 0x800 != 0) (@as(u64, 0x1000) -% @as(u64, 0x100000000)) else 0;
19 const hi32 = (((target +% 0x80000000 +% fixup) >> 12) -% ((pc -% 12) >> 12)) >> 20;
20 return @truncate(hi32 >> 20);
21}