Contents
How the machine works, from bits to data-oriented design, in twelve sections. Topics are written in any order; each names what it builds on.
1. Numbers in the machine
Bits and bytes
Not written yet
Binary and hexadecimal
Not written yet
Unsigned integers
Not written yet
Signed integers: two's complement
Not written yet
Bitwise operations
Not written yet
Integer conversions in C
Not written yet
Floating point
Not written yet
Endianness
Not written yet
Characters and text
Not written yet
2. The machine model
Instructions are bytes
Not written yet
Registers
Not written yet
A first NASM program
Not written yet
Memory and addresses
Not written yet
Looking inside with a debugger
Not written yet
Arithmetic and the flags
Not written yet
Bit instructions
Not written yet
Jumps
Not written yet
Talking to the OS
Not written yet
Project: a hex dump tool
Not written yet
3. C on the machine
C's types on x86-64
Not written yet
Reading what the compiler made
Not written yet
Variables live in memory
Not written yet
Pointers
Not written yet
Arrays
3.6Pointer arithmetic
Arguments are copies
Not written yet
Casts and reading memory as another type
Not written yet
Structs
Not written yet
Strings are bytes with a length
Not written yet
Undefined behaviour, briefly
Not written yet
4. Data layout
Alignment, data and memory
Why the CPU wants alignment
Not written yet
Padding you can see
Not written yet
Aligning memory yourself
Not written yet
Arrays of structs
Not written yet
Struct of arrays
Not written yet
Bit fields and packing
Not written yet
Data that leaves the program
Not written yet
Project: an ELF/PE header viewer
Not written yet
5. Functions and the calling conventions
The stack
Not written yet
call and ret
Not written yet
The System V calling convention
Not written yet
The Windows x64 calling convention
Not written yet
C and NASM calling each other
Not written yet
Stack frames and locals
Not written yet
Structs in and out of functions
Not written yet
The stack's limits
Not written yet
Project: no recursion, a stack of your own
Not written yet
6. Memory from the OS
Virtual memory
Not written yet
Pages
Not written yet
Asking the OS for memory
Not written yet
Reserve and commit
Not written yet
Protection
Not written yet
Giving memory back
Not written yet
What malloc hides
Not written yet
Mapping files
Not written yet
7. Allocators
Why write your own
Not written yet
The stack allocator
Not written yet
Scratch memory
Not written yet
Caller-provided buffers
Not written yet
Pools
Not written yet
Arrays that grow without moving
Not written yet
Allocating everything up front
Not written yet
Catching overruns
Not written yet
Project: a word-frequency counter
Not written yet
8. Inside the CPU
The pipeline
Not written yet
Out-of-order execution
Not written yet
Branch prediction
Not written yet
Branchless code
Not written yet
Caches
Not written yet
Cache lines and layout
Not written yet
Prefetching
Not written yet
The TLB
Not written yet
9. Measuring
What a measurement tells you
Not written yet
Clocks
Not written yet
rdtsc and rdtscp
Not written yet
A micro-benchmark
Not written yet
Performance counters
Not written yet
Reading the tables
Not written yet
Project: a memory latency prober
Not written yet
10. SIMD
One instruction, many lanes
Not written yet
SIMD in NASM
Not written yet
Intrinsics in C
Not written yet
Padding arrays to the SIMD width
Not written yet
Compares and masks
Not written yet
Shuffles and horizontal work
Not written yet
Integer SIMD on bytes
Not written yet
Which CPU has what
Not written yet
What the compiler vectorises on its own
Not written yet
11. Lanes and threads
Cores and hardware threads
Not written yet
Starting threads
Not written yet
Atomics
Not written yet
Memory ordering
Not written yet
False sharing
Not written yet
Lanes and SPMD
Not written yet
Barriers
Not written yet
Splitting work
Not written yet
Work stealing
Not written yet
Project: a parallel SIMD CSV parser
Not written yet
12. Data-oriented design
Data and its transformations
Not written yet
Tables by type
Not written yet
One source of truth
Not written yet
Index tables, or reorder the table
Not written yet
Queues of deferred work
Not written yet
Hash tables over flat arrays
Not written yet
Handles instead of pointers
Not written yet
Tables in files
Not written yet
Project: a column store for CSV
Not written yet