From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752033AbbHaGNn (ORCPT ); Mon, 31 Aug 2015 02:13:43 -0400 Received: from terminus.zytor.com ([198.137.202.10]:36687 "EHLO mail.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751233AbbHaGNm (ORCPT ); Mon, 31 Aug 2015 02:13:42 -0400 User-Agent: K-9 Mail for Android In-Reply-To: <20150831060549.GB7093@gmail.com> References: <1440776707-22016-1-git-send-email-mst@redhat.com> <20150831060549.GB7093@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Subject: Re: [PATCH 1/2] x86/bitops: implement __test_bit From: "H. Peter Anvin" Date: Sun, 30 Aug 2015 23:13:20 -0700 To: Ingo Molnar , "Michael S. Tsirkin" CC: linux-kernel@vger.kernel.org, Thomas Gleixner , Ingo Molnar , x86@kernel.org, Rusty Russell , Linus Torvalds Message-ID: <0779C35A-141F-4019-942A-CD3F861048A3@zytor.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Presumably because gcc can't generate bt... whether or not it is worth it is another matter. On August 30, 2015 11:05:49 PM PDT, Ingo Molnar wrote: > >* 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 -- Sent from my Android device with K-9 Mail. Please excuse my brevity.