how to disable the multiplication optimization?

Y

Yixin Cao

GCC always avoids multiplication instructions as much as possible, so a *= 10; will be translated into:

leal (%eax, %eax, 4), %eax
add %eax, %eax

I do know that it is due to historic reason, for that old CPU spent 30+ clock cycles to finish a multiplication
instruction. But it is never true now, while 3 clock cycles will suffice, so it brings the side affect of bigger object
files without any gain.
It might do it default for the consideration of compatibility, but my problem is how to disable it, for my code will
never run on a box been made a decade ago.

Yixin Cao
 
I

Ian Collins

Yixin said:
GCC always avoids multiplication instructions as much as possible, so a
*= 10; will be translated into:

leal (%eax, %eax, 4), %eax
add %eax, %eax
That's a compiler specific feature, bast to ask on gcc list.
 
K

Keith Thompson

Yixin Cao said:
GCC always avoids multiplication instructions as much as possible,
so a *= 10; will be translated into: [snip]
It might do it default for the consideration of compatibility, but my
problem is how to disable it, for my code will never run on a box been
made a decade ago.

If reading the gcc documentation doesn't answer this, try gnu.gcc.help.
 
Y

Yixin Cao

Following is what Intel C Compiler generates:
9: 8d 0c 89 lea (%ecx,%ecx,4),%ecx
c: 8d 04 48 lea (%eax,%ecx,2),%eax

So, it might not a be the gcc only setting.

Anyway, thanks, I have sent this to gnu.gcc.help to try to find an answer.


Keith said:
Yixin Cao said:
GCC always avoids multiplication instructions as much as possible,
so a *= 10; will be translated into: [snip]
It might do it default for the consideration of compatibility, but my
problem is how to disable it, for my code will never run on a box been
made a decade ago.

If reading the gcc documentation doesn't answer this, try gnu.gcc.help.
 
C

christian.bau

GCC always avoids multiplication instructions as much as possible, so a *= 10; will be translated into:

leal (%eax, %eax, 4), %eax
add %eax, %eax

I do know that it is due to historic reason, for that old CPU spent 30+ clock cycles to finish a multiplication
instruction. But it is never true now, while 3 clock cycles will suffice, so it brings the side affect of bigger object
files without any gain.
It might do it default for the consideration of compatibility, but my problem is how to disable it, for my code will
never run on a box been made a decade ago.

Yixin Cao

1. It's still likely to be faster.
2. Did you actually check how many bytes of code are generated in each
case?
3. What about running on the box made a decade from now?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top