Project

General

Profile

Bug #9681 ยป 20141023-compile_data_alloc-word-align.patch

ngoto (Naohisa Goto), 10/23/2014 10:09 AM

View differences:

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

  
586
/* check if word-aligned memory access is needed */
587
#if defined(__sparc) /* sparc 32-bit and 64-bit (sparc v9) */
588
  #define STRICT_ADDRESS_ALIGNMENT
589
#endif
590

  
591
#ifdef STRICT_ADDRESS_ALIGNMENT
592
/* 
593
 * On sparc V8 (32-bit), because sizeof(long long) > sizeof(VALUE) and
594
 * sizeof(double) > sizeof(VALUE), a struct that may contain long long or
595
 * double is aligned to sizeof(double) or sizeof(long long), respectively.
596
 */
597
  #if defined(HAVE_TRUE_LONG_LONG) && SIZEOF_LONG_LONG > SIZEOF_VALUE && \
598
      SIZEOF_LONG_LONG >= SIZEOF_DOUBLE
599
    #define ALIGN_SIZE SIZEOF_LONG_LONG
600
  #elif SIZEOF_DOUBLE > SIZEOF_VALUE
601
    #define ALIGN_SIZE SIZEOF_DOUBLE
602
  #else
603
    #define ALIGN_SIZE SIZEOF_VALUE
604
  #endif
605
  /* ALIGN_SIZE must be 2 ** N. */
606
  #define ALIGN_SIZE_MASK ((size_t)((ALIGN_SIZE) - 1))
607
#endif /* STRICT_ADDRESS_ALIGNMENT */
608

  
586 609
static void *
587 610
compile_data_alloc(rb_iseq_t *iseq, size_t size)
588 611
{
......
590 613
    struct iseq_compile_data_storage *storage =
591 614
	iseq->compile_data->storage_current;
592 615

  
593
    if (storage->pos + size > storage->size) {
616
#ifdef STRICT_ADDRESS_ALIGNMENT
617
    size_t padding = 0;
618
    size_t mis;
619
#else
620
    const size_t padding = 0; /* to be optimized by compiler */
621
#endif
622

  
623
#ifdef STRICT_ADDRESS_ALIGNMENT
624
    mis = (size_t)storage->pos & ALIGN_SIZE_MASK;
625
    if (mis > 0) {
626
        padding = ALIGN_SIZE - mis;
627
/* Optimize when a VALUE is requested on 32-bit sparc or equivalents. */
628
#if ALIGN_SIZE > SIZEOF_VALUE
629
        if (padding == sizeof(VALUE)) {
630
            padding = 0;
631
        }
632
#endif
633
    }
634
#endif /* STRICT_ADDRESS_ALIGNMENT */
635

  
636
    if (storage->pos + padding + size > storage->size) {
594 637
	unsigned long alloc_size = storage->size * 2;
595 638

  
639
#ifdef STRICT_ADDRESS_ALIGNMENT
640
        padding = 0; /* assumes that start address is always aligned. */
641
#endif
642

  
596 643
      retry:
597 644
	if (alloc_size < size) {
598 645
	    alloc_size *= 2;
......
608 655
	storage->buff = (char *)(&storage->buff + 1);
609 656
    }
610 657

  
658
#ifdef STRICT_ADDRESS_ALIGNMENT
659
    storage->pos += padding;
660
#endif
611 661
    ptr = (void *)&storage->buff[storage->pos];
612 662
    storage->pos += size;
613 663
    return ptr;