“Instruction Re-ordering Everywhere: The C++ 'As-If' Rule and the Role of Sequence"
summary
Claims that C++ gives the compiler and CPU carte blanche to reorder instructions as long as logical dependencies hold and observable results match; cites As-if rule (Section 1.91) and shows concrete examples: a mouse highlight function refactored (row/column computations reordered) and still produces correct output because operator precedence, associativity and static single assignment reasoning preserve values. Explains runtime actors (compiler optimizations, CPU OOO execution, cache-line effects) and the practical rule: add explicit dependencies (atomics/fences) to fix undefined behavior.
AI-written summary · about
chapters (11)
- 0:00Introduction to instruction reordering
- 3:07Key takeaways on dependencies
- 10:35Sequence vs algorithm in C++
- 17:13Assumptions in design and pizza example
- 23:28Requirements and constraints influence order
- 28:47Imperative vs sequential devices
- 32:37Physical vs logical sequence
- 38:55State and dependencies in code
- 43:50The C++ 'As-If' rule explained
- 47:43Focus on dependency management
- 51:57Q&A on reordering granularity
related talks
42mThe C++ Execution Model
56m“The C++ Execution Model”
59mA Relaxed Guide to memory_order_relaxed
01h 00mOut-of-order execution - what can it do for me?
17mPutting Weak Memory in Order via a Promising Intermediate Representation
01h 02mThe Two Memory Models
01h 11mProgramming language memory models: Problems, solutions, and directions
01h 28mAtomic’s memory orders, what for?
