From patchwork Mon Nov 1 20:20:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 46917 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C7CC8385843A for ; Mon, 1 Nov 2021 20:22:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C7CC8385843A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1635798130; bh=NYvcMKQdqXVn9nonTtd1e5HedPpgt2AdUuiaIyF/bOA=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=E/+yLPNonn8ddr75eGTLF7j3D+QAEQAJdmao+qgAiZoEl+GV0Ia2Y5k/AkkcuH9e6 X5W4wlHtH2eZilo0iBp/RbvUQgv3rz3hAu3Hgw3omM0PSUSNtkJ0Jw4mCEeUFxQRPd 2V3IlXIWhyE5XBJ682ke5YK2MqNN5ujSfB7ARYQ4= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qt1-x830.google.com (mail-qt1-x830.google.com [IPv6:2607:f8b0:4864:20::830]) by sourceware.org (Postfix) with ESMTPS id 1DBFA385842E for ; Mon, 1 Nov 2021 20:21:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1DBFA385842E Received: by mail-qt1-x830.google.com with SMTP id s1so15623293qta.13 for ; Mon, 01 Nov 2021 13:21:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NYvcMKQdqXVn9nonTtd1e5HedPpgt2AdUuiaIyF/bOA=; b=bgtbY40kZ91zpDWqpAfmE5UUUMgFrnwpZSvnBIspC3sk1vjIKFDz1qrYq6B4DachyN Nib705rDpFcEfgZIzXY647i6O14dSl9fILInXgVYoT9PlUxhzNa2Rnt6MH+NBXTv5LeL GAnthwdzsTtIjvsdGCr9T9QLLd+Nj18BXKAlGYDUIsNhyLHB9PFo5lzkWe5ISEn0/Nai vB6dCS6M3oRqXvunuFHald2zoW1Btvsh/G18vruj48s5QZ+7cPpMdUhFFgYcA65wgr2/ QnbgWIQpcqTE7SQgtPnluPaojQkeCc+puHL9CZ3DS+FoCA46ZKBzb6IvE67D9yLswupz cDVA== X-Gm-Message-State: AOAM53003q/68dUZeEBsqQMOBwg4OFXH1PrkTZVOErge177lcvIHTd1/ qGsoocAEm2IeacbdThpthdVqFhUAOw37AA== X-Google-Smtp-Source: ABdhPJx1U5ElHE0M9KW82RPrcLmnBHV1MyZiBagCZYd5N9p/hJlhDRdD0k/j155eVz5PyVp0sse3Dg== X-Received: by 2002:a05:622a:14c7:: with SMTP id u7mr6655376qtx.241.1635798064397; Mon, 01 Nov 2021 13:21:04 -0700 (PDT) Received: from birita.. ([2804:431:c7cb:b64f:7c54:165f:8728:a193]) by smtp.gmail.com with ESMTPSA id d11sm10023965qtx.81.2021.11.01.13.21.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 13:21:04 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v3 1/7] math: Simplify hypotf implementation Date: Mon, 1 Nov 2021 17:20:53 -0300 Message-Id: <20211101202059.1026032-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211101202059.1026032-1-adhemerval.zanella@linaro.org> References: <20211101202059.1026032-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: Wilco Dijkstra Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Use a more optimized comparison for check for NaN and infinite and add an inlined issignaling implementation for float. With gcc it results in 2 FP comparisons. The file Copyright is also changed to use GPL, the implementation was completely changed by 7c10fd3515f to use double precision instead of scaling and this change removes all the GET_FLOAT_WORD usage. Checked on x86_64-linux-gnu. --- sysdeps/ieee754/flt-32/e_hypotf.c | 60 ++++++++++++---------------- sysdeps/ieee754/flt-32/math_config.h | 9 +++++ 2 files changed, 35 insertions(+), 34 deletions(-) diff --git a/sysdeps/ieee754/flt-32/e_hypotf.c b/sysdeps/ieee754/flt-32/e_hypotf.c index e770947dc1..ea18775829 100644 --- a/sysdeps/ieee754/flt-32/e_hypotf.c +++ b/sysdeps/ieee754/flt-32/e_hypotf.c @@ -1,46 +1,38 @@ -/* e_hypotf.c -- float version of e_hypot.c. - */ +/* Euclidean distance function. Float/Binary32 version. + Copyright (C) 2012-2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ #include #include +#include "math_config.h" #include float -__ieee754_hypotf(float x, float y) +__ieee754_hypotf (float x, float y) { - double d_x, d_y; - int32_t ha, hb; - - GET_FLOAT_WORD(ha,x); - ha &= 0x7fffffff; - GET_FLOAT_WORD(hb,y); - hb &= 0x7fffffff; - if (ha == 0x7f800000 && !issignaling (y)) - return fabsf(x); - else if (hb == 0x7f800000 && !issignaling (x)) - return fabsf(y); - else if (ha > 0x7f800000 || hb > 0x7f800000) - return fabsf(x) * fabsf(y); - else if (ha == 0) - return fabsf(y); - else if (hb == 0) - return fabsf(x); - - d_x = (double) x; - d_y = (double) y; + if (!isfinite(x) || !isfinite(y)) + { + if ((isinf (x) || isinf (y)) + && !issignalingf_inline (x) && !issignalingf_inline (y)) + return INFINITY; + return x + y; + } - return (float) sqrt(d_x * d_x + d_y * d_y); + return sqrt ((double) x * (double) x + (double) y * (double) y); } #ifndef __ieee754_hypotf libm_alias_finite (__ieee754_hypotf, __hypotf) diff --git a/sysdeps/ieee754/flt-32/math_config.h b/sysdeps/ieee754/flt-32/math_config.h index 513454a297..daa8a82f99 100644 --- a/sysdeps/ieee754/flt-32/math_config.h +++ b/sysdeps/ieee754/flt-32/math_config.h @@ -101,6 +101,15 @@ asdouble (uint64_t i) return u.f; } +static inline int +issignalingf_inline (float x) +{ + uint32_t ix = asuint (x); + if (HIGH_ORDER_BIT_IS_SET_FOR_SNAN) + return (ix & 0x7fc00000) == 0x7fc00000; + return 2 * (ix ^ 0x00400000) > 2 * 0x7fc00000UL; +} + #define NOINLINE __attribute__ ((noinline)) attribute_hidden float __math_oflowf (uint32_t); From patchwork Mon Nov 1 20:20:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 46918 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C26A4385803B for ; Mon, 1 Nov 2021 20:22:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C26A4385803B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1635798172; bh=1WX3AJhxYzokRhAd2/7VDvAm7Xucidp5SWfSwSGh558=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=fuZ1IWVWKX90flyr2WKlzJVbbMUsHg2h7U5x8SxHrkrKp6bE2QEkk1S+sa2Xitr52 1j6dAVv4Sz6U+/bjiKDNz7vk6kYjma0LmeasdaEmIYMlKBbbzBjzQxFVhoDArrb9E9 C1MQcynWmIj4AWxp6Ua/uEFp87l4+w6ZeLu2oqzc= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x730.google.com (mail-qk1-x730.google.com [IPv6:2607:f8b0:4864:20::730]) by sourceware.org (Postfix) with ESMTPS id D9F393858432 for ; Mon, 1 Nov 2021 20:21:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D9F393858432 Received: by mail-qk1-x730.google.com with SMTP id bp7so12502985qkb.10 for ; Mon, 01 Nov 2021 13:21:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1WX3AJhxYzokRhAd2/7VDvAm7Xucidp5SWfSwSGh558=; b=35S1C4jCoKFnBvTrIupEnK5/vyWmqSAha8eUFvlaeQ+uBGtcNONHfZHfH5uXAcseFk cvSJ5wCtMJRy/JoPno9ADmR6DBPjk1b1KkCZ5qEz2Ncwp6HEMnI/aDCruGqIJJ25G7LZ EfNBz/YrHOmYrm86NQNZmp8kxwe/mmLn23pvj+3EyPmWYKy5AlDbuo7NtYv830qNudWW ulruAIvEkvPDeK8YNh7wIKVTnTsFNjgnacKl8xNlH5Jl+V38Q5kK1l0oESuyY2BXhMmW OcvWzALrIOiv1WH1RHoq2wWe3FK36mpL3+76XDwhgywTKUNQnjA3txPPpCflWUvQCQUf bz1g== X-Gm-Message-State: AOAM532UHD9VSNGSiTk36Mxb25GOQpT2idXMr0NhZ1noPpibkAlruHmJ k48UyzWYbveZGCNErqXY0fxGO2QQntUcoQ== X-Google-Smtp-Source: ABdhPJzqT8CttHnDV9//9psqxpin4mfp62t8MUYEAjVEfZL9k5LQ/Qw7YKpj96qLOXOMV+//T47slQ== X-Received: by 2002:a05:620a:1a1c:: with SMTP id bk28mr11323678qkb.131.1635798067283; Mon, 01 Nov 2021 13:21:07 -0700 (PDT) Received: from birita.. ([2804:431:c7cb:b64f:7c54:165f:8728:a193]) by smtp.gmail.com with ESMTPSA id d11sm10023965qtx.81.2021.11.01.13.21.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 13:21:07 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v3 2/7] math: Use an improved algorithm for hypot (dbl-64) Date: Mon, 1 Nov 2021 17:20:54 -0300 Message-Id: <20211101202059.1026032-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211101202059.1026032-1-adhemerval.zanella@linaro.org> References: <20211101202059.1026032-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: Wilco Dijkstra Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" This implementation is based on the 'An Improved Algorithm for hypot(a,b)' by Carlos F. Borges [1] using the MyHypot3 with the following changes: - Handle qNaN and sNaN. - Tune the 'widely varying operands' to avoid spurious underflow due the multiplication and fix the return value for upwards rounding mode. - Handle required underflow exception for denormal results. The main advantage of the new algorithm is its precision: with a random 1e9 input pairs in the range of [DBL_MIN, DBL_MAX], glibc current implementation shows around 0.34% results with an error of 1 ulp (3424869 results) while the new implementation only shows 0.002% of total (18851). The performance result are also only slight worse than current implementation. On x86_64 (Ryzen 5900X) with gcc 12: Before: "hypot": { "workload-random": { "duration": 3.73319e+09, "iterations": 1.12e+08, "reciprocal-throughput": 22.8737, "latency": 43.7904, "max-throughput": 4.37184e+07, "min-throughput": 2.28361e+07 } } After: "hypot": { "workload-random": { "duration": 3.74534e+09, "iterations": 9.8e+07, "reciprocal-throughput": 25.8957, "latency": 50.5399, "max-throughput": 3.86164e+07, "min-throughput": 1.97864e+07 } } Co-Authored-By: Paul Zimmermann Checked on x86_64-linux-gnu and aarch64-linux-gnu. [1] https://arxiv.org/pdf/1904.09481.pdf --- sysdeps/ieee754/dbl-64/e_hypot.c | 225 ++++++++++++------------------- 1 file changed, 87 insertions(+), 138 deletions(-) diff --git a/sysdeps/ieee754/dbl-64/e_hypot.c b/sysdeps/ieee754/dbl-64/e_hypot.c index 9ec4c1ced0..638bf019ad 100644 --- a/sysdeps/ieee754/dbl-64/e_hypot.c +++ b/sysdeps/ieee754/dbl-64/e_hypot.c @@ -1,164 +1,113 @@ -/* @(#)e_hypot.c 5.1 93/09/24 */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ +/* Euclidean distance function. Double/Binary64 version. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. -/* __ieee754_hypot(x,y) - * - * Method : - * If (assume round-to-nearest) z=x*x+y*y - * has error less than sqrt(2)/2 ulp, than - * sqrt(z) has error less than 1 ulp (exercise). - * - * So, compute sqrt(x*x+y*y) with some care as - * follows to get the error below 1 ulp: - * - * Assume x>y>0; - * (if possible, set rounding to round-to-nearest) - * 1. if x > 2y use - * x1*x1+(y*y+(x2*(x+x1))) for x*x+y*y - * where x1 = x with lower 32 bits cleared, x2 = x-x1; else - * 2. if x <= 2y use - * t1*y1+((x-y)*(x-y)+(t1*y2+t2*y)) - * where t1 = 2x with lower 32 bits cleared, t2 = 2x-t1, - * y1= y with lower 32 bits chopped, y2 = y-y1. - * - * NOTE: scaling may be necessary if some argument is too - * large or too tiny - * - * Special cases: - * hypot(x,y) is INF if x or y is +INF or -INF; else - * hypot(x,y) is NAN if x or y is NAN. - * - * Accuracy: - * hypot(x,y) returns sqrt(x^2+y^2) with error less - * than 1 ulps (units in the last place) - */ + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +/* This implementation is based on 'An Improved Algorithm for hypot(a,b)' by + Carlos F. Borges [1] using the MyHypot3 with the following changes: + + - Handle qNaN and sNaN. + - Tune the 'widely varying operands' to avoid spurious underflow + due the multiplication and fix the return value for upwards + rounding mode. + - Handle required underflow exception for subnormal results. + + [1] https://arxiv.org/pdf/1904.09481.pdf */ #include #include #include +#include #include +#include + +/* sqrt (DBL_EPSILON / 2.0) */ +#define SQRT_EPS_DIV_2 0x1.6a09e667f3bcdp-27 +/* DBL_MIN / (sqrt (DBL_EPSILON / 2.0)) */ +#define DBL_MIN_THRESHOLD 0x1.6a09e667f3bcdp-996 +/* eps (double) * sqrt (DBL_MIN)) */ +#define SCALE 0x1p-563 +/* 1 / eps (sqrt (DBL_MIN) */ +#define INV_SCALE 0x1p+563 +/* sqrt (DBL_MAX) */ +#define SQRT_DBL_MAX 0x1.6a09e667f3bccp+511 +/* sqrt (DBL_MIN) */ +#define SQRT_DBL_MIN 0x1p-511 double __ieee754_hypot (double x, double y) { - double a, b, t1, t2, y1, y2, w; - int32_t j, k, ha, hb; - - GET_HIGH_WORD (ha, x); - ha &= 0x7fffffff; - GET_HIGH_WORD (hb, y); - hb &= 0x7fffffff; - if (hb > ha) - { - a = y; b = x; j = ha; ha = hb; hb = j; - } - else + if (!isfinite(x) || !isfinite(y)) { - a = x; b = y; + if ((isinf (x) || isinf (y)) + && !issignaling_inline (x) && !issignaling_inline (y)) + return INFINITY; + return x + y; } - SET_HIGH_WORD (a, ha); /* a <- |a| */ - SET_HIGH_WORD (b, hb); /* b <- |b| */ - if ((ha - hb) > 0x3c00000) - { - return a + b; - } /* x/y > 2**60 */ - k = 0; - if (__glibc_unlikely (ha > 0x5f300000)) /* a>2**500 */ + + double ax = fabs (x); + double ay = fabs (y); + if (ay > ax) { - if (ha >= 0x7ff00000) /* Inf or NaN */ - { - uint32_t low; - w = a + b; /* for sNaN */ - if (issignaling (a) || issignaling (b)) - return w; - GET_LOW_WORD (low, a); - if (((ha & 0xfffff) | low) == 0) - w = a; - GET_LOW_WORD (low, b); - if (((hb ^ 0x7ff00000) | low) == 0) - w = b; - return w; - } - /* scale a and b by 2**-600 */ - ha -= 0x25800000; hb -= 0x25800000; k += 600; - SET_HIGH_WORD (a, ha); - SET_HIGH_WORD (b, hb); + double tmp = ax; + ax = ay; + ay = tmp; } - if (__builtin_expect (hb < 0x23d00000, 0)) /* b < 2**-450 */ + + /* Widely varying operands. The DBL_MIN_THRESHOLD check is used to avoid + a spurious underflow from the multiplication. */ + if (ax >= DBL_MIN_THRESHOLD && ay <= ax * SQRT_EPS_DIV_2) + return (ay == 0.0) ? ax : math_narrow_eval (ax + DBL_TRUE_MIN); + + double scale = SCALE; + if (ax > SQRT_DBL_MAX) { - if (hb <= 0x000fffff) /* subnormal b or 0 */ - { - uint32_t low; - GET_LOW_WORD (low, b); - if ((hb | low) == 0) - return a; - t1 = 0; - SET_HIGH_WORD (t1, 0x7fd00000); /* t1=2^1022 */ - b *= t1; - a *= t1; - k -= 1022; - GET_HIGH_WORD (ha, a); - GET_HIGH_WORD (hb, b); - if (hb > ha) - { - t1 = a; - a = b; - b = t1; - j = ha; - ha = hb; - hb = j; - } - } - else /* scale a and b by 2^600 */ - { - ha += 0x25800000; /* a *= 2^600 */ - hb += 0x25800000; /* b *= 2^600 */ - k -= 600; - SET_HIGH_WORD (a, ha); - SET_HIGH_WORD (b, hb); - } + ax *= scale; + ay *= scale; + scale = INV_SCALE; } - /* medium size a and b */ - w = a - b; - if (w > b) + else if (ay < SQRT_DBL_MIN) { - t1 = 0; - SET_HIGH_WORD (t1, ha); - t2 = a - t1; - w = sqrt (t1 * t1 - (b * (-b) - t2 * (a + t1))); + ax /= scale; + ay /= scale; } else + scale = 1.0; + + double h = sqrt (ax * ax + ay * ay); + + double t1, t2; + if (h == 0.0) + return h; + else if (h <= 2.0 * ay) { - a = a + a; - y1 = 0; - SET_HIGH_WORD (y1, hb); - y2 = b - y1; - t1 = 0; - SET_HIGH_WORD (t1, ha + 0x00100000); - t2 = a - t1; - w = sqrt (t1 * y1 - (w * (-w) - (t1 * y2 + t2 * b))); + double delta = h - ay; + t1 = ax * (2.0 * delta - ax); + t2 = (delta - 2.0 * (ax - ay)) * delta; } - if (k != 0) + else { - uint32_t high; - t1 = 1.0; - GET_HIGH_WORD (high, t1); - SET_HIGH_WORD (t1, high + (k << 20)); - w *= t1; - math_check_force_underflow_nonneg (w); - return w; + double delta = h - ax; + t1 = 2.0 * delta * (ax - 2 * ay); + t2 = (4.0 * delta - ay) * ay + delta * delta; } - else - return w; + h -= (t1 + t2) / (2.0 * h); + h = math_narrow_eval (h * scale); + math_check_force_underflow_nonneg (h); + return h; } #ifndef __ieee754_hypot libm_alias_finite (__ieee754_hypot, __hypot) From patchwork Mon Nov 1 20:20:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 46919 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1EA2B3858023 for ; Mon, 1 Nov 2021 20:23:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1EA2B3858023 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1635798215; bh=B/ia2Dyjl/lc3zFhG4ZW3b61ZeEaT/wlxrtvMaqW0/k=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=yLdhLvgaYU9CX/d3w1YP93bYKZdNpg9t8hvMVCrWVpKnK8dddETzPo7vGMWzvVNLu UgNIhSNs1gNeHy3j92xfe13rUNGkSmEFMS6fV+IUEVC44j+1D0MD/u+yMOCsUXMC4R QewbDnubXvsb+QFpEZu2i/13KsS/8zRLDY5KGrWw= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qt1-x835.google.com (mail-qt1-x835.google.com [IPv6:2607:f8b0:4864:20::835]) by sourceware.org (Postfix) with ESMTPS id 5D4113858403 for ; Mon, 1 Nov 2021 20:21:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5D4113858403 Received: by mail-qt1-x835.google.com with SMTP id n2so17039868qta.2 for ; Mon, 01 Nov 2021 13:21:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=B/ia2Dyjl/lc3zFhG4ZW3b61ZeEaT/wlxrtvMaqW0/k=; b=QnDNMP89Yyd+jso2KeOuVnCd2IW2VTDZ9FpX5vi+632umNfSpTK0ODflhARgGvbCdx wUl4VAx5lnAFMnZMChUjLw+HzBBQNbQp+XJFXGr29pQfaQWeVyvNvTG1hMlogICLOxpx 6yya/Gox4HIdlyG34H5+OAIEQvyL3uYtpN9DQZT3Ukw96pF1wexZTM866BXvOGtMOC+S FchBx5oGKJNoQkiAjwKdPt1kkhb6F4DnJWFiN6rz49kFIfXNEUhPn2hvzTeIPRHkGJEa PpmeyA0SD+s49YWCm84ajBEsPTxyUS5lr1xNgnOTglTTCKvw6qrhebyRIorhNPMkx/Uh xFbw== X-Gm-Message-State: AOAM533FWEG76xQcMrcK8oAl6cBYuQ7N1ZUBGAygrrtbrCk7b6WllIH3 OtByqk34vbRVZZnf6w+k/G6vdGV8dDKAAg== X-Google-Smtp-Source: ABdhPJycXL3cjqxeZtkmBeP6PJk8Y6Uv5FKYujfRV4OqH3uiC7bptD6/3nHVj75yXjUecNIn4uUk2w== X-Received: by 2002:a05:622a:1996:: with SMTP id u22mr6527898qtc.128.1635798068728; Mon, 01 Nov 2021 13:21:08 -0700 (PDT) Received: from birita.. ([2804:431:c7cb:b64f:7c54:165f:8728:a193]) by smtp.gmail.com with ESMTPSA id d11sm10023965qtx.81.2021.11.01.13.21.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 13:21:08 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v3 3/7] math: Use an improved algorithm for hypotl (ldbl-96) Date: Mon, 1 Nov 2021 17:20:55 -0300 Message-Id: <20211101202059.1026032-4-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211101202059.1026032-1-adhemerval.zanella@linaro.org> References: <20211101202059.1026032-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: Wilco Dijkstra Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" This implementation is based on 'An Improved Algorithm for hypot(a,b)' by Carlos F. Borges [1] using the MyHypot3 with the following changes: - Handle qNaN and sNaN. - Tune the 'widely varying operands' to avoid spurious underflow due the multiplication and fix the return value for upwards rounding mode. - Handle required underflow exception for subnormal results. The main advantage of the new algorithm is its precision. With a random 1e8 input pairs in the range of [LDBL_MIN, LDBL_MAX], glibc current implementation shows around 0.02% results with an error of 1 ulp (23158 results) while the new implementation only shows 0.0001% of total (111). [1] https://arxiv.org/pdf/1904.09481.pdf --- sysdeps/ieee754/ldbl-96/e_hypotl.c | 229 +++++++++++++---------------- 1 file changed, 99 insertions(+), 130 deletions(-) diff --git a/sysdeps/ieee754/ldbl-96/e_hypotl.c b/sysdeps/ieee754/ldbl-96/e_hypotl.c index 44e72353c0..1363dce16c 100644 --- a/sysdeps/ieee754/ldbl-96/e_hypotl.c +++ b/sysdeps/ieee754/ldbl-96/e_hypotl.c @@ -1,142 +1,111 @@ -/* e_hypotl.c -- long double version of e_hypot.c. - */ +/* Euclidean distance function. Long Double/Binary96 version. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. -/* __ieee754_hypotl(x,y) - * - * Method : - * If (assume round-to-nearest) z=x*x+y*y - * has error less than sqrt(2)/2 ulp, than - * sqrt(z) has error less than 1 ulp (exercise). - * - * So, compute sqrt(x*x+y*y) with some care as - * follows to get the error below 1 ulp: - * - * Assume x>y>0; - * (if possible, set rounding to round-to-nearest) - * 1. if x > 2y use - * x1*x1+(y*y+(x2*(x+x1))) for x*x+y*y - * where x1 = x with lower 32 bits cleared, x2 = x-x1; else - * 2. if x <= 2y use - * t1*y1+((x-y)*(x-y)+(t1*y2+t2*y)) - * where t1 = 2x with lower 32 bits cleared, t2 = 2x-t1, - * y1= y with lower 32 bits chopped, y2 = y-y1. - * - * NOTE: scaling may be necessary if some argument is too - * large or too tiny - * - * Special cases: - * hypot(x,y) is INF if x or y is +INF or -INF; else - * hypot(x,y) is NAN if x or y is NAN. - * - * Accuracy: - * hypot(x,y) returns sqrt(x^2+y^2) with error less - * than 1 ulps (units in the last place) - */ + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +/* This implementation is based on 'An Improved Algorithm for hypot(a,b)' by + Carlos F. Borges [1] using the MyHypot3 with the following changes: + + - Handle qNaN and sNaN. + - Tune the 'widely varying operands' to avoid spurious underflow + due the multiplication and fix the return value for upwards + rounding mode. + - Handle required underflow exception for subnormal results. + + [1] https://arxiv.org/pdf/1904.09481.pdf */ #include #include #include #include -long double __ieee754_hypotl(long double x, long double y) +/* sqrt (LDBL_EPSILON / 2.0) */ +#define SQRT_EPS_DIV_2 0x8p-35L +/* DBL_MIN / (sqrt (LDBL_EPSILON / 2.0)) */ +#define LDBL_MIN_THRESHOLD 0x8p-16353L +/* eps (long double) * sqrt (LDBL_MIN) */ +#define SCALE 0x8p-8257L +/* 1 / eps (sqrt (LDBL_MIN) */ +#define INV_SCALE 0x8p+8251L +/* sqrt (LDBL_MAX) */ +#define SQRT_LDBL_MAX 0xb.504f333f9de6484p+8188L +/* sqrt (LDBL_MIN) */ +#define SQRT_LDBL_MIN 0x8p-8194L + +long double +__ieee754_hypotl (long double x, long double y) { - long double a,b,t1,t2,y1,y2,w; - uint32_t j,k,ea,eb; + if (!isfinite(x) || !isfinite(y)) + { + if ((isinf (x) || isinf (y)) + && !issignaling (x) && !issignaling (y)) + return INFINITY; + return x + y; + } + + long double ax = fabsl (x); + long double ay = fabsl (y); + if (ay > ax) + { + long double tmp = ax; + ax = ay; + ay = tmp; + } + + /* Widely varying operands. The LDBL_MIN_THRESHOLD check is used to avoid + a spurious underflow from the multiplication. */ + if (ax >= LDBL_MIN_THRESHOLD && ay <= ax * SQRT_EPS_DIV_2) + return (ay == 0.0) ? ax : ax + LDBL_TRUE_MIN; + + long double scale = SCALE; + if (ax > SQRT_LDBL_MAX) + { + ax *= scale; + ay *= scale; + scale = INV_SCALE; + } + else if (ay < SQRT_LDBL_MIN) + { + ax /= scale; + ay /= scale; + } + else + scale = 1.0L; + + long double h = sqrtl (ax * ax + ay * ay); - GET_LDOUBLE_EXP(ea,x); - ea &= 0x7fff; - GET_LDOUBLE_EXP(eb,y); - eb &= 0x7fff; - if(eb > ea) {a=y;b=x;j=ea; ea=eb;eb=j;} else {a=x;b=y;} - SET_LDOUBLE_EXP(a,ea); /* a <- |a| */ - SET_LDOUBLE_EXP(b,eb); /* b <- |b| */ - if((ea-eb)>0x46) {return a+b;} /* x/y > 2**70 */ - k=0; - if(__builtin_expect(ea > 0x5f3f,0)) { /* a>2**8000 */ - if(ea == 0x7fff) { /* Inf or NaN */ - uint32_t exp __attribute__ ((unused)); - uint32_t high,low; - w = a+b; /* for sNaN */ - if (issignaling (a) || issignaling (b)) - return w; - GET_LDOUBLE_WORDS(exp,high,low,a); - if(((high&0x7fffffff)|low)==0) w = a; - GET_LDOUBLE_WORDS(exp,high,low,b); - if(((eb^0x7fff)|(high&0x7fffffff)|low)==0) w = b; - return w; - } - /* scale a and b by 2**-9600 */ - ea -= 0x2580; eb -= 0x2580; k += 9600; - SET_LDOUBLE_EXP(a,ea); - SET_LDOUBLE_EXP(b,eb); - } - if(__builtin_expect(eb < 0x20bf, 0)) { /* b < 2**-8000 */ - if(eb == 0) { /* subnormal b or 0 */ - uint32_t exp __attribute__ ((unused)); - uint32_t high,low; - GET_LDOUBLE_WORDS(exp,high,low,b); - if((high|low)==0) return a; - SET_LDOUBLE_WORDS(t1, 0x7ffd, 0x80000000, 0); /* t1=2^16382 */ - b *= t1; - a *= t1; - k -= 16382; - GET_LDOUBLE_EXP (ea, a); - GET_LDOUBLE_EXP (eb, b); - if (eb > ea) - { - t1 = a; - a = b; - b = t1; - j = ea; - ea = eb; - eb = j; - } - } else { /* scale a and b by 2^9600 */ - ea += 0x2580; /* a *= 2^9600 */ - eb += 0x2580; /* b *= 2^9600 */ - k -= 9600; - SET_LDOUBLE_EXP(a,ea); - SET_LDOUBLE_EXP(b,eb); - } - } - /* medium size a and b */ - w = a-b; - if (w>b) { - uint32_t high; - GET_LDOUBLE_MSW(high,a); - SET_LDOUBLE_WORDS(t1,ea,high,0); - t2 = a-t1; - w = sqrtl(t1*t1-(b*(-b)-t2*(a+t1))); - } else { - uint32_t high; - GET_LDOUBLE_MSW(high,b); - a = a+a; - SET_LDOUBLE_WORDS(y1,eb,high,0); - y2 = b - y1; - GET_LDOUBLE_MSW(high,a); - SET_LDOUBLE_WORDS(t1,ea+1,high,0); - t2 = a - t1; - w = sqrtl(t1*y1-(w*(-w)-(t1*y2+t2*b))); - } - if(k!=0) { - uint32_t exp; - t1 = 1.0; - GET_LDOUBLE_EXP(exp,t1); - SET_LDOUBLE_EXP(t1,exp+k); - w *= t1; - math_check_force_underflow_nonneg (w); - return w; - } else return w; + long double t1; + long double t2; + if (h == 0.0L) + return h; + if (h <= 2.0L * ay) + { + long double delta = h - ay; + t1 = ax * (2.0L * delta - ax); + t2 = (delta - 2.0L * (ax - ay)) * delta; + } + else + { + long double delta = h - ax; + t1 = 2.0L * delta * (ax - 2.0L * ay); + t2 = (4.0L * delta - ay) * ay + delta * delta; + } + h -= (t1 + t2) / (2.0L * h); + h *= scale; + math_check_force_underflow_nonneg (h); + return h; } libm_alias_finite (__ieee754_hypotl, __hypotl) From patchwork Mon Nov 1 20:20:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 46920 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8BC7F385802B for ; Mon, 1 Nov 2021 20:24:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8BC7F385802B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1635798263; bh=JV9NVd9pYhvrmIpR52JbY4sZFWLAXpo0DtuUOU5hVDs=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=EjIxMo5eEPi//JG8fFPMzR22reZqrCG6jMlCIyT4TEeXCyqk3oEZR9NXXPkXxxH+M iwhqONIYZ+t6BCRnvph5dDgbVTRLkVBwoI9OSgBdwpNfCHGwQc5h8likv4MrMibdIi ZDFHMVQ/+4QNuyntKXnic/cDTp457RMqpBmK14S0= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x731.google.com (mail-qk1-x731.google.com [IPv6:2607:f8b0:4864:20::731]) by sourceware.org (Postfix) with ESMTPS id A48303858001 for ; Mon, 1 Nov 2021 20:21:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A48303858001 Received: by mail-qk1-x731.google.com with SMTP id bl12so3461791qkb.13 for ; Mon, 01 Nov 2021 13:21:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JV9NVd9pYhvrmIpR52JbY4sZFWLAXpo0DtuUOU5hVDs=; b=aiF6BtWQ9iriMv7dko0Wn3Hyidkyz+elS8BGJew7YzbDbNuHBk1zdi/VI8BxYuhybE 0nUuBIkK3vqhA8y44Nt/wIm2BUiA91cu/AFDfXbDvPcEuIwIXA3fCND/QXSh7s8kqLa9 nje3ZtJJURCTWWWNsrH4LZF4meg34pwTuQiIpaWy42zRI5r7wIbJ3gIo++YZSBzjysXN v42dnxIckOZg3MZNZGr5BJZc0VZXMlJ651paQZ6Ec6nCYhRbqVhe1tsstmAveQRszQek sUme6pn97mS/xOnyW6TTkDbXmEgZebbDokVv2Ay55mqkER42jgiOYfR01sXAbQ6uYFo2 HnNw== X-Gm-Message-State: AOAM531zPf0g+AxV4NLw8rbP2DKIoG6ne3JETaOinlRU6YgqqDs1nGHj UfxBgoFQqCHJc3JMx/bkubNDqos3r5ZXjg== X-Google-Smtp-Source: ABdhPJxstKPg0DjnsDkSyUslB/PVGEyRvj6yEWnKyj0aYQn/OkzL3LffnsMJ8anOsFG7VAWqLFKsvw== X-Received: by 2002:a05:620a:1910:: with SMTP id bj16mr12383514qkb.34.1635798070113; Mon, 01 Nov 2021 13:21:10 -0700 (PDT) Received: from birita.. ([2804:431:c7cb:b64f:7c54:165f:8728:a193]) by smtp.gmail.com with ESMTPSA id d11sm10023965qtx.81.2021.11.01.13.21.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 13:21:09 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v3 4/7] math: Use an improved algorithm for hypotl (ldbl-128) Date: Mon, 1 Nov 2021 17:20:56 -0300 Message-Id: <20211101202059.1026032-5-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211101202059.1026032-1-adhemerval.zanella@linaro.org> References: <20211101202059.1026032-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: Wilco Dijkstra Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" This implementation is based on 'An Improved Algorithm for hypot(a,b)' by Carlos F. Borges [1] using the MyHypot3 with the following changes: - Handle qNaN and sNaN. - Tune the 'widely varying operands' to avoid spurious underflow due the multiplication and fix the return value for upwards rounding mode. - Handle required underflow exception for subnormal results. The main advantage of the new algorithm is its precision. With a random 1e9 input pairs in the range of [LDBL_MIN, LDBL_MAX], glibc current implementation shows around 0.05% results with an error of 1 ulp (453266 results) while the new implementation only shows 0.0001% of total (1280). Checked on aarch64-linux-gnu and x86_64-linux-gnu. [1] https://arxiv.org/pdf/1904.09481.pdf --- sysdeps/ieee754/ldbl-128/e_hypotl.c | 224 ++++++++++++---------------- 1 file changed, 97 insertions(+), 127 deletions(-) diff --git a/sysdeps/ieee754/ldbl-128/e_hypotl.c b/sysdeps/ieee754/ldbl-128/e_hypotl.c index cd4fdbc4a6..c5068e330a 100644 --- a/sysdeps/ieee754/ldbl-128/e_hypotl.c +++ b/sysdeps/ieee754/ldbl-128/e_hypotl.c @@ -1,141 +1,111 @@ -/* e_hypotl.c -- long double version of e_hypot.c. - */ +/* Euclidean distance function. Long Double/Binary128 version. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. -/* __ieee754_hypotl(x,y) - * - * Method : - * If (assume round-to-nearest) z=x*x+y*y - * has error less than sqrtl(2)/2 ulp, than - * sqrtl(z) has error less than 1 ulp (exercise). - * - * So, compute sqrtl(x*x+y*y) with some care as - * follows to get the error below 1 ulp: - * - * Assume x>y>0; - * (if possible, set rounding to round-to-nearest) - * 1. if x > 2y use - * x1*x1+(y*y+(x2*(x+x1))) for x*x+y*y - * where x1 = x with lower 64 bits cleared, x2 = x-x1; else - * 2. if x <= 2y use - * t1*y1+((x-y)*(x-y)+(t1*y2+t2*y)) - * where t1 = 2x with lower 64 bits cleared, t2 = 2x-t1, - * y1= y with lower 64 bits chopped, y2 = y-y1. - * - * NOTE: scaling may be necessary if some argument is too - * large or too tiny - * - * Special cases: - * hypotl(x,y) is INF if x or y is +INF or -INF; else - * hypotl(x,y) is NAN if x or y is NAN. - * - * Accuracy: - * hypotl(x,y) returns sqrtl(x^2+y^2) with error less - * than 1 ulps (units in the last place) - */ + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +/* This implementation is based on 'An Improved Algorithm for hypot(a,b)' by + Carlos F. Borges [1] using the MyHypot3 with the following changes: + + - Handle qNaN and sNaN. + - Tune the 'widely varying operands' to avoid spurious underflow + due the multiplication and fix the return value for upwards + rounding mode. + - Handle required underflow exception for subnormal results. + + [1] https://arxiv.org/pdf/1904.09481.pdf */ #include #include #include #include +/* sqrt (LDBL_EPSILON / 2.0) */ +#define SQRT_EPS_DIV_2 L(0x1.6a09e667f3bcc908b2fb1366ea95p-57) +/* DBL_MIN / (sqrt (LDBL_EPSILON / 2.0)) */ +#define LDBL_MIN_THRESHOLD L(0x1.6a09e667f3bcc908b2fb1366ea96p-16326) +/* eps (long double) *(sqrt (LDBL_MIN) */ +#define SCALE L(0x1p-8303) +/* 1 / eps (sqrt (LDBL_MIN) */ +#define INV_SCALE L(0x1p+8303) +/* sqrt (LDBL_MAX) */ +#define SQRT_LDBL_MAX L(0x1.6a09e667f3bcc908b2fb1366ea95p+8191) +/* sqrt (LDBL_MIN) */ +#define SQRT_LDBL_MIN L(0x1p-8191) + _Float128 __ieee754_hypotl(_Float128 x, _Float128 y) { - _Float128 a,b,t1,t2,y1,y2,w; - int64_t j,k,ha,hb; + if (!isfinite(x) || !isfinite(y)) + { + if ((isinf (x) || isinf (y)) + && !issignaling (x) && !issignaling (y)) + return INFINITY; + return x + y; + } + + _Float128 ax = fabsl (x); + _Float128 ay = fabsl (y); + if (ay > ax) + { + _Float128 tmp = ax; + ax = ay; + ay = tmp; + } + + /* Widely varying operands. The DBL_MIN_THRESHOLD check is used to avoid + an spurious underflow from the multiplication. */ + if (ax >= LDBL_MIN_THRESHOLD && ay <= ax * SQRT_EPS_DIV_2) + return (ay == 0.0) ? ax : ax + LDBL_TRUE_MIN; + + _Float128 scale = SCALE; + if (ax > SQRT_LDBL_MAX) + { + ax *= scale; + ay *= scale; + scale = INV_SCALE; + } + else if (ay < SQRT_LDBL_MIN) + { + ax /= scale; + ay /= scale; + } + else + scale = 1.0; + + _Float128 h = sqrtl (ax * ax + ay * ay); - GET_LDOUBLE_MSW64(ha,x); - ha &= 0x7fffffffffffffffLL; - GET_LDOUBLE_MSW64(hb,y); - hb &= 0x7fffffffffffffffLL; - if(hb > ha) {a=y;b=x;j=ha; ha=hb;hb=j;} else {a=x;b=y;} - SET_LDOUBLE_MSW64(a,ha); /* a <- |a| */ - SET_LDOUBLE_MSW64(b,hb); /* b <- |b| */ - if((ha-hb)>0x78000000000000LL) {return a+b;} /* x/y > 2**120 */ - k=0; - if(ha > 0x5f3f000000000000LL) { /* a>2**8000 */ - if(ha >= 0x7fff000000000000LL) { /* Inf or NaN */ - uint64_t low; - w = a+b; /* for sNaN */ - if (issignaling (a) || issignaling (b)) - return w; - GET_LDOUBLE_LSW64(low,a); - if(((ha&0xffffffffffffLL)|low)==0) w = a; - GET_LDOUBLE_LSW64(low,b); - if(((hb^0x7fff000000000000LL)|low)==0) w = b; - return w; - } - /* scale a and b by 2**-9600 */ - ha -= 0x2580000000000000LL; - hb -= 0x2580000000000000LL; k += 9600; - SET_LDOUBLE_MSW64(a,ha); - SET_LDOUBLE_MSW64(b,hb); - } - if(hb < 0x20bf000000000000LL) { /* b < 2**-8000 */ - if(hb <= 0x0000ffffffffffffLL) { /* subnormal b or 0 */ - uint64_t low; - GET_LDOUBLE_LSW64(low,b); - if((hb|low)==0) return a; - t1=0; - SET_LDOUBLE_MSW64(t1,0x7ffd000000000000LL); /* t1=2^16382 */ - b *= t1; - a *= t1; - k -= 16382; - GET_LDOUBLE_MSW64 (ha, a); - GET_LDOUBLE_MSW64 (hb, b); - if (hb > ha) - { - t1 = a; - a = b; - b = t1; - j = ha; - ha = hb; - hb = j; - } - } else { /* scale a and b by 2^9600 */ - ha += 0x2580000000000000LL; /* a *= 2^9600 */ - hb += 0x2580000000000000LL; /* b *= 2^9600 */ - k -= 9600; - SET_LDOUBLE_MSW64(a,ha); - SET_LDOUBLE_MSW64(b,hb); - } - } - /* medium size a and b */ - w = a-b; - if (w>b) { - t1 = 0; - SET_LDOUBLE_MSW64(t1,ha); - t2 = a-t1; - w = sqrtl(t1*t1-(b*(-b)-t2*(a+t1))); - } else { - a = a+a; - y1 = 0; - SET_LDOUBLE_MSW64(y1,hb); - y2 = b - y1; - t1 = 0; - SET_LDOUBLE_MSW64(t1,ha+0x0001000000000000LL); - t2 = a - t1; - w = sqrtl(t1*y1-(w*(-w)-(t1*y2+t2*b))); - } - if(k!=0) { - uint64_t high; - t1 = 1; - GET_LDOUBLE_MSW64(high,t1); - SET_LDOUBLE_MSW64(t1,high+(k<<48)); - w *= t1; - math_check_force_underflow_nonneg (w); - return w; - } else return w; + _Float128 t1; + _Float128 t2; + if (h == 0.0) + return h; + if (h <= 2.0 * ay) + { + _Float128 delta = h - ay; + t1 = ax * (2.0 * delta - ax); + t2 = (delta - 2.0 * (ax - ay)) * delta; + } + else + { + _Float128 delta = h - ax; + t1 = 2.0 * delta * (ax - 2 * ay); + t2 = (4.0 * delta - ay) * ay + delta * delta; + } + h -= (t1 + t2) / (2.0 * h); + h *= scale; + math_check_force_underflow_nonneg (h); + return h; } libm_alias_finite (__ieee754_hypotl, __hypotl) From patchwork Mon Nov 1 20:20:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 46922 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 569ED3858025 for ; Mon, 1 Nov 2021 20:25:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 569ED3858025 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1635798348; bh=MTUrYwPqg+huc/QJSRndkANLkJZDs5F7aSW+oJwdO1Y=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=CdNrixz+GnjILQtbbRoCiZO9icJw1iqYuwVgQEug0HNgFoomwJmwe4bT9TMFlWFzS +CVzoaRBswo9ypmmSJCzHRwJbVGykdYISSAFKmFAlq1ScwwQUpN8Rlpz3TfyIXmXfn pOOp4ER8IMXUyvKyC6H2x9S+Rxj1rUVrtDRjf7LY= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x729.google.com (mail-qk1-x729.google.com [IPv6:2607:f8b0:4864:20::729]) by sourceware.org (Postfix) with ESMTPS id 59BA53858039 for ; Mon, 1 Nov 2021 20:21:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 59BA53858039 Received: by mail-qk1-x729.google.com with SMTP id r8so3918220qkp.4 for ; Mon, 01 Nov 2021 13:21:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MTUrYwPqg+huc/QJSRndkANLkJZDs5F7aSW+oJwdO1Y=; b=CiR3bXJB6kAMHxbSab2p3NZ91s7exY00aZVMbK2CWLdHSnEsYat7K32MNNxpsLpPWn b/5Z5TMNYb2gkL/vsXoYJ0uiIunK+/yjPDcyDQDYrvDDUkG9jc7IHA5jeLI1hmHTlkIs yCTtvygsnwzBmdZ7osYECBqAwdWWviqFVetHeEwZcKi48e0eVeOQEe1B6Q5M7PJki5Mb iZH842ymNqdXVdCJkRfkUaal4/tHmolEVCj1rGoeMVqtAmP0lROoWTPLPB1A0xhyEC9R lrk4gV6wHBNhp8AbUZ4JhU/IlOaA8XM0COKh1UIdrw+CeZ7M53WPGNxbKVaQgwH08piW GbGQ== X-Gm-Message-State: AOAM530oRq/D3uxorVGRyn0s9omZGG6PjbD6vgTmi7WCfTXyovtsl5Un SwWqtIT2blt423Cj9g7XEigB7TPXYRe92w== X-Google-Smtp-Source: ABdhPJxmwXXaYZGMyfuvENqZukOU2HznBVdQo2rUxz+kHNYd3il6p4Z6V2gp6xADto/coWC7XQrXXA== X-Received: by 2002:a05:620a:44c1:: with SMTP id y1mr14510376qkp.265.1635798071491; Mon, 01 Nov 2021 13:21:11 -0700 (PDT) Received: from birita.. ([2804:431:c7cb:b64f:7c54:165f:8728:a193]) by smtp.gmail.com with ESMTPSA id d11sm10023965qtx.81.2021.11.01.13.21.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 13:21:11 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v3 5/7] math: Remove powerpc e_hypot Date: Mon, 1 Nov 2021 17:20:57 -0300 Message-Id: <20211101202059.1026032-6-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211101202059.1026032-1-adhemerval.zanella@linaro.org> References: <20211101202059.1026032-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TVD_SUBJ_WIPE_DEBT, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: Wilco Dijkstra Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" The powerpc64 does show a big difference (which is mitigated slightly by the last path): power9 master: "hypot": { "workload-random": { "duration": 5.41027e+08, "iterations": 3.6e+07, "reciprocal-throughput": 14.6467, "latency": 15.4103, "max-throughput": 6.82746e+07, "min-throughput": 6.48916e+07 } } power9 patched: "hypot": { "workload-random": { "duration": 5.37776e+08, "iterations": 2.4e+07, "reciprocal-throughput": 19.915, "latency": 24.8997, "max-throughput": 5.02135e+07, "min-throughput": 4.01612e+07 } } power8 master: "hypot": { "workload-random": { "duration": 5.27104e+08, "iterations": 3.2e+07, "reciprocal-throughput": 15.872, "latency": 17.072, "max-throughput": 6.3004e+07, "min-throughput": 5.85755e+07 } } power8 patched: "hypot": { "workload-random": { "duration": 5.21972e+08, "iterations": 2.2e+07, "reciprocal-throughput": 21.8583, "latency": 25.5937, "max-throughput": 4.57493e+07, "min-throughput": 3.9072e+07 } } Checked on powerpc64-linux-gnu (power8) and powerpc64le-linux-gnu (power9). --- sysdeps/powerpc/fpu/e_hypot.c | 87 ------------------- sysdeps/powerpc/fpu/e_hypotf.c | 78 ----------------- .../powerpc32/power4/fpu/multiarch/Makefile | 5 +- .../power4/fpu/multiarch/e_hypot-power7.c | 23 ----- .../power4/fpu/multiarch/e_hypot-ppc32.c | 23 ----- .../powerpc32/power4/fpu/multiarch/e_hypot.c | 33 ------- .../power4/fpu/multiarch/e_hypotf-power7.c | 23 ----- .../power4/fpu/multiarch/e_hypotf-ppc32.c | 23 ----- .../powerpc32/power4/fpu/multiarch/e_hypotf.c | 33 ------- 9 files changed, 1 insertion(+), 327 deletions(-) delete mode 100644 sysdeps/powerpc/fpu/e_hypot.c delete mode 100644 sysdeps/powerpc/fpu/e_hypotf.c delete mode 100644 sysdeps/powerpc/powerpc32/power4/fpu/multiarch/e_hypot-power7.c delete mode 100644 sysdeps/powerpc/powerpc32/power4/fpu/multiarch/e_hypot-ppc32.c delete mode 100644 sysdeps/powerpc/powerpc32/power4/fpu/multiarch/e_hypot.c delete mode 100644 sysdeps/powerpc/powerpc32/power4/fpu/multiarch/e_hypotf-power7.c delete mode 100644 sysdeps/powerpc/powerpc32/power4/fpu/multiarch/e_hypotf-ppc32.c delete mode 100644 sysdeps/powerpc/powerpc32/power4/fpu/multiarch/e_hypotf.c diff --git a/sysdeps/powerpc/fpu/e_hypot.c b/sysdeps/powerpc/fpu/e_hypot.c deleted file mode 100644 index f96c589bbd..0000000000 --- a/sysdeps/powerpc/fpu/e_hypot.c +++ /dev/null @@ -1,87 +0,0 @@ -/* Pythagorean addition using doubles - Copyright (C) 2011-2021 Free Software Foundation, Inc. - This file is part of the GNU C Library - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If - not, see . */ - -#include -#include -#include -#include -#include - -/* __ieee754_hypot(x,y) - * - * This a FP only version without any FP->INT conversion. - * It is similar to default C version, making appropriates - * overflow and underflows checks as well scaling when it - * is needed. - */ - -double -__ieee754_hypot (double x, double y) -{ - if ((isinf (x) || isinf (y)) - && !issignaling (x) && !issignaling (y)) - return INFINITY; - if (isnan (x) || isnan (y)) - return x + y; - - x = fabs (x); - y = fabs (y); - - if (y > x) - { - double t = x; - x = y; - y = t; - } - if (y == 0.0) - return x; - - /* if y is higher enough, y * 2^60 might overflow. The tests if - y >= 1.7976931348623157e+308/2^60 (two60factor) and uses the - appropriate check to avoid the overflow exception generation. */ - if (y <= 0x1.fffffffffffffp+963 && x > (y * 0x1p+60)) - return x + y; - - if (x > 0x1p+500) - { - x *= 0x1p-600; - y *= 0x1p-600; - return sqrt (x * x + y * y) / 0x1p-600; - } - if (y < 0x1p-500) - { - if (y <= 0x0.fffffffffffffp-1022) - { - x *= 0x1p+1022; - y *= 0x1p+1022; - double ret = sqrt (x * x + y * y) / 0x1p+1022; - math_check_force_underflow_nonneg (ret); - return ret; - } - else - { - x *= 0x1p+600; - y *= 0x1p+600; - return sqrt (x * x + y * y) / 0x1p+600; - } - } - return sqrt (x * x + y * y); -} -#ifndef __ieee754_hypot -libm_alias_finite (__ieee754_hypot, __hypot) -#endif diff --git a/sysdeps/powerpc/fpu/e_hypotf.c b/sysdeps/powerpc/fpu/e_hypotf.c deleted file mode 100644 index fa201dda51..0000000000 --- a/sysdeps/powerpc/fpu/e_hypotf.c +++ /dev/null @@ -1,78 +0,0 @@ -/* Pythagorean addition using floats - Copyright (C) 2011-2021 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If - not, see . */ - -#include -#include -#include -#include - -/* __ieee754_hypotf(x,y) - - This a FP only version without any FP->INT conversion. - It is similar to default C version, making appropriates - overflow and underflows checks as using double precision - instead of scaling. */ - -#ifdef _ARCH_PWR7 -/* POWER7 isinf and isnan optimizations are fast. */ -# define TEST_INF_NAN(x, y) \ - if ((isinff(x) || isinff(y)) \ - && !issignaling (x) && !issignaling (y)) \ - return INFINITY; \ - if (isnanf(x) || isnanf(y)) \ - return x + y; -# else -/* For POWER6 and below isinf/isnan triggers LHS and PLT calls are - * costly (especially for POWER6). */ -# define GET_TWO_FLOAT_WORD(f1,f2,i1,i2) \ - do { \ - ieee_float_shape_type gf_u1; \ - ieee_float_shape_type gf_u2; \ - gf_u1.value = (f1); \ - gf_u2.value = (f2); \ - (i1) = gf_u1.word & 0x7fffffff; \ - (i2) = gf_u2.word & 0x7fffffff; \ - } while (0) - -# define TEST_INF_NAN(x, y) \ - do { \ - uint32_t hx, hy; \ - GET_TWO_FLOAT_WORD(x, y, hx, hy); \ - if (hy > hx) { \ - uint32_t ht = hx; hx = hy; hy = ht; \ - } \ - if (hx >= 0x7f800000) { \ - if ((hx == 0x7f800000 || hy == 0x7f800000) \ - && !issignaling (x) && !issignaling (y)) \ - return INFINITY; \ - return x + y; \ - } \ - } while (0) -#endif - - -float -__ieee754_hypotf (float x, float y) -{ - TEST_INF_NAN (x, y); - - return sqrt ((double) x * x + (double) y * y); -} -#ifndef __ieee754_hypotf -libm_alias_finite (__ieee754_hypotf, __hypotf) -#endif diff --git a/sysdeps/powerpc/powerpc32/power4/fpu/multiarch/Makefile b/sysdeps/powerpc/powerpc32/power4/fpu/multiarch/Makefile index 60f2c95532..1de0f9b350 100644 --- a/sysdeps/powerpc/powerpc32/power4/fpu/multiarch/Makefile +++ b/sysdeps/powerpc/powerpc32/power4/fpu/multiarch/Makefile @@ -15,8 +15,7 @@ libm-sysdep_routines += s_llrintf-power6 s_llrintf-ppc32 s_llrint-power6 \ s_lrint-ppc32 s_modf-power5+ s_modf-ppc32 \ s_modff-power5+ s_modff-ppc32 s_logbl-power7 \ s_logbl-ppc32 s_logb-power7 s_logb-ppc32 \ - s_logbf-power7 s_logbf-ppc32 e_hypot-power7 \ - e_hypot-ppc32 e_hypotf-power7 e_hypotf-ppc32 + s_logbf-power7 s_logbf-ppc32 CFLAGS-s_llrintf-power6.c += -mcpu=power6 CFLAGS-s_llrintf-ppc32.c += -mcpu=power4 @@ -35,8 +34,6 @@ CFLAGS-s_modff-power5+.c = -mcpu=power5+ CFLAGS-s_logbl-power7.c = -mcpu=power7 CFLAGS-s_logb-power7.c = -mcpu=power7 CFLAGS-s_logbf-power7.c = -mcpu=power7 -CFLAGS-e_hypot-power7.c = -mcpu=power7 -CFLAGS-e_hypotf-power7.c = -mcpu=power7 # These files quiet sNaNs in a way that is optimized away without # -fsignaling-nans. diff --git a/sysdeps/powerpc/powerpc32/power4/fpu/multiarch/e_hypot-power7.c b/sysdeps/powerpc/powerpc32/power4/fpu/multiarch/e_hypot-power7.c deleted file mode 100644 index 382b4a0b27..0000000000 --- a/sysdeps/powerpc/powerpc32/power4/fpu/multiarch/e_hypot-power7.c +++ /dev/null @@ -1,23 +0,0 @@ -/* __ieee_hypot() POWER7 version. - Copyright (C) 2013-2021 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include - -#define __ieee754_hypot __ieee754_hypot_power7 - -#include diff --git a/sysdeps/powerpc/powerpc32/power4/fpu/multiarch/e_hypot-ppc32.c b/sysdeps/powerpc/powerpc32/power4/fpu/multiarch/e_hypot-ppc32.c deleted file mode 100644 index abb14d5469..0000000000 --- a/sysdeps/powerpc/powerpc32/power4/fpu/multiarch/e_hypot-ppc32.c +++ /dev/null @@ -1,23 +0,0 @@ -/* __ieee_hypot() PowerPC32 version. - Copyright (C) 2013-2021 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include - -#define __ieee754_hypot __ieee754_hypot_ppc32 - -#include diff --git a/sysdeps/powerpc/powerpc32/power4/fpu/multiarch/e_hypot.c b/sysdeps/powerpc/powerpc32/power4/fpu/multiarch/e_hypot.c deleted file mode 100644 index a16efa350c..0000000000 --- a/sysdeps/powerpc/powerpc32/power4/fpu/multiarch/e_hypot.c +++ /dev/null @@ -1,33 +0,0 @@ -/* Multiple versions of ieee754_hypot. - Copyright (C) 2013-2021 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include -#include -#include -#include "init-arch.h" - -extern __typeof (__ieee754_hypot) __ieee754_hypot_ppc32 attribute_hidden; -extern __typeof (__ieee754_hypot) __ieee754_hypot_power7 attribute_hidden; - -libc_ifunc (__ieee754_hypot, - (hwcap & PPC_FEATURE_ARCH_2_06) - ? __ieee754_hypot_power7 - : __ieee754_hypot_ppc32); - -libm_alias_finite (__ieee754_hypot, __hypot) diff --git a/sysdeps/powerpc/powerpc32/power4/fpu/multiarch/e_hypotf-power7.c b/sysdeps/powerpc/powerpc32/power4/fpu/multiarch/e_hypotf-power7.c deleted file mode 100644 index f8a26ff22f..0000000000 --- a/sysdeps/powerpc/powerpc32/power4/fpu/multiarch/e_hypotf-power7.c +++ /dev/null @@ -1,23 +0,0 @@ -/* __ieee754_hypot POWER7 version. - Copyright (C) 2013-2021 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include - -#define __ieee754_hypotf __ieee754_hypotf_power7 - -#include diff --git a/sysdeps/powerpc/powerpc32/power4/fpu/multiarch/e_hypotf-ppc32.c b/sysdeps/powerpc/powerpc32/power4/fpu/multiarch/e_hypotf-ppc32.c deleted file mode 100644 index b13f8c9db2..0000000000 --- a/sysdeps/powerpc/powerpc32/power4/fpu/multiarch/e_hypotf-ppc32.c +++ /dev/null @@ -1,23 +0,0 @@ -/* __ieee_hypot() PowerPC32 version. - Copyright (C) 2013-2021 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include - -#define __ieee754_hypotf __ieee754_hypotf_ppc32 - -#include diff --git a/sysdeps/powerpc/powerpc32/power4/fpu/multiarch/e_hypotf.c b/sysdeps/powerpc/powerpc32/power4/fpu/multiarch/e_hypotf.c deleted file mode 100644 index 1e72605db8..0000000000 --- a/sysdeps/powerpc/powerpc32/power4/fpu/multiarch/e_hypotf.c +++ /dev/null @@ -1,33 +0,0 @@ -/* Multiple versions of ieee754_hypotf. - Copyright (C) 2013-2021 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include -#include -#include -#include "init-arch.h" - -extern __typeof (__ieee754_hypotf) __ieee754_hypotf_ppc32 attribute_hidden; -extern __typeof (__ieee754_hypotf) __ieee754_hypotf_power7 attribute_hidden; - -libc_ifunc (__ieee754_hypotf, - (hwcap & PPC_FEATURE_ARCH_2_06) - ? __ieee754_hypotf_power7 - : __ieee754_hypotf_ppc32); - -libm_alias_finite (__ieee754_hypotf, __hypotf) From patchwork Mon Nov 1 20:20:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 46921 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E49A13858403 for ; Mon, 1 Nov 2021 20:25:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E49A13858403 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1635798305; bh=4nzPXNbMD+IYULWPjmVMdkD3QiRnsyO9spx2RxwYKTM=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=KZu6LoBeikmftKGu8YmmUaMfTWodz651UlZmeyD0K2Wf191DV2Wr5xfHOcsqABsFs XSG5yyTHbF3gww6koGguTFqpEgNbC6BKWsiw2kmDJpBoru3Mej5FaU2mKzyGPCcF9B +vafENxOsdxagbE1t7JPiLEO5Ac3WlaPUmZYs2MI= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qt1-x833.google.com (mail-qt1-x833.google.com [IPv6:2607:f8b0:4864:20::833]) by sourceware.org (Postfix) with ESMTPS id 6A77C385801F for ; Mon, 1 Nov 2021 20:21:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6A77C385801F Received: by mail-qt1-x833.google.com with SMTP id v4so2569283qtw.8 for ; Mon, 01 Nov 2021 13:21:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4nzPXNbMD+IYULWPjmVMdkD3QiRnsyO9spx2RxwYKTM=; b=3F1xmW89WAuVyZ/KtLJdYovDLsYMPoXU5ctJZLfhI/7tiibiJpMKZtdudOMn1mUXtV HMNQR5BUCKarP5JgkM25M7/qdUdAL/0h2G5l4e3kAYKgjfe3n4GWMe2WqsgI4p08YQ0y 8/4JKIFK+sOYmddD/ppk+T/RnqoodutqVlYxt/f4BhrJNi6LKPBmMOnxdinmV22TOXQt Sey1TXf5wuEQrW8wPoaZwF5x2NIGM6gDZN5TKjmxJ5bqazlkzmesuHO9pS0pA8RXsxIN vE7pF9rKIgXMJJva2qfLnYaFq3Gt91bMDUWZTGCLW0Mx0r/iV40Gg3bA2htfAzjxEfBT 4zrQ== X-Gm-Message-State: AOAM532i+vAH/SYAupnYu/FbzVuLrvNSmbaqK/JsLHM+farq1AI0AmPn vpjLX0UR0yLQPsZ1wkMmTHFYHLSPhuzpxA== X-Google-Smtp-Source: ABdhPJy+qY+Td+TvLUREkYapsZ4BHiHEeAQvAcLWyGaDXxXAiQqqwARDrlQbXsFiY1zyICUYMYKt7Q== X-Received: by 2002:ac8:7146:: with SMTP id h6mr33072512qtp.293.1635798072797; Mon, 01 Nov 2021 13:21:12 -0700 (PDT) Received: from birita.. ([2804:431:c7cb:b64f:7c54:165f:8728:a193]) by smtp.gmail.com with ESMTPSA id d11sm10023965qtx.81.2021.11.01.13.21.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 13:21:12 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v3 6/7] i386: Move hypot implementation to C Date: Mon, 1 Nov 2021 17:20:58 -0300 Message-Id: <20211101202059.1026032-7-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211101202059.1026032-1-adhemerval.zanella@linaro.org> References: <20211101202059.1026032-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: Wilco Dijkstra Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" The generic hypotf is slight slower, mostly due the tricks the assembly does to optimize the isinf/isnan/issignaling. The generic hypot is way slower, since the optimized implementation uses the i386 default excessive precision to issue the operation directly. A similar implementation is provided instead of using the generic implementation: Checked on i686-linux-gnu. --- sysdeps/i386/fpu/e_hypot.S | 75 ------------------------------------- sysdeps/i386/fpu/e_hypot.c | 46 +++++++++++++++++++++++ sysdeps/i386/fpu/e_hypotf.S | 64 ------------------------------- 3 files changed, 46 insertions(+), 139 deletions(-) delete mode 100644 sysdeps/i386/fpu/e_hypot.S create mode 100644 sysdeps/i386/fpu/e_hypot.c delete mode 100644 sysdeps/i386/fpu/e_hypotf.S diff --git a/sysdeps/i386/fpu/e_hypot.S b/sysdeps/i386/fpu/e_hypot.S deleted file mode 100644 index f2c956b77a..0000000000 --- a/sysdeps/i386/fpu/e_hypot.S +++ /dev/null @@ -1,75 +0,0 @@ -/* Compute the hypothenuse of X and Y. - Copyright (C) 1998-2021 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include -#include - -DEFINE_DBL_MIN - -#ifdef PIC -# define MO(op) op##@GOTOFF(%edx) -#else -# define MO(op) op -#endif - - .text -ENTRY(__ieee754_hypot) -#ifdef PIC - LOAD_PIC_REG (dx) -#endif - fldl 4(%esp) // x - fxam - fnstsw - fldl 12(%esp) // y : x - movb %ah, %ch - fxam - fnstsw - movb %ah, %al - orb %ch, %ah - sahf - jc 1f - fmul %st(0) // y * y : x - fxch // x : y * y - fmul %st(0) // x * x : y * y - faddp // x * x + y * y - fsqrt - DBL_NARROW_EVAL_UFLOW_NONNEG -2: ret - - // We have to test whether any of the parameters is Inf. - // In this case the result is infinity. -1: andb $0x45, %al - cmpb $5, %al - je 3f // jump if y is Inf - andb $0x45, %ch - cmpb $5, %ch - jne 4f // jump if x is not Inf - fxch -3: fstp %st(1) - fabs - jmp 2b - -4: testb $1, %al - jnz 5f // y is NaN - fxch -5: fstp %st(1) - jmp 2b - -END(__ieee754_hypot) -libm_alias_finite (__ieee754_hypot, __hypot) diff --git a/sysdeps/i386/fpu/e_hypot.c b/sysdeps/i386/fpu/e_hypot.c new file mode 100644 index 0000000000..f2c9a8f1b9 --- /dev/null +++ b/sysdeps/i386/fpu/e_hypot.c @@ -0,0 +1,46 @@ +/* Euclidean distance function. Double/Binary64 i386 version. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include +#include +#include + +/* The i386 allows to use the default excess of precision to optimize the + hypot implementation, since internal multiplication and sqrt is carried + with 80-bit FP type. */ +double +__ieee754_hypot (double x, double y) +{ + if (!isfinite (x) || !isfinite (y)) + { + if ((isinf (x) || isinf (y)) + && !issignaling (x) && !issignaling (y)) + return INFINITY; + return x + y; + } + + long double lx = x; + long double ly = y; + double r = sqrtl (math_narrow_eval (lx * lx + ly * ly)); + math_check_force_underflow_nonneg (r); + return r; +} +libm_alias_finite (__ieee754_hypot, __hypot) diff --git a/sysdeps/i386/fpu/e_hypotf.S b/sysdeps/i386/fpu/e_hypotf.S deleted file mode 100644 index cec5d15403..0000000000 --- a/sysdeps/i386/fpu/e_hypotf.S +++ /dev/null @@ -1,64 +0,0 @@ -/* Compute the hypothenuse of X and Y. - Copyright (C) 1998-2021 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include -#include - - .text -ENTRY(__ieee754_hypotf) - flds 4(%esp) // x - fxam - fnstsw - flds 8(%esp) // y : x - movb %ah, %ch - fxam - fnstsw - movb %ah, %al - orb %ch, %ah - sahf - jc 1f - fmul %st(0) // y * y : x - fxch // x : y * y - fmul %st(0) // x * x : y * y - faddp // x * x + y * y - fsqrt - FLT_NARROW_EVAL -2: ret - - // We have to test whether any of the parameters is Inf. - // In this case the result is infinity. -1: andb $0x45, %al - cmpb $5, %al - je 3f // jump if y is Inf - andb $0x45, %ch - cmpb $5, %ch - jne 4f // jump if x is not Inf - fxch -3: fstp %st(1) - fabs - jmp 2b - -4: testb $1, %al - jnz 5f // y is NaN - fxch -5: fstp %st(1) - jmp 2b - -END(__ieee754_hypotf) -libm_alias_finite (__ieee754_hypotf, __hypotf) From patchwork Mon Nov 1 20:20:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 46923 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D16393858025 for ; Mon, 1 Nov 2021 20:26:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D16393858025 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1635798396; bh=YjowwPWljn/L4T1VypupBb9/xFCpTaRtmuTw0Vv43lU=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=YIL/Ye2NRzJoL55Ox8DVJiP0iL++BMaOr5nKk2wNvKqa+w6xUdfb2vsvkxs9bFBJo AaUgpAug5FD6w//EryBKMrtW/qifBWrmp/Fpubigj3nT9HAjIoy8T6KH7mEVo98aYr jqP+rRFgxrojDlt585BKwfkSA6Ehf+C9dEzPEiIY= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qv1-xf32.google.com (mail-qv1-xf32.google.com [IPv6:2607:f8b0:4864:20::f32]) by sourceware.org (Postfix) with ESMTPS id 645A43858001 for ; Mon, 1 Nov 2021 20:21:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 645A43858001 Received: by mail-qv1-xf32.google.com with SMTP id v2so11965993qve.11 for ; Mon, 01 Nov 2021 13:21:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YjowwPWljn/L4T1VypupBb9/xFCpTaRtmuTw0Vv43lU=; b=kp5PqEP8ux50rAQ9sMpnHSu8nK0LGxBxwyJFzWtqCz3QU0c50cvl6c10RK1m0+Yc/5 tgoUrgugiYjdOFCSddi4SlLctsmtK062MAXHgRXJ2uU13+OF+4AQv4NIlX4Sfn1mTwnH 7t/2yIIWfAne6GE1GxtpKFvlxNRewJjl8Cgb8cXAMvsflPjAcfX+ySGywhOJ1hTh0FT1 V19P+/OUEkt9Iy6NXfBlIPGyu6IzkBdbpaZhngn7Ie08iRzw5WShxR9GWlzUQc4CP0e3 gBsMK9IvEmcZ1XbnSplkxATq18tGUhiCLX94tunHaffcN2b7/wHnFmMmD2uqvf4vEVAp A7lA== X-Gm-Message-State: AOAM531Q0uEpPgUXlEd58SUeKQrdtTsHIbrNen6oTo1hYhRQ3/XnSore amHv7wOAnG/xgu63rvf0OKEmN0AgXpXrCg== X-Google-Smtp-Source: ABdhPJwoO9zNWUbglhWfwdp7A08Q69XU2CNpgI9+/lm7utwiglE4LyT39AIzVhYGnS2d3LP2LOOfqw== X-Received: by 2002:a05:6214:226e:: with SMTP id gs14mr30747736qvb.8.1635798074459; Mon, 01 Nov 2021 13:21:14 -0700 (PDT) Received: from birita.. ([2804:431:c7cb:b64f:7c54:165f:8728:a193]) by smtp.gmail.com with ESMTPSA id d11sm10023965qtx.81.2021.11.01.13.21.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Nov 2021 13:21:14 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v3 7/7] math: Remove the error handling wrapper from hypot and hypotf Date: Mon, 1 Nov 2021 17:20:59 -0300 Message-Id: <20211101202059.1026032-8-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211101202059.1026032-1-adhemerval.zanella@linaro.org> References: <20211101202059.1026032-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Cc: Wilco Dijkstra Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" The error handling is moved to sysdeps/ieee754 version with no SVID support. The compatibility symbol versions still use the wrapper with SVID error handling around the new code. There is no new symbol version nor compatibility code on !LIBM_SVID_COMPAT targets (e.g. riscv). Only ia64 is unchanged, since it still uses the arch specific __libm_error_region on its implementation. On x86_64 (Ryzen 5900X) with gcc 12: * master: "hypot": { "workload-random": { "duration": 3.74534e+09, "iterations": 9.8e+07, "reciprocal-throughput": 25.8957, "latency": 50.5399, "max-throughput": 3.86164e+07, "min-throughput": 1.97864e+07 } } *patched: "hypot": { "workload-random": { "duration": 3.70135e+09, "iterations": 1.04e+08, "reciprocal-throughput": 21.8944, "latency": 49.2854, "max-throughput": 4.56739e+07, "min-throughput": 2.029e+07 } } Checked on x86_64-linux-gnu, i686-linux-gnu, and aarch64-linux-gnu. --- math/Versions | 2 ++ math/w_hypot.c | 8 ++++++ math/w_hypot_compat.c | 13 +++++++--- math/w_hypotf.c | 8 ++++++ math/w_hypotf_compat.c | 6 ++--- sysdeps/i386/fpu/e_hypot.c | 14 +++++++++- sysdeps/ieee754/dbl-64/e_hypot.c | 26 ++++++++++++++++--- sysdeps/ieee754/dbl-64/w_hypot.c | 1 + sysdeps/ieee754/flt-32/e_hypotf.c | 19 +++++++++++--- sysdeps/ieee754/flt-32/w_hypotf.c | 1 + sysdeps/mach/hurd/i386/libm.abilist | 2 ++ sysdeps/unix/sysv/linux/aarch64/libm.abilist | 2 ++ sysdeps/unix/sysv/linux/alpha/libm.abilist | 2 ++ sysdeps/unix/sysv/linux/arm/be/libm.abilist | 2 ++ sysdeps/unix/sysv/linux/arm/le/libm.abilist | 2 ++ sysdeps/unix/sysv/linux/hppa/libm.abilist | 2 ++ sysdeps/unix/sysv/linux/i386/libm.abilist | 2 ++ .../sysv/linux/m68k/coldfire/libm.abilist | 2 ++ .../unix/sysv/linux/m68k/m680x0/libm.abilist | 2 ++ .../sysv/linux/microblaze/be/libm.abilist | 2 ++ .../sysv/linux/microblaze/le/libm.abilist | 2 ++ .../unix/sysv/linux/mips/mips32/libm.abilist | 2 ++ .../unix/sysv/linux/mips/mips64/libm.abilist | 2 ++ sysdeps/unix/sysv/linux/nios2/libm.abilist | 2 ++ .../linux/powerpc/powerpc32/fpu/libm.abilist | 2 ++ .../powerpc/powerpc32/nofpu/libm.abilist | 2 ++ .../linux/powerpc/powerpc64/be/libm.abilist | 2 ++ .../linux/powerpc/powerpc64/le/libm.abilist | 2 ++ .../unix/sysv/linux/s390/s390-32/libm.abilist | 2 ++ .../unix/sysv/linux/s390/s390-64/libm.abilist | 2 ++ sysdeps/unix/sysv/linux/sh/be/libm.abilist | 2 ++ sysdeps/unix/sysv/linux/sh/le/libm.abilist | 2 ++ .../sysv/linux/sparc/sparc32/libm.abilist | 2 ++ .../sysv/linux/sparc/sparc64/libm.abilist | 2 ++ .../unix/sysv/linux/x86_64/64/libm.abilist | 2 ++ .../unix/sysv/linux/x86_64/x32/libm.abilist | 2 ++ 36 files changed, 135 insertions(+), 15 deletions(-) create mode 100644 math/w_hypot.c create mode 100644 math/w_hypotf.c create mode 100644 sysdeps/ieee754/dbl-64/w_hypot.c create mode 100644 sysdeps/ieee754/flt-32/w_hypotf.c diff --git a/math/Versions b/math/Versions index a4b5405ddc..fef7a08c3b 100644 --- a/math/Versions +++ b/math/Versions @@ -628,5 +628,7 @@ libm { fminimum_numf64x; fminimum_numf128; fminimum_magf64x; fminimum_magf128; fminimum_mag_numf64x; fminimum_mag_numf128; + # No SVID compatible error handling. + hypotf; hypot; } } diff --git a/math/w_hypot.c b/math/w_hypot.c new file mode 100644 index 0000000000..66f723a896 --- /dev/null +++ b/math/w_hypot.c @@ -0,0 +1,8 @@ +#include +#undef __USE_WRAPPER_TEMPLATE +#define __USE_WRAPPER_TEMPLATE 1 +#undef declare_mgen_alias +#define declare_mgen_alias(a, b) +#include +versioned_symbol (libm, __hypot, hypot, GLIBC_2_35); +libm_alias_float_other (__hypot, hypot) diff --git a/math/w_hypot_compat.c b/math/w_hypot_compat.c index f07039cc51..ec983a4ab8 100644 --- a/math/w_hypot_compat.c +++ b/math/w_hypot_compat.c @@ -20,9 +20,9 @@ #include -#if LIBM_SVID_COMPAT +#if LIBM_SVID_COMPAT && SHLIB_COMPAT (libm, GLIBC_2_0, GLIBC_2_35) double -__hypot (double x, double y) +__hypot_compat (double x, double y) { double z = __ieee754_hypot(x,y); if(__builtin_expect(!isfinite(z), 0) @@ -31,5 +31,12 @@ __hypot (double x, double y) return z; } -libm_alias_double (__hypot, hypot) +compat_symbol (libm, __hypot_compat, hypot, GLIBC_2_0); +# ifdef NO_LONG_DOUBLE +weak_alias (__hypot_compat, hypotl) +# endif +# ifdef LONG_DOUBLE_COMPAT +LONG_DOUBLE_COMPAT_CHOOSE_libm_hypotl ( + compat_symbol (libm, __hypot_compat, hypotl, FIRST_VERSION_libm_hypotl), ); +# endif #endif diff --git a/math/w_hypotf.c b/math/w_hypotf.c new file mode 100644 index 0000000000..b15a9b06d0 --- /dev/null +++ b/math/w_hypotf.c @@ -0,0 +1,8 @@ +#include +#undef __USE_WRAPPER_TEMPLATE +#define __USE_WRAPPER_TEMPLATE 1 +#undef declare_mgen_alias +#define declare_mgen_alias(a, b) +#include +versioned_symbol (libm, __hypotf, hypotf, GLIBC_2_35); +libm_alias_float_other (__hypotf, hypotf) diff --git a/math/w_hypotf_compat.c b/math/w_hypotf_compat.c index 05898d3420..2bde4553b0 100644 --- a/math/w_hypotf_compat.c +++ b/math/w_hypotf_compat.c @@ -22,9 +22,9 @@ #include -#if LIBM_SVID_COMPAT +#if LIBM_SVID_COMPAT && SHLIB_COMPAT (libm, GLIBC_2_0, GLIBC_2_35) float -__hypotf(float x, float y) +__hypotf_compat (float x, float y) { float z = __ieee754_hypotf(x,y); if(__builtin_expect(!isfinite(z), 0) @@ -34,5 +34,5 @@ __hypotf(float x, float y) return z; } -libm_alias_float (__hypot, hypot) +compat_symbol (libm, __hypotf_compat, hypotf, GLIBC_2_0); #endif diff --git a/sysdeps/i386/fpu/e_hypot.c b/sysdeps/i386/fpu/e_hypot.c index f2c9a8f1b9..ac081c3476 100644 --- a/sysdeps/i386/fpu/e_hypot.c +++ b/sysdeps/i386/fpu/e_hypot.c @@ -20,14 +20,17 @@ #include #include #include +#include #include +#include #include +#include /* The i386 allows to use the default excess of precision to optimize the hypot implementation, since internal multiplication and sqrt is carried with 80-bit FP type. */ double -__ieee754_hypot (double x, double y) +__hypot (double x, double y) { if (!isfinite (x) || !isfinite (y)) { @@ -41,6 +44,15 @@ __ieee754_hypot (double x, double y) long double ly = y; double r = sqrtl (math_narrow_eval (lx * lx + ly * ly)); math_check_force_underflow_nonneg (r); + if (isinf (r)) + __set_errno (ERANGE); return r; } +strong_alias (__hypot, __ieee754_hypot) +#if LIBM_SVID_COMPAT +versioned_symbol (libm, __hypot, hypot, GLIBC_2_35); libm_alias_finite (__ieee754_hypot, __hypot) +libm_alias_double_other (__hypot, hypot) +#else +libm_alias_double (__hypot, hypot) +#endif diff --git a/sysdeps/ieee754/dbl-64/e_hypot.c b/sysdeps/ieee754/dbl-64/e_hypot.c index 638bf019ad..ed1e857b23 100644 --- a/sysdeps/ieee754/dbl-64/e_hypot.c +++ b/sysdeps/ieee754/dbl-64/e_hypot.c @@ -32,7 +32,18 @@ #include #include #include +#include #include +#include +#include + +static inline double +handle_errno (double r) +{ + if (isinf (r)) + __set_errno (ERANGE); + return r; +} /* sqrt (DBL_EPSILON / 2.0) */ #define SQRT_EPS_DIV_2 0x1.6a09e667f3bcdp-27 @@ -48,7 +59,7 @@ #define SQRT_DBL_MIN 0x1p-511 double -__ieee754_hypot (double x, double y) +__hypot (double x, double y) { if (!isfinite(x) || !isfinite(y)) { @@ -70,7 +81,9 @@ __ieee754_hypot (double x, double y) /* Widely varying operands. The DBL_MIN_THRESHOLD check is used to avoid a spurious underflow from the multiplication. */ if (ax >= DBL_MIN_THRESHOLD && ay <= ax * SQRT_EPS_DIV_2) - return (ay == 0.0) ? ax : math_narrow_eval (ax + DBL_TRUE_MIN); + return (ay == 0.0) + ? ax + : handle_errno (math_narrow_eval (ax + DBL_TRUE_MIN)); double scale = SCALE; if (ax > SQRT_DBL_MAX) @@ -107,8 +120,13 @@ __ieee754_hypot (double x, double y) h -= (t1 + t2) / (2.0 * h); h = math_narrow_eval (h * scale); math_check_force_underflow_nonneg (h); - return h; + return handle_errno (h); } -#ifndef __ieee754_hypot +strong_alias (__hypot, __ieee754_hypot) libm_alias_finite (__ieee754_hypot, __hypot) +#if LIBM_SVID_COMPAT +versioned_symbol (libm, __hypot, hypot, GLIBC_2_35); +libm_alias_double_other (__hypot, hypot) +#else +libm_alias_double (__hypot, hypot) #endif diff --git a/sysdeps/ieee754/dbl-64/w_hypot.c b/sysdeps/ieee754/dbl-64/w_hypot.c new file mode 100644 index 0000000000..1cc8931700 --- /dev/null +++ b/sysdeps/ieee754/dbl-64/w_hypot.c @@ -0,0 +1 @@ +/* Not needed. */ diff --git a/sysdeps/ieee754/flt-32/e_hypotf.c b/sysdeps/ieee754/flt-32/e_hypotf.c index ea18775829..9d5d109902 100644 --- a/sysdeps/ieee754/flt-32/e_hypotf.c +++ b/sysdeps/ieee754/flt-32/e_hypotf.c @@ -20,9 +20,12 @@ #include #include "math_config.h" #include +#include +#include +#include float -__ieee754_hypotf (float x, float y) +__hypotf (float x, float y) { if (!isfinite(x) || !isfinite(y)) { @@ -32,8 +35,16 @@ __ieee754_hypotf (float x, float y) return x + y; } - return sqrt ((double) x * (double) x + (double) y * (double) y); + float r = sqrt ((double) x * (double) x + (double) y * (double) y); + if (!isfinite (r)) + __set_errno (ERANGE); + return r; } -#ifndef __ieee754_hypotf -libm_alias_finite (__ieee754_hypotf, __hypotf) +strong_alias (__hypotf, __ieee754_hypotf) +#if LIBM_SVID_COMPAT +versioned_symbol (libm, __hypotf, hypotf, GLIBC_2_35); +libm_alias_float_other (__hypot, hypot) +#else +libm_alias_float (__hypot, hypot) #endif +libm_alias_finite (__ieee754_hypotf, __hypotf) diff --git a/sysdeps/ieee754/flt-32/w_hypotf.c b/sysdeps/ieee754/flt-32/w_hypotf.c new file mode 100644 index 0000000000..1cc8931700 --- /dev/null +++ b/sysdeps/ieee754/flt-32/w_hypotf.c @@ -0,0 +1 @@ +/* Not needed. */ diff --git a/sysdeps/mach/hurd/i386/libm.abilist b/sysdeps/mach/hurd/i386/libm.abilist index abf91bd142..8f40ddb150 100644 --- a/sysdeps/mach/hurd/i386/libm.abilist +++ b/sysdeps/mach/hurd/i386/libm.abilist @@ -1179,3 +1179,5 @@ GLIBC_2.35 fminimumf64x F GLIBC_2.35 fminimuml F GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrtl F +GLIBC_2.35 hypot F +GLIBC_2.35 hypotf F diff --git a/sysdeps/unix/sysv/linux/aarch64/libm.abilist b/sysdeps/unix/sysv/linux/aarch64/libm.abilist index 1cef7d3db7..c2e3c6453e 100644 --- a/sysdeps/unix/sysv/linux/aarch64/libm.abilist +++ b/sysdeps/unix/sysv/linux/aarch64/libm.abilist @@ -1144,3 +1144,5 @@ GLIBC_2.35 fminimumf64x F GLIBC_2.35 fminimuml F GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrtl F +GLIBC_2.35 hypot F +GLIBC_2.35 hypotf F diff --git a/sysdeps/unix/sysv/linux/alpha/libm.abilist b/sysdeps/unix/sysv/linux/alpha/libm.abilist index 59d51021fa..4f85b6180f 100644 --- a/sysdeps/unix/sysv/linux/alpha/libm.abilist +++ b/sysdeps/unix/sysv/linux/alpha/libm.abilist @@ -1201,6 +1201,8 @@ GLIBC_2.35 fminimumf64x F GLIBC_2.35 fminimuml F GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrtl F +GLIBC_2.35 hypot F +GLIBC_2.35 hypotf F GLIBC_2.4 __clog10l F GLIBC_2.4 __finitel F GLIBC_2.4 __fpclassifyl F diff --git a/sysdeps/unix/sysv/linux/arm/be/libm.abilist b/sysdeps/unix/sysv/linux/arm/be/libm.abilist index 44666ad7cd..36190add84 100644 --- a/sysdeps/unix/sysv/linux/arm/be/libm.abilist +++ b/sysdeps/unix/sysv/linux/arm/be/libm.abilist @@ -531,6 +531,8 @@ GLIBC_2.35 fminimumf64 F GLIBC_2.35 fminimuml F GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrtl F +GLIBC_2.35 hypot F +GLIBC_2.35 hypotf F GLIBC_2.4 _LIB_VERSION D 0x4 GLIBC_2.4 __clog10 F GLIBC_2.4 __clog10f F diff --git a/sysdeps/unix/sysv/linux/arm/le/libm.abilist b/sysdeps/unix/sysv/linux/arm/le/libm.abilist index 44666ad7cd..36190add84 100644 --- a/sysdeps/unix/sysv/linux/arm/le/libm.abilist +++ b/sysdeps/unix/sysv/linux/arm/le/libm.abilist @@ -531,6 +531,8 @@ GLIBC_2.35 fminimumf64 F GLIBC_2.35 fminimuml F GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrtl F +GLIBC_2.35 hypot F +GLIBC_2.35 hypotf F GLIBC_2.4 _LIB_VERSION D 0x4 GLIBC_2.4 __clog10 F GLIBC_2.4 __clog10f F diff --git a/sysdeps/unix/sysv/linux/hppa/libm.abilist b/sysdeps/unix/sysv/linux/hppa/libm.abilist index 35d316a720..b5dd4e851f 100644 --- a/sysdeps/unix/sysv/linux/hppa/libm.abilist +++ b/sysdeps/unix/sysv/linux/hppa/libm.abilist @@ -842,4 +842,6 @@ GLIBC_2.35 fminimumf64 F GLIBC_2.35 fminimuml F GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrtl F +GLIBC_2.35 hypot F +GLIBC_2.35 hypotf F GLIBC_2.4 exp2l F diff --git a/sysdeps/unix/sysv/linux/i386/libm.abilist b/sysdeps/unix/sysv/linux/i386/libm.abilist index ef99b3e104..5d89aaa08e 100644 --- a/sysdeps/unix/sysv/linux/i386/libm.abilist +++ b/sysdeps/unix/sysv/linux/i386/libm.abilist @@ -1186,3 +1186,5 @@ GLIBC_2.35 fminimumf64x F GLIBC_2.35 fminimuml F GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrtl F +GLIBC_2.35 hypot F +GLIBC_2.35 hypotf F diff --git a/sysdeps/unix/sysv/linux/m68k/coldfire/libm.abilist b/sysdeps/unix/sysv/linux/m68k/coldfire/libm.abilist index 44666ad7cd..36190add84 100644 --- a/sysdeps/unix/sysv/linux/m68k/coldfire/libm.abilist +++ b/sysdeps/unix/sysv/linux/m68k/coldfire/libm.abilist @@ -531,6 +531,8 @@ GLIBC_2.35 fminimumf64 F GLIBC_2.35 fminimuml F GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrtl F +GLIBC_2.35 hypot F +GLIBC_2.35 hypotf F GLIBC_2.4 _LIB_VERSION D 0x4 GLIBC_2.4 __clog10 F GLIBC_2.4 __clog10f F diff --git a/sysdeps/unix/sysv/linux/m68k/m680x0/libm.abilist b/sysdeps/unix/sysv/linux/m68k/m680x0/libm.abilist index 58316c96ae..e7cd739a54 100644 --- a/sysdeps/unix/sysv/linux/m68k/m680x0/libm.abilist +++ b/sysdeps/unix/sysv/linux/m68k/m680x0/libm.abilist @@ -882,3 +882,5 @@ GLIBC_2.35 fminimumf64 F GLIBC_2.35 fminimuml F GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrtl F +GLIBC_2.35 hypot F +GLIBC_2.35 hypotf F diff --git a/sysdeps/unix/sysv/linux/microblaze/be/libm.abilist b/sysdeps/unix/sysv/linux/microblaze/be/libm.abilist index b5e5da0272..274ecff630 100644 --- a/sysdeps/unix/sysv/linux/microblaze/be/libm.abilist +++ b/sysdeps/unix/sysv/linux/microblaze/be/libm.abilist @@ -843,3 +843,5 @@ GLIBC_2.35 fminimumf64 F GLIBC_2.35 fminimuml F GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrtl F +GLIBC_2.35 hypot F +GLIBC_2.35 hypotf F diff --git a/sysdeps/unix/sysv/linux/microblaze/le/libm.abilist b/sysdeps/unix/sysv/linux/microblaze/le/libm.abilist index b5e5da0272..274ecff630 100644 --- a/sysdeps/unix/sysv/linux/microblaze/le/libm.abilist +++ b/sysdeps/unix/sysv/linux/microblaze/le/libm.abilist @@ -843,3 +843,5 @@ GLIBC_2.35 fminimumf64 F GLIBC_2.35 fminimuml F GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrtl F +GLIBC_2.35 hypot F +GLIBC_2.35 hypotf F diff --git a/sysdeps/unix/sysv/linux/mips/mips32/libm.abilist b/sysdeps/unix/sysv/linux/mips/mips32/libm.abilist index 4113d3170d..08b902118d 100644 --- a/sysdeps/unix/sysv/linux/mips/mips32/libm.abilist +++ b/sysdeps/unix/sysv/linux/mips/mips32/libm.abilist @@ -842,4 +842,6 @@ GLIBC_2.35 fminimumf64 F GLIBC_2.35 fminimuml F GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrtl F +GLIBC_2.35 hypot F +GLIBC_2.35 hypotf F GLIBC_2.4 exp2l F diff --git a/sysdeps/unix/sysv/linux/mips/mips64/libm.abilist b/sysdeps/unix/sysv/linux/mips/mips64/libm.abilist index 18fe9cc57a..09bb3bd75b 100644 --- a/sysdeps/unix/sysv/linux/mips/mips64/libm.abilist +++ b/sysdeps/unix/sysv/linux/mips/mips64/libm.abilist @@ -1144,3 +1144,5 @@ GLIBC_2.35 fminimumf64x F GLIBC_2.35 fminimuml F GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrtl F +GLIBC_2.35 hypot F +GLIBC_2.35 hypotf F diff --git a/sysdeps/unix/sysv/linux/nios2/libm.abilist b/sysdeps/unix/sysv/linux/nios2/libm.abilist index 3a2b34ecc2..11abbb5668 100644 --- a/sysdeps/unix/sysv/linux/nios2/libm.abilist +++ b/sysdeps/unix/sysv/linux/nios2/libm.abilist @@ -843,3 +843,5 @@ GLIBC_2.35 fminimumf64 F GLIBC_2.35 fminimuml F GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrtl F +GLIBC_2.35 hypot F +GLIBC_2.35 hypotf F diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libm.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libm.abilist index 740cc8f55b..1688809c36 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libm.abilist +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libm.abilist @@ -888,6 +888,8 @@ GLIBC_2.35 fminimumf64 F GLIBC_2.35 fminimuml F GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrtl F +GLIBC_2.35 hypot F +GLIBC_2.35 hypotf F GLIBC_2.4 __clog10l F GLIBC_2.4 __finitel F GLIBC_2.4 __fpclassifyl F diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libm.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libm.abilist index 16fb30566b..e880cebd78 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libm.abilist +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libm.abilist @@ -887,6 +887,8 @@ GLIBC_2.35 fminimumf64 F GLIBC_2.35 fminimuml F GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrtl F +GLIBC_2.35 hypot F +GLIBC_2.35 hypotf F GLIBC_2.4 __clog10l F GLIBC_2.4 __finitel F GLIBC_2.4 __fpclassifyl F diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libm.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libm.abilist index ad4b98c09a..033385dfc1 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libm.abilist +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libm.abilist @@ -881,6 +881,8 @@ GLIBC_2.35 fminimumf64 F GLIBC_2.35 fminimuml F GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrtl F +GLIBC_2.35 hypot F +GLIBC_2.35 hypotf F GLIBC_2.4 __clog10l F GLIBC_2.4 __finitel F GLIBC_2.4 __fpclassifyl F diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libm.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libm.abilist index 955765051c..7923d428bc 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libm.abilist +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libm.abilist @@ -1316,3 +1316,5 @@ GLIBC_2.35 fminimumf64x F GLIBC_2.35 fminimuml F GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrtl F +GLIBC_2.35 hypot F +GLIBC_2.35 hypotf F diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/libm.abilist b/sysdeps/unix/sysv/linux/s390/s390-32/libm.abilist index 1f5bd7754d..9a84163089 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-32/libm.abilist +++ b/sysdeps/unix/sysv/linux/s390/s390-32/libm.abilist @@ -1145,6 +1145,8 @@ GLIBC_2.35 fminimumf64x F GLIBC_2.35 fminimuml F GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrtl F +GLIBC_2.35 hypot F +GLIBC_2.35 hypotf F GLIBC_2.4 __clog10l F GLIBC_2.4 __finitel F GLIBC_2.4 __fpclassifyl F diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/libm.abilist b/sysdeps/unix/sysv/linux/s390/s390-64/libm.abilist index 0b18481f39..174bde4fa0 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-64/libm.abilist +++ b/sysdeps/unix/sysv/linux/s390/s390-64/libm.abilist @@ -1145,6 +1145,8 @@ GLIBC_2.35 fminimumf64x F GLIBC_2.35 fminimuml F GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrtl F +GLIBC_2.35 hypot F +GLIBC_2.35 hypotf F GLIBC_2.4 __clog10l F GLIBC_2.4 __finitel F GLIBC_2.4 __fpclassifyl F diff --git a/sysdeps/unix/sysv/linux/sh/be/libm.abilist b/sysdeps/unix/sysv/linux/sh/be/libm.abilist index f525a9e77e..1e1324d667 100644 --- a/sysdeps/unix/sysv/linux/sh/be/libm.abilist +++ b/sysdeps/unix/sysv/linux/sh/be/libm.abilist @@ -842,4 +842,6 @@ GLIBC_2.35 fminimumf64 F GLIBC_2.35 fminimuml F GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrtl F +GLIBC_2.35 hypot F +GLIBC_2.35 hypotf F GLIBC_2.4 exp2l F diff --git a/sysdeps/unix/sysv/linux/sh/le/libm.abilist b/sysdeps/unix/sysv/linux/sh/le/libm.abilist index f525a9e77e..1e1324d667 100644 --- a/sysdeps/unix/sysv/linux/sh/le/libm.abilist +++ b/sysdeps/unix/sysv/linux/sh/le/libm.abilist @@ -842,4 +842,6 @@ GLIBC_2.35 fminimumf64 F GLIBC_2.35 fminimuml F GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrtl F +GLIBC_2.35 hypot F +GLIBC_2.35 hypotf F GLIBC_2.4 exp2l F diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/libm.abilist b/sysdeps/unix/sysv/linux/sparc/sparc32/libm.abilist index 727d1ce707..217e6eff7f 100644 --- a/sysdeps/unix/sysv/linux/sparc/sparc32/libm.abilist +++ b/sysdeps/unix/sysv/linux/sparc/sparc32/libm.abilist @@ -1152,6 +1152,8 @@ GLIBC_2.35 fminimumf64x F GLIBC_2.35 fminimuml F GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrtl F +GLIBC_2.35 hypot F +GLIBC_2.35 hypotf F GLIBC_2.4 __clog10l F GLIBC_2.4 __finitel F GLIBC_2.4 __fpclassifyl F diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/libm.abilist b/sysdeps/unix/sysv/linux/sparc/sparc64/libm.abilist index 0f57574523..6b53b0c59f 100644 --- a/sysdeps/unix/sysv/linux/sparc/sparc64/libm.abilist +++ b/sysdeps/unix/sysv/linux/sparc/sparc64/libm.abilist @@ -1144,3 +1144,5 @@ GLIBC_2.35 fminimumf64x F GLIBC_2.35 fminimuml F GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrtl F +GLIBC_2.35 hypot F +GLIBC_2.35 hypotf F diff --git a/sysdeps/unix/sysv/linux/x86_64/64/libm.abilist b/sysdeps/unix/sysv/linux/x86_64/64/libm.abilist index 574789e061..dbefbc3a1a 100644 --- a/sysdeps/unix/sysv/linux/x86_64/64/libm.abilist +++ b/sysdeps/unix/sysv/linux/x86_64/64/libm.abilist @@ -1177,3 +1177,5 @@ GLIBC_2.35 fminimumf64x F GLIBC_2.35 fminimuml F GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrtl F +GLIBC_2.35 hypot F +GLIBC_2.35 hypotf F diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/libm.abilist b/sysdeps/unix/sysv/linux/x86_64/x32/libm.abilist index 1dc89b304d..8001d0f219 100644 --- a/sysdeps/unix/sysv/linux/x86_64/x32/libm.abilist +++ b/sysdeps/unix/sysv/linux/x86_64/x32/libm.abilist @@ -1177,3 +1177,5 @@ GLIBC_2.35 fminimumf64x F GLIBC_2.35 fminimuml F GLIBC_2.35 fsqrt F GLIBC_2.35 fsqrtl F +GLIBC_2.35 hypot F +GLIBC_2.35 hypotf F