This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Bit-field struct member sign extension pattern results in redundant


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~


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]