From 7380a624a1203b0eb3734c65cc1ebdbcbdf358f0 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sat, 17 Oct 2020 15:03:39 +0200 Subject: [PATCH] Add an alternative for __builtin_clz. Speed isn't critical here, and this was ostensibly the last GCC-ism. --- turbopfor-encode.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/turbopfor-encode.h b/turbopfor-encode.h index 9341efc..d149ae7 100644 --- a/turbopfor-encode.h +++ b/turbopfor-encode.h @@ -94,11 +94,20 @@ unsigned char *write_vb(Docid val, unsigned char *out) template inline unsigned num_bits(Docid x) { +#ifdef __GNUC__ if (x == 0) { return 0; } else { return sizeof(Docid) * CHAR_BIT - __builtin_clz(x); } +#else + for (int i = sizeof(Docid) * CHAR_BIT; i-- > 0; ) { + if (x & (Docid{1} << i)) { + return i; + } + } + return 0; +#endif } struct BitWriter { -- 2.39.2