Changeset 23 for trunk/kernel/libk/bits.h
- Timestamp:
- Jun 18, 2017, 10:06:41 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/libk/bits.h
r14 r23 78 78 79 79 /********************************************************************************************** 80 * This macro returns the number of 32 bits words required to register sizeentries.80 * This macro returns the number of 32 bits words required to register <size> entries. 81 81 *********************************************************************************************/ 82 82 83 83 #define BITMAP_SIZE(size) ( ((size) & 31) ? (((size)>>5) + 1) : ((size)>>5) ) 84 85 /**********************************************************************************************86 * This macro declare a bitmap data structure. It is actually an array of uint32_t.87 * size is the total number of entries in the bitmap.88 *********************************************************************************************/89 90 #define BITMAP( name , size ) uint32_t name[BITMAP_SIZE(size)]91 84 92 85 typedef uint32_t bitmap_t; 93 86 94 /********************************************************************************************** 87 /********************************************************************************************* 88 * This function reset all bits in a bitmap. (array ot 32 bits words). 89 ********************************************************************************************* 90 * @ bitmap : pointer on first word in the bitmap. 91 * @ len : number of bits to reset. 92 ********************************************************************************************/ 93 void bitmap_init( bitmap_t * bitmap, 94 uint32_t len ); 95 96 /********************************************************************************************* 95 97 * This function set a specific bit in a bitmap. 96 ********************************************************************************************* *98 ********************************************************************************************* 97 99 * @ bitmap : pointer on the bitmap 98 100 * @ index : bit index in the bitmap 99 ******************************************************************************************** */101 ********************************************************************************************/ 100 102 extern inline void bitmap_set( bitmap_t * bitmap, 101 103 uint32_t index ); 102 104 103 /********************************************************************************************* *105 /********************************************************************************************* 104 106 * This function clear a specific bit in a bitmap. 105 ********************************************************************************************* *107 ********************************************************************************************* 106 108 * @ bitmap : pointer on the bitmap 107 109 * @ index : bit index in the bitmap 108 ******************************************************************************************** */110 ********************************************************************************************/ 109 111 extern inline void bitmap_clear( bitmap_t * bitmap, 110 112 uint32_t index ); 111 113 112 /********************************************************************************************* *114 /********************************************************************************************* 113 115 * This function returns a specific bit in a bitmap. 114 ********************************************************************************************* *116 ********************************************************************************************* 115 117 * @ bitmap : pointer on the bitmap 116 118 * @ index : bit index in the bitmap 117 * @ returns tru if bitmap[index] is set118 ******************************************************************************************** */119 * @ returns true if bitmap[index] is set 120 ********************************************************************************************/ 119 121 extern inline bool_t bitmap_state( bitmap_t * bitmap, 120 122 uint32_t index ); 121 123 122 /********************************************************************************************* *124 /********************************************************************************************* 123 125 * This function set a range of bits in a bitmap : [index ... (index + len)[ 124 ********************************************************************************************* *126 ********************************************************************************************* 125 127 * @ bitmap : pointer on the bitmap 126 128 * @ index : first bit index in the bitmap 127 129 * @ len : number of bits to set 128 ******************************************************************************************** */130 ********************************************************************************************/ 129 131 extern void bitmap_set_range( bitmap_t * bitmap, 130 132 uint32_t index, 131 133 uint32_t len ); 132 134 133 /********************************************************************************************* *135 /********************************************************************************************* 134 136 * This function reset a range of bits in a bitmap : [index ... (index + len)[ 135 ********************************************************************************************* *137 ********************************************************************************************* 136 138 * @ bitmap : pointer on the bitmap 137 139 * @ index : first bit index in the bitmap 138 140 * @ len : number of bits to clear 139 ******************************************************************************************** */141 ********************************************************************************************/ 140 142 extern void bitmap_clear_range( bitmap_t * bitmap, 141 143 uint32_t index, 142 144 uint32_t len ); 143 145 144 /********************************************************************************************* *146 /********************************************************************************************* 145 147 * This function returns the index of first bit set in a bitmap, starting from index. 146 ********************************************************************************************* *148 ********************************************************************************************* 147 149 * @ bitmap : pointer on the bitmap 148 150 * @ index : first bit to analyse in the bitmap 149 151 * @ size : number of bits to analyse in bitmap 150 152 * @ returns index if found / returns 0xFFFFFFFF if bit not found 151 ******************************************************************************************** */153 ********************************************************************************************/ 152 154 extern uint32_t bitmap_ffs2( bitmap_t * bitmap, 153 155 uint32_t index, 154 156 uint32_t size ); 155 157 156 /********************************************************************************************* *158 /********************************************************************************************* 157 159 * This function returns the index of first bit cleared in a bitmap, starting from index. 158 ********************************************************************************************* *160 ********************************************************************************************* 159 161 * @ bitmap : pointer on the bitmap 160 162 * @ index : first bit to analyse in the bitmap 161 163 * @ size : number of bits to analyse in bitmap 162 164 * @ returns index if found / returns 0xFFFFFFFF if bit not found 163 ******************************************************************************************** */165 ********************************************************************************************/ 164 166 extern uint32_t bitmap_ffc2( bitmap_t * bitmap, 165 167 uint32_t index, 166 168 uint32_t size ); 167 169 168 /********************************************************************************************* *170 /********************************************************************************************* 169 171 * This function returns the index of first bit set in a bitmap, starting from bit 0. 170 ********************************************************************************************* *172 ********************************************************************************************* 171 173 * @ bitmap : pointer on the bitmap 172 174 * @ size : number of bits to analyse in bitmap 173 175 * @ returns index if found / returns 0xFFFFFFFF if bit not found 174 ******************************************************************************************** */176 ********************************************************************************************/ 175 177 extern uint32_t bitmap_ffs( bitmap_t * bitmap, 176 178 uint32_t size ); 177 179 178 /********************************************************************************************* *180 /********************************************************************************************* 179 181 * This function returns the index of first bit cleared in a bitmap, starting from bit 0. 180 ********************************************************************************************* *182 ********************************************************************************************* 181 183 * @ bitmap : pointer on the bitmap 182 184 * @ size : number of bits to alalyse in bitmap 183 185 * @ returns index if found / returns 0xFFFFFFFF if bit not found 184 ******************************************************************************************** */186 ********************************************************************************************/ 185 187 extern uint32_t bitmap_ffc( bitmap_t * bitmap, 186 188 uint32_t size ); 187 189 188 /********************************************************************************************* *190 /********************************************************************************************* 189 191 * This function returns the number of bits to code a non-zero unsigned integer value. 190 ********************************************************************************************* *192 ********************************************************************************************* 191 193 * @ val : value to analyse 192 194 * @ returns number of bits 193 ******************************************************************************************** */195 ********************************************************************************************/ 194 196 static inline uint32_t bits_nr( uint32_t val ) 195 197 { … … 202 204 } 203 205 204 /********************************************************************************************* *206 /********************************************************************************************* 205 207 * This function takes an unsigned integer value as input argument, and returns another 206 208 * unsigned integer, that is the (base 2) logarithm of the smallest power of 2 contained 207 209 * in the input value. 208 ********************************************************************************************* *210 ********************************************************************************************* 209 211 * @ val : value to analyse 210 212 * @ returns logarithm value 211 ******************************************************************************************** */213 ********************************************************************************************/ 212 214 static inline uint32_t bits_log2( uint32_t val ) 213 215 {
Note: See TracChangeset
for help on using the changeset viewer.