Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
noob: 32 bit vs 64 bit?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Gentoo on AMD64
View previous topic :: View next topic  
Author Message
thinking
n00b
n00b


Joined: 22 May 2005
Posts: 46

PostPosted: Mon Sep 12, 2005 10:33 am    Post subject: noob: 32 bit vs 64 bit? Reply with quote

hiho@ll

i have a very noob question about 32bit vs. 64bit architecture
it's not really a gentoo but i already posted somewhere else, but i didn't get the answer i was searching for ;-) (i know maybe the wrong question)
http://www.linuxquestions.org/questions/showthread.php?s=&threadid=354948&highlight=32bit+64bit

for those who don't want read the thread above, the same thread here:
shortly i'll explain what i know and think about the topic:
a cpu has registers to work with
on 32bit these registers are a maximum of 32bit in size
on 64bit they are 64bit in size
so they can store larger values which means they can mostly (for example) be faster or use better hardware (larger harddisk, more ram)

why i ask the question:
if you compile a prog for example a C prog which uses integer
the int value on a 32bit architecture will be 32bit in size on 64bit it's 64bit
ok
now what if i write a prog where i know i don't need to store greater values than 32bit

if i compile the prog on a 32bit architecture, will it run on 64bit?
if not, why? i think the cpu registers are just bigger, why shouldn't work 32bit code on a 64 architecture[/url]?

maybe it's simple and my direction of thinking is right
but i don't think so, that's why i'm asking ;-)

thx@ll
Back to top
View user's profile Send private message
alistair
Retired Dev
Retired Dev


Joined: 15 Jul 2005
Posts: 869

PostPosted: Mon Sep 12, 2005 10:46 am    Post subject: Reply with quote

32bit programs will run on amd64 (with bios set to allow 32bit mode). For exampe u can quite happily install gentoo-x86 on a 64 bit machine. But u should note that u can't link a 32bit app to a 64 bit library or vise versa.

4bit(i think) flags determine whether the cpu is in 32 or 64 bit mode, Ill let more informed others go into the details of this.
Back to top
View user's profile Send private message
thinking
n00b
n00b


Joined: 22 May 2005
Posts: 46

PostPosted: Mon Sep 12, 2005 10:52 am    Post subject: Reply with quote

hmm
does this mean if the cpu is in 64bit mode you can't do 32bit calculations like 32bit cpu?
i know i can do the same calculation because 64bit is bigger! but the cpu in 64bit mode has to read more altough i only want 32bit calculations, not?

?? why i can't link 32bit code to 64bit? (i think that's exactly my problem of understanding the topic)
well, i'm thinking to much as a software developer ;-)
Back to top
View user's profile Send private message
alistair
Retired Dev
Retired Dev


Joined: 15 Jul 2005
Posts: 869

PostPosted: Mon Sep 12, 2005 11:20 am    Post subject: Reply with quote

if your in 64 mode then u can't execute 32 instructions. The kernel switchs operating modes for u though so u dont need to worry. (dont ask me how). U can happily execute 64 and 32 bit programs concurrently.

As for the linking. just imagine the mess that would be caused if some 64bit code passed a long (ie 64bit's) to 32bit code.

sadly i can't find a very interesting doc on the 64bit kernel
Back to top
View user's profile Send private message
thinking
n00b
n00b


Joined: 22 May 2005
Posts: 46

PostPosted: Mon Sep 12, 2005 11:59 am    Post subject: Reply with quote

hmm
thx
i think i understand the problem now ;-)
Back to top
View user's profile Send private message
andrew_j_w
Guru
Guru


Joined: 28 Jun 2003
Posts: 534
Location: York, UK

PostPosted: Mon Sep 12, 2005 6:29 pm    Post subject: Reply with quote

One important point to remember is that for AMD64 int is still only 32 bits, it's only long that is 64 bit. The biggest problems comes when programmers try to cast a pointer (64 bits) into an int (32 bits).

HTH,
Andrew
Back to top
View user's profile Send private message
babo
Guru
Guru


Joined: 10 Aug 2004
Posts: 477
Location: Ljubljana

PostPosted: Mon Sep 12, 2005 7:12 pm    Post subject: Reply with quote

so basicly if I understand correctly in order to make a program that runs on x86 to run on amd64 you need to change int's to long's?
PS: I am pretty dumb about programing, but am still interested :)
Back to top
View user's profile Send private message
scharkalvin
Guru
Guru


Joined: 31 Jan 2004
Posts: 331
Location: south florida

PostPosted: Tue Sep 13, 2005 12:43 pm    Post subject: Reply with quote

Just as the 386 family (that's 386,586,pentium,PII,PIII.P4,athlon,etc) have a real-8086 emulation mode which
enables you to run DOS programs inside of a 32 bit OS (such as windows-NT) the AMD64 cpu's have an
emulation mode that enables you to run 32 bit programs inside of a 64bit OS. However the buck stops there.
You CAN'T run the real-86 emulation mode inside the 32 bit emulation mode, or inside the 64 bit mode.
This means that the DOS-emu package will NOT run with a 64bit OS. I don't know how many people need
to run DOS-emu, but if you do you CAN'T run it on an AMD-64 system UNLESS you run it on a 32 bit
kernel. So in this case you will need a dual boot system, chroot is NOT enough!
Back to top
View user's profile Send private message
Biased turkey
n00b
n00b


Joined: 14 Jul 2005
Posts: 36
Location: Montreal, Canada

PostPosted: Tue Sep 13, 2005 7:59 pm    Post subject: Reply with quote

alistair wrote:
32bit programs will run on amd64 (with bios set to allow 32bit mode). For exampe u can quite happily install gentoo-x86 on a 64 bit machine. But u should note that u can't link a 32bit app to a 64 bit library or vise versa.

4bit(i think) flags determine whether the cpu is in 32 or 64 bit mode, Ill let more informed others go into the details of this.


I don't remember seeing anything in my BIOS setting to specifically allow 32 or 64 bits mode ( I have an Nforce4 mobo ) Are you sure about that ?
Back to top
View user's profile Send private message
stonie
Tux's lil' helper
Tux's lil' helper


Joined: 03 Jun 2003
Posts: 87
Location: S'Minga, Halleluja

PostPosted: Wed Sep 14, 2005 7:22 pm    Post subject: Reply with quote

Quote:

I don't remember seeing anything in my BIOS setting to specifically allow 32 or 64 bits mode ( I have an Nforce4 mobo ) Are you sure about that ?


I have read this pretty often now. I' ve been working with nforce 3 + 4 and never seen such an option in the bios menu. Guess the CPU does 32 bit code execution by default......... :roll:
_________________
How could I know what I think before I realized what I said???

http://valid.x86-secret.com/show_oc?id=63327
Back to top
View user's profile Send private message
alistair
Retired Dev
Retired Dev


Joined: 15 Jul 2005
Posts: 869

PostPosted: Wed Sep 14, 2005 10:03 pm    Post subject: Reply with quote

woops... :oops: why did i think that? maybe i should play with my bios a little more frequently
Back to top
View user's profile Send private message
Nemonux
n00b
n00b


Joined: 27 Nov 2004
Posts: 19
Location: Aachen, Germany

PostPosted: Thu Sep 15, 2005 2:56 pm    Post subject: Reply with quote

@scharkalvin: Interesting what you say about 8086 emulation. I'll get an AMD64 processor soon and until now I sometimes use dos-box to play some old games. The dualboot workaround even means that I have to provide all needed applications as 32bit binaries, is that right? So I would need a secound root file tree, just like the chroot stuff? I wanted to try to avoid that. Looks like the old gamse have to stay on my notebook.
_________________
A rainy day in May...
Back to top
View user's profile Send private message
Matt6543
n00b
n00b


Joined: 20 Sep 2009
Posts: 1

PostPosted: Sun Sep 20, 2009 12:36 am    Post subject: Reply with quote

I know that this thread is over and done, but I feel I have to comment on the main question......
32bit can not run on 64bit. I'll do a comparision with 16bit and 32bit on a x86 (Intel/AMD) code directly.

If I use this (pointless) code:
mov ax , 0x123
add ax , 0x321
mov bx , ax
(so it makes register ax and bx = 444)

Compiled in 16 bit code is:
B8 23 01 05 21 03 89 C3

If its run in 32 bit mode - the processor will think the code is this...
B8 23 01 05 21 03 89 C3
mov eax , 0x21050123
add [ebx+edi] , ecx (or some thing like that)
There for it did not even finish the first operation correctly and the second is almost rubbish



Matt
Back to top
View user's profile Send private message
meteozwh
n00b
n00b


Joined: 27 May 2003
Posts: 38

PostPosted: Sun Sep 20, 2009 11:17 pm    Post subject: Reply with quote

That's right. And another difference that I found no one ever mentioned here is the amd64 ABI(Application Binary Interface) is totally different from x86 ABI.

The amd64 arch have more registers than x86 and as from AMD64, functions use register to pass the parameters while in the x86 mode, functions use the stack to pass the parameters. That's a very important issue to concern.
Matt6543 wrote:
I know that this thread is over and done, but I feel I have to comment on the main question......
32bit can not run on 64bit. I'll do a comparision with 16bit and 32bit on a x86 (Intel/AMD) code directly.

If I use this (pointless) code:
mov ax , 0x123
add ax , 0x321
mov bx , ax
(so it makes register ax and bx = 444)

Compiled in 16 bit code is:
B8 23 01 05 21 03 89 C3

If its run in 32 bit mode - the processor will think the code is this...
B8 23 01 05 21 03 89 C3
mov eax , 0x21050123
add [ebx+edi] , ecx (or some thing like that)
There for it did not even finish the first operation correctly and the second is almost rubbish



Matt
Back to top
View user's profile Send private message
Akkara
Administrator
Administrator


Joined: 28 Mar 2006
Posts: 5128
Location: &akkara

PostPosted: Sun Sep 20, 2009 11:53 pm    Post subject: Reply with quote

babo wrote:
so basicly if I understand correctly in order to make a program that runs on x86 to run on amd64 you need to change int's to long's?
PS: I am pretty dumb about programing, but am still interested :)

Not usually. If it is a well-designed program, all you need to do is recompile it on a amd64 system (or, cross-compile it on any system but using a amd64-targeted compiler). The only times the size of the integers vs. pointers become a problem, is when someone tried to be clever and stuffed a pointer into an integer (or vice versa). That kind of program will break unless pointers and integers are the same size.

Properties of 32-bit:
  • Pointers are 32 bits
  • This means maximum addressable memory is 4GB (and usually less is available because the kernel reserves some).
  • Ints are 32 bits
  • If you need a 64-bit integer, they can be had by declaring them "long long" (usually).
  • But operating on 64-bit integers takes twice as many instructions. They are implemented internally as two 32-bit integers, operating on the halves, and propagating the carries.
  • Multiplication and division of 64-bit quantities takes even more than twice as many ops.


Properties of 64-bit:
  • Pointers are 64 bits.
  • Maximum addressable memory is <huge>. You'll run into motherboard limits long before you run into the CPU limit.
  • Ints are 32 bits. Even though 64-bits is the natural operand size, 32-bit ints are used to save space in memory since it isn't often one needs very large integers.
  • If you want a 64-bit integer, "long" will usually declare one.
  • Operating on 64-bit integers is just as efficient as operating on 32-bit. So good speed for high-precision arithmetic-heavy applications.
  • The 64-bit pointers take 8 bytes to store compared to 4 bytes in a 32-bit system. Which means a pointer-heavy app will need more memory on a 64-bit system compared to 32-bit.
  • In x86, more registers are available in 64-bit mode (this is in addition to them being longer). More registers = fewer references to memory = tighter code that's less performance-sensitive to fast vs slow memory.
Back to top
View user's profile Send private message
poly_poly-man
Advocate
Advocate


Joined: 06 Dec 2006
Posts: 2477
Location: RIT, NY, US

PostPosted: Mon Sep 21, 2009 12:21 am    Post subject: Reply with quote

If you're programming in c, basically totally ignore how many bits there are... the only difference is made to long and pointers.

for normal use, there's not a really big difference. For normal programming, there's not a really big difference. You only start hitting strangeness while using more than about 1gb ram (starts to slow down on 32-bit - over about 3 or 4 gb, you slow down even more for PAE), or programming in assembly (strange rules about what you can or can't push, etc.)
_________________
iVBORw0KGgoAAAANSUhEUgAAA

avatar: new version of logo - see topic 838248. Potentially still a WiP.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Gentoo on AMD64 All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum