From patchwork Tue Jun 20 06:20:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 9798633 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 A06C360328 for ; Tue, 20 Jun 2017 06:22:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 98F52269A3 for ; Tue, 20 Jun 2017 06:22:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8DEB026E98; Tue, 20 Jun 2017 06:22:32 +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 3B805269A3 for ; Tue, 20 Jun 2017 06:22:32 +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 1dNCWa-0003Rj-Ek; Tue, 20 Jun 2017 06:20:28 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dNCWY-0003Rb-W1 for xen-devel@lists.xenproject.org; Tue, 20 Jun 2017 06:20:27 +0000 Received: from [85.158.139.211] by server-5.bemta-5.messagelabs.com id E4/23-02183-AAEB8495; Tue, 20 Jun 2017 06:20:26 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrPIsWRWlGSWpSXmKPExsXS6fjDS3fZPo9 Ig+/HZS2+b5nM5MDocfjDFZYAxijWzLyk/IoE1oyFV1QL3ilV7Pm7jK2BcbZkFyMnh5BAnsSC C62sIDavgJ3EoVObGUFsCQFDidMLb7KA2CwCqhIfHnSxg9hsAuoSbc+2A9VzcIgIGEicO5oEY jIL6EtsWwdWLSxgKvF60WVmiOl2Egs2XACr5hUQlPi7QxgkzAwU3jD/FOsERu5ZCJlZSDIQtp bEw1+3WCBsbYllC18zzwLbJS2x/B8HRNhG4sLZnUyoSkBsd4ljbcsYFzByrGLUKE4tKkst0jU y0UsqykzPKMlNzMzRNTQw1ctNLS5OTE/NSUwq1kvOz93ECAzIegYGxh2MNyf7HWKU5GBSEuXV 2uQRKcSXlJ9SmZFYnBFfVJqTWnyIUYaDQ0mCN3wvUE6wKDU9tSItMwcYGzBpCQ4eJRHedbuA0 rzFBYm5xZnpEKlTjIpS4rzVIH0CIImM0jy4Nlg8XmKUlRLmZWRgYBDiKUgtys0sQZV/xSjOwa gkzCsEjG4hnsy8Erjpr4AWMwEtZj7jArK4JBEhJdXAyHc3s/Hggys8Zs9zdB4+ajrIfY33Ude d5WpLFvHJVUrNsdN7+5brUlXJrTrj1I4lT94sjihb9Wdr/out7E9VmKZFcu+cwv2j9asOr/Ki OVMN19vIBRjKsKbvTmN92biJ9+nUadHzl37wSf/8l29j69P8i+aSJdnOuXsUOrNVfRfNqfnmF zPdTYmlOCPRUIu5qDgRALgsvPTCAgAA X-Env-Sender: JBeulich@suse.com X-Msg-Ref: server-14.tower-206.messagelabs.com!1497939620!65355232!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.4.19; banners=-,-,- X-VirusChecked: Checked Received: (qmail 46152 invoked from network); 20 Jun 2017 06:20:22 -0000 Received: from prv-mh.provo.novell.com (HELO prv-mh.provo.novell.com) (137.65.248.74) by server-14.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 20 Jun 2017 06:20:22 -0000 Received: from INET-PRV-MTA by prv-mh.provo.novell.com with Novell_GroupWise; Tue, 20 Jun 2017 00:20:20 -0600 Message-Id: <5948DAC20200007800164514@prv-mh.provo.novell.com> X-Mailer: Novell GroupWise Internet Agent 14.2.2 Date: Tue, 20 Jun 2017 00:20:18 -0600 From: "Jan Beulich" To: "xen-devel" References: <5948DAC20200007800164514@prv-mh.provo.novell.com> Mime-Version: 1.0 Cc: Andrew Cooper Subject: [Xen-devel] [PATCH] x86emul: simplify SHLD/SHRD 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 First of all there's no point considering the "shift == width" case, when immediately before that check we mask "shift" by "width - 1". And then truncate_word() use can be reduced too: dst.val, as obtained by generic operand fetching code, is already suitably truncated, and its use can also be made symmetric in the main conditional expression (on only left shift results). Finally masking the result of a right shift is not necessary when the left hand operand doesn't have more than "width" significant bits. Signed-off-by: Jan Beulich x86emul: simplify SHLD/SHRD handling First of all there's no point considering the "shift == width" case, when immediately before that check we mask "shift" by "width - 1". And then truncate_word() use can be reduced too: dst.val, as obtained by generic operand fetching code, is already suitably truncated, and its use can also be made symmetric in the main conditional expression (on only left shift results). Finally masking the result of a right shift is not necessary when the left hand operand doesn't have more than "width" significant bits. Signed-off-by: Jan Beulich --- a/xen/arch/x86/x86_emulate/x86_emulate.c +++ b/xen/arch/x86/x86_emulate/x86_emulate.c @@ -6414,16 +6414,14 @@ x86_emulate( } if ( (shift &= width - 1) == 0 ) break; - dst.orig_val = truncate_word(dst.val, dst.bytes); - dst.val = ((shift == width) ? src.val : - (b & 8) ? - /* shrd */ - ((dst.orig_val >> shift) | - truncate_word(src.val << (width - shift), dst.bytes)) : - /* shld */ - ((dst.orig_val << shift) | - ((src.val >> (width - shift)) & ((1ull << shift) - 1)))); - dst.val = truncate_word(dst.val, dst.bytes); + dst.orig_val = dst.val; + dst.val = (b & 8) ? + /* shrd */ + ((dst.orig_val >> shift) | + truncate_word(src.val << (width - shift), dst.bytes)) : + /* shld */ + (truncate_word(dst.orig_val << shift, dst.bytes) | + (src.val >> (width - shift))); _regs.eflags &= ~(X86_EFLAGS_OF | X86_EFLAGS_SF | X86_EFLAGS_ZF | X86_EFLAGS_PF | X86_EFLAGS_CF); if ( (dst.val >> ((b & 8) ? (shift - 1) : (width - shift))) & 1 ) Reviewed-by: Andrew Cooper --- a/xen/arch/x86/x86_emulate/x86_emulate.c +++ b/xen/arch/x86/x86_emulate/x86_emulate.c @@ -6414,16 +6414,14 @@ x86_emulate( } if ( (shift &= width - 1) == 0 ) break; - dst.orig_val = truncate_word(dst.val, dst.bytes); - dst.val = ((shift == width) ? src.val : - (b & 8) ? - /* shrd */ - ((dst.orig_val >> shift) | - truncate_word(src.val << (width - shift), dst.bytes)) : - /* shld */ - ((dst.orig_val << shift) | - ((src.val >> (width - shift)) & ((1ull << shift) - 1)))); - dst.val = truncate_word(dst.val, dst.bytes); + dst.orig_val = dst.val; + dst.val = (b & 8) ? + /* shrd */ + ((dst.orig_val >> shift) | + truncate_word(src.val << (width - shift), dst.bytes)) : + /* shld */ + (truncate_word(dst.orig_val << shift, dst.bytes) | + (src.val >> (width - shift))); _regs.eflags &= ~(X86_EFLAGS_OF | X86_EFLAGS_SF | X86_EFLAGS_ZF | X86_EFLAGS_PF | X86_EFLAGS_CF); if ( (dst.val >> ((b & 8) ? (shift - 1) : (width - shift))) & 1 )