Repository navigation
Conversation
x86 has no f64<->i64 vector conversion below AVX-512, so the ALP encoder's per-value round trip (fast_round's `as i64` and decode_value's `as f64`) kept the f64 encode loop scalar, with is_impossible_to_encode called per value, and the decoder's inverse FOR loop scalar as well. For an integer i with |i| <= 2^51, the bits of MAGIC_NUMBER + i are MAGIC_NUMBER.to_bits() + i, so rounding and both conversions become float and integer adds that vectorize: - encode: values whose scaled magnitude is below 2^51 (and not -0.0) are encoded through the bits, 64 at a time; values outside that range are redone with the existing scalar path while still in cache, and once a whole chunk misses the range the rest of the vector goes straight to the scalar path. Output is byte-identical - the FOR range of a vector whose values all fit is found with float min/max, exact for these integers, instead of emulated 64-bit integer compares - decode: a vector whose frame of reference and bit width bound every value inside (-2^51, 2^51) converts through the bits; others keep the existing path - the per-value AlpFloat helpers are #[inline], which lets the f32 loops vectorize too Co-authored-by: Isaac <no-reply@databricks.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
None.
Rationale for this change
x86 has no vector
f64<->i64conversion before AVX-512DQ. The ALP encoder's per-value round trip(
fast_round'sas i64,decode_value'sas f64) therefore keeps the f64 encode loop scalar,with
is_impossible_to_encodecalled as a function per value. The decoder's inverse FOR loop isscalar for the same reason, and the FOR min/max over
i64is emulated on SSE2.What changes are included in this PR?
For an integer
iwith|i| <= 2^51, the bits ofMAGIC_NUMBER + iareMAGIC_NUMBER.to_bits() + i. This turns the rounding and both conversions into float and integeradds:
AlpFloatgains batch methods:encode_values,decode_valuesandmin_max_encoded. Theirdefault implementations are the existing scalar loops, and f64 overrides them.
the existing scalar code while still in cache: a scaled magnitude of at least
2^51, NaN, ±inf,and -0.0. Once a whole chunk misses, the rest of the vector uses the scalar path directly, so
high-precision data doesn't pay twice. Output is byte-identical.
are exact integers, never NaN.
frame_of_referenceandbit_width, that every value iswithin
(-2^51, 2^51)before using the magic path.#[inline]on the per-value helpers lets the f32 loops vectorize too.Are these changes tested?
Covered by the existing ALP tests. Encoded output was also checked to be byte-identical, and decoded
output bit-identical, to main's. The datasets covered:
2^51boundary, large integers, mixed scales and constantsThey used lengths around vector boundaries, over 3 pages with uneven
getsizes.alpbench (128K values), Intel Xeon Platinum 8559C, default x86-64 target, median of 5 alternatingrounds:
alpbench, f64f32 keeps the scalar default methods, which vectorize once the per-value helpers are
#[inline]:encode 1.17-1.27x, decode 1.06-1.12x.
An earlier version did a full scalar fix-up pass after the vector pass. It slowed f64
high-precision encoding to 0.95x, which is why the fix-up works per 64-value chunk. None of the
measured inputs are slower in this version. Not measured on aarch64: NEON converts between f64 and
i64 natively, so the f64 gain there is likely smaller.
Are there any significant user-facing changes?
No. The new methods are on
AlpFloat, which is crate-private.AI usage disclosure
An AI coding agent (Claude Code) generated the code and this description, and ran the benchmarks and
the output checks. This PR is a draft until the submitter has reviewed it.
This pull request and its description were written by Isaac.