From @mmalex :

"
i cant believe i never realised before that to make a bitmask with set bits in [x0, x1), you can just do `mask = (1u<<x1)-(1u<<x0);` (obviously be sure that 0<=x0<=x1<32). ive used the degenerate case with x0==0 a billion times, but never thought to extend it. doh.
"

@TomF @mmalex big if true! will add to my bitops notes...
@TomF @mmalex some late 90s Amiga AGA demos used this to do saturating add on a 6bit per channel pixel where RGB are each on a separate byte. When a channel overflowed the 7th bit would be on, we could then mask it, shift and sub to create a 6 "on" bitmask to OR into the original value and thus force the value to be 0x3f.
@winden @TomF i love this trick! i think i learned it late in my vga pc scene age, and maybe used it in one of those fake rgb interlaced effects... happy times
@TomF @mmalex I think for that sort of thing I would have started with (unsigned)(-1) for all 1's and then done logical shifts left and right to abbreviate the mask and put it in position, but I'm used to having single-cycle barrel shifters. That'd definitely work better on hardware that has to pay extra for each bit of shift. Cool trick.