aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/gallium/auxiliary/util/u_math.h
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2014-05-01 17:03:50 +0200
committermarha <marha@users.sourceforge.net>2014-05-01 17:03:50 +0200
commitaadab8d97e31348ffe45d1e5d36ad90b0ccd17aa (patch)
tree37bc7921f864ead4f6eb357b31a1eb66d46aaef9 /mesalib/src/gallium/auxiliary/util/u_math.h
parent2e0adb33e03e3142f1412ed570415c5ce616dcef (diff)
parentea0cd87ecbe9fc3c5503ccad7f87a895a458d6d4 (diff)
downloadvcxsrv-aadab8d97e31348ffe45d1e5d36ad90b0ccd17aa.tar.gz
vcxsrv-aadab8d97e31348ffe45d1e5d36ad90b0ccd17aa.tar.bz2
vcxsrv-aadab8d97e31348ffe45d1e5d36ad90b0ccd17aa.zip
Merge remote-tracking branch 'origin/released'
Conflicts: libxcb/src/xcb_util.c mesalib/src/mesa/drivers/dri/common/dri_util.c xorg-server/os/utils.c
Diffstat (limited to 'mesalib/src/gallium/auxiliary/util/u_math.h')
-rw-r--r--mesalib/src/gallium/auxiliary/util/u_math.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/mesalib/src/gallium/auxiliary/util/u_math.h b/mesalib/src/gallium/auxiliary/util/u_math.h
index ec03e4e58..a60e1830a 100644
--- a/mesalib/src/gallium/auxiliary/util/u_math.h
+++ b/mesalib/src/gallium/auxiliary/util/u_math.h
@@ -567,6 +567,22 @@ static INLINE unsigned util_last_bit(unsigned u)
#endif
}
+/**
+ * Find last bit in a word that does not match the sign bit. The least
+ * significant bit is 1.
+ * Return 0 if no bits are set.
+ */
+static INLINE unsigned util_last_bit_signed(int i)
+{
+#if defined(__GNUC__) && ((__GNUC__ * 100 + __GNUC_MINOR__) >= 407)
+ return 31 - __builtin_clrsb(i);
+#else
+ if (i >= 0)
+ return util_last_bit(i);
+ else
+ return util_last_bit(~(unsigned)i);
+#endif
+}
/* Destructively loop over all of the bits in a mask as in:
*
@@ -715,6 +731,21 @@ util_bitcount(unsigned n)
#endif
}
+/**
+ * Reverse bits in n
+ * Algorithm taken from:
+ * http://stackoverflow.com/questions/9144800/c-reverse-bits-in-unsigned-integer
+ */
+static INLINE unsigned
+util_bitreverse(unsigned n)
+{
+ n = ((n >> 1) & 0x55555555u) | ((n & 0x55555555u) << 1);
+ n = ((n >> 2) & 0x33333333u) | ((n & 0x33333333u) << 2);
+ n = ((n >> 4) & 0x0f0f0f0fu) | ((n & 0x0f0f0f0fu) << 4);
+ n = ((n >> 8) & 0x00ff00ffu) | ((n & 0x00ff00ffu) << 8);
+ n = ((n >> 16) & 0xffffu) | ((n & 0xffffu) << 16);
+ return n;
+}
/**
* Convert from little endian to CPU byte order.