1 /* 2 * Copyright (c) 2020, Microsoft Corporation. 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 25 #ifndef OS_CPU_WINDOWS_AARCH64_COPY_WINDOWS_AARCH64_INLINE_HPP 26 #define OS_CPU_WINDOWS_AARCH64_COPY_WINDOWS_AARCH64_INLINE_HPP 27 28 #include <string.h> 29 30 static void pd_conjoint_words(const HeapWord* from, HeapWord* to, size_t count) { 31 (void)memmove(to, from, count * HeapWordSize); 32 } 33 34 static void pd_disjoint_words(const HeapWord* from, HeapWord* to, size_t count) { 35 switch (count) { 36 case 8: to[7] = from[7]; 37 case 7: to[6] = from[6]; 38 case 6: to[5] = from[5]; 39 case 5: to[4] = from[4]; 40 case 4: to[3] = from[3]; 41 case 3: to[2] = from[2]; 42 case 2: to[1] = from[1]; 43 case 1: to[0] = from[0]; 44 case 0: break; 45 default: 46 (void)memcpy(to, from, count * HeapWordSize); 47 break; 48 } 49 } 50 51 static void pd_disjoint_words_atomic(const HeapWord* from, HeapWord* to, size_t count) { 52 switch (count) { 53 case 8: to[7] = from[7]; 54 case 7: to[6] = from[6]; 55 case 6: to[5] = from[5]; 56 case 5: to[4] = from[4]; 57 case 4: to[3] = from[3]; 58 case 3: to[2] = from[2]; 59 case 2: to[1] = from[1]; 60 case 1: to[0] = from[0]; 61 case 0: break; 62 default: while (count-- > 0) { 63 *to++ = *from++; 64 } 65 break; 66 } 67 } 68 69 static void pd_aligned_conjoint_words(const HeapWord* from, HeapWord* to, size_t count) { 70 // pd_conjoint_words(from, to, count); 71 (void)memmove(to, from, count * HeapWordSize); 72 } 73 74 static void pd_aligned_disjoint_words(const HeapWord* from, HeapWord* to, size_t count) { 75 pd_disjoint_words(from, to, count); 76 } 77 78 static void pd_conjoint_bytes(const void* from, void* to, size_t count) { 79 (void)memmove(to, from, count); 80 } 81 82 static void pd_conjoint_bytes_atomic(const void* from, void* to, size_t count) { 83 pd_conjoint_bytes(from, to, count); 84 } 85 86 static void pd_conjoint_jshorts_atomic(const jshort* from, jshort* to, size_t count) { 87 if (from > to) { 88 while (count-- > 0) { 89 // Copy forwards 90 *to++ = *from++; 91 } 92 } else { 93 from += count - 1; 94 to += count - 1; 95 while (count-- > 0) { 96 // Copy backwards 97 *to-- = *from--; 98 } 99 } 100 } 101 102 static void pd_conjoint_jints_atomic(const jint* from, jint* to, size_t count) { 103 if (from > to) { 104 while (count-- > 0) { 105 // Copy forwards 106 *to++ = *from++; 107 } 108 } else { 109 from += count - 1; 110 to += count - 1; 111 while (count-- > 0) { 112 // Copy backwards 113 *to-- = *from--; 114 } 115 } 116 } 117 118 static void pd_conjoint_jlongs_atomic(const jlong* from, jlong* to, size_t count) { 119 pd_conjoint_oops_atomic((const oop*)from, (oop*)to, count); 120 } 121 122 static void pd_conjoint_oops_atomic(const oop* from, oop* to, size_t count) { 123 if (from > to) { 124 while (count-- > 0) { 125 // Copy forwards 126 *to++ = *from++; 127 } 128 } else { 129 from += count - 1; 130 to += count - 1; 131 while (count-- > 0) { 132 // Copy backwards 133 *to-- = *from--; 134 } 135 } 136 } 137 138 static void pd_arrayof_conjoint_bytes(const HeapWord* from, HeapWord* to, size_t count) { 139 pd_conjoint_bytes_atomic(from, to, count); 140 } 141 142 static void pd_arrayof_conjoint_jshorts(const HeapWord* from, HeapWord* to, size_t count) { 143 pd_conjoint_jshorts_atomic((const jshort*)from, (jshort*)to, count); 144 } 145 146 static void pd_arrayof_conjoint_jints(const HeapWord* from, HeapWord* to, size_t count) { 147 pd_conjoint_jints_atomic((const jint*)from, (jint*)to, count); 148 } 149 150 static void pd_arrayof_conjoint_jlongs(const HeapWord* from, HeapWord* to, size_t count) { 151 pd_conjoint_jlongs_atomic((const jlong*)from, (jlong*)to, count); 152 } 153 154 static void pd_arrayof_conjoint_oops(const HeapWord* from, HeapWord* to, size_t count) { 155 pd_conjoint_oops_atomic((const oop*)from, (oop*)to, count); 156 } 157 158 #endif // OS_CPU_WINDOWS_AARCH64_COPY_WINDOWS_AARCH64_INLINE_HPP