__lqarx, __ldarx, __lwarx, __lharx, __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

void __lqarx (volatile long* addr, long dst[2]);

long __ldarx (volatile long* addr);

int __lwarx (volatile int* addr);

short __lharx(volatile short* addr);

char __lbarx(volatile char* addr);

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 __stqcx (__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 __alignx for a description of the __fence built-in function).

__ldarx and __lqarx is valid only in 64-bit mode. __lqarx, __lharx, and __lbarx is valid only when -qarch is set to target POWER8™ processors.