From b0c1cae18066d0103a440894b5256939852021eb Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 1 Mar 2016 18:37:05 +0100 Subject: Add zsetup, zunsetup, zinit, zfree, zswap, zsave, zload, zbits, and zlsb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/zlsb.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/zlsb.c (limited to 'src/zlsb.c') 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; + } + } +} -- cgit v1.2.3-70-g09d2