169bb4bb4Scarlsonj /* 269bb4bb4Scarlsonj * CDDL HEADER START 369bb4bb4Scarlsonj * 469bb4bb4Scarlsonj * The contents of this file are subject to the terms of the 569bb4bb4Scarlsonj * Common Development and Distribution License (the "License"). 669bb4bb4Scarlsonj * You may not use this file except in compliance with the License. 769bb4bb4Scarlsonj * 869bb4bb4Scarlsonj * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 969bb4bb4Scarlsonj * or http://www.opensolaris.org/os/licensing. 1069bb4bb4Scarlsonj * See the License for the specific language governing permissions 1169bb4bb4Scarlsonj * and limitations under the License. 1269bb4bb4Scarlsonj * 1369bb4bb4Scarlsonj * When distributing Covered Code, include this CDDL HEADER in each 1469bb4bb4Scarlsonj * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 1569bb4bb4Scarlsonj * If applicable, add the following below this CDDL HEADER, with the 1669bb4bb4Scarlsonj * fields enclosed by brackets "[]" replaced with your own identifying 1769bb4bb4Scarlsonj * information: Portions Copyright [yyyy] [name of copyright owner] 1869bb4bb4Scarlsonj * 1969bb4bb4Scarlsonj * CDDL HEADER END 2069bb4bb4Scarlsonj */ 2169bb4bb4Scarlsonj 2269bb4bb4Scarlsonj /* 23*7257d1b4Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 2469bb4bb4Scarlsonj * Use is subject to license terms. 2569bb4bb4Scarlsonj */ 2669bb4bb4Scarlsonj 2769bb4bb4Scarlsonj #pragma ident "%Z%%M% %I% %E% SMI" 2869bb4bb4Scarlsonj 2969bb4bb4Scarlsonj /* 3069bb4bb4Scarlsonj * Common implementation of ffs for kernel, mdb, and libc. Note that mdb 3169bb4bb4Scarlsonj * renames ffs into mdb_ffs to avoid user-space clashes with the signature of 3269bb4bb4Scarlsonj * ffs(3C). 3369bb4bb4Scarlsonj */ 3469bb4bb4Scarlsonj 3569bb4bb4Scarlsonj #if defined(_KERNEL) || defined(ffs) 3669bb4bb4Scarlsonj #include <sys/int_types.h> 3769bb4bb4Scarlsonj #define arg_t uintmax_t 3869bb4bb4Scarlsonj #else 3969bb4bb4Scarlsonj #define arg_t int 40*7257d1b4Sraf #include "lint.h" 4169bb4bb4Scarlsonj #endif 4269bb4bb4Scarlsonj 4369bb4bb4Scarlsonj int 4469bb4bb4Scarlsonj ffs(arg_t bits) 4569bb4bb4Scarlsonj { 4669bb4bb4Scarlsonj int i; 4769bb4bb4Scarlsonj 4869bb4bb4Scarlsonj if (bits == 0) 4969bb4bb4Scarlsonj return (0); 5069bb4bb4Scarlsonj for (i = 1; ; i++, bits >>= 1) { 5169bb4bb4Scarlsonj if (bits & 1) 5269bb4bb4Scarlsonj break; 5369bb4bb4Scarlsonj } 5469bb4bb4Scarlsonj return (i); 5569bb4bb4Scarlsonj } 56