From patchwork Wed Apr 3 12:11:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 785434 Delivered-To: patch@linaro.org Received: by 2002:adf:f001:0:b0:33e:7753:30bd with SMTP id j1csp282889wro; Wed, 3 Apr 2024 05:13:44 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXYG88enj0f+IGeLZLLWBRSBvUeMZI/e5JjTrV8hUAgTrBfdrskQ9U47/e1FHHTQFpXU5nMzEILQgfixTh/PEoR X-Google-Smtp-Source: AGHT+IE7BkMl7mUlXcA7UD9//sMkapI/k9uT3QXtoz8bGGtS3jPW2PowgwQh6JjsR0uYsoLSFPAK X-Received: by 2002:a05:6808:1709:b0:3c5:d2fb:ed8a with SMTP id bc9-20020a056808170900b003c5d2fbed8amr1355108oib.35.1712146424019; Wed, 03 Apr 2024 05:13:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712146423; cv=pass; d=google.com; s=arc-20160816; b=twRK+yormT2W9M2Iy+hHq7CSBAPRSrhke7OKgCdtOEw3NzHvTgCjb/Da1JbAK+08zQ c0/1pXXcD/XA09RloSuQnpMP22j5w/QHCwqiKNSOxuKPuTBaeu7z6demEVN8KGt4WCpj UxA6MjtCu+sp627iyqczrknKEFs2UxuEkbOONnkmNVUQl2HGVJ6NEoiJABgZIugiqbYs 8VmRI8+fNEQmKzHd9kkGet1iAbbNWZjqco53KRelvux+DejxzCV9pCeBNTUfMi0B13AQ G5llR+S7g7Hn0M2+Sf4btV3Mcon5XM51AlqQvAODOIx2xucYV/ZdmSkgVHUY55I8ks87 de1w== 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:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=mcC9BT77771N8Eii2ZWnHojpfSkULVnusjkmQelNl8o=; fh=+6orIzRLXQY2FWXAtGF+abYflc8V+YPKzsYFuX0DJM4=; b=ett6B60nu0tAixQf0acwXW5Ug5MfYZVccqKPOKrFOy/UPHaGwgfeghfpHtjADsqT3v 05NkQIvlUZ8lIu2S4vx4qNFGfBaya28ebVtmL0XAYHraZPhfn/4kbBvo3xswKkat0c55 crVi3P5/ChEOsYW1soszMzfi6ti/S3rAdtxaatietH6L0CEziXnEChuwd/kntoenPV/5 5CvsG1W3T5x9Q5/WekURl1mQJjq+o00H1rloi8mDd2aidUFzf9CfpZYHmGc+Tb1IDU7h cAVpJHusWveK25mMTayRkkzYP2ckeLTy3HmOWUpIsZaIKadqvLcbiwbJ0zUc1sqpdaIW psmA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YmQAYLOd; 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 pc4-20020a05620a840400b00789f61e3e39si13510207qkn.74.2024.04.03.05.13.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 05:13:43 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-bounces+patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YmQAYLOd; 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 9C8B3384475D for ; Wed, 3 Apr 2024 12:13:43 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by sourceware.org (Postfix) with ESMTPS id 1BB69384640D for ; Wed, 3 Apr 2024 12:12:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1BB69384640D 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 1BB69384640D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1029 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712146338; cv=none; b=gYnbCOPvkNElUGgfRq0HV5csDEZAdSHO1ND8wMWmasiRT3TCYTFhe+vBIWQfCiGnT+vJCu5hGMe1hb0AsUo7Qu6AN91OzCEJDQfQWEYrJtjji7zHhJI9XwDZqrtdyZvjNC0X4Rnfy+baLLreil8FEfBv0D2Iy4qdx4nvS0ct8Ps= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712146338; c=relaxed/simple; bh=pTBS8UJ8xIbuv48fM//Cqy517Qa01Ep8u6I9kE9tSFA=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=hqvaDWXnVyLRsTG2Au7MaHP3PE25gtenlTCxfXECppbOn7B8jlNj0G+672Bw3/XTuTNQH2H99au2+RiJv1wb3qRe9CYp7qH1guUF4wktPRElPy2Lv8E8/TLJeoz4kvzj6RmVu84g1zbtjEN+emPHDAwaxyfCh32QJN7Nn183kx8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pj1-x1029.google.com with SMTP id 98e67ed59e1d1-2a2474f2595so2069548a91.1 for ; Wed, 03 Apr 2024 05:12:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712146331; x=1712751131; 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; bh=mcC9BT77771N8Eii2ZWnHojpfSkULVnusjkmQelNl8o=; b=YmQAYLOd3RijGtnSgBKsJgK2vhuOieuBV2fdXbg2uJDj/3WP+7QJRKrQfv55lbOGPm jS7+eYsDz74C7YXVHfGB4avyI7SxOi/+/l/Or/gLa3pU3ZAe3iXjAzpDwLTv0ikWCLsU X3LlyzuVzQpAE3MRTaeSoxqMRpOvdLYqnACTKvglGf7VtvtbTyDcbTXOTyMFHcGJ9Suu F5kq5tFEUTZxN+GGdlS2h1wNWHqAhkXTpWxdKUXQfjqXoKFeFZoRiQTnoiHUzVXterS7 SNdGlnyD6zwJkO4n1wt/BY4CQqHkVwjJZ0//xJg/YwCeDvUTsWgygLABvYK4nzVZcR/+ D6Eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712146331; x=1712751131; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mcC9BT77771N8Eii2ZWnHojpfSkULVnusjkmQelNl8o=; b=Qu3GvsI/qYiP9PBqKnTHyYo0E3xIdY2HcvziLyEegmbgGOLNT4PFJ++Pok44iYhhpn e6tB1wjs39QapL+Oaj9ClpueqFKsZ/ehS+LKq2RiWZCm8bCtoUd8Jdr0XLiSbM1c5QS2 J6BozZ9riMfvMFSrnFxaNVJTHKYO1Kee0rHEhLzsD3y3oe2tTlNn69v2fZ1mHwM/WToh WTKQ/cFuj3ga32Pal7yove32dJ/eTQJAmcNk1KHKKL3L52jFPRRh33X1qXG1+7BKmzAC s+Ejn78XGz+5Rz1+iSDYT0ZDnAWf8G2NZ1hf8TFQ5pp+UD1qhFk0BAcjq0tYY7Y59GSr hFZQ== X-Gm-Message-State: AOJu0YxKw8b4T0ynKMUO9nvDVZuAv0aYlA2hCk7+0nHLIjecClM4Ojdz aRXrWJYHIb9MGUmTCw9zWJgiij3HYrIpqKfodBYeipFwecQrSJKufi4qrrzJ+EFYXnVfCYw6TDN n X-Received: by 2002:a17:90a:bb89:b0:29b:307a:d5ed with SMTP id v9-20020a17090abb8900b0029b307ad5edmr2463967pjr.10.1712146331305; Wed, 03 Apr 2024 05:12:11 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c3:b18e:12db:8f9c:da5:36ce]) by smtp.gmail.com with ESMTPSA id q6-20020a17090a938600b0029ffcf1df72sm13574141pjo.38.2024.04.03.05.12.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 05:12:10 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: "H . J . Lu" Subject: [PATCH v2 10/10] i386: Do not raise inexact exception on trunc/truncf Date: Wed, 3 Apr 2024 09:11:50 -0300 Message-Id: <20240403121150.1018799-11-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240403121150.1018799-1-adhemerval.zanella@linaro.org> References: <20240403121150.1018799-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham 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 It is not allowed anymore on ISO C23. Checked on x86_64-linux-gnu and i686-linux-gnu. --- sysdeps/i386/fpu/{s_trunc.S => s_trunc.c} | 37 +++++++++++---------- sysdeps/i386/fpu/{s_truncf.S => s_truncf.c} | 37 +++++++++++---------- 2 files changed, 38 insertions(+), 36 deletions(-) rename sysdeps/i386/fpu/{s_trunc.S => s_trunc.c} (61%) rename sysdeps/i386/fpu/{s_truncf.S => s_truncf.c} (61%) diff --git a/sysdeps/i386/fpu/s_trunc.S b/sysdeps/i386/fpu/s_trunc.c similarity index 61% rename from sysdeps/i386/fpu/s_trunc.S rename to sysdeps/i386/fpu/s_trunc.c index 40e45c9f9c..5880964499 100644 --- a/sysdeps/i386/fpu/s_trunc.S +++ b/sysdeps/i386/fpu/s_trunc.c @@ -1,5 +1,5 @@ -/* Truncate double value. - Copyright (C) 1997-2024 Free Software Foundation, Inc. +/* Round to integer, toward zero. i386 version. + Copyright (C) 2024 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 @@ -16,22 +16,23 @@ License along with the GNU C Library; if not, see . */ -#include +#define NO_MATH_REDIRECT +#include +#include #include -ENTRY(__trunc) - fldl 4(%esp) - subl $32, %esp - cfi_adjust_cfa_offset (32) - fnstenv 4(%esp) - movl $0xc00, %edx - orl 4(%esp), %edx - movl %edx, (%esp) - fldcw (%esp) - frndint - fldenv 4(%esp) - addl $32, %esp - cfi_adjust_cfa_offset (-32) - ret -END(__trunc) +double +__trunc (double x) +{ + fenv_t fenv; + double r; + + libc_feholdexcept_setround_387 (&fenv, FE_TOWARDZERO); + asm volatile ("frndint" : "=t" (r) : "0" (x)); + /* Preserve "invalid" exceptions from sNaN input. */ + fenv.__status_word |= libc_fetestexcept_387 (FE_INVALID); + libc_fesetenv_387 (&fenv); + + return r; +} libm_alias_double (__trunc, trunc) diff --git a/sysdeps/i386/fpu/s_truncf.S b/sysdeps/i386/fpu/s_truncf.c similarity index 61% rename from sysdeps/i386/fpu/s_truncf.S rename to sysdeps/i386/fpu/s_truncf.c index 0b26e09d61..037099024f 100644 --- a/sysdeps/i386/fpu/s_truncf.S +++ b/sysdeps/i386/fpu/s_truncf.c @@ -1,5 +1,5 @@ -/* Truncate float value. - Copyright (C) 1997-2024 Free Software Foundation, Inc. +/* Round to integer, toward zero. i386 version. + Copyright (C) 2024 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 @@ -16,22 +16,23 @@ License along with the GNU C Library; if not, see . */ -#include +#define NO_MATH_REDIRECT +#include +#include #include -ENTRY(__truncf) - flds 4(%esp) - subl $32, %esp - cfi_adjust_cfa_offset (32) - fnstenv 4(%esp) - movl $0xc00, %edx - orl 4(%esp), %edx - movl %edx, (%esp) - fldcw (%esp) - frndint - fldenv 4(%esp) - addl $32, %esp - cfi_adjust_cfa_offset (-32) - ret -END(__truncf) +float +__truncf (float x) +{ + fenv_t fenv; + float r; + + libc_feholdexcept_setround_387 (&fenv, FE_TOWARDZERO); + asm volatile ("frndint" : "=t" (r) : "0" (x)); + /* Preserve "invalid" exceptions from sNaN input. */ + fenv.__status_word |= libc_fetestexcept_387 (FE_INVALID); + libc_fesetenv_387 (&fenv); + + return r; +} libm_alias_float (__trunc, trunc)