public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Length-Changing Prefixes problem with the x86 Backend
       [not found] <9b38093e0806251411if2c318cg168839f36d03743d@mail.gmail.com>
@ 2008-06-25 21:17 ` Nadav
  2008-06-26  5:49 ` Uros Bizjak
  1 sibling, 0 replies; 3+ messages in thread
From: Nadav @ 2008-06-25 21:17 UTC (permalink / raw)
  To: gcc

Hello,

I came across a problem with the x86 backend of gcc (3.3 - 4.1).  When
I compile code which access a lookup table of size 65536, gcc
generates code which uses 16bit opcodes.

The intel architecture optimization guide warns that 16bit opcodes
should be avoided whenever possible due to Length-Changing Prefixes
(LCP).  The recommendation is: ""If imm16 is needed, load equivalent
imm32 into a register and use the word value in the register instead.
""

I would expect gcc to use a 32bits register and mask it, if needed.
Even when I use 32bits registers and mask them ( & 0xFFFF), gcc
detects correctly that my variable is effectively only 16bits and it
generates 16bits code.
I modified the generated assembly to use 32bit registers and it ran much faster.

--
Cheers,
Nadav

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Length-Changing Prefixes problem with the x86 Backend
       [not found] <9b38093e0806251411if2c318cg168839f36d03743d@mail.gmail.com>
  2008-06-25 21:17 ` Length-Changing Prefixes problem with the x86 Backend Nadav
@ 2008-06-26  5:49 ` Uros Bizjak
  1 sibling, 0 replies; 3+ messages in thread
From: Uros Bizjak @ 2008-06-26  5:49 UTC (permalink / raw)
  To: Nadav; +Cc: gcc

On Wed, Jun 25, 2008 at 11:11 PM, Nadav <nadav256@gmail.com> wrote:

> I came across a problem with the x86 backend of gcc (3.3 - 4.1).  When I
> compile code which access a lookup table of size 65536, gcc generates code
> which uses 16bit opcodes.
>
> The intel architecture optimization guide warns that 16bit opcodes should be
> avoided whenever possible due to Length-Changing Prefixes (LCP).  The
> recommendation is: ""If imm16 is needed, load equivalent imm32 into a
> register and use the word value in the register instead. ""
>
> I would expect gcc to use a 32bits register and mask it, if needed.
> Even when I use 32bits registers and mask them ( & 0xFFFF), gcc detects
> correctly that my variable is effectively only 16bits and it generates
> 16bits code.
> I modified the generated assembly to use 32bit registers and it ran much
> faster.

Please file a bugreport following instructions at
http://gcc.gnu.org/bugs.html. Please also add a runtime test that can
be used to analyze the problem.

Thanks,
Uros.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Length-Changing Prefixes problem with the x86 Backend
@ 2008-07-25 13:57 Agner Fog
  0 siblings, 0 replies; 3+ messages in thread
From: Agner Fog @ 2008-07-25 13:57 UTC (permalink / raw)
  To: Uros Bizjak, nadav256, gcc

On Thu, 26 Jun 2008 Uros wrote:

 >Please also add a runtime test that can be used to analyze the problem.

I am a temporary guest on the gcc mailing list and I haven't seen your 
mail before. In case your problem hasn't been solved yet, I can inform 
you that I have a disassembler which puts comments into the disassembly 
file in case of length-changing prefixes and other sub-optimal or 
illegal instruction codes. Just compile with -c to get an object file 
and run it on the disassembler:
objconv -fasm yourfile.o yourfile.asm

It supports all x86 instruction sets up to SSE4.2 and SSE5 (but not AVX 
and FMA yet). It may be useful for testing other compiler features as 
well, such as support for new instruction sets.

Get it from www.agner.org/optimize/objconv.zip
This is a cross-platform multi-purpose tool. The assembly output is in 
MASM format, not AT&T. Use .intel_syntax noprefix in case you want to 
assemble the disassembly on GAS.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-07-25 13:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <9b38093e0806251411if2c318cg168839f36d03743d@mail.gmail.com>
2008-06-25 21:17 ` Length-Changing Prefixes problem with the x86 Backend Nadav
2008-06-26  5:49 ` Uros Bizjak
2008-07-25 13:57 Agner Fog

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).