Re: [PATCH] KVM: x86: small optimization for is_mtrr_mask calculation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On March 5, 2020 6:05:40 PM PST, linmiaohe <linmiaohe@xxxxxxxxxx> wrote:
>Hi,
>Paolo Bonzini <pbonzini@xxxxxxxxxx> wrote:
>>On 05/03/20 03:48, linmiaohe wrote:
>>> From: Miaohe Lin <linmiaohe@xxxxxxxxxx>
>>> 
>>> 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.




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux