chiark / gitweb /
use __builtin_ctz if available
authorstevenj <stevenj@alum.mit.edu>
Sun, 9 Mar 2008 19:24:01 +0000 (15:24 -0400)
committerstevenj <stevenj@alum.mit.edu>
Sun, 9 Mar 2008 19:24:01 +0000 (15:24 -0400)
darcs-hash:20080309192401-c8de0-4524cb891c0806a70adf643340e1065adeea996d.gz

util/sobolseq.c

index bd73b40fda091f8d80b3d855e2e663446e465037..42120fc7d21c73f7bce2f282f2f7b885d24a3345 100644 (file)
@@ -87,11 +87,16 @@ typedef struct nlopt_soboldata_s {
  */
 static unsigned rightzero32(uint32_t n)
 {
+#if defined(__GNUC__) && \
+    ((__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || __GNUC__ > 3)
+     return __builtin_ctz(~n); /* gcc builtin for version >= 3.4 */
+#else
      const uint32_t a = 0x05f66a47; /* magic number, found by brute force */
      static const unsigned decode[32] = {0,1,2,26,23,3,15,27,24,21,19,4,12,16,28,6,31,25,22,14,20,18,11,5,30,13,17,10,29,9,8,7};
      n = ~n; /* change to rightmost-one problem */
      n = a * (n & (-n)); /* store in n to make sure mult. is 32 bits */
      return decode[n >> 27];
+#endif
 }
 
 /* generate the next term x_{n+1} in the Sobol sequence, as an array