Skip to content

Commit f16216c

Browse files
author
Julian LALU
committed
replace if (hud::is_constant_evaluated()) with if consteval
1 parent 694a4fc commit f16216c

18 files changed

+426
-396
lines changed

.github/workflows/coverage.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ on:
55
branches: ["main"]
66

77
jobs:
8-
# We deactivate it because LCOV_EXCL_START and LCOV_EXCL_STOP are not
9-
# taken into account, same for if (hud::is_constant_evaluated())
8+
# We deactivate it because LCOV_EXCL_START and LCOV_EXCL_STOP are not
9+
# taken into account, same for if consteval
1010
# coverage_windows_msvc:
1111
# runs-on: windows-latest
1212
# steps:
@@ -122,4 +122,4 @@ jobs:
122122
name: coverage-linux-gcc
123123
path: |
124124
target/test/coverage.linux.gcc.lcov.info
125-
target/test/linux.gcc/
125+
target/test/linux.gcc/

interface/core/bits/bits_windows.h

Lines changed: 64 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace hud::windows
1717
*/
1818
static constexpr u32 reverse_bytes(const u32 value) noexcept
1919
{
20-
if (hud::is_constant_evaluated())
20+
if consteval
2121
{
2222
u32 tmp = ((value << 8) & 0xFF00FF00) | ((value >> 8) & 0xFF00FF);
2323
return (tmp << 16) | (tmp >> 16);
@@ -36,7 +36,7 @@ namespace hud::windows
3636
*/
3737
static constexpr u64 reverse_bytes(const u64 value) noexcept
3838
{
39-
if (hud::is_constant_evaluated())
39+
if consteval
4040
{
4141
u64 tmp = value;
4242
tmp = ((tmp & 0x00000000FFFFFFFFull) << 32) | ((tmp & 0xFFFFFFFF00000000ull) >> 32);
@@ -58,7 +58,7 @@ namespace hud::windows
5858
*/
5959
static constexpr u32 rotate_left(const u32 value, const u32 shift) noexcept
6060
{
61-
if (hud::is_constant_evaluated())
61+
if consteval
6262
{
6363
if (shift == 0)
6464
{
@@ -80,7 +80,7 @@ namespace hud::windows
8080
*/
8181
static constexpr u64 rotate_left(const u64 value, const u32 shift) noexcept
8282
{
83-
if (hud::is_constant_evaluated())
83+
if consteval
8484
{
8585
if (shift == 0)
8686
{
@@ -102,7 +102,7 @@ namespace hud::windows
102102
*/
103103
static constexpr u32 rotate_right(const u32 value, const u32 shift) noexcept
104104
{
105-
if (hud::is_constant_evaluated())
105+
if consteval
106106
{
107107
if (shift == 0)
108108
{
@@ -124,7 +124,7 @@ namespace hud::windows
124124
*/
125125
static constexpr u64 rotate_right(const u64 value, const u32 shift) noexcept
126126
{
127-
if (hud::is_constant_evaluated())
127+
if consteval
128128
{
129129
if (shift == 0)
130130
{
@@ -162,14 +162,19 @@ namespace hud::windows
162162
#else
163163
if (value == 0)
164164
return 32;
165-
if (hud::is_constant_evaluated())
165+
if consteval
166+
{
166167
return hud::common::bits::leading_zeros(value);
167-
u32 result = 0;
168-
if (_BitScanReverse((unsigned long *)&result, value))
168+
}
169+
else
169170
{
170-
return 31 - result;
171+
u32 result = 0;
172+
if (_BitScanReverse((unsigned long *)&result, value))
173+
{
174+
return 31 - result;
175+
}
176+
return 32;
171177
}
172-
return 32;
173178
#endif
174179
}
175180

@@ -181,27 +186,32 @@ namespace hud::windows
181186
#else
182187
if (value == 0)
183188
return 64;
184-
if (hud::is_constant_evaluated())
185-
return hud::common::bits::leading_zeros(value);
186-
#if defined(HD_TARGET_X64)
187-
u32 result = 0;
188-
if (_BitScanReverse64((unsigned long *)&result, value))
189-
{
190-
return 63 - result;
191-
}
192-
return 64;
193-
#else
194-
u32 result = 0;
195-
if ((value >> 32) && _BitScanReverse((unsigned long *)&result, static_cast<u32>(value >> 32)))
189+
if consteval
196190
{
197-
return 31 - result;
191+
return hud::common::bits::leading_zeros(value);
198192
}
199-
if (_BitScanReverse((unsigned long *)&result, static_cast<u32>(value)))
193+
else
200194
{
201-
return 63 - result;
202-
}
203-
return 64;
195+
#if defined(HD_TARGET_X64)
196+
u32 result = 0;
197+
if (_BitScanReverse64((unsigned long *)&result, value))
198+
{
199+
return 63 - result;
200+
}
201+
return 64;
202+
#else
203+
u32 result = 0;
204+
if ((value >> 32) && _BitScanReverse((unsigned long *)&result, static_cast<u32>(value >> 32)))
205+
{
206+
return 31 - result;
207+
}
208+
if (_BitScanReverse((unsigned long *)&result, static_cast<u32>(value)))
209+
{
210+
return 63 - result;
211+
}
212+
return 64;
204213
#endif
214+
}
205215
#endif
206216
}
207217

@@ -222,11 +232,16 @@ namespace hud::windows
222232
#else
223233
if (value == 0)
224234
return 32;
225-
if (hud::is_constant_evaluated())
235+
if consteval
236+
{
226237
return hud::common::bits::trailing_zeros(value);
227-
u32 result = 0;
228-
_BitScanForward((unsigned long *)&result, value);
229-
return result;
238+
}
239+
else
240+
{
241+
u32 result = 0;
242+
_BitScanForward((unsigned long *)&result, value);
243+
return result;
244+
}
230245
#endif
231246
}
232247

@@ -237,22 +252,27 @@ namespace hud::windows
237252
#else
238253
if (value == 0)
239254
return 64;
240-
if (hud::is_constant_evaluated())
255+
if consteval
256+
{
241257
return hud::common::bits::trailing_zeros(value);
258+
}
259+
else
260+
{
242261
#if defined(HD_TARGET_X64)
243-
u64 result = 0;
244-
_BitScanForward64((unsigned long *)&result, value);
245-
return result;
262+
u64 result = 0;
263+
_BitScanForward64((unsigned long *)&result, value);
264+
return result;
246265
#else
247-
u32 result = 0;
248-
if (static_cast<u32>(value) == 0)
249-
{
250-
_BitScanForward((unsigned long *)&result, static_cast<u32>(value >> 32));
251-
return result + 32;
252-
}
253-
_BitScanForward((unsigned long *)&result, static_cast<u32>(value));
254-
return result;
266+
u32 result = 0;
267+
if (static_cast<u32>(value) == 0)
268+
{
269+
_BitScanForward((unsigned long *)&result, static_cast<u32>(value >> 32));
270+
return result + 32;
271+
}
272+
_BitScanForward((unsigned long *)&result, static_cast<u32>(value));
273+
return result;
255274
#endif
275+
}
256276
#endif
257277
}
258278
};

interface/core/containers/array.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ namespace hud
256256
{
257257
// We moving an array of bitwise movable constructible type where type_t != u_type_t We can't use reinterpret_cast to still the pointer
258258
// in constant evaluation. So we allocate a new allocation, move elements then free the moved allocation.
259-
if (hud::is_constant_evaluated())
259+
if consteval
260260
// LCOV_EXCL_START
261261
{
262262
allocation_() = allocator_().template allocate<type_t>(other.max_count());
@@ -1171,20 +1171,24 @@ namespace hud
11711171
// If we don't need to reallocate
11721172
else
11731173
{
1174-
if (hud::is_constant_evaluated())
1174+
if consteval
11751175
// LCOV_EXCL_START
11761176
{
11771177
copy_assign_or_copy_construct_no_reallocation(source, source_count);
11781178
}
11791179
// LCOV_EXCL_STOP
1180-
else if (!hud::is_bitwise_copy_assignable_v<type_t, u_type_t>)
1181-
{
1182-
copy_assign_or_copy_construct_no_reallocation(source, source_count);
1183-
}
1184-
else if (source_count > 0u)
1180+
else
11851181
{
1186-
hud::memory::copy_assign_object_array(data(), source, source_count);
1182+
if (!hud::is_bitwise_copy_assignable_v<type_t, u_type_t>)
1183+
{
1184+
copy_assign_or_copy_construct_no_reallocation(source, source_count);
1185+
}
1186+
else if (source_count > 0u)
1187+
{
1188+
hud::memory::copy_assign_object_array(data(), source, source_count);
1189+
}
11871190
}
1191+
11881192
end_ptr = allocation_().data_at(source_count);
11891193
}
11901194
}

interface/core/defines.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@
1616
#define __STDC_WANT_LIB_EXT1__ 1 // Enable bounds-checked functions ( ISO C Safe Array Functions : memcpy_s, strcpy_s, snwprintf_s, etc... )
1717

1818
#if HD_HAS_BUILTIN_UNREACHABLE
19-
#define HD_ASSUME(cond) \
20-
do \
21-
{ \
22-
if (!hud::is_constant_evaluated()) \
23-
{ \
24-
if (!(cond)) \
25-
__builtin_unreachable(); \
26-
} \
19+
#define HD_ASSUME(cond) \
20+
do \
21+
{ \
22+
if consteval \
23+
{ \
24+
} \
25+
else \
26+
{ \
27+
if (!(cond)) \
28+
__builtin_unreachable(); \
29+
} \
2730
} while (false)
2831
#else
2932
#define HD_ASSUME(cond) \

interface/core/i128/i128_portable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ namespace hud
661661
constexpr u128_portable operator*(u128_portable other) const noexcept
662662
{
663663
#if defined(HD_COMPILER_MSVC) && defined(HD_TARGET_X64)
664-
if (hud::is_constant_evaluated())
664+
if consteval
665665
{
666666
u64 a32 = low_ >> 32;
667667
u64 a00 = low_ & 0xffffffff;

interface/core/math/math.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ namespace hud
338338
requires(hud::is_floating_point_v<type_t>)
339339
{
340340
// Implementation from boost https://live.boost.org/doc/libs/1_85_0/boost/math/ccmath/ldexp.hpp
341-
if (hud::is_constant_evaluated())
341+
if consteval
342342
{
343343
return math::abs(value) == type_t {0.f} ? value :
344344
!math::is_finite(value) ? value :
@@ -359,13 +359,16 @@ namespace hud
359359
return value;
360360
}();
361361
}
362-
else if (hud::is_same_v<type_t, f32>)
363-
{
364-
return ::ldexpf(value, exp);
365-
}
366362
else
367363
{
368-
return ::ldexpl(value, exp);
364+
if (hud::is_same_v<type_t, f32>)
365+
{
366+
return ::ldexpf(value, exp);
367+
}
368+
else
369+
{
370+
return ::ldexpl(value, exp);
371+
}
369372
}
370373
}
371374
}; // namespace math

0 commit comments

Comments
 (0)