1289765Scem/*- 2289765Scem * Copyright (c) 1990, 1993 3289765Scem * The Regents of the University of California. All rights reserved. 4289765Scem * 5289765Scem * Redistribution and use in source and binary forms, with or without 6289765Scem * modification, are permitted provided that the following conditions 7289765Scem * are met: 8289765Scem * 1. Redistributions of source code must retain the above copyright 9289765Scem * notice, this list of conditions and the following disclaimer. 10289765Scem * 2. Redistributions in binary form must reproduce the above copyright 11289765Scem * notice, this list of conditions and the following disclaimer in the 12289765Scem * documentation and/or other materials provided with the distribution. 13289766Scem * 3. Neither the name of the University nor the names of its contributors 14289765Scem * may be used to endorse or promote products derived from this software 15289765Scem * without specific prior written permission. 16289765Scem * 17289765Scem * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18289765Scem * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19289765Scem * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20289765Scem * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21289765Scem * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22289765Scem * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23289765Scem * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24289765Scem * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25289765Scem * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26289765Scem * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27289765Scem * SUCH DAMAGE. 28289765Scem */ 29289765Scem 30289765Scem#include <sys/cdefs.h> 31289765Scem__FBSDID("$FreeBSD: releng/11.0/sys/libkern/ffsll.c 289766 2015-10-22 21:04:47Z cem $"); 32289765Scem 33289765Scem#include <sys/libkern.h> 34289765Scem 35289765Scem/* 36289765Scem * Find First Set bit 37289765Scem */ 38289765Scemint 39289765Scemffsll(long long mask) 40289765Scem{ 41289765Scem int bit; 42289765Scem 43289765Scem if (mask == 0) 44289765Scem return (0); 45289765Scem for (bit = 1; !(mask & 1); bit++) 46289765Scem mask = (unsigned long long)mask >> 1; 47289765Scem return (bit); 48289765Scem} 49