Re: Efficiency




"KJH" <k_jh77@xxxxxxxxx> wrote in message
news:1193417360.765130.21700@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Why is it so that nowadays:

mov eax,[esi]
mov [edi],eax

is more efficient than

lodsd
stosd


I think you basically answered this:

... also it seems that modern Pentiums and above really like
their instructions more RISC-like (aka boring instr set).


lods/stos have a number of problems from a compiler perspective. A compiler
has to figure out what registers to use to implement the compiled code. The
compiler wants instructions which are easy to use, fast, and orthogonal.
The compiler wants to maximize the use of the registers and not ignore
registers that it could be using - because not doing so wastes cpu time.
The lods/stos instructions are slow on older cpu's. The mov instructions
are equivalent to or faster, on cpu's which pair instructions, than
lods/stos. The mov instructions can also be reordered to eliminate push/pop
instructions or separated to prevent register stalls. The the mov
instructions are also more orthogonal. The compiler has a choice of many
register combinations with mov instead of just eax, es:edi, or ds:esi. So,
from the compiler perspective, use of lods/stos become special cases. The
compiler might implement these for some compile option such as compile for
size, instead of speed. If an extremely fast xchg instruction had been
implemented, then use of lods/stos might've been common in x86 compilers.


Rod Pemberton

.



Relevant Pages

  • Re: on reduce instruction lenght
    ... "mov eax, ebx" to ... push r1, r2, r3; ... map to all instructions, which will make any complete implementation ... the source download for my compiler does include the complete ...
    (alt.lang.asm)
  • Re: Cost of calling a standard library function
    ... instructions like "REP MOVSD" are simply like "on-chip macros"...that ... RISC-style instruction can execute just as well, ... RISC "MOV" instructions...that's why we're getting the speed ...
    (alt.lang.asm)
  • Re: optimation, a black art?
    ... RISC is no less problematic - the MIPS architecture almost failed ... initially because it depended too much on the compiler for scheduling ... instructions regardless of whether the branch was taken. ... blocks and scheduled execution. ...
    (comp.lang.lisp)
  • Re: interpreter vs. compiled
    ... there is a process that runs product instructions, ... the notion that JIT technology compiles code. ... my C implementation a compiler. ... new machine language for each one. ...
    (comp.lang.python)
  • Re: optimation, a black art?
    ... instructions may be completely subsumed by slower running ones. ... Trace scheduling (also called Basic Block ... To do this the compiler has to estimate where the value lies in the ... permutation generate the actual sequence of instructions following ...
    (comp.lang.lisp)