Message ID | 20231228172026.2013007-1-adhemerval.zanella@linaro.org |
---|---|
Headers |
Return-Path: <libc-alpha-bounces+patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6BD403858004 for <patchwork@sourceware.org>; Thu, 28 Dec 2023 17:21:07 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id 808E63858C53 for <libc-alpha@sourceware.org>; Thu, 28 Dec 2023 17:20:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 808E63858C53 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 808E63858C53 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703784033; cv=none; b=ICIIIKn3+Cs/2iu6LEMa62JgD9BcITKdGIx4Z0X4NNP0o9KfwE8Jh88HYNFZooJPG0Hj1f968RvvTNpAti4wlVhycxn5W3qkSZqSrUD+sqU5bpjUFxES/Y/S1l9A4pkpODUnVET44/kA/ClCwDSG2LsMh0fvemxr2Vp39bphsQU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703784033; c=relaxed/simple; bh=ItnTCa0ITfROYJAlkJFf/bgel0E6q3ADf1I6aVx2riw=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=qQPX6KmZUFDf6dn+0VEJQhAc7kkQMIF8YAK5qr5PZqlXqYKruc/EbLFjDY/3GV0YzwyWxS7ezdX6cAwzQ/H2158KxJkRBcl1jfRickRDAKofM6Eptwslb8yasbjfIuhmOItQ8iPqRC/Xy232i/kXXjII9zs4e3Pn89ur1Obk8bs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-6d9bbf71bc8so1091181b3a.1 for <libc-alpha@sourceware.org>; Thu, 28 Dec 2023 09:20:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1703784030; x=1704388830; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=HqQW9/O7bSQNN7dqB6w2gf2+vRt7trtSUXe2yV/+ezc=; b=o6ORoU+MRqwDEhyE70/SPCnGZt3aEyBFQC2vxoi3rBsONbipWhBxGkpqFuc31XSZ2J +VSERNuA7sfMMRbOLMSXAPMoVJN0eZRRju/7+e2VCYYIcI/4W2LXnVrhl639dGURibxg NfsPg+Q2yADMjiVzyLz+8F1W5ylk8i23mbvvk3pPAFB4F0Mf1YfzM4D11KoMu0JY0wmY DHQOGI/5ZwFqreyLwaf310JD9fcDLBXFSeqRG1UpM5raB5NNp+BIRIVNYom4I7G3eZj9 m/jJ12wvwgWVBR0d/TQB8/DOQiaeZQ85yr3hAHLQ43+j1FBNkAMIA972fxXZko2CJbvU 2pZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703784030; x=1704388830; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=HqQW9/O7bSQNN7dqB6w2gf2+vRt7trtSUXe2yV/+ezc=; b=RzcaRY8OA6cerZqGi0iy9VtJkkzfsdkh+NsViMsp2VNgGKI2Upb53OrbosMvck7EEu lY+RWYsKsEqSn0vbKffouFhJikpQXw6p+aNMRVp703LgUOFVoqG+CNLp6LK/koakoPRM wH2+n+euD5+kKFL00BXI//mZ7sZanwqCVrBIIRVnVQNu/FDkW5255bvSyvWio+2PF5Vr fgrxnRAMCPB/tEL7AAmP59NZ2aJ8dYLf6M5q0urdSa0QBeNT78tRr0vM/AgZBh1K+XZ8 I3EOfqMYCBnt3aWe+NDFYm7oyxaVqE864OHKR6xJxWWothI0+BuA2WkMe76qDgXtvsIx HlpA== X-Gm-Message-State: AOJu0YyqJSy4LNHq2BTylGWJX8x5yFX4ChzdDAkOrpj2no3etysK9ojA Mnsun35lA+MkdFeUYfp9FRVc+lQdhDfDIY/ijGyHgld+0cI= X-Google-Smtp-Source: AGHT+IE71SsfmHbkXTqbSo3vh9oiKfsjBcYkDnpJvCI7FHdSq3fh62JWW2NBFObPwl16j0de8bXD2w== X-Received: by 2002:a05:6a00:2fc6:b0:6d9:b5cb:d794 with SMTP id fn6-20020a056a002fc600b006d9b5cbd794mr3235918pfb.21.1703784029814; Thu, 28 Dec 2023 09:20:29 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c1:bd9:84dc:8a87:ea0:57d7]) by smtp.gmail.com with ESMTPSA id q7-20020aa79827000000b006d9a94a03a8sm9593839pfl.77.2023.12.28.09.20.28 for <libc-alpha@sourceware.org> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 09:20:29 -0800 (PST) From: Adhemerval Zanella <adhemerval.zanella@linaro.org> To: libc-alpha@sourceware.org Subject: [PATCH 00/12] Improve rounding to interger function for C23 Date: Thu, 28 Dec 2023 14:20:14 -0300 Message-Id: <20231228172026.2013007-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_NUMSUBJECT, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list <libc-alpha.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/libc-alpha/> List-Post: <mailto:libc-alpha@sourceware.org> List-Help: <mailto:libc-alpha-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=subscribe> Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org |
Series |
Improve rounding to interger function for C23
|
|
Message
Adhemerval Zanella Netto
Dec. 28, 2023, 5:20 p.m. UTC
As indicated by GCC documentation [1], ISO C23 does not allow that C bindings ceil, floor, round, and trunc (in all floating point formats) to raise inexact exceptions (different than ISO C99/C11 where this is allowed). A recent MIPS patch to used some arch-specific instructions raised this issue [1] and it was not caught because there was no proper testing. By adding the missing tests, some implementations do indeed raise inexact exceptions. The generic implementation all uses integer operation, so they are not subject to this issue. The powerpc (for power4 and lower) and the riscv avoid the inexact exception by disabling/enabling exceptions. The x86 uses some arch-specific implementation for long double and on i386 (due to the use of x87 instruction). Instead of adding newer symbols depending on the required standard version, the patchset adapts the faulty ones to avoid raising the inexact exception. The x86 version already saves/restore the floating point status, so I think it is unlikely the patch would yield much performance difference (I did not do any performance analysis on whether a generic implementation would yield better performance). I checked on powerpc, powerpc64, aarch64, armhf, x86, and did some regression checks on riscv. [1] https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-fno-fp-int-builtin-inexact [2] https://sourceware.org/pipermail/libc-alpha/2023-December/153528.html Adhemerval Zanella (12): math: Reformat Makefile. powerpc: Add missing arch flags on rounding ifunc variants math: Add test to check if ceil raise inexact floating-point exception math: Add test to check if floor raise inexact floating-point exception math: Add test to check if trunc raise inexact floating-point exception math: Add test to check if round raise inexact floating-point exception x86: Do not raise inexact exception on ceill x86: Do not raise inexact exception on floorl x86: Do not raise inexact exception on truncl x86: Do not raise inexact exception on floor/floorf i386: Do not raise inexact exception on ceil/ceilf i386: Do not raise inexact exception on trunc/truncf math/Makefile | 861 ++++++++++++++---- math/test-ceil-except-2.c | 67 ++ math/test-ceil-except.c | 85 ++ math/test-floor-except-2.c | 67 ++ math/test-floor-except.c | 85 ++ math/test-round-except-2.c | 67 ++ math/test-round-except.c | 85 ++ math/test-trunc-except-2.c | 67 ++ math/test-trunc-except.c | 85 ++ sysdeps/i386/fpu/s_ceil.S | 34 - sysdeps/i386/fpu/s_ceil.c | 38 + sysdeps/i386/fpu/s_ceilf.S | 34 - sysdeps/i386/fpu/s_ceilf.c | 38 + sysdeps/i386/fpu/s_ceill.S | 39 - sysdeps/i386/fpu/s_floor.S | 34 - sysdeps/i386/fpu/s_floor.c | 38 + sysdeps/i386/fpu/s_floorf.S | 34 - sysdeps/i386/fpu/s_floorf.c | 38 + sysdeps/i386/fpu/s_floorl.S | 39 - sysdeps/i386/fpu/{s_trunc.S => s_trunc.c} | 37 +- sysdeps/i386/fpu/{s_truncf.S => s_truncf.c} | 37 +- .../powerpc32/power4/fpu/multiarch/Makefile | 6 + .../fpu/s_truncl.S => x86/fpu/s_ceill.c} | 38 +- sysdeps/x86/fpu/s_floorl.c | 38 + .../fpu/s_truncl.S => x86/fpu/s_truncl.c} | 40 +- sysdeps/x86_64/fpu/s_ceill.S | 34 - sysdeps/x86_64/fpu/s_floorl.S | 33 - 27 files changed, 1583 insertions(+), 515 deletions(-) create mode 100644 math/test-ceil-except-2.c create mode 100644 math/test-ceil-except.c create mode 100644 math/test-floor-except-2.c create mode 100644 math/test-floor-except.c create mode 100644 math/test-round-except-2.c create mode 100644 math/test-round-except.c create mode 100644 math/test-trunc-except-2.c create mode 100644 math/test-trunc-except.c delete mode 100644 sysdeps/i386/fpu/s_ceil.S create mode 100644 sysdeps/i386/fpu/s_ceil.c delete mode 100644 sysdeps/i386/fpu/s_ceilf.S create mode 100644 sysdeps/i386/fpu/s_ceilf.c delete mode 100644 sysdeps/i386/fpu/s_ceill.S delete mode 100644 sysdeps/i386/fpu/s_floor.S create mode 100644 sysdeps/i386/fpu/s_floor.c delete mode 100644 sysdeps/i386/fpu/s_floorf.S create mode 100644 sysdeps/i386/fpu/s_floorf.c delete mode 100644 sysdeps/i386/fpu/s_floorl.S rename sysdeps/i386/fpu/{s_trunc.S => s_trunc.c} (61%) rename sysdeps/i386/fpu/{s_truncf.S => s_truncf.c} (61%) rename sysdeps/{x86_64/fpu/s_truncl.S => x86/fpu/s_ceill.c} (57%) create mode 100644 sysdeps/x86/fpu/s_floorl.c rename sysdeps/{i386/fpu/s_truncl.S => x86/fpu/s_truncl.c} (61%) delete mode 100644 sysdeps/x86_64/fpu/s_ceill.S delete mode 100644 sysdeps/x86_64/fpu/s_floorl.S
Comments
Ping. On 28/12/23 14:20, Adhemerval Zanella wrote: > As indicated by GCC documentation [1], ISO C23 does not allow that C > bindings ceil, floor, round, and trunc (in all floating point formats) > to raise > inexact exceptions (different than ISO C99/C11 where this is allowed). > > A recent MIPS patch to used some arch-specific instructions raised this > issue [1] and it was not caught because there was no proper testing. By > adding the missing tests, some implementations do indeed raise inexact > exceptions. > > The generic implementation all uses integer operation, so they are not > subject to this issue. The powerpc (for power4 and lower) and the riscv > avoid the inexact exception by disabling/enabling exceptions. The x86 > uses some arch-specific implementation for long double and on i386 (due > to the use of x87 instruction). > > Instead of adding newer symbols depending on the required standard > version, the patchset adapts the faulty ones to avoid raising the > inexact exception. The x86 version already saves/restore the floating > point status, so I think it is unlikely the patch would yield much > performance difference (I did not do any performance analysis on whether > a generic implementation would yield better performance). > > I checked on powerpc, powerpc64, aarch64, armhf, x86, and did some > regression checks on riscv. > > [1] https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-fno-fp-int-builtin-inexact > [2] https://sourceware.org/pipermail/libc-alpha/2023-December/153528.html > > Adhemerval Zanella (12): > math: Reformat Makefile. > powerpc: Add missing arch flags on rounding ifunc variants > math: Add test to check if ceil raise inexact floating-point exception > math: Add test to check if floor raise inexact floating-point > exception > math: Add test to check if trunc raise inexact floating-point > exception > math: Add test to check if round raise inexact floating-point > exception > x86: Do not raise inexact exception on ceill > x86: Do not raise inexact exception on floorl > x86: Do not raise inexact exception on truncl > x86: Do not raise inexact exception on floor/floorf > i386: Do not raise inexact exception on ceil/ceilf > i386: Do not raise inexact exception on trunc/truncf > > math/Makefile | 861 ++++++++++++++---- > math/test-ceil-except-2.c | 67 ++ > math/test-ceil-except.c | 85 ++ > math/test-floor-except-2.c | 67 ++ > math/test-floor-except.c | 85 ++ > math/test-round-except-2.c | 67 ++ > math/test-round-except.c | 85 ++ > math/test-trunc-except-2.c | 67 ++ > math/test-trunc-except.c | 85 ++ > sysdeps/i386/fpu/s_ceil.S | 34 - > sysdeps/i386/fpu/s_ceil.c | 38 + > sysdeps/i386/fpu/s_ceilf.S | 34 - > sysdeps/i386/fpu/s_ceilf.c | 38 + > sysdeps/i386/fpu/s_ceill.S | 39 - > sysdeps/i386/fpu/s_floor.S | 34 - > sysdeps/i386/fpu/s_floor.c | 38 + > sysdeps/i386/fpu/s_floorf.S | 34 - > sysdeps/i386/fpu/s_floorf.c | 38 + > sysdeps/i386/fpu/s_floorl.S | 39 - > sysdeps/i386/fpu/{s_trunc.S => s_trunc.c} | 37 +- > sysdeps/i386/fpu/{s_truncf.S => s_truncf.c} | 37 +- > .../powerpc32/power4/fpu/multiarch/Makefile | 6 + > .../fpu/s_truncl.S => x86/fpu/s_ceill.c} | 38 +- > sysdeps/x86/fpu/s_floorl.c | 38 + > .../fpu/s_truncl.S => x86/fpu/s_truncl.c} | 40 +- > sysdeps/x86_64/fpu/s_ceill.S | 34 - > sysdeps/x86_64/fpu/s_floorl.S | 33 - > 27 files changed, 1583 insertions(+), 515 deletions(-) > create mode 100644 math/test-ceil-except-2.c > create mode 100644 math/test-ceil-except.c > create mode 100644 math/test-floor-except-2.c > create mode 100644 math/test-floor-except.c > create mode 100644 math/test-round-except-2.c > create mode 100644 math/test-round-except.c > create mode 100644 math/test-trunc-except-2.c > create mode 100644 math/test-trunc-except.c > delete mode 100644 sysdeps/i386/fpu/s_ceil.S > create mode 100644 sysdeps/i386/fpu/s_ceil.c > delete mode 100644 sysdeps/i386/fpu/s_ceilf.S > create mode 100644 sysdeps/i386/fpu/s_ceilf.c > delete mode 100644 sysdeps/i386/fpu/s_ceill.S > delete mode 100644 sysdeps/i386/fpu/s_floor.S > create mode 100644 sysdeps/i386/fpu/s_floor.c > delete mode 100644 sysdeps/i386/fpu/s_floorf.S > create mode 100644 sysdeps/i386/fpu/s_floorf.c > delete mode 100644 sysdeps/i386/fpu/s_floorl.S > rename sysdeps/i386/fpu/{s_trunc.S => s_trunc.c} (61%) > rename sysdeps/i386/fpu/{s_truncf.S => s_truncf.c} (61%) > rename sysdeps/{x86_64/fpu/s_truncl.S => x86/fpu/s_ceill.c} (57%) > create mode 100644 sysdeps/x86/fpu/s_floorl.c > rename sysdeps/{i386/fpu/s_truncl.S => x86/fpu/s_truncl.c} (61%) > delete mode 100644 sysdeps/x86_64/fpu/s_ceill.S > delete mode 100644 sysdeps/x86_64/fpu/s_floorl.S >