video: align the framebuffer for the uint32_t writes into it ea9efff4e540
render_line() writes the framebuffer a pixel at a time through a
uint32_t pointer, but it is declared as a uint8_t array, which C only
promises byte alignment. gcc -Wcast-align=strict points at it:
src/video.c:1195:41: warning: cast increases required alignment of
target type [-Wcast-align]
On x86 a misaligned store is merely slower. On riscv64 Linux it traps
and the kernel emulates it, hundreds of times slower, or it faults. In
narvi's baseline build the linker happened to place it at 0x1b7a58,
8-byte aligned, so nothing went wrong yet; _Alignas makes that a
guarantee instead of luck. (The warning itself stays: it judges the
pointer's type, not the object.)
- Author
- Andy McCall @andymccall <[email protected]>
- via
- agent
agent:claude@andymccall <[email protected]> · keyless, under your grant for changes,refs,seal · key d6ea60db88d4
- When
- · 2026-10-20 23:52 UTC
- Signature
- ◈ sealed by agent:claude@andymccall
- Hash
ea9efff4e5406b975d308d34a1f8ea123381cce12ed7b5f80fac3cae8792d2c3- Depends on
- 03a3459e6372
- Depended on by
- nothing yet
- In bookmarks
- main riscv-1
- Edits
- 2 atoms, 0 tree operations, 1 file
Browse the tree at this change
modified src/video.c +3 −1
| … | 186 unchanged lines |
||
| 187 | 187 | uint16_t ntsc_scan_pos_y; |
|
| 188 | 188 | int frame_count = 0; |
|
| 189 | 189 | ||
| 190 | - | static uint8_t framebuffer[SCREEN_WIDTH * SCREEN_HEIGHT * 4]; |
|
| 190 | + | // Written a pixel at a time through a uint32_t pointer (render_line), so it |
|
| 191 | + | // must be aligned for one: a byte array only promises byte alignment. |
|
| 192 | + | static _Alignas(uint32_t) uint8_t framebuffer[SCREEN_WIDTH * SCREEN_HEIGHT * 4]; |
|
| 191 | 193 | #ifndef __EMSCRIPTEN__ |
|
| 192 | 194 | static uint8_t png_buffer[SCREEN_WIDTH * SCREEN_HEIGHT * 3]; |
|
| 193 | 195 | #endif |
|
| … | 2264 unchanged lines |