kit

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

mem_ptr_widths.c (944B)


      1 /* mem: stores and loads through explicit pointers at each width, using a
      2  * noinline helper so the pointer is opaque and the compiler cannot fold the
      3  * round-trip. Exercises strb/ldrb, strh/ldrh, str w/ldr w, str x/ldr x via
      4  * base-register addressing.
      5  *   8:5  16:6  32:9  64:22  -> 42 */
      6 __attribute__((noinline)) static void put8(unsigned char* p, unsigned char v) {
      7   *p = v;
      8 }
      9 __attribute__((noinline)) static void put16(unsigned short* p,
     10                                             unsigned short v) {
     11   *p = v;
     12 }
     13 __attribute__((noinline)) static void put32(unsigned int* p, unsigned int v) {
     14   *p = v;
     15 }
     16 __attribute__((noinline)) static void put64(unsigned long* p, unsigned long v) {
     17   *p = v;
     18 }
     19 int test_main(void) {
     20   unsigned char c;
     21   unsigned short s;
     22   unsigned int i;
     23   unsigned long l;
     24   put8(&c, 5);
     25   put16(&s, 6);
     26   put32(&i, 9);
     27   put64(&l, 22);
     28   unsigned long sum = (unsigned long)c + s + i + l;
     29   return (int)sum;
     30 }