$ show cmuratori/computer_enhance
This repository contains the example code and homework assignments for Casey Muratori's "Performance Aware Programming" course (computerenhance.com). It is primarily educational material, not a production application. The core deliverable is a fully-functional 8086 instruction decoder, disassembler, and cycle estimator (sim86) implemented in C++, with multi-language bindings (C#, Python, Rust, Go, Node.js, WebAssembly, etc.). The rest of the repository comprises over 150 standalone C++ programs and x86 assembly listings that systematically explore performance measurement, memory hierarchy, SIMD (including AVX and FMA), floating-point math optimization (haversine distance), and profiling techniques. Each listing is self-contained, often including a custom repetition tester for accurate benchmarking. The architecture is a collection of independent executables that share common infrastructure via file inclusion (buffer, platform metrics, JSON parser, profiler macros). There is no build system beyond Windows batch scripts; portability to Linux/macOS is community-contributed and not officially tested. The code is well-crafted for teaching low-level performance concepts but is not designed for production reuse, though several components (the 8086 decoder, repetition tester, dead-code prevention macros) could be extracted with minimal effort.
The LLM identified 5 files worth highlighting for reuse:
Core 8086 decoder/disassembler library exposed via extern 'C' API. It provides functions to decode instruction bytes, format text output, and estimate cycle counts. The library is self-contained (no external dependencies) and has been wrapped in C#, Python, Rust, Go, Node.js, WebAssembly, and others. Reusable in any project that needs 8086 instruction analysis.
A generic performance measurement harness that runs a test function multiple 'waves', collecting CPU timer cycles, OS page faults, byte counts, and operation counts. It prints results in CSV format with derived metrics (GB/s, GOp/s, KB per page fault). The pattern is reusable for any performance benchmark: just provide a callback and call BeginTime/EndTime within the test.
Provides macros `PretendToWrite` and `PretendToRead` that use inline assembly to prevent the compiler from optimizing away benchmarked code. These are essential for accurate timing measurements and are reusable in any C/C++ benchmarking context where dead-code elimination is a concern.
A hand-written, bounds-checked JSON parser that handles haversine pair data. It supports scientific notation, negative numbers, and escaped quotes without external dependencies. The parser is self-contained and uses a `Token` struct and error reporting via `Error()`. Could be reused in any low-dependency C++ project needing JSON parsing.
The execution engine for the sim86 8086 simulator. It interprets decoded instructions and updates registers and memory. Written in C-style C++ with minimal reliance on the standard library, making it portable. Reusable as part of an 8086 emulation system.