From patchwork Tue Sep 20 17:24:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 607660 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2060947pvb; Tue, 20 Sep 2022 15:38:20 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6/HPBYuToB3BC81adJC5mhGzVUSDITukAY5c7wrgJYpxv1oxLA1fzWiYn1FLGWW4Tq1mD9 X-Received: by 2002:ac8:5209:0:b0:35b:b179:9ca1 with SMTP id r9-20020ac85209000000b0035bb1799ca1mr21717545qtn.260.1663713500012; Tue, 20 Sep 2022 15:38:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663713500; cv=none; d=google.com; s=arc-20160816; b=PH/K4gtcDZYN0zEMS3GSv9dbDjwz4cc20/Ikdj4jWCg1Ja4Lw5ILQ5w4kwk1Wqdm/a 8aPpfyZ0MKT/VmZoRUjj9yZ4NaugKcb/MDBsQnloJFJEegJLb3aCldPw6VloNP+mHLEb UmFZgRrxeo9S4TVXFfcrC4zDMQD9tMsTs7OyVd6I9mKnbUzu9R6QRE+Iey1GJwzWEyn9 /mRp0n+oi3Sigu2Lu8+D7RwfGLZIRzy8KksIQo1VFm9B8xkmsd1x3/mGDIidr1B65Bm6 rqr9hFYDBj4KVgrjGNImA+4zl5r0AoblZUewKmz6B0lCTHpHA4fLymRWIbMZvpZLBI6v 6EYQ== 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=8qNlguD+njmm2618TYLP1T4Fj6fykhZdMOk4HXO6te4=; b=NwWZWzSpFA7fVRKlOsoqR7GePg+CuLphOZiUWxyA0rt3nF3a3P7Sp2/r6a/NzHY6pL 5qYgIc9PPNofUP7uCm0jqLyKDtNc/ipn/0ioHdjC5Ax2ZYERonIK0I1ADAqx4rhfMjtZ ocjzEn9DOdAJknJAFkdtEMpgHiIBSTHRMgTrt5TfcdPJ3WyxVK0f2utFFJ2xsrY15Shv phHRrWwIdqlnLlLZ2qrTDcjykQZnGVeesVBEvzF7bDGFk/nT7dJGsLAqlgJxcoY/+v+3 xIGf8kH07EkkLARvvToSdbMzwt+OVPQImze7r3fCxlReSCdKucPSUgYC9q4Jm+RBGlHN NjfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VpY7Y91i; 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 c22-20020a05622a025600b003446c6e015bsi666639qtx.407.2022.09.20.15.38.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Sep 2022 15:38:20 -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=VpY7Y91i; 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]:39270 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oalsh-0004K6-GL for patch@linaro.org; Tue, 20 Sep 2022 18:38:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39842) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oagzn-0006H2-9K for qemu-devel@nongnu.org; Tue, 20 Sep 2022 13:25:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:40295) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oagzk-00022Q-4a for qemu-devel@nongnu.org; Tue, 20 Sep 2022 13:25:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663694715; 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=8qNlguD+njmm2618TYLP1T4Fj6fykhZdMOk4HXO6te4=; b=VpY7Y91iRsdH3rda3J2/MXga088W/lpD2zRYtcsDgu13R18dvPXGynhvsA8T3phgmGIRR+ x+2vv8mKNIai7gvgRfzTseKcOOoaq62UaOK07RIErvbPlsQLiA3pn9/IQ2VKyjYSTFWeYE KB3T8/pFijtgA5hpfJgj0y3kaYhe1yI= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-551-opfu15tQM9SSS8t3dlpUAQ-1; Tue, 20 Sep 2022 13:25:13 -0400 X-MC-Unique: opfu15tQM9SSS8t3dlpUAQ-1 Received: by mail-ed1-f71.google.com with SMTP id h13-20020a056402280d00b004528c8400afso2343728ede.6 for ; Tue, 20 Sep 2022 10:25:13 -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=8qNlguD+njmm2618TYLP1T4Fj6fykhZdMOk4HXO6te4=; b=zAlqA7+tvm7GhC+x+Y8i9iEEhhLE9ZwMFHXurKn2XSs1y+mOZ8eh7+WDawLxKLwm/V KjsiupHGBmf5XTlYJUv0fXP5k/PyPZ1QTBSqL72yaJ3un+f/zhPuj8fGGunLuJ1eLWDO PvRuo9hACD0MNAmgARxkkLeywoZUbh98fNbdbTur0Nk+s1Cp9Tjl2ubqCpNyrm7piGAg O3CFqy3sLgZq6ukj49a3+KLx1VKLTvvwBObVoLdIX2Ezkxtmo+uB/G3zsD1EqBTVhkES X7hvcrKivM4iZ/qWm1jR5h8sWTSjUGMXFRBD5cTlgVngiugzIeo8kZX341MJXIFN2xqJ j76Q== X-Gm-Message-State: ACrzQf0ER8Sl7vmn4nXG8sj6S/gamMySYaOkBlF1j8kO1b3nQ6TO9uj0 iC6AN/ARUQtVjlYEiffUFtfZf+/v0z5x9aLQMUv/YX0DXK3eP9hwYQhUT145w1TahZOJuxi3s+W G+UCNviRnA8C6+ud6wIzyzmk8vCuSoWJ5b+MHtqfwFOIRmjAtEg1YIiLAyBq7Qnle6sg= X-Received: by 2002:a17:907:724b:b0:780:49ab:4b66 with SMTP id ds11-20020a170907724b00b0078049ab4b66mr18029476ejc.67.1663694711772; Tue, 20 Sep 2022 10:25:11 -0700 (PDT) X-Received: by 2002:a17:907:724b:b0:780:49ab:4b66 with SMTP id ds11-20020a170907724b00b0078049ab4b66mr18029454ejc.67.1663694711444; Tue, 20 Sep 2022 10:25:11 -0700 (PDT) Received: from [192.168.10.118] ([2001:b07:6468:f312:9af8:e5f5:7516:fa89]) by smtp.gmail.com with ESMTPSA id n16-20020a1709062bd000b00730bfe6adc4sm200151ejg.37.2022.09.20.10.25.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Sep 2022 10:25:10 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org, paul@nowt.org Subject: [PATCH v2 01/37] target/i386: Define XMMReg and access macros, align ZMM registers Date: Tue, 20 Sep 2022 19:24:31 +0200 Message-Id: <20220920172507.95568-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220920172507.95568-1-pbonzini@redhat.com> References: <20220920172507.95568-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 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 This will be used for emission and endian adjustments of gvec operations. Signed-off-by: Richard Henderson Message-Id: <20220822223722.1697758-2-richard.henderson@linaro.org> Signed-off-by: Paolo Bonzini --- target/i386/cpu.h | 56 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 13 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 82004b65b9..8311b69c88 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1233,18 +1233,34 @@ typedef struct SegmentCache { uint32_t flags; } SegmentCache; -#define MMREG_UNION(n, bits) \ - union n { \ - uint8_t _b_##n[(bits)/8]; \ - uint16_t _w_##n[(bits)/16]; \ - uint32_t _l_##n[(bits)/32]; \ - uint64_t _q_##n[(bits)/64]; \ - float32 _s_##n[(bits)/32]; \ - float64 _d_##n[(bits)/64]; \ - } +typedef union MMXReg { + uint8_t _b_MMXReg[64 / 8]; + uint16_t _w_MMXReg[64 / 16]; + uint32_t _l_MMXReg[64 / 32]; + uint64_t _q_MMXReg[64 / 64]; + float32 _s_MMXReg[64 / 32]; + float64 _d_MMXReg[64 / 64]; +} MMXReg; -typedef MMREG_UNION(ZMMReg, 512) ZMMReg; -typedef MMREG_UNION(MMXReg, 64) MMXReg; +typedef union XMMReg { + uint64_t _q_XMMReg[128 / 64]; +} XMMReg; + +typedef union YMMReg { + uint64_t _q_YMMReg[256 / 64]; + XMMReg _x_YMMReg[256 / 128]; +} YMMReg; + +typedef union ZMMReg { + uint8_t _b_ZMMReg[512 / 8]; + uint16_t _w_ZMMReg[512 / 16]; + uint32_t _l_ZMMReg[512 / 32]; + uint64_t _q_ZMMReg[512 / 64]; + float32 _s_ZMMReg[512 / 32]; + float64 _d_ZMMReg[512 / 64]; + XMMReg _x_ZMMReg[512 / 128]; + YMMReg _y_ZMMReg[512 / 256]; +} ZMMReg; typedef struct BNDReg { uint64_t lb; @@ -1267,6 +1283,13 @@ typedef struct BNDCSReg { #define ZMM_S(n) _s_ZMMReg[15 - (n)] #define ZMM_Q(n) _q_ZMMReg[7 - (n)] #define ZMM_D(n) _d_ZMMReg[7 - (n)] +#define ZMM_X(n) _x_ZMMReg[3 - (n)] +#define ZMM_Y(n) _y_ZMMReg[1 - (n)] + +#define XMM_Q(n) _q_XMMReg[1 - (n)] + +#define YMM_Q(n) _q_YMMReg[3 - (n)] +#define YMM_X(n) _x_YMMReg[1 - (n)] #define MMX_B(n) _b_MMXReg[7 - (n)] #define MMX_W(n) _w_MMXReg[3 - (n)] @@ -1279,6 +1302,13 @@ typedef struct BNDCSReg { #define ZMM_S(n) _s_ZMMReg[n] #define ZMM_Q(n) _q_ZMMReg[n] #define ZMM_D(n) _d_ZMMReg[n] +#define ZMM_X(n) _x_ZMMReg[n] +#define ZMM_Y(n) _y_ZMMReg[n] + +#define XMM_Q(n) _q_XMMReg[n] + +#define YMM_Q(n) _q_YMMReg[n] +#define YMM_X(n) _x_YMMReg[n] #define MMX_B(n) _b_MMXReg[n] #define MMX_W(n) _w_MMXReg[n] @@ -1556,8 +1586,8 @@ typedef struct CPUArchState { float_status mmx_status; /* for 3DNow! float ops */ float_status sse_status; uint32_t mxcsr; - ZMMReg xmm_regs[CPU_NB_REGS == 8 ? 8 : 32]; - ZMMReg xmm_t0; + ZMMReg xmm_regs[CPU_NB_REGS == 8 ? 8 : 32] QEMU_ALIGNED(16); + ZMMReg xmm_t0 QEMU_ALIGNED(16); MMXReg mmx_t0; uint64_t opmask_regs[NB_OPMASK_REGS]; From patchwork Tue Sep 20 17:24:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 607638 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2041548pvb; Tue, 20 Sep 2022 14:45:00 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7Q/vkqfyj45N6FQU5QnQ3LAE3EjfSqnxfrnVA4XsA0cPsh6dFlKxyM4/lQ9GWTQTyaKhXE X-Received: by 2002:a05:622a:60d:b0:343:808:f55c with SMTP id z13-20020a05622a060d00b003430808f55cmr20892219qta.438.1663710300035; Tue, 20 Sep 2022 14:45:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663710300; cv=none; d=google.com; s=arc-20160816; b=SR8PWLQSlJyyNdA/iCBKRxunoY+pU+i9VZcY8hUWFSq0b4u7dQMNItA/Qtb91gLx1P VKVkXUvF/Fs6b/tk/AmVClALuXUOR4ZI7pf0zqKe8QSpfREKIdr6xvJTOanKvHdDMh38 smutPC3UM6/EwlXV9wF+GOpk5+/ZXkoX1t/Rt5KzxkHrxO678PM8ua66yCDkzZgVEgcM zXAKECK8bs6eIopgy8yHMqJlEl/RZpm02S96IO2sRtLSS5BOMR7t7aQ2eBTrE3MCxxu9 lxO575fnB/WKv7G9o99C5TBPswlWzno0X+ZKfU8kVFnM6h1sZdIDIQ43FFlqkDiu9/m1 jK5A== 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=0cKuu8KwWrHFcXenB2KvhX7Mcmnc9QSZITTwlBYZzfU=; b=qCXHOJqXNgjXH/GjKg2QbGH2XymzHajhM/iWTTIECvV3sXRBNB4w6Kvu5i4Q5sQy6f 9OWKJdbBMUCKF5cSU+o0/0FwuMgB+Cru0/BqwairmTEBB/gSme52+rmbiPt6t2CRfTjg KkG2+VtNPm6lGaM+MBgDpDjqKRtyPrHqVmbPcdtRXKlOlrwpZtkom6WIB7livmHViRDY ToXycotiCtBzuOh2uieJU29USwtsfc3Zs4fIqGy5Or9s9ow4IS5vaBBmaXByBJG/bgl4 ChO+sb4WGqXmD/psW4KYSagUpqI+mdfCSVwjQcXTL/hmOeKATe16y1/kAym4sqt4sCSx /6Lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XeQahWVQ; 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 fw15-20020a056214238f00b004ac6f38cc86si480476qvb.567.2022.09.20.14.44.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Sep 2022 14:45:00 -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=XeQahWVQ; 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]:45830 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oal35-0002vM-I7 for patch@linaro.org; Tue, 20 Sep 2022 17:44:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57430) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oah0N-0006T3-8W for qemu-devel@nongnu.org; Tue, 20 Sep 2022 13:25:59 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:21529) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oah0L-0002Eh-JK for qemu-devel@nongnu.org; Tue, 20 Sep 2022 13:25:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663694752; 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=0cKuu8KwWrHFcXenB2KvhX7Mcmnc9QSZITTwlBYZzfU=; b=XeQahWVQaDg2N2H41I7zgl4cIxKAu91fdn+JQsPZXOfL32LvD0J6y1p5HGatiYYfjF3r+p el1LC9mjT+D8Cr5CtMSDue0xUn4SGrW5r4qD0KLSuCvlJo1OmJbqdMQ5ToGKdxPoesHxtQ Xb1xxlRg+eDlD4Pe1TfX0iti5GQGt/0= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-259-owTTpphMMIimfvPE4uVSDQ-1; Tue, 20 Sep 2022 13:25:51 -0400 X-MC-Unique: owTTpphMMIimfvPE4uVSDQ-1 Received: by mail-ed1-f70.google.com with SMTP id y14-20020a056402440e00b0044301c7ccd9so2348253eda.19 for ; Tue, 20 Sep 2022 10:25:51 -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=0cKuu8KwWrHFcXenB2KvhX7Mcmnc9QSZITTwlBYZzfU=; b=LXV0wmCGHUaGRNXe5uEQ99qF6XmsVWig/Kweb+HL6/ZowekNGjFmfV238K/IbX31oX +22q5nZydoN5imNz5De/Gs7+f/+wpqkVHaMZRCl1ineM9baKan3BX5czneR03oOTGCHQ pvnbqX/CINIA5EX+XXrUsHI7nwQwJ8/HrrjcWChDAJRq8eRYDRpX4Rb5uXBeM3gxApwL p/1xaak26f/UtQ6r76uOmvfc/jbV8kUO8+x9GQTh2hOLcrzrwFX1xvPSbVw7Vj4EGx9w aqybbQRDf/73ivO+5z21ThELxSo0mLgROIxcd7og5q8NJCE60pWOYHY8jVNKb+Kwvc3U m8hg== X-Gm-Message-State: ACrzQf2RuBruFQ3T7rVj/c9g4CXVSMq4oE2nkVdD/oYuCKDsT8Zb5rm7 9/Y1eGPfpR0walrYew2KLuX7civoZNkPNZVI6JEwy6OSl4nv8qHjz8RX8mOtW/ec/EJhtEWsPI/ 9IN2CZslh1QuucbH6I321nqMSSakaick7CgpnPhJWyeS8zmk+9TwyeDh6Fxm9iLBz0Bw= X-Received: by 2002:a17:906:eece:b0:76f:5c6:2340 with SMTP id wu14-20020a170906eece00b0076f05c62340mr17899141ejb.383.1663694750091; Tue, 20 Sep 2022 10:25:50 -0700 (PDT) X-Received: by 2002:a17:906:eece:b0:76f:5c6:2340 with SMTP id wu14-20020a170906eece00b0076f05c62340mr17899117ejb.383.1663694749815; Tue, 20 Sep 2022 10:25:49 -0700 (PDT) Received: from [192.168.10.118] ([2001:b07:6468:f312:9af8:e5f5:7516:fa89]) by smtp.gmail.com with ESMTPSA id ay21-20020a056402203500b0044e9601e53fsm236088edb.19.2022.09.20.10.25.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Sep 2022 10:25:49 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: richard.henderson@linaro.org, paul@nowt.org Subject: [PATCH v2 27/37] target/i386: Use tcg gvec ops for pmovmskb Date: Tue, 20 Sep 2022 19:24:57 +0200 Message-Id: <20220920172507.95568-28-pbonzini@redhat.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220920172507.95568-1-pbonzini@redhat.com> References: <20220920172507.95568-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 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 | 90 +++++++++++++++++++++++++++++++++++--- 1 file changed, 85 insertions(+), 5 deletions(-) diff --git a/target/i386/tcg/emit.c.inc b/target/i386/tcg/emit.c.inc index c5e90111a9..5345e791b7 100644 --- a/target/i386/tcg/emit.c.inc +++ b/target/i386/tcg/emit.c.inc @@ -1192,14 +1192,94 @@ 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); + } +} + +#ifdef TARGET_I386 +#define TCG_TARGET_HAS_extract2_tl TCG_TARGET_HAS_extract2_i32 +#else +#define TCG_TARGET_HAS_extract2_tl TCG_TARGET_HAS_extract2_i64 +#endif + static void gen_PMOVMSKB(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode) { - if (s->prefix & PREFIX_DATA) { - gen_helper_pmovmskb_xmm(s->tmp2_i32, cpu_env, OP_PTR2); - } else { - gen_helper_pmovmskb_mmx(s->tmp2_i32, cpu_env, OP_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[2].ot; + int vec_len = vector_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; + if (TCG_TARGET_HAS_extract2_tl) { + /* + * Load the next byte of the result into the high byte of T. + * TCG does a similar expansion of deposit to shl+extract2; by + * loading the whole word, the shift left is avoided. + */ +#ifdef TARGET_X86_64 + tcg_gen_ld_tl(t, cpu_env, offsetof(CPUX86State, xmm_t0.ZMM_Q((vec_len - 1) / 8))); +#else + tcg_gen_ld_tl(t, cpu_env, offsetof(CPUX86State, xmm_t0.ZMM_L((vec_len - 1) / 4))); +#endif + + tcg_gen_extract2_tl(s->T0, t, s->T0, TARGET_LONG_BITS - 8); + } else { + /* + * The _previous_ value is deposited into bits 8 and higher of t. Because + * those bits are known to be zero after ld8u, this becomes a shift+or + * if deposit is not available. + */ + tcg_gen_ld8u_tl(t, cpu_env, offsetof(CPUX86State, xmm_t0.ZMM_B(vec_len - 1))); + tcg_gen_deposit_tl(s->T0, t, s->T0, 8, TARGET_LONG_BITS - 8); + } } - tcg_gen_extu_i32_tl(s->T0, s->tmp2_i32); + tcg_temp_free(t); } static void gen_PSHUFW(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode)