8000 merge revision(s) 48288: [Backport #9681] · github/ruby@e5db49c · GitHub
[go: up one dir, main page]

Skip to content

Commit e5db49c

Browse files
committed
merge revision(s) 48288: [Backport ruby#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 ruby#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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@48302 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 901dcec commit e5db49c

File tree

3 files changed

+80
-5
lines changed

3 files changed

+80
-5
lines changed

ChangeLog

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
Thu Nov 6 22:36:55 2014 Naohisa Goto <ngotogenome@gmail.com>
2+
3+
* compile.c (compile_data_alloc): add padding when strict alignment
4+
is required for memory access. Currently, the padding is enabled
5+
only when the CPU is 32-bit SPARC and the compiler is GCC.
6+
[Bug #9681] [ruby-core:61715]
7+
8+
* compile.c (STRICT_ALIGNMENT): defined if strict alignment is required
9+
10+
* compile.c (ALIGNMENT_SIZE, ALIGNMENT_SIZE_MASK, PADDING_SIZE_MAX):
11+
new macros for alignemnt word size, bit mask, max size of padding.
12+
13+
* compile.c (calc_padding): new function to calculate padding size.
14+
115
Wed Nov 5 00:18:22 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
216

317
* configure.in (__builtin_setjmp): disable with gcc/clang earlier

compile.c

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,18 +583,72 @@ rb_iseq_translate_threaded_code(rb_iseq_t *iseq)
583583
/* definition of data structure for compiler */
584584
/*********************************************/
585585

586+
/*
587+
* On 32-bit SPARC, GCC by default generates SPARC V7 code that may require
588+
* 8-byte word alignment. On the other hand, Oracle Solaris Studio seems to
589+
* generate SPARCV8PLUS code with unaligned memory accesss instructions.
590+
* That is why the STRICT_ALIGNMENT is defined only with GCC.
591+
*/
592+
#if defined(__sparc) && SIZEOF_VOIDP == 4 && defined(__GNUC__)
593+
#define STRICT_ALIGNMENT
594+
#endif
595+
596+
#ifdef STRICT_ALIGNMENT
597+
#if defined(HAVE_TRUE_LONG_LONG) && SIZEOF_LONG_LONG > SIZEOF_VALUE
598+
#define ALIGNMENT_SIZE SIZEOF_LONG_LONG
599+
#else
600+
#define ALIGNMENT_SIZE SIZEOF_VALUE
601+
#endif
602+
#define PADDING_SIZE_MAX ((size_t)((ALIGNMENT_SIZE) - 1))
603+
#define ALIGNMENT_SIZE_MASK PADDING_SIZE_MAX
604+
/* Note: ALIGNMENT_SIZE == (2 ** N) is expected. */
605+
#else
606+
#define PADDING_SIZE_MAX 0
607+
#endif /* STRICT_ALIGNMENT */
608+
609+
#ifdef STRICT_ALIGNMENT
610+
/* calculate padding size for aligned memory access */
611+
static size_t
612+
calc_padding(void *ptr, size_t size)
613+
{
614+
size_t mis;
615+
size_t padding = 0;
616+
617+
mis = (size_t)ptr & ALIGNMENT_SIZE_MASK;
618+
if (mis > 0) {
619+
padding = ALIGNMENT_SIZE - mis;
620+
}
621+
/*
622+
* On 32-bit sparc or equivalents, when a single VALUE is requested
623+
* and padding == sizeof(VALUE), it is clear that no padding is needed.
624+
*/
625+
#if ALIGNMENT_SIZE > SIZEOF_VALUE
626+
if (size == sizeof(VALUE) && padding == sizeof(VALUE)) {
627+
padding = 0;
628+
}
629+
#endif
630+
631+
return padding;
632+
}
633+
#endif /* STRICT_ALIGNMENT */
634+
586635
static void *
587636
compile_data_alloc(rb_iseq_t *iseq, size_t size)
588637
{
589638
void *ptr = 0;
590639
struct iseq_compile_data_storage *storage =
591640
iseq->compile_data->storage_current;
641+
#ifdef STRICT_ALIGNMENT
642+
size_t padding = calc_padding((void *)&storage->buff[storage->pos], size);
643+
#else
644+
const size_t padding = 0; /* expected to be optimized by compiler */
645+
#endif /* STRICT_ALIGNMENT */
592646

593-
if (storage->pos + size > storage->size) {
647+
if (storage->pos + size + padding > storage->size) {
594648
unsigned long alloc_size = storage->size * 2;
595649

596650
retry:
597-
if (alloc_size < size) {
651+
if (alloc_size < size + PADDING_SIZE_MAX) {
598652
alloc_size *= 2;
599653
goto retry;
600654
}
@@ -606,8 +660,15 @@ compile_data_alloc(rb_iseq_t *iseq, size_t size)
606660
storage->pos = 0;
607661
storage->size = alloc_size;
608662
storage->buff = (char *)(&storage->buff + 1);
663+
#ifdef STRICT_ALIGNMENT
664+
padding = calc_padding((void *)&storage->buff[storage->pos], size);
665+
#endif /* STRICT_ALIGNMENT */
609666
}
610667

668+
#ifdef STRICT_ALIGNMENT
669+
storage->pos += (int)padding;
670+
#endif /* STRICT_ALIGNMENT */
671+
611672
ptr = (void *)&storage->buff[storage->pos];
612673
storage->pos += size;
613674
return ptr;

version.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#define RUBY_VERSION "2.1.5"
2-
#define RUBY_RELEASE_DATE "2014-11-05"
3-
#define RUBY_PATCHLEVEL 270
2+
#define RUBY_RELEASE_DATE "2014-11-06"
3+
#define RUBY_PATCHLEVEL 271
44

55
#define RUBY_RELEASE_YEAR 2014
66
#define RUBY_RELEASE_MONTH 11
7-
#define RUBY_RELEASE_DAY 5
7+
#define RUBY_RELEASE_DAY 6
88

99
#include "ruby/version.h"
1010

0 commit comments

Comments
 (0)
0