← Sun, Nov 8 digest

JIT bitmap text rendering for microcontrollers

read article ↗ hn thread ↗

Raph Levien details a JIT compiler that generates highly optimized ARM assembly for ultra-fast proportional bitmap text rendering on the RP2350 microcontroller.

read it A deeply technical build log detailing an ingenious JIT text-rendering technique and dot-product kerning for microcontrollers.

summary

Raph Levien explores text rendering for vic-2350, an 80s home computer re-envisioning on an RP2350 microcontroller, using a race-the-beam approach. To overcome strict cycle budgets without wasting RAM, he built a JIT compiler that emits custom ARM assembly on the fly to render proportional bitmap text at 23 cycles per glyph. The article also covers a packed font format and a novel dot-product kerning trick using bitvector popcounts. Commenters point out fascinating prior art from 1996 FrameMaker patents.

key points

  1. The JIT compiler generates optimized ARM assembly on the fly, rendering text at 23 cycles per glyph plus 3 cycles per line of height.
  2. The renderer avoids caching JIT output to save precious SRAM, running the JIT in under 100 microseconds before scanout.
  3. Kerning is evaluated at display list build time using bitvector dot products and popcounts requiring only two bytes per glyph.

who should read it

Embedded systems engineers, graphics programmers, and retrocomputing enthusiasts.

discussion warm

consensus

Commenters praise the elegant low-level hacking, tight cycle accounting, and the clever dot-product kerning trick.

pushback

A commenter notes that giving up a framebuffer makes the screen write-only, precluding reads required for operations like flood fills.

best comment by drfuchs ↗

For prior related work, check out patent US-6377261-B1 "Compiling glyphs into instructions for imaging for execution on a general purpose computer" filed 1996. The basic idea is each character turns into a sequence of "Load Immediate" / "Shift" / "OR to Memory" instructions; so there's no more fetching from a stored bitmap of the font, as the pixels are implicit in the Immediate data in the generated machine code. Then you can get fancy when one row of pixels is the same as the previous row in the character, so you don't even need to do the Load Immediate. Etc. This scheme was used in …

Highlights direct historical prior art from a 1996 patent used in FrameMaker that compiled glyphs into immediate instructions.

Generated by an LLM from the article and thread. Check the sources before relying on it.