kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

155_musttail_indirect_packed_stack.toy (832B)


      1 // Keep this call genuinely indirect and force Tiny3 past all four AAPCS32 core
      2 // argument registers.  ARM32 must preserve the target in IP while its exact
      3 // three-byte stack-argument load uses LR as the carrier and IP to pack byte 2.
      4 record @[.packed] Tiny3 {
      5   x: u8,
      6   y: u8,
      7   z: u8,
      8 }
      9 
     10 fn @[.noinline] check(a: i32, b: i32, c: i32, d: i32, tiny: Tiny3): i32 {
     11   return (a - 11) + (b - 13) + (c - 17) + (d - 19) +
     12          (tiny.x as i32 - 23) + (tiny.y as i32 - 29) +
     13          (tiny.z as i32 - 31);
     14 }
     15 
     16 fn @[.noinline] forward(fp: *fn(i32, i32, i32, i32, Tiny3): i32,
     17                        a: i32, b: i32, c: i32, d: i32,
     18                        tiny: Tiny3): i32 {
     19   return musttail fp(a, b, c, d, tiny);
     20 }
     21 
     22 fn main(): i32 {
     23   let tiny: Tiny3 = Tiny3 { x: 23, y: 29, z: 31 };
     24   return forward(check, 11, 13, 17, 19, tiny);
     25 }