From patchwork Mon Dec 10 17:24:14 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 204993 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 928AB2C032F for ; Tue, 11 Dec 2012 04:24:39 +1100 (EST) Received: from localhost ([::1]:53899 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ti75o-00088a-E3 for incoming@patchwork.ozlabs.org; Mon, 10 Dec 2012 12:24:36 -0500 Received: from eggs.gnu.org ([208.118.235.92]:48976) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ti75e-00086d-GI for qemu-devel@nongnu.org; Mon, 10 Dec 2012 12:24:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ti75W-0001VP-V3 for qemu-devel@nongnu.org; Mon, 10 Dec 2012 12:24:26 -0500 Received: from mail-ia0-f171.google.com ([209.85.210.171]:46222) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ti75W-0001VJ-Nm for qemu-devel@nongnu.org; Mon, 10 Dec 2012 12:24:18 -0500 Received: by mail-ia0-f171.google.com with SMTP id k27so5286695iad.16 for ; Mon, 10 Dec 2012 09:24:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer; bh=Kj1hfpKeiSMfufMl6EHiZ6LmrvH9x89oHnz+jl0LEj0=; b=JyzVj54v2/lkEhsfyLbEciDqAiztyzPFe646Y7cQ033n/Afa6RixBvOfJnHXUiWAhf vt8eOr2XfLwc+FTn8TYtaz2PI1zKnJyhpd5iqha27KVhj9/iKyb8pg8wxz9jpSbHo6XE VuRRFEEAqqxeL7y8x2JkflpRoWYlfA8ebMfdzPoT4DbPCfEqTDKHovpxrcKE6uL/j+M3 nGZzP8Hk+g5ldmPDYB0ZcRo87u+W0QH79CENNnzWOmINPGlcLpCVDcQipNngOx3GoiH9 oIOLLMRg31Zk2Xwm7TiHIVQJhihahh5q+WmbFoTdcAoVmqkofXBK0tEISQSzSWxX6VX5 upFw== Received: by 10.50.85.170 with SMTP id i10mr7354941igz.14.1355160258109; Mon, 10 Dec 2012 09:24:18 -0800 (PST) Received: from anchor.twiddle.home.com (50-194-63-110-static.hfc.comcastbusiness.net. [50.194.63.110]) by mx.google.com with ESMTPS id ww6sm6388011igb.2.2012.12.10.09.24.16 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 10 Dec 2012 09:24:17 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 10 Dec 2012 09:24:14 -0800 Message-Id: <1355160254-20637-1-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 1.7.11.7 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.210.171 Cc: Peter Maydell , Aurelien Jarno Subject: [Qemu-devel] [PATCH v2] tcg-i386: Perform cmov detection at runtime for 32-bit. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Cc: Aurelien Jarno Cc: Peter Maydell Signed-off-by: Richard Henderson --- configure | 19 +++++++++++++++++++ tcg/i386/tcg-target.c | 31 ++++++++++++++++++++++++++++++- tcg/i386/tcg-target.h | 5 ----- 3 files changed, 49 insertions(+), 6 deletions(-) Changes v1->v2: * Configure-time detection for cpuid.h. * Don't do any checking for preprocessor defines that "imply" cmov. r~ diff --git a/configure b/configure index e5aedef..1231600 100755 --- a/configure +++ b/configure @@ -3071,6 +3071,21 @@ if compile_prog "" "" ; then has_environ=yes fi +######################################## +# check if cpuid.h is usable. + +cpuid_h=no +cat > $TMPC << EOF +#include +int main(void) { + return 0; +} +EOF +if compile_prog "" "" ; then + cpuid_h=yes +fi + + ########################################## # End of CC checks # After here, no more $cc or $ld runs @@ -3601,6 +3616,10 @@ if test "$has_environ" = "yes" ; then echo "CONFIG_HAS_ENVIRON=y" >> $config_host_mak fi +if test "$cpuid_h" = "yes" ; then + echo "CONFIG_CPUID_H=y" >> $config_host_mak +fi + if test "$glusterfs" = "yes" ; then echo "CONFIG_GLUSTERFS=y" >> $config_host_mak fi diff --git a/tcg/i386/tcg-target.c b/tcg/i386/tcg-target.c index 6f3ad3c..8d603a5 100644 --- a/tcg/i386/tcg-target.c +++ b/tcg/i386/tcg-target.c @@ -97,6 +97,18 @@ static const int tcg_target_call_oarg_regs[] = { # define TCG_REG_L1 TCG_REG_EDX #endif +/* For 32-bit, we are going to attempt to determine at runtime whether cmov + is available. However, the host compiler must supply , as we're + not going to go so far as our own inline assembly. */ +#if TCG_TARGET_REG_BITS == 64 +# define have_cmov 1 +#elif defined(CONFIG_CPUID_H) +#include +static bool have_cmov; +#else +# define have_cmov 0 +#endif + static uint8_t *tb_ret_addr; static void patch_reloc(uint8_t *code_ptr, int type, @@ -943,7 +955,14 @@ static void tcg_out_movcond32(TCGContext *s, TCGCond cond, TCGArg dest, TCGArg v1) { tcg_out_cmp(s, c1, c2, const_c2, 0); - tcg_out_modrm(s, OPC_CMOVCC | tcg_cond_to_jcc[cond], dest, v1); + if (have_cmov) { + tcg_out_modrm(s, OPC_CMOVCC | tcg_cond_to_jcc[cond], dest, v1); + } else { + int over = gen_new_label(); + tcg_out_jxx(s, tcg_cond_to_jcc[tcg_invert_cond(cond)], over, 1); + tcg_out_mov(s, TCG_TYPE_I32, dest, v1); + tcg_out_label(s, over, s->code_ptr); + } } #if TCG_TARGET_REG_BITS == 64 @@ -2243,6 +2262,16 @@ static void tcg_target_qemu_prologue(TCGContext *s) static void tcg_target_init(TCGContext *s) { + /* For 32-bit, 99% certainty that we're running on hardware that supports + cmov, but we still need to check. In case cmov is not available, we'll + use a small forward branch. */ +#ifndef have_cmov + { + unsigned a, b, c, d; + have_cmov = (__get_cpuid(1, &a, &b, &c, &d) && (d & bit_CMOV)); + } +#endif + #if !defined(CONFIG_USER_ONLY) /* fail safe */ if ((1 << CPU_TLB_ENTRY_BITS) != sizeof(CPUTLBEntry)) diff --git a/tcg/i386/tcg-target.h b/tcg/i386/tcg-target.h index dbc6756..450078b 100644 --- a/tcg/i386/tcg-target.h +++ b/tcg/i386/tcg-target.h @@ -90,12 +90,7 @@ typedef enum { #define TCG_TARGET_HAS_nand_i32 0 #define TCG_TARGET_HAS_nor_i32 0 #define TCG_TARGET_HAS_deposit_i32 1 -#if defined(__x86_64__) || defined(__i686__) -/* Use cmov only if the compiler is already doing so. */ #define TCG_TARGET_HAS_movcond_i32 1 -#else -#define TCG_TARGET_HAS_movcond_i32 0 -#endif #if TCG_TARGET_REG_BITS == 64 #define TCG_TARGET_HAS_div2_i64 1