Skip to content

[clang] missing support for _Float128 (C23) #80195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nickdesaulniers opened this issue Jan 31, 2024 · 8 comments
Closed

[clang] missing support for _Float128 (C23) #80195

nickdesaulniers opened this issue Jan 31, 2024 · 8 comments
Labels
backend:AArch64 c23 clang Clang issues not falling into any other category duplicate Resolved as duplicate floating-point Floating-point math

Comments

@nickdesaulniers
Copy link
Member

nickdesaulniers commented Jan 31, 2024

_Float128 x;
<source>:1:1: error: unknown type name '_Float128'
    1 | _Float128 x;
      | ^

"Annex H (normative) IEC 60559 interchange and extended types" subsection "H.2.1 Interchange floating types" talks about:

Types designated:
_FloatN
where N is 16, 32, 64, or ≥ 128 and a multiple of 32

Looks like clang does not support this type. The extension type __float128 seems supported, but only on x86_64 (or rather, at least not on aarch64 where instead long double seems to be 128b). After first class compiler support is enabled for these types on all supported targets, there's some preprocessor defines that should be defined by clang as well.

An implementation that defines STDC_IEC_60559_BFP and STDC_IEC_60559_TYPES shall
provide _Float32 and _Float64 as interchange floating types with the same representation and
alignment requirements as float and double, respectively. If the implementation’s long double
type supports an IEC 60559 interchange format of width N > 64, then the implementation shall also
provide the type _FloatN as an interchange floating type with the same representation and alignment
requirements as long double.

Otherwise libraries that seek to provide support for functions that have _Float128 return or parameter types need to result to compiler version detection (rather than feature detection) and type alias to compiler extensions (or long double 🤢 🤮 ).

In particular, porting code making excessive use of long double on x86_64 to aarch64 has been quite painful. _Float128 will help, but clang is currently missing pieces that may help make code more platform-portable easier.

@nickdesaulniers nickdesaulniers added clang Clang issues not falling into any other category backend:AArch64 c23 labels Jan 31, 2024
@llvmbot
Copy link
Member

llvmbot commented Jan 31, 2024

@llvm/issue-subscribers-backend-aarch64

Author: Nick Desaulniers (nickdesaulniers)

```c _Float128 x; ``` ``` <source>:1:1: error: unknown type name '_Float128' 1 | _Float128 x; | ^ ``` "Annex H (normative) IEC 60559 interchange and extended types" subsection "H.2.1 Interchange floating types" talks about:

> Types designated:
_FloatN
where N is 16, 32, 64, or ≥ 128 and a multiple of 32

Looks like clang does not support this type. The extension type __float128 seems supported, but only on x86_64 (or rather, at least not on aarch64). After first class compiler support is enabled for these types on all supported targets, there's some preprocessor defines that should be defined by clang as well.

> An implementation that defines STDC_IEC_60559_BFP and STDC_IEC_60559_TYPES shall
provide _Float32 and _Float64 as interchange floating types with the same representation and
alignment requirements as float and double, respectively. If the implementation’s long double
type supports an IEC 60559 interchange format of width N > 64, then the implementation shall also
provide the type _FloatN as an interchange floating type with the same representation and alignment
requirements as long double.

Otherwise libraries that seek to provide support for functions that have _Float128 return or parameter types need to result to compiler version detection (rather than feature detection) and type alias to compiler extensions.

In particular, porting code making excessive use of long double on x86_64 to aarch64 has been quite painful. _Float128 will help, but clang is currently missing pieces that may help make code more platform-portable easier.

@pinskia
Copy link

pinskia commented Jan 31, 2024

Note _Float128 could be easily supported for aarch64-linux-gnu as long double there is the same. For Darwin/Mac OS IIRC long double is the same as double.

Note also _Float128 support was addded in GCC 7+ for aarch64-- (darwin is not supported in GCC yet).

@tgross35
Copy link
Contributor

GNU GCC 13 supports both __float128 and _Float128 on MacOS aarch64, unsure about x86.

Is there any reason not to make _Float128 available on all platforms, at least 64-bit? LLVM makes this possible already via fp128.

@tgross35
Copy link
Contributor

tgross35 commented May 11, 2024

Note that there seem to be some ABI bugs on 32-bit platforms, see the garbage output at https://gcc.godbolt.org/z/avxEGPoz9. Also:

@nickdesaulniers
Copy link
Member Author

Is there a canonical way to feature detect _Float128 support? H.2.4.2 kind of mentions this

An implementation that defines STDC_IEC_60559_BFP
and STDC_IEC_60559_TYPES shall provide _Float32x, and may provide one or both of the
types _Float64x and _Float128x.

That may there seems unhelpful since checking __STDC_IEC_60559_BFP__ doesn't imply support for _Float128.

LLVM's libc has some hacked up feature detection that is gross and that I'm not proud of; was curious if I can replace that.

@tgross35
Copy link
Contributor

It looks like GCC defines __FLT128_IS_IEC_60559__ but Clang does not. Maybe this is a reasonable convention to align with? https://godbolt.org/z/bTnWGfY14. I don't see anything in the standard either. Regarding the bit you quoted, couldn't _Float64x be x86 f80 rather than _Float128?

@tgross35
Copy link
Contributor

Also, my #97335 overlaps here.

@pinskia
Copy link

pinskia commented Jan 17, 2025

__FLT128_IS_IEC_60559__ is equivant to the C23 macro FLT128_IS_IEC_60559 (which comes from https://open-std.org/jtc1/sc22/wg14/www/docs/n2379.htm paper).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:AArch64 c23 clang Clang issues not falling into any other category duplicate Resolved as duplicate floating-point Floating-point math
Projects
None yet
Development

No branches or pull requests

6 participants