Optimize highway Exp using floating-point rounding (round_small technique). - #3356
Open
copybara-service[bot] wants to merge 1 commit into
Open
Optimize highway Exp using floating-point rounding (round_small technique).#3356copybara-service[bot] wants to merge 1 commit into
copybara-service[bot] wants to merge 1 commit into
Conversation
…ique). Use the magic-constant float rounding trick (as in YNNPACK `round_small`) for range reduction: `(x * log2(e) + magic) - magic`, where magic = 1.5 * 2^mantissa_bits. This eliminates both the sign check (`(x < 0) ? -0.5 : +0.5`) and integer conversions (`ToInt32` / `ConvertTo`), keeping range reduction and exponent scaling entirely within floating-point and bitwise operations. Benchmark results on x86_64 (`:math_benchmark`): - f32x16: 19.57 - 20.27 ticks (was 27.06 - 41.09 ticks, ~28-50% faster) - f32x8: 20.01 ticks (was 24.30 - 31.00 ticks, ~18-35% faster) - f32x4: 17.46 ticks (was 19.39 - 73.74 ticks, ~10-76% faster) - f32x2: 17.55 - 42.01 ticks (was 80.88 ticks, ~48-78% faster) - f32 scalar: 16.13 - 18.77 ticks (was 29.96 - 31.16 ticks, ~40-46% faster) - f64x8: 24.69 ticks (was 31.35 - 34.49 ticks, ~21-28% faster) - f64x2: 18.63 ticks (was 22.75 ticks, ~18% faster) - f64 scalar: 17.40 - 20.50 ticks (was 23.34 - 28.92 ticks, ~25-35% faster) PiperOrigin-RevId: 976692126
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.
Optimize highway Exp using floating-point rounding (round_small technique).
Use the magic-constant float rounding trick (as in YNNPACK
round_small) for range reduction:(x * log2(e) + magic) - magic,where magic = 1.5 * 2^mantissa_bits. This eliminates both the sign check
(
(x < 0) ? -0.5 : +0.5) and integer conversions (ToInt32/ConvertTo),keeping range reduction and exponent scaling entirely within floating-point
and bitwise operations.
Benchmark results on x86_64 (
:math_benchmark):