1 /* 2 * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved. 3 * Copyright (c) 2014, Red Hat Inc. All rights reserved. 4 * Copyright (c) 2020, 2022, Huawei Technologies Co., Ltd. All rights reserved. 5 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6 * 7 * This code is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU General Public License version 2 only, as 9 * published by the Free Software Foundation. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 * 25 */ 26 27 #ifndef CPU_RISCV_COPY_RISCV_HPP 28 #define CPU_RISCV_COPY_RISCV_HPP 29 30 #include OS_CPU_HEADER(copy) 31 32 static void pd_fill_to_words(HeapWord* tohw, size_t count, juint value) { 33 julong* to = (julong*) tohw; 34 julong v = ((julong) value << 32) | value; 35 while (count-- > 0) { 36 *to++ = v; 37 } 38 } 39 40 static void pd_fill_to_aligned_words(HeapWord* tohw, size_t count, juint value) { 41 pd_fill_to_words(tohw, count, value); 42 } 43 44 static void pd_fill_to_bytes(void* to, size_t count, jubyte value) { 45 (void)memset(to, value, count); 46 } 47 48 static void pd_zero_to_words(HeapWord* tohw, size_t count) { 49 pd_fill_to_words(tohw, count, 0); 50 } 51 52 static void pd_zero_to_bytes(void* to, size_t count) { 53 (void)memset(to, 0, count); 54 } 55 56 static void pd_conjoint_words(const HeapWord* from, HeapWord* to, size_t count) { 57 (void)memmove(to, from, count * HeapWordSize); 58 } 59 60 static inline void pd_disjoint_words_helper(const HeapWord* from, HeapWord* to, size_t count, bool is_atomic) { 61 switch (count) { 62 case 8: to[7] = from[7]; // fall through 63 case 7: to[6] = from[6]; // fall through 64 case 6: to[5] = from[5]; // fall through 65 case 5: to[4] = from[4]; // fall through 66 case 4: to[3] = from[3]; // fall through 67 case 3: to[2] = from[2]; // fall through 68 case 2: to[1] = from[1]; // fall through 69 case 1: to[0] = from[0]; // fall through 70 case 0: break; 71 default: 72 if (is_atomic) { 73 while (count-- > 0) { *to++ = *from++; } 74 } else { 75 memcpy(to, from, count * HeapWordSize); 76 } 77 } 78 } 79 80 static void pd_disjoint_words(const HeapWord* from, HeapWord* to, size_t count) { 81 pd_disjoint_words_helper(from, to, count, false); 82 } 83 84 static void pd_disjoint_words_atomic(const HeapWord* from, HeapWord* to, size_t count) { 85 pd_disjoint_words_helper(from, to, count, true); 86 } 87 88 static void pd_aligned_conjoint_words(const HeapWord* from, HeapWord* to, size_t count) { 89 pd_conjoint_words(from, to, count); 90 } 91 92 static void pd_aligned_disjoint_words(const HeapWord* from, HeapWord* to, size_t count) { 93 pd_disjoint_words(from, to, count); 94 } 95 96 static void pd_conjoint_bytes(const void* from, void* to, size_t count) { 97 (void)memmove(to, from, count); 98 } 99 100 static void pd_conjoint_bytes_atomic(const void* from, void* to, size_t count) { 101 pd_conjoint_bytes(from, to, count); 102 } 103 104 static void pd_conjoint_jshorts_atomic(const jshort* from, jshort* to, size_t count) { 105 _Copy_conjoint_jshorts_atomic(from, to, count); 106 } 107 108 static void pd_conjoint_jints_atomic(const jint* from, jint* to, size_t count) { 109 _Copy_conjoint_jints_atomic(from, to, count); 110 } 111 112 static void pd_conjoint_jlongs_atomic(const jlong* from, jlong* to, size_t count) { 113 _Copy_conjoint_jlongs_atomic(from, to, count); 114 } 115 116 static void pd_conjoint_oops_atomic(const oop* from, oop* to, size_t count) { 117 assert(BytesPerLong == BytesPerOop, "jlongs and oops must be the same size."); 118 _Copy_conjoint_jlongs_atomic((const jlong*)from, (jlong*)to, count); 119 } 120 121 static void pd_arrayof_conjoint_bytes(const HeapWord* from, HeapWord* to, size_t count) { 122 _Copy_arrayof_conjoint_bytes(from, to, count); 123 } 124 125 static void pd_arrayof_conjoint_jshorts(const HeapWord* from, HeapWord* to, size_t count) { 126 _Copy_arrayof_conjoint_jshorts(from, to, count); 127 } 128 129 static void pd_arrayof_conjoint_jints(const HeapWord* from, HeapWord* to, size_t count) { 130 _Copy_arrayof_conjoint_jints(from, to, count); 131 } 132 133 static void pd_arrayof_conjoint_jlongs(const HeapWord* from, HeapWord* to, size_t count) { 134 _Copy_arrayof_conjoint_jlongs(from, to, count); 135 } 136 137 static void pd_arrayof_conjoint_oops(const HeapWord* from, HeapWord* to, size_t count) { 138 assert(!UseCompressedOops, "foo!"); 139 assert(BytesPerLong == BytesPerOop, "jlongs and oops must be the same size"); 140 _Copy_arrayof_conjoint_jlongs(from, to, count); 141 } 142 143 #endif // CPU_RISCV_COPY_RISCV_HPP