> as long as you do not cross the cache line, MOV is
guaranteed to be atomic (at least on P6 family and above) .
It is a bit off-topic, but…
A while ago I made some research on read atomicity and did find
that Intel makes this promise ( from
http://download.intel.com/design/PentiumII/manuals/24319202.pdf):
7.1.1. Guaranteed Atomic Operations
The Intel386™, Intel486™, Pentium®, and P6 family processors guarantee that the following
basic memory operations will always be carried out atomically:
• Reading or writing a byte.
• Reading or writing a word aligned on a 16-bit boundary.
• Reading or writing a doubleword aligned on a 32-bit boundary.
The P6 family processors guarantee that the following additional memory operations will
always be carried out atomically:
• Reading or writing a quadword aligned on a 64-bit boundary. (This operation is also
guaranteed on the Pentium® processor.)
• 16-bit accesses to uncached memory locations that fit within a 32-bit data bus.
• 16-, 32-, and 64-bit accesses to cached memory that fit within a 32-Byte cache line.
Accesses to cacheable memory that are split across bus widths, cache lines, and page boundaries
are not guaranteed to be atomic by the Intel486™, Pentium®, or P6 family processors. The P6
family processors provide bus control signals that permit external memory subsystems to make
split accesses atomic; however, nonaligned data accesses will seriously impact the performance
of the processor and should be avoided where possible.
But I could no and can not find anything similar about, let’s say, AMD.
Can anyone point to an official document (not a newsgroup and the like,
but vendor’s manual or guide) about read/write/modify atomicity for any of
the AMD processors?
I searched all PDFs I could find at
http://www.amd.com/us-en/Processors/DevelopWithAMD/0,,30_2252_11467_11513,00.html
for “atomic” but found only what relates to LOCK prefix (and this is NOT what I was looking for).
-------------- Original message --------------
From: Steve Dispensa
>
> On Jul 20, 2007, at 7:35 PM, xxxxx@hotmail.com wrote:
>
> > Thomas,
> >
> >> Examine the “Interlocked” family of functions.
> >
> > Actually, as long as the OP does not cross the cache line, he does
> > not even need interlocked functions in order to insure atomicity of
> > memory access - as long as you do not cross the cache line, MOV is
> > guaranteed to be atomic (at least on P6 family and above) .
> > Furthermore, as long as he relies upon the natural data alignement,
> > his memory accesses are guaranteed to be atomic even on older
> > processors. This is not a problem at all. The real problem here is
> > that the OP just does not seem to see any difference between
> > atomicity of memory access and synchronization, and this is,
> > apparently, going to put him into a trouble - imagine if his
> > variables are inter-dependent…
>
> While it may be true that aligned memory accesses are atomic, they
> don’t enforce memory barriers, and they may need volatile qualifiers.
> It’s very hard to do this stuff right without using the OS’s built-in
> synch/interlock functions, which do make ordering guarantees.
>
> Plus, while the OP may indeed be an expert on (current) computer
> platforms, do you expect every maintenance coder to be that good too?
> Real world experience says they won’t always be. And what if the next
> programmer decides to compile it for IA-64 or architecture N+1, N
> +2, …? Will they make exactly the same memory read/write ordering
> guarantees that x86 does? Even x86 has a history of inconsistency on
> this point.
>
> So, if you’re an absolute expert writing for a narrowly defined
> platform, your comments are correct; most people/projects don’t fall
> into that category.
>
> http://blogs.msdn.com/oldnewthing/archive/2004/05/28/143769.aspx
> http://64.233.169.104/search?q=cache:tPN1977REOsJ:www.aristeia.com/
> Papers/DDJ_Jul_Aug_2004_revised.pdf+scott+meyers+volatile
> +barrier&hl=en&ct=clnk&cd=1&gl=us&client=safari
>
> -Steve
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer