File indexing completed on 2025-01-18 10:13:16
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef UPB_BASE_INTERNAL_LOG2_H_
0010 #define UPB_BASE_INTERNAL_LOG2_H_
0011
0012
0013 #include "upb/port/def.inc"
0014
0015 #ifdef __cplusplus
0016 extern "C" {
0017 #endif
0018
0019 UPB_INLINE int upb_Log2Ceiling(int x) {
0020 if (x <= 1) return 0;
0021 #ifdef __GNUC__
0022 return 32 - __builtin_clz(x - 1);
0023 #else
0024 int lg2 = 0;
0025 while ((1 << lg2) < x) lg2++;
0026 return lg2;
0027 #endif
0028 }
0029
0030 UPB_INLINE int upb_Log2CeilingSize(int x) { return 1 << upb_Log2Ceiling(x); }
0031
0032 #ifdef __cplusplus
0033 }
0034 #endif
0035
0036 #include "upb/port/undef.inc"
0037
0038 #endif