This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Replace __ppc64__ with __powerpc64__ and fix is_iec559 for non-ibm128
ClosedPublic

Authored by MaskRay on Nov 6 2022, 4:39 PM.

Details

Summary

The lowercase __ppc64__ is not defined by non-darwin powerpc64 GCC, therefore
it lures users to write code which is not portable to GCC. Migrate to
__powerpc64__ in preparation for undefining __ppc64__. __powerpc64__ is
much more common than __PPC64__.

Update alignment_of.pass.cpp to use 1 unconditionally:
on powerpc-unknown-linux-gnu alignof(bool) = _Alignof(bool) = __alignof(bool) = 1.
The value 4 might be derived from an ancient Clang.

Change is_iec559 to true when long double uses uses IEEE 754 quadruple or double
precision (i.e. not ibm128).

Diff Detail

Event Timeline

MaskRay created this revision.Nov 6 2022, 4:39 PM
MaskRay requested review of this revision.Nov 6 2022, 4:39 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 6 2022, 4:39 PM
Herald added 1 blocking reviewer(s): Restricted Project. · View Herald Transcript
q66 added a comment.Nov 7 2022, 10:02 AM

how about fixing this properly while at it?

the reason is_iec559 is false for powerpc is that on glibc, the IBM 128-bit double-double format is not compliant; however, on musl, long double is 64-bit and equal to double, which means the value should be true there

in chimera i have the following patch: https://github.com/chimera-linux/cports/blob/master/main/llvm/patches/0017-libc-treat-long-doubles-as-IEEE754-on-musl-ppc.patch

i am not sure if there is some better way to make this work...

q66 added a comment.Nov 7 2022, 10:06 AM

(this patch also accounts for glibc setups that use the real quad-precision ieee754 long doubles, which is possible since some time ago, natively in hardware starting with POWER9 - e.g. fedora defaults to that now, as far as i know - the logic here checks for two conditions - having a larger exponent indicates real ieee754 quad float as double-double's is identical to double, while having the same amount of mantissa digits indicates that long double is equal to double)

(this patch also accounts for glibc setups that use the real quad-precision ieee754 long doubles, which is possible since some time ago, natively in hardware starting with POWER9 - e.g. fedora defaults to that now, as far as i know - the logic here checks for two conditions - having a larger exponent indicates real ieee754 quad float as double-double's is identical to double, while having the same amount of mantissa digits indicates that long double is equal to double)

I think there are 3 modes.

  • -mlong-double-64
  • -mlong-double-128 -mabi=ieeelongdouble
  • -mlong-double-128 -mabi=ibmlongdouble

If -mlong-double-128 -mabi=ieeelongdouble should define is_iec559 as well, we can detect IBM128 with defined(__LONG_DOUBLE_IBM128__).

q66 added a comment.Nov 7 2022, 10:14 AM

yes, my patch effectively accounts for both modes; -mabi=ieeelongdouble is accounted for with the first expression (__LDBL_MAX_EXP__ > __DBL_MAX_EXP__; with ibmlongdouble, it is true that __LDBL_MAX_EXP__ == __DBL_MAX_EXP__) while -mlong-double-64 is accounted for with the second expression (__LDBL_MANT_DIG__ == __DBL_MANT_DIG__)

q66 added a comment.EditedNov 7 2022, 10:17 AM

but you are right; that means you can simply change you patch to use #if defined(__powerpc__) && defined(__LONG_DOUBLE_IBM128__) instead of #ifdef __powerpc__ and it will be fully correct

i was not aware of the existence of that macro

MaskRay updated this revision to Diff 473740.Nov 7 2022, 10:26 AM
MaskRay retitled this revision from [libc++] Replace __ppc64__ with __powerpc64__ to [libc++] Replace __ppc64__ with __powerpc64__ and fix is_iec559 for non-ibm128.
MaskRay edited the summary of this revision. (Show Details)

Use #if defined(__powerpc__) && defined(__LONG_DOUBLE_IBM128__).

Technically __powerpc__ is redundant but the check makes it clear it's powerpc specific.

thesamesam accepted this revision.Nov 7 2022, 5:47 PM
ldionne accepted this revision.Nov 22 2022, 8:02 AM

The CI failure looks unrelated. LGTM, thanks for the cleanup.

This revision is now accepted and ready to land.Nov 22 2022, 8:02 AM
This revision was landed with ongoing or failed builds.Nov 22 2022, 1:33 PM
This revision was automatically updated to reflect the committed changes.