From patchwork Sat Dec 24 03:59:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 708572 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tlsK23pqmz9sfH for ; Sat, 24 Dec 2016 15:11:50 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="YDKyw7c8"; dkim-atps=neutral Received: from localhost ([::1]:41912 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cKdgS-0007ZF-86 for incoming@patchwork.ozlabs.org; Fri, 23 Dec 2016 23:11:48 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55198) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cKdVr-0006Qz-5j for qemu-devel@nongnu.org; Fri, 23 Dec 2016 23:00:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cKdVq-0005Tq-9y for qemu-devel@nongnu.org; Fri, 23 Dec 2016 23:00:51 -0500 Received: from mail-pg0-x241.google.com ([2607:f8b0:400e:c05::241]:35829) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cKdVq-0005So-3I for qemu-devel@nongnu.org; Fri, 23 Dec 2016 23:00:50 -0500 Received: by mail-pg0-x241.google.com with SMTP id i5so2479495pgh.2 for ; Fri, 23 Dec 2016 20:00:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=Af8RPHvVs0is56OQDAQwRCCN5ZpRxtCGoEZOiM1u4Ow=; b=YDKyw7c8UzVNLPvE3laZjUp1LfQRUw602uqOtShd/6KVpNRiEyxiON7mqmwn4uahro f5flkxrWQQDbCUIT4xD8qGBVljOXuqtOsfzy1jmvVoWMH8/rIdsWWRs5cICw4JUDl2Vj AanxeB0xVq0M0vdJ8yy6r8o6aLy1KELdx6o5uJQ1Xo1q5Y8K4HyuEShKTHRvcvgwDJi5 9BcxdEZUww0MOFkrc/08h7KyrfAHzfDcBcq4pp0Ow1iSiGlqQ/ECJjGcKt7MVTSetJ0J qkKrCJ/j8TjYf1FQt/c7uxkNuhM/vd66oa5AgnoJ9BccGwYhmJD2NL21nBxbAlTvdtyz o2Uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=Af8RPHvVs0is56OQDAQwRCCN5ZpRxtCGoEZOiM1u4Ow=; b=eT77G19VqdTH7KrfWVqOqrWYPq8/PkH5cYfuwroivop5v/yn0DGL94TlKaQbcJZM28 uWJQ4z3jaNSfNNk/5kRRdmzmqvVV7JCe6FzznlarNhH2oepYH//kWtsAWONJ8mqNqbo7 xK4pBY9+DFGv+GbClst7tWinBNI3JYbomlsl05795CXobJMs8M8k2hv3A5QOtgATEaMx EiF8CfPWLxwjxwcv5kX4ImMqEwPhmEc5enyZQcwskrm8BaalybmlSnu5C4mzcecJHu6+ RkXwggXbcZ5RuFyQ68OaFk0kcopx9dFwabA/VuFJzx3XPd3+dVg422f7kv8F3w1XJqZC fSgQ== X-Gm-Message-State: AIkVDXIq+OkqLUlKaH9EHULsAhw46qXksibv6c6KPsUm9wspYYVaL+OFFPtnlvbFgbEU+Q== X-Received: by 10.84.172.131 with SMTP id n3mr34999765plb.5.1482552049112; Fri, 23 Dec 2016 20:00:49 -0800 (PST) Received: from bigtime.domain ([2602:47:d954:1500:5e51:4fff:fe40:9c64]) by smtp.gmail.com with ESMTPSA id n25sm65339316pfi.33.2016.12.23.20.00.48 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Dec 2016 20:00:48 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 23 Dec 2016 19:59:44 -0800 Message-Id: <20161224040042.12654-8-rth@twiddle.net> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20161224040042.12654-1-rth@twiddle.net> References: <20161224040042.12654-1-rth@twiddle.net> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c05::241 Subject: [Qemu-devel] [PATCH 07/65] tcg/i386: Implement field extraction opcodes 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: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Richard Henderson --- tcg/i386/tcg-target.h | 12 +++++++++--- tcg/i386/tcg-target.inc.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/tcg/i386/tcg-target.h b/tcg/i386/tcg-target.h index 7625188..dc19c47 100644 --- a/tcg/i386/tcg-target.h +++ b/tcg/i386/tcg-target.h @@ -94,8 +94,8 @@ extern bool have_bmi1; #define TCG_TARGET_HAS_nand_i32 0 #define TCG_TARGET_HAS_nor_i32 0 #define TCG_TARGET_HAS_deposit_i32 1 -#define TCG_TARGET_HAS_extract_i32 0 -#define TCG_TARGET_HAS_sextract_i32 0 +#define TCG_TARGET_HAS_extract_i32 1 +#define TCG_TARGET_HAS_sextract_i32 1 #define TCG_TARGET_HAS_movcond_i32 1 #define TCG_TARGET_HAS_add2_i32 1 #define TCG_TARGET_HAS_sub2_i32 1 @@ -126,7 +126,7 @@ extern bool have_bmi1; #define TCG_TARGET_HAS_nand_i64 0 #define TCG_TARGET_HAS_nor_i64 0 #define TCG_TARGET_HAS_deposit_i64 1 -#define TCG_TARGET_HAS_extract_i64 0 +#define TCG_TARGET_HAS_extract_i64 1 #define TCG_TARGET_HAS_sextract_i64 0 #define TCG_TARGET_HAS_movcond_i64 1 #define TCG_TARGET_HAS_add2_i64 1 @@ -142,6 +142,12 @@ extern bool have_bmi1; ((ofs) == 0 && (len) == 16)) #define TCG_TARGET_deposit_i64_valid TCG_TARGET_deposit_i32_valid +/* Check for the possibility of high-byte extraction and, for 64-bit, + zero-extending 32-bit right-shift. */ +#define TCG_TARGET_extract_i32_valid(ofs, len) ((ofs) == 8 && (len) == 8) +#define TCG_TARGET_extract_i64_valid(ofs, len) \ + (((ofs) == 8 && (len) == 8) || ((ofs) + (len)) == 32) + #if TCG_TARGET_REG_BITS == 64 # define TCG_AREG0 TCG_REG_R14 #else diff --git a/tcg/i386/tcg-target.inc.c b/tcg/i386/tcg-target.inc.c index eeb1777..39f62bd 100644 --- a/tcg/i386/tcg-target.inc.c +++ b/tcg/i386/tcg-target.inc.c @@ -2143,6 +2143,40 @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc, } break; + case INDEX_op_extract_i64: + if (args[2] + args[3] == 32) { + /* This is a 32-bit zero-extending right shift. */ + tcg_out_mov(s, TCG_TYPE_I32, args[0], args[1]); + tcg_out_shifti(s, SHIFT_SHR, args[0], args[2]); + break; + } + /* FALLTHRU */ + case INDEX_op_extract_i32: + /* On the off-chance that we can use the high-byte registers. + Otherwise we emit the same ext16 + shift pattern that we + would have gotten from the normal tcg-op.c expansion. */ + tcg_debug_assert(args[2] == 8 && args[3] == 8); + if (args[1] < 4 && args[0] < 8) { + tcg_out_modrm(s, OPC_MOVZBL, args[0], args[1] + 4); + } else { + tcg_out_ext16u(s, args[0], args[1]); + tcg_out_shifti(s, SHIFT_SHR, args[0], 8); + } + break; + + case INDEX_op_sextract_i32: + /* We don't implement sextract_i64, as we cannot sign-extend to + 64-bits without using the REX prefix that explicitly excludes + access to the high-byte registers. */ + tcg_debug_assert(args[2] == 8 && args[3] == 8); + if (args[1] < 4 && args[0] < 8) { + tcg_out_modrm(s, OPC_MOVSBL, args[0], args[1] + 4); + } else { + tcg_out_ext16s(s, args[0], args[1], 0); + tcg_out_shifti(s, SHIFT_SAR, args[0], 8); + } + break; + case INDEX_op_mb: tcg_out_mb(s, args[0]); break; @@ -2204,6 +2238,9 @@ static const TCGTargetOpDef x86_op_defs[] = { { INDEX_op_setcond_i32, { "q", "r", "ri" } }, { INDEX_op_deposit_i32, { "Q", "0", "Q" } }, + { INDEX_op_extract_i32, { "r", "r" } }, + { INDEX_op_sextract_i32, { "r", "r" } }, + { INDEX_op_movcond_i32, { "r", "r", "ri", "r", "0" } }, { INDEX_op_mulu2_i32, { "a", "d", "a", "r" } }, @@ -2265,6 +2302,7 @@ static const TCGTargetOpDef x86_op_defs[] = { { INDEX_op_extu_i32_i64, { "r", "r" } }, { INDEX_op_deposit_i64, { "Q", "0", "Q" } }, + { INDEX_op_extract_i64, { "r", "r" } }, { INDEX_op_movcond_i64, { "r", "r", "re", "r", "0" } }, { INDEX_op_mulu2_i64, { "a", "d", "a", "r" } },