ibit_shift_combo.c (620B)
1 /* Mixed shift+mask idiom: extract a byte field via a logical right shift 2 * followed by an AND mask, and rebuild via a left shift + OR. Exercises the 3 * shift forms feeding directly into and/orr (the common bitfield pattern) so 4 * the operand chaining round-trips. volatile defeats folding. 5 * x = 0x2A3B; (x >> 8) & 0xFF = 0x2A (42) 6 * y = 0x10; (y << 2) | 0x02 = 0x42 -> & 0x3F = 0x02 (2) 7 * 42 + 2 - 2 = 42. */ 8 int test_main(void) { 9 volatile unsigned int x = 0x2A3B; 10 volatile unsigned int y = 0x10; 11 int hi = (int)((x >> 8) & 0xFF); 12 int lo = (int)(((y << 2) | 0x02) & 0x3F); 13 return hi + lo - 2; 14 }