From patchwork Fri Oct 25 18:21:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 838389 Delivered-To: patch@linaro.org Received: by 2002:adf:e287:0:b0:37d:45d0:187 with SMTP id v7csp445195wri; Fri, 25 Oct 2024 11:31:59 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXbmxaNuFXC3nHXrM1eMl/AKqI3YslULmvOdSlhil96wWO79ji4Dy0qSt2CKAmnxMOOlOx6Iw==@linaro.org X-Google-Smtp-Source: AGHT+IHzCPwm4sKfN4AHVOjFHr4bkzgWdhEYcbgWlZNqNQz1thsgDxU5a/TvmTOdnA1wARSqwWgq X-Received: by 2002:a05:6870:2154:b0:25e:1edb:5bcf with SMTP id 586e51a60fabf-29051ade6f1mr442730fac.6.1729881118773; Fri, 25 Oct 2024 11:31:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1729881118; cv=pass; d=google.com; s=arc-20240605; b=bxAcariFhcp0sggXsvwCC1E6jRQP5wt0BhD8yomnrIIVJGQ9GOMeq1XUX3hjgrCMqT x6+FcNssn7K2GZZU9kOLEi2UflGMmsSKiLqP6zFC2/l+t/TbFaZSGKX0owDsuKkqhtxU MJtWUh9WOSD23jR6/NDHh+OCIVSiT8NLbVQEqiwVRoQqwN+rrGYZNAZMyh9ezLrQW2M8 meWl8MAxFUTzsufhlWU3GjNlUfAckwvndB3PXrF9lSpw0ZDQmKQjkKT4cASRQmHIa+N3 iFCCNs7HTW+dVsgUxd5nPeHtzwGedWMzGJTtlPXeypLTDaiRylBqw2aebfGsLwm4Wq34 ssMw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=QHlm6lG26mBbWkA7bcRJrhHOpgTJ5K6vhGZwHdzW2Ko=; fh=t7K9SrKfAVamsrcTQr7hpJTc6WX7Vbl5hwH62Vkp0W0=; b=WqnnenU+R6wEYOcnxbMvwZiQ8P66qawhhCZd/UIlDDFPX9EXDwVdlOKIbccUJd2dLm 7KB4edjUL1f/rjU/Kpw5SLI60hzGAl5srokY7tG4e5Uos7Ov/JZn/rEqkDjQHmQHe4G+ S1dYIem9OuGfIql9CPKzl6Xm0XGFkmQ2Jam/B5WKd5vwKf0yuLB/rH5+Z/7AlvW1n9Iu NjDUaSq1jLlQDhg7/0joejnRkUH0Ywb0wEsrH+o/aCnETk66RIV1YKLKolLkzX4bJdzo IFGe73iCDBObEndHSmeFrGTAIvhoDNV/tTAFR3sNRIH+EnugYv+2ca9yBM0cyU3s2Qh7 L7Zg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xGvQfkpg; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces~patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id af79cd13be357-7b18d343ce4si209654885a.502.2024.10.25.11.31.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Oct 2024 11:31:58 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xGvQfkpg; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces~patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5D2203858401 for ; Fri, 25 Oct 2024 18:31:58 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by sourceware.org (Postfix) with ESMTPS id C5AED385840A for ; Fri, 25 Oct 2024 18:27:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C5AED385840A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C5AED385840A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729880846; cv=none; b=MITMSooj6RE9mXAbNv3zOSonFJB6AsgFr4W7MT3Ea2MhQ8PJzD/unqeeeoqrqKbfwSr+Vn+/3iKMOZ1m8D9L+qekvplnfXeAiY0F9uHYYAmsHb4KeDR+nC4GyCSHpiS27sObxeIYLA5vDDdMFCKuvgLThdEyAs5UC7fXwycTC1Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729880846; c=relaxed/simple; bh=zIFP+ypC2hIrAorVUG7tPjsLSIiQIB9EW8lqjMbz7h4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=YkvPT5MraPaBFcQKiTBHbvcR3ouVcHvI5+xBtdF6w48PRml+u8gNkY117MMkAikZ75T6EUXfQmFrQnkYhD3hDiVGFEl4fEn5M5qET/hvgf6sv5EOi26CUZp7WbD1A1QlE51IECovq9CepQNBmL75xX/bxiDQ8pRI1oQ4ITLn1uQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-20c693b68f5so24214055ad.1 for ; Fri, 25 Oct 2024 11:27:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1729880834; x=1730485634; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QHlm6lG26mBbWkA7bcRJrhHOpgTJ5K6vhGZwHdzW2Ko=; b=xGvQfkpgOZAcLY5S1pf0QkOclN0Zw94KQ7QDti//YwYc/Xy3bqgHhJWmjntg5/UqEV 4LSjicdyjhpN15Ax4ECBxjdURerPE8sSFnZN0SWT3H+uBMZb9qDI77MccIrBzCVVkR6S F6PfNRyMP7ymzUszNb8AbSX7BH/WDxJGEqI097iBZf39/j7HQ822RHO6cC7I42JM4XTn v+MJ/RQgPvYZ4h4bzBKk3xbnoom3ZpneeOkn5JCoS/CqI631NTZgj/avbQzgTLbcgL0S L2Myhae+3Y+54cAgO4eE+Q93NTdzXJ+7JuO4VROzsA5C6v5OaFUz6/bzf/qLpo00r4GP mXQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729880834; x=1730485634; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QHlm6lG26mBbWkA7bcRJrhHOpgTJ5K6vhGZwHdzW2Ko=; b=aQ2GaQboXHPsMQp5N4QOVg/GlaTQKD9JTdateYC7r2ag8y4lTbdMzwcxxqhKogT+Im dXckkrz1JGsevgkmwkp3kcSN6DBjH52ND7Z9dWFHc7p+82JR/nNVCPOB5WZiKY05AKlR doixN7WGlOHeHl9RJh/IQYhcz4jltFTcOxGoJBZH0JllJDAnXq/TUm67ib6Pm18SD8/3 T3DCF5jt8cU9D+3rnqT24yFSzs0qx+dvjrVKCbnG0RGZ6+3PZTSAckBp0NeV5nrwd+GU ShSGqyDP4cY9YhLLeDC742KR1w26LJ+LVuEnaCe+JI/Jb46Ctkr+zib6Ny4zWcYfPe1g bRbA== X-Gm-Message-State: AOJu0YxAMKHrNuD53WTdbqvhDvxuyJK1HXJi7Po0JN7xPSRP4nDujSrD Xx+KUb/Hj27DZUa+gK9lI+G+Q2QfNdoWUhFHwQccZyzRVhFLMl+ULYIMp/5jCI72X7O0hq5rDzs U X-Received: by 2002:a17:903:192:b0:20b:7be8:8eb9 with SMTP id d9443c01a7336-210c6ccc963mr425955ad.54.1729880833926; Fri, 25 Oct 2024 11:27:13 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c3:a8a8:cb9e:64f4:66fb:5ca2]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-210bbf44550sm12314075ad.14.2024.10.25.11.27.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Oct 2024 11:27:13 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Paul Zimmermann , Alexei Sibidanov Subject: [PATCH 13/17] math: Use log2p1f from CORE-MATH Date: Fri, 25 Oct 2024 15:21:51 -0300 Message-ID: <20241025182614.2022697-14-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241025182614.2022697-1-adhemerval.zanella@linaro.org> References: <20241025182614.2022697-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, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patch=linaro.org@sourceware.org The CORE-MATH implementation is correctly rounded (for any rounding mode) and shows better performance compared to the generic log2p1f. The code was adapted to glibc style and to use the definition of math_config.h (to handle errno, overflow, and underflow). Benchtest on x64_64 (Ryzen 9 5900X, gcc 14.2.1), aarch64 (Neoverse-N1, gcc 13.3.1), and powerpc (POWER10, gcc 13.2.1): Latency master patched improvement x86_64 70.1462 47.0090 32.98% x86_64v2 70.2513 47.6160 32.22% x86_64v3 60.4840 39.9443 33.96% i686 164.068 122.909 25.09% aarch64 25.9169 16.9207 34.71% power10 18.1261 9.8592 45.61% powerpc 17.2683 9.38665 45.64% reciprocal-throughput master patched improvement x86_64 26.2240 16.4082 37.43% x86_64v2 25.0911 15.7480 37.24% x86_64v3 20.9371 11.7264 43.99% i686 90.4209 95.3073 -5.40% aarch64 16.8537 8.9561 46.86% power10 12.9401 6.5555 49.34% powerpc 9.01763 7.54745 16.30% The performance decrease for i686 is mostly due the use of x87 fpu, when building with '-msse2 -mfpmath=sse: master patched improvement latency 164.068 102.982 37.23% reciprocal-throughput 89.1968 82.5117 7.49% Signed-off-by: Alexei Sibidanov Signed-off-by: Paul Zimmermann Signed-off-by: Adhemerval Zanella --- SHARED-FILES | 4 + sysdeps/aarch64/libm-test-ulps | 4 - sysdeps/arc/fpu/libm-test-ulps | 4 - sysdeps/arc/nofpu/libm-test-ulps | 2 - sysdeps/arm/libm-test-ulps | 4 - sysdeps/hppa/fpu/libm-test-ulps | 4 - sysdeps/i386/fpu/libm-test-ulps | 4 - .../i386/i686/fpu/multiarch/libm-test-ulps | 4 - sysdeps/ieee754/flt-32/s_log2p1f.c | 248 ++++++++++++++++++ sysdeps/loongarch/lp64/libm-test-ulps | 4 - sysdeps/m68k/m680x0/fpu/libm-test-ulps | 4 - sysdeps/mips/mips32/libm-test-ulps | 4 - sysdeps/mips/mips64/libm-test-ulps | 4 - sysdeps/powerpc/fpu/libm-test-ulps | 4 - sysdeps/powerpc/nofpu/libm-test-ulps | 4 - sysdeps/riscv/nofpu/libm-test-ulps | 1 - sysdeps/riscv/rvd/libm-test-ulps | 4 - sysdeps/s390/fpu/libm-test-ulps | 4 - sysdeps/sparc/fpu/libm-test-ulps | 4 - sysdeps/x86_64/fpu/libm-test-ulps | 4 - 20 files changed, 252 insertions(+), 67 deletions(-) create mode 100644 sysdeps/ieee754/flt-32/s_log2p1f.c diff --git a/SHARED-FILES b/SHARED-FILES index a559e97318..98ad2671b1 100644 --- a/SHARED-FILES +++ b/SHARED-FILES @@ -243,3 +243,7 @@ sysdeps/ieee754/flt-32/s_expm1f.c (file src/binary32/expm1/expm1f.c in CORE_MATH) - The code was adapted to use glibc code style and internal functions to handle errno, overflow, and underflow. +sysdeps/ieee754/flt-32/s_log2p1f.c + (file src/binary32/log2p1/log2p1f.c in CORE_MATH) + - The code was adapted to use glibc code style and internal + functions to handle errno, overflow, and underflow. diff --git a/sysdeps/aarch64/libm-test-ulps b/sysdeps/aarch64/libm-test-ulps index c6c40df9fa..cb1c18cb50 100644 --- a/sysdeps/aarch64/libm-test-ulps +++ b/sysdeps/aarch64/libm-test-ulps @@ -1422,22 +1422,18 @@ ldouble: 1 Function: "log2p1": double: 2 -float: 2 ldouble: 3 Function: "log2p1_downward": double: 2 -float: 2 ldouble: 3 Function: "log2p1_towardzero": double: 2 -float: 2 ldouble: 2 Function: "log2p1_upward": double: 2 -float: 2 ldouble: 3 Function: "log_advsimd": diff --git a/sysdeps/arc/fpu/libm-test-ulps b/sysdeps/arc/fpu/libm-test-ulps index ca01eb3b4b..d233bd75a0 100644 --- a/sysdeps/arc/fpu/libm-test-ulps +++ b/sysdeps/arc/fpu/libm-test-ulps @@ -1012,19 +1012,15 @@ float: 1 Function: "log2p1": double: 2 -float: 2 Function: "log2p1_downward": double: 2 -float: 2 Function: "log2p1_towardzero": double: 2 -float: 2 Function: "log2p1_upward": double: 2 -float: 2 Function: "log_towardzero": double: 1 diff --git a/sysdeps/arc/nofpu/libm-test-ulps b/sysdeps/arc/nofpu/libm-test-ulps index 266381f6ea..fe74fb8ea9 100644 --- a/sysdeps/arc/nofpu/libm-test-ulps +++ b/sysdeps/arc/nofpu/libm-test-ulps @@ -246,11 +246,9 @@ float: 1 Function: "log2p1": double: 1 -float: 2 Function: "logp1": double: 1 -float: 1 Function: "pow": double: 1 diff --git a/sysdeps/arm/libm-test-ulps b/sysdeps/arm/libm-test-ulps index 12451d24a7..b6b194143a 100644 --- a/sysdeps/arm/libm-test-ulps +++ b/sysdeps/arm/libm-test-ulps @@ -1006,19 +1006,15 @@ float: 3 Function: "log2p1": double: 1 -float: 2 Function: "log2p1_downward": double: 2 -float: 2 Function: "log2p1_towardzero": double: 2 -float: 2 Function: "log2p1_upward": double: 2 -float: 2 Function: "log_downward": float: 2 diff --git a/sysdeps/hppa/fpu/libm-test-ulps b/sysdeps/hppa/fpu/libm-test-ulps index 05ad1cf9b3..9f89528947 100644 --- a/sysdeps/hppa/fpu/libm-test-ulps +++ b/sysdeps/hppa/fpu/libm-test-ulps @@ -1029,19 +1029,15 @@ float: 3 Function: "log2p1": double: 2 -float: 2 Function: "log2p1_downward": double: 2 -float: 2 Function: "log2p1_towardzero": double: 2 -float: 2 Function: "log2p1_upward": double: 2 -float: 2 Function: "log_downward": float: 2 diff --git a/sysdeps/i386/fpu/libm-test-ulps b/sysdeps/i386/fpu/libm-test-ulps index abf9a9192b..d0bd63371d 100644 --- a/sysdeps/i386/fpu/libm-test-ulps +++ b/sysdeps/i386/fpu/libm-test-ulps @@ -1484,25 +1484,21 @@ ldouble: 1 Function: "log2p1": double: 1 -float: 1 float128: 3 ldouble: 4 Function: "log2p1_downward": double: 2 -float: 2 float128: 3 ldouble: 3 Function: "log2p1_towardzero": double: 2 -float: 2 float128: 2 ldouble: 3 Function: "log2p1_upward": double: 2 -float: 2 float128: 3 ldouble: 5 diff --git a/sysdeps/i386/i686/fpu/multiarch/libm-test-ulps b/sysdeps/i386/i686/fpu/multiarch/libm-test-ulps index 6d9d49d153..a97722b7e7 100644 --- a/sysdeps/i386/i686/fpu/multiarch/libm-test-ulps +++ b/sysdeps/i386/i686/fpu/multiarch/libm-test-ulps @@ -1487,25 +1487,21 @@ ldouble: 1 Function: "log2p1": double: 1 -float: 1 float128: 3 ldouble: 4 Function: "log2p1_downward": double: 2 -float: 2 float128: 3 ldouble: 4 Function: "log2p1_towardzero": double: 2 -float: 2 float128: 2 ldouble: 4 Function: "log2p1_upward": double: 1 -float: 2 float128: 3 ldouble: 5 diff --git a/sysdeps/ieee754/flt-32/s_log2p1f.c b/sysdeps/ieee754/flt-32/s_log2p1f.c new file mode 100644 index 0000000000..a185ddc376 --- /dev/null +++ b/sysdeps/ieee754/flt-32/s_log2p1f.c @@ -0,0 +1,248 @@ +/* Correctly-rounded biased argument natural logarithm function for binary32 + value. + +Copyright (c) 2022-2024 Alexei Sibidanov. + +This file is part of the CORE-MATH project +project (file src/binary32/log2p1/log2p1f.c revision bc385c2). + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#include +#include +#include +#include +#include "math_config.h" + +float +__log2p1f (float x) +{ + static const double ix[] = + { + 0x1p+0, 0x1.fc07f01fcp-1, 0x1.f81f81f82p-1, + 0x1.f44659e4ap-1, 0x1.f07c1f07cp-1, 0x1.ecc07b302p-1, + 0x1.e9131abfp-1, 0x1.e573ac902p-1, 0x1.e1e1e1e1ep-1, + 0x1.de5d6e3f8p-1, 0x1.dae6076bap-1, 0x1.d77b654b8p-1, + 0x1.d41d41d42p-1, 0x1.d0cb58f6ep-1, 0x1.cd8568904p-1, + 0x1.ca4b3055ep-1, 0x1.c71c71c72p-1, 0x1.c3f8f01c4p-1, + 0x1.c0e070382p-1, 0x1.bdd2b8994p-1, 0x1.bacf914c2p-1, + 0x1.b7d6c3ddap-1, 0x1.b4e81b4e8p-1, 0x1.b2036406cp-1, + 0x1.af286bca2p-1, 0x1.ac5701ac6p-1, 0x1.a98ef606ap-1, + 0x1.a6d01a6dp-1, 0x1.a41a41a42p-1, 0x1.a16d3f97ap-1, + 0x1.9ec8e951p-1, 0x1.9c2d14ee4p-1, 0x1.99999999ap-1, + 0x1.970e4f80cp-1, 0x1.948b0fcd6p-1, 0x1.920fb49dp-1, + 0x1.8f9c18f9cp-1, 0x1.8d3018d3p-1, 0x1.8acb90f6cp-1, + 0x1.886e5f0acp-1, 0x1.861861862p-1, 0x1.83c977ab2p-1, + 0x1.818181818p-1, 0x1.7f405fd02p-1, 0x1.7d05f417ep-1, + 0x1.7ad2208ep-1, 0x1.78a4c8178p-1, 0x1.767dce434p-1, + 0x1.745d1745ep-1, 0x1.724287f46p-1, 0x1.702e05c0cp-1, + 0x1.6e1f76b44p-1, 0x1.6c16c16c2p-1, 0x1.6a13cd154p-1, + 0x1.681681682p-1, 0x1.661ec6a52p-1, 0x1.642c8590cp-1, + 0x1.623fa7702p-1, 0x1.605816058p-1, 0x1.5e75bb8dp-1, + 0x1.5c9882b94p-1, 0x1.5ac056b02p-1, 0x1.58ed23082p-1, + 0x1.571ed3c5p-1, 0x1.555555556p-1, 0x1.5390948f4p-1, + 0x1.51d07eae2p-1, 0x1.501501502p-1, 0x1.4e5e0a73p-1, + 0x1.4cab88726p-1, 0x1.4afd6a052p-1, 0x1.49539e3b2p-1, + 0x1.47ae147aep-1, 0x1.460cbc7f6p-1, 0x1.446f86562p-1, + 0x1.42d6625d6p-1, 0x1.414141414p-1, 0x1.3fb013fbp-1, + 0x1.3e22cbce4p-1, 0x1.3c995a47cp-1, 0x1.3b13b13b2p-1, + 0x1.3991c2c18p-1, 0x1.381381382p-1, 0x1.3698df3dep-1, + 0x1.3521cfb2cp-1, 0x1.33ae45b58p-1, 0x1.323e34a2cp-1, + 0x1.30d19013p-1, 0x1.2f684bda2p-1, 0x1.2e025c04cp-1, + 0x1.2c9fb4d82p-1, 0x1.2b404ad02p-1, 0x1.29e4129e4p-1, + 0x1.288b01288p-1, 0x1.27350b882p-1, 0x1.25e22708p-1, + 0x1.24924924ap-1, 0x1.23456789ap-1, 0x1.21fb78122p-1, + 0x1.20b470c68p-1, 0x1.1f7047dc2p-1, 0x1.1e2ef3b4p-1, + 0x1.1cf06ada2p-1, 0x1.1bb4a4046p-1, 0x1.1a7b9611ap-1, + 0x1.19453808cp-1, 0x1.181181182p-1, 0x1.16e068942p-1, + 0x1.15b1e5f76p-1, 0x1.1485f0e0ap-1, 0x1.135c81136p-1, + 0x1.12358e75ep-1, 0x1.111111112p-1, 0x1.0fef010fep-1, + 0x1.0ecf56be6p-1, 0x1.0db20a89p-1, 0x1.0c9714fbcp-1, + 0x1.0b7e6ec26p-1, 0x1.0a6810a68p-1, 0x1.0953f3902p-1, + 0x1.084210842p-1, 0x1.073260a48p-1, 0x1.0624dd2f2p-1, + 0x1.05197f7d8p-1, 0x1.041041042p-1, 0x1.03091b52p-1, + 0x1.020408102p-1, 0x1.01010101p-1, 0x1p-1 + }; + + static const double lix[] = { + 0x0p+0, -0x1.6fe50b6f1eafap-7, -0x1.6e79685c160d5p-6, + -0x1.11cd1d51955bap-5, -0x1.6bad37591e03p-5, -0x1.c4dfab908ddb5p-5, + -0x1.0eb389fab4795p-4, -0x1.3aa2fdd26ae99p-4, -0x1.663f6faca846bp-4, + -0x1.918a16e4cb157p-4, -0x1.bc84240a78a13p-4, -0x1.e72ec1181cfb1p-4, + -0x1.08c588cd964e4p-3, -0x1.1dcd19759f2e3p-3, -0x1.32ae9e27627c6p-3, + -0x1.476a9f989a58ap-3, -0x1.5c01a39fa6533p-3, -0x1.70742d4eed455p-3, + -0x1.84c2bd02d6434p-3, -0x1.98edd077e9f0ap-3, -0x1.acf5e2db31eeap-3, + -0x1.c0db6cddaa82dp-3, -0x1.d49ee4c33121ap-3, -0x1.e840be751d775p-3, + -0x1.fbc16b9003e0bp-3, -0x1.0790adbae3fcp-2, -0x1.11307dad465b5p-2, + -0x1.1ac05b2924cc5p-2, -0x1.24407ab0cc41p-2, -0x1.2db10fc4ea424p-2, + -0x1.37124cea58697p-2, -0x1.406463b1d455dp-2, -0x1.49a784bcbaa37p-2, + -0x1.52dbdfc4f341dp-2, -0x1.5c01a39ff2c9bp-2, -0x1.6518fe46abaa5p-2, + -0x1.6e221cd9d6933p-2, -0x1.771d2ba7f5791p-2, -0x1.800a56315ee2ap-2, + -0x1.88e9c72df8611p-2, -0x1.91bba891d495fp-2, -0x1.9a8023920fa4dp-2, + -0x1.a33760a7fbca6p-2, -0x1.abe18797d2effp-2, -0x1.b47ebf734b923p-2, + -0x1.bd0f2e9eb2b84p-2, -0x1.c592fad2be1aap-2, -0x1.ce0a4923cf5e6p-2, + -0x1.d6753e02f4ebcp-2, -0x1.ded3fd445afp-2, -0x1.e726aa1e558fep-2, + -0x1.ef6d67325ba38p-2, -0x1.f7a8568c8aea6p-2, -0x1.ffd799a81be87p-2, + 0x1.f804ae8d33c4p-2, 0x1.efec61b04af4ep-2, 0x1.e7df5fe572606p-2, + 0x1.dfdd89d5b0009p-2, 0x1.d7e6c0abbd924p-2, 0x1.cffae611a74d6p-2, + 0x1.c819dc2d8578cp-2, 0x1.c043859e5bdbcp-2, 0x1.b877c57b47c04p-2, + 0x1.b0b67f4f29a66p-2, 0x1.a8ff97183ed07p-2, 0x1.a152f14293c74p-2, + 0x1.99b072a9289cap-2, 0x1.921800927e284p-2, 0x1.8a8980ac4113p-2, + 0x1.8304d90c2859dp-2, 0x1.7b89f02cbd49ap-2, 0x1.7418aceb84ab1p-2, + 0x1.6cb0f68656c95p-2, 0x1.6552b49993dc2p-2, 0x1.5dfdcf1eacd7bp-2, + 0x1.56b22e6b97c18p-2, 0x1.4f6fbb2ce6943p-2, 0x1.48365e6957b42p-2, + 0x1.4106017c0dbcfp-2, 0x1.39de8e15727d9p-2, 0x1.32bfee37489bcp-2, + 0x1.2baa0c34989c3p-2, 0x1.249cd2b177fd5p-2, 0x1.1d982c9d50468p-2, + 0x1.169c0536677acp-2, 0x1.0fa848045f67bp-2, 0x1.08bce0d9a7c6p-2, + 0x1.01d9bbcf66a2cp-2, 0x1.f5fd8a90e2d85p-3, 0x1.e857d3d3af1e5p-3, + 0x1.dac22d3ec5f4ep-3, 0x1.cd3c712db459ap-3, 0x1.bfc67a7ff3c22p-3, + 0x1.b2602497678f4p-3, 0x1.a5094b555a1f8p-3, 0x1.97c1cb136b96fp-3, + 0x1.8a8980ac8652dp-3, 0x1.7d60496c83f66p-3, 0x1.7046031c7cdafp-3, + 0x1.633a8bf460335p-3, 0x1.563dc2a08b102p-3, 0x1.494f863bbc1dep-3, + 0x1.3c6fb6507a37ep-3, 0x1.2f9e32d5257ecp-3, 0x1.22dadc2a627efp-3, + 0x1.1625931802e49p-3, 0x1.097e38cef9519p-3, 0x1.f9c95dc138295p-4, + 0x1.e0b1ae90505f6p-4, 0x1.c7b528b5fcffap-4, 0x1.aed391abb17a1p-4, + 0x1.960caf9bd35eap-4, 0x1.7d60496e3edebp-4, 0x1.64ce26bf2108ep-4, + 0x1.4c560fe5b573bp-4, 0x1.33f7cde24adfbp-4, 0x1.1bb32a5ed9353p-4, + 0x1.0387efbd3006ep-4, 0x1.d6ebd1f1d0955p-5, 0x1.a6f9c37a8beabp-5, + 0x1.77394c9d6762cp-5, 0x1.47aa07358e1a4p-5, 0x1.184b8e4d490efp-5, + 0x1.d23afc4d95c78p-6, 0x1.743ee8678a7cbp-6, 0x1.16a21e243bf78p-6, + 0x1.72c7ba20c907ep-7, 0x1.720d9c0536e17p-8, 0x0p+0 + }; + + double z = x; + uint32_t ux = asuint (x); + uint32_t ax = ux & (~0u >> 1); + if (__glibc_unlikely (ux >= 0x17fu << 23)) + { /* x <= -1 */ + if (ux == (0x17fu << 23)) + return __math_divzerof (1); + if (ux > (0x1ffu << 23)) + return x + x; /* nan */ + return __math_invalidf (x); + } + else if (__glibc_unlikely (ax >= (0xff << 23))) + { /* +inf, nan */ + if (ax > (0xff << 23)) + return x + x; /* nan */ + return INFINITY; + } + else if (__glibc_likely (ax < 0x3cb7aa26u)) + { /* |x| < 0x1.6f544cp-6 */ + double z2 = z * z, z4 = z2 * z2; + if ( __glibc_likely(ax < 0x3b9d9d34u)) + { /* |x| < 0x1.3b3a68p-8 */ + if (__glibc_likely (ax < 0x39638a7eu)) + { /* |x| < 0x1.c714fcp-13 */ + if (__glibc_likely (ax < 0x329c5639u)) + { /* |x| < 0x1.38ac72p-26 */ + static const double c[] = + { + 0x1.71547652b82fep+0, -0x1.71547652b82ffp-1 + }; + return z * (c[0] + z * c[1]); + } + else + { + if (__glibc_unlikely (ux == 0x32ff7045u)) + return 0x1.70851ap-25f - 0x1.8p-80f; + if (__glibc_unlikely (ux == 0xb395efbbu)) + return -0x1.b0a00ap-24f + 0x1p-76f; + if (__glibc_unlikely (ux == 0x35a14df7u)) + return 0x1.d16d2p-20f + 0x1p-72f; + if (__glibc_unlikely (ux == 0x3841cb81u)) + return 0x1.17949ep-14f + 0x1p-67f; + static const double c[] = + { + 0x1.71547652b82fep+0, -0x1.71547652b82fdp-1, + 0x1.ec709ead0c9a7p-2, -0x1.7154773c1cb29p-2 + }; + return z * ((c[0] + z * c[1]) + z2 * (c[2] + z * c[3])); + } + } + else + { + if (__glibc_unlikely (ux == 0xbac9363du)) + return -0x1.2282aap-9f + 0x1p-61f; + static const double c[] = + { + 0x1.71547652b82fep+0, -0x1.71547652b83p-1, + 0x1.ec709dc28f51bp-2, -0x1.7154765157748p-2, + 0x1.2778a510a3682p-2, -0x1.ec745df1551fcp-3 + }; + return z + * ((c[0] + z * c[1]) + z2 * (c[2] + z * c[3]) + + z4 * ((c[4] + z * c[5]))); + } + } + else + { + static const double c[] = + { + 0x1.71547652b82fep+0, -0x1.71547652b82fbp-1, + 0x1.ec709dc3b6a73p-2, -0x1.71547652dc09p-2, + 0x1.2776c1a88901p-2, -0x1.ec7095bd4d208p-3, + 0x1.a66bec7fc8f7p-3, -0x1.71a900fc3f3f9p-3 + }; + return z + * ((c[0] + z * c[1]) + z2 * (c[2] + z * c[3]) + + z4 * ((c[4] + z * c[5]) + z2 * (c[6] + z * c[7]))); + } + } + else + { /* |x| >= 0x1.6f544cp-6 */ + float h, l; + /* With gcc 6.3.0, if we return 0x1.e90026p+4f + 0x1.fp-21 + in the second exceptional case, with rounding up it yields + 0x1.e90026p+4 which is incorrect, thus we use this workaround. See + https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112367. */ + if (__glibc_unlikely (ux == 0x52928e33u)) + { + h = 0x1.318ffap+5f; + l = 0x1.fp-20f; + return h + l; + } + if (__glibc_unlikely (ux == 0x4ebd09e3u)) + { + h = 0x1.e90026p+4f; + l = 0x1.fp-21; + return h + l; + } + uint64_t tp = asuint64 (z + 1.0); + uint64_t m = tp & (~(uint64_t) 0 >> 12); + int e = (tp >> 52) - 0x3ff; + int j = (m + ((int64_t) 1 << (52 - 8))) >> (52 - 7), k = j > 53; + e += k; + double xd = asdouble (m | (uint64_t) 0x3ff << 52); + z = fma (xd, ix[j], -1.0); + static const double c[] = + { + 0x1.71547652b82fep+0, -0x1.71547652b82ffp-1, 0x1.ec709dc32988bp-2, + -0x1.715476521ec2bp-2, 0x1.277801a1ad904p-2, -0x1.ec731704d6a88p-3 + }; + double z2 = z * z; + double c0 = c[0] + z * c[1]; + double c2 = c[2] + z * c[3]; + double c4 = c[4] + z * c[5]; + c0 += z2 * (c2 + z2 * c4); + return (z * c0 - lix[j]) + e; + } +} +libm_alias_float (__log2p1, log2p1) diff --git a/sysdeps/loongarch/lp64/libm-test-ulps b/sysdeps/loongarch/lp64/libm-test-ulps index 5d407a49fe..b59d68202e 100644 --- a/sysdeps/loongarch/lp64/libm-test-ulps +++ b/sysdeps/loongarch/lp64/libm-test-ulps @@ -1252,22 +1252,18 @@ ldouble: 1 Function: "log2p1": double: 2 -float: 2 ldouble: 3 Function: "log2p1_downward": double: 2 -float: 2 ldouble: 3 Function: "log2p1_towardzero": double: 2 -float: 2 ldouble: 2 Function: "log2p1_upward": double: 2 -float: 2 ldouble: 3 Function: "log_downward": diff --git a/sysdeps/m68k/m680x0/fpu/libm-test-ulps b/sysdeps/m68k/m680x0/fpu/libm-test-ulps index 7fef8942ae..3964b83b81 100644 --- a/sysdeps/m68k/m680x0/fpu/libm-test-ulps +++ b/sysdeps/m68k/m680x0/fpu/libm-test-ulps @@ -1091,19 +1091,15 @@ double: 1 Function: "log2p1": double: 1 -float: 2 Function: "log2p1_downward": double: 1 -float: 2 Function: "log2p1_towardzero": double: 1 -float: 2 Function: "log2p1_upward": double: 1 -float: 2 Function: "logp1": double: 1 diff --git a/sysdeps/mips/mips32/libm-test-ulps b/sysdeps/mips/mips32/libm-test-ulps index f9d7bf8598..f1d0543aea 100644 --- a/sysdeps/mips/mips32/libm-test-ulps +++ b/sysdeps/mips/mips32/libm-test-ulps @@ -1003,22 +1003,18 @@ float: 3 Function: "log2p1": double: 1 -float: 2 ldouble: 1 Function: "log2p1_downward": double: 2 -float: 2 ldouble: 2 Function: "log2p1_towardzero": double: 2 -float: 2 ldouble: 2 Function: "log2p1_upward": double: 2 -float: 2 ldouble: 1 Function: "log_downward": diff --git a/sysdeps/mips/mips64/libm-test-ulps b/sysdeps/mips/mips64/libm-test-ulps index 4f3c82d64c..fecd998560 100644 --- a/sysdeps/mips/mips64/libm-test-ulps +++ b/sysdeps/mips/mips64/libm-test-ulps @@ -1260,22 +1260,18 @@ ldouble: 1 Function: "log2p1": double: 1 -float: 2 ldouble: 3 Function: "log2p1_downward": double: 2 -float: 2 ldouble: 3 Function: "log2p1_towardzero": double: 2 -float: 2 ldouble: 2 Function: "log2p1_upward": double: 2 -float: 2 ldouble: 3 Function: "log_downward": diff --git a/sysdeps/powerpc/fpu/libm-test-ulps b/sysdeps/powerpc/fpu/libm-test-ulps index ddbd184e58..f775c56618 100644 --- a/sysdeps/powerpc/fpu/libm-test-ulps +++ b/sysdeps/powerpc/fpu/libm-test-ulps @@ -1569,25 +1569,21 @@ ldouble: 4 Function: "log2p1": double: 2 -float: 2 float128: 3 ldouble: 2 Function: "log2p1_downward": double: 2 -float: 2 float128: 3 ldouble: 4 Function: "log2p1_towardzero": double: 2 -float: 2 float128: 2 ldouble: 5 Function: "log2p1_upward": double: 2 -float: 2 float128: 3 ldouble: 6 diff --git a/sysdeps/powerpc/nofpu/libm-test-ulps b/sysdeps/powerpc/nofpu/libm-test-ulps index c79dfcc2cc..a732166765 100644 --- a/sysdeps/powerpc/nofpu/libm-test-ulps +++ b/sysdeps/powerpc/nofpu/libm-test-ulps @@ -1317,22 +1317,18 @@ ldouble: 4 Function: "log2p1": double: 1 -float: 2 ldouble: 2 Function: "log2p1_downward": double: 2 -float: 2 ldouble: 4 Function: "log2p1_towardzero": double: 2 -float: 2 ldouble: 5 Function: "log2p1_upward": double: 2 -float: 2 ldouble: 6 Function: "log_downward": diff --git a/sysdeps/riscv/nofpu/libm-test-ulps b/sysdeps/riscv/nofpu/libm-test-ulps index 4caf84f316..739d04bc5c 100644 --- a/sysdeps/riscv/nofpu/libm-test-ulps +++ b/sysdeps/riscv/nofpu/libm-test-ulps @@ -1209,7 +1209,6 @@ ldouble: 1 Function: "log2p1": double: 1 -float: 1 ldouble: 3 Function: "log_downward": diff --git a/sysdeps/riscv/rvd/libm-test-ulps b/sysdeps/riscv/rvd/libm-test-ulps index e9c4b72c04..f6bb6e05e1 100644 --- a/sysdeps/riscv/rvd/libm-test-ulps +++ b/sysdeps/riscv/rvd/libm-test-ulps @@ -1252,22 +1252,18 @@ ldouble: 1 Function: "log2p1": double: 2 -float: 2 ldouble: 3 Function: "log2p1_downward": double: 2 -float: 2 ldouble: 3 Function: "log2p1_towardzero": double: 2 -float: 2 ldouble: 2 Function: "log2p1_upward": double: 2 -float: 2 ldouble: 3 Function: "log_downward": diff --git a/sysdeps/s390/fpu/libm-test-ulps b/sysdeps/s390/fpu/libm-test-ulps index a42c9f273a..b444d4475e 100644 --- a/sysdeps/s390/fpu/libm-test-ulps +++ b/sysdeps/s390/fpu/libm-test-ulps @@ -1251,22 +1251,18 @@ ldouble: 1 Function: "log2p1": double: 2 -float: 2 ldouble: 3 Function: "log2p1_downward": double: 2 -float: 2 ldouble: 3 Function: "log2p1_towardzero": double: 2 -float: 2 ldouble: 2 Function: "log2p1_upward": double: 2 -float: 2 ldouble: 3 Function: "log_downward": diff --git a/sysdeps/sparc/fpu/libm-test-ulps b/sysdeps/sparc/fpu/libm-test-ulps index 3bee496247..c7f8531d6d 100644 --- a/sysdeps/sparc/fpu/libm-test-ulps +++ b/sysdeps/sparc/fpu/libm-test-ulps @@ -1260,22 +1260,18 @@ ldouble: 1 Function: "log2p1": double: 1 -float: 2 ldouble: 3 Function: "log2p1_downward": double: 2 -float: 2 ldouble: 3 Function: "log2p1_towardzero": double: 2 -float: 2 ldouble: 2 Function: "log2p1_upward": double: 2 -float: 2 ldouble: 3 Function: "log_downward": diff --git a/sysdeps/x86_64/fpu/libm-test-ulps b/sysdeps/x86_64/fpu/libm-test-ulps index ffb1d4f3c9..de19bf26f7 100644 --- a/sysdeps/x86_64/fpu/libm-test-ulps +++ b/sysdeps/x86_64/fpu/libm-test-ulps @@ -1910,25 +1910,21 @@ float: 1 Function: "log2p1": double: 2 -float: 2 float128: 3 ldouble: 4 Function: "log2p1_downward": double: 2 -float: 2 float128: 3 ldouble: 4 Function: "log2p1_towardzero": double: 2 -float: 2 float128: 2 ldouble: 4 Function: "log2p1_upward": double: 2 -float: 2 float128: 3 ldouble: 5