@@ -40,75 +40,75 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4040
4141#if defined(DAEMON_USE_COMPILER_INTRINSICS ) && defined(__GNUC__ )
4242
43- uint32_t FindLSB ( const uint32_t value ) {
44- return value ? __builtin_ctzl ( value ) : 32 ;
45- }
43+ inline uint32_t FindLSB ( const uint32_t value ) {
44+ return value ? __builtin_ctzl ( value ) : 32 ;
45+ }
4646
47- uint32_t FindLSB ( const uint64_t value ) {
48- return value ? __builtin_ctzll ( value ) : 64 ;
49- }
47+ inline uint32_t FindLSB ( const uint64_t value ) {
48+ return value ? __builtin_ctzll ( value ) : 64 ;
49+ }
5050
51- uint32_t FindMSB ( const uint32_t value ) {
52- return value ? __builtin_clzl ( value ) : 32 ;
53- }
51+ inline uint32_t FindMSB ( const uint32_t value ) {
52+ return value ? __builtin_clzl ( value ) : 32 ;
53+ }
5454
55- uint32_t FindMSB ( const uint64_t value ) {
56- return value ? __builtin_clzll ( value ) : 64 ;
57- }
55+ inline uint32_t FindMSB ( const uint64_t value ) {
56+ return value ? __builtin_clzll ( value ) : 64 ;
57+ }
5858
59- uint16_t CountLeadingZeroes ( const uint16_t value ) {
60- return FindLSB ( value );
61- }
59+ inline uint16_t CountLeadingZeroes ( const uint16_t value ) {
60+ return FindLSB ( value );
61+ }
6262
63- uint32_t CountLeadingZeroes ( const uint32_t value ) {
64- return FindLSB ( value );
65- }
63+ inline uint32_t CountLeadingZeroes ( const uint32_t value ) {
64+ return FindLSB ( value );
65+ }
6666
67- uint64_t CountLeadingZeroes ( const uint64_t value ) {
68- return FindLSB ( value );
69- }
67+ inline uint64_t CountLeadingZeroes ( const uint64_t value ) {
68+ return FindLSB ( value );
69+ }
7070
7171#elif defined(DAEMON_USE_COMPILER_INTRINSICS ) && defined(_MSC_VER )
7272
73- uint32_t FindLSB ( const uint32_t value ) {
73+ inline uint32_t FindLSB ( const uint32_t value ) {
7474 unsigned long index ;
7575 const bool nonZero = _BitScanForward ( & index , value );
7676 return nonZero ? index : 32 ;
7777 }
7878
79- uint32_t FindLSB ( const uint64_t value ) {
79+ inline uint32_t FindLSB ( const uint64_t value ) {
8080 unsigned long index ;
8181 const bool nonZero = _BitScanForward64 ( & index , value );
8282 return nonZero ? index : 64 ;
8383 }
8484
85- uint32_t FindMSB ( const uint32_t value ) {
85+ inline uint32_t FindMSB ( const uint32_t value ) {
8686 unsigned long index ;
8787 const bool nonZero = _BitScanReverse ( & index , value );
8888 return nonZero ? index : 32 ;
8989 }
9090
91- uint32_t FindMSB ( const uint64_t value ) {
91+ inline uint32_t FindMSB ( const uint64_t value ) {
9292 unsigned long index ;
9393 const bool nonZero = _BitScanReverse64 ( & index , value );
9494 return nonZero ? index : 64 ;
9595 }
9696
97- uint16_t CountLeadingZeroes ( const uint16_t value ) {
97+ inline uint16_t CountLeadingZeroes ( const uint16_t value ) {
9898 return __lzcnt16 ( value );
9999 }
100100
101- uint32_t CountLeadingZeroes ( const uint32_t value ) {
101+ inline uint32_t CountLeadingZeroes ( const uint32_t value ) {
102102 return __lzcnt ( value );
103103 }
104104
105- uint64_t CountLeadingZeroes ( const uint64_t value ) {
105+ inline uint64_t CountLeadingZeroes ( const uint64_t value ) {
106106 return __lzcnt64 ( value );
107107 }
108108
109109#else
110110
111- uint32_t FindLSB ( const uint32_t value ) {
111+ inline uint32_t FindLSB ( const uint32_t value ) {
112112 for ( int i = 0 ; i < 32 ; i ++ ) {
113113 if ( value & ( 1u << i ) ) {
114114 return i ;
@@ -118,7 +118,7 @@ uint64_t CountLeadingZeroes( const uint64_t value ) {
118118 return 32 ;
119119 }
120120
121- uint32_t FindLSB ( const uint64_t value ) {
121+ inline uint32_t FindLSB ( const uint64_t value ) {
122122 for ( int i = 0 ; i < 64 ; i ++ ) {
123123 if ( value & ( 1ull << i ) ) {
124124 return i ;
@@ -128,7 +128,7 @@ uint64_t CountLeadingZeroes( const uint64_t value ) {
128128 return 64 ;
129129 }
130130
131- uint32_t FindMSB ( const uint32_t value ) {
131+ inline uint32_t FindMSB ( const uint32_t value ) {
132132 for ( int i = 31 ; i >= 0 ; i -- ) {
133133 if ( value & ( 1u << i ) ) {
134134 return i ;
@@ -138,7 +138,7 @@ uint64_t CountLeadingZeroes( const uint64_t value ) {
138138 return 32 ;
139139 }
140140
141- uint32_t FindMSB ( const uint64_t value ) {
141+ inline uint32_t FindMSB ( const uint64_t value ) {
142142 for ( int i = 63 ; i >= 0 ; i -- ) {
143143 if ( value & ( 1ull << i ) ) {
144144 return i ;
@@ -148,125 +148,125 @@ uint64_t CountLeadingZeroes( const uint64_t value ) {
148148 return 63 ;
149149 }
150150
151- uint16_t CountLeadingZeroes ( const uint16_t value ) {
151+ inline uint16_t CountLeadingZeroes ( const uint16_t value ) {
152152 return value ? FindLSB ( value ) - 1 : 0 ;
153153 }
154154
155- uint32_t CountLeadingZeroes ( const uint32_t value ) {
155+ inline uint32_t CountLeadingZeroes ( const uint32_t value ) {
156156 return value ? FindLSB ( value ) - 1 : 0 ;
157157 }
158158
159- uint64_t CountLeadingZeroes ( const uint64_t value ) {
159+ inline uint64_t CountLeadingZeroes ( const uint64_t value ) {
160160 return value ? FindLSB ( value ) - 1 : 0 ;
161161 }
162162
163163#endif
164164
165- [[nodiscard ]] uint8_t SetBit ( const uint8_t value , const uint32_t bit ) {
165+ [[nodiscard ]] inline uint8_t SetBit ( const uint8_t value , const uint32_t bit ) {
166166 return value | ( 1u << bit );
167167}
168168
169- [[nodiscard ]] uint16_t SetBit ( const uint16_t value , const uint32_t bit ) {
169+ [[nodiscard ]] inline uint16_t SetBit ( const uint16_t value , const uint32_t bit ) {
170170 return value | ( 1u << bit );
171171}
172172
173- [[nodiscard ]] uint32_t SetBit ( const uint32_t value , const uint32_t bit ) {
173+ [[nodiscard ]] inline uint32_t SetBit ( const uint32_t value , const uint32_t bit ) {
174174 return value | ( 1u << bit );
175175}
176176
177- [[nodiscard ]] uint64_t SetBit ( const uint64_t value , const uint32_t bit ) {
177+ [[nodiscard ]] inline uint64_t SetBit ( const uint64_t value , const uint32_t bit ) {
178178 return value | ( 1ull << bit );
179179}
180180
181- void SetBit ( uint8_t * value , const uint32_t bit ) {
181+ inline void SetBit ( uint8_t * value , const uint32_t bit ) {
182182 * value |= ( 1u << bit );
183183}
184184
185- void SetBit ( uint16_t * value , const uint32_t bit ) {
185+ inline void SetBit ( uint16_t * value , const uint32_t bit ) {
186186 * value |= ( 1u << bit );
187187}
188188
189- void SetBit ( uint32_t * value , const uint32_t bit ) {
189+ inline void SetBit ( uint32_t * value , const uint32_t bit ) {
190190 * value |= ( 1u << bit );
191191}
192192
193- void SetBit ( uint64_t * value , const uint32_t bit ) {
193+ inline void SetBit ( uint64_t * value , const uint32_t bit ) {
194194 * value |= ( 1ull << bit );
195195}
196196
197- [[nodiscard ]] uint8_t UnSetBit ( const uint8_t value , const uint32_t bit ) {
197+ [[nodiscard ]] inline uint8_t UnSetBit ( const uint8_t value , const uint32_t bit ) {
198198 return value & ~( 1u << bit );
199199}
200200
201- [[nodiscard ]] uint16_t UnSetBit ( const uint16_t value , const uint32_t bit ) {
201+ [[nodiscard ]] inline uint16_t UnSetBit ( const uint16_t value , const uint32_t bit ) {
202202 return value & ~( 1u << bit );
203203}
204204
205- [[nodiscard ]] uint32_t UnSetBit ( const uint32_t value , const uint32_t bit ) {
205+ [[nodiscard ]] inline uint32_t UnSetBit ( const uint32_t value , const uint32_t bit ) {
206206 return value & ~( 1u << bit );
207207}
208208
209- [[nodiscard ]] uint64_t UnSetBit ( const uint64_t value , const uint32_t bit ) {
209+ [[nodiscard ]] inline uint64_t UnSetBit ( const uint64_t value , const uint32_t bit ) {
210210 return value & ~( 1ull << bit );
211211}
212212
213- void UnSetBit ( uint8_t * value , const uint32_t bit ) {
213+ inline void UnSetBit ( uint8_t * value , const uint32_t bit ) {
214214 * value &= ~( 1u << bit );
215215}
216216
217- void UnSetBit ( uint16_t * value , const uint32_t bit ) {
217+ inline void UnSetBit ( uint16_t * value , const uint32_t bit ) {
218218 * value &= ~( 1u << bit );
219219}
220220
221- void UnSetBit ( uint32_t * value , const uint32_t bit ) {
221+ inline void UnSetBit ( uint32_t * value , const uint32_t bit ) {
222222 * value &= ~( 1u << bit );
223223}
224224
225- void UnSetBit ( uint64_t * value , const uint32_t bit ) {
225+ inline void UnSetBit ( uint64_t * value , const uint32_t bit ) {
226226 * value &= ~( 1ull << bit );
227227}
228228
229- int CompareBit ( const uint8_t lhs , const uint8_t rhs , const uint32_t bit ) {
229+ inline int CompareBit ( const uint8_t lhs , const uint8_t rhs , const uint32_t bit ) {
230230 const uint8_t lhsBit = lhs & ( 1u << bit );
231231 const uint8_t rhsBit = rhs & ( 1u << bit );
232232 return lhsBit < rhsBit ? -1 : ( lhsBit > rhsBit ? 1 : 0 );
233233}
234234
235- int CompareBit ( const uint16_t lhs , const uint16_t rhs , const uint32_t bit ) {
235+ inline int CompareBit ( const uint16_t lhs , const uint16_t rhs , const uint32_t bit ) {
236236 const uint16_t lhsBit = lhs & ( 1u << bit );
237237 const uint16_t rhsBit = rhs & ( 1u << bit );
238238 return lhsBit < rhsBit ? -1 : ( lhsBit > rhsBit ? 1 : 0 );
239239}
240240
241- int CompareBit ( const uint32_t lhs , const uint32_t rhs , const uint32_t bit ) {
241+ inline int CompareBit ( const uint32_t lhs , const uint32_t rhs , const uint32_t bit ) {
242242 const uint32_t lhsBit = lhs & ( 1u << bit );
243243 const uint32_t rhsBit = rhs & ( 1u << bit );
244244 return lhsBit < rhsBit ? -1 : ( lhsBit > rhsBit ? 1 : 0 );
245245}
246246
247- int CompareBit ( const uint64_t lhs , const uint64_t rhs , const uint32_t bit ) {
247+ inline int CompareBit ( const uint64_t lhs , const uint64_t rhs , const uint32_t bit ) {
248248 const uint64_t lhsBit = lhs & ( 1ull << bit );
249249 const uint64_t rhsBit = rhs & ( 1ull << bit );
250250 return lhsBit < rhsBit ? -1 : ( lhsBit > rhsBit ? 1 : 0 );
251251}
252252
253- const bool BitSet ( const uint8_t value , const uint32_t bit ) {
253+ inline const bool BitSet ( const uint8_t value , const uint32_t bit ) {
254254 return value & ( 1u << bit );
255255}
256256
257- const bool BitSet ( const uint16_t value , const uint32_t bit ) {
257+ inline const bool BitSet ( const uint16_t value , const uint32_t bit ) {
258258 return value & ( 1u << bit );
259259}
260260
261- const bool BitSet ( const uint32_t value , const uint32_t bit ) {
261+ inline const bool BitSet ( const uint32_t value , const uint32_t bit ) {
262262 return value & ( 1u << bit );
263263}
264264
265- const bool BitSet ( const uint64_t value , const uint32_t bit ) {
265+ inline const bool BitSet ( const uint64_t value , const uint32_t bit ) {
266266 return value & ( 1ull << bit );
267267}
268268
269- uint32_t FindMZeroBit ( uint64_t value ) {
269+ inline uint32_t FindMZeroBit ( uint64_t value ) {
270270 if ( value == UINT64_MAX ) {
271271 return 64 ;
272272 }
@@ -279,7 +279,7 @@ uint32_t FindMZeroBit( uint64_t value ) {
279279 return bit - 1 ;
280280}
281281
282- uint32_t FindZeroBitFast ( const uint64_t value ) {
282+ inline uint32_t FindZeroBitFast ( const uint64_t value ) {
283283 const uint32_t bit = FindLSB ( value );
284284 return bit ? bit - 1 : FindLSB ( ~value ) - 1 ;
285285}
0 commit comments