Re: C/C++ Compiler's Optimization Failed

From: Bryan Parkoff (bryan.nospam.parkoff_at_nospam.com)
Date: 02/21/04


Date: Sat, 21 Feb 2004 05:43:13 +0000 (UTC)


    I agree with Jack. I should always depend on Intel VTune while I write
in assembly. It can be very difficult to write in assembly without using
C/C++'s help.
    First, I write C/C++ code before I can convert C/C++ code into assembly
code. I remove some unnecessary instructions such as AND by reducing CPU's
clock. Use Intel VTune to test assembly code for maximum optimization and
performance. I have done many times while I am studying my own project in
assembly language.

-- 
Bryan Parkoff
"Jack Klein" <jackklein@spamcop.net> wrote in message
news:fqmd30h5a1aaet528eti7gqidrbhnu8ej4@4ax.com...
> On Sat, 21 Feb 2004 01:18:24 +0000 (UTC), "Bryan Parkoff"
> <bryan.nospam.parkoff@nospam.com> wrote in comp.lang.asm.x86:
>
> >     I wrote C++ code below.
> >
> > VOID Set_Red(U_BYTE _Red, U_BYTE _Green, U_BYTE _Blue)
> > {
> >     Red = (0x00 << 24) | (_Red << 16) | (_Green << 8) | _Blue;
> > }
>
> Of course the code you wrote happens to be illegal C++, but I don't
> suppose you care about that.
>
> >     I used C/C++ Compiler's Optimization.  The machine language shows
below.
> >
> > mov  ecx, DWORD PTR [esp+0ch]
> > xor  eax, eax
> > mov  ah, BYTE PTR [esp+04h]
> > and  ecx, 0ffh
> > mov  al, BYTE PTR [esp+08h]
> > shl  eax, 08h
> > or  eax, ecx
> > mov  DWORD PTR [0409500h], eax
> > ret
> >
> >     I am shocked that C/C++ Compiler did not tune optimization very well
> > because partial register DOES EXIST!!
>
> I am shocked that all you have ever done since starting to post to
> usenet is complain.  Intel's processors aren't good enough, the C and
> C++ languages weren't designed to meet your idea of what they should
> be, nobody's compiler is good enough for you.
>
> If you don't like the code generated by that compiler, try a different
> one.  If you don't like the code generated by any compiler, write your
> own or do without.
>
> If you don't like Intel's processors, develop your own.
>
> And why are you complaining in an assembly language newsgroup about
> the code generated by a compiler?  C and C++ compilers are really
> off-topic here, except perhaps for how to use their inline assembly
> support or how to link their code with assembly language code.
> Whatever C and C++ compilers do for C and C++ code is not an issue
> that belongs here.
>
> >     My correction code should be below.
> >
> > mov  eax, DWORD PTR [esp+04h]
> > shl  eax, 08h
> > or  eax, DWORD PTR [esp+08h]
> > shl  eax, 08h
> > or  eax, DWORD PTR [esp+0ch]
> > ret
> >
> >     I am very concerned that all C/C++ Compiler does not do good job to
tune
> > optimization properly.  I used Intel VTune to detect and discover many
hot
> > spots that they do include partial register.  I did test on both Pentium
III
> > and Pentium IV.  They do apply partial register that should be avoided.
>
> Frankly, that is not the job or a C or C++ compiler.
>
> >     What is your recommendation?
>
> My recommendation is that you quit complaining about everything.
> Write your own compiler, then you can blame yourself when it misses
> something.
>
> >     1. Write C/C++ code in DEBUG version.
> >     2. Test C/C++ code on any computer to see if it works with NO BUG
> > (Optimization is not important YET!!)
> >     3. Change from DEBUG version to RELEASE version.
> >     4. Test C/C++ code on any computer to see if it works with NO BUG
> > (Optimization is ENABLED!!)
> >     5. Use VTune to discover hot spots including partial register.
> >     6. Convert C/C++ code into machine language in your own hands
manually.
> >     7. Link your existing C/C++ code and Machine code together.
> >     8. Test mixed C/C++ code and Machine code on any computer to see if
it
> > works with NO BUG.
> >     9. After all tests are done, it will be big IMPACT for improved
> > optimization.
>
> Improved optimization of WHAT???
>
> What application have you written that performed correctly and only
> failed to meet its requirements because it executed too slowly?
>
> Many assembly language programmers are interested in wringing the
> maximum performance out of a processor, that is usually the reason
> they program in assembly.
>
> If C and C++ compilers do not do a good enough job for you, then don't
> use them.  Stop complaining about compilers unless you are going to
> write your own.
>
> -- 
> Jack Klein
> Home: http://JK-Technology.Com
> FAQs for
> comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
> comp.lang.c++ http://www.parashift.com/c++-faq-lite/
> alt.comp.lang.learn.c-c++
> http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
>


Relevant Pages

  • Re: compiler generated output
    ... > compiler to generate code which only uses 386 instruction). ... > Thus, while replacing mov/and with movzx, the jump is still there. ... mov eax, ... Software Optimization Guide for ...
    (comp.lang.asm.x86)
  • Re: C/C++ Compilers Optimization Failed
    ... > xor eax, eax ... If you don't like the code generated by that compiler, ... And why are you complaining in an assembly language newsgroup about ... > (Optimization is not important YET!!) ...
    (comp.lang.asm.x86)
  • Re: Compiler inserts redundant comparison against zero
    ... optimization, both for speed and size", deals ... test eax, eax; value of variable x already in eax ... The economical code executes at label: ... This is what comes of the compiler following the rules, while the human sees the possibilities! ...
    (comp.lang.asm.x86)
  • Re: Compiler inserts redundant comparison against zero
    ... > So I was surprised to find out how the C compiler ... > optimization, both for speed and size", deals ... > test eax, eax; value of variable x already in eax ... > cmp eax, 0Eh ...
    (comp.lang.asm.x86)
  • Re: Brian Kernighan, maybe Im not worthy, maybe Im scum
    ... what experienced programmers do, ... optimization, ... Thugs" ad nauseum fits that a lot more closely than discussing compiler ... be modified outside a loop, and guessing ...
    (comp.programming)