__swp intrinsic

This intrinsic inserts a SWP{size} instruction into the instruction stream generated by the compiler. It enables you to swap data between memory locations from your C or C++ code.

Note

The use of SWP and SWPB is deprecated in ARMv6 and above.

Show/hideSyntax

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

where:

val

Is the data 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 21. Access widths supported by the __swp intrinsic

InstructionSize of data loadedC cast
SWPBunsigned byte(char *)
SWPword(int *)

Show/hideReturn value

The __swp intrinsic returns the data value that previously, is in the memory address pointed to by ptr, before this value is overwritten by val.

Show/hideExample

int foo(void)
{
    int loc=0xff;
    return(__swp(0x20, (volatile int *)loc));
}

Compiling this code produces

||foo|| PROC
    MOV      r1, #0xff
    MOV      r0, #0x20
    SWP      r0, r0, [r1]
    BX       lr
    ENDP

Show/hideSee also

Copyright © 2010-2011 ARM. All rights reserved.ARM DUI 0491C
Non-ConfidentialID080411