lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Thu, 05 Mar 2020 18:09:10 -0800
From:   hpa@...or.com
To:     linmiaohe <linmiaohe@...wei.com>,
        Paolo Bonzini <pbonzini@...hat.com>
CC:     "kvm@...r.kernel.org" <kvm@...r.kernel.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        "x86@...nel.org" <x86@...nel.org>,
        "rkrcmar@...hat.com" <rkrcmar@...hat.com>,
        "sean.j.christopherson@...el.com" <sean.j.christopherson@...el.com>,
        "vkuznets@...hat.com" <vkuznets@...hat.com>,
        "jmattson@...gle.com" <jmattson@...gle.com>,
        "joro@...tes.org" <joro@...tes.org>,
        "tglx@...utronix.de" <tglx@...utronix.de>,
        "mingo@...hat.com" <mingo@...hat.com>,
        "bp@...en8.de" <bp@...en8.de>
Subject: Re: [PATCH] KVM: x86: small optimization for is_mtrr_mask calculation

On March 5, 2020 6:05:40 PM PST, linmiaohe <linmiaohe@...wei.com> wrote:
>Hi,
>Paolo Bonzini <pbonzini@...hat.com> wrote:
>>On 05/03/20 03:48, linmiaohe wrote:
>>> From: Miaohe Lin <linmiaohe@...wei.com>
>>> 
>>> We can get is_mtrr_mask by calculating (msr - 0x200) % 2 directly.
>>>  		index = (msr - 0x200) / 2;
>>> -		is_mtrr_mask = msr - 0x200 - 2 * index;
>>> +		is_mtrr_mask = (msr - 0x200) % 2;
>>>  		if (!is_mtrr_mask)
>>>  			*pdata = vcpu->arch.mtrr_state.var_ranges[index].base;
>>>  		else
>>> 
>>
>>If you're going to do that, might as well use ">> 1" for index instead
>of "/ 2", and "msr & 1" for is_mtrr_mask.
>>
>
>Many thanks for suggestion. What do you mean is like this ?
>
>	index = (msr - 0x200) >> 1;
>	is_mtrr_mask = msr & 1;
>
>Thanks again.

You realize that the compiler will probably produce exactly the same code, right? As such, it is about making the code easy for the human reader.

Even if it didn't, this code is as far from performance critical as one can possibly get.
-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ