flsll.c revision 184587
1289715Sglebius/*-
2289715Sglebius * Copyright (c) 1990, 1993
3289715Sglebius *	The Regents of the University of California.  All rights reserved.
4289715Sglebius *
5289715Sglebius * Redistribution and use in source and binary forms, with or without
6289715Sglebius * modification, are permitted provided that the following conditions
7289715Sglebius * are met:
8289715Sglebius * 1. Redistributions of source code must retain the above copyright
9289715Sglebius *    notice, this list of conditions and the following disclaimer.
10289715Sglebius * 2. Redistributions in binary form must reproduce the above copyright
11289715Sglebius *    notice, this list of conditions and the following disclaimer in the
12289715Sglebius *    documentation and/or other materials provided with the distribution.
13289715Sglebius * 4. Neither the name of the University nor the names of its contributors
14289715Sglebius *    may be used to endorse or promote products derived from this software
15289715Sglebius *    without specific prior written permission.
16289715Sglebius *
17289715Sglebius * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18289715Sglebius * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19289715Sglebius * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20289715Sglebius * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21289715Sglebius * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22289715Sglebius * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23289715Sglebius * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24289715Sglebius * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25289715Sglebius * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26289715Sglebius * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27289715Sglebius * SUCH DAMAGE.
28289715Sglebius */
29289715Sglebius
30289715Sglebius#include <sys/cdefs.h>
31289715Sglebius__FBSDID("$FreeBSD: head/lib/libc/string/flsll.c 184587 2008-11-03 10:22:19Z kib $");
32289715Sglebius
33289715Sglebius#include <strings.h>
34289715Sglebius
35289715Sglebius/*
36289715Sglebius * Find Last Set bit
37289715Sglebius */
38289715Sglebiusint
39289715Sglebiusflsll(long long mask)
40289715Sglebius{
41289715Sglebius	int bit;
42289715Sglebius
43289715Sglebius	if (mask == 0)
44289715Sglebius		return (0);
45289715Sglebius	for (bit = 1; mask != 1; bit++)
46289715Sglebius		mask = (unsigned long long)mask >> 1;
47289715Sglebius	return (bit);
48289715Sglebius}
49289715Sglebius