__ldarx, __lwarx

Purpose

Load Doubleword and Reserve Indexed, Load Word and Reserve Indexed

Loads the value from the memory location specified by addr and returns the result. For __lwarx, in 64-bit mode, the compiler returns the sign-extended result.

Prototype

long __ldarx (volatile long* addr);

int __lwarx (volatile int* addr);

Parameters

addr
The address of the value to be loaded. Must be aligned on a 4-byte boundary for a single word and on an 8-byte boundary for a doubleword.

Usage

This function can be used with a subsequent __stdcx (or __stwcx) built-in function to implement a read-modify-write on a specified memory location. The two built-in functions work together to ensure that if the store is successfully performed, no other processor or mechanism can modify the target doubleword between the time the __ldarx function is executed and the time the __stdcx function completes. This has the same effect as inserting __fence built-in functions before and after the __ldarx built-in function and can inhibit compiler optimization of surrounding code (see __alignx for a description of the __fence built-in function).

__ldarx is valid only in 64-bit mode.