views:

89

answers:

3

the question is about when does a 64bit load/store operations are considered to be atomic.

  • if i have a 64bit processor, but i'm using 32bit OS. Will i have 64bit atomicity?
  • if i'm using 64bit OS but running an 32bit application (using WoW64), will i have 64bit atomicity?
+3  A: 

The application must be running on a 64bit OS and in native 64bit mode to gain the advantages of x64, unsurprisingly. If you're running in 32bit mode, either on a 32bit OS (with a 32bit app), you will get 32bit atomicity. If you're running 64bit mode on a 64bit OS on a 64bit CPU, you will get 64bit atomicity. All of the components in the chain (app, OS, CPU) must be running 64bit to get 64bit.

DeadMG
I don't quite understand how the OS could stop the application from using 64-bit access. Is this something specific to x86 architecture? Does it have some specific "32bit mode" that is forced by the operating system? At least the TI 64x series DSP I am currently working with does not have such limitations.
PauliL
The OS can only issue microcode in it's own bit width and can't do virtual memory mapping with a larger address space. It's impossible for a 32bit desktop OS to run a 64bit program. When the x64 CPU detects a 32bit OS, it runs in an emulation mode too, which will act like it's 32bit.
DeadMG
DeadMG: As I understand, enabling long mode does not mean that instructions must be 64 bit from that point on. E.g.: http://wiki.osdev.org/Long_Mode#How_do_I_enable_Long_Mode_.3F I guess that's part of how 32 bit Mac OS X managed to keep the kernel 32 bit while having the ability to run 64 bit applications. I guess CPU's don't detect operating systems - they must be explicitly set up to enter a particular mode.
andras
This does in fact seems to be confirmed by Wikipedia and others, e.g.: http://communities.vmware.com/message/956139#956139 and http://superuser.com/questions/100780/is-it-possible-to-run-64bit-applications-on-a-32bit-operating-system-if-the-hard
andras
+2  A: 

It is only the 32/64 "bitness" of the application that matters - i.e. that your 64 bit loads/stores are atomic at the assembly level.
You need a 64 bit application to get that for "free".*
For the 64 bit application you need a 64 bit CPU and an OS that can execute it.
The OS can be anything, as long as it can start a 64 bit process on a 64 bit CPU.

if i have a 64bit processor, but i'm using 32bit OS. Will i have 64bit atomicity?

32 bit Windows, Linux: You simply cannot run 64 bit applications on 32 bit Windows or Linux, even on a 64 bit CPU.
32 bit Mac OS X: If your application is a 64 bit app, then yes.

if i'm using 64bit OS but running an 32bit application (using WoW64), will i have 64bit atomicity?

No. Your loads and stores at the machine code level will still be 32 bit loads and stores if you are running a 32 bit application.

*You can get 64 bit atomic reads/writes on a 32 bit CPU with compiler intrinsics where available and/or direct assembly.

andras
+2  A: 

Not by default! But some SSE instructions under x86 support 64bit and 128bit atomic load/store, of course you must first ensure memory aligment. Look examples:

procedure Move64(var Source, Destination);
//Move 8 bytes atomicly from Source 8-byte aligned to Destination!
asm
  movq  xmm0, qword [Source]
  movq  qword [Destination], xmm0
end;

procedure Move64(newData: pointer; newReference: cardinal; var Destination); overload; 
//Move 8 bytes atomically into 8-byte Destination!
asm
  movd  xmm0, eax
  movd  xmm1, edx
  punpckldq xmm0, xmm1
  movq  qword [Destination], xmm0
end; 

procedure Move128(var Source, Destination);
//Move 16 bytes atomicly from Source to 16-byte aligned to Destination!
asm
  movdqa  xmm0, dqword [Source]
  movdqa  dqword [Destination], xmm0
end;
GJ