Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:13:16

0001 // Protocol Buffers - Google's data interchange format
0002 // Copyright 2023 Google LLC.  All rights reserved.
0003 // https://developers.google.com/protocol-buffers/
0004 ///
0005 // Use of this source code is governed by a BSD-style
0006 // license that can be found in the LICENSE file or at
0007 // https://developers.google.com/open-source/licenses/bsd
0008 
0009 #ifndef UPB_BASE_INTERNAL_LOG2_H_
0010 #define UPB_BASE_INTERNAL_LOG2_H_
0011 
0012 // Must be last.
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 } /* extern "C" */
0034 #endif
0035 
0036 #include "upb/port/undef.inc"
0037 
0038 #endif /* UPB_BASE_INTERNAL_LOG2_H_ */