[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1fa33c9b-eede-9214-b8af-b38d00047898@redhat.com>
Date: Mon, 15 Apr 2019 10:11:57 +0200
From: Paolo Bonzini <pbonzini@...hat.com>
To: David Laight <David.Laight@...LAB.COM>,
Sean Christopherson <sean.j.christopherson@...el.com>
Cc: "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"kvm@...r.kernel.org" <kvm@...r.kernel.org>
Subject: Re: [PATCH] KVM: x86: optimize check for valid PAT value
On 11/04/19 11:06, David Laight wrote:
> It may be possible to generate shorter code that executes just as
> fast by generating a single constant and deriving the others from it.
> - generate 4s - needed first
> - shift right 2 to get 1s (in parallel with the xor)
> - use lea to get 6s (in parallel with an lea to do the add)
> - invert the 1s to get FEs (also in parallel with the add)
> - xor the FEs with the 6s to get F8s (in parallel with the or)
> - and/test for the result
FWIW, here is yet another way to do it:
/* Change 6/7 to 4/5 */
data &= ~((data & 0x0404040404040404ULL) >> 1);
/* Only allow 0/1/4/5 now */
return !(data & 0xFAFAFAFAFAFAFAFAULL);
movabs $0x404040404040404, %rcx
andq %rdx, %rcx
shrq %rcx
notq %rcx
movabs $0xFAFAFAFAFAFAFA, %rax
andq %rcx, %rdx
test %rax, %rdx
Paolo
Powered by blists - more mailing lists