File tree 2 files changed +39
-0
lines changed
2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -833,6 +833,7 @@ set(SRC_UTILITIES
833
833
"Utils/MakeArray.h"
834
834
"Utils/MetaPtr.h"
835
835
"Utils/Result.h"
836
+ "Utils/Round.h"
836
837
"Utils/String.cpp"
837
838
"Utils/String.h"
838
839
"Utils/Time.cpp"
Original file line number Diff line number Diff line change
1
+ //
2
+ // SPDX-License-Identifier: LGPL-2.1-or-later
3
+ //
4
+ // Copyright © 2023 ANSSI. All Rights Reserved.
5
+ //
6
+ // Author(s): fabienfl (ANSSI)
7
+ //
8
+ #pragma once
9
+
10
+ #include < type_traits>
11
+
12
+ namespace Orc {
13
+
14
+ template <typename T>
15
+ inline std::enable_if_t <std::is_unsigned_v<T>, T> RoundUp (T value, size_t multiple)
16
+ {
17
+ if (multiple == 0 )
18
+ {
19
+ return value;
20
+ }
21
+
22
+ const T remainder = value % multiple;
23
+ if (remainder == 0 )
24
+ {
25
+ return value;
26
+ }
27
+
28
+ return value + multiple - remainder ;
29
+ }
30
+
31
+ // Faster version for power of 2 multiples
32
+ template <typename T>
33
+ constexpr T RoundUpPow2 (T value, size_t multiple)
34
+ {
35
+ return ((value - 1u ) & ~(static_cast <T>(multiple) - 1u )) + multiple;
36
+ }
37
+
38
+ } // namespace Orc
You can’t perform that action at this time.
0 commit comments