From patchwork Fri Apr 25 20:44:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 884433 Delivered-To: patch@linaro.org Received: by 2002:a5d:474d:0:b0:38f:210b:807b with SMTP id o13csp4160445wrs; Fri, 25 Apr 2025 14:02:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU/0T1k97mevuL4PNm5A8o6slYiS7xlrJVR1WrR/n3/gZ0Aq8EUZ/t9a/bnxNUGZK/bJqPoPA==@linaro.org X-Google-Smtp-Source: AGHT+IEYmNnHYxHmrWpOj9EBpErzlb0F9p8V1mI3UrwVs8cYt5wnoZchZ+CwjwwGToGrnFXMzJEn X-Received: by 2002:a05:620a:44d6:b0:7c9:443b:84e9 with SMTP id af79cd13be357-7c966863abfmr165409085a.3.1745614963474; Fri, 25 Apr 2025 14:02:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1745614963; cv=pass; d=google.com; s=arc-20240605; b=PN++ycFUeXUjZERL4t5RpxIMWeZl/TsdCind26+d/qmZwCtVRW0TZ2qxSfAflGiiu7 BZtyDkJqfYGVQM7bh0KAORbYtcLv7J3n/umUIHf2WgI6bMsnKhWzMCv164oQNERtGYS0 rWdZkv2RsyKoFPZ97QZLCrmIp1yopu1Xdd65w+c6Rel0Nxwu0IQLt1BzzAZEoLr1xLk9 m/xzDNFtfExt6TRTKYv5h+kq9Qf3iQYa4egTYFL9PDm9FwZCMm3pv4cjS4j2AC2IePwW 8NKNwKqmfNqtSpdbb6Vg1X5ks7MuTbAyTMkysBiVYujAUnt2tq9DCIDSYIdY4xlOiVap Dozw== 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=DL6X6wJeQeN9fQLlMuT5plFpq0oUcSpw/523iWeL9yU=; fh=dHLBnA+MhGtNtN2B2JMAELi4oD+gmgMg7DL8H0jYbkI=; b=aSr7MjHtfqnHHF8hXt1mffe3MXa9rczMHem4UsDpgTBM+lC4qvnw2BrIun/BZ/lDNn zsGfX/rKHkqjsuLI7cr1987wu/vx+TTpbQ7srSBPwjSR9pQLg4zs9Fo5pIBtx2vKg1Ii LAnlP1lFgHhtQIWYQDTVWZUUdoTbiKZzafPJdiT/2W3CDbFE/fDPZETBg97AmVmDt2km sNnxAYaIVTo8afpVk0OpM2JId/xfVwgYtS0HlNSs7Lv4+oDAr/gZGi+Xi6sQ5AKsD1tb q9mxAFtFaSZCf61PGCTUvaluCOVtrkDJzrKBpBsq8R85UA8bCq3IYBjkEMk5aGuf4iyV YkKw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hNRqo9Mn; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id ada2fe7eead31-4d3d71d6762si1391260137.393.2025.04.25.14.02.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Apr 2025 14:02:43 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hNRqo9Mn; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c 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 0A7AE3857836 for ; Fri, 25 Apr 2025 21:02:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0A7AE3857836 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=hNRqo9Mn X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by sourceware.org (Postfix) with ESMTPS id 594AA385840F for ; Fri, 25 Apr 2025 20:53:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 594AA385840F 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 594AA385840F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::102f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1745614400; cv=none; b=XEMhKv4UvcDfHIG8lBOyHR8HYfhbsAVgvw3pogg2cHkjf0bAkMomvpoJofvdosLw/iShmSZd6YTfxUQAsHXl/MMFEtd6qAxzf25Kj0QNlQw14Tc+eW1/19MYo+9bWgl4w9mLnYoc389i/WzLGEwCatrhTWUaHafNPDnJCEMvJf4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1745614400; c=relaxed/simple; bh=9FV7UechfvkoAWH6AeVI25rzdIZ64jDAMUZUWk1T76I=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Z/W/crQ8+zcIgkb9r6Bx3SYBaeNu/1b+PUbhp287a3wPPG3U6IpTLKUO8Ca9Iov9AQkGQMlg/Sv5ZVR6WFis4EJD8TW/6qg7S4AD+5moeW+G2Ui00GyzKEJDA4lr67T63bNY45DZd7tgKCKc+L9iRzJ1ABY6mmjP8vebZRMdRZg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 594AA385840F Received: by mail-pj1-x102f.google.com with SMTP id 98e67ed59e1d1-3012a0c8496so2190730a91.2 for ; Fri, 25 Apr 2025 13:53:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1745614399; x=1746219199; 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=DL6X6wJeQeN9fQLlMuT5plFpq0oUcSpw/523iWeL9yU=; b=hNRqo9Mn886WQMu06R3qEL/dpz6dMqUfid8TJ8a5tEHv89I81CrQkrFZ0ffQpTA/el cT/ONqACC/OpPUtqsLL2BV4YkzgCfH6a9cVj11cgFR1yG8+t0A5bG5E+MqzV9t7HyDMo hMkv5pKnb+HIgx5GdbFUn2WRiFDi1MB7CCUjWYBSR4rWZIQfrIF9A3pKFW3FIIb7EwLZ H2Wrw1U8AgvElr48bEzVAKXekBtVFtwmqFmIaUeU/OsxmWBuW/eSutQ2ixfxhzX0mRm4 hDU/zbXlW/C7uuwDjBVGzC+JafJlu/+FoDKhFMVrOdSvRMYqPyJn9g5xf2LOMMjpWgkD x9TA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745614399; x=1746219199; 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=DL6X6wJeQeN9fQLlMuT5plFpq0oUcSpw/523iWeL9yU=; b=sKb0sx4X0c11/U3gEr5kZGP8KeGCkofRh6RadwC6mlVj0al1oNc5SOz94YdMeYsUlH 55NxWdgFbe3vWDnJYj9cK7Nbg5sOKqIfPW7Fr7o23Bdx3rF38HfucwePoqv008OL4FZg zMXQqbFtUBH/TQcIbBwLfVa2IzNhy7oJ8weLqiPuda63vuuPukKCzfDPyDsb6BuGtZkI VsbT2rgAk9Qg3KtEdnAv5cY6wuCe4DMQt7lZ/6bQAifjHFh9Pnr0o4rAmHzJ7Kl0Hkvb Jr9mloAItBElh3f9kaHlYRVcZDj8o3D6sCJ1+82okAtG4iG/4ISD7p8b8uDywpmnk3d/ Yhhg== X-Gm-Message-State: AOJu0Yyrmw2rZOIC2YF9wyM8MlUBtJYv2g+bCgyf4xuc9W7ahYTmtVW1 AmIXeJHrqDmki9Gkrg8NSuDnl1ZGJRvtjAPLI7ajyftE8urX1/AUXGH2leokKZbSZkd7DOjPJ5I O X-Gm-Gg: ASbGnctxDW/gNEdrhKX355S1LStiM+OmL+nAdKI4khiQ9fFWfYcRbnQv35bINnwrszZ J1CCY9RZkCwu9A9N4YKj0tA+wsQNcdv824oiVHQRXfLJgedblMTUyRvKASYLcdFGuKrr+sp+CvT Tx0jXIZCWYTtxlrYEvTWQ1tTzcdcWjlntz+j4AzqeaT4aAg8loBTRdoazySCLaTuIYnY1akh7C/ xHqGSS4o9aWMsB7FgXXfgVzUPYzJIxolHGXsZ2T7DZ0Kf+Ks16NH1ABnZCMMwi2Ms2TBzzDm/e/ ipf5ssWulixqrUtaSvonsphnJu+3dqzpoNnfmEP51PSVYwX0G3x8hg== X-Received: by 2002:a17:90b:270b:b0:2f7:4cce:ae37 with SMTP id 98e67ed59e1d1-30a01339f6fmr1513403a91.18.1745614398931; Fri, 25 Apr 2025 13:53:18 -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.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Apr 2025 13:53:18 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 4/4] math: Optimize float ilogb/llogb Date: Fri, 25 Apr 2025 17:44:10 -0300 Message-ID: <20250425205309.3866442-5-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/flt-32/e_ilogbf.c | 42 +------------------ sysdeps/ieee754/flt-32/w_ilogbf.c | 70 +++++++++++++++++++++++++++++++ sysdeps/ieee754/flt-32/w_llogbf.c | 2 + 3 files changed, 73 insertions(+), 41 deletions(-) create mode 100644 sysdeps/ieee754/flt-32/w_ilogbf.c create mode 100644 sysdeps/ieee754/flt-32/w_llogbf.c diff --git a/sysdeps/ieee754/flt-32/e_ilogbf.c b/sysdeps/ieee754/flt-32/e_ilogbf.c index 024b114638..a27fb94732 100644 --- a/sysdeps/ieee754/flt-32/e_ilogbf.c +++ b/sysdeps/ieee754/flt-32/e_ilogbf.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_ilogbf (float x) -{ - uint32_t ux = asuint (x); - int ex = (ux & ~SIGN_MASK) >> MANTISSA_WIDTH; - if (ex == 0) /* zero or subnormal */ - { - /* Clear sign and exponent. */ - ux <<= 1 + EXPONENT_WIDTH; - if (ux == 0) - return FP_ILOGB0; - /* sbunormal */ - return -127 - stdc_leading_zeros (ux); - } - if (ex == EXPONENT_MASK >> MANTISSA_WIDTH) /* NaN or Inf */ - return ux << (1 + EXPONENT_WIDTH) ? FP_ILOGBNAN : INT_MAX; - return ex - 127; -} +/* ilogbf is implemented at w_ilogbf.c */ diff --git a/sysdeps/ieee754/flt-32/w_ilogbf.c b/sysdeps/ieee754/flt-32/w_ilogbf.c new file mode 100644 index 0000000000..21e40c7721 --- /dev/null +++ b/sysdeps/ieee754/flt-32/w_ilogbf.c @@ -0,0 +1,70 @@ +/* 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 +#include "math_config.h" + +#ifdef DEF_AS_LLOGBF +# 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 +M_DECL_FUNC (IMPL_NAME) (float x) +{ + uint32_t ux = asuint (x); + int ex = (ux & ~SIGN_MASK) >> MANTISSA_WIDTH; + if (ex == 0) /* zero or subnormal */ + { + /* Clear sign and exponent. */ + ux <<= 1 + EXPONENT_WIDTH; + if (ux == 0) + return invalid_ret (RET_LOGB0); + /* sbunormal */ + return (RET_TYPE)-127 - stdc_leading_zeros (ux); + } + if (ex == EXPONENT_MASK >> MANTISSA_WIDTH) /* NaN or Inf */ + return invalid_ret (ux << (1 + EXPONENT_WIDTH) ? RET_LOGBNAN : RET_LOGMAX); + return ex - 127; +} +libm_alias_float (IMPL_NAME, FUNC_NAME); diff --git a/sysdeps/ieee754/flt-32/w_llogbf.c b/sysdeps/ieee754/flt-32/w_llogbf.c new file mode 100644 index 0000000000..8676434f6e --- /dev/null +++ b/sysdeps/ieee754/flt-32/w_llogbf.c @@ -0,0 +1,2 @@ +#define DEF_AS_LLOGBF +#include "w_ilogbf.c"