3 ms·
> if mod 32/64 was specified in C, compilers couldn't optimize to this This reads a bit ambiguously, though the conclusion would be same. If C specification h
by lifthrasiir 3y ago
> if mod 32/64 was specified in C, compilers couldn't optimize to this
This reads a bit ambiguously, though the conclusion would be same.
If C specification had that requirement, yeah, they have to do mod 32/64 every time integers with unknown bounds are used for `b`. But then Intel should have noticed this first and define LZHI to use mod 32/64 according to the operand, or make two versions of LZHI.
If C code had that requirement, for example, by always using `a & ((1 << (b & 31)) - 1)` to avoid an UB, compilers indeed would not be able to optimize it into a single BZHI. But they can use AND+BZHI, and I think BZHI has only a half of throughput than AND in almost all supported processors, so an excess AND probably can't do much harm.
- dzaima 3y agoTrue, Intel could've been influenced if there was an expectation on the behavior of shifts. But I doubt they'd have made two versions, and we'd just be stuck with the less useful mod 32/64 one.