[LLVMdev] ctpop intrinsic question

Tobias Oberstein tobias.oberstein at gmx.de
Tue Feb 19 16:26:08 PST 2008


Hello,

is it correct, that the "llvm.ctpop" Hamming weight intrinsic is 
currently (LLVM 2.2) implemented in

Line 254 in lib/CodeGen/IntrinsicLowering.cpp

/// LowerCTPOP - Emit the code to lower ctpop of V before the specified
/// instruction IP.
static Value *LowerCTPOP(Value *V, Instruction *IP) {
   assert(V->getType()->isInteger() && "Can't ctpop a non-integer type!");

and that the implemented algorithm is essentially the first of the 3 
given tree reduction based algorithms given in

http://en.wikipedia.org/wiki/Hamming_weight??

How can I emit that intrinsic from LLVMBuilder?

What is the correct LLVM textual IR representation? I tried

; ModuleID = 'test'

define i64 @popcount(i64 %x) {
entry:
	%tmp = call i64 @llvm.ctpop.i64(i64 %x)
	ret i64 %tmp
}


which gives me errors .. I tried several others and read the lang. ref., 
but I don't get it;(

Any hints appreciated,
Tobias



More information about the llvm-dev mailing list