HT-Speed
The Sub-Millisecond, Zero-Libc x86-64 Native Compiler
HT-Speed is an ultra-minimalist, single-pass native compiler that translates a clean, human-friendly systems language directly into standalone Linux x86-64 static ELF executables. It operates without intermediate assembly text, without libc, and without external linkers.
Built by TheMaster1127 using cib (C-Is-Bloated).
Table of Contents
The Problem
Modern language toolchains suffer from massive abstraction layers:
- Compilation Latency: Compiling trivial programs with GCC or Clang takes 30–50 ms and burns 80–120 million CPU instructions.
- C Runtime Baggage: Even static C binaries carry dozens of kilobytes of startup routines (
crt1.o), symbol tables, and unused dynamic resolution code.
- Serialization Tax: Traditional compilers generate an AST, serialize it to an intermediate representation (IR), emit textual assembly (
.s), write it to disk, and invoke external assemblers and linkers to assemble it back into binary machine code.
The Solution
HT-Speed flattens the entire compilation pipeline into pure memory operations:
- Zero Assembly Text: Source tokens are translated directly into physical x86-64 machine code bytes in a single streaming pass.
- Zero Libc Runtime: Output binaries communicate directly with the Linux kernel via raw hardware syscalls (
sys_write, sys_read, sys_mmap, sys_munmap, sys_exit).
- Sub-Millisecond Speed: The compiler executes directly on bare-metal silicon in sub-400 microseconds, burns ~43,562 CPU cycles on cold starts, and completes small compilations inside 14 page faults.
Live Hardware Silicon Benchmarks (vs. TinyCC)
Measured on Artix Linux x86-64 physical hardware back-to-back using Linux perf stat compiling identical workloads against TinyCC (tcc):
Workload 1: Micro-Scale Cold Latency
Tests cold process startup, micro-latency, and zero-libc footprint (test_speed/test.hts vs test_speed/test.c, 100 runs):
| Metric |
TinyCC (tcc) |
HT-Speed (htspeed_cib) |
Hardware Advantage |
| CPU Cycles Burned |
5,475,801 |
43,562 |
125.7× FEWER CYCLES |
| Kernel Page Faults |
327 |
14 |
23.4× FEWER PAGE FAULTS |
| Active Task-Clock (CPU time) |
2.74 ms |
0.94 ms |
2.9× FASTER CPU TIME |
| Elapsed Wall-Clock Time |
0.002943845 s |
0.001144271 s |
2.6× FASTER WALL CLOCK |
| Branches Evaluated |
1,662,261 |
12,077 |
137.6× FEWER BRANCHES |
| Output Executable Size |
4842 bytes |
945 bytes |
5.1× SMALLER (Pure Static) |
Workload 2: Mega-Scale Throughput (1.2 Million Lines / 100,000 Functions)
Tests sustained streaming throughput, branch prediction stability, and memory efficiency under extreme scale (test_speed/crazy_test.hts vs test_speed/crazy_test.c):
| Metric |
TinyCC (tcc) |
HT-Speed (htspeed_cib) |
Hardware Advantage |
| Elapsed Wall-Clock Time |
0.241938624 s |
0.080267682 s |
3.0× FASTER WALL CLOCK |
| Active Task-Clock (CPU time) |
239.82 ms |
79.05 ms |
3.0× FASTER CPU TIME |
| CPU Cycles Burned |
959,761,224 |
310,139,005 |
3.1× FEWER CYCLES |
| Kernel Page Faults |
14,446 |
542 |
26.7× FEWER PAGE FAULTS |
| Branches Evaluated |
645,057,589 |
375,671,021 |
1.7× FEWER BRANCHES |
| Output Executable Size |
16M (16203730 B) |
25M (25400312 B) |
Pure Static x86-64 ELF |
Hardware Throughput Analysis:
- 15+ Million Lines/Sec: HT-Speed compiles 1.2 million lines into a working 25 MB executable in ~80 milliseconds.
- 26.7× Fewer Page Faults: While TCC's libc allocator burns thousands of page faults managing heap buckets, HT-Speed's linear BSS layout only faults 542 pages.
- 0.03% Branch Miss Rate: Streaming single-pass design keeps the CPU pipeline completely saturated at ~3.7 instructions per cycle (IPC).
Directory & Project Layout
The repository is organized into a clean, modular structure (automatically generated from .gitignore):
.
├── examples
│ ├── bubble.hts
│ ├── demo.hts
│ ├── echo.hts
│ ├── hello.hts
│ ├── math_stress.hts
│ ├── mega_test.hts
│ ├── nested.hts
│ ├── numbers.hts
│ ├── ttt.hts
│ └── v4_test.hts
├── htspeed_cib.c
├── LICENSE
├── README.md
├── src
│ ├── compiler.h
│ ├── elf.h
│ ├── emitter.h
│ ├── expr.h
│ ├── lexer.h
│ ├── parser.h
│ ├── runtimes.h
│ ├── stmt.h
│ ├── string.h
│ ├── syscalls.h
│ ├── tables.h
│ └── types.h
├── tests
│ ├── 01_hello.expected
│ ├── 01_hello.hts
│ ├── 02_function.expected
│ ├── 02_function.hts
│ ├── 03_fib.expected
│ ├── 03_fib.hts
│ ├── 04_loop.expected
│ ├── 04_loop.hts
│ ├── 05_while.expected
│ ├── 05_while.hts
... more ...
│ ├── 56_pass_by_pointer.expected
│ ├── 56_pass_by_pointer.hts
│ ├── 57_dot_field_conflict.expected
│ ├── 57_dot_field_conflict.hts
│ ├── 58_struct_field_collision.expected
│ ├── 58_struct_field_collision.hts
│ ├── inc_helper.inc
│ └── setup.sh
├── test.sh
└── test_speed
├── test.c
└── test.hts
5 directories, 148 files
Architecture & The Unity Build Engine
HT-Speed uses a Unity Build architecture. Rather than compiling independent .c files into .o objects and paying linker overhead, htspeed_cib.c includes the headers in src/ directly into a single translation unit.
[ Source Code (.hts) ]
│
▼
┌───────────────┐
│ src/lexer.h │ Single-pass streaming tokenizer
└───────┬───────┘
▼
┌───────────────┐
│ src/parser.h │ Pratt parser (src/expr.h + src/stmt.h)
└───────┬───────┘
▼
┌───────────────┐
│ src/emitter.h │ Direct x86-64 machine code byte emission
└───────┬───────┘
▼
┌───────────────┐
│ src/runtimes.h│ Backpatches relocations & appends inlined runtimes
└───────┬───────┘
▼
[ 120-Byte Header + Native Machine Code ] ──► Written directly to disk
Compiler Architecture Guarantees:
- Contiguous Cache Packing: Hot functions (
emit_u8, next_token) are inlined by GCC -O2, packing execution instructions into the same L1 cache lines.
- Dead-Code Elimination: If a program does not print dynamic signed numbers, the 111-byte
itoa routine is completely omitted from the binary. If exit() is called explicitly, the fallback exit sequence is suppressed.
- Zero Intermediate Disk I/O: The compiler does not create intermediate
.s or .o files. Machine code is emitted directly into RAM buffers and flushed to disk in a single write operation.
Design Decisions & Hardware Philosophy
1. Why Single-Segment RWX (The 120-Byte Rule)
Modern compilers split binaries into multiple segments: RX (Read + Execute) for machine code and RW (Read + Write) for data to satisfy the security principle of W^X (Write XOR Execute).
In HT-Speed, binaries are emitted with a single RWX segment (PF_R | PF_W | PF_X). This was a conscious architectural trade-off:
-
The 120-Byte Record: By using a single program header (
Elf64_Phdr), the entire ELF header footprint is exactly 120 bytes ($64\text{B Ehdr} + 56\text{B Phdr}$).
-
Zero Page-Padding Bloat: The Linux kernel ELF loader requires separate memory segments to be page-aligned in virtual memory ($0x1000 = 4,096\text{ bytes}$). Separating code from data into
RX and RW segments forces a minimum file padding of 4 KB.
- By using a unified RWX layout, code and data sit contiguously in the same memory page. A complete, working executable can be as small as 198 bytes on disk without padding penalties.
2. The 18 Page-Fault Breakthrough (Demand Paging Awareness)
Earlier versions of the compiler suffered from ~121 kernel page faults per compilation. Profile analysis revealed that the compiler was executing:
m_memset(&C, 0, sizeof(C)); // Wiping static compiler buffers
Under Linux, static uninitialized memory (.bss) is mapped via Copy-On-Write (COW) to a system-wide read-only zero page. When you write to that memory, the MMU triggers a page fault (Hardware Trap 14), forcing the kernel to allocate a physical 4 KB RAM page.
Wiping multi-megabyte structs triggered consecutive kernel page faults on memory that was never even used by the program being compiled. By deleting the bulk memset and only resetting scalar tracking integers (code_len = 0, data_len = 16, etc.), page faults instantly dropped from 121 to 18, and CPU cycles dropped from 116,000 to ~33,600 (a 3.4× speedup).
3. Separation of Concerns: tests/ vs examples/
To prevent repository rot and maintain strict compiler verification:
tests/ (Automated Regression Suite): Hermetic, deterministic test files generated programmatically by tests/setup.sh. Every test has an accompanying .expected output, an optional .args file, and an exit-code contract. Run via ./test.sh to stress every instruction, boundary condition, and parser edge case.
examples/ (Real-World Programs): Clean, human-readable showcase programs (hello.hts, bubble.hts, and full terminal games like ttt.hts) designed for developers to read, inspect, and run directly.
4. The Live Automated Benchmark & README Pipeline
Most compiler documentation features stale or hallucinated benchmark numbers. HT-Speed eliminates documentation drift with generate_readme.sh:
- It compiles the current engine and runs
perf stat on physical silicon across both Micro and Mega workloads against TinyCC.
- It extracts live CPU cycles, page faults, task-clock execution time, and branch counts directly from hardware performance counters.
- It compiles the example binaries to pull live on-disk byte counts.
- It reads
.gitignore and generates an accurate directory tree.