hotspot/src/cpu/sparc/vm/copy_sparc.hpp
author twisti
Fri, 13 Feb 2009 09:09:35 -0800
changeset 2031 24e034f56dcb
parent 670 ddf3e9583f2f
child 5694 1e0532a6abff
child 5547 f4b087cbb361
permissions -rw-r--r--
6800154: Add comments to long_by_long_mulhi() for better understandability Summary: This patch adds a comment pointing to the Hacker's Delight version of the algorithm plus a verbatim copy of it. Furthermore it adds inline comments. Reviewed-by: kvn, jrose
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
670
ddf3e9583f2f 6719955: Update copyright year
xdono
parents: 360
diff changeset
     2
 * Copyright 2003-2008 Sun Microsystems, Inc.  All Rights Reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
// Inline functions for memory copy and fill.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
static void pd_conjoint_words(HeapWord* from, HeapWord* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
  (void)memmove(to, from, count * HeapWordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
static void pd_disjoint_words(HeapWord* from, HeapWord* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  switch (count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  case 8:  to[7] = from[7];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  case 7:  to[6] = from[6];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  case 6:  to[5] = from[5];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  case 5:  to[4] = from[4];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  case 4:  to[3] = from[3];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  case 3:  to[2] = from[2];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  case 2:  to[1] = from[1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  case 1:  to[0] = from[0];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  case 0:  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  default: (void)memcpy(to, from, count * HeapWordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
           break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
static void pd_disjoint_words_atomic(HeapWord* from, HeapWord* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  switch (count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  case 8:  to[7] = from[7];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  case 7:  to[6] = from[6];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  case 6:  to[5] = from[5];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  case 5:  to[4] = from[4];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  case 4:  to[3] = from[3];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  case 3:  to[2] = from[2];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  case 2:  to[1] = from[1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  case 1:  to[0] = from[0];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  case 0:  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  default: while (count-- > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
             *to++ = *from++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
           }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
           break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
static void pd_aligned_conjoint_words(HeapWord* from, HeapWord* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  (void)memmove(to, from, count * HeapWordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
static void pd_aligned_disjoint_words(HeapWord* from, HeapWord* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  pd_disjoint_words(from, to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
static void pd_conjoint_bytes(void* from, void* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  (void)memmove(to, from, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
static void pd_conjoint_bytes_atomic(void* from, void* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  (void)memmove(to, from, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
static void pd_conjoint_jshorts_atomic(jshort* from, jshort* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  // FIXME
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  (void)memmove(to, from, count << LogBytesPerShort);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
static void pd_conjoint_jints_atomic(jint* from, jint* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  // FIXME
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  (void)memmove(to, from, count << LogBytesPerInt);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
static void pd_conjoint_jlongs_atomic(jlong* from, jlong* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
#ifdef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  assert(BytesPerLong == BytesPerOop, "jlongs and oops must be the same size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  pd_conjoint_oops_atomic((oop*)from, (oop*)to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  // Guarantee use of ldd/std via some asm code, because compiler won't.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  // See solaris_sparc.il.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  _Copy_conjoint_jlongs_atomic(from, to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
static void pd_conjoint_oops_atomic(oop* from, oop* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  // Do better than this: inline memmove body  NEEDS CLEANUP
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  if (from > to) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    while (count-- > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
      // Copy forwards
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
      *to++ = *from++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    from += count - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    to   += count - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    while (count-- > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
      // Copy backwards
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
      *to-- = *from--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
static void pd_arrayof_conjoint_bytes(HeapWord* from, HeapWord* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  pd_conjoint_bytes_atomic(from, to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
static void pd_arrayof_conjoint_jshorts(HeapWord* from, HeapWord* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  pd_conjoint_jshorts_atomic((jshort*)from, (jshort*)to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
static void pd_arrayof_conjoint_jints(HeapWord* from, HeapWord* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  pd_conjoint_jints_atomic((jint*)from, (jint*)to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
static void pd_arrayof_conjoint_jlongs(HeapWord* from, HeapWord* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  pd_conjoint_jlongs_atomic((jlong*)from, (jlong*)to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
static void pd_arrayof_conjoint_oops(HeapWord* from, HeapWord* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  pd_conjoint_oops_atomic((oop*)from, (oop*)to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
static void pd_fill_to_words(HeapWord* tohw, size_t count, juint value) {
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   140
#ifdef _LP64
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   141
  guarantee(mask_bits((uintptr_t)tohw, right_n_bits(LogBytesPerLong)) == 0,
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   142
         "unaligned fill words");
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   143
  julong* to = (julong*)tohw;
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   144
  julong  v  = ((julong)value << 32) | value;
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   145
  while (count-- > 0) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   146
    *to++ = v;
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   147
  }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   148
#else // _LP64
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   149
  juint* to = (juint*)tohw;
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   150
  while (count-- > 0) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   151
    *to++ = value;
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   152
  }
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   153
#endif // _LP64
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
static void pd_fill_to_aligned_words(HeapWord* tohw, size_t count, juint value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  assert(MinObjAlignmentInBytes == BytesPerLong, "need alternate implementation");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
   julong* to = (julong*)tohw;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
   julong  v  = ((julong)value << 32) | value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
   // If count is odd, odd will be equal to 1 on 32-bit platform
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
   // and be equal to 0 on 64-bit platform.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
   size_t odd = count % (BytesPerLong / HeapWordSize) ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
   size_t aligned_count = align_object_size(count - odd) / HeapWordsPerLong;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
   julong* end = ((julong*)tohw) + aligned_count - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
   while (to <= end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
     DEBUG_ONLY(count -= BytesPerLong / HeapWordSize ;)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
     *to++ = v;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
   assert(count == odd, "bad bounds on loop filling to aligned words");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
   if (odd) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
     *((juint*)to) = value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
static void pd_fill_to_bytes(void* to, size_t count, jubyte value) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  (void)memset(to, value, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
static void pd_zero_to_words(HeapWord* tohw, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  pd_fill_to_words(tohw, count, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
static void pd_zero_to_bytes(void* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  (void)memset(to, 0, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
}