From patchwork Fri Oct 25 18:21:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 838376 Delivered-To: patch@linaro.org Received: by 2002:adf:e287:0:b0:37d:45d0:187 with SMTP id v7csp442881wri; Fri, 25 Oct 2024 11:26:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVdfHiw+pZTFW6ZPQEcLxpuzib6pXSO8ZG6heQbGCR8RRTbgWOWHJwTtCHNmg6mdlpBkdZ0BQ==@linaro.org X-Google-Smtp-Source: AGHT+IFzB9O79tOlvrIwbpsjrhn/CN7pSZRLKUFiRKKWkb4UaDLMDJxbgrW8XF7o7yi41sb2yO71 X-Received: by 2002:a05:6214:3f8b:b0:6cb:e3ec:18c1 with SMTP id 6a1803df08f44-6d18570b647mr4541546d6.15.1729880815089; Fri, 25 Oct 2024 11:26:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1729880815; cv=pass; d=google.com; s=arc-20240605; b=QpKKHid8lysMq6eL5THa69XN8wQLySOjmrhipzwLF1whAgezjZmHJBil5gFvq2nl6j CCSmzoa6r86RbyECKmPCYEmxfFyscdT720nrtp+wY/7R2r407Md2hqAJqDPBDPwCBkYG y3n/CUtstvZn/VOh4v64Rygb9V9RC/R/66RG4MptpieYFqqCAOp3/ClnpFGBPYxye9wZ faHsZ6UPBGDvmM2a5ZXUpgaJbrZsWUOnaxjUvivqyYWcW70XZALVeNJUzlrKG50Ne1+A BJ8O55GysJG30Ts/2HG55NGu8qkhVG0dsN0vU6dwEWJL8Y5E6p++sKGf5WsHtzrXcxFw RsQw== 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=qC+B9ZD/JWyWHwXjehnL/2uKtcoBMvUbW08CMg7HjJs=; fh=t7K9SrKfAVamsrcTQr7hpJTc6WX7Vbl5hwH62Vkp0W0=; b=e/8K/EZF9y+1KQti+YMuZBblJD6XqwuJeGfSU1fS/+Q3WBrJVT03TPF0d3QyaJ4PvO N/JhU3VY0wvk2yQiW8UsenJulU+CkyOxnSw2Nz8EQ5WN7gIBnZM6ptonv5gn4tPEOt1M AjMePPrccBKKZoJPiIw5nqMT13K0cBNJ87C0JFzx9XGhREaahnc+A5ivAKlLwTxXpE7e mYtkFGNVUkJ+kik2jeEx7lLEl3/chhkuZqaT+4+ut2ZzXY5RCfJZHbFLzxzARM2G2fkf 5Ps9WuzMkaF3/LCouLOiJID4MqVJwyrMBmfcVJvneG6UMN2mUQfnasMy9Uw1zZ1r8cPo th8A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=z4OZH5XN; 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 6a1803df08f44-6d179a4c773si21354076d6.415.2024.10.25.11.26.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Oct 2024 11:26:55 -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=z4OZH5XN; 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 AA4303858CD1 for ; Fri, 25 Oct 2024 18:26:54 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by sourceware.org (Postfix) with ESMTPS id 7F1423858D29 for ; Fri, 25 Oct 2024 18:26:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7F1423858D29 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 7F1423858D29 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::632 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729880800; cv=none; b=SJBjx4tYwSWDDcj77ImZiXCK4l/PfSJtRcxoGuE0cOdoyfbuM1lbt/Or+Nz4ti9AmeoN27TzUjz1HyZpY1RO8n/8bPIpoY/K8vaa9TQHMprzlnaTdme73XqShRFO6sV5BD/kSyM7E6VWWBXn7CNfnmfFKjoRN3/snHG2iPKGtFk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729880800; c=relaxed/simple; bh=oRS6lUdlHnQvGnFAVcf/qeLt3HxV47QVKsjDp1O0vSg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=E1Xdvq9Rq4nwFbljuusiSsjbXFA9gc8k2pPvYH5he9Fo9YuJXekChI7ZbIl/gOv7npstJDfbYZcN1foopd3jKZ1k+zEmZMe8SOt0jpKPmpk8N1emY7THRh/EVf1dHvlyC3T4ulY4HTBQGf2mKmRtGeMsXWN+o4thm98OkCAJIAk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-20bb39d97d1so19004315ad.2 for ; Fri, 25 Oct 2024 11:26:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1729880784; x=1730485584; 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=qC+B9ZD/JWyWHwXjehnL/2uKtcoBMvUbW08CMg7HjJs=; b=z4OZH5XNwtyMF7Vfdh97abfYAenYdiY9n9xSGbpgoAkpUxdD7DPqD4lgpgY9WX9/YA br0D9z38K/aLhKJ4QGCgN8Ou7GJ8V7tKeN8zg6NcYGNJvf8S1juJFU+FlKuDTlLRYlNs hKYCtSlm23rm8ewyvzb57neNs2osJuySFGWxQjjaP7WNvwN88EOdXD/3/obAcIV+m24D m5QhiTZvMJcaXh50YN9ASd7eD6bCietODgVqJNi2Nt0/9Aei/GYhympb4FMhdpjSmIGV ecgljmHqb7M+Pk2ypiv7AUQSK3zxaMiPfj3iJNLRiu5th0uDRMQC9T9rANPFrpzGw6fd m7Qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729880784; x=1730485584; 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=qC+B9ZD/JWyWHwXjehnL/2uKtcoBMvUbW08CMg7HjJs=; b=AEyeIhSvdaPGCyTow8JSgZDptJv7BHD64KGDf8qry+P142GGJl4L/oO8SxRxmp9wXk QkX8z7yWUEtsvH94jR4Vyp4oHjYQ/kwq41JYdxhWg4eTp8VdwBb18R3NtWu3bX+izTGX B1LxVS6g2Uq/Wa6EAcex/LfIzTIOilZwEy43bCmATG06UjF98VBRrBwk32bd7B14GGsz QOZYD5kaBurWOHA4rexbV54a9Wjk1wt/QeTctFj/U5C7otaFDhRkHG+lD3Cs6mvqhAWq RDYMHkga6iLljqBnqXn3gd9vefxazyG6ka9M9vGkey7M+D6W7TfQURnqg8rlfYuxTlLL MfZA== X-Gm-Message-State: AOJu0Yw1EkcnDmdyD46bgA5oaxaLlL7QI8hw53Nwjzr9MXxkghUOEfKz aql/jqyLea1wlmv09nafPnCZPW/5D7ZqTygJqcUqJK6beovy4lNIn7Asd2Jybm+U/yvxqvfHgWd S X-Received: by 2002:a17:902:e746:b0:20b:4f95:932d with SMTP id d9443c01a7336-210c686a10fmr888685ad.3.1729880784304; Fri, 25 Oct 2024 11:26:24 -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.26.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Oct 2024 11:26:22 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Paul Zimmermann , Alexei Sibidanov Subject: [PATCH 01/17] math: Add e_gammaf_r to glibc code and style Date: Fri, 25 Oct 2024 15:21:39 -0300 Message-ID: <20241025182614.2022697-2-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.3 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.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 Also remove the use of builtins in favor of standard names, compiler already inline them (if supported) with current compiler options. It also fixes and issue where __builtin_roundeven is not support on gcc older than version 10. Checked on x86_64-linux-gnu and i686-linux_gnu. Signed-off-by: Adhemerval Zanella --- sysdeps/ieee754/flt-32/e_gammaf_r.c | 178 ++++++++++++++++------------ sysdeps/m68k/m680x0/fpu/math_errf.c | 1 - 2 files changed, 101 insertions(+), 78 deletions(-) delete mode 100644 sysdeps/m68k/m680x0/fpu/math_errf.c diff --git a/sysdeps/ieee754/flt-32/e_gammaf_r.c b/sysdeps/ieee754/flt-32/e_gammaf_r.c index 90ed3b4890..8c32d9bf5d 100644 --- a/sysdeps/ieee754/flt-32/e_gammaf_r.c +++ b/sysdeps/ieee754/flt-32/e_gammaf_r.c @@ -37,9 +37,7 @@ SOFTWARE. #include #include #include - -typedef union {float f; uint32_t u;} b32u32_u; -typedef union {double f; uint64_t u;} b64u64_u; +#include "math_config.h" float __ieee754_gammaf_r (float x, int *signgamp) @@ -54,97 +52,123 @@ __ieee754_gammaf_r (float x, int *signgamp) /* List of exceptional cases. Each entry contains the 32-bit encoding u of x, a binary32 approximation f of gamma(x), and a correction term df. */ - static const struct {uint32_t u; float f, df;} tb[] = { - {0x27de86a9u, 0x1.268266p+47f, 0x1p22f}, // x = 0x1.bd0d52p-48 - {0x27e05475u, 0x1.242422p+47f, 0x1p22f}, // x = 0x1.c0a8eap-48 - {0xb63befb3u, -0x1.5cb6e4p+18f, 0x1p-7f}, // x = -0x1.77df66p-19 - {0x3c7bb570u, 0x1.021d9p+6f, 0x1p-19f}, // x = 0x1.f76aep-7 - {0x41e886d1u, 0x1.33136ap+98f, 0x1p73f}, // x = 0x1.d10da2p+4 - {0xc067d177u, 0x1.f6850cp-3f, 0x1p-28f}, // x = -0x1.cfa2eep+1 - {0xbd99da31u, -0x1.befe66p+3, -0x1p-22f}, // x = -0x1.33b462p-4 - {0xbf54c45au, -0x1.a6b4ecp+2, +0x1p-23f}, // x = -0x1.a988b4p-1 - {0x41ee77feu, 0x1.d3631cp+101, -0x1p-76f}, // x = 0x1.dceffcp+4 - {0x3f843a64u, 0x1.f6c638p-1, 0x1p-26f}, // x = 0x1.0874c8p+0 + static const struct + { + uint32_t u; + float f, df; + } tb[] = { + { 0x27de86a9u, 0x1.268266p+47f, 0x1p22f }, /* x = 0x1.bd0d52p-48 */ + { 0x27e05475u, 0x1.242422p+47f, 0x1p22f }, /* x = 0x1.c0a8eap-48 */ + { 0xb63befb3u, -0x1.5cb6e4p+18f, 0x1p-7f }, /* x = -0x1.77df66p-19 */ + { 0x3c7bb570u, 0x1.021d9p+6f, 0x1p-19f }, /* x = 0x1.f76aep-7 */ + { 0x41e886d1u, 0x1.33136ap+98f, 0x1p73f }, /* x = 0x1.d10da2p+4 */ + { 0xc067d177u, 0x1.f6850cp-3f, 0x1p-28f }, /* x = -0x1.cfa2eep+1 */ + { 0xbd99da31u, -0x1.befe66p+3, -0x1p-22f }, /* x = -0x1.33b462p-4 */ + { 0xbf54c45au, -0x1.a6b4ecp+2, +0x1p-23f }, /* x = -0x1.a988b4p-1 */ + { 0x41ee77feu, 0x1.d3631cp+101, -0x1p-76f }, /* x = 0x1.dceffcp+4 */ + { 0x3f843a64u, 0x1.f6c638p-1, 0x1p-26f }, /* x = 0x1.0874c8p+0 */ }; - b32u32_u t = {.f = x}; - uint32_t ax = t.u<<1; - if(__builtin_expect(ax>=(0xffu<<24), 0)){ /* x=NaN or +/-Inf */ - if(ax==(0xffu<<24)){ /* x=+/-Inf */ - if(t.u>>31){ /* x=-Inf */ - return x / x; /* will raise the "Invalid operation" exception */ - } - return x; /* x=+Inf */ + uint32_t t = asuint (x); + uint32_t ax = t << 1; + if (__glibc_unlikely (ax >= (0xffu << 24))) + { /* x=NaN or +/-Inf */ + if (ax == (0xffu << 24)) + { /* x=+/-Inf */ + if (t >> 31) /* x=-Inf */ + return __math_invalidf (x); + return x; /* x=+Inf */ + } + return x + x; /* x=NaN, where x+x ensures the "Invalid operation" + exception is set if x is sNaN */ } - return x + x; /* x=NaN, where x+x ensures the "Invalid operation" - exception is set if x is sNaN */ - } double z = x; - if(__builtin_expect(ax<0x6d000000u, 0)){ /* |x| < 0x1p-18 */ - volatile double d = (0x1.fa658c23b1578p-1 - 0x1.d0a118f324b63p-1*z)*z - 0x1.2788cfc6fb619p-1; - double f = 1.0/z + d; - float r = f; - b64u64_u rt = {.f = f}; - if(((rt.u+2)&0xfffffff) < 4){ - for(unsigned i=0;i= 0x1.18522p+5f)) + { + /* Overflow case. The original CORE-MATH code returns 0x1p127f * + 0x1p127f, but apparently some compilers replace this by +Inf. */ + return math_narrow_eval (x * 0x1p127f); } - return r; - } - float fx = __builtin_floorf(x); - if(__builtin_expect(x >= 0x1.18522p+5f, 0)){ - /* Overflow case. The original CORE-MATH code returns 0x1p127f * 0x1p127f, - but apparently some compilers replace this by +Inf. */ - return math_narrow_eval (x * 0x1p127f); - } /* compute k only after the overflow check, otherwise the case to integer might overflow */ int k = fx; - if(__builtin_expect(fx==x, 0)){ /* x is integer */ - if(x == 0.0f){ - return 1.0f/x; + if (__glibc_unlikely (fx == x)) + { /* x is integer */ + if (x == 0.0f) + return 1.0f / x; + if (x < 0.0f) + return __math_invalidf (0.0f); + double t0 = 1, x0 = 1; + for (int i = 1; i < k; i++, x0 += 1.0) + t0 *= x0; + return t0; } - if(x < 0.0f){ - return 0.0f / 0.0f; /* should raise the "Invalid operation" exception */ + if (__glibc_unlikely (x < -42.0f)) + { /* negative non-integer */ + /* For x < -42, x non-integer, |gamma(x)| < 2^-151. */ + static const float sgn[2] = { 0x1p-127f, -0x1p-127f }; + /* Underflows always happens */ + return math_narrow_eval (0x1p-127f * sgn[k & 1]); } - double t0 = 1, x0 = 1; - for(int i=1; i