News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Compiler Inefficiencies

Started by Posit, May 18, 2005, 05:36:32 PM

Previous topic - Next topic

Posit

To test whether inline assembly is having an effect, I tried the original versions of the project source files. The compiler generated the exact same assembly instructions for the function in question, with no inline assembly anywhere in the project.

I then tried turning various compiler options on and off. The only one that made a difference was adding /G6, which generates the following slightly shorter code. The redundant instruction is even more noticable.


173:      if (++data[0] != 0)         //no carry, so return
004014B3   mov         eax,dword ptr [esi+8]
004014B6   inc         dword ptr [eax]
004014B8   mov         eax,dword ptr [esi+8]
004014BB   cmp         dword ptr [eax],0
004014BE   jne         ArbInt::operator+++5Fh (0040150f)

hitchhikr

Either you don't know how to use a compiler or your own a crippled version of vc.

Vortex

Result with the Digital Mars compiler:

_TEXT segment
assume CS:_TEXT
_foo:
  mov EAX,4[ESP]
  inc dword ptr [EAX]
  je L15
  push offset FLAT:_DATA
  call near ptr _printf
  add ESP,4
L15:  ret
_TEXT ends

Posit

Quote from: hitchhikr on May 19, 2005, 08:22:01 AM
Either you don't know how to use a compiler or your own a crippled version of vc.

I'm willing to entertain both possibilities.

Jibz

Posit,

I'm getting roughly the same result as you with your code and VC7. Quite strange.

I wonder if it's really due to some optimization for Intel processors as MichaelW suggested .. what is your CPU, Intel or AMD?

GCC (3.4.2) -O2 produced

    mov     edx, DWORD PTR [ebx+8]
    mov     eax, DWORD PTR [edx]
    inc     eax
    mov     DWORD PTR [edx], eax
    test    eax, eax
    jne     L1


which doesn't have the extra read, but the test seems superfluous.

GregL

If you are using Visual C++ Standard Edition, it does not include the optimizing compiler. You can get an optimizing compiler from the VC++ Toolkit 2003.

Related reading material:
http://www.sawtoothdistortion.com/Articles/FreeOptimizingCompiler.html



Posit

The CPU is a Celeron 2.4 GHz.

MichaelW

eschew obfuscation