我要评分
获取效率
正确性
完整性
易理解

Replacing the x86 bswap Assembly Instruction

Symptom

Error: unknown mnemonic 'bswap' -- 'bswap x3'

Cause

bswap is the reverse byte order instruction of the x86 and needs to be replaced with the REV instruction of the ARM64.

Procedure

  • bswap instruction on the x86:
    inline uint32_t bswap(uint32_t val) { 
        __asm__("bswap %0" : "=r" (val) : "0" (val));
        return val; 
    }
  • Code on the Kunpeng platform:
    static inline uint32_t bswap(uint32_t val) { 
        __asm__("rev %w[dst], %w[src]" : [dst]"=r"(val) : [src]"r"(val)); 
        return val;
    }