From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,NICE_REPLY_A,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 27470 invoked from network); 2 Dec 2020 17:10:08 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 2 Dec 2020 17:10:08 -0000 Received: (qmail 22512 invoked by uid 550); 2 Dec 2020 17:10:01 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 22494 invoked from network); 2 Dec 2020 17:10:01 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=subject : to : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=pp1; bh=eBFURl5C3JMDK4roOuXZ/YJ8DkIN4DjpiTMyO/RUdqg=; b=hjn/5VtpKyFo0h5x6unN0qGqMpjmuyWaCXpNYCiGTgOuBHChbxKMhV91SBihCK9jKx01 5LmkiVWVfq8cgYgeRqhAMtHIwGsf184edFO6Gnj/oFuu5zvyRUin9D+qNJdrZf407wkX oEJxF3ErPh+rA3pdbSQYSvKQlQeM9FrRHuWxuPNKNYW48LbZ83kNay/wMDXvY9JSna9Q i+Jrfisakx1g/S4H03wZ8HqrizvxdF2TZMCgSzbnZkRk2+FJSwY69vLffU3qx/wIguOB CqJA/RSN8IQP5+5irZ0hceRW6cJPwHCehQqCLZImPREQXG0E0PI4xYj/OER0jMVcCW3T /Q== To: musl@lists.openwall.com References: <20201201143634.13419-1-mhillen@linux.ibm.com> <20201201205020.GT534@brightrain.aerifal.cx> <3a1b3e6f-3978-4a7a-70b5-9bf18db7704b@linux.ibm.com> <20201202142504.GV534@brightrain.aerifal.cx> <20201202160140.GW534@brightrain.aerifal.cx> From: Marius Hillenbrand Message-ID: <0fda3e37-b513-91fc-f09e-cfca11a76a20@linux.ibm.com> Date: Wed, 2 Dec 2020 18:09:44 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0 MIME-Version: 1.0 In-Reply-To: <20201202160140.GW534@brightrain.aerifal.cx> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312,18.0.737 definitions=2020-12-02_08:2020-11-30,2020-12-02 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 mlxlogscore=999 spamscore=0 bulkscore=0 priorityscore=1501 impostorscore=0 clxscore=1015 adultscore=0 lowpriorityscore=0 malwarescore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012020096 Subject: Re: [musl] [PATCH] s390x: derive float_t from compiler or default to float 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