Protocol Buffers - Google's data interchange format (grpc依赖)
https://developers.google.com/protocol-buffers/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
873 B
38 lines
873 B
// Protocol Buffers - Google's data interchange format |
|
// Copyright 2023 Google LLC. All rights reserved. |
|
// https://developers.google.com/protocol-buffers/ |
|
/// |
|
// Use of this source code is governed by a BSD-style |
|
// license that can be found in the LICENSE file or at |
|
// https://developers.google.com/open-source/licenses/bsd |
|
|
|
#ifndef UPB_BASE_INTERNAL_LOG2_H_ |
|
#define UPB_BASE_INTERNAL_LOG2_H_ |
|
|
|
// Must be last. |
|
#include "upb/port/def.inc" |
|
|
|
#ifdef __cplusplus |
|
extern "C" { |
|
#endif |
|
|
|
UPB_INLINE int upb_Log2Ceiling(int x) { |
|
if (x <= 1) return 0; |
|
#ifdef __GNUC__ |
|
return 32 - __builtin_clz(x - 1); |
|
#else |
|
int lg2 = 0; |
|
while ((1 << lg2) < x) lg2++; |
|
return lg2; |
|
#endif |
|
} |
|
|
|
UPB_INLINE int upb_Log2CeilingSize(int x) { return 1 << upb_Log2Ceiling(x); } |
|
|
|
#ifdef __cplusplus |
|
} /* extern "C" */ |
|
#endif |
|
|
|
#include "upb/port/undef.inc" |
|
|
|
#endif /* UPB_BASE_INTERNAL_LOG2_H_ */
|
|
|