musl - musl - an implementation of the standard library for Linux-based systems

index : musl
musl - an implementation of the standard library for Linux-based systems
summary refs log tree commit diff
path: root/src/internal/atomic.h
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2020年06月11日 00:12:48 -0400
committerRich Felker <dalias@aerifal.cx>2020年06月11日 00:12:48 -0400
commitca36573ecfbbef7a1563aaa1a8486081f8c9fdda (patch)
tree5f85ff1f9d9b28c986415d42b226009fb63daf0c /src/internal/atomic.h
parent1fc67fc117f9d25d240d46bbef78ebccacec7097 (diff)
downloadmusl-ca36573ecfbbef7a1563aaa1a8486081f8c9fdda.tar.gz
add fallback a_clz_32 implementation
some archs already have a_clz_32, used to provide a_ctz_32, but it hasn't been mandatory because it's not used anywhere yet. mallocng will need it, however, so add it now. it should probably be optimized better, but doesn't seem to make a difference at present.
Diffstat (limited to 'src/internal/atomic.h')
-rw-r--r--src/internal/atomic.h 15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/internal/atomic.h b/src/internal/atomic.h
index f938879b..99539cc0 100644
--- a/src/internal/atomic.h
+++ b/src/internal/atomic.h
@@ -315,4 +315,19 @@ static inline int a_clz_64(uint64_t x)
}
#endif
+#ifndef a_clz_32
+#define a_clz_32 a_clz_32
+static inline int a_clz_32(uint32_t x)
+{
+ x--;
+ x |= x >> 1;
+ x |= x >> 2;
+ x |= x >> 4;
+ x |= x >> 8;
+ x |= x >> 16;
+ x++;
+ return 31-a_ctz_32(x);
+}
+#endif
+
#endif
generated by cgit v1.2.1 (git 2.18.0) at 2025年09月08日 10:08:31 +0000

AltStyle によって変換されたページ (->オリジナル) /