Skip to content

Element-typed parameters and index scaling (eliminate manual byte/cell math) #66

Description

@tetsuo-cpp

Summary

Make parameter (and shared) declarations carry element type and size so indexing is in elements by default, removing error-prone 4 * / CELLS patterns for narrow types.

Motivation

demo/attention.forth must use byte addressing for f32 globals:

2 PICK HEAD_DIM * I + 4 * Q + F32@

while f64 shared uses CELLS. Mixing F32@ (4-byte) with cell-oriented mental models is a footgun and obscures algorithms.

Proposed model

\! param Q f32[32768]
\! param SCALE f64
\! shared SCORES f64[1024]

Using Q pushes a typed base; indexing words scale by element size:

Word / form Behavior
i Q []@ or Q I @ load element i of Q with correct width/address space
x i Q []! store element
Or keep Q I CELLS + @ but define CELLS relative to the pointer’s element type

Minimum viable improvement:

  1. Allow f32 / i32 / f16 / … in \! param / \! shared (not only i64/f64 storage with separate access words).
  2. Document that addresses are byte addresses always, or introduce element-pointer types — pick one model and stick to it.
  3. Provide []@ / []! (or typed @) that scale correctly.

Acceptance criteria

  • Header accepts reduced-width element types for params (and ideally shared)
  • At least one ergonomic indexing path that does not require manual 4 * for f32
  • Attention-style kernel can be rewritten more clearly
  • LIT + language doc updates
  • Clarify relationship to existing F32@ / I32@ / CELLS words (compat policy)

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions