From nobody Thu Oct 31 23:57:28 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1685197222; cv=none; d=zohomail.com; s=zohoarc; b=UdWOIkykiW3C7+olvHabazG+L2rgktmMQz8ntWmC1Q4MfAAEOuypyrSKN2ekSqxrkbJ0L/5hl3HVAaHpacbNmexnh3nbqiZ1rj7jvvQkwu/ZTa7RT6FCpj5pu8fsPnBW38gEaii63lkgAwH1t4d66bm0VX50pqBerMeMIUP/7sc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685197222; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=DDbFBgISj2NEyBK0D5B4JQEN40ApYglGb4D217KNjVU=; b=ADv61Uwz9I7AR6OoY1AS191VzK2uNtZUZtvQp15FcDJAXi1Icihl8aFyIcrxR8ldClupJlvJInsG73Hzod5pbkBUI2grC8CkNtVO5n3zyHfqZQdzmjV4FAF1iPuHdutsLfBUSO4GVj82Qml7HdDBa2PXlwfqnb0XEdGB745Oz+E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1685197222757396.7362950786119; Sat, 27 May 2023 07:20:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q2ulJ-0007o1-9R; Sat, 27 May 2023 10:19:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q2ulI-0007ng-7g for qemu-devel@nongnu.org; Sat, 27 May 2023 10:19:16 -0400 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q2ulG-0002GC-Id for qemu-devel@nongnu.org; Sat, 27 May 2023 10:19:16 -0400 Received: by mail-pj1-x102a.google.com with SMTP id 98e67ed59e1d1-256481ce1b5so430175a91.1 for ; Sat, 27 May 2023 07:19:14 -0700 (PDT) Received: from stoup.. ([2602:ae:1598:4c01:be31:c162:a57e:7431]) by smtp.gmail.com with ESMTPSA id j20-20020a170902759400b001a988a71617sm1258992pll.192.2023.05.27.07.19.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 May 2023 07:19:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1685197153; x=1687789153; 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=DDbFBgISj2NEyBK0D5B4JQEN40ApYglGb4D217KNjVU=; b=DCD0ru6fPCyggh9ahSI/GdOAxD46vY7QCkaJACsvPwC5QppfTrz5GjRmEoVo40edU2 YfFMChM3UlkwHHwVbe/cxOEGuF7zDpLGBpXNgnyLukz1bziN0QGU9JgOgk8AaAjFhkAN Jd8QKLUlOB7jzhi9pomUP3GFyk0taoNzA3fwUOEWSWPE+LKGiLmqd4LKZu6DeVo/qCYk +n4B/ukz83UbjzBfR8J67/7h0qE59QuM3yHsrm6+h8TgYdcHbljEXmXkkyYCkq6tFyPK 3Az0YZjXRlWfXOzJuGDGQa3s6Sp58iyL2cXDKqwZklHw9aW1idZvsuBO09UQ68So09i5 1WHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685197153; x=1687789153; 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=DDbFBgISj2NEyBK0D5B4JQEN40ApYglGb4D217KNjVU=; b=gCzNUO+FEqkYBvindUPOIGWj7jSOo2lR6tctgOo2oDixeWMxGr9NRrlbd6DEmywiJz kdrpFQBx2q8+zdj5cLrynNFi8omDKyMQ60N/Hi+PEz6MwoT9kIy30g7b1EWHaobWH+W5 DUpV5lw0+aN8C05428/yvzL9WpA7md5m681xzh50eH25D0YhoEl/smoUBYVrG/PFLUdR Nb6rtK0qGX1tjfXbenURz20jagIJjNhS3+pD8FvjH8u7hUvvo1jWutc9scTurIx7jaeN Qj9lsJUpQqf8pSxiz88vPUmW/LI0UXEVUIkm0nUwrB7Dy5ywsgzZzl6B4lmUQa6kNjSa vUWw== X-Gm-Message-State: AC+VfDxC7/TYT9Yz2M+ydftBJSlyXm7yUgqMtRbRS5raO0h3rVc8txV7 UFEtczhUAkJSxcgf5ZK6bj/T/IQ2AN58V3RQ4BM= X-Google-Smtp-Source: ACHHUZ4Ek5Sd0iNyaOE1tVN9NY9mSUIzq3wIFvBS50nWQExksYN11+tA5vcaTewmS3C4wOm401kyrg== X-Received: by 2002:a17:902:e884:b0:1ae:1237:874d with SMTP id w4-20020a170902e88400b001ae1237874dmr5890752plg.69.1685197152924; Sat, 27 May 2023 07:19:12 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: christoph.muellner@vrull.eu, alex.bennee@linaro.org Subject: [PATCH 1/4] fpu: Add float64_to_int{32,64}_modulo Date: Sat, 27 May 2023 07:19:07 -0700 Message-Id: <20230527141910.1885950-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230527141910.1885950-1-richard.henderson@linaro.org> References: <20230527141910.1885950-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102a; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1685197223796100007 Content-Type: text/plain; charset="utf-8" Add versions of float64_to_int* which do not saturate the result. Signed-off-by: Richard Henderson Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Christoph Muellner Tested-by: Christoph Muellner --- include/fpu/softfloat.h | 3 ++ fpu/softfloat.c | 31 ++++++++++++++++ fpu/softfloat-parts.c.inc | 78 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 112 insertions(+) diff --git a/include/fpu/softfloat.h b/include/fpu/softfloat.h index 3dcf20e3a2..cd130564d8 100644 --- a/include/fpu/softfloat.h +++ b/include/fpu/softfloat.h @@ -751,6 +751,9 @@ int16_t float64_to_int16_round_to_zero(float64, float_s= tatus *status); int32_t float64_to_int32_round_to_zero(float64, float_status *status); int64_t float64_to_int64_round_to_zero(float64, float_status *status); =20 +int32_t float64_to_int32_modulo(float64, FloatRoundMode, float_status *sta= tus); +int64_t float64_to_int64_modulo(float64, FloatRoundMode, float_status *sta= tus); + uint16_t float64_to_uint16_scalbn(float64, FloatRoundMode, int, float_stat= us *); uint32_t float64_to_uint32_scalbn(float64, FloatRoundMode, int, float_stat= us *); uint64_t float64_to_uint64_scalbn(float64, FloatRoundMode, int, float_stat= us *); diff --git a/fpu/softfloat.c b/fpu/softfloat.c index 108f9cb224..c05819afcd 100644 --- a/fpu/softfloat.c +++ b/fpu/softfloat.c @@ -852,11 +852,24 @@ static uint64_t parts128_float_to_uint(FloatParts128 = *p, FloatRoundMode rmode, #define parts_float_to_uint(P, R, Z, M, S) \ PARTS_GENERIC_64_128(float_to_uint, P)(P, R, Z, M, S) =20 +static int64_t parts64_float_to_sint_modulo(FloatParts64 *p, + FloatRoundMode rmode, + int bitsm1, float_status *s); +static int64_t parts128_float_to_sint_modulo(FloatParts128 *p, + FloatRoundMode rmode, + int bitsm1, float_status *s); + +#define parts_float_to_sint_modulo(P, R, M, S) \ + PARTS_GENERIC_64_128(float_to_sint_modulo, P)(P, R, M, S) + static void parts64_sint_to_float(FloatParts64 *p, int64_t a, int scale, float_status *s); static void parts128_sint_to_float(FloatParts128 *p, int64_t a, int scale, float_status *s); =20 +#define parts_float_to_sint(P, R, Z, MN, MX, S) \ + PARTS_GENERIC_64_128(float_to_sint, P)(P, R, Z, MN, MX, S) + #define parts_sint_to_float(P, I, Z, S) \ PARTS_GENERIC_64_128(sint_to_float, P)(P, I, Z, S) =20 @@ -3409,6 +3422,24 @@ int64_t bfloat16_to_int64_round_to_zero(bfloat16 a, = float_status *s) return bfloat16_to_int64_scalbn(a, float_round_to_zero, 0, s); } =20 +int32_t float64_to_int32_modulo(float64 a, FloatRoundMode rmode, + float_status *s) +{ + FloatParts64 p; + + float64_unpack_canonical(&p, a, s); + return parts_float_to_sint_modulo(&p, rmode, 31, s); +} + +int64_t float64_to_int64_modulo(float64 a, FloatRoundMode rmode, + float_status *s) +{ + FloatParts64 p; + + float64_unpack_canonical(&p, a, s); + return parts_float_to_sint_modulo(&p, rmode, 63, s); +} + /* * Floating-point to unsigned integer conversions */ diff --git a/fpu/softfloat-parts.c.inc b/fpu/softfloat-parts.c.inc index 247400031c..527e15e6ab 100644 --- a/fpu/softfloat-parts.c.inc +++ b/fpu/softfloat-parts.c.inc @@ -1181,6 +1181,84 @@ static uint64_t partsN(float_to_uint)(FloatPartsN *p= , FloatRoundMode rmode, return r; } =20 +/* + * Like partsN(float_to_sint), except do not saturate the result. + * Instead, return the rounded unbounded precision two's compliment result, + * modulo 2**(bitsm1 + 1). + */ +static int64_t partsN(float_to_sint_modulo)(FloatPartsN *p, + FloatRoundMode rmode, + int bitsm1, float_status *s) +{ + int flags =3D 0; + uint64_t r; + bool overflow =3D false; + + switch (p->cls) { + case float_class_snan: + flags |=3D float_flag_invalid_snan; + /* fall through */ + case float_class_qnan: + flags |=3D float_flag_invalid; + r =3D 0; + break; + + case float_class_inf: + overflow =3D true; + r =3D 0; + break; + + case float_class_zero: + return 0; + + case float_class_normal: + /* TODO: N - 2 is frac_size for rounding; could use input fmt. */ + if (parts_round_to_int_normal(p, rmode, 0, N - 2)) { + flags =3D float_flag_inexact; + } + + if (p->exp <=3D DECOMPOSED_BINARY_POINT) { + /* + * Because we rounded to integral, and exp < 64, + * we know frac_low is zero. + */ + r =3D p->frac_hi >> (DECOMPOSED_BINARY_POINT - p->exp); + if (p->exp < bitsm1) { + /* Result in range. */ + } else if (p->exp =3D=3D bitsm1) { + /* The only in-range value is INT_MIN. */ + overflow =3D !p->sign || p->frac_hi !=3D DECOMPOSED_IMPLIC= IT_BIT; + } else { + overflow =3D true; + } + } else { + /* Overflow, but there might still be bits to return. */ + int shl =3D p->exp - DECOMPOSED_BINARY_POINT; + if (shl < N) { + frac_shl(p, shl); + r =3D p->frac_hi; + } else { + r =3D 0; + } + overflow =3D true; + } + + if (p->sign) { + r =3D -r; + } + break; + + default: + g_assert_not_reached(); + } + + if (overflow) { + flags =3D float_flag_invalid | float_flag_invalid_cvti; + } + float_raise(flags, s); + return r; +} + /* * Integer to float conversions * --=20 2.34.1 From nobody Thu Oct 31 23:57:28 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1685197221; cv=none; d=zohomail.com; s=zohoarc; b=bxX9t9Wf3RKTALYdNZqiZvt9qQPKd8i8emHAzAWcdkClTsuzLGB3K0b9a6lPLRyxYDddsxNfuXbNAZw7PpKEMm8ZoPzmh7CDi9SzY6p3htJik1u7edDLN6seMoq+NHP5c3av7AMkgRaBrBjhz/q1MrM13f95EUsTvPLe20Ecmi8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685197221; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2PeQwKwKV8qp9CY2VpKZ0tpDcxwU9A3roabUSRDXyns=; b=hHobj83dtpE8kWK4NWXHjaVYPXTJ/ek7xlVVSeK/TFqLSeTJuya59Q5nSVJnUKjBU6Hms20SogFO2TmbnJ+1kDMWN17uIhmpXWJAFAHTwZ93qCK7pmPIl1Yo0eXRYSRunnCCJETDAqDEAUTI+hmeIkhavSykoBOG6fVZj8JM820= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1685197221570199.38886041246099; Sat, 27 May 2023 07:20:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q2ulN-0007op-Cx; Sat, 27 May 2023 10:19:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q2ulJ-0007ns-1F for qemu-devel@nongnu.org; Sat, 27 May 2023 10:19:17 -0400 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q2ulH-0002GJ-AP for qemu-devel@nongnu.org; Sat, 27 May 2023 10:19:16 -0400 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1b01d3bb571so7741795ad.2 for ; Sat, 27 May 2023 07:19:14 -0700 (PDT) Received: from stoup.. ([2602:ae:1598:4c01:be31:c162:a57e:7431]) by smtp.gmail.com with ESMTPSA id j20-20020a170902759400b001a988a71617sm1258992pll.192.2023.05.27.07.19.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 May 2023 07:19:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1685197153; x=1687789153; 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=2PeQwKwKV8qp9CY2VpKZ0tpDcxwU9A3roabUSRDXyns=; b=CN5yD7Rm0sCYOj9kDa1dcUyVRp6zz8NaTKZWfzIyGTpbxaXZlVhN6VU2/hR9ASDtjv J3XNU52c89hcaeL2ZViidb5EzHcahp3D7Lm/hHZYCr3VFbuz4yCgG4CSu9ueFMGTmHjK IhuxojQp3lH3fs1N2OboqeI1OkW8jAN1uvM7dCxiVl9gqzE9HFrf164sqpXrvBSdS65C KZ2r5n1/vkugZuDY1cAK+hJ8dkfF/W6sDsDVdJSlk3zpjz9IwHnGwchdRPHqevWTbUJw QuGUC1wRvwQeiVDkkoWcHWs/P/BFFuWJCGKz/qZncLnbfUI41rYqc3PzG559fhL5L3g/ q6vA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685197153; x=1687789153; 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=2PeQwKwKV8qp9CY2VpKZ0tpDcxwU9A3roabUSRDXyns=; b=PulTmdEvV88TwhD0gcBcKrkr8NQCnH80prtl4ZfkVLm9sADnVrUahgQ15FU8iavq64 3D2qbUEHJf3rdlr9OjEpiRbLe3378l0KallYsXAt/k8ZopbsIQAaj+Veia8FuxGtSLmv f+G418xa6Pm8uiuQD0g7VRHT02WmG0+bhljExYAQkqF2MuTVGKGTjymAh5WTnJZNZy0Q 0uUS0SY86PnH6HdqWxr+2flqBG85Lxs4SEAF0ibFq798CdPOda8DtrzqH/HNmgr/sPzN DSnOE5HCt/ftbgBOO7obKjHU1SBmXZKelSoMYg7LtsWgZl6WiCp4IKNzZroiq7z+wAXH 6Zaw== X-Gm-Message-State: AC+VfDyfr+fU7djtUNNRiSaTJPTRnozMVgZbyijGXaCCkizLtkgBRiyo HVOWavLxd8EYmClkNl/auRZogNna6quF7dq51Yw= X-Google-Smtp-Source: ACHHUZ55stOFPq8971z+0yqTR2WN42ij8wud05MhmKA3akDAYzpn5jdpDA7mQjNhl6Ue1R5aNOpwjQ== X-Received: by 2002:a17:902:ce8b:b0:1af:c602:cd52 with SMTP id f11-20020a170902ce8b00b001afc602cd52mr6756596plg.67.1685197153632; Sat, 27 May 2023 07:19:13 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: christoph.muellner@vrull.eu, alex.bennee@linaro.org Subject: [PATCH 2/4] tests/tcg/alpha: Add test for cvttq Date: Sat, 27 May 2023 07:19:08 -0700 Message-Id: <20230527141910.1885950-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230527141910.1885950-1-richard.henderson@linaro.org> References: <20230527141910.1885950-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x631.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1685197222860100001 Content-Type: text/plain; charset="utf-8" Test for invalid, integer overflow, and inexact. Test for proper result, modulo 2**64. Signed-off-by: Richard Henderson Acked-by: Alex Benn=C3=A9e Reviewed-by: Christoph Muellner Tested-by: Christoph Muellner --- tests/tcg/alpha/test-cvttq.c | 78 +++++++++++++++++++++++++++++++++ tests/tcg/alpha/Makefile.target | 2 +- 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 tests/tcg/alpha/test-cvttq.c diff --git a/tests/tcg/alpha/test-cvttq.c b/tests/tcg/alpha/test-cvttq.c new file mode 100644 index 0000000000..d1ad995312 --- /dev/null +++ b/tests/tcg/alpha/test-cvttq.c @@ -0,0 +1,78 @@ +#include + +#define FPCR_SUM (1UL << 63) +#define FPCR_INED (1UL << 62) +#define FPCR_UNFD (1UL << 61) +#define FPCR_UNDZ (1UL << 60) +#define FPCR_DYN_SHIFT 58 +#define FPCR_DYN_CHOPPED (0UL << FPCR_DYN_SHIFT) +#define FPCR_DYN_MINUS (1UL << FPCR_DYN_SHIFT) +#define FPCR_DYN_NORMAL (2UL << FPCR_DYN_SHIFT) +#define FPCR_DYN_PLUS (3UL << FPCR_DYN_SHIFT) +#define FPCR_DYN_MASK (3UL << FPCR_DYN_SHIFT) +#define FPCR_IOV (1UL << 57) +#define FPCR_INE (1UL << 56) +#define FPCR_UNF (1UL << 55) +#define FPCR_OVF (1UL << 54) +#define FPCR_DZE (1UL << 53) +#define FPCR_INV (1UL << 52) +#define FPCR_OVFD (1UL << 51) +#define FPCR_DZED (1UL << 50) +#define FPCR_INVD (1UL << 49) +#define FPCR_DNZ (1UL << 48) +#define FPCR_DNOD (1UL << 47) +#define FPCR_STATUS_MASK (FPCR_IOV | FPCR_INE | FPCR_UNF \ + | FPCR_OVF | FPCR_DZE | FPCR_INV) + +static long test_cvttq(long *ret_e, double d) +{ + unsigned long reset =3D (FPCR_INED | FPCR_UNFD | FPCR_OVFD | FPCR_DZED= | + FPCR_INVD | FPCR_DYN_NORMAL); + long r, e; + + asm("excb\n\t" + "mt_fpcr %3\n\t" + "excb\n\t" + "cvttq/svic %2, %0\n\t" + "excb\n\t" + "mf_fpcr %1\n\t" + "excb\n\t" + : "=3Df"(r), "=3Df"(e) + : "f"(d), "f"(reset)); + + *ret_e =3D e & FPCR_STATUS_MASK; + return r; +} + +int main (void) +{ + static const struct { + double d; + long r; + long e; + } T[] =3D { + { 1.0, 1, 0 }, + { -1.0, -1, 0 }, + { 1.5, 1, FPCR_INE }, + { 0x1.0p32, 0x0000000100000000ul, 0 }, + { -0x1.0p63, 0x8000000000000000ul, 0 }, + { 0x1.0p63, 0x8000000000000000ul, FPCR_IOV | FPCR_INE }, + { 0x1.0p64, 0x0000000000000000ul, FPCR_IOV | FPCR_INE }, + { 0x1.cccp64, 0xccc0000000000000ul, FPCR_IOV | FPCR_INE }, + { __builtin_inf(), 0, FPCR_INV }, + { __builtin_nan(""), 0, FPCR_INV }, + }; + + int i, err =3D 0; + + for (i =3D 0; i < sizeof(T)/sizeof(T[0]); i++) { + long e, r =3D test_cvttq(&e, T[i].d); + + if (r !=3D T[i].r || e !=3D T[i].e) { + printf("Fail %a: expect (%016lx : %04lx) got (%016lx : %04lx)\= n", + T[i].d, T[i].r, T[i].e >> 48, r, e >> 48); + err =3D 1; + } + } + return err; +} diff --git a/tests/tcg/alpha/Makefile.target b/tests/tcg/alpha/Makefile.tar= get index a585080328..b94500a7d9 100644 --- a/tests/tcg/alpha/Makefile.target +++ b/tests/tcg/alpha/Makefile.target @@ -5,7 +5,7 @@ ALPHA_SRC=3D$(SRC_PATH)/tests/tcg/alpha VPATH+=3D$(ALPHA_SRC) =20 -ALPHA_TESTS=3Dhello-alpha test-cond test-cmov test-ovf +ALPHA_TESTS=3Dhello-alpha test-cond test-cmov test-ovf test-cvttq TESTS+=3D$(ALPHA_TESTS) =20 test-cmov: EXTRA_CFLAGS=3D-DTEST_CMOV --=20 2.34.1 From nobody Thu Oct 31 23:57:28 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1685197243; cv=none; d=zohomail.com; s=zohoarc; b=liyCY9CArSktNMSVhycVcp+jWXsGH8wf6BY96X8QjGltDYnx0t8y+i5A0NOmMxqaL+6JvF11C7ppi+UKL9/JgdhBkPbMqCILap978BRm2zj1hGqOUWXFf9BvQ+VUIMoKy1WAFsEecFTBwZC5lQ9p+DX4ozjpmx/htk2nsvBFTQU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685197243; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=u+CMDJ9rmMCJWN+tP1xmh2RBmH8yQeZ+BBhiYDZHw0M=; b=asLeCOmPmnEMIEovV4lYPwpXYqEDELWihvZg+UMzy9bJlB3J3fXqgJTxFSgW9UU5K2C57p9g171XXvWzgB5K1txNwg3nEjx731ARPuf2BdY5ngdtxCssOr75kdvyrhQDqSF45boUKaJg0TYcAGQxK3n9mVCRhIOE4QfDgCfQHgQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1685197243214814.3114816629928; Sat, 27 May 2023 07:20:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q2ulN-0007p5-L7; Sat, 27 May 2023 10:19:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q2ulJ-0007oN-ID for qemu-devel@nongnu.org; Sat, 27 May 2023 10:19:17 -0400 Received: from mail-pg1-x52e.google.com ([2607:f8b0:4864:20::52e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q2ulH-0002GT-Ls for qemu-devel@nongnu.org; Sat, 27 May 2023 10:19:17 -0400 Received: by mail-pg1-x52e.google.com with SMTP id 41be03b00d2f7-52cb8e5e9f5so1224644a12.0 for ; Sat, 27 May 2023 07:19:15 -0700 (PDT) Received: from stoup.. ([2602:ae:1598:4c01:be31:c162:a57e:7431]) by smtp.gmail.com with ESMTPSA id j20-20020a170902759400b001a988a71617sm1258992pll.192.2023.05.27.07.19.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 May 2023 07:19:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1685197154; x=1687789154; 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=u+CMDJ9rmMCJWN+tP1xmh2RBmH8yQeZ+BBhiYDZHw0M=; b=XVTQgssaL6/74jC50WNAmA023RVUrK/7NYajgEtuuVpcUiPtcI4wLpAJi9z1CGn9Fr MZXOMN8yCGv4uNeVTpVAjS2JovywqO6UGPVskH6iH8noEsxUuNFzAWj0AME9iTjsSwNQ JABKtnl/P/odVrQUwRcN+2dN5NGWlDAHYqSvktmiFrBibxK+AmW8yUdbw3ppLMYeAi5F CLIWLIGXDuYJlT1qKmGNELI61T5dI0JBFiTHJPzUOWIrjsQDqrfI1fX/eyaDee6e+7Xh NVx/1VKml/fgNK9RzROi7EGHoFVs6SGaGfY6RK8ZRMsb2l5ZLGaKWrdyeBvnfe1EZBDb ingw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685197154; x=1687789154; 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=u+CMDJ9rmMCJWN+tP1xmh2RBmH8yQeZ+BBhiYDZHw0M=; b=Bigr2ZdraL0ESl+McLpwmpQHQzDkRZZqxiO2pR0ijszfSt5TFoIaMGkt4LupylQNV9 DGH0O6N7NjbEygQ3coyqIvUMEbSUd8GbukD4fy0hfK7oCngarJ9bDklV8piLgwuw82Ml Rep5mNdFqxZhUaaMDZdMxku+pFREGRXqITFwntfcN/C1TrOPa4KMQt+WE/zJxA/nWqX7 BU3QwGI3sbGF37W6PjIBflOnlpvf9HqLUQUmnfdlaMDl0D0Lftk/dJcwY3Z5W3P0aIjh QQ/SoL+XBH5eho7NDjrhrzGx11OH9/g6g9iUFy/hUf/MmKZ4mEDdGbof8HwegAwzn4sQ d2yg== X-Gm-Message-State: AC+VfDwBWxE4/nkzhdNnfc/5t8pxgi3Rnl88zFhZ2P29XDBn5oFrtvUN zMTZXzdRHAsptNyxL+AXnzjMd5TjrpyYq+hOjBA= X-Google-Smtp-Source: ACHHUZ5N09oDA2RVtWir1JRxC+ljpnnN/NeLl0avt0ln6jxCSTWvdh0zET6YpcZjzZkDVDbW5QmeSw== X-Received: by 2002:a17:902:d4ce:b0:1b0:34d5:1bc7 with SMTP id o14-20020a170902d4ce00b001b034d51bc7mr204687plg.20.1685197154469; Sat, 27 May 2023 07:19:14 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: christoph.muellner@vrull.eu, alex.bennee@linaro.org Subject: [PATCH 3/4] target/alpha: Use float64_to_int64_modulo for CVTTQ Date: Sat, 27 May 2023 07:19:09 -0700 Message-Id: <20230527141910.1885950-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230527141910.1885950-1-richard.henderson@linaro.org> References: <20230527141910.1885950-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::52e; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1685197244792100001 Content-Type: text/plain; charset="utf-8" For the most part we can use the new generic routine, though exceptions need some post-processing to sort invalid from integer overflow. Signed-off-by: Richard Henderson Reviewed-by: Christoph Muellner Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Christoph Muellner --- target/alpha/fpu_helper.c | 85 +++++++++------------------------------ 1 file changed, 18 insertions(+), 67 deletions(-) diff --git a/target/alpha/fpu_helper.c b/target/alpha/fpu_helper.c index 3ff8bb456d..63d9e9ce39 100644 --- a/target/alpha/fpu_helper.c +++ b/target/alpha/fpu_helper.c @@ -453,78 +453,29 @@ uint64_t helper_cvtqs(CPUAlphaState *env, uint64_t a) =20 static uint64_t do_cvttq(CPUAlphaState *env, uint64_t a, int roundmode) { - uint64_t frac, ret =3D 0; - uint32_t exp, sign, exc =3D 0; - int shift; + float64 fa; + int64_t ret; + uint32_t exc; =20 - sign =3D (a >> 63); - exp =3D (uint32_t)(a >> 52) & 0x7ff; - frac =3D a & 0xfffffffffffffull; + fa =3D t_to_float64(a); + ret =3D float64_to_int64_modulo(fa, roundmode, &FP_STATUS); =20 - if (exp =3D=3D 0) { - if (unlikely(frac !=3D 0) && !env->fp_status.flush_inputs_to_zero)= { - goto do_underflow; - } - } else if (exp =3D=3D 0x7ff) { - exc =3D FPCR_INV; - } else { - /* Restore implicit bit. */ - frac |=3D 0x10000000000000ull; + exc =3D get_float_exception_flags(&FP_STATUS); + if (unlikely(exc)) { + set_float_exception_flags(0, &FP_STATUS); =20 - shift =3D exp - 1023 - 52; - if (shift >=3D 0) { - /* In this case the number is so large that we must shift - the fraction left. There is no rounding to do. */ - if (shift < 64) { - ret =3D frac << shift; - } - /* Check for overflow. Note the special case of -0x1p63. */ - if (shift >=3D 11 && a !=3D 0xC3E0000000000000ull) { + /* We need to massage the resulting exceptions. */ + if (exc & float_flag_invalid_cvti) { + /* Overflow, either normal or infinity. */ + if (float64_is_infinity(fa)) { + exc =3D FPCR_INV; + } else { exc =3D FPCR_IOV | FPCR_INE; } - } else { - uint64_t round; - - /* In this case the number is smaller than the fraction as - represented by the 52 bit number. Here we must think - about rounding the result. Handle this by shifting the - fractional part of the number into the high bits of ROUND. - This will let us efficiently handle round-to-nearest. */ - shift =3D -shift; - if (shift < 63) { - ret =3D frac >> shift; - round =3D frac << (64 - shift); - } else { - /* The exponent is so small we shift out everything. - Leave a sticky bit for proper rounding below. */ - do_underflow: - round =3D 1; - } - - if (round) { - exc =3D FPCR_INE; - switch (roundmode) { - case float_round_nearest_even: - if (round =3D=3D (1ull << 63)) { - /* Fraction is exactly 0.5; round to even. */ - ret +=3D (ret & 1); - } else if (round > (1ull << 63)) { - ret +=3D 1; - } - break; - case float_round_to_zero: - break; - case float_round_up: - ret +=3D 1 - sign; - break; - case float_round_down: - ret +=3D sign; - break; - } - } - } - if (sign) { - ret =3D -ret; + } else if (exc & float_flag_invalid) { + exc =3D FPCR_INV; + } else if (exc & float_flag_inexact) { + exc =3D FPCR_INE; } } env->error_code =3D exc; --=20 2.34.1 From nobody Thu Oct 31 23:57:28 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1685197222; cv=none; d=zohomail.com; s=zohoarc; b=k46/1V3jpsFDdRJji9rwvOnaxyTXhinEgfBnOgjwFya/5fdw5yTJx31jm0ZDJpkfPiqvXFrPnpicfNGGaSAp8+ug87QFqeHzfcrtZyt0p76lSBm6e5LanmPUHWRKUKqWD0Qn7gLe2F8GBHrk8I5kY6tcI9ExHkCXoZAR1kpD19Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685197222; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=4Ci3Rw1Bwfq/vRMH6eDy4QVIqFnQy7Z61D8fU9qGASA=; b=bElxVHbnVlEjv+bqoIaHCW+Gxmjf7tQEqAieZJWGcqZlndHh1QpD826ILLeirSvBGYpbuJO7lZMUv63zufeVAbpY4rY9Xs2ryo/eAEB3V2785ZdF+jHO1JYwqcs/nsy/CVD/C9jBjAxd9ssO5oNQT7IxAPgdQp6hHwQajN1tjiI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1685197222705923.1640445794837; Sat, 27 May 2023 07:20:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q2ulO-0007pC-7L; Sat, 27 May 2023 10:19:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q2ulK-0007og-EM for qemu-devel@nongnu.org; Sat, 27 May 2023 10:19:19 -0400 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q2ulI-0002Gg-Ng for qemu-devel@nongnu.org; Sat, 27 May 2023 10:19:18 -0400 Received: by mail-pj1-x102a.google.com with SMTP id 98e67ed59e1d1-2564b0921f1so304152a91.3 for ; Sat, 27 May 2023 07:19:16 -0700 (PDT) Received: from stoup.. ([2602:ae:1598:4c01:be31:c162:a57e:7431]) by smtp.gmail.com with ESMTPSA id j20-20020a170902759400b001a988a71617sm1258992pll.192.2023.05.27.07.19.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 May 2023 07:19:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1685197155; x=1687789155; 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=4Ci3Rw1Bwfq/vRMH6eDy4QVIqFnQy7Z61D8fU9qGASA=; b=opHnNvlK67U5GEiwnV5AJmHAEhCy0zfcc8EfjaiERh3+sewTukAAu828PJeaJ4fUxw zYV09YDgXxUQ8sQ68bJqoU/ytHJiz7XUD+fNQu4245Xm15T9fEO7UuLFlEBgrtCRc4Ml mHEpKvSAOR+QMW1DxWV69nI7PkFrknE8+0uIflibGmvKZG/zKoowRBA227W6C6kETtbq VU9EbQN6MqMwJV/2XheekZYK/+ktVpay+TANl0mMHsxxskaQwE1etyc6WwjKViAzOUJK GWYJopMdXXeajGBQ+pV+vLfx3go3BSk+l/xqyHGEHnUCIGPuMEQbiGZneB1CW3Ldt/kH NPwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685197155; x=1687789155; 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=4Ci3Rw1Bwfq/vRMH6eDy4QVIqFnQy7Z61D8fU9qGASA=; b=afVjlmsWSHyoVPKL3gYde4XxUvLonOWnIQvhRxuFFE7E/zQOMEeyDRy6M+9YJGA2r/ hfCzCw77mcrfH+ekXukJ2pK7O6NxYOOsqFoex8qfJTPq7yRuVHcj+XMHme7MvtAb5Th+ RyxRnt82y+4hyHMYL2tSliBhrfnAH8MAFR6LEILXjESp/1EdCxkzx7OfPlrSXcq+70AM cUNL6XRRStyoVD2okQnMVGfaBNnaW4Q6lvqoMJHSk7FES7ippCjDAHAn6YIIqiBaNRhg Srqwd6cNuthEPpOXuO10FNaD3S9i+wK4h4acofbUnodx0y0wuDmWrV9xISktJCB3E2Q/ sGmg== X-Gm-Message-State: AC+VfDzi7GS8MxBtPD4TXcdmPHAYbipdJ77TmjZoOeCgqnPqhbUywyY/ Kl8PkeHWs1LawdnpKE90r+9orEOw5YeHBailRaY= X-Google-Smtp-Source: ACHHUZ5uVfZGpOYcdjj130ClUPZFaEU0SyYCoV4YKvtTuk2mB+A+19ET2W3v5GyBE3T10j+8BaKfYA== X-Received: by 2002:a17:902:ea0b:b0:1af:b3b6:4947 with SMTP id s11-20020a170902ea0b00b001afb3b64947mr7767551plg.24.1685197155272; Sat, 27 May 2023 07:19:15 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: christoph.muellner@vrull.eu, alex.bennee@linaro.org Subject: [PATCH 4/4] target/arm: Use float64_to_int32_modulo for FJCVTZS Date: Sat, 27 May 2023 07:19:10 -0700 Message-Id: <20230527141910.1885950-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230527141910.1885950-1-richard.henderson@linaro.org> References: <20230527141910.1885950-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102a; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1685197223136100005 Content-Type: text/plain; charset="utf-8" The standard floating point results are provided by the generic routine. We only need handle the extra Z flag result afterward. Signed-off-by: Richard Henderson Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Christoph Muellner Tested-by: Christoph Muellner --- target/arm/vfp_helper.c | 71 +++++++---------------------------------- 1 file changed, 12 insertions(+), 59 deletions(-) diff --git a/target/arm/vfp_helper.c b/target/arm/vfp_helper.c index 36906db8e0..789bba36cc 100644 --- a/target/arm/vfp_helper.c +++ b/target/arm/vfp_helper.c @@ -1120,68 +1120,21 @@ const FloatRoundMode arm_rmode_to_sf_map[] =3D { uint64_t HELPER(fjcvtzs)(float64 value, void *vstatus) { float_status *status =3D vstatus; - uint32_t exp, sign; - uint64_t frac; - uint32_t inexact =3D 1; /* !Z */ + uint32_t inexact, frac; + uint32_t e_old, e_new; =20 - sign =3D extract64(value, 63, 1); - exp =3D extract64(value, 52, 11); - frac =3D extract64(value, 0, 52); + e_old =3D get_float_exception_flags(status); + set_float_exception_flags(0, status); + frac =3D float64_to_int32_modulo(value, float_round_to_zero, status); + e_new =3D get_float_exception_flags(status); + set_float_exception_flags(e_old | e_new, status); =20 - if (exp =3D=3D 0) { - /* While not inexact for IEEE FP, -0.0 is inexact for JavaScript. = */ - inexact =3D sign; - if (frac !=3D 0) { - if (status->flush_inputs_to_zero) { - float_raise(float_flag_input_denormal, status); - } else { - float_raise(float_flag_inexact, status); - inexact =3D 1; - } - } - frac =3D 0; - } else if (exp =3D=3D 0x7ff) { - /* This operation raises Invalid for both NaN and overflow (Inf). = */ - float_raise(float_flag_invalid, status); - frac =3D 0; + if (value =3D=3D float64_chs(float64_zero)) { + /* While not inexact for IEEE FP, -0.0 is inexact for JavaScript. = */ + inexact =3D 1; } else { - int true_exp =3D exp - 1023; - int shift =3D true_exp - 52; - - /* Restore implicit bit. */ - frac |=3D 1ull << 52; - - /* Shift the fraction into place. */ - if (shift >=3D 0) { - /* The number is so large we must shift the fraction left. */ - if (shift >=3D 64) { - /* The fraction is shifted out entirely. */ - frac =3D 0; - } else { - frac <<=3D shift; - } - } else if (shift > -64) { - /* Normal case -- shift right and notice if bits shift out. */ - inexact =3D (frac << (64 + shift)) !=3D 0; - frac >>=3D -shift; - } else { - /* The fraction is shifted out entirely. */ - frac =3D 0; - } - - /* Notice overflow or inexact exceptions. */ - if (true_exp > 31 || frac > (sign ? 0x80000000ull : 0x7fffffff)) { - /* Overflow, for which this operation raises invalid. */ - float_raise(float_flag_invalid, status); - inexact =3D 1; - } else if (inexact) { - float_raise(float_flag_inexact, status); - } - - /* Honor the sign. */ - if (sign) { - frac =3D -frac; - } + /* Normal inexact or overflow or NaN */ + inexact =3D e_new & (float_flag_inexact | float_flag_invalid); } =20 /* Pack the result and the env->ZF representation of Z together. */ --=20 2.34.1