kit

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

icmp_branch_signed_int.c (996B)


      1 /* Signed 32-bit comparisons used as if/ternary branch conditions. Each compare
      2  * feeds a conditional branch (cmp + b.cond / cbz), exercising branch-label
      3  * synthesis in the symbolizer (and same-section branch relaxation in `as`).
      4  * volatile operands defeat folding. noinline keeps each compare in its own call
      5  * so the branch is real. Exit code totals 42. */
      6 __attribute__((noinline)) static int pick_lt(int a, int b) {
      7   return a < b ? 10 : 1;
      8 }
      9 __attribute__((noinline)) static int pick_le(int a, int b) {
     10   return a <= b ? 10 : 1;
     11 }
     12 __attribute__((noinline)) static int pick_gt(int a, int b) {
     13   return a > b ? 1 : 11;
     14 }
     15 __attribute__((noinline)) static int pick_ge(int a, int b) {
     16   return a >= b ? 1 : 11;
     17 }
     18 int test_main(void) {
     19   volatile int a = -3, b = 7;
     20   int r = 0;
     21   r += pick_lt(a, b); /* -3 <  7 -> 10 */
     22   r += pick_le(a, b); /* -3 <= 7 -> 10 */
     23   r += pick_gt(a, b); /* -3 >  7 false -> 11 */
     24   r += pick_ge(a, b); /* -3 >= 7 false -> 11 */
     25   return r;           /* 42 */
     26 }