From patchwork Thu Dec 8 11:36:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 9466177 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 1F56F60231 for ; Thu, 8 Dec 2016 11:38:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1932228448 for ; Thu, 8 Dec 2016 11:38:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0D947284ED; Thu, 8 Dec 2016 11:38:24 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 087B828448 for ; Thu, 8 Dec 2016 11:38:23 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cEwzo-0001mh-Td; Thu, 08 Dec 2016 11:36:16 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cEwzn-0001mU-So for xen-devel@lists.xenproject.org; Thu, 08 Dec 2016 11:36:16 +0000 Received: from [85.158.137.68] by server-9.bemta-3.messagelabs.com id 7F/90-08915-FA549485; Thu, 08 Dec 2016 11:36:15 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrBIsWRWlGSWpSXmKPExsXS6fjDS3etq2e EwYyl6hbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8a+vT9YCva0MVasuXeFsYGxNaiLkZNDSCBP YtPqT4wgNq+AncSOrXvZQGwJAUOJp++vg9ksAqoSj7d2M4PYbALqEm3PtrN2MXJwiAgYSJw7m gRiMgvoS2xbxwJiCgu4Sjz5nQUx3E5i2YttLCA2p4C9xP4PD9lASngFBCX+7hAGCTMDlUzZPJ F1AiPPLITMLCQZCFtL4uGvWywQtrbEsoWvmWeBrZWWWP6PAyJsL3F6dh8jqhIQ20viwLI57As YOVYxahSnFpWlFukamuolFWWmZ5TkJmbm6BoaGOvlphYXJ6an5iQmFesl5+duYgSGKgMQ7GBc s93zEKMkB5OSKO+uCe4RQnxJ+SmVGYnFGfFFpTmpxYcYNTg4BLbtWn2BUYolLz8vVUmCt8/FM 0JIsCg1PbUiLTMHGE0wpRIcPEoivKogad7igsTc4sx0iNQpRkUpcd5JIAkBkERGaR5cGyyCLz HKSgnzMgIdJcRTkFqUm1mCKv+KUZyDUUmYdwnIFJ7MvBK46a+AFjMBLZ53wx1kcUkiQkqqgdH mS9GyUO6/hw/P5vS0i5iiNT85oblQcCJj4Ba2E5Panm+Kcf0WGctp3dR748EHxtPrvkRqHnza IHI+0bdd3qzXVPSQ/N4HsZrGGy8u3XfF72ivzLvyB7Lrf4rLFO1qE/drK3oTVeo2OZSZ+6N84 3+vQnarW07rN+4vn5zttOHRi7t1mdeTFyuxFGckGmoxFxUnAgCn7iKy2wIAAA== X-Env-Sender: JBeulich@suse.com X-Msg-Ref: server-5.tower-31.messagelabs.com!1481196971!71884020!1 X-Originating-IP: [137.65.248.74] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.0.16; banners=-,-,- X-VirusChecked: Checked Received: (qmail 12042 invoked from network); 8 Dec 2016 11:36:13 -0000 Received: from prv-mh.provo.novell.com (HELO prv-mh.provo.novell.com) (137.65.248.74) by server-5.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 8 Dec 2016 11:36:13 -0000 Received: from INET-PRV-MTA by prv-mh.provo.novell.com with Novell_GroupWise; Thu, 08 Dec 2016 04:36:11 -0700 Message-Id: <584953BB0200007800126A99@prv-mh.provo.novell.com> X-Mailer: Novell GroupWise Internet Agent 14.2.1 Date: Thu, 08 Dec 2016 04:36:11 -0700 From: "Jan Beulich" To: "xen-devel" References: <584951630200007800126A86@prv-mh.provo.novell.com> In-Reply-To: <584951630200007800126A86@prv-mh.provo.novell.com> Mime-Version: 1.0 Cc: Andrew Cooper Subject: [Xen-devel] [PATCH v2 2/6] x86emul: simplify FPU source operand handling X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Consistently use ea instead of src for passing the memory address to ->read(). This eliminates the need to copy ea to src, resulting in a couple of hundred bytes smaller binary size. In addition for opcode DE we can leverage SrcMem16 to eliminate a call of the ->read() hook. At the same time drop the stray Mov attributes from D8, DA, DC, and DE: They're meaningful for memory writes only. Signed-off-by: Jan Beulich Reviewed-by: Andrew Cooper x86emul: simplify FPU source operand handling Consistently use ea instead of src for passing the memory address to ->read(). This eliminates the need to copy ea to src, resulting in a couple of hundred bytes smaller binary size. In addition for opcode DE we can leverage SrcMem16 to eliminate a call of the ->read() hook. At the same time drop the stray Mov attributes from D8, DA, DC, and DE: They're meaningful for memory writes only. Signed-off-by: Jan Beulich Reviewed-by: Andrew Cooper --- a/xen/arch/x86/x86_emulate/x86_emulate.c +++ b/xen/arch/x86/x86_emulate/x86_emulate.c @@ -159,10 +159,10 @@ static const opcode_desc_t opcode_table[ ByteOp|DstMem|SrcImplicit|ModRM, DstMem|SrcImplicit|ModRM, DstImplicit|SrcImmByte, DstImplicit|SrcImmByte, ImplicitOps, ImplicitOps, /* 0xD8 - 0xDF */ - ImplicitOps|ModRM|Mov, ImplicitOps|ModRM|Mov, - ImplicitOps|ModRM|Mov, ImplicitOps|ModRM|Mov, - ImplicitOps|ModRM|Mov, ImplicitOps|ModRM|Mov, - ImplicitOps|ModRM|Mov, ImplicitOps|ModRM|Mov, + ImplicitOps|ModRM, ImplicitOps|ModRM|Mov, + ImplicitOps|ModRM, ImplicitOps|ModRM|Mov, + ImplicitOps|ModRM, ImplicitOps|ModRM|Mov, + DstImplicit|SrcMem16|ModRM, ImplicitOps|ModRM|Mov, /* 0xE0 - 0xE7 */ DstImplicit|SrcImmByte, DstImplicit|SrcImmByte, DstImplicit|SrcImmByte, DstImplicit|SrcImmByte, @@ -3589,10 +3589,8 @@ x86_emulate( break; default: ASSERT(ea.type == OP_MEM); - ea.bytes = 4; - src = ea; - if ( (rc = ops->read(src.mem.seg, src.mem.off, &src.val, - src.bytes, ctxt)) != 0 ) + if ( (rc = ops->read(ea.mem.seg, ea.mem.off, &src.val, + 4, ctxt)) != X86EMUL_OKAY ) goto done; switch ( modrm_reg & 7 ) { @@ -3668,10 +3666,8 @@ x86_emulate( switch ( modrm_reg & 7 ) { case 0: /* fld m32fp */ - ea.bytes = 4; - src = ea; if ( (rc = ops->read(ea.mem.seg, ea.mem.off, &src.val, - src.bytes, ctxt)) != 0 ) + 4, ctxt)) != X86EMUL_OKAY ) goto done; emulate_fpu_insn_memsrc("flds", src.val); break; @@ -3690,10 +3686,8 @@ x86_emulate( case 4: /* fldenv - TODO */ goto cannot_emulate; case 5: /* fldcw m2byte */ - ea.bytes = 2; - src = ea; - if ( (rc = ops->read(src.mem.seg, src.mem.off, &src.val, - src.bytes, ctxt)) != 0 ) + if ( (rc = ops->read(ea.mem.seg, ea.mem.off, &src.val, + 2, ctxt)) != X86EMUL_OKAY ) goto done; emulate_fpu_insn_memsrc("fldcw", src.val); break; @@ -3727,10 +3721,8 @@ x86_emulate( break; default: generate_exception_if(ea.type != OP_MEM, EXC_UD); - ea.bytes = 4; - src = ea; - if ( (rc = ops->read(src.mem.seg, src.mem.off, &src.val, - src.bytes, ctxt)) != 0 ) + if ( (rc = ops->read(ea.mem.seg, ea.mem.off, &src.val, + 4, ctxt)) != X86EMUL_OKAY ) goto done; switch ( modrm_reg & 7 ) { @@ -3788,10 +3780,8 @@ x86_emulate( switch ( modrm_reg & 7 ) { case 0: /* fild m32i */ - ea.bytes = 4; - src = ea; - if ( (rc = ops->read(src.mem.seg, src.mem.off, &src.val, - src.bytes, ctxt)) != 0 ) + if ( (rc = ops->read(ea.mem.seg, ea.mem.off, &src.val, + 4, ctxt)) != X86EMUL_OKAY ) goto done; emulate_fpu_insn_memsrc("fildl", src.val); break; @@ -3815,10 +3805,8 @@ x86_emulate( emulate_fpu_insn_memdst("fistpl", dst.val); break; case 5: /* fld m80fp */ - ea.bytes = 10; - src = ea; - if ( (rc = ops->read(src.mem.seg, src.mem.off, - &src.val, src.bytes, ctxt)) != 0 ) + if ( (rc = ops->read(ea.mem.seg, ea.mem.off, &src.val, + 10, ctxt)) != X86EMUL_OKAY ) goto done; emulate_fpu_insn_memsrc("fldt", src.val); break; @@ -3850,10 +3838,8 @@ x86_emulate( break; default: ASSERT(ea.type == OP_MEM); - ea.bytes = 8; - src = ea; - if ( (rc = ops->read(src.mem.seg, src.mem.off, &src.val, - src.bytes, ctxt)) != 0 ) + if ( (rc = ops->read(ea.mem.seg, ea.mem.off, &src.val, + 8, ctxt)) != X86EMUL_OKAY ) goto done; switch ( modrm_reg & 7 ) { @@ -3902,10 +3888,8 @@ x86_emulate( switch ( modrm_reg & 7 ) { case 0: /* fld m64fp */; - ea.bytes = 8; - src = ea; - if ( (rc = ops->read(src.mem.seg, src.mem.off, &src.val, - src.bytes, ctxt)) != 0 ) + if ( (rc = ops->read(ea.mem.seg, ea.mem.off, &src.val, + 8, ctxt)) != X86EMUL_OKAY ) goto done; emulate_fpu_insn_memsrc("fldl", src.val); break; @@ -3959,11 +3943,6 @@ x86_emulate( break; default: generate_exception_if(ea.type != OP_MEM, EXC_UD); - ea.bytes = 2; - src = ea; - if ( (rc = ops->read(src.mem.seg, src.mem.off, &src.val, - src.bytes, ctxt)) != 0 ) - goto done; switch ( modrm_reg & 7 ) { case 0: /* fiadd m16i */ @@ -4021,10 +4000,8 @@ x86_emulate( switch ( modrm_reg & 7 ) { case 0: /* fild m16i */ - ea.bytes = 2; - src = ea; - if ( (rc = ops->read(src.mem.seg, src.mem.off, &src.val, - src.bytes, ctxt)) != 0 ) + if ( (rc = ops->read(ea.mem.seg, ea.mem.off, &src.val, + 2, ctxt)) != X86EMUL_OKAY ) goto done; emulate_fpu_insn_memsrc("filds", src.val); break; @@ -4048,18 +4025,14 @@ x86_emulate( emulate_fpu_insn_memdst("fistps", dst.val); break; case 4: /* fbld m80dec */ - ea.bytes = 10; - src = ea; - if ( (rc = ops->read(src.mem.seg, src.mem.off, - &src.val, src.bytes, ctxt)) != 0 ) + if ( (rc = ops->read(ea.mem.seg, ea.mem.off, &src.val, + 10, ctxt)) != X86EMUL_OKAY ) goto done; emulate_fpu_insn_memsrc("fbld", src.val); break; case 5: /* fild m64i */ - ea.bytes = 8; - src = ea; - if ( (rc = ops->read(src.mem.seg, src.mem.off, &src.val, - src.bytes, ctxt)) != 0 ) + if ( (rc = ops->read(ea.mem.seg, ea.mem.off, &src.val, + 8, ctxt)) != X86EMUL_OKAY ) goto done; emulate_fpu_insn_memsrc("fildll", src.val); break; --- a/xen/arch/x86/x86_emulate/x86_emulate.c +++ b/xen/arch/x86/x86_emulate/x86_emulate.c @@ -159,10 +159,10 @@ static const opcode_desc_t opcode_table[ ByteOp|DstMem|SrcImplicit|ModRM, DstMem|SrcImplicit|ModRM, DstImplicit|SrcImmByte, DstImplicit|SrcImmByte, ImplicitOps, ImplicitOps, /* 0xD8 - 0xDF */ - ImplicitOps|ModRM|Mov, ImplicitOps|ModRM|Mov, - ImplicitOps|ModRM|Mov, ImplicitOps|ModRM|Mov, - ImplicitOps|ModRM|Mov, ImplicitOps|ModRM|Mov, - ImplicitOps|ModRM|Mov, ImplicitOps|ModRM|Mov, + ImplicitOps|ModRM, ImplicitOps|ModRM|Mov, + ImplicitOps|ModRM, ImplicitOps|ModRM|Mov, + ImplicitOps|ModRM, ImplicitOps|ModRM|Mov, + DstImplicit|SrcMem16|ModRM, ImplicitOps|ModRM|Mov, /* 0xE0 - 0xE7 */ DstImplicit|SrcImmByte, DstImplicit|SrcImmByte, DstImplicit|SrcImmByte, DstImplicit|SrcImmByte, @@ -3589,10 +3589,8 @@ x86_emulate( break; default: ASSERT(ea.type == OP_MEM); - ea.bytes = 4; - src = ea; - if ( (rc = ops->read(src.mem.seg, src.mem.off, &src.val, - src.bytes, ctxt)) != 0 ) + if ( (rc = ops->read(ea.mem.seg, ea.mem.off, &src.val, + 4, ctxt)) != X86EMUL_OKAY ) goto done; switch ( modrm_reg & 7 ) { @@ -3668,10 +3666,8 @@ x86_emulate( switch ( modrm_reg & 7 ) { case 0: /* fld m32fp */ - ea.bytes = 4; - src = ea; if ( (rc = ops->read(ea.mem.seg, ea.mem.off, &src.val, - src.bytes, ctxt)) != 0 ) + 4, ctxt)) != X86EMUL_OKAY ) goto done; emulate_fpu_insn_memsrc("flds", src.val); break; @@ -3690,10 +3686,8 @@ x86_emulate( case 4: /* fldenv - TODO */ goto cannot_emulate; case 5: /* fldcw m2byte */ - ea.bytes = 2; - src = ea; - if ( (rc = ops->read(src.mem.seg, src.mem.off, &src.val, - src.bytes, ctxt)) != 0 ) + if ( (rc = ops->read(ea.mem.seg, ea.mem.off, &src.val, + 2, ctxt)) != X86EMUL_OKAY ) goto done; emulate_fpu_insn_memsrc("fldcw", src.val); break; @@ -3727,10 +3721,8 @@ x86_emulate( break; default: generate_exception_if(ea.type != OP_MEM, EXC_UD); - ea.bytes = 4; - src = ea; - if ( (rc = ops->read(src.mem.seg, src.mem.off, &src.val, - src.bytes, ctxt)) != 0 ) + if ( (rc = ops->read(ea.mem.seg, ea.mem.off, &src.val, + 4, ctxt)) != X86EMUL_OKAY ) goto done; switch ( modrm_reg & 7 ) { @@ -3788,10 +3780,8 @@ x86_emulate( switch ( modrm_reg & 7 ) { case 0: /* fild m32i */ - ea.bytes = 4; - src = ea; - if ( (rc = ops->read(src.mem.seg, src.mem.off, &src.val, - src.bytes, ctxt)) != 0 ) + if ( (rc = ops->read(ea.mem.seg, ea.mem.off, &src.val, + 4, ctxt)) != X86EMUL_OKAY ) goto done; emulate_fpu_insn_memsrc("fildl", src.val); break; @@ -3815,10 +3805,8 @@ x86_emulate( emulate_fpu_insn_memdst("fistpl", dst.val); break; case 5: /* fld m80fp */ - ea.bytes = 10; - src = ea; - if ( (rc = ops->read(src.mem.seg, src.mem.off, - &src.val, src.bytes, ctxt)) != 0 ) + if ( (rc = ops->read(ea.mem.seg, ea.mem.off, &src.val, + 10, ctxt)) != X86EMUL_OKAY ) goto done; emulate_fpu_insn_memsrc("fldt", src.val); break; @@ -3850,10 +3838,8 @@ x86_emulate( break; default: ASSERT(ea.type == OP_MEM); - ea.bytes = 8; - src = ea; - if ( (rc = ops->read(src.mem.seg, src.mem.off, &src.val, - src.bytes, ctxt)) != 0 ) + if ( (rc = ops->read(ea.mem.seg, ea.mem.off, &src.val, + 8, ctxt)) != X86EMUL_OKAY ) goto done; switch ( modrm_reg & 7 ) { @@ -3902,10 +3888,8 @@ x86_emulate( switch ( modrm_reg & 7 ) { case 0: /* fld m64fp */; - ea.bytes = 8; - src = ea; - if ( (rc = ops->read(src.mem.seg, src.mem.off, &src.val, - src.bytes, ctxt)) != 0 ) + if ( (rc = ops->read(ea.mem.seg, ea.mem.off, &src.val, + 8, ctxt)) != X86EMUL_OKAY ) goto done; emulate_fpu_insn_memsrc("fldl", src.val); break; @@ -3959,11 +3943,6 @@ x86_emulate( break; default: generate_exception_if(ea.type != OP_MEM, EXC_UD); - ea.bytes = 2; - src = ea; - if ( (rc = ops->read(src.mem.seg, src.mem.off, &src.val, - src.bytes, ctxt)) != 0 ) - goto done; switch ( modrm_reg & 7 ) { case 0: /* fiadd m16i */ @@ -4021,10 +4000,8 @@ x86_emulate( switch ( modrm_reg & 7 ) { case 0: /* fild m16i */ - ea.bytes = 2; - src = ea; - if ( (rc = ops->read(src.mem.seg, src.mem.off, &src.val, - src.bytes, ctxt)) != 0 ) + if ( (rc = ops->read(ea.mem.seg, ea.mem.off, &src.val, + 2, ctxt)) != X86EMUL_OKAY ) goto done; emulate_fpu_insn_memsrc("filds", src.val); break; @@ -4048,18 +4025,14 @@ x86_emulate( emulate_fpu_insn_memdst("fistps", dst.val); break; case 4: /* fbld m80dec */ - ea.bytes = 10; - src = ea; - if ( (rc = ops->read(src.mem.seg, src.mem.off, - &src.val, src.bytes, ctxt)) != 0 ) + if ( (rc = ops->read(ea.mem.seg, ea.mem.off, &src.val, + 10, ctxt)) != X86EMUL_OKAY ) goto done; emulate_fpu_insn_memsrc("fbld", src.val); break; case 5: /* fild m64i */ - ea.bytes = 8; - src = ea; - if ( (rc = ops->read(src.mem.seg, src.mem.off, &src.val, - src.bytes, ctxt)) != 0 ) + if ( (rc = ops->read(ea.mem.seg, ea.mem.off, &src.val, + 8, ctxt)) != X86EMUL_OKAY ) goto done; emulate_fpu_insn_memsrc("fildll", src.val); break;