summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2020-11-24 17:03:23 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2020-11-24 17:03:23 -0500
commite3aa668ef358739148adb1a4965b629d07467575 (patch)
treedddffef533139b5cc380783f45f17fce054f3480 /util.c
parent55d0ece0a9072ca409bdf6ff2f3b6d0b268e2952 (diff)
loading a file
Diffstat (limited to 'util.c')
-rw-r--r--util.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/util.c b/util.c
new file mode 100644
index 0000000..8b13492
--- /dev/null
+++ b/util.c
@@ -0,0 +1,20 @@
+#ifndef UTIL_C_
+#define UTIL_C_
+
+#include "base.h"
+
+static uint util_popcount(u64 x) {
+ // @TODO: portability
+ return (uint)__builtin_popcountll(x);
+}
+
+static bool util_is_power_of_2(u64 x) {
+ return util_popcount(x) == 1;
+}
+
+static void util_zero_memory(void *mem, size_t size) {
+ extern void *memset(void *s, int c, size_t n);
+ memset(mem, 0, size);
+}
+
+#endif