Skip to content

E112: the primitives (a survey), and the plan made from them - #88

Merged
y6ui3i merged 1 commit into
mainfrom
perf64/primitives
Nov 20, 2026
Merged

y6ui3i merged 1 commit into
mainfrom
perf64/primitives

Conversation

@y6ui3i

@y6ui3i y6ui3i commented Nov 20, 2026

Copy link
Copy Markdown
Owner

What

The owner's proposal: not benchmarks, which measure a mixture, but one small C program for each thing a program is made of, built with GCC as real programs are. No change to src/.

  • tests/prim64/: 23 programs (loop, if, the conditional operator, pointer, recursion, pointer to a function, switch, arrays and structures, multiply and divide, bytes; double arithmetic, comparison and conversion, float, long double; shifts, rotations and bit searching, bit fields; filling and copying, pixels one at a time and several at a time; a hash, large numbers), kept built (p_*.elf, GCC 15.2) with what each prints on the real CPU (p_*.out).
  • tools/prim64.sh: runs each on g86m and compares; with ORACLE_HOST=name builds them again there and takes the expected text.
  • tools/prim64_table.py: the table, from /usr/bin/time -l and a counting copy of the sources.
  • docs/primitives64.md: the table and the order of work. E112 in docs/experiments.md.

Found

  • All 23 print on g86m what they print on the real CPU.
  • The integer primitives are alike: 291 to 339 host instructions for a guest instruction, whether the short front runs all of their instructions or two thirds. An instruction that goes to the rest of the CPU costs about 60 more. The card expected the indirect CALL and JMP, CMOV and the shifts to be expensive; they are not.
  • Four groups are expensive: a string instruction with a repeat count (369 for every byte), division (bit by bit), the XMM registers (373 to 471), the x87 (477).
  • The numbers are user mode's, whose run loop costs about 30 host instructions more than the machine's: they compare the primitives with each other, not with the boot (289).

Order of work (each an entry of its own)

  1. String instructions with a repeat count, all repetitions in one go
  2. Division
  3. The front's missing integer kinds
  4. double and float
  5. Packed SSE
  6. The x87
  7. What all share (E111's list)

Not measured

The primitives inside the machine, with paging; how common each primitive is in real programs.

🤖 Generated with Claude Code

23 small C programs, one for each thing a program is made of (loop, if,
the conditional operator, pointer, recursion, pointer to a function,
switch, arrays and structures, multiply and divide, bytes, double, float,
long double, shifts, rotations, bit fields, filling and copying, pixels,
a hash, large numbers), built with GCC and kept built. All print on g86m
what they print on the real CPU.

tools/prim64.sh runs and compares them; tools/prim64_table.py prints host
instructions for a guest instruction and what the short front does not
run. The integer primitives are alike (291 to 339); the expensive groups
are the string instructions with a repeat count, division, the XMM
registers and the x87. The order of work is docs/primitives64.md.

No change to src/.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@y6ui3i
y6ui3i merged commit 87e2ef1 into main Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant