ibit_long_shift_const.c (617B)
1 /* 64-bit shifts by a constant amount on `long`/`unsigned long`. Exercises the 2 * 64-bit immediate shift forms (LSL/LSR/ASR via the x-register UBFM/SBFM). 3 * volatile defeats folding. 4 * u = 0x15 (21): u << 1 = 42 (logical left) 5 * v = 0x150 (336): v >> 3 = 42 (logical right, unsigned) 6 * s = -336: s >> 3 = -42 (arithmetic right, signed) 7 * 42 + 42 + (-42) = 42. */ 8 int test_main(void) { 9 volatile unsigned long u = 0x15; 10 volatile unsigned long v = 0x150; 11 volatile long s = -336; 12 long lsl = (long)(u << 1); 13 long lsr = (long)(v >> 3); 14 long asr = s >> 3; 15 return (int)(lsl + lsr + asr); 16 }