1*4e70a2e1SSascha Wildner /*-
2*4e70a2e1SSascha Wildner * Copyright (c) 1990, 1993
3*4e70a2e1SSascha Wildner * The Regents of the University of California. All rights reserved.
4*4e70a2e1SSascha Wildner *
5*4e70a2e1SSascha Wildner * Redistribution and use in source and binary forms, with or without
6*4e70a2e1SSascha Wildner * modification, are permitted provided that the following conditions
7*4e70a2e1SSascha Wildner * are met:
8*4e70a2e1SSascha Wildner * 1. Redistributions of source code must retain the above copyright
9*4e70a2e1SSascha Wildner * notice, this list of conditions and the following disclaimer.
10*4e70a2e1SSascha Wildner * 2. Redistributions in binary form must reproduce the above copyright
11*4e70a2e1SSascha Wildner * notice, this list of conditions and the following disclaimer in the
12*4e70a2e1SSascha Wildner * documentation and/or other materials provided with the distribution.
13*4e70a2e1SSascha Wildner * 3. Neither the name of the University nor the names of its contributors
14*4e70a2e1SSascha Wildner * may be used to endorse or promote products derived from this software
15*4e70a2e1SSascha Wildner * without specific prior written permission.
16*4e70a2e1SSascha Wildner *
17*4e70a2e1SSascha Wildner * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18*4e70a2e1SSascha Wildner * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19*4e70a2e1SSascha Wildner * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20*4e70a2e1SSascha Wildner * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21*4e70a2e1SSascha Wildner * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22*4e70a2e1SSascha Wildner * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23*4e70a2e1SSascha Wildner * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24*4e70a2e1SSascha Wildner * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25*4e70a2e1SSascha Wildner * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26*4e70a2e1SSascha Wildner * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27*4e70a2e1SSascha Wildner * SUCH DAMAGE.
28*4e70a2e1SSascha Wildner *
29*4e70a2e1SSascha Wildner * $FreeBSD: head/sys/libkern/flsll.c 289766 2015-10-22 21:04:47Z cem $
30*4e70a2e1SSascha Wildner */
31*4e70a2e1SSascha Wildner
32*4e70a2e1SSascha Wildner #include <sys/libkern.h>
33*4e70a2e1SSascha Wildner
34*4e70a2e1SSascha Wildner /*
35*4e70a2e1SSascha Wildner * Find Last Set bit
36*4e70a2e1SSascha Wildner */
37*4e70a2e1SSascha Wildner int
flsll(long long mask)38*4e70a2e1SSascha Wildner flsll(long long mask)
39*4e70a2e1SSascha Wildner {
40*4e70a2e1SSascha Wildner int bit;
41*4e70a2e1SSascha Wildner
42*4e70a2e1SSascha Wildner if (mask == 0)
43*4e70a2e1SSascha Wildner return (0);
44*4e70a2e1SSascha Wildner for (bit = 1; mask != 1; bit++)
45*4e70a2e1SSascha Wildner mask = (unsigned long long)mask >> 1;
46*4e70a2e1SSascha Wildner return (bit);
47*4e70a2e1SSascha Wildner }
48