diff options
author | Chris Lattner <sabre@nondot.org> | 2008-10-15 16:02:15 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-10-15 16:02:15 +0000 |
commit | f4fee2a9765cf24084084d104ef549265c0ead8f (patch) | |
tree | ba5539ccfff51a33877ad5d46195b7e0a418353d /lib/Target/README.txt | |
parent | b2029c98ead6bd5bf22116cd3a731c8c357bd22f (diff) | |
download | llvm-f4fee2a9765cf24084084d104ef549265c0ead8f.tar.gz llvm-f4fee2a9765cf24084084d104ef549265c0ead8f.tar.bz2 llvm-f4fee2a9765cf24084084d104ef549265c0ead8f.tar.xz |
move PR1488 into this file.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@57579 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/README.txt')
-rw-r--r-- | lib/Target/README.txt | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/Target/README.txt b/lib/Target/README.txt index a7fa80288c..173c0bc5f3 100644 --- a/lib/Target/README.txt +++ b/lib/Target/README.txt @@ -283,6 +283,39 @@ unsigned long reverse(unsigned v) { //===---------------------------------------------------------------------===// +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. |