Page 1 of 1

could two lea instructions be executed in parallel

Posted: Wed Dec 18, 2013 6:53 am
by blackoil

Code: Select all

lea esi , [ eax + ecx * 4]
lea edi , [ edx + ebx * 4]

Re: could two lea instructions be executed in parallel

Posted: Wed Dec 18, 2013 7:02 am
by Combuster
What if all computers on the world had to wait for each others LEA instructions to complete? :wink:

Re: could two lea instructions be executed in parallel

Posted: Wed Dec 18, 2013 11:07 am
by Brendan
Hi,
blackoil wrote:

Code: Select all

lea esi , [ eax + ecx * 4]
lea edi , [ edx + ebx * 4]
Yes, in theory (depending on which CPU) it's possible for multiple LEA instructions that don't depend on each other to be "in fight" at the same time on the same CPU, and (in theory) they may even pass through the stages of that CPU in step (e.g. both being started in the same cycle and both being retired in the same cycle).

Of course it depends a lot on which CPU - it certainly can't happen with an old 8086. I'm not too sure if it will happen with the latest "Sandy Bridge" or "Haswell" CPUs or not (for both these CPUs there's multiple ALUs where 2 of them do LEA, but one ALU does "normal LEA" and the other "fast LEA", so while 2 LEAs could happen in parallel one would finish faster and be retired sooner).


Cheers,

Brendan

Re: could two lea instructions be executed in parallel

Posted: Thu Dec 19, 2013 8:43 am
by blackoil
I tried two lea instructions. the ticks seem to be the same, no matter one or two.

Code: Select all

extern UINT GetTickCount@0();
void	main()
{
	UINT	b,e;

	b = GetTickCount@0();

	for(i=0;i<100000000;i+=1)
		{
		#asm "lea esi,[ eax + ecx ]"
		#asm "lea edi,[ edx + ebx ]"
		}

	e = GetTickCount@0();

	printf("%u ticks",e-b);
}

Re: could two lea instructions be executed in parallel

Posted: Thu Dec 19, 2013 9:41 am
by Combuster
Playing the dumb compiler says: (and the way you're doing imports says the compiler is dumb)

Code: Select all

mov [ebp+4], 0
.loopstart:
mov eax, [ebp+4]
cmp eax, 100000000
jae .loopend
push esi
push edi
push ebx
lea esi, [eax + ecx]
lea edi, [edx + ebx]
pop ebx
pop edi
pop esi
mov eax, [ebp+4]
inc eax
mov [ebp+4], eax
jmp .loopstart
You'd be looking at a difference of 1/15th of the time if everything took exactly one cycle, but that's of it's own a shabby assumption to go on. Plus Windows' GetTickCount is pretty imprecise.

Re: could two lea instructions be executed in parallel

Posted: Thu Dec 19, 2013 7:03 pm
by Brendan
Hi,
Combuster wrote:Playing the dumb compiler says: (and the way you're doing imports says the compiler is dumb)
Surely if the compiler was slightly smart, it'd optimise it down to a single "printf("%u ticks",GetTickCount@0()-GetTickCount@0());" line. ;)


Cheers,

Brendan

Re: could two lea instructions be executed in parallel

Posted: Thu Dec 19, 2013 8:39 pm
by blackoil
I do more tests for 3,4 lea instructions.
It shows two lea instructions could be executed in parallel.

1,2 lea instructions occupy same cycles.
3,4 lea instructions occupy same cycles, too.

I don't need very precise timing, just to guess how many lea instructions could be executed in parallel.