fa9e4066f08beec538e775443c5be79dd423fcabahrens/*-
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Copyright (c) 1990, 1993
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The Regents of the University of California. All rights reserved.
fa9e4066f08beec538e775443c5be79dd423fcabahrens *
f65e61c04bc28ffd6bda04619c84330b420450b5ahrens * Redistribution and use in source and binary forms, with or without
f65e61c04bc28ffd6bda04619c84330b420450b5ahrens * modification, are permitted provided that the following conditions
fa9e4066f08beec538e775443c5be79dd423fcabahrens * are met:
fa9e4066f08beec538e775443c5be79dd423fcabahrens * 1. Redistributions of source code must retain the above copyright
fa9e4066f08beec538e775443c5be79dd423fcabahrens * notice, this list of conditions and the following disclaimer.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * 2. Redistributions in binary form must reproduce the above copyright
fa9e4066f08beec538e775443c5be79dd423fcabahrens * notice, this list of conditions and the following disclaimer in the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * documentation and/or other materials provided with the distribution.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * 3. Neither the name of the University nor the names of its contributors
fa9e4066f08beec538e775443c5be79dd423fcabahrens * may be used to endorse or promote products derived from this software
fa9e4066f08beec538e775443c5be79dd423fcabahrens * without specific prior written permission.
fa9e4066f08beec538e775443c5be79dd423fcabahrens *
fa9e4066f08beec538e775443c5be79dd423fcabahrens * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
fa9e4066f08beec538e775443c5be79dd423fcabahrens * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
fa9e4066f08beec538e775443c5be79dd423fcabahrens * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
fa9e4066f08beec538e775443c5be79dd423fcabahrens * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
fa9e4066f08beec538e775443c5be79dd423fcabahrens * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
478ed9ada0b6efe1318150a700986aa47e6a926dEric Taylor * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
fa9e4066f08beec538e775443c5be79dd423fcabahrens * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
fa9e4066f08beec538e775443c5be79dd423fcabahrens * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
fa9e4066f08beec538e775443c5be79dd423fcabahrens * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
fa9e4066f08beec538e775443c5be79dd423fcabahrens * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
fa9e4066f08beec538e775443c5be79dd423fcabahrens * SUCH DAMAGE.
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <sys/cdefs.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens__FBSDID("$FreeBSD$");
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <strings.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens/*
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Find Last Set bit
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrensint
fa9e4066f08beec538e775443c5be79dd423fcabahrensfls(int mask)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens int bit;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (mask == 0)
de8267e0f723ed2c38ea9def92d465f69a300f56timh return (0);
478ed9ada0b6efe1318150a700986aa47e6a926dEric Taylor for (bit = 1; mask != 1; bit++)
fa9e4066f08beec538e775443c5be79dd423fcabahrens mask = (unsigned int)mask >> 1;
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock return (bit);
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens