All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
target/Linux-x86_64/include/citrusleaf/cf_bits.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2008-2013 by Aerospike.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to
6  * deal in the Software without restriction, including without limitation the
7  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8  * sell copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20  * IN THE SOFTWARE.
21  *****************************************************************************/
22 #pragma once
23 
24 #include <citrusleaf/cf_atomic.h>
25 #include <citrusleaf/cf_types.h>
26 #include <strings.h>
27 #include <string.h>
28 #include <inttypes.h>
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 /******************************************************************************
35  * CONSTANTS
36  ******************************************************************************/
37 
38 static const char cf_LogTable256[] =
39 {
40 #define CF_LT(n) n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n
41  -1, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
42  CF_LT(4), CF_LT(5), CF_LT(5), CF_LT(6), CF_LT(6), CF_LT(6), CF_LT(6),
43  CF_LT(7), CF_LT(7), CF_LT(7), CF_LT(7), CF_LT(7), CF_LT(7), CF_LT(7), CF_LT(7)
44 };
45 
46 /******************************************************************************
47  * FUNCTIONS
48  ******************************************************************************/
49 
50 extern int cf_bits_find_last_set(uint32_t c);
51 extern int cf_bits_find_last_set_64(uint64_t c);
52 
53 /******************************************************************************
54  * INLINE FUNCTIONS
55  ******************************************************************************/
56 
57 static inline uint32_t cf_roundup( uint32_t i, uint32_t modulus) {
58  uint32_t t = i % modulus;
59  if (t == 0) return(i);
60  return( i + (modulus - t ) );
61 }
62 
63 static inline uint64_t cf_roundup_64( uint64_t i, uint32_t modulus) {
64  uint64_t t = i % modulus;
65  if (t == 0) return(i);
66  return( i + (modulus - t ) );
67 }
68 
69 /******************************************************************************
70  * MACROS
71  ******************************************************************************/
72 
73 #define cf_bits_find_first_set(__x) ffs(__x)
74 #define cf_bits_find_first_set_64(__x) ffsll(__x)
75 
76 #define cf_max_uint32(__x, __y) ( (__x) > (__y) ? (__x) : (__y) )
77 #define cf_max(__x, __y) ( (__x) > (__y) ? (__x) : (__y) )
78 
79 /******************************************************************************/
80 
81 #ifdef __cplusplus
82 } // end extern "C"
83 #endif