4.3A Little TSO/x86 Formalism

book pp. 42–46 · ~3 min read

  • three changes from SC
  • extended value rule
  • B entry
  • FENCE rules
  • x86-TSO

Three edits to SC’s definition

TSO’s formal definition is SC’s definition with exactly three changes.

Change 1 — drop Store→Load (enable the FIFO write buffer). All cores still insert their loads and stores into <m<_m respecting program order for the other three cases, same or different addresses:

L(a)<pL(b)L(a)<mL(b)/* LoadLoad */L(a)<pS(b)L(a)<mS(b)/* LoadStore */S(a)<pS(b)S(a)<mS(b)/* StoreStore */\begin{aligned} L(a) <_p L(b) &\Rightarrow L(a) <_m L(b) && \text{/* Load} \rightarrow \text{Load */} \\ L(a) <_p S(b) &\Rightarrow L(a) <_m S(b) && \text{/* Load} \rightarrow \text{Store */} \\ S(a) <_p S(b) &\Rightarrow S(a) <_m S(b) && \text{/* Store} \rightarrow \text{Store */} \end{aligned}

(The fourth rule, S(a)<pL(b)S(a)<mL(b)S(a) <_p L(b) \Rightarrow S(a) <_m L(b), is gone.)

Change 2 — extend the value rule (need bypassing ). Every load gets its value from:

val(L(a))=val(MAX<m{S(a)S(a)<mL(a) or S(a)<pL(a)})\text{val}(L(a)) = \text{val}\big(\operatorname{MAX}_{<_m}\{\, S(a) \mid S(a) <_m L(a) \ \textbf{or}\ S(a) <_p L(a) \,\}\big)

The book rightly calls this equation mind-bending: a load returns the last same-address store that is either (a) before it in memory order or (b) before it in program order — though possibly after it in memory order — with option (b) taking precedence. In one clause, write-buffer bypassing overrides the rest of the memory system. This is what forced r1 = NEW in §4.2’s Table 4.3.

Change 3 — define FENCEs (order everything):

L(a)<pFENCEL(a)<mFENCES(a)<pFENCES(a)<mFENCEFENCE<pFENCEFENCE<mFENCEFENCE<pL(a)FENCE<mL(a)FENCE<pS(a)FENCE<mS(a)\begin{aligned} L(a) <_p \text{FENCE} &\Rightarrow L(a) <_m \text{FENCE} \\ S(a) <_p \text{FENCE} &\Rightarrow S(a) <_m \text{FENCE} \\ \text{FENCE} <_p \text{FENCE} &\Rightarrow \text{FENCE} <_m \text{FENCE} \\ \text{FENCE} <_p L(a) &\Rightarrow \text{FENCE} <_m L(a) \\ \text{FENCE} <_p S(a) &\Rightarrow \text{FENCE} <_m S(a) \end{aligned}

Because TSO already enforces everything except Store→Load, one could define TSO FENCEs minimally — only Store→FENCE and FENCE→Load. The book chooses the redundant all-ordering definition: it doesn’t hurt, and it makes TSO’s FENCE identical to the FENCEs of chapter 5’s relaxed models.

The ordering table

Op 1 ↓ \ Op 2 →LoadStoreRMWFENCE
LoadXXXX
StoreBXXX
RMWXXXX
FENCEXXXX

X = ordering enforced · B = bypassing required if same address · hover any cell

Table 4.4 (recreated): TSO ordering rules. Two differences from SC’s Table 3.4 — the Store,Load entry weakens from X to B, and the FENCE row/column exist at all (an SC machine acts as if a FENCE surrounded every operation).

Is x86 really TSO?

It is widely believed that the x86 memory model is equivalent to TSO (for normal cacheable memory and normal instructions) — but to the book’s knowledge, neither AMD nor Intel has guaranteed it or released a formal x86 model. The vendors define x86’s model with prose and examples: all the examples conform to TSO, and the prose seems consistent with it, but equivalence could only be proven against a public formal spec (none exists) and could be disproven by a counterexample (none found).

The constructive answer is Sewell et al.’s x86-TSO : a model in two provably equivalent forms — an abstract machine (essentially §4.4’s write-buffered switch plus a single global lock for x86 LOCK’d instructions), accessible to practitioners, and a labeled transition system that eases formal proofs. x86-TSO is consistent with the vendors’ informal rules and litmus tests, and empirical testing on AMD and Intel platforms revealed no violations — support, though never proof. The book joins Sewell et al. in urging x86 hardware and software creators to adopt the unambiguous, accessible x86-TSO model.

Check yourself

1.TSO's formal definition makes exactly three changes to SC's. What are they?

2.TSO's value rule: val(L(a)) = val(MAX<m {S(a) | S(a) <m L(a) OR S(a) <p L(a)}). When both clauses offer a store, which wins?

3.TSO FENCEs could be defined minimally. Which two orderings would suffice, and why does the book define them to order everything anyway?

4.What is the actual status of "x86 = TSO"?

4 questions