Skip to content

Commit 806f52c

Browse files
committed
Fix issue on missing methods on older android NDKs
1 parent 9834c71 commit 806f52c

File tree

2 files changed

+47
-6
lines changed

2 files changed

+47
-6
lines changed

.github/workflows/build_android.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
distribution: ${{env.JAVA_DISTRIBUTION}}
4545
java-version: ${{env.JAVA_VERSION}}
4646
- name: Setup Android SDK
47-
uses: android-actions/setup-android@v2.0.10
47+
uses: android-actions/setup-android@v3
4848
- name: Setup Android NDK
4949
uses: nttld/setup-ndk@v1
5050
with:
@@ -71,7 +71,7 @@ jobs:
7171
distribution: ${{env.JAVA_DISTRIBUTION}}
7272
java-version: ${{env.JAVA_VERSION}}
7373
- name: Setup Android SDK
74-
uses: android-actions/setup-android@v2.0.10
74+
uses: android-actions/setup-android@v3
7575
- name: Setup Android NDK
7676
uses: nttld/setup-ndk@v1
7777
with:
@@ -102,7 +102,7 @@ jobs:
102102
distribution: ${{env.JAVA_DISTRIBUTION}}
103103
java-version: ${{env.JAVA_VERSION}}
104104
- name: Setup Android SDK
105-
uses: android-actions/setup-android@v2.0.10
105+
uses: android-actions/setup-android@v3
106106
- name: Setup Android NDK
107107
uses: nttld/setup-ndk@v1
108108
with:

thirdparty/bungee_library/upstream/src/log2.h

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,52 @@
55

66
#include "Assert.h"
77

8-
#include <bit>
8+
#include <limits>
99
#include <type_traits>
1010

1111
namespace Bungee {
1212

13+
template <class T>
14+
constexpr int bit_width(T x) noexcept
15+
{
16+
static_assert(std::is_integral_v<T>, "T must be an integral type");
17+
using U = std::make_unsigned_t<T>;
18+
19+
U u = static_cast<U>(x);
20+
21+
if (u == 0)
22+
return 0;
23+
24+
int width = 0;
25+
while (u != 0)
26+
{
27+
u >>= 1;
28+
++width;
29+
}
30+
31+
return width;
32+
}
33+
34+
template <class T>
35+
constexpr int countr_zero(T x) noexcept
36+
{
37+
static_assert(std::is_integral_v<T>, "T must be an integral type");
38+
using U = std::make_unsigned_t<T>;
39+
U u = static_cast<U>(x);
40+
41+
if (u == 0)
42+
return std::numeric_limits<U>::digits; // number of bits in type
43+
44+
int count = 0;
45+
while ((u & 1) == 0)
46+
{
47+
u >>= 1;
48+
++count;
49+
}
50+
51+
return count;
52+
}
53+
1354
template <bool floor = false>
1455
static inline int log2(unsigned x)
1556
{
@@ -18,9 +59,9 @@ static inline int log2(unsigned x)
1859

1960
int y;
2061
if constexpr (floor)
21-
y = std::bit_width(x) - 1;
62+
y = bit_width(x) - 1;
2263
else
23-
y = std::countr_zero(x);
64+
y = countr_zero(x);
2465

2566
BUNGEE_ASSERT1(floor ? (1 << y <= x && x < 2 << y) : (x == 1 << y));
2667
return y;

0 commit comments

Comments
 (0)