From 6690572bf3d674618c4907ac7bbc52ab949902dc Mon Sep 17 00:00:00 2001 From: Max Wash Date: Wed, 8 Feb 2023 17:12:34 +0000 Subject: [PATCH] kernel: add utility math functions --- include/socks/util.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/socks/util.h b/include/socks/util.h index 8205781..3fd1ff5 100644 --- a/include/socks/util.h +++ b/include/socks/util.h @@ -6,5 +6,14 @@ extern void data_size_to_string(size_t value, char *out, size_t outsz); static inline bool power_of_2(size_t x) { return (x > 0 && (x & (x - 1)) == 0); } +static inline unsigned long long div64_pow2(unsigned long long x, unsigned long long y) +{ + return x >> (__builtin_ctz(y)); +} + +static inline unsigned long long absdiff64(unsigned long long x, unsigned long long y) +{ + return x > y ? y - x : x - y; +} #endif