Can DMB instructions be safely omitted in ARM Cortex M4

这一生的挚爱 提交于 2019-12-01 12:38:24

I'm not aware of whether Cortex M4 can be used in a multi-cpu/multi-core configuration, but in general:

  1. Memory barriers are never necessary (can always be omitted) in single-core systems.
  2. Memory barriers are always necessary (can never be omitted) in multi-core systems where threads/processes operating on the same memory may be running on different cores.

Presence or lack of reordering memory writes at the hardware level is irrelevant.

Of course I would expect the DMB instruction to be essentially free on chips that don't support SMP, so I'm not sure why you'd want to try to hack it out.

Please note that, based on the question's referencing the code the compiler produces for atomic intrinsics, I'm assuming the context is for synchronization of atomics to make them match the high-level specification, not other uses like IO barriers for MMIO, and the above "never" should not be read as applying to this (unrelated) use (though I suspect, for the reasons you already cited, it doesn't apply to Cortex M4).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!