From patchwork Fri Nov 18 09:47:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 626114 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp33951pvb; Fri, 18 Nov 2022 01:53:41 -0800 (PST) X-Google-Smtp-Source: AA0mqf7jZKzQ2roZklOXgBkj2fyBaEAiueEvzj9fCct8I40vr76y4PB/q9NrI5EdYmt/KNkXMsUM X-Received: by 2002:ae9:ed05:0:b0:6cf:9ca3:b33d with SMTP id c5-20020ae9ed05000000b006cf9ca3b33dmr5029373qkg.475.1668765221500; Fri, 18 Nov 2022 01:53:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668765221; cv=none; d=google.com; s=arc-20160816; b=zw1sZg19U0ngdIbp31q5T82pagfyzzuxV4dTlvWEpVleGUa2H+XatPovuotnG+hLx6 waxbuVRSin1LTK4Uh47mwoBqzBX03Q6T1uySDDrND0flzuelYn/DiYLUwq2KfMEhg74t q8PT3htGHGVNd4AofHpnMZdwEYUZz11f252nSxZ4q0ghrRMmTS1lS4Ddti+OQLXUhKUT 1vdiWuWz8uReZM6JB0ufwzPWIk6txyunMRHxwM59FLuplYsjtg2GbWZrkN3Vk6HVkbIW emK6xDJ0Tpof4EBpjlgGOXi4lenamhncEBLUH3IQWRtQdU14uoHtuLm6j8gZvKjqDXBW kFnw== 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:to:from :dkim-signature; bh=tex5BgNy0m4Jvy/PmpG7dbIZx8VBa5q+aB9+9yTGsNk=; b=CnS9f8w7xgOirvr2ZM91JrJjS33RsHpLJzctz/8YB8bvHwNcnIptoWBYLRXbTfRT+m CP96dsMDeDGjXczYLSx3F6jTU0CkHx7meSSXQBIRMbytPeLamy6bU3CLsM/hs1LTym67 9V7JUBHTRPlE21XC1p1e6Jgo3EAixRwyWZUFydHy1OFIwh+Ts8m9hNiMNPQxgI5sDZ1Q 0BUoIlc2rVe1pnEXZxR2NnO84ydtGbf57tPN9Yb+kvnZIuL7l+BI42CvzzdzQARuX5mR DPsBgg/H/h33MUMnF9ie//cjiJkvZEk6YWGX8P2ZYrwwVsKnnFM5GBFS4RKp3fPsM+Eh z+ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xhUERY+F; 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 l7-20020a05620a28c700b006f27650e2f9si1842873qkp.196.2022.11.18.01.53.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 18 Nov 2022 01:53:41 -0800 (PST) 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=xhUERY+F; 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 1ovxzh-0007sa-C2; Fri, 18 Nov 2022 04:49:09 -0500 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 1ovxz5-0007So-0y for qemu-devel@nongnu.org; Fri, 18 Nov 2022 04:48:38 -0500 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ovxz1-00024y-F3 for qemu-devel@nongnu.org; Fri, 18 Nov 2022 04:48:30 -0500 Received: by mail-pj1-x1031.google.com with SMTP id k2-20020a17090a4c8200b002187cce2f92so2636877pjh.2 for ; Fri, 18 Nov 2022 01:48:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=tex5BgNy0m4Jvy/PmpG7dbIZx8VBa5q+aB9+9yTGsNk=; b=xhUERY+FGLH7tvak+RYppGQ0nyoOpaq536TNDvm6nqa/pnU3+tUqDt+trLsF1yQntX HFvnBUT0DmumxapwLRt3vbjWh3nNEr3x8wYk44GKvoSsz2avuMkfgLjRWIyDNY9HrP+H BktcmLAViC/Hd9FGCMUGEBPzk6+aDoa5tkHOW6UoC7/6grvqIVrZAgwk9pPGlsWKezza mNWdJpkRpJhFYE22KTCM5gnnbcd4gpp2+l5qUutjVcDaqe7bCrLtDJs2eiToB4rzrq6c l0gvfqVXN9ohdiJaowilu0Fk1la9PVeIfbj4ju7RQcagdUUz0+Jcsg/Es4Eedrs56FD8 p97g== 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:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tex5BgNy0m4Jvy/PmpG7dbIZx8VBa5q+aB9+9yTGsNk=; b=wk1oWwRExA2oaVGwPPsej2acPy2NjPLYT972V2XGRR2q+hKVPAhnmRkDoVQwOJeeR+ vVhnXQcne4I9eir/8KRwAqsdfqaxaMsJWuTDjLOYFALDMWjnChmc/2dYepM+8A49GPf2 k307V0o8/fXiB2VEf3IXlLO1mzS5OhcOiQGuIJpOUCv0bYk58BuuHAqFGbuOy6IGL5jc pJotyS66YYICsowG6Ekf5ThBU8P5Kzp5SELqyrjAm0YP5B3ona+WY1dZptx0WIEup5TY rC08DDMwuxkwF3yH1Vo6wpLVxFZnH0whiSHHA5KCD/sml5J2u64jHTHGmX1/AQ+wVgp1 He5Q== X-Gm-Message-State: ANoB5pkezOWebFGPYV/Penfq/xc9hG0Oq4cr3D1KE8Gg04MlI46baoma 3Dq5JDpgHOyTV+fBCZsu1uGF/dmIE5m8fw== X-Received: by 2002:a17:90a:1a11:b0:213:f398:ed51 with SMTP id 17-20020a17090a1a1100b00213f398ed51mr6883100pjk.216.1668764906235; Fri, 18 Nov 2022 01:48:26 -0800 (PST) Received: from stoup.. ([2602:47:d48a:1201:90b2:345f:bf0a:c412]) by smtp.gmail.com with ESMTPSA id n12-20020a170902e54c00b0018862bb3976sm3115421plf.308.2022.11.18.01.48.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Nov 2022 01:48:25 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH for-8.0 14/29] tcg/i386: Add have_atomic16 Date: Fri, 18 Nov 2022 01:47:39 -0800 Message-Id: <20221118094754.242910-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221118094754.242910-1-richard.henderson@linaro.org> References: <20221118094754.242910-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1031; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1031.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 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-bounces+patch=linaro.org@nongnu.org Notice when Intel has 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 9e0e82d80a..5b037b1d2b 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 24e9efe631..f4c0c7b8a2 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; @@ -4165,6 +4166,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); + } } } }