mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Marius Hillenbrand <mhillen@linux.ibm.com>
To: musl@lists.openwall.com
Cc: Marius Hillenbrand <mhillen@linux.ibm.com>
Subject: [musl] [PATCH] s390x: derive float_t from compiler or default to float
Date: Tue,  1 Dec 2020 15:36:34 +0100	[thread overview]
Message-ID: <20201201143634.13419-1-mhillen@linux.ibm.com> (raw)

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


             reply	other threads:[~2020-12-01 14:38 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-01 14:36 Marius Hillenbrand [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201201143634.13419-1-mhillen@linux.ibm.com \
    --to=mhillen@linux.ibm.com \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).