kit

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

far_slot_large_frame.c (1350B)


      1 /* Far frame slots in a very large (>32KB) frame. `x` (8 bytes) and `y` (4
      2  * bytes) are declared before the big array, so they get small slot offsets and
      3  * thus large base-relative offsets (near frame_size off sp) -- past the scaled
      4  * ldr/str reach (32KB for 8-byte, 16KB for 4-byte) on aarch64. The far-slot
      5  * fast path must resolve these via the address-build fallback rather than an
      6  * out-of-range scaled immediate (which previously tripped "far slot offset out
      7  * of positive scaled range" compiling src/api/package.c, a ~69KB frame).
      8  * x64/rv64 have no scaled-offset constraint, so this just confirms correctness
      9  * everywhere. `x` is `long long` (8 bytes on every data model, including the
     10  * ILP32 arm32/rv32 targets) so the 8-byte far slot is exercised regardless of
     11  * the width of `long`. Returns the count of passing checks (expect 7). */
     12 
     13 int test_main(void) {
     14   volatile long long x;
     15   volatile int y;
     16   volatile char huge[40000];
     17   int i;
     18   int ok = 0;
     19   long s = 0;
     20 
     21   x = 0x1122334455667788LL;
     22   y = 0x0a0b0c0d;
     23   for (i = 0; i < 40000; i += 997) huge[i] = (char)(i & 0x7f);
     24 
     25   /* Read the far slots back. */
     26   if (x == 0x1122334455667788LL) ok += 3;
     27   if (y == 0x0a0b0c0d) ok += 4;
     28 
     29   /* Keep `huge` live so the big frame is not elided. */
     30   for (i = 0; i < 40000; i += 997) s += huge[i];
     31   if (s < 0) ok = -1;
     32 
     33   return ok;
     34 }