glusterfs

Форк
0
/
find_last_bit.c 
61 строка · 1.6 Кб
1
/* bit search implementation
2
 *
3
 * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
4
 * Written by David Howells (dhowells@redhat.com)
5
 *
6
 * Copyright (C) 2008 IBM Corporation
7
 * 'find_last_bit' is written by Rusty Russell <rusty@rustcorp.com.au>
8
 * (Inspired by David Howell's find_next_bit implementation)
9
 *
10
 * Rewritten by Yury Norov <yury.norov@gmail.com> to decrease
11
 * size and improve performance, 2015.
12
 *
13
 * This program is free software; you can redistribute it and/or
14
 * modify it under the terms of the GNU General Public License
15
 * as published by the Free Software Foundation; either version
16
 * 2 of the License, or (at your option) any later version.
17
 */
18

19
/**
20
 * @find_last_bit
21
 * optimized implementation of find last bit in
22
 */
23

24
#ifndef BITS_PER_LONG
25
#ifdef __LP64__
26
#define BITS_PER_LONG 64
27
#else
28
#define BITS_PER_LONG 32
29
#endif
30
#endif
31

32
unsigned long gw_tw_fls (unsigned long word)
33
{
34
        int num = BITS_PER_LONG;
35

36
#if BITS_PER_LONG == 64
37
        if (!(word & (~0ul << 32))) {
38
                num -= 32;
39
                word <<= 32;
40
        }
41
#endif
42
        if (!(word & (~0ul << (BITS_PER_LONG-16)))) {
43
                num -= 16;
44
                word <<= 16;
45
        }
46
        if (!(word & (~0ul << (BITS_PER_LONG-8)))) {
47
                num -= 8;
48
                word <<= 8;
49
        }
50
        if (!(word & (~0ul << (BITS_PER_LONG-4)))) {
51
                num -= 4;
52
                word <<= 4;
53
        }
54
        if (!(word & (~0ul << (BITS_PER_LONG-2)))) {
55
                num -= 2;
56
                word <<= 2;
57
        }
58
        if (!(word & (~0ul << (BITS_PER_LONG-1))))
59
                num -= 1;
60
        return num;
61
}
62

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.