Skip to content

Commit 96707e3

Browse files
committed
Re-sync c-core 1.73.0-pre1
1 parent a7928c6 commit 96707e3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+10928
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Protocol Buffers - Google's data interchange format
2+
// Copyright 2023 Google LLC. All rights reserved.
3+
//
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file or at
6+
// https://developers.google.com/open-source/licenses/bsd
7+
8+
#ifndef UPB_BASE_INTERNAL_ENDIAN_H_
9+
#define UPB_BASE_INTERNAL_ENDIAN_H_
10+
11+
#include <stdint.h>
12+
13+
// Must be last.
14+
#include "upb/port/def.inc"
15+
16+
#ifdef __cplusplus
17+
extern "C" {
18+
#endif
19+
20+
UPB_INLINE bool upb_IsLittleEndian(void) {
21+
const int x = 1;
22+
return *(char*)&x == 1;
23+
}
24+
25+
UPB_INLINE uint32_t upb_BigEndian32(uint32_t val) {
26+
if (upb_IsLittleEndian()) return val;
27+
28+
return ((val & 0xff) << 24) | ((val & 0xff00) << 8) |
29+
((val & 0xff0000) >> 8) | ((val & 0xff000000) >> 24);
30+
}
31+
32+
UPB_INLINE uint64_t upb_BigEndian64(uint64_t val) {
33+
if (upb_IsLittleEndian()) return val;
34+
35+
const uint64_t hi = ((uint64_t)upb_BigEndian32((uint32_t)val)) << 32;
36+
const uint64_t lo = upb_BigEndian32((uint32_t)(val >> 32));
37+
return hi | lo;
38+
}
39+
40+
#ifdef __cplusplus
41+
} /* extern "C" */
42+
#endif
43+
44+
#include "upb/port/undef.inc"
45+
46+
#endif /* UPB_BASE_INTERNAL_ENDIAN_H_ */
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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_ */

0 commit comments

Comments
 (0)