ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_stbtt_alloc.c File Reference

Fixed bump arena with refcount auto-reset for stb_truetype. More...

#include "ra8_stbtt_alloc.h"
#include <stdalign.h>
#include <stddef.h>
#include <stdint.h>
Include dependency graph for ra8_stbtt_alloc.c:

Go to the source code of this file.

Enumerations

enum  ra8_stbtt_alloc_consts_t : uint32_t {
  k_ra8_stbtt_align = 16U ,
  k_ra8_stbtt_align_mask = 15U ,
  k_ra8_stbtt_arena_bytes = 96U * 1024U
}
 Arena sizing knobs (no magic numbers). More...

Functions

void * ra8_stbtt_malloc (size_t n)
 Allocate n bytes of glyph scratch from the static arena.
void ra8_stbtt_free (void *p)
 Release a block previously returned by ra8_stbtt_malloc().
size_t ra8_stbtt_alloc_high_water (void)
 Worst-case arena high-water mark observed since boot, in bytes.

Variables

static uint8_t s_arena [k_ra8_stbtt_arena_bytes]
 Backing store for all stb_truetype scratch (NASA P10 Rule 3).
static size_t s_offset = 0U
 Current bump offset into s_arena, bytes.
static size_t s_live = 0U
 Count of live (allocated, not yet freed) blocks.
static size_t s_high_water = 0U
 Peak s_offset observed since boot (diagnostic).

Detailed Description

Fixed bump arena with refcount auto-reset for stb_truetype.

See ra8_stbtt_alloc.h for the rationale. The capacity is sized from the measured worst case: the densest printable-ASCII glyph ('@') of the bundled Literata face at the library's maximum font size (k_reflow_max_font_px = 96 px) accumulates ~32 KiB of stb scratch within a single rasterisation. The arena is provisioned at 3x that so a heavier face or a larger glyph still fits with margin.

[Ring 4 / Reflow] {World: NS}

Since
0.1.0

Definition in file ra8_stbtt_alloc.c.

Enumeration Type Documentation

◆ ra8_stbtt_alloc_consts_t

enum ra8_stbtt_alloc_consts_t : uint32_t

Arena sizing knobs (no magic numbers).

Enumerator
k_ra8_stbtt_align 

Allocation alignment, bytes.

k_ra8_stbtt_align_mask 

k_ra8_stbtt_align - 1.

k_ra8_stbtt_arena_bytes 

3x the 32 KiB worst case.

Definition at line 31 of file ra8_stbtt_alloc.c.

Function Documentation

◆ ra8_stbtt_alloc_high_water()

size_t ra8_stbtt_alloc_high_water ( void )

Worst-case arena high-water mark observed since boot, in bytes.

Diagnostic hook for sizing/regression: lets a host test or an on-target probe confirm the configured capacity has headroom.

Returns
Peak number of simultaneously-bumped bytes since boot.
Return values
0No allocation has been made yet.
Precondition
None beyond a consistent arena state.
Called single-threaded from the rasteriser.
Postcondition
The arena state is left unchanged (pure read).
The returned value never decreases across calls.
Note
Not thread-safe: rasterisation is single-threaded.
Since
0.1.0

Definition at line 83 of file ra8_stbtt_alloc.c.

References s_high_water.

◆ ra8_stbtt_free()

void ra8_stbtt_free ( void * p)

Release a block previously returned by ra8_stbtt_malloc().

Decrements the live-block count; the bump offset is not tracked per block. When the count reaches zero the arena is fully drained, so the offset rewinds to the base. A nullptr argument is ignored.

Parameters
[in]pPointer to release; nullptr is ignored.
Returns
None.
Precondition
p was returned by ra8_stbtt_malloc(), or is nullptr.
Called single-threaded from the rasteriser.
Postcondition
The live-block count is decremented (never below zero).
When the live-block count reaches zero the arena offset rewinds to the base (full auto-reset).
Note
Not thread-safe: rasterisation is single-threaded.
Since
0.1.0

Definition at line 70 of file ra8_stbtt_alloc.c.

References s_live, and s_offset.

◆ ra8_stbtt_malloc()

void * ra8_stbtt_malloc ( size_t n)

Allocate n bytes of glyph scratch from the static arena.

Bumps the arena offset by n rounded up to the 16-byte alignment and increments the live-block count. Requests larger than the arena, or that do not fit the remaining capacity, fail with nullptr.

Parameters
[in]nByte count requested by stb_truetype.
Returns
16-byte-aligned pointer into the arena, or nullptr if the request does not fit the remaining capacity.
Return values
nullptrThe request exceeds the arena or remaining capacity.
Precondition
The arena is in a consistent state (statically zero-initialised).
Called single-threaded from the rasteriser.
Postcondition
On success the live-block count is incremented and the offset advances by the aligned size.
On failure the arena state is unchanged.
Note
Not thread-safe: rasterisation is single-threaded.
Since
0.1.0

Definition at line 50 of file ra8_stbtt_alloc.c.

References k_ra8_stbtt_align_mask, k_ra8_stbtt_arena_bytes, s_arena, s_high_water, s_live, and s_offset.

Variable Documentation

◆ s_arena

uint8_t s_arena[k_ra8_stbtt_arena_bytes]
static

Backing store for all stb_truetype scratch (NASA P10 Rule 3).

Aligned so every 16-byte-rounded offset yields a 16-byte-aligned pointer.

Definition at line 39 of file ra8_stbtt_alloc.c.

◆ s_high_water

size_t s_high_water = 0U
static

Peak s_offset observed since boot (diagnostic).

Definition at line 48 of file ra8_stbtt_alloc.c.

Referenced by ra8_stbtt_alloc_high_water(), and ra8_stbtt_malloc().

◆ s_live

size_t s_live = 0U
static

Count of live (allocated, not yet freed) blocks.

Definition at line 45 of file ra8_stbtt_alloc.c.

Referenced by ra8_stbtt_free(), and ra8_stbtt_malloc().

◆ s_offset

size_t s_offset = 0U
static

Current bump offset into s_arena, bytes.

Definition at line 42 of file ra8_stbtt_alloc.c.

Referenced by ra8_stbtt_free(), and ra8_stbtt_malloc().