bool SwapBytes32(char *,unsigned __int64) PROC ; SwapBytes32, COMDAT
test dl, 3
je SHORT $LN5@SwapBytes3
xor al, al
ret 0
$LN5@SwapBytes3:
test rdx, rdx
je SHORT $LN3@SwapBytes3
dec rdx
shr rdx, 2
inc rdx
npad 9
$LL4@SwapBytes3:
mov eax, DWORD PTR [rcx]
lea rcx, QWORD PTR [rcx+4]
bswap eax
mov DWORD PTR [rcx-4], eax
sub rdx, 1
jne SHORT $LL4@SwapBytes3
$LN3@SwapBytes3:
mov al, 1
ret 0
I am sure one can do better, but it is just generally fine code.
The current code uses special casing for MSVC, but this code is likely unneeded. It seems to seek to avoid
memcpy
calls. But Microsoft's compiler is smart.Let us consider this example:
With
/O2
, MSVC compiles it down toI am sure one can do better, but it is just generally fine code.