From patchwork Thu Dec 28 17:20:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 758597 Delivered-To: patch@linaro.org Received: by 2002:a5d:67c6:0:b0:336:6142:bf13 with SMTP id n6csp4114536wrw; Thu, 28 Dec 2023 09:20:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IE5BYx3FFglfgGHwBjVYz+a6kSjRHYAuGOUpTkk1il332vzSesyD7ya6cHSAZPp2N7I/y0R X-Received: by 2002:a05:620a:5625:b0:77d:cc40:252e with SMTP id vv5-20020a05620a562500b0077dcc40252emr11929459qkn.51.1703784047619; Thu, 28 Dec 2023 09:20:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1703784047; cv=pass; d=google.com; s=arc-20160816; b=sHyWCF0oL92W0e9vOwvw5mMK09+4UhtV1m05qYJP7M6nHnqHo8i4yTuIuFQnKfl5ve pbygZCL3X9NsOk8kxUla1ayIDlX7XyZIO3AFSeA10V2lHGAYeu0cjZAaqLMZAhru/pCS 6I1e88wnr7pgqdtxMeulN+xYFzkMQOvWbID/jpbotIFzgZC26i3GGdoiOi12uvmK0vuP NEKkykUCbxx0jGXk9S0hPRh1qCxXLRFpVM968s/FbUdgIzSMN5mExoQjvqQfZhdcwuWe lkUnXs15g1rgFIrrKqrlKNxy5bwh4UA2ligm30pDKZ7+qmQA7etD2SzJY486meypubyf J2jw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=HqQW9/O7bSQNN7dqB6w2gf2+vRt7trtSUXe2yV/+ezc=; fh=dHLBnA+MhGtNtN2B2JMAELi4oD+gmgMg7DL8H0jYbkI=; b=FrWC/Zl5AH478orGgn58wk6YpnrBxGTXjNYQqg0eVq5D7bRxxiKMiFW6SvjGn9hwDR YeEM/eBAJSa4GShEESqT8bQHbCq+7Ul0MRlnT2QR4M+FTdtqb7aC+IdF3G6MwbL57x63 WoRoRQ6uz4ZDIe6iR8i08VRLlF9Upui2CXa+hb1rHZo9Wv1tskSkSP9+TkyTccLOApxx 1INnZW1Pxf2njs/LVG1WoV9dlcBF+pIy1XUA2DGIa/Y0ZnQ3s11+2k0xLqAL4D6o4Nds B/0cdXudYqTSr2CP+7HX1jnZaVUQhQszLlrTjxqEhxjrLohvQId2LzNrWQ5GD/DaJ6ad 87yA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=o6ORoU+M; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id g26-20020a05620a109a00b00781149a883csi16340501qkk.349.2023.12.28.09.20.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 09:20:47 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=o6ORoU+M; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces+patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2AB3D38582A1 for ; Thu, 28 Dec 2023 17:20:47 +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 ; 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 ; 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-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 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 09:20:29 -0800 (PST) From: Adhemerval Zanella 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 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patch=linaro.org@sourceware.org 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