From patchwork Wed May 3 07:06:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 678610 Delivered-To: patch@linaro.org Received: by 2002:a5d:4a41:0:0:0:0:0 with SMTP id v1csp904130wrs; Wed, 3 May 2023 00:10:47 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6yL4+xjeYK1gxcOnOMEaZDmRzvTx5Z/uVDKkDTucS1eNLA46uCMu0LD2adXDnk1Ejj09K6 X-Received: by 2002:ac8:5c88:0:b0:3f3:63ed:62d8 with SMTP id r8-20020ac85c88000000b003f363ed62d8mr186855qta.29.1683097846939; Wed, 03 May 2023 00:10:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683097846; cv=none; d=google.com; s=arc-20160816; b=Nbx9YC5X5RsnQgxqdEuEM/wdCI0KdF8huOR/aMFhbW93zUxnHDqPd5jhdVDCg34BbL vgAxekW3Wg/rjv5Y5KJiTndeaK9tNUNBv+WRkAmNcTpXOar32N1QwUmFQyeSMw5VIguz W1XTmknK81zlI2coXw4DpNxl8l08SMLJOQzgSpj/1iWuoNjxhYEh83e+oYFO35dUKTb4 aeBe998HyO9lKdVWiCV8UMlqX++44eTcDk+x+wDB0dh6/VB1GAb4BeDW44II99/2PaUQ gZUdGNGKBR9jgFZpBeaOHl+baEnW3cfg0897lNhyx8z6xDEbhyjYk2px2n72aY5p+/iv vgXA== 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=AlbQNgtkgysZMHjfft1C2G8eExbC6pUxkdPDPUlgiFs=; b=PObuCLE8iy/NdFQrfw75MBH2EfdNaRfDyWKUIbmvRMsUuKDUuOx6Yp/T70HxmB1zfY nOR2aoS6FABZJ8xiWeO88PNYWJYQglPb7D0/E3PQVtN3j/Di7BVmSGU08etCY6sasKMb Qodoq302/Wlm/SArGFdwPEJXdZSu2sZTyuxSBX0DnqhbBpQct0bAaOpfuEnAyt01avgG 7WmoIGuJvKD6Bmv8yUotRwTmW+mO1XJ53jzkj9hc5eyMUmf97v7b8YAIx0AQmk6xnZYY vLXmR0mT4MmkpQNLnLIemDzfEKrceVJeCd9TdaBGlq+1p+WEW9JdTIxJ3z5WsheoFaqb V3uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=F0mH2cTO; 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 v20-20020ac85794000000b003ef5ec1dab9si16207047qta.553.2023.05.03.00.10.46 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 03 May 2023 00:10:46 -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=F0mH2cTO; 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 1pu6ai-00086D-Ia; Wed, 03 May 2023 03:07:56 -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 1pu6aL-000605-9w for qemu-devel@nongnu.org; Wed, 03 May 2023 03:07:33 -0400 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pu6Zx-0005Zv-IZ for qemu-devel@nongnu.org; Wed, 03 May 2023 03:07:32 -0400 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-3f19a80a330so29502345e9.2 for ; Wed, 03 May 2023 00:07:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1683097628; x=1685689628; 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=AlbQNgtkgysZMHjfft1C2G8eExbC6pUxkdPDPUlgiFs=; b=F0mH2cTOcVgXUOHG7GibycCjAs9KyTyDhxLWIyIwZ5qmthZzduKtnEccuQj3wzhWsZ 9kq8Tx8HPEeXFQVLDA20AKpGnq/hynE2bKc7KCYR1mnS/Z/sJ6aG/Rz00ydxjSvjvnjz lWvBBH40OUpC8YxypWN4TPS1RCOmu301jX0sOIlmV3OEW1SjgK9IH7oC0NfWFfYpssrH hzXzBKm3+mPluEN7F9JR6vCLi2pxwanrKPcMghrtpk0tzowhB+OaTKc5iNnc6z5ZiGtD ifTC0xeaKbKQdr4NlB3oBP79JFGfeLg+Hsjx6g7SpVsTQg6NC6v4qIhQa/SPf0h8AL8Z gj7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683097628; x=1685689628; 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=AlbQNgtkgysZMHjfft1C2G8eExbC6pUxkdPDPUlgiFs=; b=e7iLZBlVrzKT+DcHGMIR7m37ah3qRE7LUGIEKWCKP8R8tY+fuQum47iV/T6tzuItI2 clXpokvr1+lGdM5Q6+ThLlsMMfqaItb/yCw3hnwEqJYxqyqaRdGaEEtIulRog3wvWp8R 2Z1RIOq1ygBE/O4w7ebb2nQDqQfsLY2Pu19L6plUPgpic8YdDyTlIK1h9sKr9soS3sNH 0xYut5++WvkMTKQpcGV82HmTjfKYou1G34jU8CHIemwKfbpTFrrXctVt6d2XPMRotYFE tqhD1MZPnDk1GkiWQooOcFYDLuBiUkrIsiAgA+fDaByJZ0Ln43dcGQDFN5+FLLU+emJN Fa9Q== X-Gm-Message-State: AC+VfDwoYTakygA/Z80dApOeXHXiz/l+6SlibpzpyqMy2cwD6yr/CVxW Zvg8PctrTVRSqGTfD7O/wKQRglz9pL3kY1hFfN+0Hg== X-Received: by 2002:a7b:cc05:0:b0:3f0:683d:224d with SMTP id f5-20020a7bcc05000000b003f0683d224dmr13525315wmh.9.1683097628520; Wed, 03 May 2023 00:07:08 -0700 (PDT) Received: from stoup.Home ([2a02:c7c:74db:8d00:c01d:9d74:b630:9087]) by smtp.gmail.com with ESMTPSA id q3-20020a1cf303000000b003f3157988f8sm921184wmq.26.2023.05.03.00.07.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 May 2023 00:07:08 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: git@xen0n.name, gaosong@loongson.cn, philmd@linaro.org, qemu-arm@nongnu.org, qemu-riscv@nongnu.org, qemu-s390x@nongnu.org Subject: [PATCH v4 14/57] tcg/i386: Add have_atomic16 Date: Wed, 3 May 2023 08:06:13 +0100 Message-Id: <20230503070656.1746170-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230503070656.1746170-1-richard.henderson@linaro.org> References: <20230503070656.1746170-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=richard.henderson@linaro.org; helo=mail-wm1-x32b.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=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 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 bb603e7968..f838683fc3 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; @@ -4024,6 +4025,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); + } } } }