From patchwork Sat May 27 14:19:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 686383 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp319877wrt; Sat, 27 May 2023 07:20:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5YF6i3d1bE/6M8/kVOjjnuCVUMBG1jQuWSxSgCJrSjNvwGOKW3QW0w7+QXIFfD9BMcq0DQ X-Received: by 2002:a05:620a:2a07:b0:75b:23a0:de93 with SMTP id o7-20020a05620a2a0700b0075b23a0de93mr2827040qkp.17.1685197221167; Sat, 27 May 2023 07:20:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685197221; cv=none; d=google.com; s=arc-20160816; b=iN0Xppsc/obFv6efSZkamPmnuHSOBjM1joKuo7QEiDawW7pvTIDhyIf6uO0RcKNgmO OKXTxAvn0Y++AEblhQy1Z04osb/Ave8RE6NsuXhhkWvwHmQnhl3bmr5eLKebR3adJEIt SqCU5LY5DzpU9hzCBKCtV/Qr7WvBtTY7Gc7tZMBUA96QuFzJrYMsFcp2DHzp2QWm6JyH ix9BVxvFgCKYQ6UvzSmX3nq5aIPOk29qOpzQveWJmJrqAGLuvhvqNRD/AcpXtvySYFOD MSciXU2m+3oclP9wUd3VmTCU2a7iYQEsvfdcfLQD5h/OZ6zKJH3oIeJL/5/Uf6Xi7Di2 LrPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender: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; bh=DDbFBgISj2NEyBK0D5B4JQEN40ApYglGb4D217KNjVU=; b=vuyjpHCz9AoMZKEpe6FLr6Y09h6BU9d6ENs/G7R2y7Q8pxixxljy0GkGWkSvH/Rh5g 2enP1WdoURbtoleHPcVPQ1Y+RlYbr6rt/qPK8108A/hnxNbq/6Q3tTvqlblmaQxbuUKW ZBUkdjTwSaqNUUoLSubAHebB0nHbG0kKh9fCfZUKS1rP3/2C9w2DI5dMRdwzOuPOtNLc OCvADjyJpL8gOHTBTe3yscCMMqWbTcc5AyG3AGVye1XMQ9ao8VhNoRhwDFxnUdlMrh3O yjgeyJzrdUevmzrI+X9LKklX25FnwN9WfGhOVtTAixXMGb5ig0xLoGnJKAiepB3ly8jk zVmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DCD0ru6f; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id p15-20020ae9f30f000000b0075943884c57si1504534qkg.312.2023.05.27.07.20.20 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 27 May 2023 07:20:21 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DCD0ru6f; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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) 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-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) 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) 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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Add versions of float64_to_int* which do not saturate the result. Signed-off-by: Richard Henderson Reviewed-by: Alex Bennée --- 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_status *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); +int32_t float64_to_int32_modulo(float64, FloatRoundMode, float_status *status); +int64_t float64_to_int64_modulo(float64, FloatRoundMode, float_status *status); + uint16_t float64_to_uint16_scalbn(float64, FloatRoundMode, int, float_status *); uint32_t float64_to_uint32_scalbn(float64, FloatRoundMode, int, float_status *); uint64_t float64_to_uint64_scalbn(float64, FloatRoundMode, int, float_status *); 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) +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); +#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) @@ -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); } +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; } +/* + * 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 = 0; + uint64_t r; + bool overflow = false; + + switch (p->cls) { + case float_class_snan: + flags |= float_flag_invalid_snan; + /* fall through */ + case float_class_qnan: + flags |= float_flag_invalid; + r = 0; + break; + + case float_class_inf: + overflow = true; + r = 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 = float_flag_inexact; + } + + if (p->exp <= DECOMPOSED_BINARY_POINT) { + /* + * Because we rounded to integral, and exp < 64, + * we know frac_low is zero. + */ + r = p->frac_hi >> (DECOMPOSED_BINARY_POINT - p->exp); + if (p->exp < bitsm1) { + /* Result in range. */ + } else if (p->exp == bitsm1) { + /* The only in-range value is INT_MIN. */ + overflow = !p->sign || p->frac_hi != DECOMPOSED_IMPLICIT_BIT; + } else { + overflow = true; + } + } else { + /* Overflow, but there might still be bits to return. */ + int shl = p->exp - DECOMPOSED_BINARY_POINT; + if (shl < N) { + frac_shl(p, shl); + r = p->frac_hi; + } else { + r = 0; + } + overflow = true; + } + + if (p->sign) { + r = -r; + } + break; + + default: + g_assert_not_reached(); + } + + if (overflow) { + flags = float_flag_invalid | float_flag_invalid_cvti; + } + float_raise(flags, s); + return r; +} + /* * Integer to float conversions * From patchwork Sat May 27 14:19:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 686384 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp319878wrt; Sat, 27 May 2023 07:20:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4OsgNCD96B1/Qwuhc8U16j7BprFpBySomQNUiJirJQUTBewxoyC87fOEsiDHNOMcXe4W3j X-Received: by 2002:a05:6214:21ac:b0:625:aa1a:9382 with SMTP id t12-20020a05621421ac00b00625aa1a9382mr4444626qvc.62.1685197221163; Sat, 27 May 2023 07:20:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685197221; cv=none; d=google.com; s=arc-20160816; b=V1J7JCnAoUtNVIvbJLqzXO/hNQJDAT/cdOxps+1qrdW4eO+YLLGzx5w0oIhG+6kXC2 uSpMqDiWvLkJH3sm8WcXJoSJgl2plc4CIS2TbcIzPNQPjjz+5oCk5PSIhu8ZLEs7A2Nq XB5Hhf/EHKSv6/tqDY65VbjNkoMptQQ4jvBjsJ9lyzdeLn7/4NDBOR4AcfCeNqOJuC5J wpI2F/9+DQLwS9+GZvLetb9ICmVUaZ2oP6veN9UgieEJI1OTIC5itGrl13MhMDCAcBcm ztU94l4rObMqrN0uShwHTZ2riFoiwamHoFsN6mqPGUsBM0tUa/oeawlZYFJR4XnZJZZF tz6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender: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; bh=2PeQwKwKV8qp9CY2VpKZ0tpDcxwU9A3roabUSRDXyns=; b=ebBZy9egYMeHRxERLj5+rxJqC4Z/IPQ+cpskXXkkx81blowA2+1Q+FlYlR2CYHTop2 s1Nz3dzAzpuqlI67c9O+1S5sxn17bFiSHJIlL+R8Df2WXGtdj76O9ySPR/F/m+SSSHfH gIOilbVAH8jPf222N0sYJp3MdAumyDsFPI15/JxlZeDHDY6Lpm+78sF0s3h7KruUeMHR IOogg0WnHgCL9SyoL98GA7QH7xd81R4WywGhNj9G0WAfjGzQ+4WniyZSGzD/LvPR5IrG xDF8Fa1/PpetxkunHG9OtkOJiyzBfumJzuhRBfs4l2eyIM7ySz3JnsF8xp8MaRIJIpcV DglA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CN5yD7Rm; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id c9-20020ac87d89000000b003ef7d5b4870si2445676qtd.147.2023.05.27.07.20.20 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 27 May 2023 07:20:21 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CN5yD7Rm; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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) 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-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) 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) 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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Test for invalid, integer overflow, and inexact. Test for proper result, modulo 2**64. Signed-off-by: Richard Henderson Acked-by: Alex Bennée Acked-by: Alex Bennée --- 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 = (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" + : "=f"(r), "=f"(e) + : "f"(d), "f"(reset)); + + *ret_e = e & FPCR_STATUS_MASK; + return r; +} + +int main (void) +{ + static const struct { + double d; + long r; + long e; + } T[] = { + { 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 = 0; + + for (i = 0; i < sizeof(T)/sizeof(T[0]); i++) { + long e, r = test_cvttq(&e, T[i].d); + + if (r != T[i].r || e != 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 = 1; + } + } + return err; +} diff --git a/tests/tcg/alpha/Makefile.target b/tests/tcg/alpha/Makefile.target index a585080328..b94500a7d9 100644 --- a/tests/tcg/alpha/Makefile.target +++ b/tests/tcg/alpha/Makefile.target @@ -5,7 +5,7 @@ ALPHA_SRC=$(SRC_PATH)/tests/tcg/alpha VPATH+=$(ALPHA_SRC) -ALPHA_TESTS=hello-alpha test-cond test-cmov test-ovf +ALPHA_TESTS=hello-alpha test-cond test-cmov test-ovf test-cvttq TESTS+=$(ALPHA_TESTS) test-cmov: EXTRA_CFLAGS=-DTEST_CMOV From patchwork Sat May 27 14:19:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 686386 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp320021wrt; Sat, 27 May 2023 07:20:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5Kf5lyi+umzmZvwVXGF8MI/T6yu5WSfLS5GTluxvPUTJYGVif3DnsfZhVuVpWaLzR+GK9R X-Received: by 2002:ac8:5b81:0:b0:3f5:7cfa:f5e9 with SMTP id a1-20020ac85b81000000b003f57cfaf5e9mr2229494qta.13.1685197242738; Sat, 27 May 2023 07:20:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685197242; cv=none; d=google.com; s=arc-20160816; b=zFlZDyaF/uUzbDCkill0ax5p8kYNiOVv74UUhxPPh4rvoY4JqShtTI7feX7HRDiTHY x4Qn0Uy17jXcB5UHpFegZUpWx+04PaH4LR76In9HApIFt8FwZz1SJGU0diqYupIR6TiS ldCUbycD++Ekx9llENnTtFW3OEJhi3DK9n1+7u/TDxXFWdtmvLIKKJGmvWo3OPvzSfL5 BIa+rDPz3gfsEbYGihcpQQ9++FRpdo52aivqgtG3kxabEwrw83Nrtk+XOA6SI6kbM0uR IBHMsWDUINXyvMVmHX5iTOrx0gN3aVgJ8CqiMzd8LvhA2wrDKaU99nVDhvwk1jRJWo5U ZiPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender: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; bh=u+CMDJ9rmMCJWN+tP1xmh2RBmH8yQeZ+BBhiYDZHw0M=; b=TMC/9LGdpUQ3bckfx1i7mBv3gjm6aabrMFkp9Ue1wH5S4hA1IuB7POuUvvLh1dGXgT lboYPdCYdCS4WWddnkCM4GibfIoJoMAE2p9LQJVWjJl2opAa8g7KZk50+45BKhfnu8ya kSfWZ7RGElBK5YKC0K2eSyPIky/71zFuTEFBpyRj1O13uWtWfCg5RFSQ0vKlKjvgp/iq QR6A0i4h5FljLL8u9+2Sanbo3CARZPWzl34M5Nx8ldh07YWklcyevPIb+smgzyw3X1gV La6TB+8pUBK9TNzvI8hofMJKyJjjSNUq+Cb3IBHwiQ+s/U6/LcHKfC3Boix52TyDWnW7 xSHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XVTQgssa; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id k7-20020ac85fc7000000b003f6acea97d4si2463896qta.510.2023.05.27.07.20.42 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 27 May 2023 07:20:42 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XVTQgssa; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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) 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-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) 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) 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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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: Philippe Mathieu-Daudé --- 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) static uint64_t do_cvttq(CPUAlphaState *env, uint64_t a, int roundmode) { - uint64_t frac, ret = 0; - uint32_t exp, sign, exc = 0; - int shift; + float64 fa; + int64_t ret; + uint32_t exc; - sign = (a >> 63); - exp = (uint32_t)(a >> 52) & 0x7ff; - frac = a & 0xfffffffffffffull; + fa = t_to_float64(a); + ret = float64_to_int64_modulo(fa, roundmode, &FP_STATUS); - if (exp == 0) { - if (unlikely(frac != 0) && !env->fp_status.flush_inputs_to_zero) { - goto do_underflow; - } - } else if (exp == 0x7ff) { - exc = FPCR_INV; - } else { - /* Restore implicit bit. */ - frac |= 0x10000000000000ull; + exc = get_float_exception_flags(&FP_STATUS); + if (unlikely(exc)) { + set_float_exception_flags(0, &FP_STATUS); - shift = exp - 1023 - 52; - if (shift >= 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 = frac << shift; - } - /* Check for overflow. Note the special case of -0x1p63. */ - if (shift >= 11 && a != 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 = FPCR_INV; + } else { exc = 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 = -shift; - if (shift < 63) { - ret = frac >> shift; - round = frac << (64 - shift); - } else { - /* The exponent is so small we shift out everything. - Leave a sticky bit for proper rounding below. */ - do_underflow: - round = 1; - } - - if (round) { - exc = FPCR_INE; - switch (roundmode) { - case float_round_nearest_even: - if (round == (1ull << 63)) { - /* Fraction is exactly 0.5; round to even. */ - ret += (ret & 1); - } else if (round > (1ull << 63)) { - ret += 1; - } - break; - case float_round_to_zero: - break; - case float_round_up: - ret += 1 - sign; - break; - case float_round_down: - ret += sign; - break; - } - } - } - if (sign) { - ret = -ret; + } else if (exc & float_flag_invalid) { + exc = FPCR_INV; + } else if (exc & float_flag_inexact) { + exc = FPCR_INE; } } env->error_code = exc; From patchwork Sat May 27 14:19:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 686382 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp319876wrt; Sat, 27 May 2023 07:20:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7+yAIJ9wem9A9IP/c3ML8AofnnpOSHz4p4KY21aGolwTaWYlJbY0Qn50cNMsfg/AGOnjE2 X-Received: by 2002:a05:620a:269e:b0:75b:23a1:3651 with SMTP id c30-20020a05620a269e00b0075b23a13651mr2692826qkp.18.1685197221146; Sat, 27 May 2023 07:20:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685197221; cv=none; d=google.com; s=arc-20160816; b=APY95Vy6GQ77AMgveJMRIOVdpXRGAP0fr930DFyIBZ8VXxBOuvhgi/krApIaW25x6u 7TJPytAsTHdm1iJeHgOnM3h/LNrxdIUYAYB5+mLgMaR2Ck5+nUcF/Dz4AVgDC1lonqBa urY4dBVaUyLO+m4BFt0Lad+kxEsZfb6lOShVT/X6joQLjHZ/s+KMdt7DPvy+sAaHeh8I s7Y8tQArYOLbFHMoDEjHbLyojQhF/BLnTfXHuEZ/DzwOfIqN17ssSQk9zHte0eNhTCR9 JofczqzrVq3cG846PhJC1088Z4h2vIX05FDAkk47v5Tk+5aF/e2AngULWgWJiPyOCBYJ CRlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender: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; bh=4Ci3Rw1Bwfq/vRMH6eDy4QVIqFnQy7Z61D8fU9qGASA=; b=bGHNY4EyAfe53XaIVzgAwvn9KMyl2/DtJaxw/9ls3qPYgKfSyMLczUPlZHOADi8WZ1 K5z0Bqo5UJR3A2ExGGGt61o3PnxWBBo4LBQuWQ2ltTscdgt0wO3zgt6kbHTaisz7XrwS fLjytQoq2BQj7Vp+ouqhvKjpKLcB4cz1u+olBThpwWFAJ0lGQK0MT+GgbYBtGGWojxiF cytVCJa8bRY6stJI0op7QI1HcbLnlzyV2TJSZKxOoB/GFyOtHpzYrEK1bapAUP7a5kRr myabV6meph/dIqzQnlqQIWnYoe1euSfMBtUtKzIKJU4Xjlf+XdFieRiRjJO4aZthKYm5 5cUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=opHnNvlK; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id s25-20020ae9f719000000b007579762eb52si2391942qkg.363.2023.05.27.07.20.20 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 27 May 2023 07:20:21 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=opHnNvlK; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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) 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-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) 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) 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 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org 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ée --- 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[] = { uint64_t HELPER(fjcvtzs)(float64 value, void *vstatus) { float_status *status = vstatus; - uint32_t exp, sign; - uint64_t frac; - uint32_t inexact = 1; /* !Z */ + uint32_t inexact, frac; + uint32_t e_old, e_new; - sign = extract64(value, 63, 1); - exp = extract64(value, 52, 11); - frac = extract64(value, 0, 52); + e_old = get_float_exception_flags(status); + set_float_exception_flags(0, status); + frac = float64_to_int32_modulo(value, float_round_to_zero, status); + e_new = get_float_exception_flags(status); + set_float_exception_flags(e_old | e_new, status); - if (exp == 0) { - /* While not inexact for IEEE FP, -0.0 is inexact for JavaScript. */ - inexact = sign; - if (frac != 0) { - if (status->flush_inputs_to_zero) { - float_raise(float_flag_input_denormal, status); - } else { - float_raise(float_flag_inexact, status); - inexact = 1; - } - } - frac = 0; - } else if (exp == 0x7ff) { - /* This operation raises Invalid for both NaN and overflow (Inf). */ - float_raise(float_flag_invalid, status); - frac = 0; + if (value == float64_chs(float64_zero)) { + /* While not inexact for IEEE FP, -0.0 is inexact for JavaScript. */ + inexact = 1; } else { - int true_exp = exp - 1023; - int shift = true_exp - 52; - - /* Restore implicit bit. */ - frac |= 1ull << 52; - - /* Shift the fraction into place. */ - if (shift >= 0) { - /* The number is so large we must shift the fraction left. */ - if (shift >= 64) { - /* The fraction is shifted out entirely. */ - frac = 0; - } else { - frac <<= shift; - } - } else if (shift > -64) { - /* Normal case -- shift right and notice if bits shift out. */ - inexact = (frac << (64 + shift)) != 0; - frac >>= -shift; - } else { - /* The fraction is shifted out entirely. */ - frac = 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 = 1; - } else if (inexact) { - float_raise(float_flag_inexact, status); - } - - /* Honor the sign. */ - if (sign) { - frac = -frac; - } + /* Normal inexact or overflow or NaN */ + inexact = e_new & (float_flag_inexact | float_flag_invalid); } /* Pack the result and the env->ZF representation of Z together. */