Remove 1 instruction from popcount
authorTudor Bosman <tudorb@fb.com>
Wed, 8 Aug 2012 21:08:03 +0000 (14:08 -0700)
committerTudor Bosman <tudorb@fb.com>
Wed, 8 Aug 2012 22:40:42 +0000 (15:40 -0700)
Summary:
by removing the unnecessary constraint that the input and output be in
the same register (copypasta from https://phabricator.fb.com/D542718)

Test Plan: folly/test

Reviewed By: soren@fb.com

FB internal diff: D543310

folly/Bits.cpp

index 41c2bc46ea32a6e5f18fae01e0d41beb9cf13c87..1c825d2a1fd1c1e8060d4bcef165acc9483d926a 100644 (file)
@@ -25,8 +25,9 @@
 namespace {
 
 int popcount_inst(unsigned int x) {
-  asm ("popcntl %0, %0" : "=r" (x) : "0" (x));
-  return x;
+  int n;
+  asm ("popcntl %1, %0" : "=r" (n) : "r" (x));
+  return n;
 }
 
 int popcount_builtin(unsigned int x) {
@@ -34,8 +35,9 @@ int popcount_builtin(unsigned int x) {
 }
 
 int popcountll_inst(unsigned long long x) {
-  asm ("popcntq %0, %0" : "=r" (x) : "0" (x));
-  return x;
+  unsigned long long n;
+  asm ("popcntq %1, %0" : "=r" (n) : "r" (x));
+  return n;
 }
 
 int popcountll_builtin(unsigned long long x) {