kit

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

ibit_shift_const.c (575B)


      1 /* 32-bit shifts by a constant amount. On aarch64 these lower to the immediate
      2  * forms: LSL via UBFM, LSR via UBFM, ASR via SBFM. volatile defeats folding.
      3  *   u = 0x15 (21):  u << 1 = 42 (logical left)
      4  *   v = 0x150 (336): v >> 3 = 42 (logical right, unsigned)
      5  *   s = -336:        s >> 3 = -42 (arithmetic right, signed)
      6  *   42 + 42 + (-42) = 42. */
      7 int test_main(void) {
      8   volatile unsigned int u = 0x15;
      9   volatile unsigned int v = 0x150;
     10   volatile int s = -336;
     11   int lsl = (int)(u << 1);
     12   int lsr = (int)(v >> 3);
     13   int asr = s >> 3;
     14   return lsl + lsr + asr;
     15 }