__ldarx, __builtin_ppc_ldarx, __lwarx, __builtin_ppc_lwarx, __lharx, __builtin_ppc_lharx, __lbarx, __builtin_ppc_lbarx

Purpose

Load Quadword and Reserve Indexed, Load Doubleword and Reserve Indexed, Load Word and Reserve Indexed, Load Halfword and Reserve Indexed, Load Byte 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 __builtin_ppc_ldarx (volatile long* addr);

int __builtin_ppc_lwarx (volatile int* addr);

short __builtin_ppc_lharx(volatile short* addr);

char __builtin_ppc_lbarx(volatile char* addr);

long __ldarx (volatile long* addr);

int __lwarx (volatile int* addr);

short __lharx(volatile short* addr);

char __lbarx(volatile char* addr);

Note:
  • The built-in function in the form of __name is a synonym of the built-in function in the form of __builtin_ppc_name.
  • The built-in function in the form of __name is provided for compatibility with IBM® XL C/C++ for AIX® 16.1.0 or earlier releases. This built-in function form might be deprecated in the future.

Parameters

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

Usage

This function can be used with a subsequent __stdcx (__stwcx, __sthcx, or __stbcx) 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 have modified the target memory between the time the load function is executed and the time the store function completes. This has the same effect on code motion as inserting __fence built-in functions before and after the load function and can inhibit compiler optimization of surrounding code (see __fence, __builtin_ppc_fence for a description of the __fence built-in function).

__ldarx is valid only in 64-bit mode. __lharx and __lbarx are valid only when -mcpu is set to target POWER8 or higher processors.

Note:

This function generates the hardware instruction but does not act as an instruction movement barrier within the compiler. If that is needed, you must also use the __fence function.