summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-14 14:28:33 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-14 14:28:33 +0000
commit240f3056aa0e095a6b03d5763c2775e97b4ee7d3 (patch)
tree071e9f61ebc458a88ecc09f9ce0deb3940929a0c
parentb0eacd027a5f45c0135c7fa294bacb8162ae46b9 (diff)
* configure.in: Check __builtin_popcountl, __builtin_bswap32 and
__builtin_bswap64. * internal.h (swap32): Use the configure result for the condition to use __builtin_bswap32. (swap64): Use the configure result for the condition to use __builtin_bswap64. * bignum.c (ones): Use the configure result for the condition to use __builtin_popcountl. (bary_unpack_internal): Use appropriate types for swap argument. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41963 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog14
-rw-r--r--bignum.c8
-rw-r--r--configure.in13
-rw-r--r--internal.h4
4 files changed, 33 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index a20408b265b..a4c7eede0e3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+Sun Jul 14 23:21:47 2013 Tanaka Akira <akr@fsij.org>
+
+ * configure.in: Check __builtin_popcountl, __builtin_bswap32 and
+ __builtin_bswap64.
+
+ * internal.h (swap32): Use the configure result for the condition to
+ use __builtin_bswap32.
+ (swap64): Use the configure result for the condition to use
+ __builtin_bswap64.
+
+ * bignum.c (ones): Use the configure result for the condition to use
+ __builtin_popcountl.
+ (bary_unpack_internal): Use appropriate types for swap argument.
+
Sun Jul 14 22:21:11 2013 Tanaka Akira <akr@fsij.org>
* bignum.c (bary_subb): Support xn < yn.
diff --git a/bignum.c b/bignum.c
index dfe5e99c0d3..ec99f7be6e7 100644
--- a/bignum.c
+++ b/bignum.c
@@ -1137,19 +1137,19 @@ bary_unpack_internal(BDIGIT *bdigits, size_t num_bdigits, const void *words, siz
}
#if defined(HAVE_UINT16_T) && 2 <= SIZEOF_BDIGITS
if (wordsize == 2 && (uintptr_t)words % ALIGNOF(uint16_t) == 0) {
- BDIGIT u = *(uint16_t *)buf;
+ uint16_t u = *(uint16_t *)buf;
return integer_unpack_single_bdigit(need_swap ? swap16(u) : u, sizeof(uint16_t), flags, dp);
}
#endif
#if defined(HAVE_UINT32_T) && 4 <= SIZEOF_BDIGITS
if (wordsize == 4 && (uintptr_t)words % ALIGNOF(uint32_t) == 0) {
- BDIGIT u = *(uint32_t *)buf;
+ uint32_t u = *(uint32_t *)buf;
return integer_unpack_single_bdigit(need_swap ? swap32(u) : u, sizeof(uint32_t), flags, dp);
}
#endif
#if defined(HAVE_UINT64_T) && 8 <= SIZEOF_BDIGITS
if (wordsize == 8 && (uintptr_t)words % ALIGNOF(uint64_t) == 0) {
- BDIGIT u = *(uint64_t *)buf;
+ uint64_t u = *(uint64_t *)buf;
return integer_unpack_single_bdigit(need_swap ? swap64(u) : u, sizeof(uint64_t), flags, dp);
}
#endif
@@ -3307,7 +3307,7 @@ big_rshift(VALUE x, unsigned long shift)
static inline int
ones(register unsigned long x)
{
-#if GCC_VERSION_SINCE(3, 4, 0)
+#ifdef HAVE_BUILTIN___BUILTIN_POPCOUNTL
return __builtin_popcountl(x);
#else
# if SIZEOF_LONG == 8
diff --git a/configure.in b/configure.in
index dce99e36b45..adc465a4274 100644
--- a/configure.in
+++ b/configure.in
@@ -1838,6 +1838,19 @@ AC_CHECK_FUNCS(utimes)
AC_CHECK_FUNCS(wait4)
AC_CHECK_FUNCS(waitpid)
+AC_DEFUN([RUBY_CHECK_BUILTIN_FUNC], [dnl
+AC_CACHE_CHECK([for $1], AS_TR_SH(rb_cv_builtin_$1),
+ [AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM([], [$2;])],
+ [AS_TR_SH(rb_cv_builtin_$1)=yes],
+ [AS_TR_SH(rb_cv_builtin_$1)=no])])
+if test "${AS_TR_SH(rb_cv_builtin_$1)}" != no; then
+ AC_DEFINE(AS_TR_CPP(HAVE_BUILTIN_$1))
+fi])
+RUBY_CHECK_BUILTIN_FUNC(__builtin_popcountl, [__builtin_popcountl(0)])
+RUBY_CHECK_BUILTIN_FUNC(__builtin_bswap32, [__builtin_bswap32(0)])
+RUBY_CHECK_BUILTIN_FUNC(__builtin_bswap64, [__builtin_bswap64(0)])
+
# Some platform neet -lrt for clock_gettime, but the other don't.
if test x"$ac_cv_func_clock_gettime" != xyes; then
# glibc 2.17 moves clock_* functions from librt to the main C library.
diff --git a/internal.h b/internal.h
index f3ecf8be9fc..a8243a793f1 100644
--- a/internal.h
+++ b/internal.h
@@ -82,7 +82,7 @@ extern "C" {
#endif
#ifndef swap32
-# if GCC_VERSION_SINCE(4,3,0)
+# ifdef HAVE_BUILTIN___BUILTIN_BSWAP32
# define swap32(x) __builtin_bswap32(x)
# endif
#endif
@@ -95,7 +95,7 @@ extern "C" {
#endif
#ifndef swap64
-# if GCC_VERSION_SINCE(4,3,0)
+# ifdef HAVE_BUILTIN___BUILTIN_BSWAP64
# define swap64(x) __builtin_bswap64(x)
# endif
#endif