JIT bitmap text rendering for microcontrollers linebender.org · 19 points · 2 co...
HN Best 200 @best
JIT bitmap text rendering for microcontrollers linebender.org · 19 points · 2 comments · HN thread
TL;DR Raph Levien describes a JIT compiler for bitmap text rendering on an RP2350 microcontroller, used in his vic-2350 retro-computer project with a race-the-beam scanline renderer. The JIT turns each string into specialized ARM code that assembles glyph bits into a 1bpp line buffer, reaching about 23 cycles per glyph, and he adds a dot-product kerning scheme that runs at display-list build time.
- Bitmap text is chosen for crisp low-resolution aesthetics and proportional spacing, which fixed-cell RP2350 projects usually avoid for performance reasons.
- The renderer races the beam with a budget of about 6 cycles per pixel, and the text object stores only the string, font pointer and colors to save double-buffered display-list RAM.
- A JIT generates unrolled ARM code per string, using ldr/ubfx/orr sequences with reordering to hide load-use delay; the loop costs 23 cycles per glyph plus 3 cycles per row of height.
- The font bitmap is packed to 960 bytes from 1140 by sharing overlapping glyph pixels, and kerning uses popcount of AND-ed bitvectors per glyph edge.
- The textdemo uses about 21k cycles for JIT compilation and 42k cycles to run the code, about 2.6% of one core, and the JIT finishes under 100µs before scanout.
- The author notes prior art such as a 1996 patent and the 1982 Blit bitblt code generation, and says the technique would also work for framebuffers.
Discussion The thread has only two comments, both pointing to earlier work rather than discussing the technique's merits. The mood is informational and appreciative, with the commenter adding historical context about glyph-to-instruction compilation used in FrameMaker.
- Prior art exists: glyphs compiled to instructions since the 1990s (most): The commenter cites US patent 6377261B1, filed in 1996, which compiles glyphs into load-immediate, shift and OR instructions. They say FrameMaker for Macintosh used this approach, implemented by Gus Fernandez.
- Per-character specialized functions could remove the shift step (a few): A follow-up comment suggests generating a separate JIT function per character, knowing its shift count, to eliminate the shift and open further optimizations. This is drawn from figures in the same patent.
Links from the comments
#textRendering #JIT #microcontrollers #RP2350 #bitmapFonts #retroComputing