Skip to content

Wire %fixp (fixed-point) arrays into Lagoon#44

Open
sigilante wants to merge 1 commit into
mainfrom
sigilante/lagoon-fixp
Open

Wire %fixp (fixed-point) arrays into Lagoon#44
sigilante wants to merge 1 commit into
mainfrom
sigilante/lagoon-fixp

Conversation

@sigilante
Copy link
Copy Markdown
Collaborator

Phase B of the fixed-point buildout — integrates /lib/fixed into Lagoon as
the %fixp array kind, element-wise plus exact reductions, mirroring the
%int2/%unum integrations.

Independent of PR #43 (Phase A scalar API): this uses only /lib/fixed's
pre-existing mul/div/scale/to-s/ng arms.

Representation

A fixed-point element occupies 2^bloq bits, with a + b + 1 = 2^bloq
(q3.4 @ bloq3/8b, q7.8 @ bloq4/16b, q15.16 @ bloq5/32b) — the same power-of-2
tiling every other kind uses. The precision [a b] rides in meta.tail
(its declared "future data" slot), read via ;;([a=@ b=@] tail).

What's wired

  • sur/lagoon: %fixp enabled in the kind union.
  • fun-scalar: add/sub/mod and all comparisons need only the
    element width and reuse /lib/twoc directly (identical to %int2 on the
    stored integer). mul/div rescale by 2^b through /lib/fixed; mul
    re-quantizes back to the array precision rather than widening (array
    elements are uniform — truncating, documented). Comparisons return the
    fixed value 1.0 (= 2^b) / 0.0.
  • trans-scalar %abs: two's-complement abs at the element width.
  • get-term (%ux, no fixed-point printer), eye/ones constant
    1.0 = 2^b from meta.tail, scale raw-pack, change guarded
    with a ~| message (conversion not yet wired).
  • Reductions: dot/mmul use a new +fixp-fdp that accumulates the
    integer products Σ sx·sy exactly, then rescales by 2^b once — exact,
    no per-product truncation. cumsum needs no special path (fixed add is
    already exact modular integer add).

Tests — /tests/lib/lagoon-fixp (7, all pass on ~hex)

q3.4 coverage: arithmetic, comparisons, abs, the ones builder, cumsum,
and exact dot/mmul. The %unum (14) and %int2 (5) regression suites
remain green.

Not in scope

change/convert for %fixp (use /lib/fixed's to-rs/from-rs); jets.

🤖 Generated with Claude Code

Phase B of the fixed-point buildout: integrates /lib/fixed into Lagoon as
the %fixp kind, element-wise plus quire-style exact reductions.

Representation: a fixed-point element occupies 2^bloq bits with
a + b + 1 = 2^bloq (q3.4 @ bloq3/8b, q7.8 @ bloq4/16b, q15.16 @ bloq5/32b),
matching the %int2/%unum tiling.  The precision [a b] is carried in
meta.tail and read via ;;([a=@ b=@] tail).

- sur/lagoon: %fixp enabled in the kind union.
- fun-scalar: add/sub/mod and all comparisons need only the width and reuse
  /lib/twoc directly (identical to %int2 on the stored integer); mul/div
  rescale by 2^b through /lib/fixed (mul re-quantizes back to the array
  precision rather than widening, since array elements are uniform);
  comparisons return the fixed value 1.0 (= 2^b) / 0.0.
- trans-scalar %abs: two's-complement abs at the element width.
- get-term (%ux, no fixed-point printer), eye/ones constant 1.0 = 2^b from
  meta.tail, scale raw-pack, change guarded with a ~| message.
- Reductions: dot/mmul use a new +fixp-fdp that accumulates the integer
  products Sum sx*sy exactly, then rescales by 2^b once (exact, no
  per-product truncation).  cumsum needs no special path (fixed add is
  already exact modular integer add).

Tests: /tests/lib/lagoon-fixp (7) over q3.4 -- arith, comparisons, abs,
ones, cumsum, exact dot and mmul.  All pass on ~hex; %unum (14) and
%int2 (5) regression suites still green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant