Skip to content

Optimize highway Exp using floating-point rounding (round_small technique). - #3356

Open
copybara-service[bot] wants to merge 1 commit into
masterfrom
test_976692126
Open

Optimize highway Exp using floating-point rounding (round_small technique).#3356
copybara-service[bot] wants to merge 1 commit into
masterfrom
test_976692126

Conversation

@copybara-service

Copy link
Copy Markdown
Contributor

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):

  • 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)

…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
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