Re: InterlockedExchange And Memory Alignment

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



What's to be confused about? There is a Windows API that has an alignment
requirement and a set of instructions for some Intel CPUs that can execute
on arbitrary unaligned data?



The fact that on certain platforms, the API uses one of these instructions
is useful to know, and can help to code better programs, but should not
cause any confusion!




"Patogenx" <patogenx@xxxxxxxxx> wrote in message
news:6631acfa-2711-4587-8ad7-dbaf8a4095ae@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

I am confused that Microsoft says memory alignment is required for
InterlockedExchange however, Intel documentation says that memory
alignment is not required for LOCK. Am i missing something, or
whatever the problem?
Thanks

from Microsoft MSDN Library

Platform SDK: DLLs, Processes, and Threads InterlockedExchange

The variable pointed to by the Target parameter must be aligned on a
32-bit boundary; otherwise, this function will behave unpredictably on
multiprocessor x86 systems and any non-x86 systems.
from Intel Software Developer?s Manual;

LOCK instruction Causes the processor?s LOCK# signal to be asserted
during execution of the accompanying instruction (turns the
instruction into an atomic instruction). In a multiprocessor
environment, the LOCK# signal insures that the processor has exclusive
use of any shared memory while the signal is asserted.
The integrity of the LOCK prefix is not affected by the alignment of
the memory field. Memory locking is observed for arbitrarily
misaligned fields.
Memory Ordering in P6 and More Recent Processor Families
Locked instructions have a total order.
Software Controlled Bus Locking
The integrity of a bus lock is not affected by the alignment of the
memory field. The LOCK semantics are followed for as many bus cycles
as necessary to update the entire operand. However, it is recommend
that locked accesses be aligned on their natural boundaries for better
system performance: ?Any boundary for an 8-bit access (locked or
otherwise). ?16-bit boundary for locked word accesses. ?32-bit
boundary for locked doubleword accesses. ?64-bit boundary for locked
quadword accesses.


.



Relevant Pages

  • Re: InterlockedExchange And Memory Alignment
    ... Intel documentation says that memory ... alignment is not required for LOCK. ... LOCK instruction Causes the processor?s LOCK# signal to be asserted ... that locked accesses be aligned on their natural boundaries for better ...
    (microsoft.public.win32.programmer.kernel)
  • InterlockedExchange And Memory Alignment
    ... Intel documentation says that memory ... alignment is not required for LOCK. ... during execution of the accompanying instruction (turns the ...
    (microsoft.public.win32.programmer.kernel)
  • InterlockedExchange and Memory Alignment
    ... Intel documentation says that memory ... alignment is not required for LOCK. ... during execution of the accompanying instruction (turns the ...
    (comp.programming.threads)
  • Re: atomic operation problem
    ... I can not fully understand how to use this 'lock' field. ... it for the whole duration of the instruction. ... if the instruction in question involves more than one memory access. ... Increment the value. ...
    (comp.arch.embedded)
  • Re: InterlockedExchange And Memory Alignment
    ... The InterlockedExchange operations are not directly related to the "lock" thing. ... They do require alignment. ... Intel documentation says that memory ... that locked accesses be aligned on their natural boundaries for better ...
    (microsoft.public.win32.programmer.kernel)