Replacing the x86 bswap Assembly Instruction
Symptom
Compilation error: Error: unknown mnemonic 'bswap'-- 'bswap x3'
Possible Cause
bswap is the reverse byte order instruction of x86 and needs to be replaced with the rev instruction of Arm64.
Solution
bswap instruction on x86:
inline uint32_t bswap(uint32_t val) {
__asm__("bswap %0" : "=r" (val) : "0" (val));
retrun val;
}
Alternative on Arm64:
inline uint32_t bswap(uint32_t val) {
__asm__("rev %w[dst], %w[src]" : [dst]"=r"(val) : [src]"r"(val));
}
Parent topic: Source Code Modification Cases