Blame bits.c

Packit 0021fb
/*
Packit 0021fb
 * This file is part of ltrace.
Packit 0021fb
 * Copyright (C) 2013 Petr Machata, Red Hat Inc.
Packit 0021fb
 *
Packit 0021fb
 * This program is free software; you can redistribute it and/or
Packit 0021fb
 * modify it under the terms of the GNU General Public License as
Packit 0021fb
 * published by the Free Software Foundation; either version 2 of the
Packit 0021fb
 * License, or (at your option) any later version.
Packit 0021fb
 *
Packit 0021fb
 * This program is distributed in the hope that it will be useful, but
Packit 0021fb
 * WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 0021fb
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 0021fb
 * General Public License for more details.
Packit 0021fb
 *
Packit 0021fb
 * You should have received a copy of the GNU General Public License
Packit 0021fb
 * along with this program; if not, write to the Free Software
Packit 0021fb
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
Packit 0021fb
 * 02110-1301 USA
Packit 0021fb
 */
Packit 0021fb
Packit 0021fb
#include "bits.h"
Packit 0021fb
Packit 0021fb
/* This is called rarely, and any overhead will be lost in ptrace
Packit 0021fb
 * noise, so the algorithm doesn't need to be terribly clever.  For
Packit 0021fb
 * the same reason we don't bother defining the corresponding _32
Packit 0021fb
 * variant.  */
Packit 0021fb
unsigned
Packit 0021fb
bitcount(uint64_t u)
Packit 0021fb
{
Packit 0021fb
	int c = 0;
Packit 0021fb
	for (; u > 0; u &= u - 1)
Packit 0021fb
		c++;
Packit 0021fb
	return c;
Packit 0021fb
}