From patchwork Wed Apr 22 01:16:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 185622 Delivered-To: patch@linaro.org Received: by 2002:a92:3d9a:0:0:0:0:0 with SMTP id k26csp163170ilf; Tue, 21 Apr 2020 18:21:55 -0700 (PDT) X-Google-Smtp-Source: APiQypK9xjLtlr5QpJ3nQhQkdaz3XVqq3bJ0FSbg2WLAXCFBSeUAXAp2ZSttKao90KrrWqsmpf3N X-Received: by 2002:a37:61cf:: with SMTP id v198mr22672648qkb.485.1587518515713; Tue, 21 Apr 2020 18:21:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587518515; cv=none; d=google.com; s=arc-20160816; b=fvcqoE493mRBnWvWkxzmypaaSxvp8ZEXNVJ3oGG2hXI6BDBGECaQ+0F/RBVSHIqhAY xJ+uFvnL2stgMy/N29EX6rpr50JM+usYgv/xnLwKtOABdJ4glnKFVMN6giEHziSIl+Ml DZ8GDiJrPFFY1YOji5dbc8K56KmN8at01Z+HXHI2mPSnsQPjAxckGcxQ5zm9b0BC9sbN Q6B07w/HsUkUmb4Mrnd2LmmR0DnIt5g1KgHLYGg9al07FQEO0HeEUI4O4+vNPXgnwoxb LjWb7S+r2gsOAWfgU1FdhBX3JzyjIKncySXhb9v+FrndkXdw4DnYVCADez0F1T8lBscC ojyQ== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=5T7KJt0fc54mlBnT3n+g8HKCVqPFI5bG2HmAN7UzeMM=; b=JVttBLIRY/keECRLYkjBwcC4C4xpjTptBuuThCL2YMdW/IqlIo5E3KwGahTGC+id6x QalOQZ7PcPadxZzraLyKsJbrl2zdJoslyf/UhbYyt6ahjuQqdpBdBTcsLTYgvQLIEDJw hf2BbhP4wqpomrjNHY/fJJwK12USA/mAFna3zGYF3n0GyVy0TTHY1oydpGNOgnav0282 mtJEF0T/0wIgFk+V6awNyTzigzvejicKIEjAcRQIsLQPY8cgtbXxX+T1S6KFUkoiUiJV 99TMRXZvGbOLA/8ZstmWeoOkDk5i7pdZKTxHSVg+Ex40+3Fkg2MZ31L3RHOSHUcfRMl+ B+BA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=D4aQBiRe; 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 71si2353956qtf.126.2020.04.21.18.21.55 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 21 Apr 2020 18:21:55 -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=D4aQBiRe; 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]:38674 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jR45L-0000Bv-6H for patch@linaro.org; Tue, 21 Apr 2020 21:21:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34274) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jR41C-0001Ha-Au for qemu-devel@nongnu.org; Tue, 21 Apr 2020 21:17:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jR41B-0001XV-LE for qemu-devel@nongnu.org; Tue, 21 Apr 2020 21:17:38 -0400 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:43440) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jR41B-0001Tk-7S for qemu-devel@nongnu.org; Tue, 21 Apr 2020 21:17:37 -0400 Received: by mail-pg1-x541.google.com with SMTP id x26so243884pgc.10 for ; Tue, 21 Apr 2020 18:17:36 -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 :mime-version:content-transfer-encoding; bh=5T7KJt0fc54mlBnT3n+g8HKCVqPFI5bG2HmAN7UzeMM=; b=D4aQBiReHKCm6EPUrCryo4Crtrgmkupl+usryWlE2/4M1ExkdNjFRRFZdBIj/elXw9 bTEHeWc0UmtHUlT3Evg6gOjX/q9jrgEaaZ/Fmn94DixVlEfrvmOhsaWWtqMKoA1yTtpS xiOnzrNlw3qCdQZX2oTEQcx6nY3cve9NiP54vz5PR7Eu6zBEHN8432xiCDPrc4txmusi ++UY4YEJLJk1e5WNAnBPTTSQWWJ2hXKx20pIXHfPZ3y3STUhOXmZikTglIv1x3PzB44f ecqlRjFIaYrv0ksXxnRdgR9PgnJPaXVTYAhj5cyWYaZaK2BAcoea+RCzfYfkwG5Uv23M LaWw== 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:mime-version:content-transfer-encoding; bh=5T7KJt0fc54mlBnT3n+g8HKCVqPFI5bG2HmAN7UzeMM=; b=dArKF/B+akgNDOsXeWYTkZMrvk1RGnZcnyK7su0cgBxzxSMm64PoImBkYLw83Xk/uY Rin9ilZnbJUkUsGM1bxZ01/5R9gpZWid6+Im8Wvb1QhFhVproCXq5UiY0/Zg4pmsyVAi IyetVbhOXOs+7Ag2vaq9ryoFkVKTHywsu+AhGZJqUqruj2c71yCkqKwGqV8+Ef9+VTGp PPFOHgJy2RYP+7qGgTA4XjO5JlPyI+4pQijfTLCkSaMmnrNYzecZuZZ6S8ywXn4zcm5+ TEal7ejCZldSyIS/+r8Wpx3gL/H5vjYtTfki8zLuljvQEvxlNU+Wn2khKBgrNJ8C5ddb QNSQ== X-Gm-Message-State: AGi0PubZ+6E8n9IV+eyxi1MfqsDtolqxAtjQa1ViwvPpzPT6ljqaYa7a RElbnIx84cnbWretwozkUOKxjiqIFIA= X-Received: by 2002:a63:230f:: with SMTP id j15mr24083965pgj.393.1587518255524; Tue, 21 Apr 2020 18:17:35 -0700 (PDT) Received: from localhost.localdomain (174-21-149-226.tukw.qwest.net. [174.21.149.226]) by smtp.gmail.com with ESMTPSA id m4sm3673561pfm.26.2020.04.21.18.17.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Apr 2020 18:17:34 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 08/36] tcg: Improve vector tail clearing Date: Tue, 21 Apr 2020 18:16:54 -0700 Message-Id: <20200422011722.13287-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200422011722.13287-1-richard.henderson@linaro.org> References: <20200422011722.13287-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::541; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x541.google.com X-detected-operating-system: by eggs.gnu.org: Error: [-] PROGRAM ABORT : Malformed IPv6 address (bad octet value). Location : parse_addr6(), p0f-client.c:67 X-Received-From: 2607:f8b0:4864:20::541 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alex.bennee@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Better handling of non-power-of-2 tails as seen with Arm 8-byte vector operations. Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- tcg/tcg-op-gvec.c | 82 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 63 insertions(+), 19 deletions(-) -- 2.20.1 diff --git a/tcg/tcg-op-gvec.c b/tcg/tcg-op-gvec.c index 5a6cc19812..43cac1a0bf 100644 --- a/tcg/tcg-op-gvec.c +++ b/tcg/tcg-op-gvec.c @@ -326,11 +326,34 @@ void tcg_gen_gvec_5_ptr(uint32_t dofs, uint32_t aofs, uint32_t bofs, in units of LNSZ. This limits the expansion of inline code. */ static inline bool check_size_impl(uint32_t oprsz, uint32_t lnsz) { - if (oprsz % lnsz == 0) { - uint32_t lnct = oprsz / lnsz; - return lnct >= 1 && lnct <= MAX_UNROLL; + uint32_t q, r; + + if (oprsz < lnsz) { + return false; } - return false; + + q = oprsz / lnsz; + r = oprsz % lnsz; + tcg_debug_assert((r & 7) == 0); + + if (lnsz < 16) { + /* For sizes below 16, accept no remainder. */ + if (r != 0) { + return false; + } + } else { + /* + * Recall that ARM SVE allows vector sizes that are not a + * power of 2, but always a multiple of 16. The intent is + * that e.g. size == 80 would be expanded with 2x32 + 1x16. + * In addition, expand_clr needs to handle a multiple of 8. + * Thus we can handle the tail with one more operation per + * diminishing power of 2. + */ + q += ctpop32(r); + } + + return q <= MAX_UNROLL; } static void expand_clr(uint32_t dofs, uint32_t maxsz); @@ -402,22 +425,31 @@ static void gen_dup_i64(unsigned vece, TCGv_i64 out, TCGv_i64 in) static TCGType choose_vector_type(const TCGOpcode *list, unsigned vece, uint32_t size, bool prefer_i64) { - if (TCG_TARGET_HAS_v256 && check_size_impl(size, 32)) { - /* - * Recall that ARM SVE allows vector sizes that are not a - * power of 2, but always a multiple of 16. The intent is - * that e.g. size == 80 would be expanded with 2x32 + 1x16. - * It is hard to imagine a case in which v256 is supported - * but v128 is not, but check anyway. - */ - if (tcg_can_emit_vecop_list(list, TCG_TYPE_V256, vece) - && (size % 32 == 0 - || tcg_can_emit_vecop_list(list, TCG_TYPE_V128, vece))) { - return TCG_TYPE_V256; - } + /* + * Recall that ARM SVE allows vector sizes that are not a + * power of 2, but always a multiple of 16. The intent is + * that e.g. size == 80 would be expanded with 2x32 + 1x16. + * It is hard to imagine a case in which v256 is supported + * but v128 is not, but check anyway. + * In addition, expand_clr needs to handle a multiple of 8. + */ + if (TCG_TARGET_HAS_v256 && + check_size_impl(size, 32) && + tcg_can_emit_vecop_list(list, TCG_TYPE_V256, vece) && + (!(size & 16) || + (TCG_TARGET_HAS_v128 && + tcg_can_emit_vecop_list(list, TCG_TYPE_V128, vece))) && + (!(size & 8) || + (TCG_TARGET_HAS_v64 && + tcg_can_emit_vecop_list(list, TCG_TYPE_V64, vece)))) { + return TCG_TYPE_V256; } - if (TCG_TARGET_HAS_v128 && check_size_impl(size, 16) - && tcg_can_emit_vecop_list(list, TCG_TYPE_V128, vece)) { + if (TCG_TARGET_HAS_v128 && + check_size_impl(size, 16) && + tcg_can_emit_vecop_list(list, TCG_TYPE_V128, vece) && + (!(size & 8) || + (TCG_TARGET_HAS_v64 && + tcg_can_emit_vecop_list(list, TCG_TYPE_V64, vece)))) { return TCG_TYPE_V128; } if (TCG_TARGET_HAS_v64 && !prefer_i64 && check_size_impl(size, 8) @@ -432,6 +464,18 @@ static void do_dup_store(TCGType type, uint32_t dofs, uint32_t oprsz, { uint32_t i = 0; + tcg_debug_assert(oprsz >= 8); + + /* + * This may be expand_clr for the tail of an operation, e.g. + * oprsz == 8 && maxsz == 64. The first 8 bytes of this store + * are misaligned wrt the maximum vector size, so do that first. + */ + if (dofs & 8) { + tcg_gen_stl_vec(t_vec, cpu_env, dofs + i, TCG_TYPE_V64); + i += 8; + } + switch (type) { case TCG_TYPE_V256: /*