i386 assembler issue?

John Reiser jreiser@BitWagon.com
Thu Apr 27 20:54:00 GMT 2000


OK, I understand the concern about i486 being slower with an implicit shift count of 1.
But when the -Os (optimize for space) flag is specified, then please use the implicit
form for shifts by 1, because it is one byte shorter.  Every byte counts in an embedded
system, or in ROM, etc.

[My use of left shift '<<' in the testcase may not be the best, because "addl %eax,%eax"
is always better than "shll $1,%eax"; all chips i586 and beyond have two adders but
only one shifter, and the shifter can only be used by one operation pipeline, etc.
So subsitute right shift '>>' in the example, or use an operand in memory:
"sall -4(%ebp)" will double a local variable without using a register.]


Alan Modra wrote:
> 
> On Thu, 27 Apr 2000, Jeffrey A Law wrote:
> 
> > I'm not an ia32 guru, but it seems to me that if there's a more
> > efficient way to encode left-shift by 1, then the assembler should
> > use it.
> 
> The smaller opcode is apparently slower on a 486.  Here's the relevant
> code in gas/config/tc-i386.c
> 
> static int
> smallest_imm_type (num)
>      offsetT num;
> {
> #if 0
>   /* This code is disabled because all the Imm1 forms in the opcode table
>      are slower on the i486, and they're the versions with the implicitly
>      specified single-position displacement, which has another syntax if
>      you really want to use that form.  If you really prefer to have the
>      one-byte-shorter Imm1 form despite these problems, re-enable this
>      code.  */
>   if (num == 1)
>     return Imm1 | Imm8 | Imm8S | Imm16 | Imm32;
> #endif
> 
> I checked a pentium manual, and there isn't any difference in speed on
> 586, and I assume that's the case for more recent processors too.  I'm not
> against re-enabling this code, since 486 is getting fairly old, but I'd
> like someone to check that there isn't some pairing problem or other issue
> on newer processors.  cc'd back to gcc-bugs in hope of interesting Ulrich
> or other x86 optimisation gurus :-)
> 
> --
> Linuxcare.  Support for the Revolution.

-- 
John Reiser, voice/fax +1 503 297 3754, jreiser@BitWagon.com


More information about the Gcc-bugs mailing list