summaryrefslogtreecommitdiffstats
path: root/usr/klibc/libgcc/__clzsi2.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr/klibc/libgcc/__clzsi2.c')
-rw-r--r--usr/klibc/libgcc/__clzsi2.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/usr/klibc/libgcc/__clzsi2.c b/usr/klibc/libgcc/__clzsi2.c
new file mode 100644
index 0000000..ebb11f0
--- /dev/null
+++ b/usr/klibc/libgcc/__clzsi2.c
@@ -0,0 +1,36 @@
+/*
+ * libgcc/__clzsi2.c
+ *
+ * Returns the leading number of 0 bits in the argument
+ */
+
+#include <stdint.h>
+#include <stddef.h>
+
+uint32_t __clzsi2(uint32_t v)
+{
+ int p = 31;
+
+ if (v & 0xffff0000) {
+ p -= 16;
+ v >>= 16;
+ }
+ if (v & 0xff00) {
+ p -= 8;
+ v >>= 8;
+ }
+ if (v & 0xf0) {
+ p -= 4;
+ v >>= 4;
+ }
+ if (v & 0xc) {
+ p -= 2;
+ v >>= 2;
+ }
+ if (v & 0x2) {
+ p -= 1;
+ v >>= 1;
+ }
+
+ return p;
+}