Click to See Complete Forum and Search --> : Weird results...


Alana Radesch
February 1st, 2005, 01:02 PM
I have assembly routine in my code where main loop for function is:

label: mov ecx,[esi+ebx]
adc [edi+ebx],ecx
lea ebx,[ebx+4]
dec eax
jnz label


Timing (with 'rdtsc') showed this loop running at 10,5 cycles per loop.

This is running slower than reference code in C++ (optimized speed) running at 6.6 cycles per loop. This C++ code is 15 instructions per loop (3 times as much as asm loop) ???

My calculations say this asm loop should run at 4.4 cycles per loop. but it is not. it is 10.5.

If I change ADC to ADD, loop indeed takes 4.4cycles. Why is ADC so slow ? It should be same speed as ADD no ?

OReubens
February 1st, 2005, 03:19 PM
Well... On P4 and up, ADC is actually one of the instructions you would want to avoid because it is slow (significantly slower than ADD, although it does depend on the code sequence)

Note that with carefull selection the P4 can have 4 instructions executing (practically) concurrently. So with the right kind of instructions in the right order a code sequence that is 4 times as large as the code here (5 instrcutions) could still be just as fast.

The loop seems to indicate you are doing large integer math ? If this is the case, and you need the extra speed (and you obviously have a P4), you might want to go with using MMX/SSE instructions to higher overall throughput.