From patchwork Mon Aug 3 23:55:06 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Turner X-Patchwork-Id: 140547 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 3642D4BB24DC for ; Mon, 3 Aug 2026 23:55:25 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-yw1-x112d.google.com (mail-yw1-x112d.google.com [IPv6:2607:f8b0:4864:20::112d]) by sourceware.org (Postfix) with ESMTPS id 155FF4BB1C2B for ; Mon, 3 Aug 2026 23:55:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 155FF4BB1C2B 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 155FF4BB1C2B Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::112d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1785801314; cv=none; b=g3zQIASH6bEb6KnDbA+bBcrzLgYjAnDKLJ2sNvzuwcAI/kd1TmUNxkJlDRxiGkl4ETpepmQVtayl/xOS2uXIFYxScSyG1Fial6hoTjFjB6FZmR5nZ3s/dpvCI05bwo1U2CkjGgqh+GbiNqjMBP6UDw99kiSl2wNCZuLNXoyqKHw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1785801314; c=relaxed/simple; bh=c6/mJgXWxgqjWZBATNbmFIjxFhmG2cx4ExYowXVYynA=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=kc/DFZbZ1xN7YWel05o3Spf0GNFFHWe8RpFcNs97tugd46kwB7DxrPsgGuHM/DqzGs7yO/NPwi0xi6Hy4V8svhlhXBIfX8mVElDh1LJZeHh0JVzXjn4y97fjNcndloEhvbZRgFpUmODMvNWhX9F3mwdMsOJLraDxaXbct1dvI1A= 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=KYyRoTKE DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 155FF4BB1C2B 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=KYyRoTKE Received: by mail-yw1-x112d.google.com with SMTP id 00721157ae682-81dfdbd86d1so41751817b3.1 for ; Mon, 03 Aug 2026 16:55:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785801313; x=1786406113; 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=9ep/9+565o7n9H711BCsuK6g0PydYvPGfDCHOAMgyXE=; b=KYyRoTKE0p4UxurhgkrJWWFIdS4/Usqhh9Ybjo1njl6O1HdCUj+0hv/7qW9HSRYDds MZcPW1ytsGUhHuxJNzFTIInT7s1mVkH5q4BQZTqUD43DMVPWqnBmx0mOKkWcD/7482eP HAo1dDZVmwr06m8S0K9bgHUQAnwiSIcBZmYtlVUOrumthmtubp8I9N3ZFTJavvk/byGe qrnaFhEKCUV+y6o4rNhdAlekYI3CtAmWp2VIO/yEQIbeia9zxxLt9zW5EWuKX8CSgI0R q7+JylnXeVW7KQIt5NKZfp4qL9G43gR4iaSGNt9tw1OVfCjuzlOycB6GZsyo+U486iE9 DZCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785801313; x=1786406113; 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=9ep/9+565o7n9H711BCsuK6g0PydYvPGfDCHOAMgyXE=; b=HJTTMI/FEbXgZnuPZSxaSI9pwESj9QejQmwVsWlWEr+f/vGOyN97VTsfOx+KCUbKYY lBP+PJJ5t9m0uCt+hOyEIozacXljZIBPoFKFtwFAyWk/gF2eGWMvAC/CSIW7d7AceGwI CyP857WWdW5+jatr/MFkUpv4f5BH7KUt2nqSRX+5Fc9xdOUhW8qK1QZWIzVvVJxDDsIO 6z9riImur3HjJtDXoku4RMVyQkwzr9LPder6mUlwZv14BXD1NsMH+/Ngsmwjib2ph+XC m2+GEaUNSTeeMgbIlHcaUJnRSYNPRzrAMEWTt3kAia2xBpWBSvkDG/ABWBGaauC4cYGI LHNQ== X-Gm-Message-State: AOJu0YwLdQmDpHC329yomNRkH6yys/g7i6L5VS4WazL4X28Kh8rD+LyX EQ5qro4xAVoVvt/N9RLA03rlB2xqlWx3wufYxmAROuY8v3glLwq46xO1ZVTKKpgh X-Gm-Gg: AR+sD10qvAiOziJi1vfMYwSnXZhVqsXBO1ztoi2JiaDjx+WMnjB/i9Z1GWhMlkZUSs+ 2PTkLX50HkC+evdsoTGzLCizjjxqp+GqpkOg2G0Yxwuh7eZpjOM569MgVAkuiQL1DDimKCjynuK l2DYmj8bwW3e4A8ZKR9phjHDfq440hIRgC/vO58SqtcEF5SOXWhN3fHK2WQg19VLz4D5OuzEwkd i0gsaa3XEt1mVicyx85Xj3vAqOAsojOrD7As0tqiHu3mbqDd96jPlC3fNsJgG8Jh+MRj7qy7a2N bSGijh0qvfRPV3PPYj6ZUgPfdlXseu6m/twDEzRhzJuFKWPNMkCEqXpXx0CkyEQEZLDSQ2Q2Z9X D4yuk5sXLJ9TsFytl33iNTV5oH97dGKIpIaSh3fiQYjPcEBT13Pb0laRTnkVbCmaaTzbQkTVc9Z HeZglJ2HwEHMT9BKCCpH2acrsVkGLeVjtXH3uSgDIzzKaoGFmBM2ErHRq5CfmEwqGNKU33FSU= X-Received: by 2002:a05:690c:4902:b0:81e:29d9:791f with SMTP id 00721157ae682-81fd4c184f4mr145700737b3.34.1785801313386; Mon, 03 Aug 2026 16:55:13 -0700 (PDT) Received: from localhost ([2600:1702:7a90:6f9f:8bc4:8aec:108d:7a04]) by smtp.gmail.com with ESMTPSA id 00721157ae682-81fcd1240d6sm63130177b3.40.2026.08.03.16.55.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2026 16:55:12 -0700 (PDT) From: Matt Turner To: libc-alpha@sourceware.org Cc: Joseph Myers , Adhemerval Zanella , Magnus Lindholm Subject: [PATCH 1/4] alpha: add the denormal trap enable bit to FE_NOMASK_ENV Date: Mon, 3 Aug 2026 19:55:06 -0400 Message-ID: <20260803235509.3532030-2-mattst88@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260803235509.3532030-1-mattst88@gmail.com> References: <20260803235509.3532030-1-mattst88@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.3 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, 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 FE_NOMASK_ENV is the floating-point environment in which no exception is masked, so it must enable every exception that FE_ALL_EXCEPT covers. On Alpha that includes the GNU extension FE_DENORMAL, whose SWCR trap enable bit is IEEE_TRAP_ENABLE_DNO (bit 6). The constant only set bits 1 through 5 (INV, DZE, OVF, UNF and INE), so after fesetenv (FE_NOMASK_ENV) a subsequent fegetexcept () returned 0x3e0000 rather than FE_ALL_EXCEPT (0x7e0000), and denormal exceptions stayed masked. Set bit 6 as well. Fixes math/test-fenv-return on alpha. Reviewed-by: Adhemerval Zanella --- sysdeps/alpha/fpu/bits/fenv.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git ./sysdeps/alpha/fpu/bits/fenv.h ./sysdeps/alpha/fpu/bits/fenv.h index b1135f1f0a..530f298914 100644 --- ./sysdeps/alpha/fpu/bits/fenv.h +++ ./sysdeps/alpha/fpu/bits/fenv.h @@ -121,7 +121,7 @@ typedef unsigned long int fenv_t; #ifdef __USE_GNU /* Floating-point environment where none of the exceptions are masked. */ -# define FE_NOMASK_ENV ((const fenv_t *) 0x880000000000003eUL) +# define FE_NOMASK_ENV ((const fenv_t *) 0x880000000000007eUL) /* Floating-point environment with (processor-dependent) non-IEEE floating point. In this case, mapping denormals to zero. */ From patchwork Mon Aug 3 23:55:07 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Turner X-Patchwork-Id: 140548 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 252B34BB24E7 for ; Mon, 3 Aug 2026 23:56:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 252B34BB24E7 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=qLYdPkVk X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-yw1-x112c.google.com (mail-yw1-x112c.google.com [IPv6:2607:f8b0:4864:20::112c]) by sourceware.org (Postfix) with ESMTPS id C8F704BB1C29 for ; Mon, 3 Aug 2026 23:55:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C8F704BB1C29 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 C8F704BB1C29 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::112c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1785801315; cv=none; b=Dq3VTNQj41YjFFnYGRtfDZgy7N+WWewf+S0w6yn3D4G3/9BpDMjNuPkV3DjJmwbTuvRal+fly7rZGLWXbl6onyyIdMh0CuW/LzNEjx1rUmrqdW5F49W65UzYfcsbBh4iRujK66Jb49LcFazpXnvFswwVLv3oP0Hr0PZSpJ6h6nY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1785801315; c=relaxed/simple; bh=M6gejCJ1JVXYyfMx3LpsxeRk1RAbWi15iEraUBmHfjw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=GqAev4eKhJoqxl5mlq5jr09see7AMOiobfiACjL+4XtRt4zmP/WOLAqFcdQkZvo388IRlDep0pvpM0XfxH2oZgT1umay2Jqmj84m+IHB/5cZwzezb3nhGf5BpPJF2gJNZ/MwrZskriYHavpiGN3NDWBmKHbFmEHexb9bU6QfMTA= 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=qLYdPkVk DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C8F704BB1C29 Received: by mail-yw1-x112c.google.com with SMTP id 00721157ae682-80bb41f7f3cso38989007b3.2 for ; Mon, 03 Aug 2026 16:55:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785801315; x=1786406115; 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=boUlwZ1rWoh22pNSKs+YIj6r+I7pIhinZHzqfxdf4Jw=; b=qLYdPkVkahoc8bgyW1xvDegigZcbAU8HjSIE2+0HfSFLrwEHhIi+B8Tq1RjeWIjWru HNtBEZb1WIbSxD3M4PBiqJDw+h8XYELeWkXOMc9fSYVYo8c3ntUufCz2ehhT3s2BvXbd N173DtGzAXWh4ttc4X/xzd6n6+AdEbAhw9DA7xQZo1t+sssuoFhPxklICmHUTdgeqOEo 2JFCvQIEZ/ohRZnDTyylZIo8eifCEPDWUPd/hDncWufJbLvCEyI+lUBNEXvB/dodbgsJ E2pLijzEJfJSNKBAaOAyNpi7z7MTT/AakvHKS/HxUv4kBPp9ERQcwZV87Q4OPZh/b2Tm EqIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785801315; x=1786406115; 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=boUlwZ1rWoh22pNSKs+YIj6r+I7pIhinZHzqfxdf4Jw=; b=PbdrYrk4W7r8KRqtgn4oO0K2crMVoPe/YsWI157FLP51waxLbZtroePQRcsm0MZBUt jVzrhQALzVjGmNV8PtHxD7cxUPC8OolT3DOXTWHVaOvAycHzDctSB5NL1aNGUAJZ67e+ PsfWSRpDeBihljqr/1wZsLb3N+QwSaqzOSxvoT9iNFNGMJmkqvp5H0euiyc9IepZBiMM xS1qXI6Xl1i+lOM2AdRvWPQcZzmKwIdVUnSseALjScrtd9vqGkVXFTJyUKpPJNfNF6gd GjD7/Uh+fdgUWM9Q/lOa2xAAwK6JL7ihM1X6Iemva/WM11QMJHxvmlum6Hzjc0SAyAps +Ybg== X-Gm-Message-State: AOJu0Yz+DxiQhS/QuBtMRXPpKYn1VX4BxamTAiuQEQWhC7P5bKejq64A aj+ItcdN4EM0NLc6Vgn688Sp4RFKNelI+Nn35C6ObQmDZuIlLr7HqIJy2hHePBR4 X-Gm-Gg: AR+sD134AOntxwYFJ+wViQgPrRaATHBbEHpR4vmWfnOp2bfEklF57DdC0kIw5teqIbd 3s6b2sMDLI9babPZg4nLWREi7v13qYbr6Yfe8TAz/r5SYUThiTm7gOrIu7/2U9yTaUwLgesmm0u nbE/xrRQVmSgoIS4VkfYa9xMT63S5gfWOI+WeEjgqaYp8E4gZN4X9zHlFEVxVUK3LWpqb16qtU/ 8GeK3nyRZ8RgVIQfKAjUby0yFQz3dxGkDunc/yUOScAK8C9NSAPwWI/q2aFELhuiepz+80Ona1P wW+ou58lPx+YGhOT2AHSa3hsBR97P7XGqbgbs0eb1/00w6zyYDYDmfn9ZupjmwavIBsT3nur97a Tw0rxLh+WDdOhMyvvnWl0b7Vq7uJHeQ8Fg8LFEa1dnkSgwboA6InNyBSr9Tq3Ufw+6L8QNa7kxG 6/gFoJBAriyqZjDJODlNQ+z8j1HLot/fdYTJyLLCfj0Fi3D7Gy3DishRVM3gS9 X-Received: by 2002:a05:690c:6903:b0:80b:bc16:8a2a with SMTP id 00721157ae682-81fd4bf6790mr153939887b3.36.1785801314923; Mon, 03 Aug 2026 16:55:14 -0700 (PDT) Received: from localhost ([2600:1702:7a90:6f9f:8bc4:8aec:108d:7a04]) by smtp.gmail.com with ESMTPSA id 00721157ae682-81fcd123dacsm63503147b3.39.2026.08.03.16.55.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2026 16:55:14 -0700 (PDT) From: Matt Turner To: libc-alpha@sourceware.org Cc: Joseph Myers , Adhemerval Zanella , Magnus Lindholm Subject: [PATCH 2/4] math: signal underflow for narrowing results that are tiny before rounding Date: Mon, 3 Aug 2026 19:55:07 -0400 Message-ID: <20260803235509.3532030-3-mattst88@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260803235509.3532030-1-mattst88@gmail.com> References: <20260803235509.3532030-1-mattst88@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.5 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, 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 A narrowing arithmetic function rounds the exact result once to the narrower type, so it underflows whenever that result is both tiny and inexact. Two cases were not being signaled. A result that rounds up to exactly the smallest normal value of the narrower type is not tiny any more once rounded, so architectures determining tininess after rounding do not raise underflow for it even though the exact result was tiny. Whether underflow is due is decided by rounding the round-to-odd value with an unbounded exponent range: dividing by the smallest normal is exact and moves it into the normal range, so the conversion that follows rounds only the significand. A subnormal result is tiny by inspection, and an inexact narrowing to one underflows. This is normally signaled by the narrowing conversion itself, but is lost where that conversion is carried out in more than one step: an intermediate type wide enough to keep the double rounding harmless for the value can still round to a number the narrower type represents exactly, leaving the final step exact. This happens on alpha, where the compiler converts long double to float via double. Both raises are redundant on architectures that already signal these, and harmless there. The comparisons use the quiet relational macros because the result is a NaN whenever an argument was, and the signaling relational operators would raise a spurious invalid exception for it. The macros take the smallest normal value of the narrower type as a new argument, as only the callers know that type. --- math/math-narrow.h | 130 ++++++++++++++++++----- sysdeps/i386/fpu/s_f32xdivf64.c | 3 +- sysdeps/i386/fpu/s_f32xmulf64.c | 3 +- sysdeps/ieee754/dbl-64/s_fadd.c | 3 +- sysdeps/ieee754/dbl-64/s_fdiv.c | 4 +- sysdeps/ieee754/dbl-64/s_ffma.c | 4 +- sysdeps/ieee754/dbl-64/s_fmul.c | 4 +- sysdeps/ieee754/dbl-64/s_fsub.c | 3 +- sysdeps/ieee754/ldbl-128/s_daddl.c | 4 +- sysdeps/ieee754/ldbl-128/s_ddivl.c | 4 +- sysdeps/ieee754/ldbl-128/s_dfmal.c | 4 +- sysdeps/ieee754/ldbl-128/s_dmull.c | 4 +- sysdeps/ieee754/ldbl-128/s_dsubl.c | 4 +- sysdeps/ieee754/ldbl-128/s_f64xaddf128.c | 4 +- sysdeps/ieee754/ldbl-128/s_f64xdivf128.c | 5 +- sysdeps/ieee754/ldbl-128/s_f64xfmaf128.c | 5 +- sysdeps/ieee754/ldbl-128/s_f64xmulf128.c | 5 +- sysdeps/ieee754/ldbl-128/s_f64xsubf128.c | 4 +- sysdeps/ieee754/ldbl-128/s_faddl.c | 4 +- sysdeps/ieee754/ldbl-128/s_fdivl.c | 4 +- sysdeps/ieee754/ldbl-128/s_ffmal.c | 4 +- sysdeps/ieee754/ldbl-128/s_fmull.c | 4 +- sysdeps/ieee754/ldbl-128/s_fsubl.c | 4 +- sysdeps/ieee754/ldbl-96/s_daddl.c | 4 +- sysdeps/ieee754/ldbl-96/s_ddivl.c | 4 +- sysdeps/ieee754/ldbl-96/s_dfmal.c | 4 +- sysdeps/ieee754/ldbl-96/s_dmull.c | 4 +- sysdeps/ieee754/ldbl-96/s_dsubl.c | 4 +- sysdeps/ieee754/ldbl-96/s_faddl.c | 4 +- sysdeps/ieee754/ldbl-96/s_fdivl.c | 4 +- sysdeps/ieee754/ldbl-96/s_ffmal.c | 4 +- sysdeps/ieee754/ldbl-96/s_fmull.c | 4 +- sysdeps/ieee754/ldbl-96/s_fsubl.c | 4 +- sysdeps/x86/fpu/s_ffma.c | 4 +- 34 files changed, 172 insertions(+), 89 deletions(-) diff --git ./math/math-narrow.h ./math/math-narrow.h index bb319cc2ca..51a43cb92b 100644 --- ./math/math-narrow.h +++ ./math/math-narrow.h @@ -62,6 +62,57 @@ u.d; \ }) +/* Raise the underflow exception for a narrowing of the round-to-odd + value W to RET that is tiny and inexact but whose underflow the + architecture did not signal. A narrowing operation rounds the exact + result once to the narrower type, so it underflows whenever that + result is both tiny and inexact. MIN_NORMAL is the smallest positive + normal value of the narrower type. Two cases need help here, and on + architectures that already signal them the extra raise is redundant + but harmless. + + A subnormal RET is tiny by inspection, so an inexact narrowing to one + underflows. This is normally signaled by the narrowing conversion, + but is lost where that conversion is performed in more than one step: + an intermediate type wide enough to make the double rounding harmless + for the value can still round to a number the narrower type + represents exactly, leaving the final step exact. + + A RET of exactly MIN_NORMAL is not tiny after rounding, so + architectures detecting tininess after rounding do not signal it even + though the exact result was tiny. Rounding W with an unbounded + exponent range decides whether it is tiny under that rule too. + + The comparisons use the quiet relational macros: RET is a NaN + whenever an argument was, and the signaling relational operators + would raise a spurious invalid exception for it. */ +#ifdef FE_UNDERFLOW +# define CHECK_NARROW_TINY(RET, W, MIN_NORMAL) \ + do \ + { \ + if (isless (RET, MIN_NORMAL) && isgreater (RET, -(MIN_NORMAL))) \ + { \ + if ((W) != (RET)) \ + __feraiseexcept (FE_UNDERFLOW); \ + } \ + else if (((RET) == (MIN_NORMAL) || (RET) == -(MIN_NORMAL)) \ + && isless (W, MIN_NORMAL) && isgreater (W, -(MIN_NORMAL))) \ + { \ + /* Dividing by MIN_NORMAL is exact and moves W into the \ + normal range, so the conversion below rounds only the \ + significand. Underflow is due only when the value is \ + still tiny afterwards; when it rounds up to exactly \ + MIN_NORMAL it is not tiny after rounding. */ \ + __typeof (RET) __scaled = (__typeof (RET)) ((W) / (MIN_NORMAL)); \ + if (__scaled > -1 && __scaled < 1) \ + __feraiseexcept (FE_UNDERFLOW); \ + } \ + } \ + while (0) +#else +# define CHECK_NARROW_TINY(RET, W, MIN_NORMAL) do { } while (0) +#endif + /* Check for error conditions from a narrowing add function returning RET with arguments X and Y and set errno as needed. Overflow and underflow can occur for finite arguments and a domain error for @@ -85,9 +136,11 @@ while (0) /* Implement narrowing add using round-to-odd. The arguments are X - and Y, the return type is TYPE and UNION, MANTISSA and SUFFIX are - as for ROUND_TO_ODD. */ -#define NARROW_ADD_ROUND_TO_ODD(X, Y, TYPE, UNION, SUFFIX, MANTISSA) \ + and Y, the return type is TYPE, MIN_NORMAL is the smallest positive + normal value of TYPE and UNION, MANTISSA and SUFFIX are as for + ROUND_TO_ODD. */ +#define NARROW_ADD_ROUND_TO_ODD(X, Y, TYPE, MIN_NORMAL, UNION, SUFFIX, \ + MANTISSA) \ do \ { \ TYPE ret; \ @@ -97,8 +150,13 @@ if ((X) == -(Y)) \ ret = (TYPE) ((X) + (Y)); \ else \ - ret = (TYPE) ROUND_TO_ODD (math_opt_barrier (X) + (Y), \ - UNION, SUFFIX, MANTISSA, false); \ + { \ + __typeof ((X) + (Y)) tmp \ + = ROUND_TO_ODD (math_opt_barrier (X) + (Y), \ + UNION, SUFFIX, MANTISSA, false); \ + ret = (TYPE) tmp; \ + CHECK_NARROW_TINY (ret, tmp, MIN_NORMAL); \ + } \ \ CHECK_NARROW_ADD (ret, (X), (Y)); \ return ret; \ @@ -143,9 +201,11 @@ while (0) /* Implement narrowing subtract using round-to-odd. The arguments are - X and Y, the return type is TYPE and UNION, MANTISSA and SUFFIX are - as for ROUND_TO_ODD. */ -#define NARROW_SUB_ROUND_TO_ODD(X, Y, TYPE, UNION, SUFFIX, MANTISSA) \ + X and Y, the return type is TYPE, MIN_NORMAL is the smallest positive + normal value of TYPE and UNION, MANTISSA and SUFFIX are as for + ROUND_TO_ODD. */ +#define NARROW_SUB_ROUND_TO_ODD(X, Y, TYPE, MIN_NORMAL, UNION, SUFFIX, \ + MANTISSA) \ do \ { \ TYPE ret; \ @@ -155,8 +215,13 @@ if ((X) == (Y)) \ ret = (TYPE) ((X) - (Y)); \ else \ - ret = (TYPE) ROUND_TO_ODD (math_opt_barrier (X) - (Y), \ - UNION, SUFFIX, MANTISSA, false); \ + { \ + __typeof ((X) - (Y)) tmp \ + = ROUND_TO_ODD (math_opt_barrier (X) - (Y), \ + UNION, SUFFIX, MANTISSA, false); \ + ret = (TYPE) tmp; \ + CHECK_NARROW_TINY (ret, tmp, MIN_NORMAL); \ + } \ \ CHECK_NARROW_SUB (ret, (X), (Y)); \ return ret; \ @@ -201,17 +266,21 @@ while (0) /* Implement narrowing multiply using round-to-odd. The arguments are - X and Y, the return type is TYPE and UNION, MANTISSA, SUFFIX and - CLEAR_UNDERFLOW are as for ROUND_TO_ODD. */ -#define NARROW_MUL_ROUND_TO_ODD(X, Y, TYPE, UNION, SUFFIX, MANTISSA, \ - CLEAR_UNDERFLOW) \ + X and Y, the return type is TYPE, MIN_NORMAL is the smallest positive + normal value of TYPE and UNION, MANTISSA, SUFFIX and CLEAR_UNDERFLOW + are as for ROUND_TO_ODD. */ +#define NARROW_MUL_ROUND_TO_ODD(X, Y, TYPE, MIN_NORMAL, UNION, SUFFIX, \ + MANTISSA, CLEAR_UNDERFLOW) \ do \ { \ TYPE ret; \ + __typeof ((X) * (Y)) tmp; \ \ - ret = (TYPE) ROUND_TO_ODD (math_opt_barrier (X) * (Y), \ - UNION, SUFFIX, MANTISSA, \ - CLEAR_UNDERFLOW); \ + tmp = ROUND_TO_ODD (math_opt_barrier (X) * (Y), \ + UNION, SUFFIX, MANTISSA, \ + CLEAR_UNDERFLOW); \ + ret = (TYPE) tmp; \ + CHECK_NARROW_TINY (ret, tmp, MIN_NORMAL); \ \ CHECK_NARROW_MUL (ret, (X), (Y)); \ return ret; \ @@ -256,17 +325,21 @@ while (0) /* Implement narrowing divide using round-to-odd. The arguments are X - and Y, the return type is TYPE and UNION, MANTISSA, SUFFIX and - CLEAR_UNDERFLOW are as for ROUND_TO_ODD. */ -#define NARROW_DIV_ROUND_TO_ODD(X, Y, TYPE, UNION, SUFFIX, MANTISSA, \ - CLEAR_UNDERFLOW) \ + and Y, the return type is TYPE, MIN_NORMAL is the smallest positive + normal value of TYPE and UNION, MANTISSA, SUFFIX and CLEAR_UNDERFLOW + are as for ROUND_TO_ODD. */ +#define NARROW_DIV_ROUND_TO_ODD(X, Y, TYPE, MIN_NORMAL, UNION, SUFFIX, \ + MANTISSA, CLEAR_UNDERFLOW) \ do \ { \ TYPE ret; \ + __typeof ((X) / (Y)) tmp; \ \ - ret = (TYPE) ROUND_TO_ODD (math_opt_barrier (X) / (Y), \ - UNION, SUFFIX, MANTISSA, \ - CLEAR_UNDERFLOW); \ + tmp = ROUND_TO_ODD (math_opt_barrier (X) / (Y), \ + UNION, SUFFIX, MANTISSA, \ + CLEAR_UNDERFLOW); \ + ret = (TYPE) tmp; \ + CHECK_NARROW_TINY (ret, tmp, MIN_NORMAL); \ \ CHECK_NARROW_DIV (ret, (X), (Y)); \ return ret; \ @@ -356,8 +429,8 @@ /* Implement narrowing fused multiply-add using round-to-odd. The arguments are X, Y and Z, the return type is TYPE and UNION, MANTISSA, SUFFIX and CLEAR_UNDERFLOW are as for ROUND_TO_ODD. */ -#define NARROW_FMA_ROUND_TO_ODD(X, Y, Z, TYPE, UNION, SUFFIX, MANTISSA, \ - CLEAR_UNDERFLOW) \ +#define NARROW_FMA_ROUND_TO_ODD(X, Y, Z, TYPE, MIN_NORMAL, UNION, \ + SUFFIX, MANTISSA, CLEAR_UNDERFLOW) \ do \ { \ typeof (X) tmp; \ @@ -371,7 +444,10 @@ if (tmp == 0) \ ret = (TYPE) (math_opt_barrier (X) * (Y) + (Z)); \ else \ - ret = (TYPE) tmp; \ + { \ + ret = (TYPE) tmp; \ + CHECK_NARROW_TINY (ret, tmp, MIN_NORMAL); \ + } \ \ CHECK_NARROW_FMA (ret, (X), (Y), (Z)); \ return ret; \ diff --git ./sysdeps/i386/fpu/s_f32xdivf64.c ./sysdeps/i386/fpu/s_f32xdivf64.c index 9090844404..00e9a51676 100644 --- ./sysdeps/i386/fpu/s_f32xdivf64.c +++ ./sysdeps/i386/fpu/s_f32xdivf64.c @@ -24,6 +24,7 @@ __f32xdivf64 (_Float64 x, _Float64 y) { /* To avoid double rounding, use round-to-odd on long double. */ NARROW_DIV_ROUND_TO_ODD ((long double) x, (long double) y, double, - union ieee854_long_double, l, mantissa1, false); + __DBL_MIN__, union ieee854_long_double, l, + mantissa1, false); } libm_alias_float32x_float64 (div) diff --git ./sysdeps/i386/fpu/s_f32xmulf64.c ./sysdeps/i386/fpu/s_f32xmulf64.c index 536ddd4d78..fc96096782 100644 --- ./sysdeps/i386/fpu/s_f32xmulf64.c +++ ./sysdeps/i386/fpu/s_f32xmulf64.c @@ -24,6 +24,7 @@ __f32xmulf64 (_Float64 x, _Float64 y) { /* To avoid double rounding, use round-to-odd on long double. */ NARROW_MUL_ROUND_TO_ODD ((long double) x, (long double) y, double, - union ieee854_long_double, l, mantissa1, false); + __DBL_MIN__, union ieee854_long_double, l, + mantissa1, false); } libm_alias_float32x_float64 (mul) diff --git ./sysdeps/ieee754/dbl-64/s_fadd.c ./sysdeps/ieee754/dbl-64/s_fadd.c index 22bf2766df..7091ae1539 100644 --- ./sysdeps/ieee754/dbl-64/s_fadd.c +++ ./sysdeps/ieee754/dbl-64/s_fadd.c @@ -29,6 +29,7 @@ float __fadd (double x, double y) { - NARROW_ADD_ROUND_TO_ODD (x, y, float, union ieee754_double, , mantissa1); + NARROW_ADD_ROUND_TO_ODD (x, y, float, __FLT_MIN__, union ieee754_double, , + mantissa1); } libm_alias_float_double (add) diff --git ./sysdeps/ieee754/dbl-64/s_fdiv.c ./sysdeps/ieee754/dbl-64/s_fdiv.c index 918e1722ca..5de0f1f37c 100644 --- ./sysdeps/ieee754/dbl-64/s_fdiv.c +++ ./sysdeps/ieee754/dbl-64/s_fdiv.c @@ -29,7 +29,7 @@ float __fdiv (double x, double y) { - NARROW_DIV_ROUND_TO_ODD (x, y, float, union ieee754_double, , mantissa1, - false); + NARROW_DIV_ROUND_TO_ODD (x, y, float, __FLT_MIN__, union ieee754_double, , + mantissa1, false); } libm_alias_float_double (div) diff --git ./sysdeps/ieee754/dbl-64/s_ffma.c ./sysdeps/ieee754/dbl-64/s_ffma.c index 14db126cfd..f341fa88cd 100644 --- ./sysdeps/ieee754/dbl-64/s_ffma.c +++ ./sysdeps/ieee754/dbl-64/s_ffma.c @@ -29,7 +29,7 @@ float __ffma (double x, double y, double z) { - NARROW_FMA_ROUND_TO_ODD (x, y, z, float, union ieee754_double, , mantissa1, - false); + NARROW_FMA_ROUND_TO_ODD (x, y, z, float, __FLT_MIN__, union ieee754_double, + , mantissa1, false); } libm_alias_float_double (fma) diff --git ./sysdeps/ieee754/dbl-64/s_fmul.c ./sysdeps/ieee754/dbl-64/s_fmul.c index 2fdc7c5f22..528096bc83 100644 --- ./sysdeps/ieee754/dbl-64/s_fmul.c +++ ./sysdeps/ieee754/dbl-64/s_fmul.c @@ -29,7 +29,7 @@ float __fmul (double x, double y) { - NARROW_MUL_ROUND_TO_ODD (x, y, float, union ieee754_double, , mantissa1, - false); + NARROW_MUL_ROUND_TO_ODD (x, y, float, __FLT_MIN__, union ieee754_double, , + mantissa1, false); } libm_alias_float_double (mul) diff --git ./sysdeps/ieee754/dbl-64/s_fsub.c ./sysdeps/ieee754/dbl-64/s_fsub.c index 79ccfaef9d..9008e7cbf4 100644 --- ./sysdeps/ieee754/dbl-64/s_fsub.c +++ ./sysdeps/ieee754/dbl-64/s_fsub.c @@ -29,6 +29,7 @@ float __fsub (double x, double y) { - NARROW_SUB_ROUND_TO_ODD (x, y, float, union ieee754_double, , mantissa1); + NARROW_SUB_ROUND_TO_ODD (x, y, float, __FLT_MIN__, union ieee754_double, , + mantissa1); } libm_alias_float_double (sub) diff --git ./sysdeps/ieee754/ldbl-128/s_daddl.c ./sysdeps/ieee754/ldbl-128/s_daddl.c index 17a76321c0..97d1073b11 100644 --- ./sysdeps/ieee754/ldbl-128/s_daddl.c +++ ./sysdeps/ieee754/ldbl-128/s_daddl.c @@ -31,7 +31,7 @@ double __daddl (_Float128 x, _Float128 y) { - NARROW_ADD_ROUND_TO_ODD (x, y, double, union ieee854_long_double, l, - mantissa3); + NARROW_ADD_ROUND_TO_ODD (x, y, double, __DBL_MIN__, + union ieee854_long_double, l, mantissa3); } libm_alias_double_ldouble (add) diff --git ./sysdeps/ieee754/ldbl-128/s_ddivl.c ./sysdeps/ieee754/ldbl-128/s_ddivl.c index be17f2d3db..a30fcb959c 100644 --- ./sysdeps/ieee754/ldbl-128/s_ddivl.c +++ ./sysdeps/ieee754/ldbl-128/s_ddivl.c @@ -31,7 +31,7 @@ double __ddivl (_Float128 x, _Float128 y) { - NARROW_DIV_ROUND_TO_ODD (x, y, double, union ieee854_long_double, l, - mantissa3, false); + NARROW_DIV_ROUND_TO_ODD (x, y, double, __DBL_MIN__, + union ieee854_long_double, l, mantissa3, false); } libm_alias_double_ldouble (div) diff --git ./sysdeps/ieee754/ldbl-128/s_dfmal.c ./sysdeps/ieee754/ldbl-128/s_dfmal.c index a6784e6fc1..beacfa2c73 100644 --- ./sysdeps/ieee754/ldbl-128/s_dfmal.c +++ ./sysdeps/ieee754/ldbl-128/s_dfmal.c @@ -32,7 +32,7 @@ double __dfmal (_Float128 x, _Float128 y, _Float128 z) { - NARROW_FMA_ROUND_TO_ODD (x, y, z, double, union ieee854_long_double, l, - mantissa3, false); + NARROW_FMA_ROUND_TO_ODD (x, y, z, double, __DBL_MIN__, + union ieee854_long_double, l, mantissa3, false); } libm_alias_double_ldouble (fma) diff --git ./sysdeps/ieee754/ldbl-128/s_dmull.c ./sysdeps/ieee754/ldbl-128/s_dmull.c index 5e5f2ee6d1..60ab752095 100644 --- ./sysdeps/ieee754/ldbl-128/s_dmull.c +++ ./sysdeps/ieee754/ldbl-128/s_dmull.c @@ -31,7 +31,7 @@ double __dmull (_Float128 x, _Float128 y) { - NARROW_MUL_ROUND_TO_ODD (x, y, double, union ieee854_long_double, l, - mantissa3, false); + NARROW_MUL_ROUND_TO_ODD (x, y, double, __DBL_MIN__, + union ieee854_long_double, l, mantissa3, false); } libm_alias_double_ldouble (mul) diff --git ./sysdeps/ieee754/ldbl-128/s_dsubl.c ./sysdeps/ieee754/ldbl-128/s_dsubl.c index a2e51664bc..b0583ef518 100644 --- ./sysdeps/ieee754/ldbl-128/s_dsubl.c +++ ./sysdeps/ieee754/ldbl-128/s_dsubl.c @@ -31,7 +31,7 @@ double __dsubl (_Float128 x, _Float128 y) { - NARROW_SUB_ROUND_TO_ODD (x, y, double, union ieee854_long_double, l, - mantissa3); + NARROW_SUB_ROUND_TO_ODD (x, y, double, __DBL_MIN__, + union ieee854_long_double, l, mantissa3); } libm_alias_double_ldouble (sub) diff --git ./sysdeps/ieee754/ldbl-128/s_f64xaddf128.c ./sysdeps/ieee754/ldbl-128/s_f64xaddf128.c index 8a53f146fd..bf2d0ccf5f 100644 --- ./sysdeps/ieee754/ldbl-128/s_f64xaddf128.c +++ ./sysdeps/ieee754/ldbl-128/s_f64xaddf128.c @@ -29,8 +29,8 @@ _Float64x __f64xaddf128 (_Float128 x, _Float128 y) { #if __HAVE_FLOAT64X_LONG_DOUBLE && __HAVE_DISTINCT_FLOAT128 - NARROW_ADD_ROUND_TO_ODD (x, y, _Float64x, union ieee854_long_double, l, - mantissa3); + NARROW_ADD_ROUND_TO_ODD (x, y, _Float64x, __FLT64X_MIN__, + union ieee854_long_double, l, mantissa3); #else NARROW_ADD_TRIVIAL (x, y, _Float64x); #endif diff --git ./sysdeps/ieee754/ldbl-128/s_f64xdivf128.c ./sysdeps/ieee754/ldbl-128/s_f64xdivf128.c index 51573c8adf..af594f566e 100644 --- ./sysdeps/ieee754/ldbl-128/s_f64xdivf128.c +++ ./sysdeps/ieee754/ldbl-128/s_f64xdivf128.c @@ -30,8 +30,9 @@ _Float64x __f64xdivf128 (_Float128 x, _Float128 y) { #if __HAVE_FLOAT64X_LONG_DOUBLE && __HAVE_DISTINCT_FLOAT128 - NARROW_DIV_ROUND_TO_ODD (x, y, _Float64x, union ieee854_long_double, l, - mantissa3, TININESS_AFTER_ROUNDING); + NARROW_DIV_ROUND_TO_ODD (x, y, _Float64x, __FLT64X_MIN__, + union ieee854_long_double, l, mantissa3, + TININESS_AFTER_ROUNDING); #else NARROW_DIV_TRIVIAL (x, y, _Float64x); #endif diff --git ./sysdeps/ieee754/ldbl-128/s_f64xfmaf128.c ./sysdeps/ieee754/ldbl-128/s_f64xfmaf128.c index 0f7d5592e0..af0436263c 100644 --- ./sysdeps/ieee754/ldbl-128/s_f64xfmaf128.c +++ ./sysdeps/ieee754/ldbl-128/s_f64xfmaf128.c @@ -30,8 +30,9 @@ _Float64x __f64xfmaf128 (_Float128 x, _Float128 y, _Float128 z) { - NARROW_FMA_ROUND_TO_ODD (x, y, z, _Float64x, union ieee854_long_double, l, - mantissa3, TININESS_AFTER_ROUNDING); + NARROW_FMA_ROUND_TO_ODD (x, y, z, _Float64x, __FLT64X_MIN__, + union ieee854_long_double, l, mantissa3, + TININESS_AFTER_ROUNDING); } libm_alias_float64x_float128 (fma) #else diff --git ./sysdeps/ieee754/ldbl-128/s_f64xmulf128.c ./sysdeps/ieee754/ldbl-128/s_f64xmulf128.c index 6a59e04bb1..d4e3322d25 100644 --- ./sysdeps/ieee754/ldbl-128/s_f64xmulf128.c +++ ./sysdeps/ieee754/ldbl-128/s_f64xmulf128.c @@ -30,8 +30,9 @@ _Float64x __f64xmulf128 (_Float128 x, _Float128 y) { #if __HAVE_FLOAT64X_LONG_DOUBLE && __HAVE_DISTINCT_FLOAT128 - NARROW_MUL_ROUND_TO_ODD (x, y, _Float64x, union ieee854_long_double, l, - mantissa3, TININESS_AFTER_ROUNDING); + NARROW_MUL_ROUND_TO_ODD (x, y, _Float64x, __FLT64X_MIN__, + union ieee854_long_double, l, mantissa3, + TININESS_AFTER_ROUNDING); #else NARROW_MUL_TRIVIAL (x, y, _Float64x); #endif diff --git ./sysdeps/ieee754/ldbl-128/s_f64xsubf128.c ./sysdeps/ieee754/ldbl-128/s_f64xsubf128.c index 05311608c8..dffb7ac7d8 100644 --- ./sysdeps/ieee754/ldbl-128/s_f64xsubf128.c +++ ./sysdeps/ieee754/ldbl-128/s_f64xsubf128.c @@ -29,8 +29,8 @@ _Float64x __f64xsubf128 (_Float128 x, _Float128 y) { #if __HAVE_FLOAT64X_LONG_DOUBLE && __HAVE_DISTINCT_FLOAT128 - NARROW_SUB_ROUND_TO_ODD (x, y, _Float64x, union ieee854_long_double, l, - mantissa3); + NARROW_SUB_ROUND_TO_ODD (x, y, _Float64x, __FLT64X_MIN__, + union ieee854_long_double, l, mantissa3); #else NARROW_SUB_TRIVIAL (x, y, _Float64x); #endif diff --git ./sysdeps/ieee754/ldbl-128/s_faddl.c ./sysdeps/ieee754/ldbl-128/s_faddl.c index 3b74da68dc..41d7a7846b 100644 --- ./sysdeps/ieee754/ldbl-128/s_faddl.c +++ ./sysdeps/ieee754/ldbl-128/s_faddl.c @@ -27,7 +27,7 @@ float __faddl (_Float128 x, _Float128 y) { - NARROW_ADD_ROUND_TO_ODD (x, y, float, union ieee854_long_double, l, - mantissa3); + NARROW_ADD_ROUND_TO_ODD (x, y, float, __FLT_MIN__, + union ieee854_long_double, l, mantissa3); } libm_alias_float_ldouble (add) diff --git ./sysdeps/ieee754/ldbl-128/s_fdivl.c ./sysdeps/ieee754/ldbl-128/s_fdivl.c index 3d10e4eec0..2d7389e02c 100644 --- ./sysdeps/ieee754/ldbl-128/s_fdivl.c +++ ./sysdeps/ieee754/ldbl-128/s_fdivl.c @@ -27,7 +27,7 @@ float __fdivl (_Float128 x, _Float128 y) { - NARROW_DIV_ROUND_TO_ODD (x, y, float, union ieee854_long_double, l, - mantissa3, false); + NARROW_DIV_ROUND_TO_ODD (x, y, float, __FLT_MIN__, + union ieee854_long_double, l, mantissa3, false); } libm_alias_float_ldouble (div) diff --git ./sysdeps/ieee754/ldbl-128/s_ffmal.c ./sysdeps/ieee754/ldbl-128/s_ffmal.c index 711baf893e..92be4e736c 100644 --- ./sysdeps/ieee754/ldbl-128/s_ffmal.c +++ ./sysdeps/ieee754/ldbl-128/s_ffmal.c @@ -28,7 +28,7 @@ float __ffmal (_Float128 x, _Float128 y, _Float128 z) { - NARROW_FMA_ROUND_TO_ODD (x, y, z, float, union ieee854_long_double, l, - mantissa3, false); + NARROW_FMA_ROUND_TO_ODD (x, y, z, float, __FLT_MIN__, + union ieee854_long_double, l, mantissa3, false); } libm_alias_float_ldouble (fma) diff --git ./sysdeps/ieee754/ldbl-128/s_fmull.c ./sysdeps/ieee754/ldbl-128/s_fmull.c index 2534d6636b..a13fe149db 100644 --- ./sysdeps/ieee754/ldbl-128/s_fmull.c +++ ./sysdeps/ieee754/ldbl-128/s_fmull.c @@ -27,7 +27,7 @@ float __fmull (_Float128 x, _Float128 y) { - NARROW_MUL_ROUND_TO_ODD (x, y, float, union ieee854_long_double, l, - mantissa3, false); + NARROW_MUL_ROUND_TO_ODD (x, y, float, __FLT_MIN__, + union ieee854_long_double, l, mantissa3, false); } libm_alias_float_ldouble (mul) diff --git ./sysdeps/ieee754/ldbl-128/s_fsubl.c ./sysdeps/ieee754/ldbl-128/s_fsubl.c index 57b7bb3f9f..38c5ce8d9b 100644 --- ./sysdeps/ieee754/ldbl-128/s_fsubl.c +++ ./sysdeps/ieee754/ldbl-128/s_fsubl.c @@ -27,7 +27,7 @@ float __fsubl (_Float128 x, _Float128 y) { - NARROW_SUB_ROUND_TO_ODD (x, y, float, union ieee854_long_double, l, - mantissa3); + NARROW_SUB_ROUND_TO_ODD (x, y, float, __FLT_MIN__, + union ieee854_long_double, l, mantissa3); } libm_alias_float_ldouble (sub) diff --git ./sysdeps/ieee754/ldbl-96/s_daddl.c ./sysdeps/ieee754/ldbl-96/s_daddl.c index ffdede0807..846509d819 100644 --- ./sysdeps/ieee754/ldbl-96/s_daddl.c +++ ./sysdeps/ieee754/ldbl-96/s_daddl.c @@ -27,7 +27,7 @@ double __daddl (long double x, long double y) { - NARROW_ADD_ROUND_TO_ODD (x, y, double, union ieee854_long_double, l, - mantissa1); + NARROW_ADD_ROUND_TO_ODD (x, y, double, __DBL_MIN__, + union ieee854_long_double, l, mantissa1); } libm_alias_double_ldouble (add) diff --git ./sysdeps/ieee754/ldbl-96/s_ddivl.c ./sysdeps/ieee754/ldbl-96/s_ddivl.c index 1bbea6fae7..fb811704e5 100644 --- ./sysdeps/ieee754/ldbl-96/s_ddivl.c +++ ./sysdeps/ieee754/ldbl-96/s_ddivl.c @@ -27,7 +27,7 @@ double __ddivl (long double x, long double y) { - NARROW_DIV_ROUND_TO_ODD (x, y, double, union ieee854_long_double, l, - mantissa1, false); + NARROW_DIV_ROUND_TO_ODD (x, y, double, __DBL_MIN__, + union ieee854_long_double, l, mantissa1, false); } libm_alias_double_ldouble (div) diff --git ./sysdeps/ieee754/ldbl-96/s_dfmal.c ./sysdeps/ieee754/ldbl-96/s_dfmal.c index 332ea895ec..b2fb24eb06 100644 --- ./sysdeps/ieee754/ldbl-96/s_dfmal.c +++ ./sysdeps/ieee754/ldbl-96/s_dfmal.c @@ -28,7 +28,7 @@ double __dfmal (long double x, long double y, long double z) { - NARROW_FMA_ROUND_TO_ODD (x, y, z, double, union ieee854_long_double, l, - mantissa1, false); + NARROW_FMA_ROUND_TO_ODD (x, y, z, double, __DBL_MIN__, + union ieee854_long_double, l, mantissa1, false); } libm_alias_double_ldouble (fma) diff --git ./sysdeps/ieee754/ldbl-96/s_dmull.c ./sysdeps/ieee754/ldbl-96/s_dmull.c index faeede2f0e..b023bded5d 100644 --- ./sysdeps/ieee754/ldbl-96/s_dmull.c +++ ./sysdeps/ieee754/ldbl-96/s_dmull.c @@ -27,7 +27,7 @@ double __dmull (long double x, long double y) { - NARROW_MUL_ROUND_TO_ODD (x, y, double, union ieee854_long_double, l, - mantissa1, false); + NARROW_MUL_ROUND_TO_ODD (x, y, double, __DBL_MIN__, + union ieee854_long_double, l, mantissa1, false); } libm_alias_double_ldouble (mul) diff --git ./sysdeps/ieee754/ldbl-96/s_dsubl.c ./sysdeps/ieee754/ldbl-96/s_dsubl.c index 7ac31434dd..594512810d 100644 --- ./sysdeps/ieee754/ldbl-96/s_dsubl.c +++ ./sysdeps/ieee754/ldbl-96/s_dsubl.c @@ -27,7 +27,7 @@ double __dsubl (long double x, long double y) { - NARROW_SUB_ROUND_TO_ODD (x, y, double, union ieee854_long_double, l, - mantissa1); + NARROW_SUB_ROUND_TO_ODD (x, y, double, __DBL_MIN__, + union ieee854_long_double, l, mantissa1); } libm_alias_double_ldouble (sub) diff --git ./sysdeps/ieee754/ldbl-96/s_faddl.c ./sysdeps/ieee754/ldbl-96/s_faddl.c index 46d4a035a3..fae922bb1b 100644 --- ./sysdeps/ieee754/ldbl-96/s_faddl.c +++ ./sysdeps/ieee754/ldbl-96/s_faddl.c @@ -25,7 +25,7 @@ float __faddl (long double x, long double y) { - NARROW_ADD_ROUND_TO_ODD (x, y, float, union ieee854_long_double, l, - mantissa1); + NARROW_ADD_ROUND_TO_ODD (x, y, float, __FLT_MIN__, + union ieee854_long_double, l, mantissa1); } libm_alias_float_ldouble (add) diff --git ./sysdeps/ieee754/ldbl-96/s_fdivl.c ./sysdeps/ieee754/ldbl-96/s_fdivl.c index a819df6d81..0cddc4f745 100644 --- ./sysdeps/ieee754/ldbl-96/s_fdivl.c +++ ./sysdeps/ieee754/ldbl-96/s_fdivl.c @@ -25,7 +25,7 @@ float __fdivl (long double x, long double y) { - NARROW_DIV_ROUND_TO_ODD (x, y, float, union ieee854_long_double, l, - mantissa1, false); + NARROW_DIV_ROUND_TO_ODD (x, y, float, __FLT_MIN__, + union ieee854_long_double, l, mantissa1, false); } libm_alias_float_ldouble (div) diff --git ./sysdeps/ieee754/ldbl-96/s_ffmal.c ./sysdeps/ieee754/ldbl-96/s_ffmal.c index 5f158b43b0..92ab91455e 100644 --- ./sysdeps/ieee754/ldbl-96/s_ffmal.c +++ ./sysdeps/ieee754/ldbl-96/s_ffmal.c @@ -26,7 +26,7 @@ float __ffmal (long double x, long double y, long double z) { - NARROW_FMA_ROUND_TO_ODD (x, y, z, float, union ieee854_long_double, l, - mantissa1, false); + NARROW_FMA_ROUND_TO_ODD (x, y, z, float, __FLT_MIN__, + union ieee854_long_double, l, mantissa1, false); } libm_alias_float_ldouble (fma) diff --git ./sysdeps/ieee754/ldbl-96/s_fmull.c ./sysdeps/ieee754/ldbl-96/s_fmull.c index cabe804070..103d819b24 100644 --- ./sysdeps/ieee754/ldbl-96/s_fmull.c +++ ./sysdeps/ieee754/ldbl-96/s_fmull.c @@ -25,7 +25,7 @@ float __fmull (long double x, long double y) { - NARROW_MUL_ROUND_TO_ODD (x, y, float, union ieee854_long_double, l, - mantissa1, false); + NARROW_MUL_ROUND_TO_ODD (x, y, float, __FLT_MIN__, + union ieee854_long_double, l, mantissa1, false); } libm_alias_float_ldouble (mul) diff --git ./sysdeps/ieee754/ldbl-96/s_fsubl.c ./sysdeps/ieee754/ldbl-96/s_fsubl.c index 0d2de90d5a..5827d02ff2 100644 --- ./sysdeps/ieee754/ldbl-96/s_fsubl.c +++ ./sysdeps/ieee754/ldbl-96/s_fsubl.c @@ -25,7 +25,7 @@ float __fsubl (long double x, long double y) { - NARROW_SUB_ROUND_TO_ODD (x, y, float, union ieee854_long_double, l, - mantissa1); + NARROW_SUB_ROUND_TO_ODD (x, y, float, __FLT_MIN__, + union ieee854_long_double, l, mantissa1); } libm_alias_float_ldouble (sub) diff --git ./sysdeps/x86/fpu/s_ffma.c ./sysdeps/x86/fpu/s_ffma.c index 329a9d7469..099f36971b 100644 --- ./sysdeps/x86/fpu/s_ffma.c +++ ./sysdeps/x86/fpu/s_ffma.c @@ -44,7 +44,7 @@ float __ffma (double x, double y, double z) { - NARROW_FMA_ROUND_TO_ODD (x, y, z, float, union ieee754_double, , mantissa1, - false); + NARROW_FMA_ROUND_TO_ODD (x, y, z, float, __FLT_MIN__, union ieee754_double, + , mantissa1, false); } libm_alias_float_double (fma) From patchwork Mon Aug 3 23:55:08 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Turner X-Patchwork-Id: 140550 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 9F64D4BB24D9 for ; Mon, 3 Aug 2026 23:56:31 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-yx1-xb12f.google.com (mail-yx1-xb12f.google.com [IPv6:2607:f8b0:4864:20::b12f]) by sourceware.org (Postfix) with ESMTPS id 123044BB24E6 for ; Mon, 3 Aug 2026 23:55:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 123044BB24E6 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 123044BB24E6 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::b12f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1785801318; cv=none; b=au6Jn7EdDFZUOdRSnl9+DXN3xYMfxPNgC0xNkoGOTXN19bQjeS5bOMqL4LvIJ24yaJ8yISxaUQcf/4pYBiblvO74v/VLgGFQEiqLqzoeL6ZTb9D2+HKkGUn1VPCB/LJ1bzUGMe3RaYOhtM9A2r1bMufjtC1mCnVAkonkLcxzZxY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1785801318; c=relaxed/simple; bh=TzLDn+5TmchY+b2CunhRS78OvE/o270xdlts4cekICM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=uB0DUtLa0t1rKpcUn0eAFRR3zrUShZPVNZQwYzf1NE+bGu5QJZX1GVr/Ma/17cX+Oil5EkV8DcEoEFMxsr/1Y1W8jfLyoqoLIJ2v3//kcPfqDBlvpF59dTCh/zv2Pm6QM46lwo2hqRxGi/tvxHYhjXb1xOZzc4VUZ1td+cSq22I= 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=ibCr6hVb DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 123044BB24E6 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=ibCr6hVb Received: by mail-yx1-xb12f.google.com with SMTP id 956f58d0204a3-66843536f94so4527787d50.3 for ; Mon, 03 Aug 2026 16:55:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785801317; x=1786406117; 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=u9Niqf5JfqZcJKZ8pTLFC83OTfirfmrtfbcoe1VmQmk=; b=ibCr6hVbMriX9GkeBojT3jxFumPGO4axK40o+ry1w5p8UTFpMGHyjD4/TVsGQ+iMRb UzsLx5udeezA7tKymBo+2FlILvZWMiNgqWzIlNGdUdL9RGnTZQNktsVweuWoYbpba5Yt VAFY1QsLKFW2M/9KF5MYtkUlPgk5GrILDjb5HGK6MCizwvDytNtw3w0w1sMtRO3qukJq WHh6zPDzRPxnerhWGSfvNC1sWkrWglp0B1p5Pt8gialt2DUJDKfPRGkJn9MivL0W7BFR xwYQ9s5SohW5bekN3yUUVv2axZkVPdyTvzzaY6Qkpc4tMMrLQqFEJj4rGRr2vCFC3tkc RXoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785801317; x=1786406117; 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=u9Niqf5JfqZcJKZ8pTLFC83OTfirfmrtfbcoe1VmQmk=; b=ZVUukLfksI5FCImYAIADiu+0MO5A2pYFSR/ddCQ5ypWihoqKjDCbldEgjT/3Zv194i cexmFyIzjzoMoac/yNXsxict7rR5KU14qVbasVxtGvruhFR84vCTInIOidBdklY9O9+t h4aw39XHbhizNyg5LFr2NFORDGL3jBTk+sz8TH8oeVsj7gW82MXSfzJkhzvpsviDumI2 ChLOaZSKZorzJDwhRB+6K+xGAvALPhOKl0UP4kQTmwHEPPDY4/8oU3yw9uhGzKWZ/cYf IYxPkPGyGotGgpXavaYvcAOr3MCSQgiZ4z24dXCL0PkB+HHS44CwRH3vssdw+OhsTlGM TW+g== X-Gm-Message-State: AOJu0YxYC1R9gMS3++bv0EPJ2DOZlngmNEEZGT6oTFEJHM3gN8tf8S16 b5phLh/Xec67wHnaItKzabVMx8FA9UarnMP3eFF8ZsoReC2xCf8OUNRVzWDJoxbY X-Gm-Gg: AR+sD10qFH2nvL6dkYDtoAgPv6ArWdTvuPwjDG09zyhPTpVFUXhaZ8nyOypOrWVxZUH d/OqZLWDLp8uLzapOdeczUsGk/PWfhtcQtI9D+XJpeYuIWOnJVxLkGBNf+xumjZPZRIDd0hWAA0 Dqt4nMRChzKQkbQB3UFmSDrSSOnA8IsAjEaoav9BbX/OTI41x4DtW1I0LzOO28R9B5bPLkaPr/3 qurSMDLoA4fO3mOa3E5zamp8kJq/dhl05953aDmHEaF5rfRLR/GR2RH4qsbfPr0/a3+xIs6CQy8 PQWRgreLdeVPtEzviHHZdIrfRAYgjauY6FMfaIz+U19BJGkXdrmIXMSU0rkd3UkOq7M6oGh+Tuw ApkeGreKGlmFX2DqJpYuikUD1I+PVY26+fVp9ZYn+8tfG8Rfby4mUniAbXf0f11uMpRaCjjChTu YEs+69Zi7qA3cxS/axrxZhl7jqrr4pUiUJ7gIdJpf/pJ4/xwBo7flF5p0bxc9NBECRPW3JM9s= X-Received: by 2002:a05:690e:400a:b0:667:8495:9604 with SMTP id 956f58d0204a3-6694f164d2bmr16062754d50.25.1785801316988; Mon, 03 Aug 2026 16:55:16 -0700 (PDT) Received: from localhost ([2600:1702:7a90:6f9f:8bc4:8aec:108d:7a04]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-66948ff805csm6600566d50.15.2026.08.03.16.55.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2026 16:55:15 -0700 (PDT) From: Matt Turner To: libc-alpha@sourceware.org Cc: Joseph Myers , Adhemerval Zanella , Magnus Lindholm Subject: [PATCH 3/4] math: signal underflow for fmaf results that are tiny before rounding Date: Mon, 3 Aug 2026 19:55:08 -0400 Message-ID: <20260803235509.3532030-4-mattst88@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260803235509.3532030-1-mattst88@gmail.com> References: <20260803235509.3532030-1-mattst88@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.4 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, 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 fmaf computes the exact result as a double and lets the return convert it to float, so that conversion is the operation's single rounding and is what has to signal underflow. Where the exact result is tiny but rounds up to the smallest normal float, architectures determining tininess after rounding do not signal it, because the value they examine is no longer tiny. Route the returns through a helper that applies CHECK_NARROW_TINY, which already decides this by rounding with an unbounded exponent range. The raise is redundant on architectures that signal such results themselves. --- sysdeps/ieee754/dbl-64/s_fmaf.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git ./sysdeps/ieee754/dbl-64/s_fmaf.c ./sysdeps/ieee754/dbl-64/s_fmaf.c index 639c273486..dc78e9453a 100644 --- ./sysdeps/ieee754/dbl-64/s_fmaf.c +++ ./sysdeps/ieee754/dbl-64/s_fmaf.c @@ -20,9 +20,24 @@ #include #include #include +#include #include #include "math_config.h" +#if !USE_FMAF_BUILTIN +/* Narrow the double result to float. The exact result of the fma is + representable as a double, so the conversion is the operation's single + rounding and it is what must signal underflow; help it where the + architecture does not. */ +static inline float +narrow_fmaf_result (double d) +{ + float ret = (float) d; + CHECK_NARROW_TINY (ret, d, __FLT_MIN__); + return ret; +} +#endif + float __fmaf (float x, float y, float z) { @@ -37,17 +52,17 @@ __fmaf (float x, float y, float z) /* If not exact or at round to even boundary, the result is correct in all rounding modes. */ if (__glibc_likely ((u & 0xfffffff) != 0)) - return result; + return narrow_fmaf_result (result); /* Also check if the double result appears exact when it might not be and thus it will not set the underflow flag if denormal. */ if ((u & 0x10000000) == 0 && ((u >> MANTISSA_WIDTH) & 0x7ff) > EXPONENT_BIAS - 126) - return result; + return narrow_fmaf_result (result); /* Return if result is exact in all rounding modes. */ if (result - xy == z && result - z == xy) - return result; + return narrow_fmaf_result (result); /* This is where 'double-rouding' might return a wrong value, and thus needs adjusting the low-order bits in the direction of the error. */ @@ -62,7 +77,7 @@ __fmaf (float x, float y, float z) u++; else u--; - return asdouble (u); + return narrow_fmaf_result (asdouble (u)); #endif /* ! USE_FMAF_BUILTIN */ } #ifndef __fmaf From patchwork Mon Aug 3 23:55:09 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Turner X-Patchwork-Id: 140549 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 00C8A4BB24D1 for ; Mon, 3 Aug 2026 23:56:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 00C8A4BB24D1 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=D8Mtt4+l X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-yw1-x1130.google.com (mail-yw1-x1130.google.com [IPv6:2607:f8b0:4864:20::1130]) by sourceware.org (Postfix) with ESMTPS id 3637D4BB24EE for ; Mon, 3 Aug 2026 23:55:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3637D4BB24EE 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 3637D4BB24EE Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1785801319; cv=none; b=Hv+iuo5kwL7cydgtnILguxjtNDSyw7R7MwqEkxIUcHC0FDWmGOSnt+lLV1xnIOejOq0EQFaWLBXaiCmtaklxfHjPS1qKhc0NT8jmuwdwe/UrZMjFW+RLFOnzZK9Ey6y0sav4l57N6dYJKz1IDtwpp2X1s9i5Fxn8Kr1cLgsfvWs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1785801319; c=relaxed/simple; bh=x5o03PxcGBP9SwmTl+0IplFhBcgz23XjsLFP+hVixmk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ixE3sNMTc+lvvMDxCbBuyW+76FllrFRGmbNqR9goeESeOmhsubGbec9gYb0Se8HsX0MFkKRAYyrMaSdpuf0ro9cQQXFI3Iu5slcAj7oQXDEcgXSq8IH7n5oQiUP54OsgCxLrZiYJH7NymI4GSBWg2Q5Q1O+nIpq4U94vx018DN4= ARC-Authentication-Results: i=1; sourceware.org Received: by mail-yw1-x1130.google.com with SMTP id 00721157ae682-81f36179dd5so55709647b3.2 for ; Mon, 03 Aug 2026 16:55:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785801318; x=1786406118; 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=S/WChJvuhy5cM6Q+NW/6D9QpY2kP1sq8b44Ujr0CV1I=; b=D8Mtt4+lsoAf+2tWoMkkbQD/OdKEhIZz68d6dLA8KZRNd0bncF+HiMm14Uv1pJsnLr mzK088U1P6m2/sziPNiNugsqqu8g6CZs143E2EJDwdpbpC9NnN1e8v8PZdHywyijEjzB T5Onlwz7RykSOTxYwlHURGkAo3FsJ4ShNUYeHz5xgYf9vXH/scA1M/Tk1u4D+QkpPrt9 CjdTL5/5qQ+S+q8TonJ5DNqXKb9g3I2xjJEwOF76xFhRKN0BwjYJfHTlygtU3/HBndqF 583r+IavDAwSRMa02NdymiWe2v5DVw9ymIP7DI35rPpNPopyUVJdXx5B5Oopj3ZvgWBg sm5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785801318; x=1786406118; 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=S/WChJvuhy5cM6Q+NW/6D9QpY2kP1sq8b44Ujr0CV1I=; b=pRCT8uX4YI61j84aVQZ0SN2zzDGkOIEEdDqH5bD4zBwT/PZRwXY7pNFTNT6p8KloHA mxmr6rshyWf1nNtIpAxn9m0J2VzivY11FFjSm7h+6vFYMU27P7JJUh3d2r2GbqJcIGj5 VWYttgaRnHtUIiRk6CYDvj7VRD/guSoXB/1KsKg8tz2VL3aLd8B+GdPq5/Xj+hLzWIgk FZUc2YGZqsgsleSYDa9glXJ8CPhguS7FDgF+P/00dqPoeeR1QEPUQLH6oqaOJyW4VS4s 7AxPMN8C7peCZWvHN21bvh5T0LxdK8sQh1BJYp2fhbWz/m5q5QKE8MHQ7tudbEMVZrg1 GgVA== X-Gm-Message-State: AOJu0Yxzn3tW/y54V+1WCgPPkIvw7gwVkHuwGHdub71qy4WQTEPFKiuN YX2sYWWo2R/G3LQH4RxqAPkfYv2nbACcs66lcjuklSwFrGJIP2QbT0SxsyQ5PPZz X-Gm-Gg: AR+sD10lZpDRwsXXTMcjQgzZ7s/waMsKTpPAQs3x2CuryqdDK6uksWSiIpSgGA2vNBS 7C0CxoQboHG4IIkvR1bp/7w+bnGJbtZaUjOnZh5zXsfs/orUPh3dmfWi11pXjtoOKiFHj7h83lX ZNcv+hczrIBV5YTW2NIM+UT+AL3vnYzVAYS1Njy8d/f940hpEiUuZBnk1vAd7oO7gfwka24gLYn vSFQQeW/v8Mz4ZVVnOmlmN8xb46LcywxPd91f0d6y6LIlpNzBnOYmN50wqr2L+LbBbfhXnQTSr+ jScFRtPYmE2usJzsSp4dSmB0hOoWXcbKdSUTC5HicX0iqxAPJKHf43RzPK7O3u9dDqpiSlugW5r n9IDbnAC9dH9Qn+yZxV9djJ1/LSi/TGVuEog3y0VBx/QINOHV6/fFF9VYgyboXRyTZSH+7CfW3a EH876gxDlVT5o58nsYTO0mkSRZH2u9T09I2asJPIoR/P1+r+qPXWLk3iwPosIz X-Received: by 2002:a05:690c:6286:b0:80c:8d09:3880 with SMTP id 00721157ae682-81fd4a86754mr153258967b3.15.1785801318380; Mon, 03 Aug 2026 16:55:18 -0700 (PDT) Received: from localhost ([2600:1702:7a90:6f9f:8bc4:8aec:108d:7a04]) by smtp.gmail.com with ESMTPSA id 00721157ae682-81fcd14658csm64226367b3.45.2026.08.03.16.55.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Aug 2026 16:55:17 -0700 (PDT) From: Matt Turner To: libc-alpha@sourceware.org Cc: Joseph Myers , Adhemerval Zanella , Magnus Lindholm Subject: [PATCH 4/4] alpha: expect test-float32x-float64-div to fail Date: Mon, 3 Aug 2026 19:55:09 -0400 Message-ID: <20260803235509.3532030-5-mattst88@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260803235509.3532030-1-mattst88@gmail.com> References: <20260803235509.3532030-1-mattst88@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 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, 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 _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 result rounded as if the exponent range were unbounded, while Alpha determines it from the delivered result. The two differ for a quotient that is tiny but rounds up to the smallest normal, as in DBL_MIN / (1 + 2^-52) under a rounding mode that rounds away from zero: the binade below DBL_MIN has a finer spacing than the subnormals, so the unbounded rounding stays below DBL_MIN and the result is tiny, but the delivered result is DBL_MIN and looks normal. Alpha signals no underflow for it. Nothing in software can correct this. The hardware detects no underflow, so no software completion trap is taken and the kernel emulation never runs, and as the operation is not really narrowing there is no wider intermediate for libm to examine. Reviewed-by: Adhemerval Zanella --- sysdeps/alpha/Makefile | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git ./sysdeps/alpha/Makefile ./sysdeps/alpha/Makefile index 60a369e255..faa59ab27a 100644 --- ./sysdeps/alpha/Makefile +++ ./sysdeps/alpha/Makefile @@ -53,6 +53,20 @@ CFLAGS-s_lrint.c += -mieee-with-inexact CFLAGS-test-misc.c += -mieee-with-inexact # Avoid "conflicting types for built-in function" warnings CFLAGS-s_isnan.c += -fno-builtin-isnanf + +# _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 +# result rounded as if the exponent range were unbounded, but Alpha +# determines it from the delivered result. For a quotient that is tiny +# but rounds up to the smallest normal -- DBL_MIN / (1 + 2^-52) under a +# rounding mode that rounds away from zero -- the unbounded rounding +# stays below DBL_MIN, because that binade has a finer spacing than the +# subnormals, while the delivered result is DBL_MIN and looks normal. +# Alpha raises no underflow for it. No trap is taken, so the kernel +# emulation cannot correct this, and the operation has no wider +# intermediate for libm to examine. +test-xfail-test-float32x-float64-div = yes endif # Build everything with full IEEE math support, and with dynamic rounding;