From patchwork Wed Apr 3 12:11:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 87979 Return-Path: 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 DF6B83846072 for ; Wed, 3 Apr 2024 12:14:29 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by sourceware.org (Postfix) with ESMTPS id D1F7D38460B2 for ; Wed, 3 Apr 2024 12:12:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D1F7D38460B2 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 D1F7D38460B2 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::534 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712146331; cv=none; b=KKbvVREGFkmjf8vP6GP5p46aJMZ433XKZjZuSKCHtkdbCO1+zUaiOZA5Z+itJabD/F1L8PlLAXHrvEbwtUV7AW1Q6SbfRONwLFft5KftEvgIbVFIj9JFj2VZi5MbZ5NwXxARj1yK+9AZ5Ib/pleVWhN9yH8VQv5/L2vS/X4/IHY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712146331; c=relaxed/simple; bh=18KWDqJOCvFGiKrMSa8OpXnOZjyCtOADkaYgH7zX9vo=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=Mz2f2ZU6EIIDBo01OiwzgS02xIux7t9sh4H7haEjj2c7+KRrB6y6h04P7kwFy1e18gBvHmgSlNps/4grM7+U1gGJNPM6p+jI0nOeJbyFRkDDZLkilwap9dVSjR/I3RaVlm74lbfBSom8JQD3xrz48W65bHA070hvDsvfdQBBg1U= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pg1-x534.google.com with SMTP id 41be03b00d2f7-5cddc5455aeso3976930a12.1 for ; Wed, 03 Apr 2024 05:12:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712146326; x=1712751126; 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=zlY9goMk06RobzKIAKJy3vjK/nrrQAIbI2heyFcTgXM=; b=zs0Jw7YWBa/RBCvgKVlhi0sOzbB0Egw9UKgRVBch4kZaiX1iFOR70RaXmKXTL1d3Ux lUXU5P+vg7GYTXL0eekq7BhuuSgQEwIjCwaN9B9Q4WSPPXuJ7bjkWoY7GsCGhzC+dtB6 KIPAsRU90/RGwPCE7P+wYqg17cZQOIu5M3IWerExQ2Rcu2FhAZir2zFKiVn+qTjcjaLR PQxfSwIPyX3UeXgg19SAHHOS1dK9LK7CtwD8P+7I6mqdJZbyfKf6mAj3DYmbEiOl/W1X /RLe2l4QK7H3j0r9Sv7HfmniNV+ClK55/7JS+VHvkIgfx6apLhvt35+AjYPJQJwWOMtz fSGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712146326; x=1712751126; 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=zlY9goMk06RobzKIAKJy3vjK/nrrQAIbI2heyFcTgXM=; b=s2c9iHwShECbCXdCCyEs4vVmN4LfSCyN09g9ekCIPpUnv4/xOTR6Uo59LS+nhD4ho4 QbGGiJK4tCQNPNtNAFP7iv4p1n551eyCX36+9p4kX/ZeLOrlXdGb2jvg4knT3qWeGfID VGM0GL8O4LDa4VJNFFABumOtwKTf3KYjrQob3bFlYL0Jxh9DbzpTAQ1C5bqn2WX2M8Z2 JRji+cumg08gVVcl2JYoFsdvo5kT6jHn5GHKNx5C4A2kJyq7T6n9oY1zaUvXsBrqOfil chL7PkFh+cv9ox0SAZCfelaTCJaKGui7/Hwv3dGHNk7cw5K7m+mSGam6AI4zZol6szO0 MT7A== X-Gm-Message-State: AOJu0YzAVEiKBosBcFal8GMoD24uzkLIlnYY+nl20+gAg0dPkfn3WEui 851riuqvVr0IxPdAqe21Q0OKC7ON0l0llpQ6oHCe6j1hFs5ccHz6dIUbLcUhkpIf4isXut8Ggpi f X-Google-Smtp-Source: AGHT+IFOoIfgqfyYM34boI3AdaT3GlgxmKdbt+PJaKbAJbNUqvsUkal0XPTA4AskvBTaM0j6Zeg2WQ== X-Received: by 2002:a17:90b:3b88:b0:2a2:2eee:e86e with SMTP id pc8-20020a17090b3b8800b002a22eeee86emr7991046pjb.2.1712146326424; Wed, 03 Apr 2024 05:12:06 -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.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 05:12:05 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: "H . J . Lu" Subject: [PATCH v2 07/10] x86: Do not raise inexact exception on truncl Date: Wed, 3 Apr 2024 09:11:47 -0300 Message-Id: <20240403121150.1018799-8-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.6 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+patchwork=sourceware.org@sourceware.org It is not allowed anymore on ISO C23. Checked on x86_64-linux-gnu and i686-linux-gnu. --- .../fpu/s_truncl.S => x86/fpu/s_truncl.c} | 40 +++++++++---------- sysdeps/x86_64/fpu/s_truncl.S | 36 ----------------- 2 files changed, 19 insertions(+), 57 deletions(-) rename sysdeps/{i386/fpu/s_truncl.S => x86/fpu/s_truncl.c} (61%) delete mode 100644 sysdeps/x86_64/fpu/s_truncl.S diff --git a/sysdeps/i386/fpu/s_truncl.S b/sysdeps/x86/fpu/s_truncl.c similarity index 61% rename from sysdeps/i386/fpu/s_truncl.S rename to sysdeps/x86/fpu/s_truncl.c index dfd0ca4a57..59614cd006 100644 --- a/sysdeps/i386/fpu/s_truncl.S +++ b/sysdeps/x86/fpu/s_truncl.c @@ -1,5 +1,5 @@ -/* Truncate long double value. - Copyright (C) 1997-2024 Free Software Foundation, Inc. +/* Round to integer, toward zero. x86 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,25 +16,23 @@ License along with the GNU C Library; if not, see . */ +#define NO_MATH_REDIRECT +#include +#include #include -#include -ENTRY(__truncl) - fldt 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 - fnstsw - andl $0x1, %eax - orl %eax, 8(%esp) - fldenv 4(%esp) - addl $32, %esp - cfi_adjust_cfa_offset (-32) - ret -END(__truncl) +long double +__truncl (long double x) +{ + fenv_t fenv; + long 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_ldouble (__trunc, trunc) diff --git a/sysdeps/x86_64/fpu/s_truncl.S b/sysdeps/x86_64/fpu/s_truncl.S deleted file mode 100644 index e3d64a84e8..0000000000 --- a/sysdeps/x86_64/fpu/s_truncl.S +++ /dev/null @@ -1,36 +0,0 @@ -/* Truncate long double value. - Copyright (C) 1997-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 - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include - -ENTRY(__truncl) - fldt 8(%rsp) - fnstenv -28(%rsp) - movl $0xc00, %edx - orl -28(%rsp), %edx - movl %edx, -32(%rsp) - fldcw -32(%rsp) - frndint - fnstsw - andl $0x1, %eax - orl %eax, -24(%rsp) - fldenv -28(%rsp) - ret -END(__truncl) -libm_alias_ldouble (__trunc, trunc)