Why is (or isn't?) SFENCE + LFENCE equivalent to MFENCE?

后端 未结 3 1983
我在风中等你
我在风中等你 2020-11-28 11:17

As we know from a previous answer to Does it make any sense instruction LFENCE in processors x86/x86_64? that we can not use SFENCE instead of MFENCE

3条回答
  •  囚心锁ツ
    2020-11-28 12:14

    What mechanism disables the LFENCE to make impossible reordering (x86 have not mechanism - Invalidate-Queue)?

    From the Intel manuals, volume 2A, page 3-464 documentation for the LFENCE instruction:

    LFENCE does not execute until all prior instructions have completed locally, and no later instruction begins execution until LFENCE completes

    So yes, your example reordering is explicitly prevented by the LFENCE instruction. Your second example involving only SFENCE instructions IS a valid reordering, since SFENCE has no impact on load operations.

提交回复
热议问题