Ferrous Moon
http://www.ferrousmoon.com:80/forums/

Data types: 64-bits or 64-bit?
http://www.ferrousmoon.com:80/forums/viewtopic.php?f=45&t=1888
Page 1 of 1

Author:  eddieringle [Tue Aug 18, 2009 7:40 pm ]
Post subject:  Data types: 64-bits or 64-bit?

Ever since I checked out the wiki page for data types I've wondered about the 64-bits row.
Does it mean for use only on a 64-bit architecture, or that it uses 64-bits of data (and is usable on a 32-bit architecture)?

Author:  Soldier of Light [Tue Aug 18, 2009 10:30 pm ]
Post subject:  Re: Data types: 64-bits or 64-bit?

It uses 64 bits. The thing about a 64 bit architecture is that pointers are longs instead of ints. However, longs can be used on a 32 bit architecture to store a number, but not a pointer.

Author:  Tycho [Thu Aug 20, 2009 4:53 pm ]
Post subject:  Re: Data types: 64-bits or 64-bit?

On GCC, a 64-bit integer can be explicitly used with 'long long', and on MSVC++, you can use '__int64'. Note that 64-bit math in 32-bit code is very slow. For example, let's say you compile this for x86 and x86_64:
Code:
#ifdef _MSC_VER typedef __int64 int64_t; #else typedef long long int64_t; #endif int64_t add64(int64_t x, int64_t y) { return x + y; }
x86_64, with GCC 4.1.2 (-O2 -fno-strict-aliasing -masm=intel -S):
Code:
add64: lea %rax, [%rdi+%rsi] ret
x86, with GCC 4.1.2 (-m32 -O2 -fno-strict-aliasing -masm=intel -S):
Code:
add64: push %ebp mov %ebp, %esp mov %eax, DWORD PTR [%ebp+8] add %eax, DWORD PTR [%ebp+16] mov %edx, DWORD PTR [%ebp+12] adc %edx, DWORD PTR [%ebp+20] leave ret
So on 64-bit, it's literally one add. With 32-bit, it's 3 moves, an add, and an add with carry. Much more work.

Author:  gamers2000 [Sat Aug 22, 2009 7:15 am ]
Post subject:  Re: Data types: 64-bits or 64-bit?

So, looking at it from the surface - all x64 code is compatible with x86 architectures, just slower?

Author:  eddieringle [Sat Aug 22, 2009 8:32 am ]
Post subject:  Re: Data types: 64-bits or 64-bit?

Quote:
So, looking at it from the surface - all x64 code is compatible with x86 architectures, just slower?
I wish that were the other way around, all the stinking assembly tutorials and informational sites deal with x86, and half of the code doesn't even work on x64 for some reason.

Author:  Tycho [Sat Aug 22, 2009 3:54 pm ]
Post subject:  Re: Data types: 64-bits or 64-bit?

No, don't confuse 64-bit integers with 64-bit code. x86_64 (also called x64) uses a different instruction set, adds and removes certain features, etc.

The thing to realize is that you _can_ use 64-bit math in 32-bit code, it just won't perform as well as it would in native 64-bit code.

Page 1 of 1 All times are UTC-05:00
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/