This intrinsic inserts an instruction of the form STREX{size} into the instruction stream generated by the compiler. It enables you to use a STREX instruction in your C or C++ code to store data to memory.
int __strex(unsigned int val, volatile void *ptr)
Where:
valIs the value to be written to memory.
ptrPoints to the address of the data to be written to in memory. To specify the size of the data to be written, cast the parameter to an appropriate integral type.
Table 4.10. Access widths supported by the __strex intrinsic
| Instruction | Size of data loaded | C cast |
|---|
STREXB | unsigned byte | (char *) |
STREXH | unsigned halfword | (short int *) |
STREX | word | (int *) |
The __strex intrinsic returns:
0if the STREX instruction succeeds
1if the STREX instruction is locked out.
The compiler does not recognize the __strex intrinsic when compiling for a target that does not support the STREX instruction. The compiler generates either a warning or an error in this case.
The __strex intrinsic does not support access to doubleword data. The compiler generates an error if you specify an access width that is not supported.
int foo(void)
{
int loc=0xff;
return(!__strex(0x20, (volatile char *)loc));
}
Compiling this code with the command‑line option --device=DLM produces
||foo|| PROC
MOVS r1,#0xff
MOVS r0,#1
MOVS r3,#0x20
STREXB r2,r3,[r1]
CMP r2,#0
BEQ |L1.24|
MOVS r0,#0
|L1.24|
BX lr
ENDP