summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/xray/xray_utils.h
diff options
context:
space:
mode:
Diffstat (limited to 'compiler-rt/lib/xray/xray_utils.h')
-rw-r--r--compiler-rt/lib/xray/xray_utils.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/compiler-rt/lib/xray/xray_utils.h b/compiler-rt/lib/xray/xray_utils.h
index a06a59491da..0a7911f12d7 100644
--- a/compiler-rt/lib/xray/xray_utils.h
+++ b/compiler-rt/lib/xray/xray_utils.h
@@ -36,6 +36,24 @@ std::pair<ssize_t, bool> retryingReadSome(int Fd, char *Begin, char *End);
// file.
int getLogFD();
+constexpr size_t gcd(size_t a, size_t b) {
+ return (b == 0) ? a : gcd(b, a % b);
+}
+
+constexpr size_t lcm(size_t a, size_t b) { return a * b / gcd(a, b); }
+
+template <class T> constexpr T nearest_boundary(T number, T multiple) {
+ return multiple * ((number / multiple) + (number % multiple ? 1 : 0));
+}
+
+constexpr size_t next_pow2_helper(size_t num, size_t acc) {
+ return (1u << acc) >= num ? (1u << acc) : next_pow2_helper(num, acc + 1);
+}
+
+constexpr size_t next_pow2(size_t number) {
+ return next_pow2_helper(number, 1);
+}
+
} // namespace __xray
#endif // XRAY_UTILS_H
OpenPOWER on IntegriCloud