aboutsummaryrefslogtreecommitdiffstats
path: root/src/zlsb.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2016-03-01 18:37:05 +0100
committerMattias Andrée <maandree@kth.se>2016-03-01 18:37:05 +0100
commitb0c1cae18066d0103a440894b5256939852021eb (patch)
treeb90f419aba218eedf1cc664c7269666306e6ccaf /src/zlsb.c
parentAdd .gitignore (diff)
downloadlibzahl-b0c1cae18066d0103a440894b5256939852021eb.tar.gz
libzahl-b0c1cae18066d0103a440894b5256939852021eb.tar.bz2
libzahl-b0c1cae18066d0103a440894b5256939852021eb.tar.xz
Add zsetup, zunsetup, zinit, zfree, zswap, zsave, zload, zbits, and zlsb
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/zlsb.c')
-rw-r--r--src/zlsb.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/zlsb.c b/src/zlsb.c
new file mode 100644
index 0000000..610b32f
--- /dev/null
+++ b/src/zlsb.c
@@ -0,0 +1,21 @@
+/* See LICENSE file for copyright and license details. */
+#include "internals"
+
+
+size_t
+zlsb(z_t a)
+{
+ size_t i = 0;
+ uint32_t x;
+ if (zzero(a)) {
+ return SIZE_MAX;
+ }
+ for (;; i++) {
+ x = a->chars[i];
+ if (x) {
+ x = ~x;
+ for (i *= BITS_PER_CHAR; x & 1; x >>= 1, i++);
+ return i;
+ }
+ }
+}