[前][次][番号順一覧][スレッド一覧]

ruby-changes:49714

From: shyouhei <ko1@a...>
Date: Mon, 15 Jan 2018 11:41:21 +0900 (JST)
Subject: [ruby-changes:49714] shyouhei:r61830 (trunk): __builtin_alloca_with_align for optimal memory access

shyouhei	2018-01-15 11:35:19 +0900 (Mon, 15 Jan 2018)

  New Revision: 61830

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61830

  Log:
    __builtin_alloca_with_align for optimal memory access
    
    ALLOCA_N takes type arugment.  It is natural that the returned
    value to be used as an array of type, thus type-aligned.
    Luckily GCC has a builtin to tell compiler such alignment info.
    This should generate beter instructions.

  Modified files:
    trunk/configure.ac
    trunk/include/ruby/ruby.h
Index: configure.ac
===================================================================
--- configure.ac	(revision 61829)
+++ configure.ac	(revision 61830)
@@ -2493,6 +2493,7 @@ AC_CACHE_CHECK([for $1], AS_TR_SH(rb_cv_ https://github.com/ruby/ruby/blob/trunk/configure.ac#L2493
 AS_IF([test "${AS_TR_SH(rb_cv_builtin_$1)}" != no], [
   AC_DEFINE(AS_TR_CPP(HAVE_BUILTIN_$1))
 ])])
+RUBY_CHECK_BUILTIN_FUNC(__builtin_alloca_with_align, [__builtin_alloca_with_align(1, 4096)])
 RUBY_CHECK_BUILTIN_FUNC(__builtin_assume_aligned, [__builtin_assume_aligned((void*)32, 32)])
 RUBY_CHECK_BUILTIN_FUNC(__builtin_bswap16, [__builtin_bswap16(0)])
 RUBY_CHECK_BUILTIN_FUNC(__builtin_bswap32, [__builtin_bswap32(0)])
Index: include/ruby/ruby.h
===================================================================
--- include/ruby/ruby.h	(revision 61829)
+++ include/ruby/ruby.h	(revision 61830)
@@ -1595,7 +1595,15 @@ rb_num2char_inline(VALUE x) https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L1595
 #define ZALLOC(type) RB_ZALLOC(type)
 #define REALLOC_N(var,type,n) RB_REALLOC_N(var,type,n)
 
+#ifdef HAVE_BUILTIN___BUILTIN_ALLOCA_WITH_ALIGN
+/* I don't know why but __builtin_alloca_with_align's second argument
+   takes bits rather than bytes. */
+#define ALLOCA_N(type, n) \
+    (type*)__builtin_alloca_with_align((sizeof(type)*(n)), \
+        sizeof(type) * CHAR_BIT)
+#else
 #define ALLOCA_N(type,n) ((type*)alloca(sizeof(type)*(n)))
+#endif
 
 void *rb_alloc_tmp_buffer(volatile VALUE *store, long len) RUBY_ATTR_ALLOC_SIZE((2));
 void *rb_alloc_tmp_buffer_with_count(volatile VALUE *store, size_t len,size_t count) RUBY_ATTR_ALLOC_SIZE((2,3));

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]