Skip to content

Enforce supported long double format#7345

Merged
davebayer merged 3 commits intomainfrom
static_assert_long_double_size
Jan 29, 2026
Merged

Enforce supported long double format#7345
davebayer merged 3 commits intomainfrom
static_assert_long_double_size

Conversation

@davebayer
Copy link
Contributor

@davebayer davebayer commented Jan 24, 2026

After thinking a bit more about #7332, I think we should make unknown/unsupported long double format a hard error. The CCCL_DISABLE_LONG_DOUBLE_SUPPORT macro can be used to disable long double support in CCCL.

The advantage is that now the user gets a message about what went wrong, not just getting some errors deep inside the libcu++'s internals.

@davebayer davebayer requested a review from a team as a code owner January 24, 2026 21:40
@davebayer davebayer requested a review from ericniebler January 24, 2026 21:40
@github-project-automation github-project-automation bot moved this to Todo in CCCL Jan 24, 2026
@cccl-authenticator-app cccl-authenticator-app bot moved this from Todo to In Review in CCCL Jan 24, 2026
Comment on lines +68 to +70
static_assert(sizeof(long double) == 16,
"When the long double format is x86 80-bit extended floating point, CCCL requires the size of long "
"double to be 16 bytes.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: Could this be a source breaking change on any of our supported platforms?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When implementing the long double format detection, I thought it would be better to make the compilation fail once the user calls an API that works with long double. However, what I missed is that the l variants of cmath functions (for example fabsl) are not templated, thus all of the machinery is instantiated even just when the headers is included.

Currently, the long double format detection results in an invalid format if the size of long double is not 16. But that also means that if your long double has 96-bits and you include <cuda/std/cmath> the compilation would fail. So, this doesn't change with this PR.

Another thing is that we don't allow long double with CUDA compilation yet.

So, the only combination for which it could be a source breaking change is C++ compilation with gcc with -m96bit-long-double flag (16 byte size is default on 64-bit systems) of source file that doesn't include <cuda/std/__cmath/abs.h>, but includes <cuda/std/__floating_point/format.h>.

I think this is very unlikely to happen.

Also, I'd like to point out that we don't currently test any of our long double functionality.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that sounds rare enough. And IIUC, if a user would be broken by this PR, they could define CCCL_DISABLE_LONG_DOUBLE to make their code compile again. Unless they would rely on long double functionality, which is broken for their platform anyway. I think we are fine. Thx for the analysis!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love that we have 80 bit long double with 128 bit size requirement ^^

@github-actions

This comment has been minimized.

@davebayer davebayer requested review from miscco and removed request for ericniebler January 25, 2026 21:08
Comment on lines +68 to +70
static_assert(sizeof(long double) == 16,
"When the long double format is x86 80-bit extended floating point, CCCL requires the size of long "
"double to be 16 bytes.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love that we have 80 bit long double with 128 bit size requirement ^^

@github-project-automation github-project-automation bot moved this from In Review to In Progress in CCCL Jan 26, 2026
Co-authored-by: Michael Schellenberger Costa <miscco@nvidia.com>
@github-actions

This comment has been minimized.

@davebayer davebayer requested a review from miscco January 26, 2026 13:57
@davebayer
Copy link
Contributor Author

I've renamed the macro to CCCL_DISABLE_LONG_DOUBLE_SUPPORT, so we are consistent with other macros disabling a support for certain type.

@github-actions
Copy link
Contributor

🥳 CI Workflow Results

🟩 Finished in 2h 05m: Pass: 100%/84 | Total: 1d 11h | Max: 1h 37m | Hits: 99%/199232

See results here.

{
return __fp_format::__invalid;
}
# if LDBL_MIN_EXP == -1021 && LDBL_MAX_EXP == 1024 && LDBL_MANT_DIG == 53
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would not be better to use if constexpr for values and check for #if defined(LDBL_MIN_EXP) outside?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had it like that before, but there is no simple way to make the static_assert(sizeof(long double) == 16) work only for the fp80 branch, so I ended up using the preprocessor directives

@github-project-automation github-project-automation bot moved this from In Progress to In Review in CCCL Jan 29, 2026
@davebayer davebayer merged commit a718382 into main Jan 29, 2026
101 checks passed
@davebayer davebayer deleted the static_assert_long_double_size branch January 29, 2026 08:31
@github-project-automation github-project-automation bot moved this from In Review to Done in CCCL Jan 29, 2026
fbusato pushed a commit to fbusato/cccl that referenced this pull request Feb 19, 2026
* Enforce supported `long double` format

* Update dialect.h

Co-authored-by: Michael Schellenberger Costa <miscco@nvidia.com>

* Be consistent with other macros

---------

Co-authored-by: Michael Schellenberger Costa <miscco@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants