From patchwork Fri Nov 18 09:47:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 626120 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp35359pvb; Fri, 18 Nov 2022 01:57:30 -0800 (PST) X-Google-Smtp-Source: AA0mqf5fTexL8g7ch5vWb8Mlm4YLYBJq0zOws77KpPW6qZEpLUmfYfXgz2zO0za815Y3miqzzqiz X-Received: by 2002:a05:622a:4110:b0:3a5:4502:3d67 with SMTP id cc16-20020a05622a411000b003a545023d67mr5874913qtb.270.1668765450613; Fri, 18 Nov 2022 01:57:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668765450; cv=none; d=google.com; s=arc-20160816; b=jFYFIO/OUw1qdFxfo9IBH2xX2ffx0Zt/7uw9/uBMuDBr3SKLfDZbq4z/lHx2pFvt7/ n5LmToNzSOWRpTmxLy6aKzRVlLyDoh4tW8CdnWwPH4NRQGFFWNXkb7qthAVYDfHz2HZN oYaa3RNU3AidXwQyeguu9Imv0R5OsX/yagXQZ3Y+i2j5qp8X0L4/qy0pPPClm1KXpWzO SNgwsXKZ2f50vG2S6Te1fM2BrXb1ovr9n8rp6xQ/+HCZPl91IEfl2vEvDHfTGD2Mv2U/ xtLR6VGtgHra8630zElftPoKx7PFDeJYDzmmHabdp073fDOdt/6bWvUOAEn2ac3h5w+m pAXA== 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=m/CUiseesWXfy8ONw/IKq3y2jtfhBMrDZnaeFnHh+EA=; b=LnVmrIVr8a3BOwKQ4jWjl2YANjGgnZHBks1HA2OgW8iRPtETIqO6/JTHosjdftOA6x DUsVQkWlAKZPcjjLr3GgE3Y2gQIQAT3YObS6XqHH+9dGHe8xcPkjvHZBlQ8BCrBWFnem /qm0zxQVlbOpJDuZiKF7wsZaUgMkim2DGvuP08q/YBePbM8cIlK/tWx+/tiwZ81blGZ0 w0pSGbbZ4Ap21mPT6KPlGlIxbOAbNG2hJBHS3mP9d+91h7EiOhpYfnSi9C+fNsSdGMIO TrSe5SWmdfpDEGb2evcJl2f6O1rwxxIQKEWqEv9TCPQ5GWBWMH1no/yFhZhToGGsoUD1 kt1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="cjh/Hx87"; 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 j12-20020ac8440c000000b003a4eab32a96si1603992qtn.298.2022.11.18.01.57.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 18 Nov 2022 01:57:30 -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="cjh/Hx87"; 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 1ovxys-0007KC-GO; Fri, 18 Nov 2022 04:48:18 -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 1ovxyc-000768-CA for qemu-devel@nongnu.org; Fri, 18 Nov 2022 04:48:06 -0500 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ovxya-0001yU-OW for qemu-devel@nongnu.org; Fri, 18 Nov 2022 04:48:02 -0500 Received: by mail-pl1-x636.google.com with SMTP id w23so4081102ply.12 for ; Fri, 18 Nov 2022 01:48:00 -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=m/CUiseesWXfy8ONw/IKq3y2jtfhBMrDZnaeFnHh+EA=; b=cjh/Hx87JI2qBBTJFpWd6RW1YdLczPKK0Z5x3b2HhaOOGeojQtzNyujUjiOQfJqtcl emIBWCfRI3KcPqKLf9ZXUMzasGEUzlIwcSHp0WDQA0Ti8MoIMNY6hPcG4R9hSzngPA41 77ziaxPfUG5aAClDDQ5q1/YskGUIZBToXDMWKze5cjmpHQkZPg+uy97AMze8MuSy2JVK ESQSxMGi/MSI7uvmhhBmQxON/TmN+Bksw+qJLFamoLid2VSA4JA9KuPLWHk5yAElVNiN TNApMTDebrJLHk3GkyizZsqXboihv2Rzt56D0njAM2rzmrfrqFzrjjfpCjO8ifL7k49i 5y0Q== 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=m/CUiseesWXfy8ONw/IKq3y2jtfhBMrDZnaeFnHh+EA=; b=cAesMA8nrJ3nG+y/mThia9KagQ+m7ZK/tAFc7lkgwXZxe9+1ynAn3gk4go8EeUEywd B9g7H9p3HJb80PA454Dm3rYBk3rzt1vp4xS7bosP97C1wx6mxLK8ErYR5Tsi2UkdMupU DxtuTF24aM7h6gX0A+p1P9ctxp2bbNhWMObVAL5oB6Lsj0g9XUmT3TC+c133HrcfZmdY OprjGW1jWXV1NGQftB2+LwGwuHZuD/Q7VuplkcGogBvthQzInAew1d6MhjWxz4voYYVg LYks31ss6ohryKByYZDsKIfjUeRWwgk4JAO0KC1KgJsbZFis3RtYrIKcmTJZxRrTAd6b rSJA== X-Gm-Message-State: ANoB5pn13E8ei7gldqbTsHiuG0GDREsuNrX1U5tTZ73WS8HeuUoWEl9U p3vdwAuZ6saX9+Yqi/Un/gikrN1NHfnNMQ== X-Received: by 2002:a17:90a:d145:b0:213:f465:14e7 with SMTP id t5-20020a17090ad14500b00213f46514e7mr6976294pjw.194.1668764879000; Fri, 18 Nov 2022 01:47:59 -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.47.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Nov 2022 01:47:58 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH for-8.0 01/29] include/qemu/cpuid: Introduce xgetbv_low Date: Fri, 18 Nov 2022 01:47:26 -0800 Message-Id: <20221118094754.242910-2-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::636; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x636.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 Replace the two uses of asm to expand xgetbv with an inline function. Since one of the two has been using the mnemonic, assume that the comment about "older versions of the assember" is obsolete, as even that is 4 years old. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- include/qemu/cpuid.h | 7 +++++++ util/bufferiszero.c | 3 +-- tcg/i386/tcg-target.c.inc | 11 ++++------- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/include/qemu/cpuid.h b/include/qemu/cpuid.h index 7adb12d320..1451e8ef2f 100644 --- a/include/qemu/cpuid.h +++ b/include/qemu/cpuid.h @@ -71,4 +71,11 @@ #define bit_LZCNT (1 << 5) #endif +static inline unsigned xgetbv_low(unsigned c) +{ + unsigned a, d; + asm("xgetbv" : "=a"(a), "=d"(d) : "c"(c)); + return a; +} + #endif /* QEMU_CPUID_H */ diff --git a/util/bufferiszero.c b/util/bufferiszero.c index ec3cd4ca15..b0660d484d 100644 --- a/util/bufferiszero.c +++ b/util/bufferiszero.c @@ -287,8 +287,7 @@ static void __attribute__((constructor)) init_cpuid_cache(void) /* We must check that AVX is not just available, but usable. */ if ((c & bit_OSXSAVE) && (c & bit_AVX) && max >= 7) { - int bv; - __asm("xgetbv" : "=a"(bv), "=d"(d) : "c"(0)); + unsigned bv = xgetbv_low(0); __cpuid_count(7, 0, a, b, c, d); if ((bv & 0x6) == 0x6 && (b & bit_AVX2)) { cache |= CACHE_AVX2; diff --git a/tcg/i386/tcg-target.c.inc b/tcg/i386/tcg-target.c.inc index c96b5a6f43..1361960156 100644 --- a/tcg/i386/tcg-target.c.inc +++ b/tcg/i386/tcg-target.c.inc @@ -4148,12 +4148,9 @@ static void tcg_target_init(TCGContext *s) /* There are a number of things we must check before we can be sure of not hitting invalid opcode. */ if (c & bit_OSXSAVE) { - unsigned xcrl, xcrh; - /* The xgetbv instruction is not available to older versions of - * the assembler, so we encode the instruction manually. - */ - asm(".byte 0x0f, 0x01, 0xd0" : "=a" (xcrl), "=d" (xcrh) : "c" (0)); - if ((xcrl & 6) == 6) { + unsigned bv = xgetbv_low(0); + + if ((bv & 6) == 6) { have_avx1 = (c & bit_AVX) != 0; have_avx2 = (b7 & bit_AVX2) != 0; @@ -4164,7 +4161,7 @@ static void tcg_target_init(TCGContext *s) * check that OPMASK and all extended ZMM state are enabled * even if we're not using them -- the insns will fault. */ - if ((xcrl & 0xe0) == 0xe0 + if ((bv & 0xe0) == 0xe0 && (b7 & bit_AVX512F) && (b7 & bit_AVX512VL)) { have_avx512vl = true;