KVM: x86: small optimization for is_mtrr_mask calculation
Hi,
Quoted 14 lines · Paolo Bonzini
Review
Quoted 10 lines · linmiaohe
From: Miaohe Lin <[email protected]>
We can get
is_mtrr_maskby calculating (msr -0x200) % 2 directly.(quoted diff) +1
-1index = (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; elseIf 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.
Quoted 18 lines · linmiaohe
Hi,
Quoted 13 lines · Paolo Bonzini
Review
Quoted 10 lines · linmiaohe
From: Miaohe Lin <[email protected]>
We can get
is_mtrr_maskby calculating (msr -0x200) % 2 directly.(quoted diff) +1
-1index = (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; elseIf you're going to do that, might as well use ">> 1" for index instead
of "/ 2", and "msr & 1" for
is_mtrr_mask.Quoted 1 line
Quoted 6 lines
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.
Signature · 1 line
Sent from my Android device with K-9 Mail. Please excuse my brevity.