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

Replacing the x86 pause Assembly Instruction

Symptom

Error: unknown mnemonic 'pause' -- 'pause'

Cause

The pause instruction provides a hint to the processor that the code sequence is in a spin-wait loop. The processor uses this hint to avoid memory order violation, which improves the processor performance. If this error message is displayed, you need to replace the pause instruction with the yield instruction for the Kunpeng platform.

Procedure

  • Example code on the x86 platform:
    static inline void PauseCPU() { 
        __asm__ __volatile__("pause" : : : "memory"); 
    }
  • Example code on the Kunpeng platform:
    static inline void PauseCPU() { 
        __asm__ __volatile__("yield" : : : "memory"); 
    }