From patchwork Tue Nov 20 12:15:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 151578 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp536091ljp; Tue, 20 Nov 2018 04:21:25 -0800 (PST) X-Google-Smtp-Source: AJdET5cL4USlzGHnbe2P9yDvLw3t93UUsf9tv4xfyBglctGwOzfl8W6WFQOVCZynY9W8aYAMktM/ X-Received: by 2002:a0d:df85:: with SMTP id i127mr1504738ywe.125.1542716485841; Tue, 20 Nov 2018 04:21:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542716485; cv=none; d=google.com; s=arc-20160816; b=sdPC2p5lHtx1pT8S/lA4plQUT7QxhtdWMzK9/N+rPI5XtDfmHtf18OpojCyE0el9U/ tR6rcE2f2bdtm8lBowoewt6X56TSH8W2qoxLGT44WCADv5FCsvsqPxVKagRyQ7cpFo99 1wxgu1bell2KAqc1LvjyHUyPQHd1xpoFkLrpVMWbWoSOY8ymOBNYigLFJuC+3BrepJlG YjIj0tbBE/V+mpjvAz8S7vvyohSEuiEe7HC+RGEny+/BFgmwE0W/SHnnWHs+K92D7bc7 J13+xJQFTKbFar0vWdMCmjzT7YCaNbaJwlG0vE1OIcrsEd5CwIuQPuejaqH/6GzDAii6 qxQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=e3EmH68WadAw/qnOzSoJTL4P+UKvkirDo0hQAqlSqhk=; b=XigYCkT71Bw63uAPTg/upvkr+A9lQco2H3V8LgqsQAtrk6+vB17pjEP8m3LOknCxg2 5BAuUSjSiNSKLHXbBEa1FNgEiO/PUJY4Lixvc+q0T3bpA9ZJuI+E/if30m1YfwBBj97Q njJX7eHJ9Y+AspiX2N8dd0oDqo2jCouy3jAmBV5oQ3FEjWQ9MW3Ckke2e2D4I6kX9z9h Sl0eedbc4W5UGmW/VWRbWYNLFgwc51gaqs4helqSO3nfPvHydOsi/TeputADekYbmHhD iZK5hzX8/gqDD9gVVeEOxurCWu8ALBsD+Q4ualgHONUcQs3HQFyf9X4B4Oz4u3vJvSBL 9Zew== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=PAk6vUQA; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id d16-v6si27509582ybe.281.2018.11.20.04.21.25 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 20 Nov 2018 04:21:25 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=PAk6vUQA; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:33375 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gP51x-0005eX-6E for patch@linaro.org; Tue, 20 Nov 2018 07:21:25 -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) 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-Received: by 2002:a62:9402:: with SMTP id m2mr1944152pfe.34.1542716180477; Tue, 20 Nov 2018 04:16:20 -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) 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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(-) -- 2.17.2 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; /* optional instructions */ #define TCG_TARGET_HAS_div2_i32 1 @@ -219,7 +220,7 @@ static inline void tb_target_set_jmp_target(uintptr_t tc_ptr, #define TCG_TARGET_DEFAULT_MO (TCG_MO_ALL & ~TCG_MO_ST_LD) -#define TCG_TARGET_HAS_MEMORY_BSWAP 1 +#define TCG_TARGET_HAS_MEMORY_BSWAP have_movbe #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; #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, TCGReg datalo, TCGReg datahi, TCGReg base, int index, intptr_t ofs, int seg, TCGMemOp memop) { - const TCGMemOp real_bswap = memop & MO_BSWAP; - TCGMemOp bswap = real_bswap; + bool need_bswap = memop & MO_BSWAP; int movop = OPC_MOVL_GvEv; - if (have_movbe && real_bswap) { - bswap = 0; + if (need_bswap) { + tcg_debug_assert(have_movbe); movop = OPC_MOVBE_GyMy; } @@ -1903,46 +1901,41 @@ static void tcg_out_qemu_ld_direct(TCGContext *s, TCGReg 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 != base && datalo != 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 + seg, - 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, ofs); - if (bswap) { - tcg_out_bswap32(s, datalo); - } break; #if TCG_TARGET_REG_BITS == 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, TCGReg datalo, TCGReg datahi, if (TCG_TARGET_REG_BITS == 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 = datalo; + if (need_bswap) { + TCGReg t = datalo; datalo = datahi; datahi = t; } @@ -1970,14 +1960,10 @@ static void tcg_out_qemu_ld_direct(TCGContext *s, TCGReg 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(); } } @@ -2053,17 +2039,11 @@ static void tcg_out_qemu_st_direct(TCGContext *s, TCGReg 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 = TCG_REG_L0; - const TCGMemOp real_bswap = memop & MO_BSWAP; - TCGMemOp bswap = real_bswap; + bool need_bswap = memop & MO_BSWAP; int movop = OPC_MOVL_EvGv; - if (have_movbe && real_bswap) { - bswap = 0; + if (need_bswap) { + tcg_debug_assert(have_movbe); movop = OPC_MOVBE_MyGy; } @@ -2072,46 +2052,24 @@ static void tcg_out_qemu_st_direct(TCGContext *s, TCGReg 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 == 32 && datalo >= 4) { - tcg_out_mov(s, TCG_TYPE_I32, scratch, datalo); - datalo = scratch; + tcg_out_mov(s, TCG_TYPE_I32, TCG_REG_L0, datalo); + datalo = 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 = 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 = scratch; - } tcg_out_modrm_offset(s, movop + seg, datalo, base, ofs); break; case MO_64: if (TCG_TARGET_REG_BITS == 64) { - if (bswap) { - tcg_out_mov(s, TCG_TYPE_I64, scratch, datalo); - tcg_out_bswap64(s, scratch); - datalo = scratch; - } tcg_out_modrm_offset(s, movop + P_REXW + seg, datalo, base, ofs); - } 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, ofs); - 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, ofs+4); } else { - if (real_bswap) { - int t = datalo; + if (need_bswap) { + TCGReg t = datalo; datalo = datahi; datahi = t; } @@ -2120,7 +2078,7 @@ static void tcg_out_qemu_st_direct(TCGContext *s, TCGReg datalo, TCGReg datahi, } break; default: - tcg_abort(); + g_assert_not_reached(); } }