ruby-changes:36221
From: nagachika <ko1@a...>
Date: Thu, 6 Nov 2014 22:47:16 +0900 (JST)
Subject: [ruby-changes:36221] nagachika:r48302 (ruby_2_1): merge revision(s) 48288: [Backport #9681]
nagachika 2014-11-06 22:46:46 +0900 (Thu, 06 Nov 2014) New Revision: 48302 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=48302 Log: merge revision(s) 48288: [Backport #9681] * compile.c (compile_data_alloc): add padding when strict alignment is required for memory access. Currently, the padding is enabled only when the CPU is 32-bit SPARC and the compiler is GCC. [Bug #9681] [ruby-core:61715] * compile.c (STRICT_ALIGNMENT): defined if strict alignment is required * compile.c (ALIGNMENT_SIZE, ALIGNMENT_SIZE_MASK, PADDING_SIZE_MAX): new macros for alignemnt word size, bit mask, max size of padding. * compile.c (calc_padding): new function to calculate padding size. Modified directories: branches/ruby_2_1/ Modified files: branches/ruby_2_1/ChangeLog branches/ruby_2_1/compile.c branches/ruby_2_1/version.h Index: ruby_2_1/ChangeLog =================================================================== --- ruby_2_1/ChangeLog (revision 48301) +++ ruby_2_1/ChangeLog (revision 48302) @@ -1,3 +1,17 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ChangeLog#L1 +Thu Nov 6 22:36:55 2014 Naohisa Goto <ngotogenome@g...> + + * compile.c (compile_data_alloc): add padding when strict alignment + is required for memory access. Currently, the padding is enabled + only when the CPU is 32-bit SPARC and the compiler is GCC. + [Bug #9681] [ruby-core:61715] + + * compile.c (STRICT_ALIGNMENT): defined if strict alignment is required + + * compile.c (ALIGNMENT_SIZE, ALIGNMENT_SIZE_MASK, PADDING_SIZE_MAX): + new macros for alignemnt word size, bit mask, max size of padding. + + * compile.c (calc_padding): new function to calculate padding size. + Wed Nov 5 00:18:22 2014 Nobuyoshi Nakada <nobu@r...> * configure.in (__builtin_setjmp): disable with gcc/clang earlier Index: ruby_2_1/compile.c =================================================================== --- ruby_2_1/compile.c (revision 48301) +++ ruby_2_1/compile.c (revision 48302) @@ -583,18 +583,72 @@ rb_iseq_translate_threaded_code(rb_iseq_ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/compile.c#L583 /* definition of data structure for compiler */ /*********************************************/ +/* + * On 32-bit SPARC, GCC by default generates SPARC V7 code that may require + * 8-byte word alignment. On the other hand, Oracle Solaris Studio seems to + * generate SPARCV8PLUS code with unaligned memory accesss instructions. + * That is why the STRICT_ALIGNMENT is defined only with GCC. + */ +#if defined(__sparc) && SIZEOF_VOIDP == 4 && defined(__GNUC__) + #define STRICT_ALIGNMENT +#endif + +#ifdef STRICT_ALIGNMENT + #if defined(HAVE_TRUE_LONG_LONG) && SIZEOF_LONG_LONG > SIZEOF_VALUE + #define ALIGNMENT_SIZE SIZEOF_LONG_LONG + #else + #define ALIGNMENT_SIZE SIZEOF_VALUE + #endif + #define PADDING_SIZE_MAX ((size_t)((ALIGNMENT_SIZE) - 1)) + #define ALIGNMENT_SIZE_MASK PADDING_SIZE_MAX + /* Note: ALIGNMENT_SIZE == (2 ** N) is expected. */ +#else + #define PADDING_SIZE_MAX 0 +#endif /* STRICT_ALIGNMENT */ + +#ifdef STRICT_ALIGNMENT +/* calculate padding size for aligned memory access */ +static size_t +calc_padding(void *ptr, size_t size) +{ + size_t mis; + size_t padding = 0; + + mis = (size_t)ptr & ALIGNMENT_SIZE_MASK; + if (mis > 0) { + padding = ALIGNMENT_SIZE - mis; + } +/* + * On 32-bit sparc or equivalents, when a single VALUE is requested + * and padding == sizeof(VALUE), it is clear that no padding is needed. + */ +#if ALIGNMENT_SIZE > SIZEOF_VALUE + if (size == sizeof(VALUE) && padding == sizeof(VALUE)) { + padding = 0; + } +#endif + + return padding; +} +#endif /* STRICT_ALIGNMENT */ + static void * compile_data_alloc(rb_iseq_t *iseq, size_t size) { void *ptr = 0; struct iseq_compile_data_storage *storage = iseq->compile_data->storage_current; +#ifdef STRICT_ALIGNMENT + size_t padding = calc_padding((void *)&storage->buff[storage->pos], size); +#else + const size_t padding = 0; /* expected to be optimized by compiler */ +#endif /* STRICT_ALIGNMENT */ - if (storage->pos + size > storage->size) { + if (storage->pos + size + padding > storage->size) { unsigned long alloc_size = storage->size * 2; retry: - if (alloc_size < size) { + if (alloc_size < size + PADDING_SIZE_MAX) { alloc_size *= 2; goto retry; } @@ -606,8 +660,15 @@ compile_data_alloc(rb_iseq_t *iseq, size https://github.com/ruby/ruby/blob/trunk/ruby_2_1/compile.c#L660 storage->pos = 0; storage->size = alloc_size; storage->buff = (char *)(&storage->buff + 1); +#ifdef STRICT_ALIGNMENT + padding = calc_padding((void *)&storage->buff[storage->pos], size); +#endif /* STRICT_ALIGNMENT */ } +#ifdef STRICT_ALIGNMENT + storage->pos += (int)padding; +#endif /* STRICT_ALIGNMENT */ + ptr = (void *)&storage->buff[storage->pos]; storage->pos += size; return ptr; Index: ruby_2_1/version.h =================================================================== --- ruby_2_1/version.h (revision 48301) +++ ruby_2_1/version.h (revision 48302) @@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/version.h#L1 #define RUBY_VERSION "2.1.5" -#define RUBY_RELEASE_DATE "2014-11-05" -#define RUBY_PATCHLEVEL 270 +#define RUBY_RELEASE_DATE "2014-11-06" +#define RUBY_PATCHLEVEL 271 #define RUBY_RELEASE_YEAR 2014 #define RUBY_RELEASE_MONTH 11 -#define RUBY_RELEASE_DAY 5 +#define RUBY_RELEASE_DAY 6 #include "ruby/version.h" Property changes on: ruby_2_1 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r48288 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/