hotspot/src/os_cpu/windows_x86/vm/copy_windows_x86.inline.hpp
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1 489c9b5090e2
child 5547 f4b087cbb361
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2003-2004 Sun Microsystems, Inc.  All Rights Reserved.
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
static void pd_conjoint_words(HeapWord* from, HeapWord* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
  (void)memmove(to, from, count * HeapWordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
static void pd_disjoint_words(HeapWord* from, HeapWord* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
#ifdef AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
  switch (count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  case 8:  to[7] = from[7];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  case 7:  to[6] = from[6];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  case 6:  to[5] = from[5];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  case 5:  to[4] = from[4];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  case 4:  to[3] = from[3];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  case 3:  to[2] = from[2];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  case 2:  to[1] = from[1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  case 1:  to[0] = from[0];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  case 0:  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
    (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
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  (void)memcpy(to, from, count * HeapWordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
#endif // AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
static void pd_disjoint_words_atomic(HeapWord* from, HeapWord* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  switch (count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  case 8:  to[7] = from[7];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  case 7:  to[6] = from[6];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  case 6:  to[5] = from[5];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  case 5:  to[4] = from[4];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  case 4:  to[3] = from[3];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  case 3:  to[2] = from[2];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  case 2:  to[1] = from[1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  case 1:  to[0] = from[0];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  case 0:  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  default: while (count-- > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
             *to++ = *from++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
           }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
           break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
static void pd_aligned_conjoint_words(HeapWord* from, HeapWord* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  (void)memmove(to, from, count * HeapWordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
static void pd_aligned_disjoint_words(HeapWord* from, HeapWord* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  pd_disjoint_words(from, to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
static void pd_conjoint_bytes(void* from, void* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  (void)memmove(to, from, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
static void pd_conjoint_bytes_atomic(void* from, void* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  pd_conjoint_bytes(from, to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
static void pd_conjoint_jshorts_atomic(jshort* from, jshort* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  // FIXME
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  (void)memmove(to, from, count << LogBytesPerShort);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
static void pd_conjoint_jints_atomic(jint* from, jint* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  // FIXME
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  (void)memmove(to, from, count << LogBytesPerInt);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
static void pd_conjoint_jlongs_atomic(jlong* from, jlong* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
#ifdef AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  assert(BytesPerLong == BytesPerOop, "jlongs and oops must be the same size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  pd_conjoint_oops_atomic((oop*)from, (oop*)to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  // Guarantee use of fild/fistp or xmm regs via some asm code, because compilers won't.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  __asm {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    mov    eax, from;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    mov    edx, to;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    mov    ecx, count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    cmp    eax, edx;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    jbe    downtest;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    jmp    uptest;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  up:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    fild   qword ptr [eax];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    fistp  qword ptr [edx];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    add    eax, 8;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    add    edx, 8;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  uptest:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    sub    ecx, 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    jge    up;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    jmp    done;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  down:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    fild   qword ptr [eax][ecx*8];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    fistp  qword ptr [edx][ecx*8];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  downtest:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    sub    ecx, 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    jge    down;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  done:;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
#endif // AMD64
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_conjoint_oops_atomic(oop* from, oop* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  // Do better than this: inline memmove body  NEEDS CLEANUP
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  if (from > to) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    while (count-- > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
      // Copy forwards
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
      *to++ = *from++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    from += count - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    to   += count - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
    while (count-- > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
      // Copy backwards
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
      *to-- = *from--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
static void pd_arrayof_conjoint_bytes(HeapWord* from, HeapWord* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
#ifdef AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  pd_conjoint_bytes_atomic(from, to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  pd_conjoint_bytes(from, to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
#endif // AMD64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
static void pd_arrayof_conjoint_jshorts(HeapWord* from, HeapWord* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  pd_conjoint_jshorts_atomic((jshort*)from, (jshort*)to, count);
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_arrayof_conjoint_jints(HeapWord* from, HeapWord* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  pd_conjoint_jints_atomic((jint*)from, (jint*)to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
static void pd_arrayof_conjoint_jlongs(HeapWord* from, HeapWord* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  pd_conjoint_jlongs_atomic((jlong*)from, (jlong*)to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
static void pd_arrayof_conjoint_oops(HeapWord* from, HeapWord* to, size_t count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  pd_conjoint_oops_atomic((oop*)from, (oop*)to, count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
}