kit

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

mem_long_array.c (545B)


      1 /* mem: a local 64-bit (long) array summed in a loop. Element accesses use the
      2  * 8-byte scaled forms (`ldr x, [base, x, lsl #3]` / `str x`). Values exceed 32
      3  * bits so the 64-bit width is required. Exit: sum -> 42. */
      4 int test_main(void) {
      5   long a[6];
      6   for (int i = 0; i < 6; ++i) a[i] = (long)(i + 1) << 32; /* big values */
      7   volatile int n = 6;
      8   long sum = 0;
      9   for (int i = 0; i < n; ++i) sum += a[i]; /* (1+..+6)<<32 = 21<<32 */
     10   long top = sum >> 32;                    /* 21 */
     11   return (int)(top + 21);                  /* 42 */
     12 }