From nobody Thu Nov 6 18:22:12 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1542716523963242.06879464028736; Tue, 20 Nov 2018 04:22:03 -0800 (PST) Received: from localhost ([::1]:33380 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gP52Y-0005vq-SX for importer@patchew.org; Tue, 20 Nov 2018 07:22:02 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43708) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gP4x7-0001mG-53 for qemu-devel@nongnu.org; Tue, 20 Nov 2018 07:16:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gP4x4-00052Q-1T for qemu-devel@nongnu.org; Tue, 20 Nov 2018 07:16:25 -0500 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:41392) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gP4x3-000523-Q0 for qemu-devel@nongnu.org; Tue, 20 Nov 2018 07:16:21 -0500 Received: by mail-pg1-x542.google.com with SMTP id 70so826761pgh.8 for ; Tue, 20 Nov 2018 04:16:21 -0800 (PST) Received: from cloudburst.twiddle.net ([172.56.31.89]) by smtp.gmail.com with ESMTPSA id p11sm39244346pgn.60.2018.11.20.04.16.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Nov 2018 04:16:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=e3EmH68WadAw/qnOzSoJTL4P+UKvkirDo0hQAqlSqhk=; b=PAk6vUQAdGa5Rx+w8evqlbdzlQwwKkl5Z6qDHBTiLX2XdrSLQyzLZYAMDNhTHipmfG ZGR/HcHXp9599aEKwck9C+OlhZkXzdq+KRCUG2yBpb6AqT5iP/FgVAfhljdCrteI5roU vHZ1qrnSyXzxNboupQeXXpJXtOORkeC38kx0I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=e3EmH68WadAw/qnOzSoJTL4P+UKvkirDo0hQAqlSqhk=; b=LYhB/fnSjQzmB6ncfQnqHLhyGM8PhuGdRrPY424VNu/gyMNJvH6P0NfPvju/f9VF9k ESVTttKejyhD/wr8U6uDK/XachY+1yBbQ+qJGNCg8tmc4qgp7JXKeb5fMLCqwsmmUfMi sN474C2G2nMoed7PW1HlIqgmomIqP156AOALAWgSpFxQtxugnkZ6pF0tb0C46axWcwHn jCkVKXd+afEiIrx2CjhGxQnrB/JXeY1zFpIozDtbv8gU5eRxfmIY5HS7tc9APBzssmnP QXuvn6d7dCpIUAT4X4jWOtmNFjX3txo4ogv9EK3x/M1pQAiw/CdPvkNP3HRM+kOvGfaP hV+g== X-Gm-Message-State: AGRZ1gJBNc9EZnEicRaGC4B89NrzeaUz3HmP5vq8Yq4pKx1ULutgdsl5 sZFoYisTsAvqzmjXnPAHHmzZ4pb1LHBuJA== X-Google-Smtp-Source: AJdET5e0aih3wGbx8keCoMKiGjzWqBJ7qOziGS3s4Uu/6BMafZrM5ZK0enND9VHrjQzTMKRsE1B9Rg== X-Received: by 2002:a62:9402:: with SMTP id m2mr1944152pfe.34.1542716180477; Tue, 20 Nov 2018 04:16:20 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 20 Nov 2018 13:15:56 +0100 Message-Id: <20181120121558.7660-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20181120121558.7660-1-richard.henderson@linaro.org> References: <20181120121558.7660-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::542 Subject: [Qemu-devel] [PATCH 3/5] tcg/i386: Set TCG_TARGET_HAS_MEMORY_BSWAP with have_movbe 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: Alistair.Francis@wdc.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This allows us to remove some code from the backend, allowing the generic code to emit any extra bswaps. This does not quite allow all of the cleanup that should be possible, as we still must take care of i386 storing bytes from non 'q' registers. Signed-off-by: Richard Henderson --- tcg/i386/tcg-target.h | 3 +- tcg/i386/tcg-target.inc.c | 112 ++++++++++++-------------------------- 2 files changed, 37 insertions(+), 78 deletions(-) diff --git a/tcg/i386/tcg-target.h b/tcg/i386/tcg-target.h index b1b861f8f2..ed2d5d4441 100644 --- a/tcg/i386/tcg-target.h +++ b/tcg/i386/tcg-target.h @@ -101,6 +101,7 @@ extern bool have_bmi1; extern bool have_popcnt; extern bool have_avx1; extern bool have_avx2; +extern bool have_movbe; =20 /* optional instructions */ #define TCG_TARGET_HAS_div2_i32 1 @@ -219,7 +220,7 @@ static inline void tb_target_set_jmp_target(uintptr_t t= c_ptr, =20 #define TCG_TARGET_DEFAULT_MO (TCG_MO_ALL & ~TCG_MO_ST_LD) =20 -#define TCG_TARGET_HAS_MEMORY_BSWAP 1 +#define TCG_TARGET_HAS_MEMORY_BSWAP have_movbe =20 #ifdef CONFIG_SOFTMMU #define TCG_TARGET_NEED_LDST_LABELS diff --git a/tcg/i386/tcg-target.inc.c b/tcg/i386/tcg-target.inc.c index 436195894b..14e1cf9eee 100644 --- a/tcg/i386/tcg-target.inc.c +++ b/tcg/i386/tcg-target.inc.c @@ -154,13 +154,12 @@ bool have_bmi1; bool have_popcnt; bool have_avx1; bool have_avx2; +bool have_movbe; =20 #ifdef CONFIG_CPUID_H -static bool have_movbe; static bool have_bmi2; static bool have_lzcnt; #else -# define have_movbe 0 # define have_bmi2 0 # define have_lzcnt 0 #endif @@ -1884,12 +1883,11 @@ static void tcg_out_qemu_ld_direct(TCGContext *s, T= CGReg datalo, TCGReg datahi, TCGReg base, int index, intptr_t ofs, int seg, TCGMemOp memop) { - const TCGMemOp real_bswap =3D memop & MO_BSWAP; - TCGMemOp bswap =3D real_bswap; + bool need_bswap =3D memop & MO_BSWAP; int movop =3D OPC_MOVL_GvEv; =20 - if (have_movbe && real_bswap) { - bswap =3D 0; + if (need_bswap) { + tcg_debug_assert(have_movbe); movop =3D OPC_MOVBE_GyMy; } =20 @@ -1903,46 +1901,41 @@ static void tcg_out_qemu_ld_direct(TCGContext *s, T= CGReg datalo, TCGReg datahi, base, index, 0, ofs); break; case MO_UW: - tcg_out_modrm_sib_offset(s, OPC_MOVZWL + seg, datalo, + if (!need_bswap) { + tcg_out_modrm_sib_offset(s, OPC_MOVZWL + seg, datalo, base, index, 0, ofs); - if (real_bswap) { - tcg_out_rolw_8(s, datalo); + } else if (datalo !=3D base && datalo !=3D index) { + tcg_out_movi(s, TCG_TYPE_I32, datalo, 0); + tcg_out_modrm_sib_offset(s, OPC_MOVBE_GyMy + P_DATA16 + seg, + datalo, base, index, 0, ofs); + } else { + tcg_out_modrm_sib_offset(s, OPC_MOVBE_GyMy + P_DATA16 + seg, + datalo, base, index, 0, ofs); + tcg_out_ext16u(s, datalo, datalo); } break; case MO_SW: - if (real_bswap) { - if (have_movbe) { - tcg_out_modrm_sib_offset(s, OPC_MOVBE_GyMy + P_DATA16 + se= g, - datalo, base, index, 0, ofs); - } else { - tcg_out_modrm_sib_offset(s, OPC_MOVZWL + seg, datalo, - base, index, 0, ofs); - tcg_out_rolw_8(s, datalo); - } - tcg_out_modrm(s, OPC_MOVSWL + P_REXW, datalo, datalo); - } else { + if (!need_bswap) { tcg_out_modrm_sib_offset(s, OPC_MOVSWL + P_REXW + seg, datalo, base, index, 0, ofs); + } else { + tcg_out_modrm_sib_offset(s, OPC_MOVBE_GyMy + P_DATA16 + seg, + datalo, base, index, 0, ofs); + tcg_out_ext16s(s, datalo, datalo, P_REXW); } break; case MO_UL: tcg_out_modrm_sib_offset(s, movop + seg, datalo, base, index, 0, o= fs); - if (bswap) { - tcg_out_bswap32(s, datalo); - } break; #if TCG_TARGET_REG_BITS =3D=3D 64 case MO_SL: - if (real_bswap) { - tcg_out_modrm_sib_offset(s, movop + seg, datalo, - base, index, 0, ofs); - if (bswap) { - tcg_out_bswap32(s, datalo); - } - tcg_out_ext32s(s, datalo, datalo); - } else { + if (!need_bswap) { tcg_out_modrm_sib_offset(s, OPC_MOVSLQ + seg, datalo, base, index, 0, ofs); + } else { + tcg_out_modrm_sib_offset(s, OPC_MOVBE_GyMy + seg, datalo, + base, index, 0, ofs); + tcg_out_ext32s(s, datalo, datalo); } break; #endif @@ -1950,12 +1943,9 @@ static void tcg_out_qemu_ld_direct(TCGContext *s, TC= GReg datalo, TCGReg datahi, if (TCG_TARGET_REG_BITS =3D=3D 64) { tcg_out_modrm_sib_offset(s, movop + P_REXW + seg, datalo, base, index, 0, ofs); - if (bswap) { - tcg_out_bswap64(s, datalo); - } } else { - if (real_bswap) { - int t =3D datalo; + if (need_bswap) { + TCGReg t =3D datalo; datalo =3D datahi; datahi =3D t; } @@ -1970,14 +1960,10 @@ static void tcg_out_qemu_ld_direct(TCGContext *s, T= CGReg datalo, TCGReg datahi, tcg_out_modrm_sib_offset(s, movop + seg, datalo, base, index, 0, ofs); } - if (bswap) { - tcg_out_bswap32(s, datalo); - tcg_out_bswap32(s, datahi); - } } break; default: - tcg_abort(); + g_assert_not_reached(); } } =20 @@ -2053,17 +2039,11 @@ static void tcg_out_qemu_st_direct(TCGContext *s, T= CGReg datalo, TCGReg datahi, TCGReg base, intptr_t ofs, int seg, TCGMemOp memop) { - /* ??? Ideally we wouldn't need a scratch register. For user-only, - we could perform the bswap twice to restore the original value - instead of moving to the scratch. But as it is, the L constraint - means that TCG_REG_L0 is definitely free here. */ - const TCGReg scratch =3D TCG_REG_L0; - const TCGMemOp real_bswap =3D memop & MO_BSWAP; - TCGMemOp bswap =3D real_bswap; + bool need_bswap =3D memop & MO_BSWAP; int movop =3D OPC_MOVL_EvGv; =20 - if (have_movbe && real_bswap) { - bswap =3D 0; + if (need_bswap) { + tcg_debug_assert(have_movbe); movop =3D OPC_MOVBE_MyGy; } =20 @@ -2072,46 +2052,24 @@ static void tcg_out_qemu_st_direct(TCGContext *s, T= CGReg datalo, TCGReg datahi, /* In 32-bit mode, 8-bit stores can only happen from [abcd]x. Use the scratch register if necessary. */ if (TCG_TARGET_REG_BITS =3D=3D 32 && datalo >=3D 4) { - tcg_out_mov(s, TCG_TYPE_I32, scratch, datalo); - datalo =3D scratch; + tcg_out_mov(s, TCG_TYPE_I32, TCG_REG_L0, datalo); + datalo =3D TCG_REG_L0; } tcg_out_modrm_offset(s, OPC_MOVB_EvGv + P_REXB_R + seg, datalo, base, ofs); break; case MO_16: - if (bswap) { - tcg_out_mov(s, TCG_TYPE_I32, scratch, datalo); - tcg_out_rolw_8(s, scratch); - datalo =3D scratch; - } tcg_out_modrm_offset(s, movop + P_DATA16 + seg, datalo, base, ofs); break; case MO_32: - if (bswap) { - tcg_out_mov(s, TCG_TYPE_I32, scratch, datalo); - tcg_out_bswap32(s, scratch); - datalo =3D scratch; - } tcg_out_modrm_offset(s, movop + seg, datalo, base, ofs); break; case MO_64: if (TCG_TARGET_REG_BITS =3D=3D 64) { - if (bswap) { - tcg_out_mov(s, TCG_TYPE_I64, scratch, datalo); - tcg_out_bswap64(s, scratch); - datalo =3D scratch; - } tcg_out_modrm_offset(s, movop + P_REXW + seg, datalo, base, of= s); - } else if (bswap) { - tcg_out_mov(s, TCG_TYPE_I32, scratch, datahi); - tcg_out_bswap32(s, scratch); - tcg_out_modrm_offset(s, OPC_MOVL_EvGv + seg, scratch, base, of= s); - tcg_out_mov(s, TCG_TYPE_I32, scratch, datalo); - tcg_out_bswap32(s, scratch); - tcg_out_modrm_offset(s, OPC_MOVL_EvGv + seg, scratch, base, of= s+4); } else { - if (real_bswap) { - int t =3D datalo; + if (need_bswap) { + TCGReg t =3D datalo; datalo =3D datahi; datahi =3D t; } @@ -2120,7 +2078,7 @@ static void tcg_out_qemu_st_direct(TCGContext *s, TCG= Reg datalo, TCGReg datahi, } break; default: - tcg_abort(); + g_assert_not_reached(); } } =20 --=20 2.17.2