x86 (or others) internals

All off topic discussions go here. Everything from the funny thing your cat did to your favorite tv shows. Non-programming computer questions are ok too.
Post Reply
User avatar
Zacariaz
Member
Member
Posts: 1069
Joined: Tue May 22, 2007 2:36 pm
Contact:

x86 (or others) internals

Post by Zacariaz »

i have been pondering exactly how the internals of, say an core2 cpu works. Not the hightech stuff, but the simple parts, like fx. multiplying two numbers.

Surely i can figure out severel way of doing this task, but if im not mistaken, the mult instruction is actually very efficient and doesnt use alot of clockcycles, and its here my problem lies.

and example:
we want to multiply (binary numbers for the ease of it)
110101 * 1101

now, the brute force atempt on this would be:
110101+110101+110101+110101+.... 1101-1 times.

Then you can use bitshifting:

(110101*1000)+(110101*100)+(110101)
(110101 << 3)+(110101<< 2)+(110101)

This certainly makes a difference. 4 cycles as oposed to 1100, but this is not as good as what my cpu can perform, or atleast so i think.

Anyhow, i would love to have a discusion regarding this subject and allso a link or two to reasources where you can learn more, as i have been unable to obtain any from google.
This was supposed to be a cool signature...
User avatar
JoeKayzA
Member
Member
Posts: 79
Joined: Wed Aug 24, 2005 11:00 pm
Location: Graz/Austria

Post by JoeKayzA »

I have not yet dissected a core 2 cpu's ALU, but in fact it is entirely possible to do an integer multiplication in a single clock cycle.

In fact it's pretty similar to the bit shifting method you showed, but don't forget that you can do all those tasks (shifting and adding) completely in parallel. Since you know the maximum width of your operands (say, for a 32 bit machine), you'll do this 32 times for any calculation. (shifting by 0, by 1, by 2 and so on, in the same cycle sum up the results).

I'm pretty sure that there are even more efficient ways, but that's what I could make up on my own.
User avatar
Zacariaz
Member
Member
Posts: 1069
Joined: Tue May 22, 2007 2:36 pm
Contact:

Post by Zacariaz »

so basicly it just means a more complex structure the more bit you are working with?

I kinda figured this, but i was not sure weather it was in fact the way it worked.
This was supposed to be a cool signature...
User avatar
JoeKayzA
Member
Member
Posts: 79
Joined: Wed Aug 24, 2005 11:00 pm
Location: Graz/Austria

Post by JoeKayzA »

Zacariaz wrote:so basicly it just means a more complex structure the more bit you are working with?

I kinda figured this, but i was not sure weather it was in fact the way it worked.
I guess this level of complexity is nothing compared to cache management and scheduling logic a modern cpu has to provide. But of course, complexity will always increase with word size while the required cycles should stay the same, it doesn't help much if a 64bit calculation takes 3 times as long as a 32bit one (on the same machine) - in that case you could just as well emulate the 64bit calculation and achieve roughly the same performance.

cheers
Joe
Post Reply