4.7.39. __strex

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.

Syntax

int __strex(unsigned int val, volatile void *ptr)

Where:

val

Is the value to be written to memory.

ptr

Points 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

InstructionSize of data loadedC cast
STREXBunsigned byte(char *)
STREXHunsigned halfword(short int *)
STREXword(int *)

Return value

The __strex intrinsic returns:

0

if the STREX instruction succeeds

1

if the STREX instruction is locked out.

Errors

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.

Example

int foo(void)
{
    int loc=0xff;

    return(!__strex(0x20, (volatile char *)loc));
}

Compiling this code with the command-line option --cpu=6k produces

||foo|| PROC
    MOV      r0,#0xff
    MOV      r2,#0x20
    STREXB   r1,r2,[r0]
    RSBS     r0,r1,#1
    MOVCC    r0,#0
    BX       lr
ENDP

See also

Copyright © 2007, 2010 ARM Limited. All rights reserved.ARM DUI 0348A
Non-Confidential