From patchwork Fri May 27 01:00:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 9137529 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6CBB86075A for ; Fri, 27 May 2016 01:01:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5FA712807E for ; Fri, 27 May 2016 01:01:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 548F4282E1; Fri, 27 May 2016 01:01:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CB4672807E for ; Fri, 27 May 2016 01:01:45 +0000 (UTC) Received: from localhost ([::1]:41156 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b669p-0000Ga-0p for patchwork-qemu-devel@patchwork.kernel.org; Thu, 26 May 2016 21:01:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40358) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b6694-0008WH-L8 for qemu-devel@nongnu.org; Thu, 26 May 2016 21:01:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b668x-0004A1-NW for qemu-devel@nongnu.org; Thu, 26 May 2016 21:00:57 -0400 Received: from mail-qg0-x243.google.com ([2607:f8b0:400d:c04::243]:33033) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b668x-00049x-J4 for qemu-devel@nongnu.org; Thu, 26 May 2016 21:00:51 -0400 Received: by mail-qg0-x243.google.com with SMTP id 90so2525809qgz.0 for ; Thu, 26 May 2016 18:00:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=iW7neofkotPFTO7Xmqa/frFRMD1j79W3EgFMnVAOOv0=; b=kBMbNjuSJaFuBrh+IGdQP19FZOL0WQF0StDf5r6McW6KnbJo+d40ArK0NzAnQZZn5Y 0HqmZXuH61/5sXdm90PktSlPg+MmcboYVkOnLpli6WSG6gZSb/mrYal0JV5IVzyKesM5 n4RZDryrba1V5UrsMneoUgbqi/m5HXA984TlQvlM8vHt25YoZ0ldMyzLb5S3r+ks0jGx ieQmt7iFfier9M+TpaCRWtO84cq41bj+EYK5ICzaMinOB1bM72F4Uwee8tzUVUEbXGGu fqXvpixWdiXMHltCptZyy12l6JTyTywP4EZprawrSHSy2NVlqWcLbTQ675+XqqDufx2T 56xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=iW7neofkotPFTO7Xmqa/frFRMD1j79W3EgFMnVAOOv0=; b=mxCc1lX+LmwKgIPwrIypiu4QOOl6KRriLC4ChhqUd4NksCm3vDiFQCJlCNtlVXXlWf cb7BD40ZZspu9h5NjcoiG6obMwIO1U8eDoIh02FljlIAOV+eN/1e8iTqzF0Ru5ug7BIE MQPFErM3cQ/Kbr3ABJsmGcM8dJpK69qzoFNGMQ1fSIpmvkjU7DCSeE4npN9a1OZtWJgq vY7ip5VkuYKsAftWFqgsRtm7v8xwInh7M+blh/wG4acC07BIGRQeI9Mrv3OHc3SjE1A7 xxXOAp1hZuAp54yddg5H0C3UDltDC7Gm38NV9Zl7TvjVF2iMqY/aFfhJpHeT69OA+AHf Na9w== X-Gm-Message-State: ALyK8tILjp5wWkjcVb9idWXeJD9aZlR4ay22Xr1TDJGD2R9c9cV8RQFJ4IaQFpaIjV3ExQ== X-Received: by 10.140.98.204 with SMTP id o70mr10957004qge.73.1464310851023; Thu, 26 May 2016 18:00:51 -0700 (PDT) Received: from bigtime.com ([172.56.17.0]) by smtp.gmail.com with ESMTPSA id 77sm1872030qgn.29.2016.05.26.18.00.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 May 2016 18:00:50 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 26 May 2016 18:00:05 -0700 Message-Id: <1464310815-13554-3-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1464310815-13554-1-git-send-email-rth@twiddle.net> References: <1464310815-13554-1-git-send-email-rth@twiddle.net> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400d:c04::243 Subject: [Qemu-devel] [PATCH v2 02/12] tcg/i386: Add support for fence X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bobby.prani@gmail.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Pranith Kumar Message-Id: <20160524171856.1000-3-bobby.prani@gmail.com> [rth: Check for sse2, fallback to locked memory op otherwise.] Signed-off-by: Richard Henderson --- tcg/i386/tcg-target.inc.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tcg/i386/tcg-target.inc.c b/tcg/i386/tcg-target.inc.c index 317484c..d3f2d73 100644 --- a/tcg/i386/tcg-target.inc.c +++ b/tcg/i386/tcg-target.inc.c @@ -121,6 +121,16 @@ static bool have_cmov; # define have_cmov 0 #endif +/* For 32-bit, we are going to attempt to determine at runtime whether + sse2 support is available. */ +#if TCG_TARGET_REG_BITS == 64 || defined(__SSE2__) +# define have_sse2 1 +#elif defined(CONFIG_CPUID_H) && defined(bit_SSE2) +static bool have_sse2; +#else +# define have_sse2 0 +#endif + /* If bit_MOVBE is defined in cpuid.h (added in GCC version 4.6), we are going to attempt to determine at runtime whether movbe is available. */ #if defined(CONFIG_CPUID_H) && defined(bit_MOVBE) @@ -686,6 +696,21 @@ static inline void tcg_out_pushi(TCGContext *s, tcg_target_long val) } } +static inline void tcg_out_fence(TCGContext *s) +{ + if (have_sse2) { + /* mfence */ + tcg_out8(s, 0x0f); + tcg_out8(s, 0xae); + tcg_out8(s, 0xf0); + } else { + /* lock orl $0,0(%esp) */ + tcg_out8(s, 0xf0); + tcg_out_modrm_offset(s, OPC_ARITH_EvIb, ARITH_OR, TCG_REG_ESP, 0); + tcg_out8(s, 0); + } +} + static inline void tcg_out_push(TCGContext *s, int reg) { tcg_out_opc(s, OPC_PUSH_r32 + LOWREGMASK(reg), 0, reg, 0); @@ -2120,6 +2145,9 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc, } break; + case INDEX_op_fence: + tcg_out_fence(s); + break; case INDEX_op_mov_i32: /* Always emitted via tcg_out_mov. */ case INDEX_op_mov_i64: case INDEX_op_movi_i32: /* Always emitted via tcg_out_movi. */ @@ -2185,6 +2213,8 @@ static const TCGTargetOpDef x86_op_defs[] = { { INDEX_op_add2_i32, { "r", "r", "0", "1", "ri", "ri" } }, { INDEX_op_sub2_i32, { "r", "r", "0", "1", "ri", "ri" } }, + { INDEX_op_fence, { } }, + #if TCG_TARGET_REG_BITS == 32 { INDEX_op_brcond2_i32, { "r", "r", "ri", "ri" } }, { INDEX_op_setcond2_i32, { "r", "r", "r", "ri", "ri" } }, @@ -2362,6 +2392,11 @@ static void tcg_target_init(TCGContext *s) available, we'll use a small forward branch. */ have_cmov = (d & bit_CMOV) != 0; #endif +#ifndef have_sse2 + /* Likewise, almost all hardware supports SSE2, but we do + have a locked memory operation to use as a substitute. */ + have_sse2 = (d & bit_SSE2) != 0; +#endif #ifndef have_movbe /* MOVBE is only available on Intel Atom and Haswell CPUs, so we need to probe for it. */