From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934725AbcLIQ1u (ORCPT ); Fri, 9 Dec 2016 11:27:50 -0500 Received: from Galois.linutronix.de ([146.0.238.70]:35608 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933406AbcLIQ1s (ORCPT ); Fri, 9 Dec 2016 11:27:48 -0500 Date: Fri, 9 Dec 2016 17:25:00 +0100 (CET) From: Thomas Gleixner To: Kyle Huey cc: Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, linux-kernel@vger.kernel.org, "Robert O'Callahan" Subject: Re: [PATCH] x86: Optimize TIF checking in __switch_to_xtra. In-Reply-To: Message-ID: References: <20161206230445.20594-1-khuey@kylehuey.com> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 9 Dec 2016, Thomas Gleixner wrote: > On Tue, 6 Dec 2016, Kyle Huey wrote: > > I propose the following patch, which results in GCC generating this code: > > > > mov (%rsi),%rax > > xor (%rdi),%rax > > mov %rdi,%rbx > > mov %rsi,%r12 > > test $0x2000000,%eax > > mov %rax,%rdx > > jne 3f > > 1: test $0x10000,%edx > > je 2f > > /* do some more work */ > > 2: /* the rest of the function */ > > ret > > 3: /* do work */ > > mov (%r12),%rdx > > xor (%rbx),%rdx > > jmp 1b > > > > When we are not doing the work controlled by these flags this is significantly > > better. We only have to load the flags from memory once, and we do a single > > XOR that we can test multiple times instead of repeatedly isolating bits. > > You rely on the compiler doing the right thing. And it's non obvious from > the code that this gets optimized as above. On i386 this creates worse code due to register pressure it seems.