PTX ISA v9.4

9.7.1.15. Integer Arithmetic Instructions: popc

popc

Population count.

Syntax

ptx
popc.type  d, a;

.type = { .b32, .b64 };

Description

Count the number of one bits in a and place the resulting population count in 32-bit destination register d. Operand a has the instruction type and destination d has type .u32.

Semantics

ptx
.u32  d = 0;
while (a != 0) {
   if (a & 0x1)  d++;
   a = a >> 1;
}

PTX ISA Notes

Introduced in PTX ISA version 2.0.

Target ISA Notes

popc requires sm_20 or higher.

Examples

ptx
popc.b32  d, a;
popc.b64  cnt, X;  // cnt is .u32
esc
Type to search across all documentation