ruby-changes:28210
From: akr <ko1@a...>
Date: Fri, 12 Apr 2013 21:02:01 +0900 (JST)
Subject: [ruby-changes:28210] akr:r40262 (trunk): * bignum.c (ones): Use __builtin_popcountl if available.
akr 2013-04-12 21:01:51 +0900 (Fri, 12 Apr 2013) New Revision: 40262 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=40262 Log: * bignum.c (ones): Use __builtin_popcountl if available. * internal.h (GCC_VERSION_SINCE): Macro moved from pack.c. * pack.c: Include internal.h for GCC_VERSION_SINCE. Modified files: trunk/ChangeLog trunk/bignum.c trunk/internal.h trunk/pack.c Index: ChangeLog =================================================================== --- ChangeLog (revision 40261) +++ ChangeLog (revision 40262) @@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Fri Apr 12 20:59:24 2013 Tanaka Akira <akr@f...> + + * bignum.c (ones): Use __builtin_popcountl if available. + + * internal.h (GCC_VERSION_SINCE): Macro moved from pack.c. + + * pack.c: Include internal.h for GCC_VERSION_SINCE. + Fri Apr 12 18:29:42 2013 Tanaka Akira <akr@f...> * common.mk: version.o depends on $(srcdir)/include/ruby/version.h Index: pack.c =================================================================== --- pack.c (revision 40261) +++ pack.c (revision 40262) @@ -11,16 +11,11 @@ https://github.com/ruby/ruby/blob/trunk/pack.c#L11 #include "ruby/ruby.h" #include "ruby/encoding.h" +#include "internal.h" #include <sys/types.h> #include <ctype.h> #include <errno.h> -#define GCC_VERSION_SINCE(major, minor, patchlevel) \ - (defined(__GNUC__) && !defined(__INTEL_COMPILER) && \ - ((__GNUC__ > (major)) || \ - (__GNUC__ == (major) && __GNUC_MINOR__ > (minor)) || \ - (__GNUC__ == (major) && __GNUC_MINOR__ == (minor) && __GNUC_PATCHLEVEL__ >= (patchlevel)))) - /* * It is intentional that the condition for natstr is HAVE_TRUE_LONG_LONG * instead of HAVE_LONG_LONG or LONG_LONG. Index: internal.h =================================================================== --- internal.h (revision 40261) +++ internal.h (revision 40262) @@ -19,6 +19,12 @@ extern "C" { https://github.com/ruby/ruby/blob/trunk/internal.h#L19 #endif #endif +#define GCC_VERSION_SINCE(major, minor, patchlevel) \ + (defined(__GNUC__) && !defined(__INTEL_COMPILER) && \ + ((__GNUC__ > (major)) || \ + (__GNUC__ == (major) && __GNUC_MINOR__ > (minor)) || \ + (__GNUC__ == (major) && __GNUC_MINOR__ == (minor) && __GNUC_PATCHLEVEL__ >= (patchlevel)))) + #if SIGNEDNESS_OF_TIME_T < 0 /* signed */ # define TIMET_MAX (time_t)((~(unsigned_time_t)0) >> 1) # define TIMET_MIN (time_t)(((unsigned_time_t)1) << (sizeof(time_t) * CHAR_BIT - 1)) Index: bignum.c =================================================================== --- bignum.c (revision 40261) +++ bignum.c (revision 40262) @@ -887,27 +887,31 @@ static void bigdivmod(VALUE x, VALUE y, https://github.com/ruby/ruby/blob/trunk/bignum.c#L887 static inline int ones(register unsigned long x) { -#if SIZEOF_LONG == 8 -# define MASK_55 0x5555555555555555UL -# define MASK_33 0x3333333333333333UL -# define MASK_0f 0x0f0f0f0f0f0f0f0fUL +#if GCC_VERSION_SINCE(3, 4, 0) + return __builtin_popcountl(x); #else -# define MASK_55 0x55555555UL -# define MASK_33 0x33333333UL -# define MASK_0f 0x0f0f0f0fUL -#endif +# if SIZEOF_LONG == 8 +# define MASK_55 0x5555555555555555UL +# define MASK_33 0x3333333333333333UL +# define MASK_0f 0x0f0f0f0f0f0f0f0fUL +# else +# define MASK_55 0x55555555UL +# define MASK_33 0x33333333UL +# define MASK_0f 0x0f0f0f0fUL +# endif x -= (x >> 1) & MASK_55; x = ((x >> 2) & MASK_33) + (x & MASK_33); x = ((x >> 4) + x) & MASK_0f; x += (x >> 8); x += (x >> 16); -#if SIZEOF_LONG == 8 +# if SIZEOF_LONG == 8 x += (x >> 32); -#endif +# endif return (int)(x & 0x7f); -#undef MASK_0f -#undef MASK_33 -#undef MASK_55 +# undef MASK_0f +# undef MASK_33 +# undef MASK_55 +#endif } static inline unsigned long -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/