Skip to content

Add options to control denormal modes#1616

Merged
dneto0 merged 1 commit into
google:mainfrom
rjodinchr:denorms
Jul 3, 2026
Merged

Add options to control denormal modes#1616
dneto0 merged 1 commit into
google:mainfrom
rjodinchr:denorms

Conversation

@rjodinchr

@rjodinchr rjodinchr commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Introduce -denorm-preserve and -denorm-flush-to-zero options to clspv.
These options allow specifying which floating-point types (fp16, fp32, fp64)
should preserve denormals or flush them to zero.

Refactor existing options to use a unified FloatingPointType enum instead of
separate enums for FMA and RoundingModeRTE.

Introduce DenormMode enum to represent the denormal handling state
(preserve, flush_to_zero, unspecified, error).

The new options are used to:

  • Set Clang's FP32DenormalMode and FPDenormalMode accordingly.
  • Emit DenormPreserve or DenormFlushToZero execution modes and
    capabilities in the SPIR-V producer.

Validation is added in ParseOptions to ensure:

  • Preserve and FlushToZero are mutually exclusive for a given type.
  • fp16 and fp64 share the same mode, as they are mapped to the single
    FPDenormalMode in Clang CodeGenOptions.

The unused cl-denorms-are-zero option is marked as having no effect.

Comment thread lib/Compiler.cpp
Comment thread include/clspv/Option.h
Comment thread lib/Compiler.cpp Outdated
Introduce `-denorm-preserve` and `-denorm-flush-to-zero` options to clspv.
These options allow specifying which floating-point types (fp16, fp32, fp64)
should preserve denormals or flush them to zero.

Refactor existing options to use a unified `FloatingPointType` enum instead of
separate enums for FMA and RoundingModeRTE.

Introduce `DenormMode` enum to represent the denormal handling state
(preserve, flush_to_zero, unspecified, error).

The new options are used to:
- Set Clang's `FP32DenormalMode` and `FPDenormalMode` accordingly.
- Emit `DenormPreserve` or `DenormFlushToZero` execution modes and
  capabilities in the SPIR-V producer.

Validation is added in `ParseOptions` to ensure:
- Preserve and FlushToZero are mutually exclusive for a given type.
- fp16 and fp64 share the same mode, as they are mapped to the single
  `FPDenormalMode` in Clang CodeGenOptions.

The unused `cl-denorms-are-zero` option is marked as having no effect.

@dneto0 dneto0 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.

Nice.
thank you!

@dneto0
dneto0 merged commit 0f162d7 into google:main Jul 3, 2026
18 checks passed
@rjodinchr
rjodinchr deleted the denorms branch July 3, 2026 15:29
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