Fedora 38 will have a new feature for ppc64le. Clang has begun using the IEEE 128-bit long double by default instead of the IBM 128-bit long double format. This allows Clang to behave the same way as GCC, which switched to IEEE 128-bit long double on ppc64le on Fedora 36. This floating point format benefits from the hardware implementation available on IBM® Power9® processor-based servers and IBM® Power10™ processor-based servers.
Background of the floating point format
The IBM System/360 Model 85 was released in 1968 and supported a 128-bit extended precision floating point format. A few decades later this format became known in the open source communities as IBM 128-bit long double or IBM double-double.
This floating point format provides a mantissa of 106 bits, 11 bits for the exponent and a signal bit. Meanwhile, its 64-bit floating point format provides a matissa of 53 bits, 11 bits as the exponent and a signal bit. According to the IBM® AIX® documentation, this data type can store numbers with more precision than the 64-bit data type, it does not store numbers of greater magnitude.
In 1985, the IEEE 754 Working Group for binary floating-point arithmetic established the IEEE Standard 754-1985, defining two binary floating point formats: a 32-bit (binary32
) and a 64-bit (binary64
). The C language was also in the process of standardization, requiring compilers to support at least three different binary floating point types called float
, double
, and long double
.
The ppc64le architecture on Linux adopted the binary32
format as float
, binary64
as double
and ibm128
as long double
, inheriting the same formats for the newer little endian architecture used on the older big endian ppc64.
In 2008, the IEEE Computer Society published the IEEE Std 754-2008, introducing an 128-bit binary floating point format (binary128
).
Format | Signal bits | Exponent bits | Mantissa bits | Size (Bytes) |
---|---|---|---|---|
binary32 |
1 | 8 | 24 | 4 |
binary64 |
1 | 11 | 53 | 8 |
binary128 |
1 | 15 | 113 | 16 |
ibm128 |
1 | 11 | 106 | 16 |
In 2017, IBM introduced the Power9 processor with native hardware support for the binary128
format, leading the way to changing the default long double
type used in C and C++. However, this transition occurred only on ppc64le because it requires an IBM® Power8® processor or newer. The same transition on ppc64 is more complex because it may run on processors that do not support 128-bit registers from VSX or Altivec, requiring an emulation to happen on 64-bit general purpose registers as well as different rules for argument passing.
How to transition to IEEE 128-bit long double
In most cases, programs and libraries will not require any modifications. They must be rebuilt with the Clang provided with Fedora 38 to start using the IEEE 128-bit long double. While IBM Power9 introduced native hardware support for binary128
, a long double
based on this format also works on IBM Power8. The only difference is the performance improvement that newer processors provide.
Note that programs built with a previous version of Clang will continue to work using the IBM 128-bit long double.
Adapting code to IEEE 128-bit long double
There is a small group of programs that make assumptions about which long double
format ppc64le uses. In those cases, these programs have to be modified.
When rewriting this code, I suggest taking advantage of the features provided by the ISO C standard to write code that will be executed correctly on different processors and operating systems, regardless of the long double
format used by the C Library (e.g., using the macro LDBL_MANT_DIG) as follows:
#include <float.h>
#if LDBL_MANT_DIG == 113
/* Insert code for IEEE binary128 long double. */
#elif LDBL_MANT_DIG == 106
/* Insert code for IBM 128-bit long double. */
#elif LDBL_MANT_DIG == 64
/* Insert code for Intel 80-bit long double. */
#elif LDBL_MANT_DIG == 53
/* Insert code for IEEE binary64 long double. */
#endif
You can still use IBM 128-bit long double
It is also possible to continue using the IBM 128-bit long double with Clang on Fedora 38. When building the source code, ensure the parameters -mabi=ibmlongdouble -mlong-double-128
are passed to Clang as follows:
$ clang -c -mabi=ibmlongdouble -mlong-double-128 test.c -o test.o
The same parameters also work on GCC.
C++ programs built with Clang must also get linked to libstdc++ because other libraries, such as libc++, do not support both long double
formats. The Fedora builds of Clang use libstdc++ by default, but if you would like to enforce the usage of libstdc++, use -stdlib=libstdc++
when calling clang++
, as follows:
$ clang++ -c -mabi=ibmlongdouble -mlong-double-128 -stdlib=libstdc++ test.cc -o test.o
Benefits of transitioning to IEEE 128-bit long double
The transition to IEEE 128-bit long double on ppc64le will allow programs to compute numbers with greater magnitude and more precision without causing any performance regressions on IBM Power9 and newer processors. This transition is expected to help scientific and engineering programs as well as improve platform compatibility with well-established standards.
Feel free to comment below if you have questions or comments. We welcome your feedback.
Last updated: August 14, 2023