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.
unsigned int __swp(unsigned int val, volatile void *ptr)
where:
valIs the data 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.12. Access widths supported by the __swp intrinsic
| Instruction | Size of data loaded | C cast |
|---|
SWPB | unsigned byte | (char *) |
SWP | word | (int *) |
The __swp intrinsic returns the data value that previously, is in the memory address pointed to by ptr, before this value is overwitten by val.
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