user316819
user316819

Reputation:

atomicity in 32/64 bit

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

Upvotes: 5

Views: 1652

Answers (3)

Andras Vass
Andras Vass

Reputation: 11638

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.

Upvotes: 3

GJ.
GJ.

Reputation: 10937

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;

Upvotes: 3

Puppy
Puppy

Reputation: 146920

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.

Upvotes: 4

Related Questions