From patchwork Thu Aug 9 03:40:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 143649 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp1577191ljj; Wed, 8 Aug 2018 20:46:49 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxo6lqH+gEehtskGiV+2ctFoe3lnpz6vrnskFlkkkUQ5wGHPKw/wrzG8heAkFPTcz6uXLa4 X-Received: by 2002:a0c:f685:: with SMTP id p5-v6mr369719qvn.22.1533786409858; Wed, 08 Aug 2018 20:46:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533786409; cv=none; d=google.com; s=arc-20160816; b=X0NnYwwyYFKuI+E5NBYJYv/lDBhRWqf8DAITNzuVujbdc+8xA5DvhoQlXyXj7f1r86 Lf9CmUBVMthqBe/BKoM72n4vUn1O6kN9yEVtKCLFX0LLFdNywNuvSQzdBMOJyx/dgTgX 0ZMUU7FPj4OsczfbfqUqwBFojvd+jH6X0zDkBxQ3VGWjnYdDvFHAkKgumNHsrKI/ym0b go+ITHO9DTD/mxutYJKoyORlI46TAG6NOzQ0ET9IgjIMBR0bOZ37vQpsD6d9lNzWT2Fk bXeVBE7QMZCYKKl2M8yiJV3viFu+Wn6voQLFPdABK/OW1LFcJSw8RpHSNtDnZecRqCsj 9qRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=Ablu58t752cnKdeomCa6I+Hum7D6ukONMk815MNMlCI=; b=QJ0GBQ6mExK4cxoIm4GiOkMzqjmEMnTJ/CuUdJXspIz7kChbakIli36xEGuqrKjYE3 maGuMIUveKhgPVXaoRgP8q9PovnenePenNRPdTyWmN49bzGZ3zrHilVraoJfrw7c1XCt bYzB+iq25O/VgN5sjTWlXl3eBzd4kfTj9j6HMlPrV5d7/YhqyqcJHlAQHCI9bJis317f BOeog2uetx4XkgwMkXtwdwKdq0fxgfMnQBvUNmg6NDooBT2yulDYiVWRzxxyHRNCigbG Ex0+OrEF98pouD+M15se4T7PItTRzK4CU5Cgwa7FEEEXNDJSbx2wsAwhOoqNKBEw81lb ZsPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Lrh8BGuo; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id q21-v6si849555qve.6.2018.08.08.20.46.49 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 08 Aug 2018 20:46:49 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=Lrh8BGuo; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:46408 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fnbuT-00027G-4O for patch@linaro.org; Wed, 08 Aug 2018 23:46:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37679) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fnboZ-0006dK-1V for qemu-devel@nongnu.org; Wed, 08 Aug 2018 23:40:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fnboX-00038r-Oa for qemu-devel@nongnu.org; Wed, 08 Aug 2018 23:40:43 -0400 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:37242) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fnboX-00038G-HU for qemu-devel@nongnu.org; Wed, 08 Aug 2018 23:40:41 -0400 Received: by mail-pg1-x544.google.com with SMTP id n7-v6so2068803pgq.4 for ; Wed, 08 Aug 2018 20:40:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Ablu58t752cnKdeomCa6I+Hum7D6ukONMk815MNMlCI=; b=Lrh8BGuolsMa5CTx9cdrZuYOYh5HPv+hp0rP/BJ7Szkfv827MktLS5Y3j5xcfjCghM oHaGa2vdHtM9eTpsyeF/eX9xbDngFdBRzipTgkOaOFFSS3hVJjV//xe7R5TfKACHzgrp rOwIME7O5yOprBYkiIZRmS3aczHXDIICGEYz0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Ablu58t752cnKdeomCa6I+Hum7D6ukONMk815MNMlCI=; b=ET1AjdJa0E6D+Au2UODpOB98AwIIRSjDOzZn51uU8++Ie6UuTVhhBPtiFg4vZAvIHl FPsr7VVa/VNDUKzWONifbWrXqyU42zO9dnYauZ+PhToZTAQPF99omwqXqtORJhQAE6Oy C4DNGlkjpH0TkQTbBQL6S/6CqMffdK8GDzhfDs6vdm6dwL19cCNsms0YyyF0E1fira7d ajiDGLMNEC6WkWlPKftkkgjFpODzuDg1r4saRzPVk/SyN29qje6R6Pa+g0mCLWHqpV2V A9Zw/toFXtKRgxDgUw2UTZVPFcAvbqFW8vlp5Q8OZaAGRsNq3g/gjTdCqoRknIVm8FBu B5mw== X-Gm-Message-State: AOUpUlHxTSEyiVp1cyTTmhgnly/rSu7WiMyI/PmY3eNGx+Y3NGp0TsUO 83gvtsp9qLgf+gCuuQ89wy0zfw6IgVU= X-Received: by 2002:a63:ea49:: with SMTP id l9-v6mr390827pgk.427.1533786040197; Wed, 08 Aug 2018 20:40:40 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-8-179.tukw.qwest.net. [97.113.8.179]) by smtp.gmail.com with ESMTPSA id q78-v6sm9674103pfi.185.2018.08.08.20.40.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 08 Aug 2018 20:40:39 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 8 Aug 2018 20:40:25 -0700 Message-Id: <20180809034033.10579-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180809034033.10579-1-richard.henderson@linaro.org> References: <20180809034033.10579-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::544 Subject: [Qemu-devel] [PATCH 03/11] target/arm: Reorganize SVE WHILE X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: laurent.desnogues@gmail.com, peter.maydell@linaro.org, alex.bennee@linaro.org, qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The pseudocode for this operation is an increment + compare loop, so comparing <= the maximum integer produces an all-true predicate. Rather than bound in both the inline code and the helper, pass the helper the number of predicate bits to set instead of the number of predicate elements to set. Cc: qemu-stable@nongnu.org (3.0.1) Tested-by: Laurent Desnogues Reviewed-by: Laurent Desnogues Reported-by: Laurent Desnogues Signed-off-by: Richard Henderson --- target/arm/sve_helper.c | 5 ---- target/arm/translate-sve.c | 49 +++++++++++++++++++++++++------------- 2 files changed, 32 insertions(+), 22 deletions(-) -- 2.17.1 Reviewed-by: Alex Bennée diff --git a/target/arm/sve_helper.c b/target/arm/sve_helper.c index 9bd0694d55..87594a8adb 100644 --- a/target/arm/sve_helper.c +++ b/target/arm/sve_helper.c @@ -2846,11 +2846,6 @@ uint32_t HELPER(sve_while)(void *vd, uint32_t count, uint32_t pred_desc) return flags; } - /* Scale from predicate element count to bits. */ - count <<= esz; - /* Bound to the bits in the predicate. */ - count = MIN(count, oprsz * 8); - /* Set all of the requested bits. */ for (i = 0; i < count / 64; ++i) { d->p[i] = esz_mask; diff --git a/target/arm/translate-sve.c b/target/arm/translate-sve.c index 9dd4c38bab..89efc80ee7 100644 --- a/target/arm/translate-sve.c +++ b/target/arm/translate-sve.c @@ -3173,19 +3173,19 @@ static bool trans_CTERM(DisasContext *s, arg_CTERM *a, uint32_t insn) static bool trans_WHILE(DisasContext *s, arg_WHILE *a, uint32_t insn) { - if (!sve_access_check(s)) { - return true; - } - - TCGv_i64 op0 = read_cpu_reg(s, a->rn, 1); - TCGv_i64 op1 = read_cpu_reg(s, a->rm, 1); - TCGv_i64 t0 = tcg_temp_new_i64(); - TCGv_i64 t1 = tcg_temp_new_i64(); + TCGv_i64 op0, op1, t0, t1, tmax; TCGv_i32 t2, t3; TCGv_ptr ptr; unsigned desc, vsz = vec_full_reg_size(s); TCGCond cond; + if (!sve_access_check(s)) { + return true; + } + + op0 = read_cpu_reg(s, a->rn, 1); + op1 = read_cpu_reg(s, a->rm, 1); + if (!a->sf) { if (a->u) { tcg_gen_ext32u_i64(op0, op0); @@ -3198,32 +3198,47 @@ static bool trans_WHILE(DisasContext *s, arg_WHILE *a, uint32_t insn) /* For the helper, compress the different conditions into a computation * of how many iterations for which the condition is true. - * - * This is slightly complicated by 0 <= UINT64_MAX, which is nominally - * 2**64 iterations, overflowing to 0. Of course, predicate registers - * aren't that large, so any value >= predicate size is sufficient. */ + t0 = tcg_temp_new_i64(); + t1 = tcg_temp_new_i64(); tcg_gen_sub_i64(t0, op1, op0); - /* t0 = MIN(op1 - op0, vsz). */ - tcg_gen_movi_i64(t1, vsz); - tcg_gen_umin_i64(t0, t0, t1); + tmax = tcg_const_i64(vsz >> a->esz); if (a->eq) { /* Equality means one more iteration. */ tcg_gen_addi_i64(t0, t0, 1); + + /* If op1 is max (un)signed integer (and the only time the addition + * above could overflow), then we produce an all-true predicate by + * setting the count to the vector length. This is because the + * pseudocode is described as an increment + compare loop, and the + * max integer would always compare true. + */ + tcg_gen_movi_i64(t1, (a->sf + ? (a->u ? UINT64_MAX : INT64_MAX) + : (a->u ? UINT32_MAX : INT32_MAX))); + tcg_gen_movcond_i64(TCG_COND_EQ, t0, op1, t1, tmax, t0); } - /* t0 = (condition true ? t0 : 0). */ + /* Bound to the maximum. */ + tcg_gen_umin_i64(t0, t0, tmax); + tcg_temp_free_i64(tmax); + + /* Set the count to zero if the condition is false. */ cond = (a->u ? (a->eq ? TCG_COND_LEU : TCG_COND_LTU) : (a->eq ? TCG_COND_LE : TCG_COND_LT)); tcg_gen_movi_i64(t1, 0); tcg_gen_movcond_i64(cond, t0, op0, op1, t0, t1); + tcg_temp_free_i64(t1); + /* Since we're bounded, pass as a 32-bit type. */ t2 = tcg_temp_new_i32(); tcg_gen_extrl_i64_i32(t2, t0); tcg_temp_free_i64(t0); - tcg_temp_free_i64(t1); + + /* Scale elements to bits. */ + tcg_gen_shli_i32(t2, t2, a->esz); desc = (vsz / 8) - 2; desc = deposit32(desc, SIMD_DATA_SHIFT, 2, a->esz);