From patchwork Fri Sep 11 23:35:15 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Turner X-Patchwork-Id: 143508 X-Patchwork-Delegate: azanella@linux.vnet.ibm.com Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 77576484B9B4 for ; Fri, 11 Sep 2026 23:36:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 77576484B9B4 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=OmgwbXcj X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-yx2-x11.google.com (mail-yx2-x11.google.com [IPv6:2607:f8b0:4864:41::11]) by sourceware.org (Postfix) with ESMTPS id 9631E48F60F0 for ; Fri, 11 Sep 2026 23:35:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9631E48F60F0 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9631E48F60F0 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:41::11 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1789169721; cv=none; b=eWOTDTJLKU0fXS25pTKNVxtEUxlK9AFYLFdLQjkaxWc3PC+3OAdQhcI4ub+00oXu9Nd+nOM4REOvirGGsP2EjUB+bBfb8NEyj952PEvm6YR7j/Q+KrVgPzyEL3ANoi0m7mtR8oKrjPhIZmk5geBpWzeoAvRNfmsU5Hha2+Itzvo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1789169721; c=relaxed/simple; bh=7zgDRvH2v7mHx3NyRNN7KETazLVZMrpvKzEe+fw8O3Q=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=YdqNVOMg1ddveMFfBx09B9nBdZ4QI7Je38tMeWYa8gBvO5U3KD1Ga6wGmZY2GKIU4Jp6XV9BPd4kg3TJuKvByXPhekypFmadGS41gxItHsd73YKsW789XoiYxAcrkwA1ulCMJPx+ZTTssCfaO03DCqnZpjsJHJPL0PTFrcpOFNY= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=OmgwbXcj DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9631E48F60F0 Received: by mail-yx2-x11.google.com with SMTP id 00721157ae682-85d43db0c29so873617b3.2 for ; Fri, 11 Sep 2026 16:35:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789169721; x=1789774521; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=mRqpfKzZZMX6mxie05IQyodL0K0XGfacGkLR4qV45wc=; b=OmgwbXcjOR88zEN03YZrhcIYZRLVgAMU8Ruw/hGEoMwQnvsWk55agZoT1zjRP1trWK 7NIqB1kIy6QyupnifKCsZnNOfnexghNaIF9GARPRRI/+ok9MbAN3AlDRVoNSqVRqIhoo NxXzfsJF7aHQZPN0kL0yfwud42uI2Zp4tRYQIlr3D49NbOReX0tSCz7aYwPrs1OQPNaY snRcjNDSGdqagdJZ6EKQ4+fDEClgHb6ZGTsn+squDKjSY/eob5yJi3JCZ4aBlMp6j2HV gHbUgCDLyHjNausukuu+JZb1+eU08rrRKC0CCHChaG8SOharuwd2lrBKd7yBXH6ipNI5 b9qA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789169721; x=1789774521; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=mRqpfKzZZMX6mxie05IQyodL0K0XGfacGkLR4qV45wc=; b=ne530BSRZEFFxzTJJ3E4uMcLkL9YsLw0D22nhp6MbGw0LkFv7eNAaYh8WV68dz/qjS spKw2+OPA4TYww9UZkcjiFN/nVliqndygm/m18ucEwiT8oC9THVxz30Noji7DYONsaIp DTSROD+yiq0nugk2kIlHY+peYwetmCJkjquvhRPWcKivMp809QL+zJqJqdRc2Toi86rv /vKZyWqrQWDrXl4BgofH4UrOj7dvZaSqGd4XbCJgWeWV1EQs+RrUicNdIk2+wMLNnCBS lDKE2VWQfQbY9PNtK4tjazaFdObni+o/2SnWwnqDOSM3Ma+O2Ksiu35+Q0xglKx856ht 8b+g== X-Gm-Message-State: AFuF++nP6LdZlGWL01yNjHwMNHfZv+EKDiJhTkl2syGaWmkk4X624w9B WTcZiMYP205UOR1mq4uls89/6wLrB128xVeZp+U3S/7GfLm4oueq1gpq8dZrIA== X-Gm-Gg: AYBFou2uCc8ChrKIeE6dy24jNciZ1v8fyDdD/0ma8te8KHsYGvbMUoqxdqUegcoZrkg OYB8Sz03zgXMH7lrh4s1S78+8HsOuPzRdIozb2T6sTQL9gRM8iDsc8eUUFlfK91iuxJ1Hmfqa0i 5eRUrv8lRZfzd4PmWsPQz4F+BpbvakiJUMBUx/6ONAZEeze5nPAVMBCAA4Hus7vVSBqTVsPItjt S0LSsbGJu2lb6wH10KRu/7OZWfjKKUEi4V25aZK/gah1vysi8NGrN0OfG8HohId94lWmsOmdQMH /JugF3AwIHQ5C3nV6AmLEgT1B9kz1ib8T5JPKRem+uZERotE68Gfe6EeJ/mugnnk6p2uSwa2ZEV CX2PfHzfcaNhP4IWu279EGVFiMzRD3XGQBxdgGCz0xSDH5fU5rHDLmYgiugJwyh5Xc9U177lfcb QLgCvyO2XSWss2unN2GXtx23qH43hG00Ce5UQrahrSf6/j8koH5kzfO+ULH1z1MiaGh4RPfLM= X-Received: by 2002:a05:690c:281:b0:869:adba:625b with SMTP id 00721157ae682-887a87bf532mr2353447b3.25.1789169720489; Fri, 11 Sep 2026 16:35:20 -0700 (PDT) Received: from localhost ([2600:1702:7a90:6f9f:8bc4:8aec:108d:7a04]) by smtp.gmail.com with ESMTPSA id 00721157ae682-88486e2ecb6sm16794727b3.21.2026.09.11.16.35.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Sep 2026 16:35:19 -0700 (PDT) From: Matt Turner To: libc-alpha@sourceware.org Cc: mattst88@gmail.com Subject: [PATCH v3 1/3] math: move the classification macros to bits/fpclassify.h Date: Fri, 11 Sep 2026 19:35:15 -0400 Message-ID: <20260911233517.2113403-1-mattst88@gmail.com> X-Mailer: git-send-email 2.54.0 MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on 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~patchwork=sourceware.org@sourceware.org fpclassify, isfinite, isnormal, isnan and isinf expand to floating-point comparisons wherever the compiler builtins do, and a machine may not be able to classify a value that way. Move them to a new bits/fpclassify.h so that such a machine can override them. signbit moves ahead of the moved macros to keep them contiguous. It is unaffected, as it is not defined in terms of a comparison. No functional change. --- bits/fpclassify.h | 85 +++++++++++++++++++++++++++++++++++++++++++++++ math/Makefile | 1 + math/math.h | 64 +---------------------------------- 3 files changed, 87 insertions(+), 63 deletions(-) create mode 100644 bits/fpclassify.h diff --git ./bits/fpclassify.h ./bits/fpclassify.h new file mode 100644 index 0000000000..939bbb8a81 --- /dev/null +++ ./bits/fpclassify.h @@ -0,0 +1,85 @@ +/* Define floating-point classification macros. + Copyright (C) 2026 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 + . */ + +#ifndef _MATH_H +# error "Never use directly; include instead." +#endif + +/* GCC bug 66462 means we cannot use the math builtins with -fsignaling-nan, + so disable builtins if this is enabled. When fixed in a newer GCC, + the __SUPPORT_SNAN__ check may be skipped for those versions. */ + +/* Return number of classification appropriate for X. */ +#if ((__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__) \ + || __glibc_clang_prereq (2,8)) \ + && (!defined __OPTIMIZE_SIZE__ || defined __cplusplus) + /* The check for __cplusplus allows the use of the builtin, even + when optimization for size is on. This is provided for + libstdc++, only to let its configure test work when it is built + with -Os. No further use of this definition of fpclassify is + expected in C++ mode, since libstdc++ provides its own version + of fpclassify in cmath (which undefines fpclassify). */ +# define fpclassify(x) __builtin_fpclassify (FP_NAN, FP_INFINITE, \ + FP_NORMAL, FP_SUBNORMAL, FP_ZERO, x) +#else +# define fpclassify(x) __MATH_TG ((x), __fpclassify, (x)) +#endif + +/* Return nonzero value if X is not +-Inf or NaN. */ +#if (__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__) \ + || __glibc_clang_prereq (2,8) +# define isfinite(x) __builtin_isfinite (x) +#else +# define isfinite(x) __MATH_TG ((x), __finite, (x)) +#endif + +/* Return nonzero value if X is neither zero, subnormal, Inf, nor NaN. */ +#if (__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__) \ + || __glibc_clang_prereq (2,8) +# define isnormal(x) __builtin_isnormal (x) +#else +# define isnormal(x) (fpclassify (x) == FP_NORMAL) +#endif + +/* Return nonzero value if X is a NaN. We could use `fpclassify' but + we already have this functions `__isnan' and it is faster. */ +#if (__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__) \ + || __glibc_clang_prereq (2,8) +# define isnan(x) __builtin_isnan (x) +#else +# define isnan(x) __MATH_TG ((x), __isnan, (x)) +#endif + +/* Return nonzero value if X is positive or negative infinity. */ +#if __HAVE_DISTINCT_FLOAT128 && !__GNUC_PREREQ (7,0) \ + && !defined __SUPPORT_SNAN__ && !defined __cplusplus \ + && !defined __clang__ + /* Since __builtin_isinf_sign is broken for float128 before GCC 7.0, + use the helper function, __isinff128, with older compilers. This is + only provided for C mode, because in C++ mode, GCC has no support + for __builtin_types_compatible_p (and when in C++ mode, this macro is + not used anyway, because libstdc++ headers undefine it). */ +# define isinf(x) \ + (__builtin_types_compatible_p (__typeof (x), _Float128) \ + ? __isinff128 (x) : __builtin_isinf_sign (x)) +#elif (__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__) \ + || __glibc_clang_prereq (3,7) +# define isinf(x) __builtin_isinf_sign (x) +#else +# define isinf(x) __MATH_TG ((x), __isinf, (x)) +#endif diff --git ./math/Makefile ./math/Makefile index 5b48e53300..d9b17a8277 100644 --- ./math/Makefile +++ ./math/Makefile @@ -30,6 +30,7 @@ headers := \ bits/flt-eval-method.h \ bits/fp-fast.h \ bits/fp-logb.h \ + bits/fpclassify.h \ bits/iscanonical.h \ bits/libm-simd-decl-stubs.h \ bits/long-double.h \ diff --git ./math/math.h ./math/math.h index 75830d7696..0926b418a5 100644 --- ./math/math.h +++ ./math/math.h @@ -1087,26 +1087,6 @@ enum FP_NORMAL }; -/* GCC bug 66462 means we cannot use the math builtins with -fsignaling-nan, - so disable builtins if this is enabled. When fixed in a newer GCC, - the __SUPPORT_SNAN__ check may be skipped for those versions. */ - -/* Return number of classification appropriate for X. */ -# if ((__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__) \ - || __glibc_clang_prereq (2,8)) \ - && (!defined __OPTIMIZE_SIZE__ || defined __cplusplus) - /* The check for __cplusplus allows the use of the builtin, even - when optimization for size is on. This is provided for - libstdc++, only to let its configure test work when it is built - with -Os. No further use of this definition of fpclassify is - expected in C++ mode, since libstdc++ provides its own version - of fpclassify in cmath (which undefines fpclassify). */ -# define fpclassify(x) __builtin_fpclassify (FP_NAN, FP_INFINITE, \ - FP_NORMAL, FP_SUBNORMAL, FP_ZERO, x) -# else -# define fpclassify(x) __MATH_TG ((x), __fpclassify, (x)) -# endif - /* Return nonzero value if sign of X is negative. */ # if __GNUC_PREREQ (6,0) || __glibc_clang_prereq (3,3) # define signbit(x) __builtin_signbit (x) @@ -1125,49 +1105,7 @@ enum # define signbit(x) __MATH_TG ((x), __signbit, (x)) # endif -/* Return nonzero value if X is not +-Inf or NaN. */ -# if (__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__) \ - || __glibc_clang_prereq (2,8) -# define isfinite(x) __builtin_isfinite (x) -# else -# define isfinite(x) __MATH_TG ((x), __finite, (x)) -# endif - -/* Return nonzero value if X is neither zero, subnormal, Inf, nor NaN. */ -# if (__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__) \ - || __glibc_clang_prereq (2,8) -# define isnormal(x) __builtin_isnormal (x) -# else -# define isnormal(x) (fpclassify (x) == FP_NORMAL) -# endif - -/* Return nonzero value if X is a NaN. We could use `fpclassify' but - we already have this functions `__isnan' and it is faster. */ -# if (__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__) \ - || __glibc_clang_prereq (2,8) -# define isnan(x) __builtin_isnan (x) -# else -# define isnan(x) __MATH_TG ((x), __isnan, (x)) -# endif - -/* Return nonzero value if X is positive or negative infinity. */ -# if __HAVE_DISTINCT_FLOAT128 && !__GNUC_PREREQ (7,0) \ - && !defined __SUPPORT_SNAN__ && !defined __cplusplus \ - && !defined __clang__ - /* Since __builtin_isinf_sign is broken for float128 before GCC 7.0, - use the helper function, __isinff128, with older compilers. This is - only provided for C mode, because in C++ mode, GCC has no support - for __builtin_types_compatible_p (and when in C++ mode, this macro is - not used anyway, because libstdc++ headers undefine it). */ -# define isinf(x) \ - (__builtin_types_compatible_p (__typeof (x), _Float128) \ - ? __isinff128 (x) : __builtin_isinf_sign (x)) -# elif (__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__) \ - || __glibc_clang_prereq (3,7) -# define isinf(x) __builtin_isinf_sign (x) -# else -# define isinf(x) __MATH_TG ((x), __isinf, (x)) -# endif +# include /* Bitmasks for the math_errhandling macro. */ # define MATH_ERRNO 1 /* errno set by math functions. */ From patchwork Fri Sep 11 23:35:16 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Turner X-Patchwork-Id: 143507 X-Patchwork-Delegate: azanella@linux.vnet.ibm.com Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F32AC48F8A71 for ; Fri, 11 Sep 2026 23:36:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F32AC48F8A71 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=hoJokJX6 X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-yx2-x11.google.com (mail-yx2-x11.google.com [IPv6:2607:f8b0:4864:41::11]) by sourceware.org (Postfix) with ESMTPS id 6934E4865605 for ; Fri, 11 Sep 2026 23:35:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6934E4865605 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6934E4865605 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:41::11 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1789169724; cv=none; b=lqoVAyjdyZ/sj9/F7RoirUzwhW41Lga3v+C7Siu/6tvJvRVdxPid5S3iT12zumg1V8kfGyoFXyQYtDZvtWjZAU/QujfAqBJ0Op3+GMffy0VbdRxmH+x0P0RSBya2Yy6P5FN7pkdhmPQYNtoReO3aLfJupKdJoZdwOdOufOR4IqI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1789169724; c=relaxed/simple; bh=kbfQdgsj/p6AQTQaLt3wiW4toj2JojpQMmxMRbkYGsA=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=FXbE56oVsp8/EqYJy4ETxRvpXdM01/IGn43BAAa4QNGfog8ZT5qeGIgpNzSlixoqAhT2kNf6yHLp8HJwVkEXWkyxTHMLRAVjlC4cSsjyZ144+mPE8SulmKcXS2A+Vr1mhfaEZewsb9IbClnGjDa/7aDl999YCra/Uh/P4xMf21A= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=hoJokJX6 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6934E4865605 Received: by mail-yx2-x11.google.com with SMTP id 956f58d0204a3-66f7f72a284so114723d50.2 for ; Fri, 11 Sep 2026 16:35:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789169724; x=1789774524; 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:content-type; bh=pjfRNZZ3qfvjvk/dOTjVpTm3kHuhNXDwiqMls6fYhSo=; b=hoJokJX6oXxuJcDEGLzZep4EWXi1QfY/bunlc+OZ45JSoC2Egkqvb77uVl9l1yrPXk o53p26CkWEnZ9WzScxeaM1mXn5vE14fYQKtLiBpmkO5oHgEPgdKFe4Toj3dv7cJc6qzV yxzgQxBOmGCDz+CimB0EOCn20FlQo6tvp7+2vcHCAQ9Hg8er0wAyfHUbZuRVvYHMV0kM OGY6WLHQ7oKY95nOGieyUN84d8KJprVbPiHyDFqF9fgNs2FlgBuyOhQBfeUyj6R4U/xC oLJy68wHaHCsijwovDs4uaI7HcQLlZT42jgBfxfHAo3iatU96OXOCrDYydGmuXjsr5sW 4HUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789169724; x=1789774524; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=pjfRNZZ3qfvjvk/dOTjVpTm3kHuhNXDwiqMls6fYhSo=; b=pJOBIy9o4y8tKtoWiGSkJTFpQar20tymgS+KhEUHPPyDPMbD4DPEw1ebdlY+/6AAeG mYXuYY3zDCpnovjVpr9MapKmmSnENY46YBFdHNXMBqYm9j1p8uVjv+t2AqXOJHpSlUJ5 mTX6mjDaEce9S85QxJRAfCf/ckORb82dESeFa+un18AF5ywApM7rEm3wIeQwezJrTUu+ ZggOX5AQOmHfehPTZCGNt6BDwKX8/LdMkTnHS5jrPTPO0CMEEHS3S8wj4WkHpqr/IbfC YL0qfOZfEmjUQ48/CNMc0xYh7IzFDhf7ElhH7MWo0Rt7/eve33OhmsroTe343xfAS04d SaLA== X-Gm-Message-State: AFuF++lXcghudgwtlPWewkyvMBXGC2ub3FwDPsO3SUAjhRfz2qbAa2MF QQl8u3M6xNwOCsHUHn6WlTbx5LxAD7HrO4grsyWGByHRuAnyv736R8qXmYtuNw== X-Gm-Gg: AYBFou1rrDBqzJ5l5L5rhdqWUmgx5gUXkqMPmfxN+w6UwqAITGFI263xyS/ioLYaOOk 1PdUG3OZtW76d48ezTiWMEPVcIrKX/D6LRlKCZ5U2RtMrfuDP/pXtkSgWGDhgnLxaGbQMawa1XH 3YR1cpPsgfKnx4WPn7BKSwNGSlWNHjzeG5g7HFmsfXTQcTki+FUMg4U8kfKALOt07DWVZ6CDnC9 zbReBy51jGW3m4BxUCOZIhRr2jpPIb27d0yAh/YxqDYgFGkGJ/mnEmryCCf5JJl3CwIQy+k+ovz Y8uSCMBsE1Fl0VaweT/FfvJuZzFDgAM8arwGKMr6UKVDgqebv5i6V4ixKH1bWeoVgGRJgy4RX3J aM6j9zyRa7r+BSsB2R8Ih1zDXjEHERFA0Q0JCCFxURV+RIVjCMxuSVmM7ZjZk/TQ80X6GXnmjJ3 oGueiWaYlrguf/+EENL92xvCtGSDzLAmWa4B0S1xlv/WAyyXlFeLgMkW6bnBk29z6/ocGrMAQ= X-Received: by 2002:a05:690e:169f:b0:66f:c1bc:402d with SMTP id 956f58d0204a3-67135e3f053mr51975d50.90.1789169723638; Fri, 11 Sep 2026 16:35:23 -0700 (PDT) Received: from localhost ([2600:1702:7a90:6f9f:8bc4:8aec:108d:7a04]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-67125db3459sm1675415d50.6.2026.09.11.16.35.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Sep 2026 16:35:22 -0700 (PDT) From: Matt Turner To: libc-alpha@sourceware.org Cc: mattst88@gmail.com Subject: [PATCH v3 2/3] math: let architectures classify without comparing Date: Fri, 11 Sep 2026 19:35:16 -0400 Message-ID: <20260911233517.2113403-2-mattst88@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260911233517.2113403-1-mattst88@gmail.com> References: <20260911233517.2113403-1-mattst88@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on 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~patchwork=sourceware.org@sourceware.org A that defines __MATH_CLASSIFY_NO_COMPARE to 1 says that comparisons cannot classify a value on this machine. The generic header defines it to 0. iszero is the one classification macro not defined in that header, since it needs no compiler builtin, so define it in terms of fpclassify there, as is already done for -fsignaling-nans. --- v3: Define __MATH_CLASSIFY_NO_COMPARE to 0 in the generic header and test its value, rather than testing whether it is defined. bits/fpclassify.h | 5 +++++ math/math.h | 7 ++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git ./bits/fpclassify.h ./bits/fpclassify.h index 939bbb8a81..5ccad0ee9d 100644 --- ./bits/fpclassify.h +++ ./bits/fpclassify.h @@ -20,6 +20,11 @@ # error "Never use directly; include instead." #endif +/* Machines where a floating-point comparison cannot classify a value + define this to 1 in their own and define the + classification macros without comparing. */ +#define __MATH_CLASSIFY_NO_COMPARE 0 + /* GCC bug 66462 means we cannot use the math builtins with -fsignaling-nan, so disable builtins if this is enabled. When fixed in a newer GCC, the __SUPPORT_SNAN__ check may be skipped for those versions. */ diff --git ./math/math.h ./math/math.h index 0926b418a5..7d52735ced 100644 --- ./math/math.h +++ ./math/math.h @@ -1162,16 +1162,17 @@ inline int issignaling (_Float128 __val) { return __issignalingf128 (__val); } /* Return nonzero value if X is subnormal. */ # define issubnormal(x) (fpclassify (x) == FP_SUBNORMAL) -/* Return nonzero value if X is zero. */ +/* Return nonzero value if X is zero. Machines that define + __MATH_CLASSIFY_NO_COMPARE to 1 cannot classify by comparing. */ # ifndef __cplusplus -# ifdef __SUPPORT_SNAN__ +# if defined __SUPPORT_SNAN__ || __MATH_CLASSIFY_NO_COMPARE # define iszero(x) (fpclassify (x) == FP_ZERO) # else # define iszero(x) (((__typeof (x)) (x)) == 0) # endif # else /* __cplusplus */ extern "C++" { -# ifdef __SUPPORT_SNAN__ +# if defined __SUPPORT_SNAN__ || __MATH_CLASSIFY_NO_COMPARE inline int iszero (float __val) { From patchwork Fri Sep 11 23:35:17 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Turner X-Patchwork-Id: 143509 X-Patchwork-Delegate: azanella@linux.vnet.ibm.com Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1B3A14B9DB4A for ; Fri, 11 Sep 2026 23:36:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1B3A14B9DB4A Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=iEVRuhC5 X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-yx2-x10.google.com (mail-yx2-x10.google.com [IPv6:2607:f8b0:4864:41::10]) by sourceware.org (Postfix) with ESMTPS id 955944C31820 for ; Fri, 11 Sep 2026 23:35:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 955944C31820 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 955944C31820 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:41::10 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1789169727; cv=none; b=bQDnKsyb0daO47rLBwc43U0wPxzMPV0SRVrQIT/cCXtEM3/ImZGGoipzDm0+rZwzkpAtNHytm2VKzS+9OmZOCUTVZWl9Ma8BkuzTWQDXBmxZh1ZbZTKuLrTYhby5xg3nSZ69/9vpmU+ZFJh0Gkqo07UauPgbUUNoTQ2BHSIJK5A= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1789169727; c=relaxed/simple; bh=fGRFOdOCLx8gUUx/tkqPc3dRn7ZLkxk28TrQWZtxsrg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=sUPcHRwiAw5sRH3ig+YMgCZhIKQOhn9mz0romGitOL962GQbvgGSRZJJbJH3fAmsbtoOLlvHxh5Fl8zutGE4lBO1oxPDwNMhGFGYF64jZngsdC6upFQQut7eZCVTDZ8oFT1jeqf1opfFxDg7DAG3+/tp9FJO0zaru2syxrK/D6w= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=iEVRuhC5 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 955944C31820 Received: by mail-yx2-x10.google.com with SMTP id 00721157ae682-85d43ac6072so948997b3.0 for ; Fri, 11 Sep 2026 16:35:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789169727; x=1789774527; 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:content-type; bh=t1JZ0dt5EDqbCsI/4J5f8ubBlGoXKU+KysK6ryrK5WY=; b=iEVRuhC58FG+Tmq8Fe3OKz6ZY0OIz6oN3DJ8Pd+pRDaGm8g2h6D0WaR0qVaD8V5d7z BHJEMUlh8v8ScUtS9qjvyp7Ic94n1jO4D+FZPBeheMxcHtKtBi71Pw00EenN/0Cfu7L7 lW0eTfXxPuFQWB1CwBDi1mdRBreD/fg6fGefprtawnFBnAnSY18ULeWeAMPG6GTPvQqF KUvtL3EXsESEko6TyDsNMPmGcQIvmH+FRRdhQrLcvSJsWTPta7pKPgyy92lZ3OqW/0aI CcxrY4Pacec+1w0UYOExfqEW8vbbvsGMXW9splNC/nerLOXyxurUL2dwwQC4+mr4I4DZ 3mBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789169727; x=1789774527; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=t1JZ0dt5EDqbCsI/4J5f8ubBlGoXKU+KysK6ryrK5WY=; b=j8UnWW3AU8TBqxO5x2xUdORFioTkJjmxY6jIR5lSDOa2CaKulUzIO7ms2ySaoTzY3Y ySX8DFzoYk2wr1XjazJ4TRO77+gevYeQACJUsHz0ymp9WOIa04AJ3pA1LIyMaV3WYd14 ZXCAnFT53kGUdTgozM2KxIQrGM0d3Bk+yPtzQ58Mpk0MSHE9FGCczcsVlPspXjK+3sS0 SThIhitbbhWGvNkF2nxXSzwWpORe5tHh85zF2MYi5pSzmQjQczJPfz4VmbQgkdHGyV07 kv2O9JVE6TlJKtP+udMGV3G3wvF32eSRtefZA0sgH2pflRldcwCFm3q2+anOYQa37R22 968Q== X-Gm-Message-State: AFuF++n6EYVbni+Rw3rz6wVIFVZlpS2CFxMZcGBbyOlHTFJzFR6fQU5d TmTgcmmBfXFEGtgNtDgqTExVtnhWjqpAw8zsY2/1ysR8h0KnMNdvjkTZEstTjQ== X-Gm-Gg: AYBFou2ph+4j6ExqO3ZZh0ZEWy1SFQWHJjQjqWaagA+2Wmj2m2HjH9mRlzlxE91tHZk 597pgpDeq9JQb1RnALqJLSP3WPU2181qix8+4AVaVsGvJ/v7IWoecJoyADCVJMif5PeBRdQBnJf OQzLC+WPeIm1oEW7sbXuxiyvpWX9EoEUQ06CnKF1Gd0pn3MltYcp7qOex7KBcuJ7avRs9AZyoDV O5GkBWua8q/TTU7OtxdfGc/a6Cvdx38W1iJ/Qah9nWhEJDWh1ZbcQeBpdgBBM1HSzzXna4SvCBG J1S36OUsxSp1ocDh+W4N2AMTXrxK67s8+5yvOWhOmMz6q57T3opbcNgY/NUtyrIG+gqk0ZlfNDS M3E90jVEpYGmy7ZyjDxb2WG0I2r51qGTH9Qtdpme48ZvNGmofIORHEleXiW1x0LnG4zSMS9Yuv0 a6jAJCfuVdLsEQKHKUYsbHs3hEYO6yJbOzaWPau1j2dyPKAjeV5erFvcGE895dME6cqidWKvs= X-Received: by 2002:a05:690c:88:b0:873:5c7b:c0f5 with SMTP id 00721157ae682-887adc39752mr1830077b3.45.1789169726743; Fri, 11 Sep 2026 16:35:26 -0700 (PDT) Received: from localhost ([2600:1702:7a90:6f9f:8bc4:8aec:108d:7a04]) by smtp.gmail.com with ESMTPSA id 00721157ae682-88488a4c120sm16594717b3.38.2026.09.11.16.35.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Sep 2026 16:35:25 -0700 (PDT) From: Matt Turner To: libc-alpha@sourceware.org Cc: mattst88@gmail.com Subject: [PATCH v3 3/3] alpha: classify floating-point values without comparing Date: Fri, 11 Sep 2026 19:35:17 -0400 Message-ID: <20260911233517.2113403-3-mattst88@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260911233517.2113403-1-mattst88@gmail.com> References: <20260911233517.2113403-1-mattst88@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on 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~patchwork=sourceware.org@sourceware.org The Alpha floating-point comparison instructions raise a denormal-operand exception for a subnormal operand. Unless the compiler arranges for software completion (it only does so for -mieee, which is not the default), the outcome depends on the FPCR denormal-operand-disable bit: either the operand is flushed to zero, which makes a subnormal indistinguishable from a zero, or the trap is delivered with no completion information, which is fatal. GCC expands the classification builtins into such comparisons, so printf ("%d\n", fpclassify (0x1p-1050)); either prints FP_ZERO or dies with SIGFPE, depending on the trap mode. iszero has the same problem without any builtin being involved, because it expands to a comparison against zero written out in the header. Add an Alpha bits/fpclassify.h that uses the out-of-line implementations, which examine the encoding in an integer register. Classifying out of line means fpclassify, isnormal, issubnormal and iszero now need libm on Alpha, since __fpclassify is exported from libm alone, unlike __isnan, __finite and __isinf, which libc exports too. This fixes C only. libstdc++ undefines these macros in and uses the builtins itself, so C++ still classifies by comparing. The new test is built with -mfp-trap-mode=n because glibc itself is built with -mieee, which would hide the problem. Without the Alpha header it fails with Didn't expect signal from child: got `Floating point exception' GCC PR target/127298 tracks expanding the classification builtins without comparisons in the Alpha back end; once a release containing that fix exists, the definitions in the Alpha header can be made conditional on the compiler predating it. --- math/Makefile | 1 + math/test-classify-subnormal.c | 63 +++++++++++++++++++++++++++++++++ sysdeps/alpha/Makefile | 6 ++++ sysdeps/alpha/bits/fpclassify.h | 37 +++++++++++++++++++ 4 files changed, 107 insertions(+) create mode 100644 math/test-classify-subnormal.c create mode 100644 sysdeps/alpha/bits/fpclassify.h diff --git ./math/Makefile ./math/Makefile index d9b17a8277..44c882063c 100644 --- ./math/Makefile +++ ./math/Makefile @@ -538,6 +538,7 @@ tests = \ bug-nextafter \ bug-nexttoward \ test-ceil-except-2 \ + test-classify-subnormal \ test-femode \ test-femode-traps \ test-fenv basic-test \ diff --git ./math/test-classify-subnormal.c ./math/test-classify-subnormal.c new file mode 100644 index 0000000000..eb874d00cc --- /dev/null +++ ./math/test-classify-subnormal.c @@ -0,0 +1,63 @@ +/* Test classification macros with subnormal arguments. + Copyright (C) 2026 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 + . */ + +/* The classification macros must distinguish a subnormal from a zero, + and must not trap. */ + +#include +#include +#include +#include + +#define TEST(TYPE, TRUE_MIN) \ + do \ + { \ + volatile TYPE sub = (TRUE_MIN); \ + TEST_VERIFY (fpclassify (sub) == FP_SUBNORMAL); \ + TEST_VERIFY (issubnormal (sub)); \ + TEST_VERIFY (isfinite (sub)); \ + TEST_VERIFY (!isnormal (sub)); \ + TEST_VERIFY (!isnan (sub)); \ + TEST_VERIFY (!isinf (sub)); \ + TEST_VERIFY (!iszero (sub)); \ + TEST_VERIFY (!signbit (sub)); \ + TEST_VERIFY (fpclassify (-sub) == FP_SUBNORMAL); \ + TEST_VERIFY (signbit (-sub)); \ + } \ + while (0) + +static int +do_test (void) +{ + TEST (float, FLT_TRUE_MIN); + TEST (double, DBL_TRUE_MIN); + TEST (long double, LDBL_TRUE_MIN); +#if __HAVE_DISTINCT_FLOAT128 + TEST (_Float128, __FLT128_DENORM_MIN__); +#endif + + /* A zero must still classify as FP_ZERO. */ + volatile double zero = 0.0; + TEST_VERIFY (fpclassify (zero) == FP_ZERO); + TEST_VERIFY (iszero (zero)); + TEST_VERIFY (!issubnormal (zero)); + + return 0; +} + +#include diff --git ./sysdeps/alpha/Makefile ./sysdeps/alpha/Makefile index faa59ab27a..825c2351d2 100644 --- ./sysdeps/alpha/Makefile +++ ./sysdeps/alpha/Makefile @@ -54,6 +54,12 @@ CFLAGS-test-misc.c += -mieee-with-inexact # Avoid "conflicting types for built-in function" warnings CFLAGS-s_isnan.c += -fno-builtin-isnanf +# glibc is built with -mieee (see below), which makes comparisons safe for +# a subnormal operand; ordinary code is not, so test the default trap mode. +# This must override the -mieee in sysdep-CFLAGS, so it has to come last on +# the command line. +CFLAGS-test-classify-subnormal.c += -mfp-trap-mode=n + # _Float32x and _Float64 are both binary64 on Alpha, so this narrowing # divide is a plain divide and the hardware alone decides whether to # signal underflow. IEEE 754 determines tininess after rounding from the diff --git ./sysdeps/alpha/bits/fpclassify.h ./sysdeps/alpha/bits/fpclassify.h new file mode 100644 index 0000000000..6efb1aee4a --- /dev/null +++ ./sysdeps/alpha/bits/fpclassify.h @@ -0,0 +1,37 @@ +/* Define floating-point classification macros. Alpha version. + Copyright (C) 2026 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 + . */ + +#ifndef _MATH_H +# error "Never use directly; include instead." +#endif + +/* The Alpha floating-point comparison instructions raise a + denormal-operand exception for a subnormal operand. With the default + trap mode the operand is either flushed to zero, which makes a + subnormal indistinguishable from a zero, or the trap is fatal. Use + the out-of-line implementations, which examine the encoding in an + integer register, rather than the builtins, which compare. GCC PR + target/127298 tracks expanding the builtins without comparisons. */ + +#define __MATH_CLASSIFY_NO_COMPARE 1 + +#define fpclassify(x) __MATH_TG ((x), __fpclassify, (x)) +#define isfinite(x) __MATH_TG ((x), __finite, (x)) +#define isnormal(x) (fpclassify (x) == FP_NORMAL) +#define isnan(x) __MATH_TG ((x), __isnan, (x)) +#define isinf(x) __MATH_TG ((x), __isinf, (x))