Project

General

Profile

Bug #9681 ยป 20141106-ruby2_0_0-r48288+r48289.patch

r48288 + r48289 for Ruby 2.0.0 - ngoto (Naohisa Goto), 11/06/2014 08:14 AM

View differences:

compile.c (working copy)
581 581
/* definition of data structure for compiler */
582 582
/*********************************************/
583 583

  
584
/*
585
 * On 32-bit SPARC, GCC by default generates SPARC V7 code that may require
586
 * 8-byte word alignment. On the other hand, Oracle Solaris Studio seems to
587
 * generate SPARCV8PLUS code with unaligned memory accesss instructions.
588
 * That is why the STRICT_ALIGNMENT is defined only with GCC.
589
 */
590
#if defined(__sparc) && SIZEOF_VOIDP == 4 && defined(__GNUC__)
591
  #define STRICT_ALIGNMENT
592
#endif
593

  
594
#ifdef STRICT_ALIGNMENT
595
  #if defined(HAVE_TRUE_LONG_LONG) && SIZEOF_LONG_LONG > SIZEOF_VALUE
596
    #define ALIGNMENT_SIZE SIZEOF_LONG_LONG
597
  #else
598
    #define ALIGNMENT_SIZE SIZEOF_VALUE
599
  #endif
600
  #define PADDING_SIZE_MAX    ((size_t)((ALIGNMENT_SIZE) - 1))
601
  #define ALIGNMENT_SIZE_MASK PADDING_SIZE_MAX
602
  /* Note: ALIGNMENT_SIZE == (2 ** N) is expected. */
603
#else
604
  #define PADDING_SIZE_MAX 0
605
#endif /* STRICT_ALIGNMENT */
606

  
607
#ifdef STRICT_ALIGNMENT
608
/* calculate padding size for aligned memory access */
609
static size_t
610
calc_padding(void *ptr, size_t size)
611
{
612
    size_t mis;
613
    size_t padding = 0;
614

  
615
    mis = (size_t)ptr & ALIGNMENT_SIZE_MASK;
616
    if (mis > 0) {
617
        padding = ALIGNMENT_SIZE - mis;
618
    }
619
/*
620
 * On 32-bit sparc or equivalents, when a single VALUE is requested
621
 * and padding == sizeof(VALUE), it is clear that no padding is needed.
622
 */
623
#if ALIGNMENT_SIZE > SIZEOF_VALUE
624
    if (size == sizeof(VALUE) && padding == sizeof(VALUE)) {
625
        padding = 0;
626
    }
627
#endif
628

  
629
    return padding;
630
}
631
#endif /* STRICT_ALIGNMENT */
632

  
584 633
static void *
585 634
compile_data_alloc(rb_iseq_t *iseq, size_t size)
586 635
{
587 636
    void *ptr = 0;
588 637
    struct iseq_compile_data_storage *storage =
589 638
	iseq->compile_data->storage_current;
639
#ifdef STRICT_ALIGNMENT
640
    size_t padding = calc_padding((void *)&storage->buff[storage->pos], size);
641
#else
642
    const size_t padding = 0; /* expected to be optimized by compiler */
643
#endif /* STRICT_ALIGNMENT */
590 644

  
591
    if (storage->pos + size > storage->size) {
645
    if (storage->pos + size + padding > storage->size) {
592 646
	unsigned long alloc_size = storage->size * 2;
593 647

  
594 648
      retry:
595
	if (alloc_size < size) {
649
	if (alloc_size < size + PADDING_SIZE_MAX) {
596 650
	    alloc_size *= 2;
597 651
	    goto retry;
598 652
	}
......
604 658
	storage->pos = 0;
605 659
	storage->size = alloc_size;
606 660
	storage->buff = (char *)(&storage->buff + 1);
661
#ifdef STRICT_ALIGNMENT
662
        padding = calc_padding((void *)&storage->buff[storage->pos], size);
663
#endif /* STRICT_ALIGNMENT */
607 664
    }
608 665

  
666
#ifdef STRICT_ALIGNMENT
667
    storage->pos += (int)padding;
668
#endif /* STRICT_ALIGNMENT */
669

  
609 670
    ptr = (void *)&storage->buff[storage->pos];
610 671
    storage->pos += size;
611 672
    return ptr;