[Issue 21041] core.bitop.byteswap(ushort) should used ROL/ROR instead of XCHG
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Jul 12 05:28:04 UTC 2020
https://issues.dlang.org/show_bug.cgi?id=21041
Bruce Carneal <bcarneal11 at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |bcarneal11 at gmail.com
--- Comment #1 from Bruce Carneal <bcarneal11 at gmail.com> ---
I didn't find a 'byteswap' in the core.bitop documentation. There is a bswap
but only for uints and ulongs AFAICT. Regardless, here's a byteswap
implementation for discussion:
auto byteswap(ushort x) { return cast(ushort)(x >> 8 | x << 8); }
For the above code ldc at -O or above generates:
movl %edi, %eax
rolw $8, %ax
retq
With ldc you can also get the above sequence using core.bitop.rol!8 explicitly.
Current dmd -O emits 7 instructions to accomplish the rolw in the code body.
The code emitted by dmd -O for the explicit call to core.bitop.rol is even
worse, which is strange.
So, yes, there's room here for DMD code gen improvement but ldc is right there.
--
More information about the Digitalmars-d-bugs
mailing list