summaryrefslogtreecommitdiff
path: root/include/ruby/ruby.h
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-01-15 02:35:19 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-01-15 02:35:19 +0000
commitdf9a70900a7380bc9b42b12ab90cf182988bcd45 (patch)
treec0a4bf7a1b4a3819490ec9ef85296298578a1685 /include/ruby/ruby.h
parent39cfa67b4f56e0c79afb352b1e9bf5c914b774ca (diff)
__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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61830 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'include/ruby/ruby.h')
-rw-r--r--include/ruby/ruby.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h
index fe0ecf4622..19489bb18c 100644
--- a/include/ruby/ruby.h
+++ b/include/ruby/ruby.h
@@ -1595,7 +1595,15 @@ rb_num2char_inline(VALUE x)
#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));