From patchwork Mon Oct 25 11:57:50 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: 46600 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 561B4385841B for ; Mon, 25 Oct 2021 11:59:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 561B4385841B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1635163146; bh=buUOR/bc/Ip7sMeCVFfsZlV1T4v4A1Q99Izs8TxkBdY=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=aB1/xmLdkQGL28vEECOT8Byr/gX/xZ37Qba3indZxXDvC9LZPkowqlFxbY46/xbO5 RvdHoCXWrjkpGYSEofBS6uNsESSxhNSzunxZERda/xeq9wogBJMhaajgyH22Bl6Hj8 pAPv0NOu++oUdDlxnEEbZMn1JLi7qtgd52qXBvzQ= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ua1-x92a.google.com (mail-ua1-x92a.google.com [IPv6:2607:f8b0:4864:20::92a]) by sourceware.org (Postfix) with ESMTPS id 10835385840C for ; Mon, 25 Oct 2021 11:58:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 10835385840C Received: by mail-ua1-x92a.google.com with SMTP id e10so21523484uab.3 for ; Mon, 25 Oct 2021 04:58: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=buUOR/bc/Ip7sMeCVFfsZlV1T4v4A1Q99Izs8TxkBdY=; b=NhADjufBbzIGOZJvfxg2P+X/v2GD5mJ6W/SND9CCv9xB3sHS2BLWZHGGyDIRVEKnQW LhS9BgVc+xnkXggST1h6g/CkHREiDLDfNJloFPrXoPFOBWkj+M3FsNAV5JbQyFLULtzZ hpEmHTT4+l13WJiedBnYaGUV//7Dp/i9180CCrNskjJb2ur2d47jybMUGQba1ayi5KS4 uyIP/e2IZVGn9I8EPYUo+fOQoaC2t7aeheHP686aH3KacAWwZ4oRbsUg88xW7mgKlwdU ceXTtPBD8KeEqnfmNMM/S/ad/D3mIcvDnu5cShA54PiDAI8ZqNmeVCNJzZxXJbnNTon7 6ivg== X-Gm-Message-State: AOAM532FN6XAcISBra6GuorV0h+F5AGxWaE5VnzdntS/kk4rH54bHrqN 7AV+cyTKBnfcGGRX65/HJAl0SCwxpVs78g== X-Google-Smtp-Source: ABdhPJyiatWtpKuMuwAEIqHpWCndEeAGlWBX/OEP6gl+eLgal0ivtTOPVOXU4rX0Gr+uOXJUsZyIrA== X-Received: by 2002:ab0:614e:: with SMTP id w14mr13879209uan.5.1635163084500; Mon, 25 Oct 2021 04:58:04 -0700 (PDT) Received: from birita.. ([2804:431:c7ca:2654:4c60:ad20:95b6:1d6c]) by smtp.gmail.com with ESMTPSA id k11sm4230490vsh.3.2021.10.25.04.58.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Oct 2021 04:58:04 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v2 3/9] math: Simplify hypotf implementation Date: Mon, 25 Oct 2021 08:57:50 -0300 Message-Id: <20211025115756.11767-4-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211025115756.11767-1-adhemerval.zanella@linaro.org> References: <20211025115756.11767-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-11.7 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 Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Use isnan()/isinf() instead of GET_FLOAT_WORD and integer operations. There is also no need to check for 0.0. 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 | 57 +++++++++++++------------------ 1 file changed, 23 insertions(+), 34 deletions(-) diff --git a/sysdeps/ieee754/flt-32/e_hypotf.c b/sysdeps/ieee754/flt-32/e_hypotf.c index e770947dc1..6495a91cd4 100644 --- a/sysdeps/ieee754/flt-32/e_hypotf.c +++ b/sysdeps/ieee754/flt-32/e_hypotf.c @@ -1,46 +1,35 @@ -/* 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 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 ((isinf (x) || isinf (y)) + && !issignaling (x) && !issignaling (y)) + return INFINITY; + if (isnan (x) || isnan (y)) + 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)