#shift u32 by 32
1 messages · Page 1 of 1 (latest)
Shifting a u32 by 32 is just clearing it, so x ^ x
yeah I know but I don't want to do add a branch just to check for this condition
cuz CPUs do support shifting by 32 nativaly
I dont' want to do this:
if (shift == 32)
result = 0
else
result = data >> shift;
LLVM will likely be good enough to optimize this out
I'd check compiler explorer first though
can also raise the shiftable value then lower it: x = @intCast(@as(u64, x) >> shift)
isn't this illegal?
why would it be
surely ranged ints will fix this...
I dont think ranged ints should fix this, expanding an integer while bit fiddling should be explicit imo
I just meant x >> n where x: u32 allowing n to be 0-32 rather than 0-31. It comes up more often than I would have expected when I’m doing bit stuff and writing the branch feels really dumb
Consider raising this in the zsf zulip so that Andrew sees it, ultimately he decides.
iirc this is UB in C