From patchwork Sat Jul 1 06:55:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 698315 Delivered-To: patch@linaro.org Received: by 2002:adf:fcc5:0:0:0:0:0 with SMTP id f5csp813307wrs; Fri, 30 Jun 2023 23:57:11 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ668DSykQn/4yBvdHGrWKR5/JFWzf2/fc0/EGKLfmeaSXG+BS1AdqjXXy8QFzfMGKxjkf6I X-Received: by 2002:ac8:5a42:0:b0:3f9:bffb:d477 with SMTP id o2-20020ac85a42000000b003f9bffbd477mr5372595qta.68.1688194631545; Fri, 30 Jun 2023 23:57:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688194631; cv=none; d=google.com; s=arc-20160816; b=eB1KojRWuvRFBSYRLxqEHB8Ut/9Egc+RoZDE9JTJ0gvq8T9BzQABXap1MjjoOGAwXN KStR8WPxaL0Sd6Cy/ycx7mSEcLRlct3eFahqp8AxATNt6jYgralTx7KhEmJRmCXT5tbl qqMs/mzZbH99koBSO7mHoYzP/q9VxuXI/EmxfacSIPL4tw2ao2z6r2V0byr8Z63bZSez OK5VAAfN1YognZLNkxXf424B9XzwQ3D0jy8txvVXTi7HDVFmpvqr7hq6+b81ja/umgPZ ECAWw0rzOsgQMhtc5sw0LgriJ3yrxHm5N0j9jXJsOMyZBcscAOslHDjLOeczY+XUrYWX Wq5Q== 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=Zw6bQp1/aPCTHVB9O6SX0clKjc4ibzsmP+nMY0H68OE=; fh=kQadAhxV42GJ3cd2VUw1RyURv/zJQGvmUdF7iLEVTtc=; b=Px0wpIjl6w3l1WJJF0++ihPGazx9VDsKJuUbTkFcxF0IAeb1AXUVhAgDOeTtxpgcmZ PLCLAAPOIG8R8hykgXQB26MhQ/dbY3HCLhZpX+xLp0tt0s2j9k0+Kl13NZy4GedJXrmv /Wd9+uoF3OdgqwbkD8lb2zvkbZoXW8vvSWwwAJkXmrjW2IbX1Ww5Su4q26PrOyda7Lke z9r3W3ZbQJdGZ01NlPvwureAQDJcV2/jdBdWM2CuYh4v5rAToEIQoRzx1ANOtxvo93nA 3QrRGJj0L5KXkKK2MdnEo5wgyYnucdm5JJtny1IrmySDabgyu4Uu/+duIqGAlo2zSxvp 2jzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=B46m4tOq; 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 7-20020ac85707000000b003f9056c111esi9027289qtw.670.2023.06.30.23.57.11 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 30 Jun 2023 23:57:11 -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=B46m4tOq; 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 1qFUVu-0007WD-Ik; Sat, 01 Jul 2023 02:55: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 1qFUVs-0007VI-UP for qemu-devel@nongnu.org; Sat, 01 Jul 2023 02:55:20 -0400 Received: from mail-lf1-x12a.google.com ([2a00:1450:4864:20::12a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qFUVr-0007FT-4p for qemu-devel@nongnu.org; Sat, 01 Jul 2023 02:55:20 -0400 Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-4f875b267d9so4333266e87.1 for ; Fri, 30 Jun 2023 23:55:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1688194517; x=1690786517; 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=Zw6bQp1/aPCTHVB9O6SX0clKjc4ibzsmP+nMY0H68OE=; b=B46m4tOq3vehnqsffCn+XtiAB44MrpLtdxBEZAvVhNW3xzh0GcojTw7OVb8yFW2c7Q IuAgaNfTAU7hl2OQfRnFenu0Adf7UO7EDI8tinVZn8PEXnIOcX+xXNpSaKAKgg+wT6Xt fYwbSgnWvPTn8a28RTEhL16Wbcjldu5t4sI5I2LjOT78QK/i3JRr5LbLBC4/nbMo6hso wEfB1hgunEvvvWg9OKrDgGXYMxa2gCQi4Q5FqxWlqZ5JKot6Bk8gN5d7N1WK1eP46F7H Wjxnw0ofcsVB7ClZVYcwqisg2NT0XN0Y9EqjWv+h+i1gIhn2Vt8S9TXrjQCfAAv+9L2c p9Og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688194517; x=1690786517; 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=Zw6bQp1/aPCTHVB9O6SX0clKjc4ibzsmP+nMY0H68OE=; b=AkPlzvwMdC1Cukdljpb8LXehh3nW9xZ3jUZ3Eo2eR787BWHH7Z9XPKNc+HK5DMYERd SR7vTU9LJnOB0B7uJvnD+o3TDIWuB8bVTskIp+5V/N63Mm/laPZDG9kCdLwyLPBQfycR kPmhmXERKnHHli9DPDZ6ztdMhRaHtbWFvbS3FUlV3WM09A3YXH77gGpr13pRnz7upLJi Pk0cOSI6xQQwOkoBv9wD58YcPbcgXF+oCNUzCpa7zjjDZr19SOcdQLVtYas4ImyVqE+6 F6lVY0YsPaJPgDat8pmll3+9QBr381yksO8B7v+3nDhIbXTHDdq4PRJC6HzSJB2oJ0se ecQQ== X-Gm-Message-State: ABy/qLa3KvyOGkYWdBYSFlAiQqYxEHqqD2oBRUeelWR0M6H0vhQ2/dpK WJSpXA8McRbUxXVHnLyZqbm+y/edH3/BhB4re9fczQ== X-Received: by 2002:a05:6512:368b:b0:4f7:6453:f3f1 with SMTP id d11-20020a056512368b00b004f76453f3f1mr3228476lfs.15.1688194517537; Fri, 30 Jun 2023 23:55:17 -0700 (PDT) Received: from localhost.localdomain ([139.47.41.96]) by smtp.gmail.com with ESMTPSA id w10-20020a1cf60a000000b003f9bd9e3226sm20874918wmc.7.2023.06.30.23.55.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jun 2023 23:55:17 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 07/11] target/alpha: Use float64_to_int64_modulo for CVTTQ Date: Sat, 1 Jul 2023 08:55:06 +0200 Message-Id: <20230701065510.514743-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230701065510.514743-1-richard.henderson@linaro.org> References: <20230701065510.514743-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::12a; envelope-from=richard.henderson@linaro.org; helo=mail-lf1-x12a.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é Message-Id: <20230527141910.1885950-4-richard.henderson@linaro.org> --- 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;