[llvm-commits] [llvm] r57579 - /llvm/trunk/lib/Target/README.txt
Chris Lattner
sabre at nondot.org
Wed Oct 15 09:02:17 PDT 2008
Author: lattner
Date: Wed Oct 15 11:02:15 2008
New Revision: 57579
URL: http://llvm.org/viewvc/llvm-project?rev=57579&view=rev
Log:
move PR1488 into this file.
Modified:
llvm/trunk/lib/Target/README.txt
Modified: llvm/trunk/lib/Target/README.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/README.txt?rev=57579&r1=57578&r2=57579&view=diff
==============================================================================
--- llvm/trunk/lib/Target/README.txt (original)
+++ llvm/trunk/lib/Target/README.txt Wed Oct 15 11:02:15 2008
@@ -283,6 +283,39 @@
//===---------------------------------------------------------------------===//
+These idioms should be recognized as popcount (see PR1488):
+
+unsigned countbits_slow(unsigned v) {
+ unsigned c;
+ for (c = 0; v; v >>= 1)
+ c += v & 1;
+ return c;
+}
+unsigned countbits_fast(unsigned v){
+ unsigned c;
+ for (c = 0; v; c++)
+ v &= v - 1; // clear the least significant bit set
+ return c;
+}
+
+BITBOARD = unsigned long long
+int PopCnt(register BITBOARD a) {
+ register int c=0;
+ while(a) {
+ c++;
+ a &= a - 1;
+ }
+ return c;
+}
+unsigned int popcount(unsigned int input) {
+ unsigned int count = 0;
+ for (unsigned int i = 0; i < 4 * 8; i++)
+ count += (input >> i) & i;
+ return count;
+}
+
+//===---------------------------------------------------------------------===//
+
These should turn into single 16-bit (unaligned?) loads on little/big endian
processors.
More information about the llvm-commits
mailing list