Right-shifts a 32-bit integer by 16 bits and applies a mask to ensure the result fits within 16 bits.
int shr16(int x) { return (x >> 16) & mask16; }