mailing list of musl libc
 help / color / mirror / Atom feed
* [musl] [PATCH] s390x: derive float_t from compiler or default to float
@ 2020-12-01 14:36 Marius Hillenbrand
  2020-12-01 20:50 ` Rich Felker
  0 siblings, 1 reply; 9+ messages in thread
From: Marius Hillenbrand @ 2020-12-01 14:36 UTC (permalink / raw)
  To: musl; +Cc: Marius Hillenbrand

Hi,

float_t should represent the type that is used to evaluate float
expressions internally. On s390(x), float_t is currently set to double.
In contrast, the isa supports single-precision float operations and
compilers by default evaluate float in single precision, which violates
the C standard (sections 5.2.4.2.2 and 7.12 in C11/C17). With
-fexcess-precision=standard, gcc evaluates float in double precision,
which aligns with the standard yet at the cost of added conversion
instructions. To improve standards compliance, this patch changes the
definition of float_t to be derived from the compiler's
__FLT_EVAL_METHOD__.

The port of glibc to s390 incorrectly deferred to the generic
definitions which, back then, tied float_t to double. Since then, this
definition has been kept to avoid ABI changes, most recently in the
refactoring of float_t into bits/flt-eval-method.h
https://sourceware.org/legacy-ml/libc-alpha/2016-11/msg00903.html
and the discussion around
https://gcc.gnu.org/legacy-ml/gcc-patches/2016-09/msg02392.html
musl apparently adopted the definition from glibc.

Given the performance overhead and reduced standards compliance, I have
reevaluated cleaning up the special behavior on s390x. I found only two
packages, ImageMagick and clucene, that use float_t in their API, out of
>130k Debian source packages scanned. To avoid breaking ABI changes, I
patched these packages to avoid their reliance on float_t (in
ImageMagick since 7.0.10-39, patch in
https://github.com/ImageMagick/ImageMagick/pull/2832 - patch for
clucene in https://sourceforge.net/p/clucene/bugs/233).

gcc-11 will drop the special case to retrofit double
precision behavior for -fexcess-precision=standard so that
__FLT_EVAL_METHOD__ will be 0 on s390x in any scenario.
https://gcc.gnu.org/pipermail/gcc-patches/2020-November/560224.html
https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=a5dd6b69fcbe74c02d4821ac2daf2b8c9f819f6e

glibc 2.33 will most likely adopt the same behavior as in this patch, so
that float_t will eventually be float on s390x in any scenario.
https://sourceware.org/pipermail/libc-alpha/2020-November/120212.html

Testing with libc-test showed no regressions. Failing testcases
src/math/lgammaf[_r].exe succeed with the patch.

Please review and consider merging this patch.

Marius


--->8------>8------>8------>8------>8------>8------>8------>8---

float_t should represent the type that is used to evaluate float
expressions internally. On s390(x), float_t is currently set to double.
In contrast, the isa supports single-precision float operations and
compilers by default evaluate float in single precision, which violates
the C standard (sections 5.2.4.2.2 and 7.12 in C11/C17, to be precise).
With -fexcess-precision=standard, gcc evaluates float in double
precision, which aligns with the standard yet at the cost of added
conversion instructions. To improve standards compliance, this patch
changes the definition of float_t to be derived from the compiler's
__FLT_EVAL_METHOD__. Note that glibc 2.33 will most likely adopt the
same behavior on s390x.
---
 arch/s390x/bits/alltypes.h.in | 4 ++++
 arch/s390x/bits/float.h       | 6 +++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/arch/s390x/bits/alltypes.h.in b/arch/s390x/bits/alltypes.h.in
index 15d18c8f..6c0eb7f4 100644
--- a/arch/s390x/bits/alltypes.h.in
+++ b/arch/s390x/bits/alltypes.h.in
@@ -9,7 +9,11 @@
 TYPEDEF int wchar_t;
 #endif
 
+#if defined(__FLT_EVAL_METHOD__) && __FLT_EVAL_METHOD__ == 1
 TYPEDEF double float_t;
+#else
+TYPEDEF float float_t;
+#endif
 TYPEDEF double double_t;
 
 TYPEDEF struct { long long __ll; long double __ld; } max_align_t;
diff --git a/arch/s390x/bits/float.h b/arch/s390x/bits/float.h
index 90b73bee..e188cb61 100644
--- a/arch/s390x/bits/float.h
+++ b/arch/s390x/bits/float.h
@@ -1,4 +1,8 @@
-#define FLT_EVAL_METHOD 1
+#ifdef __FLT_EVAL_METHOD__
+#define FLT_EVAL_METHOD __FLT_EVAL_METHOD__
+#else
+#define FLT_EVAL_METHOD 0
+#endif
 
 #define LDBL_TRUE_MIN 6.47517511943802511092443895822764655e-4966L
 #define LDBL_MIN 3.36210314311209350626267781732175260e-4932L
-- 
2.26.2


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [musl] [PATCH] s390x: derive float_t from compiler or default to float
  2020-12-01 14:36 [musl] [PATCH] s390x: derive float_t from compiler or default to float Marius Hillenbrand
@ 2020-12-01 20:50 ` Rich Felker
  2020-12-02 10:44   ` Marius Hillenbrand
  0 siblings, 1 reply; 9+ messages in thread
From: Rich Felker @ 2020-12-01 20:50 UTC (permalink / raw)
  To: musl

On Tue, Dec 01, 2020 at 03:36:34PM +0100, Marius Hillenbrand wrote:
> Hi,
> 
> float_t should represent the type that is used to evaluate float
> expressions internally. On s390(x), float_t is currently set to double.
> In contrast, the isa supports single-precision float operations and
> compilers by default evaluate float in single precision, which violates
> the C standard (sections 5.2.4.2.2 and 7.12 in C11/C17). With
> -fexcess-precision=standard, gcc evaluates float in double precision,
> which aligns with the standard yet at the cost of added conversion
> instructions. To improve standards compliance, this patch changes the
> definition of float_t to be derived from the compiler's
> __FLT_EVAL_METHOD__.
> 
> The port of glibc to s390 incorrectly deferred to the generic
> definitions which, back then, tied float_t to double. Since then, this
> definition has been kept to avoid ABI changes, most recently in the
> refactoring of float_t into bits/flt-eval-method.h
> https://sourceware.org/legacy-ml/libc-alpha/2016-11/msg00903.html
> and the discussion around
> https://gcc.gnu.org/legacy-ml/gcc-patches/2016-09/msg02392.html
> musl apparently adopted the definition from glibc.
> 
> Given the performance overhead and reduced standards compliance, I have
> reevaluated cleaning up the special behavior on s390x. I found only two
> packages, ImageMagick and clucene, that use float_t in their API, out of
> >130k Debian source packages scanned. To avoid breaking ABI changes, I
> patched these packages to avoid their reliance on float_t (in
> ImageMagick since 7.0.10-39, patch in
> https://github.com/ImageMagick/ImageMagick/pull/2832 - patch for
> clucene in https://sourceforge.net/p/clucene/bugs/233).
> 
> gcc-11 will drop the special case to retrofit double
> precision behavior for -fexcess-precision=standard so that
> __FLT_EVAL_METHOD__ will be 0 on s390x in any scenario.
> https://gcc.gnu.org/pipermail/gcc-patches/2020-November/560224.html
> https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=a5dd6b69fcbe74c02d4821ac2daf2b8c9f819f6e
> 
> glibc 2.33 will most likely adopt the same behavior as in this patch, so
> that float_t will eventually be float on s390x in any scenario.
> https://sourceware.org/pipermail/libc-alpha/2020-November/120212.html
> 
> Testing with libc-test showed no regressions. Failing testcases
> src/math/lgammaf[_r].exe succeed with the patch.
> 
> Please review and consider merging this patch.

Thanks for the detailed report. To be clear, all models/ISA-levels
support the single-precision ops and future GCC will always use them
even with -fexcess-precision=standard, but old ones switch to using
double precision ops with -fexcess-precision=standard to meet the
contract of evaluating in (old definition of) float_t. Is this
correct?

Rich

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [musl] [PATCH] s390x: derive float_t from compiler or default to float
  2020-12-01 20:50 ` Rich Felker
@ 2020-12-02 10:44   ` Marius Hillenbrand
  2020-12-02 14:25     ` Rich Felker
  0 siblings, 1 reply; 9+ messages in thread
From: Marius Hillenbrand @ 2020-12-02 10:44 UTC (permalink / raw)
  To: musl

On 12/1/20 9:50 PM, Rich Felker wrote:
> On Tue, Dec 01, 2020 at 03:36:34PM +0100, Marius Hillenbrand wrote:
>> Hi,
>>
>> float_t should represent the type that is used to evaluate float
>> expressions internally. On s390(x), float_t is currently set to double.
>> In contrast, the isa supports single-precision float operations and
>> compilers by default evaluate float in single precision, which violates
>> the C standard (sections 5.2.4.2.2 and 7.12 in C11/C17). With
>> -fexcess-precision=standard, gcc evaluates float in double precision,
>> which aligns with the standard yet at the cost of added conversion
>> instructions. To improve standards compliance, this patch changes the
>> definition of float_t to be derived from the compiler's
>> __FLT_EVAL_METHOD__.
>>
>> The port of glibc to s390 incorrectly deferred to the generic
>> definitions which, back then, tied float_t to double. Since then, this
>> definition has been kept to avoid ABI changes, most recently in the
>> refactoring of float_t into bits/flt-eval-method.h
>> https://sourceware.org/legacy-ml/libc-alpha/2016-11/msg00903.html
>> and the discussion around
>> https://gcc.gnu.org/legacy-ml/gcc-patches/2016-09/msg02392.html
>> musl apparently adopted the definition from glibc.
>>
>> Given the performance overhead and reduced standards compliance, I have
>> reevaluated cleaning up the special behavior on s390x. I found only two
>> packages, ImageMagick and clucene, that use float_t in their API, out of
>>> 130k Debian source packages scanned. To avoid breaking ABI changes, I
>> patched these packages to avoid their reliance on float_t (in
>> ImageMagick since 7.0.10-39, patch in
>> https://github.com/ImageMagick/ImageMagick/pull/2832 - patch for
>> clucene in https://sourceforge.net/p/clucene/bugs/233).
>>
>> gcc-11 will drop the special case to retrofit double
>> precision behavior for -fexcess-precision=standard so that
>> __FLT_EVAL_METHOD__ will be 0 on s390x in any scenario.
>> https://gcc.gnu.org/pipermail/gcc-patches/2020-November/560224.html
>> https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=a5dd6b69fcbe74c02d4821ac2daf2b8c9f819f6e
>>
>> glibc 2.33 will most likely adopt the same behavior as in this patch, so
>> that float_t will eventually be float on s390x in any scenario.
>> https://sourceware.org/pipermail/libc-alpha/2020-November/120212.html
>>
>> Testing with libc-test showed no regressions. Failing testcases
>> src/math/lgammaf[_r].exe succeed with the patch.
>>
>> Please review and consider merging this patch.
> 
> Thanks for the detailed report. To be clear, all models/ISA-levels
> support the single-precision ops and future GCC will always use them
> even with -fexcess-precision=standard, but old ones switch to using
> double precision ops with -fexcess-precision=standard to meet the
> contract of evaluating in (old definition of) float_t. Is this
> correct?

Yes, your summary is correct -- with one exception that I omitted in my
original post: future GCC compiled against current libc will still
switch to using double precision ops with -fexcess-precision=standard to
match the old definition of float_t. When future GCC detects a future
libc at compile-time, it will always use single-precision ops. Without
that switch, updating GCC while keeping your current libc would have
worsened the situation wrt the C standard.

Marius

-- 
Marius Hillenbrand
Linux on Z development
IBM Deutschland Research & Development GmbH
Vors. des Aufsichtsrats: Gregor Pillen / Geschäftsführung: Dirk Wittkopp
Sitz der Gesellschaft: Böblingen / Registergericht: Amtsgericht
Stuttgart, HRB 243294

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [musl] [PATCH] s390x: derive float_t from compiler or default to float
  2020-12-02 10:44   ` Marius Hillenbrand
@ 2020-12-02 14:25     ` Rich Felker
  2020-12-02 16:01       ` Rich Felker
  0 siblings, 1 reply; 9+ messages in thread
From: Rich Felker @ 2020-12-02 14:25 UTC (permalink / raw)
  To: Marius Hillenbrand; +Cc: musl

On Wed, Dec 02, 2020 at 11:44:59AM +0100, Marius Hillenbrand wrote:
> On 12/1/20 9:50 PM, Rich Felker wrote:
> > On Tue, Dec 01, 2020 at 03:36:34PM +0100, Marius Hillenbrand wrote:
> >> Hi,
> >>
> >> float_t should represent the type that is used to evaluate float
> >> expressions internally. On s390(x), float_t is currently set to double.
> >> In contrast, the isa supports single-precision float operations and
> >> compilers by default evaluate float in single precision, which violates
> >> the C standard (sections 5.2.4.2.2 and 7.12 in C11/C17). With
> >> -fexcess-precision=standard, gcc evaluates float in double precision,
> >> which aligns with the standard yet at the cost of added conversion
> >> instructions. To improve standards compliance, this patch changes the
> >> definition of float_t to be derived from the compiler's
> >> __FLT_EVAL_METHOD__.
> >>
> >> The port of glibc to s390 incorrectly deferred to the generic
> >> definitions which, back then, tied float_t to double. Since then, this
> >> definition has been kept to avoid ABI changes, most recently in the
> >> refactoring of float_t into bits/flt-eval-method.h
> >> https://sourceware.org/legacy-ml/libc-alpha/2016-11/msg00903.html
> >> and the discussion around
> >> https://gcc.gnu.org/legacy-ml/gcc-patches/2016-09/msg02392.html
> >> musl apparently adopted the definition from glibc.
> >>
> >> Given the performance overhead and reduced standards compliance, I have
> >> reevaluated cleaning up the special behavior on s390x. I found only two
> >> packages, ImageMagick and clucene, that use float_t in their API, out of
> >>> 130k Debian source packages scanned. To avoid breaking ABI changes, I
> >> patched these packages to avoid their reliance on float_t (in
> >> ImageMagick since 7.0.10-39, patch in
> >> https://github.com/ImageMagick/ImageMagick/pull/2832 - patch for
> >> clucene in https://sourceforge.net/p/clucene/bugs/233).
> >>
> >> gcc-11 will drop the special case to retrofit double
> >> precision behavior for -fexcess-precision=standard so that
> >> __FLT_EVAL_METHOD__ will be 0 on s390x in any scenario.
> >> https://gcc.gnu.org/pipermail/gcc-patches/2020-November/560224.html
> >> https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=a5dd6b69fcbe74c02d4821ac2daf2b8c9f819f6e
> >>
> >> glibc 2.33 will most likely adopt the same behavior as in this patch, so
> >> that float_t will eventually be float on s390x in any scenario.
> >> https://sourceware.org/pipermail/libc-alpha/2020-November/120212.html
> >>
> >> Testing with libc-test showed no regressions. Failing testcases
> >> src/math/lgammaf[_r].exe succeed with the patch.
> >>
> >> Please review and consider merging this patch.
> > 
> > Thanks for the detailed report. To be clear, all models/ISA-levels
> > support the single-precision ops and future GCC will always use them
> > even with -fexcess-precision=standard, but old ones switch to using
> > double precision ops with -fexcess-precision=standard to meet the
> > contract of evaluating in (old definition of) float_t. Is this
> > correct?
> 
> Yes, your summary is correct -- with one exception that I omitted in my
> original post: future GCC compiled against current libc will still
> switch to using double precision ops with -fexcess-precision=standard to
> match the old definition of float_t. When future GCC detects a future
> libc at compile-time, it will always use single-precision ops. Without
> that switch, updating GCC while keeping your current libc would have
> worsened the situation wrt the C standard.

How does this "detecting an updated libc" take place? That sounds like
it could be really problematic...

Rich

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [musl] [PATCH] s390x: derive float_t from compiler or default to float
  2020-12-02 14:25     ` Rich Felker
@ 2020-12-02 16:01       ` Rich Felker
  2020-12-02 17:09         ` Marius Hillenbrand
  0 siblings, 1 reply; 9+ messages in thread
From: Rich Felker @ 2020-12-02 16:01 UTC (permalink / raw)
  To: Marius Hillenbrand; +Cc: musl

On Wed, Dec 02, 2020 at 09:25:04AM -0500, Rich Felker wrote:
> On Wed, Dec 02, 2020 at 11:44:59AM +0100, Marius Hillenbrand wrote:
> > On 12/1/20 9:50 PM, Rich Felker wrote:
> > > On Tue, Dec 01, 2020 at 03:36:34PM +0100, Marius Hillenbrand wrote:
> > >> Hi,
> > >>
> > >> float_t should represent the type that is used to evaluate float
> > >> expressions internally. On s390(x), float_t is currently set to double.
> > >> In contrast, the isa supports single-precision float operations and
> > >> compilers by default evaluate float in single precision, which violates
> > >> the C standard (sections 5.2.4.2.2 and 7.12 in C11/C17). With
> > >> -fexcess-precision=standard, gcc evaluates float in double precision,
> > >> which aligns with the standard yet at the cost of added conversion
> > >> instructions. To improve standards compliance, this patch changes the
> > >> definition of float_t to be derived from the compiler's
> > >> __FLT_EVAL_METHOD__.
> > >>
> > >> The port of glibc to s390 incorrectly deferred to the generic
> > >> definitions which, back then, tied float_t to double. Since then, this
> > >> definition has been kept to avoid ABI changes, most recently in the
> > >> refactoring of float_t into bits/flt-eval-method.h
> > >> https://sourceware.org/legacy-ml/libc-alpha/2016-11/msg00903.html
> > >> and the discussion around
> > >> https://gcc.gnu.org/legacy-ml/gcc-patches/2016-09/msg02392.html
> > >> musl apparently adopted the definition from glibc.
> > >>
> > >> Given the performance overhead and reduced standards compliance, I have
> > >> reevaluated cleaning up the special behavior on s390x. I found only two
> > >> packages, ImageMagick and clucene, that use float_t in their API, out of
> > >>> 130k Debian source packages scanned. To avoid breaking ABI changes, I
> > >> patched these packages to avoid their reliance on float_t (in
> > >> ImageMagick since 7.0.10-39, patch in
> > >> https://github.com/ImageMagick/ImageMagick/pull/2832 - patch for
> > >> clucene in https://sourceforge.net/p/clucene/bugs/233).
> > >>
> > >> gcc-11 will drop the special case to retrofit double
> > >> precision behavior for -fexcess-precision=standard so that
> > >> __FLT_EVAL_METHOD__ will be 0 on s390x in any scenario.
> > >> https://gcc.gnu.org/pipermail/gcc-patches/2020-November/560224.html
> > >> https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=a5dd6b69fcbe74c02d4821ac2daf2b8c9f819f6e
> > >>
> > >> glibc 2.33 will most likely adopt the same behavior as in this patch, so
> > >> that float_t will eventually be float on s390x in any scenario.
> > >> https://sourceware.org/pipermail/libc-alpha/2020-November/120212.html
> > >>
> > >> Testing with libc-test showed no regressions. Failing testcases
> > >> src/math/lgammaf[_r].exe succeed with the patch.
> > >>
> > >> Please review and consider merging this patch.
> > > 
> > > Thanks for the detailed report. To be clear, all models/ISA-levels
> > > support the single-precision ops and future GCC will always use them
> > > even with -fexcess-precision=standard, but old ones switch to using
> > > double precision ops with -fexcess-precision=standard to meet the
> > > contract of evaluating in (old definition of) float_t. Is this
> > > correct?
> > 
> > Yes, your summary is correct -- with one exception that I omitted in my
> > original post: future GCC compiled against current libc will still
> > switch to using double precision ops with -fexcess-precision=standard to
> > match the old definition of float_t. When future GCC detects a future
> > libc at compile-time, it will always use single-precision ops. Without
> > that switch, updating GCC while keeping your current libc would have
> > worsened the situation wrt the C standard.
> 
> How does this "detecting an updated libc" take place? That sounds like
> it could be really problematic...

I'm looking at
https://gcc.gnu.org/pipermail/gcc-patches/2020-November/560225.html
which seems to be what you're talking about, and don't understand how
it's intended to work. It looks like it's running a test for target
behavior on the host compiler (there is no target compiler at the
point this test is run). Looking again, I guess that's why it's under
a condition for build==host==target. What happens when cross
compiling? Do you get the old behavior unless manually setting
--disable-s390-excess-float-precision?

Also I guess this mildly breaks use of a libc older than the one the
compiler was built for, but that's probably the case in general with
GCC for various other reasons too.

Rich

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [musl] [PATCH] s390x: derive float_t from compiler or default to float
  2020-12-02 16:01       ` Rich Felker
@ 2020-12-02 17:09         ` Marius Hillenbrand
  2020-12-02 19:13           ` Rich Felker
  0 siblings, 1 reply; 9+ messages in thread
From: Marius Hillenbrand @ 2020-12-02 17:09 UTC (permalink / raw)
  To: musl



On 12/2/20 5:01 PM, Rich Felker wrote:
> On Wed, Dec 02, 2020 at 09:25:04AM -0500, Rich Felker wrote:
>> On Wed, Dec 02, 2020 at 11:44:59AM +0100, Marius Hillenbrand wrote:
>>> On 12/1/20 9:50 PM, Rich Felker wrote:
>>>> On Tue, Dec 01, 2020 at 03:36:34PM +0100, Marius Hillenbrand wrote:
>>>>> Hi,
>>>>>
>>>>> float_t should represent the type that is used to evaluate float
>>>>> expressions internally. On s390(x), float_t is currently set to double.
>>>>> In contrast, the isa supports single-precision float operations and
>>>>> compilers by default evaluate float in single precision, which violates
>>>>> the C standard (sections 5.2.4.2.2 and 7.12 in C11/C17). With
>>>>> -fexcess-precision=standard, gcc evaluates float in double precision,
>>>>> which aligns with the standard yet at the cost of added conversion
>>>>> instructions. To improve standards compliance, this patch changes the
>>>>> definition of float_t to be derived from the compiler's
>>>>> __FLT_EVAL_METHOD__.
>>>>>
>>>>> The port of glibc to s390 incorrectly deferred to the generic
>>>>> definitions which, back then, tied float_t to double. Since then, this
>>>>> definition has been kept to avoid ABI changes, most recently in the
>>>>> refactoring of float_t into bits/flt-eval-method.h
>>>>> https://sourceware.org/legacy-ml/libc-alpha/2016-11/msg00903.html
>>>>> and the discussion around
>>>>> https://gcc.gnu.org/legacy-ml/gcc-patches/2016-09/msg02392.html
>>>>> musl apparently adopted the definition from glibc.
>>>>>
>>>>> Given the performance overhead and reduced standards compliance, I have
>>>>> reevaluated cleaning up the special behavior on s390x. I found only two
>>>>> packages, ImageMagick and clucene, that use float_t in their API, out of
>>>>>> 130k Debian source packages scanned. To avoid breaking ABI changes, I
>>>>> patched these packages to avoid their reliance on float_t (in
>>>>> ImageMagick since 7.0.10-39, patch in
>>>>> https://github.com/ImageMagick/ImageMagick/pull/2832 - patch for
>>>>> clucene in https://sourceforge.net/p/clucene/bugs/233).
>>>>>
>>>>> gcc-11 will drop the special case to retrofit double
>>>>> precision behavior for -fexcess-precision=standard so that
>>>>> __FLT_EVAL_METHOD__ will be 0 on s390x in any scenario.
>>>>> https://gcc.gnu.org/pipermail/gcc-patches/2020-November/560224.html
>>>>> https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=a5dd6b69fcbe74c02d4821ac2daf2b8c9f819f6e
>>>>>
>>>>> glibc 2.33 will most likely adopt the same behavior as in this patch, so
>>>>> that float_t will eventually be float on s390x in any scenario.
>>>>> https://sourceware.org/pipermail/libc-alpha/2020-November/120212.html
>>>>>
>>>>> Testing with libc-test showed no regressions. Failing testcases
>>>>> src/math/lgammaf[_r].exe succeed with the patch.
>>>>>
>>>>> Please review and consider merging this patch.
>>>>
>>>> Thanks for the detailed report. To be clear, all models/ISA-levels
>>>> support the single-precision ops and future GCC will always use them
>>>> even with -fexcess-precision=standard, but old ones switch to using
>>>> double precision ops with -fexcess-precision=standard to meet the
>>>> contract of evaluating in (old definition of) float_t. Is this
>>>> correct?
>>>
>>> Yes, your summary is correct -- with one exception that I omitted in my
>>> original post: future GCC compiled against current libc will still
>>> switch to using double precision ops with -fexcess-precision=standard to
>>> match the old definition of float_t. When future GCC detects a future
>>> libc at compile-time, it will always use single-precision ops. Without
>>> that switch, updating GCC while keeping your current libc would have
>>> worsened the situation wrt the C standard.
>>
>> How does this "detecting an updated libc" take place? That sounds like
>> it could be really problematic...
> 
> I'm looking at
> https://gcc.gnu.org/pipermail/gcc-patches/2020-November/560225.html
> which seems to be what you're talking about, and don't understand how
> it's intended to work. It looks like it's running a test for target
> behavior on the host compiler (there is no target compiler at the
> point this test is run). Looking again, I guess that's why it's under
> a condition for build==host==target.

Right, that's the patch. The check only applies to a "native build",
with the assumption that the build environment is the same as the
intended target environment.

> What happens when cross
> compiling? Do you get the old behavior unless manually setting
> --disable-s390-excess-float-precision?

When cross compiling, we get the new behavior (the setting starts at
"auto", which is never resolved to yes or no; so the AC_DEFINE is left out).

In any case, manually setting
--enable/disable-s390-excess-float-precision takes precedence.

> Also I guess this mildly breaks use of a libc older than the one the
> compiler was built for, but that's probably the case in general with
> GCC for various other reasons too.

In this specific case, you would get a mismatch between GCC's behavior
and the definition of float_t. Selectively updating GCC while keeping an
older libc is fine when you build GCC in the target environment, or add
the --enable-s390-excess-float-precision flag.

Marius
-- 
Marius Hillenbrand
Linux on Z development
IBM Deutschland Research & Development GmbH
Vors. des Aufsichtsrats: Gregor Pillen / Geschäftsführung: Dirk Wittkopp
Sitz der Gesellschaft: Böblingen / Registergericht: Amtsgericht
Stuttgart, HRB 243294

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [musl] [PATCH] s390x: derive float_t from compiler or default to float
  2020-12-02 17:09         ` Marius Hillenbrand
@ 2020-12-02 19:13           ` Rich Felker
  2020-12-03 16:53             ` Marius Hillenbrand
  0 siblings, 1 reply; 9+ messages in thread
From: Rich Felker @ 2020-12-02 19:13 UTC (permalink / raw)
  To: Marius Hillenbrand; +Cc: musl

On Wed, Dec 02, 2020 at 06:09:44PM +0100, Marius Hillenbrand wrote:
> 
> 
> On 12/2/20 5:01 PM, Rich Felker wrote:
> > On Wed, Dec 02, 2020 at 09:25:04AM -0500, Rich Felker wrote:
> >> On Wed, Dec 02, 2020 at 11:44:59AM +0100, Marius Hillenbrand wrote:
> >>> On 12/1/20 9:50 PM, Rich Felker wrote:
> >>>> On Tue, Dec 01, 2020 at 03:36:34PM +0100, Marius Hillenbrand wrote:
> >>>>> Hi,
> >>>>>
> >>>>> float_t should represent the type that is used to evaluate float
> >>>>> expressions internally. On s390(x), float_t is currently set to double.
> >>>>> In contrast, the isa supports single-precision float operations and
> >>>>> compilers by default evaluate float in single precision, which violates
> >>>>> the C standard (sections 5.2.4.2.2 and 7.12 in C11/C17). With
> >>>>> -fexcess-precision=standard, gcc evaluates float in double precision,
> >>>>> which aligns with the standard yet at the cost of added conversion
> >>>>> instructions. To improve standards compliance, this patch changes the
> >>>>> definition of float_t to be derived from the compiler's
> >>>>> __FLT_EVAL_METHOD__.
> >>>>>
> >>>>> The port of glibc to s390 incorrectly deferred to the generic
> >>>>> definitions which, back then, tied float_t to double. Since then, this
> >>>>> definition has been kept to avoid ABI changes, most recently in the
> >>>>> refactoring of float_t into bits/flt-eval-method.h
> >>>>> https://sourceware.org/legacy-ml/libc-alpha/2016-11/msg00903.html
> >>>>> and the discussion around
> >>>>> https://gcc.gnu.org/legacy-ml/gcc-patches/2016-09/msg02392.html
> >>>>> musl apparently adopted the definition from glibc.
> >>>>>
> >>>>> Given the performance overhead and reduced standards compliance, I have
> >>>>> reevaluated cleaning up the special behavior on s390x. I found only two
> >>>>> packages, ImageMagick and clucene, that use float_t in their API, out of
> >>>>>> 130k Debian source packages scanned. To avoid breaking ABI changes, I
> >>>>> patched these packages to avoid their reliance on float_t (in
> >>>>> ImageMagick since 7.0.10-39, patch in
> >>>>> https://github.com/ImageMagick/ImageMagick/pull/2832 - patch for
> >>>>> clucene in https://sourceforge.net/p/clucene/bugs/233).
> >>>>>
> >>>>> gcc-11 will drop the special case to retrofit double
> >>>>> precision behavior for -fexcess-precision=standard so that
> >>>>> __FLT_EVAL_METHOD__ will be 0 on s390x in any scenario.
> >>>>> https://gcc.gnu.org/pipermail/gcc-patches/2020-November/560224.html
> >>>>> https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=a5dd6b69fcbe74c02d4821ac2daf2b8c9f819f6e
> >>>>>
> >>>>> glibc 2.33 will most likely adopt the same behavior as in this patch, so
> >>>>> that float_t will eventually be float on s390x in any scenario.
> >>>>> https://sourceware.org/pipermail/libc-alpha/2020-November/120212.html
> >>>>>
> >>>>> Testing with libc-test showed no regressions. Failing testcases
> >>>>> src/math/lgammaf[_r].exe succeed with the patch.
> >>>>>
> >>>>> Please review and consider merging this patch.
> >>>>
> >>>> Thanks for the detailed report. To be clear, all models/ISA-levels
> >>>> support the single-precision ops and future GCC will always use them
> >>>> even with -fexcess-precision=standard, but old ones switch to using
> >>>> double precision ops with -fexcess-precision=standard to meet the
> >>>> contract of evaluating in (old definition of) float_t. Is this
> >>>> correct?
> >>>
> >>> Yes, your summary is correct -- with one exception that I omitted in my
> >>> original post: future GCC compiled against current libc will still
> >>> switch to using double precision ops with -fexcess-precision=standard to
> >>> match the old definition of float_t. When future GCC detects a future
> >>> libc at compile-time, it will always use single-precision ops. Without
> >>> that switch, updating GCC while keeping your current libc would have
> >>> worsened the situation wrt the C standard.
> >>
> >> How does this "detecting an updated libc" take place? That sounds like
> >> it could be really problematic...
> > 
> > I'm looking at
> > https://gcc.gnu.org/pipermail/gcc-patches/2020-November/560225.html
> > which seems to be what you're talking about, and don't understand how
> > it's intended to work. It looks like it's running a test for target
> > behavior on the host compiler (there is no target compiler at the
> > point this test is run). Looking again, I guess that's why it's under
> > a condition for build==host==target.
> 
> Right, that's the patch. The check only applies to a "native build",
> with the assumption that the build environment is the same as the
> intended target environment.
> 
> > What happens when cross
> > compiling? Do you get the old behavior unless manually setting
> > --disable-s390-excess-float-precision?
> 
> When cross compiling, we get the new behavior (the setting starts at
> "auto", which is never resolved to yes or no; so the AC_DEFINE is left out).
> 
> In any case, manually setting
> --enable/disable-s390-excess-float-precision takes precedence.

FWIW this means building GCC 11 for any older version of glibc or musl
will give a broken configuration unless you pass
--disable-s390-excess-float-precision to configure. I'm not sure if
anything should be done about that; at least I might want to handle it
in mcm...

In any case this probably means I should include your patch in this
release cycle so at least current version builds right.

BTW is there a -m option to override at runtime in order to test both
behaviors, so you don't have to build a new GCC from scratch to do it?

Rich

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [musl] [PATCH] s390x: derive float_t from compiler or default to float
  2020-12-02 19:13           ` Rich Felker
@ 2020-12-03 16:53             ` Marius Hillenbrand
  2020-12-03 19:06               ` Rich Felker
  0 siblings, 1 reply; 9+ messages in thread
From: Marius Hillenbrand @ 2020-12-03 16:53 UTC (permalink / raw)
  To: musl

On 12/2/20 8:13 PM, Rich Felker wrote:
> On Wed, Dec 02, 2020 at 06:09:44PM +0100, Marius Hillenbrand wrote:
>> On 12/2/20 5:01 PM, Rich Felker wrote:
>>> On Wed, Dec 02, 2020 at 09:25:04AM -0500, Rich Felker wrote:
[...]
>>> I'm looking at
>>> https://gcc.gnu.org/pipermail/gcc-patches/2020-November/560225.html
>>> which seems to be what you're talking about, and don't understand how
>>> it's intended to work. It looks like it's running a test for target
>>> behavior on the host compiler (there is no target compiler at the
>>> point this test is run). Looking again, I guess that's why it's under
>>> a condition for build==host==target.
>>
>> Right, that's the patch. The check only applies to a "native build",
>> with the assumption that the build environment is the same as the
>> intended target environment.
>>
>>> What happens when cross
>>> compiling? Do you get the old behavior unless manually setting
>>> --disable-s390-excess-float-precision?
>>
>> When cross compiling, we get the new behavior (the setting starts at
>> "auto", which is never resolved to yes or no; so the AC_DEFINE is left out).
>>
>> In any case, manually setting
>> --enable/disable-s390-excess-float-precision takes precedence.
> 
> FWIW this means building GCC 11 for any older version of glibc or musl
> will give a broken configuration unless you pass
> --disable-s390-excess-float-precision to configure. I'm not sure if
> anything should be done about that; at least I might want to handle it
> in mcm...

I will look into handling cross compiles in a more differentiating way...

> 
> In any case this probably means I should include your patch in this
> release cycle so at least current version builds right.
> 
> BTW is there a -m option to override at runtime in order to test both
> behaviors, so you don't have to build a new GCC from scratch to do it?

Yes, in the current GCC, -fexcess-precision=standard or fast switches
between the two behaviors (i.e., both __FLT_EVAL_METHOD__ and emitted
code; "fast" corresponds to the "new" behavior).

Marius
-- 
Marius Hillenbrand
Linux on Z development
IBM Deutschland Research & Development GmbH
Vors. des Aufsichtsrats: Gregor Pillen / Geschäftsführung: Dirk Wittkopp
Sitz der Gesellschaft: Böblingen / Registergericht: Amtsgericht
Stuttgart, HRB 243294

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [musl] [PATCH] s390x: derive float_t from compiler or default to float
  2020-12-03 16:53             ` Marius Hillenbrand
@ 2020-12-03 19:06               ` Rich Felker
  0 siblings, 0 replies; 9+ messages in thread
From: Rich Felker @ 2020-12-03 19:06 UTC (permalink / raw)
  To: Marius Hillenbrand; +Cc: musl

On Thu, Dec 03, 2020 at 05:53:52PM +0100, Marius Hillenbrand wrote:
> On 12/2/20 8:13 PM, Rich Felker wrote:
> > On Wed, Dec 02, 2020 at 06:09:44PM +0100, Marius Hillenbrand wrote:
> >> On 12/2/20 5:01 PM, Rich Felker wrote:
> >>> On Wed, Dec 02, 2020 at 09:25:04AM -0500, Rich Felker wrote:
> [...]
> >>> I'm looking at
> >>> https://gcc.gnu.org/pipermail/gcc-patches/2020-November/560225.html
> >>> which seems to be what you're talking about, and don't understand how
> >>> it's intended to work. It looks like it's running a test for target
> >>> behavior on the host compiler (there is no target compiler at the
> >>> point this test is run). Looking again, I guess that's why it's under
> >>> a condition for build==host==target.
> >>
> >> Right, that's the patch. The check only applies to a "native build",
> >> with the assumption that the build environment is the same as the
> >> intended target environment.
> >>
> >>> What happens when cross
> >>> compiling? Do you get the old behavior unless manually setting
> >>> --disable-s390-excess-float-precision?
> >>
> >> When cross compiling, we get the new behavior (the setting starts at
> >> "auto", which is never resolved to yes or no; so the AC_DEFINE is left out).
> >>
> >> In any case, manually setting
> >> --enable/disable-s390-excess-float-precision takes precedence.
> > 
> > FWIW this means building GCC 11 for any older version of glibc or musl
> > will give a broken configuration unless you pass
> > --disable-s390-excess-float-precision to configure. I'm not sure if
> > anything should be done about that; at least I might want to handle it
> > in mcm...
> 
> I will look into handling cross compiles in a more differentiating way...

I can't think of any valid way to detect (note: at configure time you
might not even have libc available) but it might be more reasonable to
take the conservative default and assume a libc that can't handle the
new definition. For example compiling old musl with the new definition
will be caused the math library to be miscompiled.

> > In any case this probably means I should include your patch in this
> > release cycle so at least current version builds right.
> > 
> > BTW is there a -m option to override at runtime in order to test both
> > behaviors, so you don't have to build a new GCC from scratch to do it?
> 
> Yes, in the current GCC, -fexcess-precision=standard or fast switches
> between the two behaviors (i.e., both __FLT_EVAL_METHOD__ and emitted
> code; "fast" corresponds to the "new" behavior).

I mean in a GCC 11 built for the new behavior, where
-fexcess-precision=standard will no longer give __FLT_EVAL_METHOD__==1
because float_t is expected to be defined as float and FLT_EVAL_METHOD
as 0. Is there a -m option to tell it "behave like old GCC, where
-fexcess-precision=standard implies evaluation in double?

Rich

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2020-12-03 19:06 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-01 14:36 [musl] [PATCH] s390x: derive float_t from compiler or default to float Marius Hillenbrand
2020-12-01 20:50 ` Rich Felker
2020-12-02 10:44   ` Marius Hillenbrand
2020-12-02 14:25     ` Rich Felker
2020-12-02 16:01       ` Rich Felker
2020-12-02 17:09         ` Marius Hillenbrand
2020-12-02 19:13           ` Rich Felker
2020-12-03 16:53             ` Marius Hillenbrand
2020-12-03 19:06               ` Rich Felker

mailing list of musl libc

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://inbox.vuxu.org/musl

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 musl musl/ http://inbox.vuxu.org/musl \
		musl@inbox.vuxu.org
	public-inbox-index musl

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.musl


code repositories for the project(s) associated with this inbox:

	https://git.vuxu.org/mirror/musl/

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git