boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

342-i64-two-word.c (1380B)


      1 /* 64-bit integers use P1's two-word convention on RV32. This exercises
      2  * both data movement and the operations whose high limb cannot be ignored. */
      3 typedef unsigned long long u64;
      4 typedef signed long long i64;
      5 
      6 static u64 g = 0x1122334455667788ULL;
      7 
      8 static u64 id(u64 x) { return x; }
      9 static u64 add2(u64 a, u64 b) { return a + b; }
     10 static u64 stack_pair(int a, int b, int c, u64 x)
     11 {
     12     return x + (u64)(a + b + c);
     13 }
     14 
     15 int main(void)
     16 {
     17     u64 x = g;
     18 
     19     if (x != 0x1122334455667788ULL) return 1;
     20     if ((x >> 32) != 0x11223344ULL) return 2;
     21     if ((x << 16) != 0x3344556677880000ULL) return 3;
     22     if (id(x) != x) return 4;
     23     if (add2(0x123456789abcdef0ULL, 0xfedcba9876543210ULL)
     24         != 0x1111111111111100ULL) return 5;
     25     if (stack_pair(1, 2, 3, 0x100000000ULL) != 0x100000006ULL)
     26         return 6;
     27 
     28     if ((0x100000000ULL - 1ULL) != 0xffffffffULL) return 7;
     29     if ((0x12345678ULL * 0x100000003ULL)
     30         != 0x12345678369d0368ULL) return 8;
     31     if ((0x123456789abcdef0ULL / 0x12345ULL) != 0x100005b00205ULL)
     32         return 9;
     33     if ((0x123456789abcdef0ULL % 0x12345ULL) != 0xa497ULL)
     34         return 10;
     35 
     36     if ((i64)-0x100000001LL != -4294967297LL) return 11;
     37     if ((i64)-0x100000001LL >= -1LL) return 12;
     38     if ((i64)-0x123456789LL / 0x12345LL != -0x10000LL) return 13;
     39     if ((i64)-0x123456789LL % 0x12345LL != -0x6789LL) return 14;
     40 
     41     return 0;
     42 }