copy_windows_x86.inline.hpp revision 1472:c18cbe5936b8
1/*
2 * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25static void pd_conjoint_words(HeapWord* from, HeapWord* to, size_t count) {
26  (void)memmove(to, from, count * HeapWordSize);
27}
28
29static void pd_disjoint_words(HeapWord* from, HeapWord* to, size_t count) {
30#ifdef AMD64
31  switch (count) {
32  case 8:  to[7] = from[7];
33  case 7:  to[6] = from[6];
34  case 6:  to[5] = from[5];
35  case 5:  to[4] = from[4];
36  case 4:  to[3] = from[3];
37  case 3:  to[2] = from[2];
38  case 2:  to[1] = from[1];
39  case 1:  to[0] = from[0];
40  case 0:  break;
41  default:
42    (void)memcpy(to, from, count * HeapWordSize);
43    break;
44  }
45#else
46  (void)memcpy(to, from, count * HeapWordSize);
47#endif // AMD64
48}
49
50static void pd_disjoint_words_atomic(HeapWord* from, HeapWord* to, size_t count) {
51  switch (count) {
52  case 8:  to[7] = from[7];
53  case 7:  to[6] = from[6];
54  case 6:  to[5] = from[5];
55  case 5:  to[4] = from[4];
56  case 4:  to[3] = from[3];
57  case 3:  to[2] = from[2];
58  case 2:  to[1] = from[1];
59  case 1:  to[0] = from[0];
60  case 0:  break;
61  default: while (count-- > 0) {
62             *to++ = *from++;
63           }
64           break;
65  }
66}
67
68static void pd_aligned_conjoint_words(HeapWord* from, HeapWord* to, size_t count) {
69  (void)memmove(to, from, count * HeapWordSize);
70}
71
72static void pd_aligned_disjoint_words(HeapWord* from, HeapWord* to, size_t count) {
73  pd_disjoint_words(from, to, count);
74}
75
76static void pd_conjoint_bytes(void* from, void* to, size_t count) {
77  (void)memmove(to, from, count);
78}
79
80static void pd_conjoint_bytes_atomic(void* from, void* to, size_t count) {
81  pd_conjoint_bytes(from, to, count);
82}
83
84static void pd_conjoint_jshorts_atomic(jshort* from, jshort* to, size_t count) {
85  // FIXME
86  (void)memmove(to, from, count << LogBytesPerShort);
87}
88
89static void pd_conjoint_jints_atomic(jint* from, jint* to, size_t count) {
90  // FIXME
91  (void)memmove(to, from, count << LogBytesPerInt);
92}
93
94static void pd_conjoint_jlongs_atomic(jlong* from, jlong* to, size_t count) {
95#ifdef AMD64
96  assert(BytesPerLong == BytesPerOop, "jlongs and oops must be the same size");
97  pd_conjoint_oops_atomic((oop*)from, (oop*)to, count);
98#else
99  // Guarantee use of fild/fistp or xmm regs via some asm code, because compilers won't.
100  __asm {
101    mov    eax, from;
102    mov    edx, to;
103    mov    ecx, count;
104    cmp    eax, edx;
105    jbe    downtest;
106    jmp    uptest;
107  up:
108    fild   qword ptr [eax];
109    fistp  qword ptr [edx];
110    add    eax, 8;
111    add    edx, 8;
112  uptest:
113    sub    ecx, 1;
114    jge    up;
115    jmp    done;
116  down:
117    fild   qword ptr [eax][ecx*8];
118    fistp  qword ptr [edx][ecx*8];
119  downtest:
120    sub    ecx, 1;
121    jge    down;
122  done:;
123  }
124#endif // AMD64
125}
126
127static void pd_conjoint_oops_atomic(oop* from, oop* to, size_t count) {
128  // Do better than this: inline memmove body  NEEDS CLEANUP
129  if (from > to) {
130    while (count-- > 0) {
131      // Copy forwards
132      *to++ = *from++;
133    }
134  } else {
135    from += count - 1;
136    to   += count - 1;
137    while (count-- > 0) {
138      // Copy backwards
139      *to-- = *from--;
140    }
141  }
142}
143
144static void pd_arrayof_conjoint_bytes(HeapWord* from, HeapWord* to, size_t count) {
145#ifdef AMD64
146  pd_conjoint_bytes_atomic(from, to, count);
147#else
148  pd_conjoint_bytes(from, to, count);
149#endif // AMD64
150}
151
152static void pd_arrayof_conjoint_jshorts(HeapWord* from, HeapWord* to, size_t count) {
153  pd_conjoint_jshorts_atomic((jshort*)from, (jshort*)to, count);
154}
155
156static void pd_arrayof_conjoint_jints(HeapWord* from, HeapWord* to, size_t count) {
157  pd_conjoint_jints_atomic((jint*)from, (jint*)to, count);
158}
159
160static void pd_arrayof_conjoint_jlongs(HeapWord* from, HeapWord* to, size_t count) {
161  pd_conjoint_jlongs_atomic((jlong*)from, (jlong*)to, count);
162}
163
164static void pd_arrayof_conjoint_oops(HeapWord* from, HeapWord* to, size_t count) {
165  pd_conjoint_oops_atomic((oop*)from, (oop*)to, count);
166}
167