4.7.7. __builtin_popcount

This builtin function returns the population count of a specified value, that is, the number of 1-bits in the value.

Syntax

int __builtin_popcount(unsigned int val)

Where:

val

is an unsigned integer whose population is to be counted.

Return value

__builtin_popcount returns the number of bits set to 1 in val.

Example

void foo(void)
{
    int i = __builtin_popcount(3); // returns 2
    int j = __builtin_popcount(5); // returns 2
    int k = __builtin_popcount(8); // returns 1
}
Copyright © 2007, 2010 ARM Limited. All rights reserved.ARM DUI 0348A
Non-Confidential