could two lea instructions be executed in parallel

Programming, for all ages and all languages.
Post Reply
blackoil
Member
Member
Posts: 146
Joined: Mon Feb 12, 2007 4:45 am

could two lea instructions be executed in parallel

Post by blackoil »

Code: Select all

lea esi , [ eax + ecx * 4]
lea edi , [ edx + ebx * 4]
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: could two lea instructions be executed in parallel

Post by Combuster »

What if all computers on the world had to wait for each others LEA instructions to complete? :wink:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: could two lea instructions be executed in parallel

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
blackoil
Member
Member
Posts: 146
Joined: Mon Feb 12, 2007 4:45 am

Re: could two lea instructions be executed in parallel

Post 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);
}
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: could two lea instructions be executed in parallel

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: could two lea instructions be executed in parallel

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
blackoil
Member
Member
Posts: 146
Joined: Mon Feb 12, 2007 4:45 am

Re: could two lea instructions be executed in parallel

Post 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.
Post Reply