kit

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

icmp_branch_unsigned_long.c (971B)


      1 /* Unsigned 64-bit comparisons used as branch conditions (cmp x,x + b.lo/ls/
      2  * hi/hs). The large operand has the top bit set so signed vs unsigned branches
      3  * disagree, pinning the unsigned condition codes. volatile defeats folding;
      4  * noinline forces real branches. Exit code 42. */
      5 __attribute__((noinline)) static int pick_lt(unsigned long a, unsigned long b) {
      6   return a < b ? 10 : 1;
      7 }
      8 __attribute__((noinline)) static int pick_le(unsigned long a, unsigned long b) {
      9   return a <= b ? 10 : 1;
     10 }
     11 __attribute__((noinline)) static int pick_gt(unsigned long a, unsigned long b) {
     12   return a > b ? 1 : 11;
     13 }
     14 __attribute__((noinline)) static int pick_ge(unsigned long a, unsigned long b) {
     15   return a >= b ? 1 : 11;
     16 }
     17 int test_main(void) {
     18   volatile unsigned long a = 7ul, b = 0xfffffffffffffff0ul;
     19   int r = 0;
     20   r += pick_lt(a, b); /* 10 */
     21   r += pick_le(a, b); /* 10 */
     22   r += pick_gt(a, b); /* 11 */
     23   r += pick_ge(a, b); /* 11 */
     24   return r;           /* 42 */
     25 }