Add IEEE 754 special value (+/-Inf, +/-NaN) support and tests to Highway math functions - #3363
Open
copybara-service[bot] wants to merge 1 commit into
Open
copybara-service[bot] wants to merge 1 commit into
copybara-service[bot] wants to merge 1 commit into
Conversation
…way math functions This change ensures that Highway math functions conform to IEEE 754 / C11 Annex F specifications for special inputs (+/-Inf, +/-NaN) and adds comprehensive unit tests covering these cases: - Erf: Added explicit NaN handling to prevent x86 minps/minpd semantics from clamping NaN to +1.0 (+/-Inf handled implicitly via range clamping). - Exp / Exp2: Added explicit handling for +Inf / overflow (preventing range reduction arithmetic cancellation into NaN) and NaN (preventing underflow flush to +0.0). - Log / Log2 / Log10: Added explicit handling for negative inputs (NaN), +/-0 (-Inf), +Inf (+Inf), and NaN (NaN). - Tanh / Expm1 / Log1p: Verified that special inputs (+/-Inf, +/-NaN) are handled implicitly by the underlying arithmetic and range reduction without requiring extra checks. - Tests: Added TestSpecialValues in math_test.cc and TestTanhSpecialValues in math_hyper_test.cc covering float32 and float64 across all vector widths. Performance Impact: - Tanh, Expm1, Log1p: 0% overhead (0 instructions added). - Erf: Negligible overhead (1 compare + 1 blend). - Exp / Exp2: ~2-4% throughput overhead (2 compares + 2 blends). - Log / Log2 / Log10: ~3-5% throughput overhead (4 compares + 4 blends). Critical-path latency impact is negligible (0-1 cycle) on superscalar architectures because comparison masks depend solely on the input register and are evaluated by out-of-order execution in parallel with the arithmetic pipeline. Workloads requiring maximum throughput on finite inputs can continue using the Fast* variants (e.g., FastExp, FastLog). PiperOrigin-RevId: 977949605
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.
Add IEEE 754 special value (+/-Inf, +/-NaN) support and tests to Highway math functions
This change ensures that Highway math functions conform to IEEE 754 / C11 Annex F specifications for special inputs (+/-Inf, +/-NaN) and adds comprehensive unit tests covering these cases:
Performance Impact:
Critical-path latency impact is negligible (0-1 cycle) on superscalar architectures because comparison masks depend solely on the input register and are evaluated by out-of-order execution in parallel with the arithmetic pipeline. Workloads requiring maximum throughput on finite inputs can continue using the Fast* variants (e.g., FastExp, FastLog).