From patchwork Fri Apr 25 20:44:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 884431 Delivered-To: patch@linaro.org Received: by 2002:a5d:474d:0:b0:38f:210b:807b with SMTP id o13csp4158607wrs; Fri, 25 Apr 2025 13:58:45 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVgGx3r9fJT87CWn9TA2/dw3sEleBB+a5Od8VSqSe6pvZMzvL1fU8nxMzvqR8mN/YACFtBAjg==@linaro.org X-Google-Smtp-Source: AGHT+IHx2Lh2k7X4KgYqGEi511WbWBOIJJ6TrfwvcmEvzuPlxwYfaLyqGzbYRgNC5rrxMkaqJKD9 X-Received: by 2002:a05:622a:178a:b0:477:1134:3ee with SMTP id d75a77b69052e-4801c1cc4e8mr68006551cf.4.1745614724941; Fri, 25 Apr 2025 13:58:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1745614724; cv=pass; d=google.com; s=arc-20240605; b=Ecvmb0w799Uw4LrDYIo1xOWeyDNz1YR3OwbKgLPV9PjVsEHs86Ea6oSsm6AqFf45tx AExtuuHkIDxVRa8Y8BcmpwewXoc/1yriomXP8lmtBuFvUUtPDsF9RXON8Sn0NW7Zmyt7 MZTBcmc8tJGuIQ2pNC/PZ+CtXm5loDhQf2KGr2rkiWAA7MAbvPiZorjV2iUxDZIWw6Nh 0IGAqNwftidg4nI4U9WfRDscbQLhlyKpazHuq1vjoWA/yCMMHR0NdOsJ2s1p6zBDF4zb 11ENZLTj0qeGgFmDqqrIJhloMVlmfJB8/bpj6nbDukL/jiPGq+pKamgU8NZ1uT0FJ7oQ udow== 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:to:from :dkim-signature:dkim-filter:arc-filter:dmarc-filter:delivered-to :dkim-filter; bh=8Z9EPWVIDQFJAUS4pfEVqhk6j/q3sAd88n4z+M/0XSM=; fh=dHLBnA+MhGtNtN2B2JMAELi4oD+gmgMg7DL8H0jYbkI=; b=IakhU0irPSKyWMsBwiVG0nNMVIE3o4zNteKi0tv8Y+yg5Lz5Yv6++jSJNIpKIjoHiq W58KnisiKbfiR2My62+jcB4JV4sK5uWlBzYMrvVp5Fv03bGZYNIUUNJ9ASjMQNqqa2xo EeO7a7GmGDZVbBxJdagwAp1hxQoS6uAvOxALLjraU9Q70bxS6S9ZyeSMZoH+B+zRXXoD N+NABeoKLCQv1eY2ir1lJF7QQWPGg1hVp9zOycNDnFuxKvHa8mZl1opiYieJjqh3+I7y vHFhvyIsojU4EMiTjYYRgY+w2Pg+alOFQDyYC2mW3GPc6tve1SFKVuQuk3F87PMNzeNW qtcg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="YaX/EIvg"; 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 d75a77b69052e-47ea1e95dc3si46394691cf.371.2025.04.25.13.58.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Apr 2025 13:58:44 -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="YaX/EIvg"; 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 792C8385840F for ; Fri, 25 Apr 2025 20:58:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 792C8385840F Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=YaX/EIvg X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by sourceware.org (Postfix) with ESMTPS id A3FDE3858D38 for ; Fri, 25 Apr 2025 20:53:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A3FDE3858D38 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 A3FDE3858D38 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::52b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1745614397; cv=none; b=k/txYymQic/L7CHBHoGkPs7mq3If5UgeYF1FAmqcNXLQdZvSeXJHR5gG4ptR6o/mh6CC2lwPZZq0f5aOdM9fTxariCm8zuC/8RzjYcvMrcEFfn8K9KH2XN+FYsVZ0KVgWhnjALLiYwk8OB7vXhSqZqRpchjZSrSgNdxCnIbjP7U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1745614397; c=relaxed/simple; bh=Jg2QpW4ri5d/T1T7m4edquh23vSCWHDM+G5yXOV3MFw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=CAJdmkUJPBmV8LryZCt46q4dmY5ysXLOWzrEnUDW1pGLL1TdQUmSFx4G7WeGpMptUdnCsBiLG2Q5E5+BIIq8tXnV+fiv9xqF9dWBfKM70G8wd27eBSjnt5p9iRHuldu++riaf6g5eDJqkfZyZcfbfLkjUbC6b9X5EPXyokR+IQY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A3FDE3858D38 Received: by mail-pg1-x52b.google.com with SMTP id 41be03b00d2f7-b0b2ce7cc81so2683285a12.3 for ; Fri, 25 Apr 2025 13:53:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1745614396; x=1746219196; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=8Z9EPWVIDQFJAUS4pfEVqhk6j/q3sAd88n4z+M/0XSM=; b=YaX/EIvgGxnHjCDsrNph3hMHHb2egTCRGcK4u5dNNVmAQ0b5d8mh5mHMwsKKFtfZs8 Q79rErBLfwFSseMexJI15TIcDl964esTT6gU+iOD2g8HpP+UlypdpBh3DYKq8MlrEGE/ w0SH0HUBZBA51A98bA8EMNx6MEq/27VEga3xmgYuVSTCrP8SWBtvMnIvyzyM5UOrjOPQ rPTf6IiJNVAX6m4CMzsfRIlAvTmdybv5PboN/SQXEAIEN3NkfV6GU1RMvmhPaSfTyBS1 Y+r6cHFHa0/pLJoOJvyLYc+a3fVXio0LEs4TQUS3eKCHFeH76RphNlBewA292veYIWUU EpEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745614396; x=1746219196; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8Z9EPWVIDQFJAUS4pfEVqhk6j/q3sAd88n4z+M/0XSM=; b=LRXvm95zPAcgYeCM2Ed2q0WuUEVsowH/suofDOmJ+gQLApcvYCRiFm37bGfLF9ZMYf Af75JQtZcnMLppgoglC0dtI5JaEh4goHOT7F3R7kxd9ZoMRs2nGJxRaTd1ColPvOn1Bv XeytvAXYLEHgjYMq+EBeGnojmAyINFnThVCH7d8x/kSMSKjmGSnB/Kst3DzbQqZVwEmK xOIZ7C8nOzBKxOmHFHGGZMHhUObPAXbdrziGyXZEnOO73UD/iXBWoEFPYEn/ZaNTEMYV bct9wThY1uMYQ/q1j9VXuzLLLDzA5Nmq4c6C2K1SE3yVfdALWVhVafeL75TYLqfGRBD6 jx3g== X-Gm-Message-State: AOJu0YyAIvvMsMzzi7NV4P5KSdKtsueKbbV+EAMGTNY5c8jI5syCns3H tgP+KPGL1IuJQE1npa2APzjy+p+mAA/7w9ZkwAcTs4JrRypuaGWHWUWYFxaS6rwYC3XBNW2jYAB W X-Gm-Gg: ASbGncsTT+ifS4wZEu8ctoMisOIJiu6CIzVZAoyCWXKIFq1alsDH3NWrQNOlcplSUfR j1FJReszbNXdKfSc+VrUEzwfwCUNUJQXeZ4sXoioQfRTYgQKqgSlyO06B4UkmipxrITfmkOThGM 0MmBFf/lxtU47r1+tmDeDnWNBZGKW9pWdI+ts9/zNpW/JeGVoIRuIMK9NRJiuv4VQDlPlxC39A8 4iF8PNQRBAg0poDDwAXAQ5qda8kzubV6Re/KXMM2Us4lFyBgilEMZW65JkH1co1raBm+UM5AO5d AfgAhl1FxRsCQQ5tbHqSw2B0lPgWRRTy4ZrilTeSPFdQ8jEEpdrzkw== X-Received: by 2002:a17:90b:258f:b0:309:f407:5ad1 with SMTP id 98e67ed59e1d1-309f7dd8b16mr6230674a91.14.1745614396347; Fri, 25 Apr 2025 13:53:16 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:9bf1:37fb:44e3:5707:516b]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-309f77371efsm2385260a91.9.2025.04.25.13.53.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Apr 2025 13:53:15 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 2/4] math: Optimize double ilogb/llogb Date: Fri, 25 Apr 2025 17:44:08 -0300 Message-ID: <20250425205309.3866442-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250425205309.3866442-1-adhemerval.zanella@linaro.org> References: <20250425205309.3866442-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 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 By removing the wrapper and setting FE_INVALID and errno inline. Checked on aarch64-linux-gnu and x86_64-linux-gnu. --- sysdeps/ieee754/dbl-64/e_ilogb.c | 42 +------------------ sysdeps/ieee754/dbl-64/w_ilogb.c | 69 ++++++++++++++++++++++++++++++++ sysdeps/ieee754/dbl-64/w_llogb.c | 2 + 3 files changed, 72 insertions(+), 41 deletions(-) create mode 100644 sysdeps/ieee754/dbl-64/w_ilogb.c create mode 100644 sysdeps/ieee754/dbl-64/w_llogb.c diff --git a/sysdeps/ieee754/dbl-64/e_ilogb.c b/sysdeps/ieee754/dbl-64/e_ilogb.c index 89e7498266..1ea2f23e2f 100644 --- a/sysdeps/ieee754/dbl-64/e_ilogb.c +++ b/sysdeps/ieee754/dbl-64/e_ilogb.c @@ -1,41 +1 @@ -/* Get integer exponent of a floating-point value. - Copyright (C) 1999-2025 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 "math_config.h" - -int -__ieee754_ilogb (double x) -{ - uint64_t ux = asuint64 (x); - int ex = (ux & ~SIGN_MASK) >> MANTISSA_WIDTH; - if (ex == 0) /* zero or subnormal */ - { - /* Clear sign and exponent */ - ux <<= 12; - if (ux == 0) - return FP_ILOGB0; - /* subnormal */ - return -1023 - stdc_leading_zeros (ux); - } - if (ex == EXPONENT_MASK >> MANTISSA_WIDTH) /* NaN or Inf */ - return ux << 12 ? FP_ILOGBNAN : INT_MAX; - return ex - 1023; -} +/* ilogb is implemented at w_ilogb.c */ diff --git a/sysdeps/ieee754/dbl-64/w_ilogb.c b/sysdeps/ieee754/dbl-64/w_ilogb.c new file mode 100644 index 0000000000..45a59588c0 --- /dev/null +++ b/sysdeps/ieee754/dbl-64/w_ilogb.c @@ -0,0 +1,69 @@ +/* Get integer exponent of a floating-point value. + Copyright (C) 1999-2025 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 +#include "math_config.h" + +#ifdef DEF_AS_LLOGB +# define IMPL_NAME __llogb +# define FUNC_NAME llogb +# define RET_TYPE long int +# define RET_LOGB0 FP_LLOGB0 +# define RET_LOGBNAN FP_LLOGBNAN +# define RET_LOGMAX LONG_MAX +#else +# define IMPL_NAME __ilogb +# define FUNC_NAME ilogb +# define RET_TYPE int +# define RET_LOGB0 FP_ILOGB0 +# define RET_LOGBNAN FP_ILOGBNAN +# define RET_LOGMAX INT_MAX +#endif + +static inline RET_TYPE +invalid_ret (RET_TYPE r) +{ + __set_errno (EDOM); + __feraiseexcept (FE_INVALID); + return r; +} + +RET_TYPE +IMPL_NAME (double x) +{ + uint64_t ux = asuint64 (x); + int ex = (ux & ~SIGN_MASK) >> MANTISSA_WIDTH; + if (ex == 0) /* zero or subnormal */ + { + /* Clear sign and exponent */ + ux <<= 12; + if (ux == 0) + return invalid_ret (RET_LOGB0); + /* subnormal */ + return (RET_TYPE)-1023 - stdc_leading_zeros (ux); + } + if (ex == EXPONENT_MASK >> MANTISSA_WIDTH) /* NaN or Inf */ + return invalid_ret (ux << 12 ? RET_LOGBNAN : RET_LOGMAX); + return ex - 1023; +} +libm_alias_double (IMPL_NAME, FUNC_NAME) diff --git a/sysdeps/ieee754/dbl-64/w_llogb.c b/sysdeps/ieee754/dbl-64/w_llogb.c new file mode 100644 index 0000000000..c984cd151a --- /dev/null +++ b/sysdeps/ieee754/dbl-64/w_llogb.c @@ -0,0 +1,2 @@ +#define DEF_AS_LLOGB +#include "w_ilogb.c"