Collapse the table of content
Expand the table of content
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer


Microsoft Specific

Emits the IPF Population Count instruction (popcnt), which determines the number of set bits (bits with the value 1) in the input 64-bit value.

__m64 __m64_popcnt( 
   __m64 value

[in] value

An __m64 union whose set bits are to be counted.

The number of set (1) bits in the input.





Header file <intrin.h>

// __m64_popcnt.cpp
// processor: IPF

#include <stdio.h>
#include <intrin.h>

#pragma intrinsic(__m64_popcnt)

int main()
    __m64 m, result;
    m.m64_i64 = -1;
    result = __m64_popcnt(m);
    printf_s("Population Count of %d (0x%I64x): %I64u\n", 
              m.m64_i64, m.m64_i64, result.m64_i64);

    m.m64_u64 = 0xaaaaaaaaaaaaaaaaI64;
    result = __m64_popcnt(m);
    printf_s("Population Count of %u (0x%I64x): %I64u\n",
              m.m64_u64, m.m64_u64, result.m64_u64);
Population Count of -1 (0xffffffffffffffff): 64 Population Count of 2863311530 (0xaaaaaaaaaaaaaaaa): 32
© 2015 Microsoft