While going through the RISC-V ISA, I have seen an instruction in the memory model section (FENCE instruction). What does it mean exactly?
相关问题
- How do shader compilers work?
- C++ Builder - Difference between Lib and Res
- Why does constructing std::string(0) not emit a co
- Why doesn't the GCC assembly output generate a
- How do you parse a dangling else?
相关文章
- How to force Delphi compiler to display all hints
- Xcode - How to change application/project name : w
- What other neat tricks does the SpecialNameAttribu
- What is the purpose of “-Wa,option” in GCC? [close
- Why does the C++ compiler give errors after lines
- Can a compiler inline a virtual function if I use
- Which x86 C++ compilers are multithreaded by itsel
- Undefined reference to fork() in Code::Blocks edit
I've found one case when using FENCE instruction is just necessary. Example:
The RISC-V ISA uses a relaxed memory model where the order of loads and stores performed by one thread may be different when seen by another. This is done to enable techniques to increase memory system performance.
For example, Thread 1 may execute:
But Thread 2 could see the loads and the stores out of order with regard to the first thread:
The FENCE ensures that all operations before the fence are observed before any operation after the fence. So if the above changed to:
Thread 1:
Then Thread 2 would be guaranteed to see the load to A and the store to B before the store to C, but still could see the store to B before the load of A.
Thread 2:
Source: http://riscv.org/download.html (User-Level ISA Spec v2.0 page 19)