• “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.

  • 相关阅读:
    vue3-Hook
    react实现列表滚动组件
    LeetCode_数学推导_困难_891.子序列宽度之和
    分享5款无广告免费的高效软件
    万姓女孩清秀文雅的名字
    【论文笔记】Enabling technologies and tools for digital twin
    小白学Java
    有效 TCP RST
    群晖7.2安装Jellyfin+alist+CloudDriver搭建无盘影院中心
    了解基于Elasticsearch 的站内搜索,及其替代方案
  • 原文地址:https://blog.csdn.net/world_hello_100/article/details/132714797