On 08/17/2017 03:29 PM, Michael Clark wrote:
> hand coded x86 asm (no worse because the sar depends on the lea)
> 
>       sx5(int):
>         shl edi, 27
>         sar edi, 27
>         movsx eax, dl

Typo in the register, but I know what you mean.  More interestingly, edi
already has the sign-extended value, so "mov eax, edi" sufficies (saving one
byte or perhaps allowing better register allocation).

That said, if anyone is tweaking x86-64 patterns on this, consider

sx5(int):
        rorx    eax, edi, 5
        sar     eax, 27

where the (newish) bmi2 rorx instruction allows the data to be moved into place
while rotating, avoiding the extra move entirely.


r~

Reply via email to