OLD | NEW |
1 /* | 1 /* |
2 * Copyright © 2007,2008,2009 Red Hat, Inc. | 2 * Copyright © 2007,2008,2009 Red Hat, Inc. |
3 * Copyright © 2011,2012 Google, Inc. | 3 * Copyright © 2011,2012 Google, Inc. |
4 * | 4 * |
5 * This is part of HarfBuzz, a text shaping library. | 5 * This is part of HarfBuzz, a text shaping library. |
6 * | 6 * |
7 * Permission is hereby granted, without written agreement and without | 7 * Permission is hereby granted, without written agreement and without |
8 * license or royalty fees, to use, copy, modify, and distribute this | 8 * license or royalty fees, to use, copy, modify, and distribute this |
9 * software and its documentation for any purpose, provided that the | 9 * software and its documentation for any purpose, provided that the |
10 * above copyright notice and the following two paragraphs appear in | 10 * above copyright notice and the following two paragraphs appear in |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 | 212 |
213 | 213 |
214 /* Return the number of 1 bits in mask. */ | 214 /* Return the number of 1 bits in mask. */ |
215 static inline HB_CONST_FUNC unsigned int | 215 static inline HB_CONST_FUNC unsigned int |
216 _hb_popcount32 (uint32_t mask) | 216 _hb_popcount32 (uint32_t mask) |
217 { | 217 { |
218 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) | 218 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) |
219 return __builtin_popcount (mask); | 219 return __builtin_popcount (mask); |
220 #else | 220 #else |
221 /* "HACKMEM 169" */ | 221 /* "HACKMEM 169" */ |
222 register uint32_t y; | 222 uint32_t y; |
223 y = (mask >> 1) &033333333333; | 223 y = (mask >> 1) &033333333333; |
224 y = mask - y - ((y >>1) & 033333333333); | 224 y = mask - y - ((y >>1) & 033333333333); |
225 return (((y + (y >> 3)) & 030707070707) % 077); | 225 return (((y + (y >> 3)) & 030707070707) % 077); |
226 #endif | 226 #endif |
227 } | 227 } |
228 | 228 |
229 /* Returns the number of bits needed to store number */ | 229 /* Returns the number of bits needed to store number */ |
230 static inline HB_CONST_FUNC unsigned int | 230 static inline HB_CONST_FUNC unsigned int |
231 _hb_bit_storage (unsigned int number) | 231 _hb_bit_storage (unsigned int number) |
232 { | 232 { |
233 #if defined(__GNUC__) && (__GNUC__ >= 4) && defined(__OPTIMIZE__) | 233 #if defined(__GNUC__) && (__GNUC__ >= 4) && defined(__OPTIMIZE__) |
234 return likely (number) ? (sizeof (unsigned int) * 8 - __builtin_clz (number))
: 0; | 234 return likely (number) ? (sizeof (unsigned int) * 8 - __builtin_clz (number))
: 0; |
235 #else | 235 #else |
236 register unsigned int n_bits = 0; | 236 unsigned int n_bits = 0; |
237 while (number) { | 237 while (number) { |
238 n_bits++; | 238 n_bits++; |
239 number >>= 1; | 239 number >>= 1; |
240 } | 240 } |
241 return n_bits; | 241 return n_bits; |
242 #endif | 242 #endif |
243 } | 243 } |
244 | 244 |
245 /* Returns the number of zero bits in the least significant side of number */ | 245 /* Returns the number of zero bits in the least significant side of number */ |
246 static inline HB_CONST_FUNC unsigned int | 246 static inline HB_CONST_FUNC unsigned int |
247 _hb_ctz (unsigned int number) | 247 _hb_ctz (unsigned int number) |
248 { | 248 { |
249 #if defined(__GNUC__) && (__GNUC__ >= 4) && defined(__OPTIMIZE__) | 249 #if defined(__GNUC__) && (__GNUC__ >= 4) && defined(__OPTIMIZE__) |
250 return likely (number) ? __builtin_ctz (number) : 0; | 250 return likely (number) ? __builtin_ctz (number) : 0; |
251 #else | 251 #else |
252 register unsigned int n_bits = 0; | 252 unsigned int n_bits = 0; |
253 if (unlikely (!number)) return 0; | 253 if (unlikely (!number)) return 0; |
254 while (!(number & 1)) { | 254 while (!(number & 1)) { |
255 n_bits++; | 255 n_bits++; |
256 number >>= 1; | 256 number >>= 1; |
257 } | 257 } |
258 return n_bits; | 258 return n_bits; |
259 #endif | 259 #endif |
260 } | 260 } |
261 | 261 |
262 static inline bool | 262 static inline bool |
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
801 { | 801 { |
802 if ( ((lo^hi) & lo) == 0 && | 802 if ( ((lo^hi) & lo) == 0 && |
803 ((lo^hi) & hi) == (lo^hi) && | 803 ((lo^hi) & hi) == (lo^hi) && |
804 ((lo^hi) & ((lo^hi) + 1)) == 0 ) | 804 ((lo^hi) & ((lo^hi) + 1)) == 0 ) |
805 return (u & ~(lo^hi)) == lo; | 805 return (u & ~(lo^hi)) == lo; |
806 else | 806 else |
807 return lo <= u && u <= hi; | 807 return lo <= u && u <= hi; |
808 } | 808 } |
809 | 809 |
810 template <typename T> static inline bool | 810 template <typename T> static inline bool |
| 811 hb_in_ranges (T u, T lo1, T hi1, T lo2, T hi2) |
| 812 { |
| 813 return hb_in_range (u, lo1, hi1) || hb_in_range (u, lo2, hi2); |
| 814 } |
| 815 |
| 816 template <typename T> static inline bool |
811 hb_in_ranges (T u, T lo1, T hi1, T lo2, T hi2, T lo3, T hi3) | 817 hb_in_ranges (T u, T lo1, T hi1, T lo2, T hi2, T lo3, T hi3) |
812 { | 818 { |
813 return hb_in_range (u, lo1, hi1) || hb_in_range (u, lo2, hi2) || hb_in_range (
u, lo3, hi3); | 819 return hb_in_range (u, lo1, hi1) || hb_in_range (u, lo2, hi2) || hb_in_range (
u, lo3, hi3); |
814 } | 820 } |
815 | 821 |
816 | 822 |
817 /* Useful for set-operations on small enums. | 823 /* Useful for set-operations on small enums. |
818 * For example, for testing "x ∈ {x1, x2, x3}" use: | 824 * For example, for testing "x ∈ {x1, x2, x3}" use: |
819 * (FLAG(x) & (FLAG(x1) | FLAG(x2) | FLAG(x3))) | 825 * (FLAG(x) & (FLAG(x1) | FLAG(x2) | FLAG(x3))) |
820 */ | 826 */ |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
903 hb_options (void) | 909 hb_options (void) |
904 { | 910 { |
905 if (unlikely (!_hb_options.i)) | 911 if (unlikely (!_hb_options.i)) |
906 _hb_options_init (); | 912 _hb_options_init (); |
907 | 913 |
908 return _hb_options.opts; | 914 return _hb_options.opts; |
909 } | 915 } |
910 | 916 |
911 | 917 |
912 #endif /* HB_PRIVATE_HH */ | 918 #endif /* HB_PRIVATE_HH */ |
OLD | NEW |