fn sign_extend_u11(x: u32) -> u32 {
(((x as i32) << (32-11)) >> (32-11)) as u32
}
Doesn't have any of the C++ issues he mentions. And it will be faster than the alternative since it's just two instructions. (Ok this is never going to matter in practice but still...)
Shifts run on less ports than xor/sub, so should be avoided if possible when performance is important, especially when using SIMD where the shifts are often quite subpar.