1253719Salfred/*-
2253719Salfred * Copyright (c) 1990, 1993
3253719Salfred *	The Regents of the University of California.  All rights reserved.
4253719Salfred *
5253719Salfred * Redistribution and use in source and binary forms, with or without
6253719Salfred * modification, are permitted provided that the following conditions
7253719Salfred * are met:
8253719Salfred * 1. Redistributions of source code must retain the above copyright
9253719Salfred *    notice, this list of conditions and the following disclaimer.
10253719Salfred * 2. Redistributions in binary form must reproduce the above copyright
11253719Salfred *    notice, this list of conditions and the following disclaimer in the
12253719Salfred *    documentation and/or other materials provided with the distribution.
13253719Salfred * 4. Neither the name of the University nor the names of its contributors
14253719Salfred *    may be used to endorse or promote products derived from this software
15253719Salfred *    without specific prior written permission.
16253719Salfred *
17253719Salfred * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18253719Salfred * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19253719Salfred * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20253719Salfred * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21253719Salfred * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22253719Salfred * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23253719Salfred * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24253719Salfred * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25253719Salfred * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26253719Salfred * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27253719Salfred * SUCH DAMAGE.
28253719Salfred */
29253719Salfred
30253719Salfred#include <sys/cdefs.h>
31253719Salfred#include <sys/libkern.h>
32253719Salfred__FBSDID("$FreeBSD$");
33253719Salfred
34253719Salfred/*
35253719Salfred * Find Last Set bit
36253719Salfred */
37253719Salfredint
38253719Salfredflsll(long long mask)
39253719Salfred{
40253719Salfred	int bit;
41253719Salfred
42253719Salfred	if (mask == 0)
43253719Salfred		return (0);
44253719Salfred	for (bit = 1; mask != 1; bit++)
45253719Salfred		mask = (unsigned long long)mask >> 1;
46253719Salfred	return (bit);
47253719Salfred}
48