/* find_last_bit.c: fallback find next bit implementation1*2* Copyright (C) 2008 IBM Corporation3* Written by Rusty Russell <[email protected]>4* (Inspired by David Howell's find_next_bit implementation)5*6* This program is free software; you can redistribute it and/or7* modify it under the terms of the GNU General Public License8* as published by the Free Software Foundation; either version9* 2 of the License, or (at your option) any later version.10*/1112#include <linux/bitops.h>13#include <linux/module.h>14#include <asm/types.h>15#include <asm/byteorder.h>1617#ifndef find_last_bit1819unsigned long find_last_bit(const unsigned long *addr, unsigned long size)20{21unsigned long words;22unsigned long tmp;2324/* Start at final word. */25words = size / BITS_PER_LONG;2627/* Partial final word? */28if (size & (BITS_PER_LONG-1)) {29tmp = (addr[words] & (~0UL >> (BITS_PER_LONG30- (size & (BITS_PER_LONG-1)))));31if (tmp)32goto found;33}3435while (words) {36tmp = addr[--words];37if (tmp) {38found:39return words * BITS_PER_LONG + __fls(tmp);40}41}4243/* Not found */44return size;45}46EXPORT_SYMBOL(find_last_bit);4748#endif495051