lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Mon, 31 Aug 2015 10:56:29 +0300
From:	"Michael S. Tsirkin" <mst@...hat.com>
To:	"H. Peter Anvin" <hpa@...or.com>
Cc:	Ingo Molnar <mingo@...nel.org>, linux-kernel@...r.kernel.org,
	Thomas Gleixner <tglx@...utronix.de>,
	Ingo Molnar <mingo@...hat.com>, x86@...nel.org,
	Rusty Russell <rusty@...tcorp.com.au>,
	Linus Torvalds <torvalds@...ux-foundation.org>
Subject: Re: [PATCH 1/2] x86/bitops: implement __test_bit

On Sun, Aug 30, 2015 at 11:13:20PM -0700, H. Peter Anvin wrote:
> 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 <mingo@...nel.org> wrote:
> >
> >* Michael S. Tsirkin <mst@...hat.com> 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

Exactly:


Disassembly of section .text:

00000000 <__variable_test_bit>:
__variable_test_bit():
   0:   8b 54 24 08             mov    0x8(%esp),%edx
   4:   8b 44 24 04             mov    0x4(%esp),%eax
   8:   0f a3 02                bt     %eax,(%edx)
   b:   19 c0                   sbb    %eax,%eax
   d:   c3                      ret    
   e:   66 90                   xchg   %ax,%ax

00000010 <__constant_test_bit>:
__constant_test_bit():
  10:   8b 4c 24 04             mov    0x4(%esp),%ecx
  14:   8b 44 24 08             mov    0x8(%esp),%eax
  18:   89 ca                   mov    %ecx,%edx
  1a:   c1 fa 04                sar    $0x4,%edx
  1d:   8b 04 90                mov    (%eax,%edx,4),%eax
  20:   d3 e8                   shr    %cl,%eax
  22:   83 e0 01                and    $0x1,%eax
  25:   c3                      ret    


That's also probably why we still have variable_test_bit
for test_bit too. It's best to be consistent with that - do you agree?
Or would you rather drop that too?

-- 
MST
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ