From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752228AbbHaGFy (ORCPT ); Mon, 31 Aug 2015 02:05:54 -0400 Received: from mail-wi0-f180.google.com ([209.85.212.180]:35913 "EHLO mail-wi0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751233AbbHaGFx (ORCPT ); Mon, 31 Aug 2015 02:05:53 -0400 Date: Mon, 31 Aug 2015 08:05:49 +0200 From: Ingo Molnar To: "Michael S. Tsirkin" Cc: linux-kernel@vger.kernel.org, Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, Rusty Russell , Linus Torvalds Subject: Re: [PATCH 1/2] x86/bitops: implement __test_bit Message-ID: <20150831060549.GB7093@gmail.com> References: <1440776707-22016-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1440776707-22016-1-git-send-email-mst@redhat.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Michael S. Tsirkin wrote: > +static __always_inline int __constant_test_bit(long nr, const unsigned long *addr) > +{ > + return ((1UL << (nr & (BITS_PER_LONG-1))) & > + (addr[nr >> _BITOPS_LONG_SHIFT])) != 0; > +} > + > +static inline int __variable_test_bit(long nr, const unsigned long *addr) > +{ > + int oldbit; > + > + asm volatile("bt %2,%1\n\t" > + "sbb %0,%0" > + : "=r" (oldbit) > + : "m" (*addr), "Ir" (nr)); > + > + return oldbit; > +} Color me confused, why use assembly for this at all? Why not just use C for testing the bit (i.e. turn __constant_test_bit() into __test_bit()) - that would also allow the compiler to propagate the result, potentially more optimally than we can do it via SBB... Thanks, Ingo