kit

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

icmp_cmp_imm.c (616B)


      1 /* Comparison against a small immediate, which lowers to `cmp w, #imm` (the
      2  * immediate form of subs) rather than a register compare. Covers the immediate
      3  * encoding of the compare in the disasm/encode round-trip. volatile defeats
      4  * folding. Exit code: a=10: (a<100)=1, (a>=5)=1, (a==10)=1 -> 1*20+1*20+1*2
      5  * = 42. */
      6 int test_main(void) {
      7   volatile int a = 10;
      8   int lt = (a < 100);                /* 1, cmp w,#100 + cset lt */
      9   int ge = (a >= 5);                 /* 1, cmp w,#5   + cset ge */
     10   int eq = (a == 10);                /* 1, cmp w,#10  + cset eq */
     11   return lt * 20 + ge * 20 + eq * 2; /* 42 */
     12 }