• “memory“ clobber


    The "memory" clobber tells the compiler that the assembly code performs memory reads or writes to items other than those listed in the input and output operands. GCC may need to flush specific register values to memory before executing the asm to ensure the memory contains the correct values. Furthermore, the compiler does not assume any values read from memory before an asm remain unchanged after that asm. Instead, it reloads them as needed. Using the "memory" clobber effectively forms a read/write memory barrier for the compiler.

    The "memory" clobber tells the compiler that the instruction may read or write to any memory address. Thus, the compiler will hold back the actions, so the memory access operation before this instruction will not be moved after this instruction and vice versa. This prevents instruction reordering due to compiler optimization and ensures the relative order of the code blocks before and after barrier().

    There is a side effect of "memory" clobber. The compiler will flush the cached values from all registers. Then, it will reread the values from the memory and caches them into the registers. Therefore, the compiler reordering optimization is suppressed.

    The volatile keyword is used to inform the compiler that the value of the variable it modifies is likely to be changed by factors outside the program. For example, if the variable is stored in the mapped memory of hardware register IO, the value may be changed. As a result, the compiler is prevented from caching the variable. For a variable modified by volatile, the compiler cannot cache the variable. Instead, when the value of the variable is used each time, the compiler must reread the value of the variable from memory.

  • 相关阅读:
    怎样吃透一个java项目?
    Oracle/PLSQL: LNNVL Function
    VR全景HDR拍摄教程
    一图读懂k8s informer client-go
    Java线程中断机制
    高等数学(第七版)同济大学 习题9-5 个人解答
    【附源码】计算机毕业设计SSM体育馆预定系统
    【K8S专栏】Kubernetes应用配置管理
    【Django | 开发】面试招聘信息网站(增加csv,excel导出&日志管理功能)
    LeetCode-剑指57-和为s的两个数字
  • 原文地址:https://blog.csdn.net/world_hello_100/article/details/132714797