WPILibC++
2027.0.0-alpha-3
Loading...
Searching...
No Matches
log2.h
Go to the documentation of this file.
1
// Protocol Buffers - Google's data interchange format
2
// Copyright 2023 Google LLC. All rights reserved.
3
// https://developers.google.com/protocol-buffers/
4
///
5
// Use of this source code is governed by a BSD-style
6
// license that can be found in the LICENSE file or at
7
// https://developers.google.com/open-source/licenses/bsd
8
9
#ifndef UPB_BASE_INTERNAL_LOG2_H_
10
#define UPB_BASE_INTERNAL_LOG2_H_
11
12
// Must be last.
13
#include "
upb/port/def.inc
"
14
15
#ifdef __cplusplus
16
extern
"C"
{
17
#endif
18
19
UPB_INLINE
int
upb_Log2Ceiling
(
int
x) {
20
if
(x <= 1)
return
0;
21
#ifdef __GNUC__
22
return
32 - __builtin_clz(x - 1);
23
#else
24
int
lg2 = 0;
25
while
((1 << lg2) < x) lg2++;
26
return
lg2;
27
#endif
28
}
29
30
UPB_INLINE
int
upb_RoundUpToPowerOfTwo
(
int
x) {
31
return
1 <<
upb_Log2Ceiling
(x);
32
}
33
34
#ifdef __cplusplus
35
}
/* extern "C" */
36
#endif
37
38
#include "
upb/port/undef.inc
"
39
40
#endif
/* UPB_BASE_INTERNAL_LOG2_H_ */
def.inc
UPB_INLINE
#define UPB_INLINE
Definition
def.inc:144
upb_Log2Ceiling
UPB_INLINE int upb_Log2Ceiling(int x)
Definition
log2.h:19
upb_RoundUpToPowerOfTwo
UPB_INLINE int upb_RoundUpToPowerOfTwo(int x)
Definition
log2.h:30
undef.inc
upb
base
internal
log2.h
Generated on Fri Oct 24 2025 05:38:27 for WPILibC++ by
1.12.0