Skip to content
DenseChip
Learn
PracticeCode labInterview

DenseChip

Navigate

Menu

LearnPracticeCode labInterview

Tools

All toolsSV editorCode repoResume
DenseChip

Practice, courses, and chip-design tools in one focused workspace.

LearnPracticeCode labInterviewToolsLearning paths

© 2026 DenseChip

AboutContactPrivacyTerms
Skip to lesson

Course contents

  • Architecture Metrics Reference
  • Workload Taxonomy for Architects
  • Architecture Glossary
  • Computer Architecture Cheatsheet
  • Pipeline Fundamentals14
  • Memory Hierarchy15
  • NoC and Interconnect Architecture6
  • Coherency and Memory Ordering9
    • Cache Coherence for the Architect
    • Memory Ordering Models
      • Models: SC, TSO, ARMv8, RVWMO
      • Where Reordering Comes From
      • Fences, Acquire/Release and Dependencies
      • Litmus Tests and Lock-Free Sync
  • Performance Analysis9
  • Accelerator Architectures6
  • SoC Architecture Tradeoffs9
  • Architecture Interview Prep14
Loading lesson

‹Memory Ordering Models
  1. Topics
  2. Computer Architecture
  3. Coherency and Memory Ordering
  4. Memory Ordering Models
  5. Fences, Acquire/Release and Dependencies

Computer Architecture · All levels

Fences, Acquire/Release and Dependencies

Full fences, acquire/release and dependencies, with a worked fence cost.

On this page

    Fence taxonomy

    A full fence orders everything before it against everything after it. Lighter primitives order one direction or one access class.

    ISA

    Full fence

    One-way primitives

    Notes

    x86-TSO

    MFENCE

    LFENCE, SFENCE order loads or stores only

    LOCK-prefixed ops and XCHG carry full barrier semantics.

    ARMv8

    DMB with domain and type

    LDAR acquire, STLR release

    DSB is stronger (drains and completes); ISB flushes the instruction stream.

    RISC-V RVWMO

    FENCE RW,RW

    AMO AQ/RL bits, LR/SC AQ/RL

    FENCE.TSO restores TSO-like order; predecessor and successor sets can be narrower.

    SFENCE.VMA is not a memory-model fence. It orders page-table writes against address translation, not data accesses against each other.

    Dependencies order without a fence

    Address and data dependencies order the dependent access on ARMv8 and RVWMO. A load that feeds another access's address or data cannot appear after it.

    Control dependencies need an explicit barrier. ARMv8 needs an ISB after the branch, RISC-V needs a FENCE, and a bare branch is never enough.

    Placing fences for publication

    An acquire load orders itself before later accesses, and a release store orders itself after earlier ones. Each is one-way: a prior load can still pass an acquire, and a later store can still pass a release.

    That one-way pair is enough for flag publication on cumulative models. Patterns needing both directions at once, such as IRIW shapes, need a full fence.

    ISA

    Writer (data then flag)

    Reader (flag then data)

    x86-TSO

    plain stores, no fence

    plain loads, no fence

    ARMv8

    plain store, then STLR flag

    LDAR flag, then plain load

    RISC-V

    plain store, FENCE, store flag

    load flag, FENCE, load data

    What a fence costs

    The calculation below is illustrative, not measured. It prices one full fence with stated assumptions.

    Diagram
    Fence stall, illustrative assumptions:
      pending stores in buffer ......... 8
      drain rate ........................ 1 store per cycle
      barrier handshake ................. 3 cycles
      t_drain = 8 stores / 1 per cycle = 8 cycles
      t_fence = 8 + 3 = 11 cycles
      at 3 GHz, 1 cycle = 0.333 ns (rounded)
      11 cycles x 0.333 ns = 3.67 ns (rounded)
      one fence per 20-cycle loop adds 11 / 20 = 55 percent

    The drain term scales with buffer occupancy, so a fence after bursty stores costs more. Over-fencing serializes memory-level parallelism that the buffer exists to expose.

    Common pitfall

    Acquire plus release is not a full fence. Code needing order in both directions across one point must use a full barrier on each side.

    Interview

    Likely probe: price a fence on the spot. Answer with the worked form: occupancy over drain rate plus handshake, then say where hoisting it out of the loop pays.

    Check yourself An ARMv8 flag protocol uses a plain store for the flag and a plain load to poll it. What can go wrong?

    The MP weak outcome: the poll sees the flag while the data load still reads stale state. Use STLR with LDAR, or a DMB on both sides.

    Check yourself A full fence sits inside a hot loop although only one publication needs it. What is the cheaper fix?

    Hoist the fence out or downgrade to release and acquire at the publication point. A fence drains buffers and stalls issue every time it runs.

    Related topics

    • Where reordering comes from

    Previous

    47 / 86

    Next: Litmus Tests and Lock-Free Sync

    Up next

    Up nextLitmus Tests and Lock-Free Sync

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • Models: SC, TSO, ARMv8, RVWMO