flsl.c revision 124480
1124480Sdes/*- 2124480Sdes * Copyright (c) 1990, 1993 3124480Sdes * The Regents of the University of California. All rights reserved. 4124480Sdes * 5124480Sdes * Redistribution and use in source and binary forms, with or without 6124480Sdes * modification, are permitted provided that the following conditions 7124480Sdes * are met: 8124480Sdes * 1. Redistributions of source code must retain the above copyright 9124480Sdes * notice, this list of conditions and the following disclaimer. 10124480Sdes * 2. Redistributions in binary form must reproduce the above copyright 11124480Sdes * notice, this list of conditions and the following disclaimer in the 12124480Sdes * documentation and/or other materials provided with the distribution. 13124480Sdes * 3. All advertising materials mentioning features or use of this software 14124480Sdes * must display the following acknowledgement: 15124480Sdes * This product includes software developed by the University of 16124480Sdes * California, Berkeley and its contributors. 17124480Sdes * 4. Neither the name of the University nor the names of its contributors 18124480Sdes * may be used to endorse or promote products derived from this software 19124480Sdes * without specific prior written permission. 20124480Sdes * 21124480Sdes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22124480Sdes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23124480Sdes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24124480Sdes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25124480Sdes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26124480Sdes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27124480Sdes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28124480Sdes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29124480Sdes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30124480Sdes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31124480Sdes * SUCH DAMAGE. 32124480Sdes */ 33124480Sdes 34124480Sdes#include <sys/cdefs.h> 35124480Sdes__FBSDID("$FreeBSD: head/sys/libkern/flsl.c 124480 2004-01-13 15:36:34Z des $"); 36124480Sdes 37124480Sdes#include <sys/libkern.h> 38124480Sdes 39124480Sdes/* 40124480Sdes * Find Last Set bit 41124480Sdes */ 42124480Sdesint 43124480Sdesflsl(long mask) 44124480Sdes{ 45124480Sdes int bit; 46124480Sdes 47124480Sdes if (mask == 0) 48124480Sdes return (0); 49124480Sdes for (bit = 1; mask != 1; bit++) 50124480Sdes mask >>= 1; 51124480Sdes return (bit); 52124480Sdes} 53