Skip to content

[memory] layout: fixed-point leaf values take 8 bytes - #68

Merged
victor-ab merged 1 commit into
victor-ab/exception-slotsfrom
victor-ab/leaf-i64
Nov 7, 2026
Merged

victor-ab merged 1 commit into
victor-ab/exception-slotsfrom
victor-ab/leaf-i64

Conversation

@victor-ab

@victor-ab victor-ab commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

Under a fixed-point plan, each leaf value is an i128: 16 bytes, the next largest part of a loaded model after its nodes and rank tables. A finite f64's fixed-point value is its odd significand, below 2^53, shifted left, so 8 bytes hold it exactly.

Design

layout: store fixed leaves in eight bytes

  • LeafValues::Fixed holds a FixedLeaf, an i64 per leaf: the signed odd significand shifted left 8 bits, and the shift in the low byte; zero is canonical. Its i128 value is rebuilt exactly where a leaf is added, single-row and grouped.
  • Every Plan::Fixed model qualifies, float32 models included: significands are below 2^53 and shifts are 0 to 123 for nonempty models (src/exact/mod.rs). Wide plans keep their limbs, and the accumulators stay 128-bit or wide.

Evidence

1 candidate 32 512
this PR vs #67 +0.7% (+0.7 to +2.0) within noise (−7.6 to +2.6) within noise (−6.4 to +1.5)

On AVX-512 (GCP c4-standard-8, Intel Xeon Platinum 8581C, SMT off, all-core turbo, one pinned core; six paired rounds), for the served requests and for groups of 128 to 1,024 rows (max_group_width 1024): like any group of 65 to 1,024 rows, these take Handle carriers and reach list_avx512:

1 candidate 32 512 128 rows 512 rows 1,024 rows
this PR vs #67 +1.7% (+1.5 to +2.4) +2.0% (+1.1 to +2.4) within noise (−1.8 to +2.6) within noise (−0.2 to +0.5) +1.6% (+1.2 to +2.0) within noise (−0.8 to +1.0)

Where the rounds disagree in sign, only their range is given.

  • The decode is a shift and a sign-extended shift by a variable amount, about a dozen instructions per leaf on AArch64, inlined into the leaf passes.
  • Tests: every shift, signed zeros, integers, the floating-point extremes and random finite values round-trip at exact scales; the import and research expectations count 8 bytes per fixed leaf.
  • cargo test --release --features research passes; clippy (workspace, research, library alone) and fmt.

@ukaratay ukaratay left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. The packing is exact: the odd significand is below 2^53, and odd << shift fits an i128 by construction, since it came from one.

The leaf table held each Fixed leaf as an i128, though it holds an
original f64, not a sum. Pack the leaf as a signed odd mantissa with
eight low bits for its shift, halving the Fixed table without changing
the sum's scale or rounding.

A finite f64's odd mantissa is below 2^53 in magnitude, so it fits with
the low bits in an i64. The fixed-scale rule bounds the shift to 0
through 123 for a nonempty model, or 124 with zero trees. Arithmetic
right shift recovers the signed mantissa; both signed zeros pack as
zero. Every Fixed plan fits, for either threshold type, so no further
plan or fallback is needed. Wide leaves keep their digits, and sums and
difference arrays still use i128 or wide accumulators: their significant
bits need not fit a leaf's encoding.

Both the constant walk's sums and the grouped leaf pass reconstruct the
fixed integer before adding it. The leaf pass takes the stored value
type apart from the sink's value type, so Wide leaves still pass through
unchanged. The conversion is always inlined to keep production
independent of research.

Test all shifts, signed zeros, integers, the floating-point extremes and
random finite values at exact scales. The existing layout, oracle and
reference-walk tests check the decoded leaves and both prediction paths;
introspection now counts eight bytes per Fixed leaf.
@victor-ab
victor-ab merged commit e50042f into main Nov 7, 2026
9 of 11 checks passed
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.

2 participants