From patchwork Sun Sep 11 23:04:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 604783 Delivered-To: patch@linaro.org Received: by 2002:a05:6504:2213:b0:1da:4c02:b5e7 with SMTP id z19csp2258755ltw; Sun, 11 Sep 2022 16:29:54 -0700 (PDT) X-Google-Smtp-Source: AA6agR7s0iPRQoEL2jQN8OzLNbWXxOS4p9QFUJ/GobPTp2lWJWRmyVppvKIMDoDLSBlgno00GQ1u X-Received: by 2002:a05:620a:21c7:b0:6cd:52bc:b578 with SMTP id h7-20020a05620a21c700b006cd52bcb578mr9154459qka.385.1662938994675; Sun, 11 Sep 2022 16:29:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662938994; cv=none; d=google.com; s=arc-20160816; b=fzVqWiVm3UMDAMQrtHt/ZeJbajm5yWMP+hjI0bWnYSIttgU2LYJKyb8yf6hovl6bdH BrXB53cBLNP8wjJT6HRIZQ3WPLjFQBxhmS5APUGyvHX6DZX+ycBJdjLBK5j+UIAJ0iv8 Yn/OfoC4fIPpR1E3KHvQLMxI8eQQLqsSmCsP/eRQGn+aB09bdyHd6gvXaDxR1r7KAsQj UCVdFahq4bqmsOKoGC1G2IK91LyIT7z0erQmgv1wIWqXo4u/TOijEFJyqunc+HwDD+8X UFzzsaVOyZTsnG+JfxHNBZdbqBqJ/Mt7N5CWtjR9VzBCx9QkinQHqpHAmFvD9SNTsQ43 QGxw== 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=JAtiCaR9lQvQR+6tBzPSfnat0AkPUvcguUA8ZEf6XIg=; b=Wv/uEb3d0+ndjF3EweignVNY2nz07QxecG18ktybJTEXEqIGPwhhQdKDVAL5MOTZ97 xuUTVAKIaGW8lF6mZlwZHCShW4LkSR1m3VKSjDsoYwuUyTJpFPbqOOLL0yrAYJoFEZl+ 6sIMOBJthx97/mHLbBE70ShrLqwHNErHzVqyAAMny5dI10/4ygm+kOmw2jR/GP6fQlbP bCsx4F++fTqel6K+g1+wTnB4KLQkh/UkZTsN5KHW27TPjLAx70AzYmWa4D7L1nQwouh6 /JvrbU6DR5DoCUW62KafJSBryZdgL7wfZcARi6BJ6nweJQsPSkSV4GeF1kkl9UTyVmpp +CBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MXQ53lwf; 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=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d18-20020a05620a241200b006bc55c16cb9si4363928qkn.362.2022.09.11.16.29.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 11 Sep 2022 16:29:54 -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=@redhat.com header.s=mimecast20190719 header.b=MXQ53lwf; 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=redhat.com Received: from localhost ([::1]:38282 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oXWOg-0002od-5Z for patch@linaro.org; Sun, 11 Sep 2022 19:29:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40456) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oXW1L-0001Mr-St for qemu-devel@nongnu.org; Sun, 11 Sep 2022 19:05:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:23209) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oXW1K-0007MV-8B for qemu-devel@nongnu.org; Sun, 11 Sep 2022 19:05:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662937545; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JAtiCaR9lQvQR+6tBzPSfnat0AkPUvcguUA8ZEf6XIg=; b=MXQ53lwfuNV1gu15kFkZYWPsI5H7zv0F7preebuyhwPwuRsm75yG51tqQxowTT3qLqTwMW IKjQMe6ZqK5WZMo+AS6aV65AL84LT19qajrtePpxLuXSGlmPP4WaUKtkrkn9TTLJ6UZaXA 569YJ7qCh6Ri30j1GSNpfFrq5AfKliE= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-651-Ltg7aSRCPQ67asHFUrVLDw-1; Sun, 11 Sep 2022 19:05:44 -0400 X-MC-Unique: Ltg7aSRCPQ67asHFUrVLDw-1 Received: by mail-ej1-f69.google.com with SMTP id go7-20020a1709070d8700b007793ffa7c44so2316428ejc.1 for ; Sun, 11 Sep 2022 16:05:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=JAtiCaR9lQvQR+6tBzPSfnat0AkPUvcguUA8ZEf6XIg=; b=BSfYZmOeYwXUgbCLAcZyPOmbas5rX6qreO3HtjFyh86Gy7WrtoACo7NkARgTZorFfd zK+dX9ieFPoqlrGiIsSE88jfRUUrAwPmNbi3/3d+3VE10dgXaBYDi6kNZWng5wVA+6Mj mCf9onXGWqnNejegz00TJyQNV2xpp9re2U/7u3M/41zKSDWq2CUFnyeaHhhUZYoGDsrZ Wf32pj2umI3M9Wg21vtXsatU19stlznAVyBAUqN3C41qAU1XI2h/6i4doDm96uHScbJW /fBmSQgBPd5sq2nBDo2NzNEccsCbv6HMb75rcAenIIw7dvZmQX3NmclFVjKL+x6iPkTR EtwA== X-Gm-Message-State: ACgBeo1aqrBOv7Aw0y2+VOZ+2IKPt7ck6X6eOiGPUmQURtSmgN49FP+M D6bMQ5MV+enMHm6YGLnaF+Z7bnDsrmd+uqspRlBs5h9Cppv9aLT2ML2rs8keKMmeOZDSBzPCFOv LqHc2dkm6FJrI8cb5S5/r8c12elN7ishwRfbhy5d9lwkaBWg75LQ034YLEeoyppVJlqA= X-Received: by 2002:a17:906:8a45:b0:77c:dd3:cebd with SMTP id gx5-20020a1709068a4500b0077c0dd3cebdmr3997585ejc.668.1662937542885; Sun, 11 Sep 2022 16:05:42 -0700 (PDT) X-Received: by 2002:a17:906:8a45:b0:77c:dd3:cebd with SMTP id gx5-20020a1709068a4500b0077c0dd3cebdmr3997570ejc.668.1662937542599; Sun, 11 Sep 2022 16:05:42 -0700 (PDT) Received: from goa-sendmail (93-44-39-154.ip95.fastwebnet.it. [93.44.39.154]) by smtp.gmail.com with ESMTPSA id ka5-20020a170907920500b0073c5192cba6sm3458406ejb.114.2022.09.11.16.05.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Sep 2022 16:05:42 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Richard Henderson Subject: [PATCH 27/37] target/i386: Use tcg gvec ops for pmovmskb Date: Mon, 12 Sep 2022 01:04:07 +0200 Message-Id: <20220911230418.340941-28-pbonzini@redhat.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220911230418.340941-1-pbonzini@redhat.com> References: <20220911230418.340941-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, 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" From: Richard Henderson As pmovmskb is used by strlen et al, this is the third highest overhead sse operation at %0.8. Signed-off-by: Richard Henderson [Reorganize to generate code for any vector size. - Paolo] Signed-off-by: Paolo Bonzini --- target/i386/tcg/emit.c.inc | 65 +++++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 5 deletions(-) diff --git a/target/i386/tcg/emit.c.inc b/target/i386/tcg/emit.c.inc index dbf2c05e16..52c0a7fbe0 100644 --- a/target/i386/tcg/emit.c.inc +++ b/target/i386/tcg/emit.c.inc @@ -1179,14 +1179,69 @@ static void gen_PINSR(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode) gen_pinsr(s, env, decode, decode->op[2].ot); } +static void gen_pmovmskb_i64(TCGv_i64 d, TCGv_i64 s) +{ + TCGv_i64 t = tcg_temp_new_i64(); + + tcg_gen_andi_i64(d, s, 0x8080808080808080ull); + + /* + * After each shift+or pair: + * 0: a.......b.......c.......d.......e.......f.......g.......h....... + * 7: ab......bc......cd......de......ef......fg......gh......h....... + * 14: abcd....bcde....cdef....defg....efgh....fgh.....gh......h....... + * 28: abcdefghbcdefgh.cdefgh..defgh...efgh....fgh.....gh......h....... + * The result is left in the high bits of the word. + */ + tcg_gen_shli_i64(t, d, 7); + tcg_gen_or_i64(d, d, t); + tcg_gen_shli_i64(t, d, 14); + tcg_gen_or_i64(d, d, t); + tcg_gen_shli_i64(t, d, 28); + tcg_gen_or_i64(d, d, t); +} + +static void gen_pmovmskb_vec(unsigned vece, TCGv_vec d, TCGv_vec s) +{ + TCGv_vec t = tcg_temp_new_vec_matching(d); + TCGv_vec m = tcg_constant_vec_matching(d, MO_8, 0x80); + + /* See above */ + tcg_gen_and_vec(vece, d, s, m); + tcg_gen_shli_vec(vece, t, d, 7); + tcg_gen_or_vec(vece, d, d, t); + tcg_gen_shli_vec(vece, t, d, 14); + tcg_gen_or_vec(vece, d, d, t); + if (vece == MO_64) { + tcg_gen_shli_vec(vece, t, d, 28); + tcg_gen_or_vec(vece, d, d, t); + } +} + static void gen_PMOVMSKB(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode) { - if (s->prefix & PREFIX_DATA) { - gen_helper_pmovmskb_xmm(s->tmp2_i32, cpu_env, s->ptr2); - } else { - gen_helper_pmovmskb_mmx(s->tmp2_i32, cpu_env, s->ptr2); + static const TCGOpcode vecop_list[] = { INDEX_op_shli_vec, 0 }; + static const GVecGen2 g = { + .fni8 = gen_pmovmskb_i64, + .fniv = gen_pmovmskb_vec, + .opt_opc = vecop_list, + .vece = MO_64, + .prefer_i64 = TCG_TARGET_REG_BITS == 64 + }; + MemOp ot = decode->op[0].ot; + int vec_len = sse_vec_len(s, decode); + TCGv t = tcg_temp_new(); + + tcg_gen_gvec_2(offsetof(CPUX86State, xmm_t0) + xmm_offset(ot), decode->op[2].offset, + vec_len, vec_len, &g); + tcg_gen_ld8u_tl(s->T0, cpu_env, offsetof(CPUX86State, xmm_t0.ZMM_B(vec_len - 1))); + while (vec_len > 8) { + vec_len -= 8; + tcg_gen_shli_tl(s->T0, s->T0, 8); + tcg_gen_ld8u_tl(t, cpu_env, offsetof(CPUX86State, xmm_t0.ZMM_B(vec_len - 1))); + tcg_gen_or_tl(s->T0, s->T0, t); } - tcg_gen_extu_i32_tl(s->T0, s->tmp2_i32); + tcg_temp_free(t); } static void gen_POR(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode)