From patchwork Tue Apr 25 19:31:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 676833 Delivered-To: patch@linaro.org Received: by 2002:a5d:4a41:0:0:0:0:0 with SMTP id v1csp2880712wrs; Tue, 25 Apr 2023 12:43:44 -0700 (PDT) X-Google-Smtp-Source: AKy350ZsqCCO+WvEa6wO84d4zfrsLBKm3NoM+fs/czCfEntBzJePay7nDdthsRE9HhFSVX86eBQ1 X-Received: by 2002:ac8:7fc2:0:b0:3ef:5993:42e0 with SMTP id b2-20020ac87fc2000000b003ef599342e0mr28637184qtk.10.1682451823879; Tue, 25 Apr 2023 12:43:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682451823; cv=none; d=google.com; s=arc-20160816; b=AYtEIcOj5Uch6SzaZIwx6KXEZe0pCbwwBpMFRyny5RjH+haT+pPBL4Qagt9F+QObgy F8h2/XTn5S88fFzFfvQcK5RPH7VDHNQhvUA15i1eh5eyv4EskgXH8mr4zir4Z/nD+DLY a5PTy5IP6bTDNDFVaAig3w9OpmUumdm1W5Rh3axnIkSoFUvNiwIv7lGxSlL/LZQljSlH ZmcIOyXFc5fzT4KgZzO07P8vO01jPAyy0UB+rqmWohlcjDG+JlIai5VFSgmJB8LU++HL pm+6PynBKyuJO3qHSpSuwNbMI4jooRtkKdLrFny3tObWRFH4Xvf+PgD0QMGmNXxOgasa zKEA== 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=uLKGPSGMAiW9EHCX31qD8RhUBJV5TJE49TIwgfGSsuA=; b=mkNPkdZ10y8PaIV88UpZ2EybF/Rs/AHA4vqWDIRbqu4oAg9Godpvrb9JjzdULVmcf8 3PEzr9+6nlznGUDrZMaqZYEyk+gZqMHcVnLPYLlXTdk/4FKL2Ao2QXMgp92lbJVbp/Z2 lJODJwMVSUSUQ3QYem8noAfx1nbul5d+PV5uh2l5UMX0KLx269jyJ2ec2z8FY6y5kV1a l7ZG6mZ+CGDe1tC0p92nj/dAwEbDbvb88RPIM1ZbcTZTrUZVgMcKIunlSbrArO+qJesY eIiRUn3mLfD4p5mVlRW5/2+AH2fTzm6Nm3CS2z9tkhhZQ+WGo5LSriHOCoM38pgj2TwQ cHrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=einTuaOs; 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 u25-20020a05622a199900b003ecb0b742f3si9521740qtc.88.2023.04.25.12.43.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 25 Apr 2023 12:43:43 -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=einTuaOs; 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 1prOQS-0002js-Ac; Tue, 25 Apr 2023 15:34:08 -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 1prOQQ-0002bp-BI for qemu-devel@nongnu.org; Tue, 25 Apr 2023 15:34:06 -0400 Received: from mail-lf1-x136.google.com ([2a00:1450:4864:20::136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1prOQG-0004el-RF for qemu-devel@nongnu.org; Tue, 25 Apr 2023 15:34:06 -0400 Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-4ec86aeeb5cso6649870e87.3 for ; Tue, 25 Apr 2023 12:33:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1682451235; x=1685043235; 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=uLKGPSGMAiW9EHCX31qD8RhUBJV5TJE49TIwgfGSsuA=; b=einTuaOsm7dfzZ/MwApYiBc8Jm6AHLdre3p8Ty7vOshFFbnpXocgYREVeAoHMvdGzU +mOCMBw4avFiMuJH3mcmFni+YX1C2pD24yDwyJQstEPno8Um1FOj1RcyBqbQ/Uxl3lHN lsg9Jv8bWWVyRtoC83JecswVEK78U2leQRx00iAt4cmJl8hL/agjcK0BADAlfPFc36dE e+hW4gQ4Xgu7wXe8K2GUyUMstLDgSWRXuZB79flxipNT8EE3hTC1ySGECcQOV7s7jObN nym8SCyk3m7Rnxu89F8ZoFvolzv3MJULCiTn9+5rBF5+w4d5s2jwKySw/5y7vuTABitE /D+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682451235; x=1685043235; 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=uLKGPSGMAiW9EHCX31qD8RhUBJV5TJE49TIwgfGSsuA=; b=MZmyIFOfg947qXoKf3kPQTBJ+Xvn7Uh+3zomY3zpHWBGK+OSeZlywMFldBSFXM8bfB rjWygNGSOmn6uIHZCHPwmNP5a0FNRX5NE+EX+Ng3dkiU0xl7x2Sk0wQ4Sbr3z7vXmpfq AZ2kRGPRhdfhHQFKxQLWc5cp3nxznOyq1s0Mx2QTiPiUT4s/wBeNPy6n7mzJe7Udp/ca Vwbpg7ec+CaVk0aag9SAut70wYVA/0ogjUQcAIbspZx3hNwFKyIoWeodV1vA6twwv22h K+NUWnVkXDDvIN+s0I356+xJhAqed1TkS4AuWVoth8+zwM5RkCiH/OIMZaK4Rvfj/vQh 6b3Q== X-Gm-Message-State: AAQBX9fSWxU74p5BbEkB/e8Fgoi1Gf2rIXjX6fu4THi0CPq7jufPy6z+ BaVH4F9eHybjqCjBNiB7WfesgfgGOrlQezvEytmQuA== X-Received: by 2002:ac2:5939:0:b0:4d1:3d1d:4914 with SMTP id v25-20020ac25939000000b004d13d1d4914mr4921505lfi.33.1682451235111; Tue, 25 Apr 2023 12:33:55 -0700 (PDT) Received: from stoup.. ([91.209.212.61]) by smtp.gmail.com with ESMTPSA id z23-20020a2e8857000000b002a8c271de33sm2160484ljj.67.2023.04.25.12.33.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Apr 2023 12:33:54 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, qemu-s390x@nongnu.org, qemu-riscv@nongnu.org, qemu-ppc@nongnu.org, git@xen0n.name, jiaxun.yang@flygoat.com, philmd@linaro.org Subject: [PATCH v3 14/57] tcg/i386: Add have_atomic16 Date: Tue, 25 Apr 2023 20:31:03 +0100 Message-Id: <20230425193146.2106111-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230425193146.2106111-1-richard.henderson@linaro.org> References: <20230425193146.2106111-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::136; envelope-from=richard.henderson@linaro.org; helo=mail-lf1-x136.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=unavailable 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 Notice when Intel or AMD have guaranteed that vmovdqa is atomic. The new variable will also be used in generated code. Signed-off-by: Richard Henderson --- include/qemu/cpuid.h | 18 ++++++++++++++++++ tcg/i386/tcg-target.h | 1 + tcg/i386/tcg-target.c.inc | 27 +++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/include/qemu/cpuid.h b/include/qemu/cpuid.h index 1451e8ef2f..35325f1995 100644 --- a/include/qemu/cpuid.h +++ b/include/qemu/cpuid.h @@ -71,6 +71,24 @@ #define bit_LZCNT (1 << 5) #endif +/* + * Signatures for different CPU implementations as returned from Leaf 0. + */ + +#ifndef signature_INTEL_ecx +/* "Genu" "ineI" "ntel" */ +#define signature_INTEL_ebx 0x756e6547 +#define signature_INTEL_edx 0x49656e69 +#define signature_INTEL_ecx 0x6c65746e +#endif + +#ifndef signature_AMD_ecx +/* "Auth" "enti" "cAMD" */ +#define signature_AMD_ebx 0x68747541 +#define signature_AMD_edx 0x69746e65 +#define signature_AMD_ecx 0x444d4163 +#endif + static inline unsigned xgetbv_low(unsigned c) { unsigned a, d; diff --git a/tcg/i386/tcg-target.h b/tcg/i386/tcg-target.h index d4f2a6f8c2..0421776cb8 100644 --- a/tcg/i386/tcg-target.h +++ b/tcg/i386/tcg-target.h @@ -120,6 +120,7 @@ extern bool have_avx512dq; extern bool have_avx512vbmi2; extern bool have_avx512vl; extern bool have_movbe; +extern bool have_atomic16; /* optional instructions */ #define TCG_TARGET_HAS_div2_i32 1 diff --git a/tcg/i386/tcg-target.c.inc b/tcg/i386/tcg-target.c.inc index b5bb4bf45d..696c656f3b 100644 --- a/tcg/i386/tcg-target.c.inc +++ b/tcg/i386/tcg-target.c.inc @@ -185,6 +185,7 @@ bool have_avx512dq; bool have_avx512vbmi2; bool have_avx512vl; bool have_movbe; +bool have_atomic16; #ifdef CONFIG_CPUID_H static bool have_bmi2; @@ -4026,6 +4027,32 @@ static void tcg_target_init(TCGContext *s) have_avx512dq = (b7 & bit_AVX512DQ) != 0; have_avx512vbmi2 = (c7 & bit_AVX512VBMI2) != 0; } + + /* + * The Intel SDM has added: + * Processors that enumerate support for IntelĀ® AVX + * (by setting the feature flag CPUID.01H:ECX.AVX[bit 28]) + * guarantee that the 16-byte memory operations performed + * by the following instructions will always be carried + * out atomically: + * - MOVAPD, MOVAPS, and MOVDQA. + * - VMOVAPD, VMOVAPS, and VMOVDQA when encoded with VEX.128. + * - VMOVAPD, VMOVAPS, VMOVDQA32, and VMOVDQA64 when encoded + * with EVEX.128 and k0 (masking disabled). + * Note that these instructions require the linear addresses + * of their memory operands to be 16-byte aligned. + * + * AMD has provided an even stronger guarantee that processors + * with AVX provide 16-byte atomicity for all cachable, + * naturally aligned single loads and stores, e.g. MOVDQU. + * + * See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104688 + */ + if (have_avx1) { + __cpuid(0, a, b, c, d); + have_atomic16 = (c == signature_INTEL_ecx || + c == signature_AMD_ecx); + } } } }