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 void pd_disjoint_words(const HeapWord* from, HeapWord* to, size_t count) { 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 memcpy(to, from, count * HeapWordSize); 73 break; 74 } 75 } 76 77 static void pd_disjoint_words_atomic(const HeapWord* from, HeapWord* to, size_t count) { 78 shared_disjoint_words_atomic(from, to, count); 79 } 80 81 static void pd_aligned_conjoint_words(const HeapWord* from, HeapWord* to, size_t count) { 82 pd_conjoint_words(from, to, count); 83 } 84 85 static void pd_aligned_disjoint_words(const HeapWord* from, HeapWord* to, size_t count) { 86 pd_disjoint_words(from, to, count); 87 } 88 89 static void pd_conjoint_bytes(const void* from, void* to, size_t count) { 90 (void)memmove(to, from, count); 91 } 92 93 static void pd_conjoint_bytes_atomic(const void* from, void* to, size_t count) { 94 pd_conjoint_bytes(from, to, count); 95 } 96 97 static void pd_conjoint_jshorts_atomic(const jshort* from, jshort* to, size_t count) { 98 _Copy_conjoint_jshorts_atomic(from, to, count); 99 } 100 101 static void pd_conjoint_jints_atomic(const jint* from, jint* to, size_t count) { 102 _Copy_conjoint_jints_atomic(from, to, count); 103 } 104 105 static void pd_conjoint_jlongs_atomic(const jlong* from, jlong* to, size_t count) { 106 _Copy_conjoint_jlongs_atomic(from, to, count); 107 } 108 109 static void pd_conjoint_oops_atomic(const oop* from, oop* to, size_t count) { 110 assert(BytesPerLong == BytesPerOop, "jlongs and oops must be the same size."); 111 _Copy_conjoint_jlongs_atomic((const jlong*)from, (jlong*)to, count); 112 } 113 114 static void pd_arrayof_conjoint_bytes(const HeapWord* from, HeapWord* to, size_t count) { 115 _Copy_arrayof_conjoint_bytes(from, to, count); 116 } 117 118 static void pd_arrayof_conjoint_jshorts(const HeapWord* from, HeapWord* to, size_t count) { 119 _Copy_arrayof_conjoint_jshorts(from, to, count); 120 } 121 122 static void pd_arrayof_conjoint_jints(const HeapWord* from, HeapWord* to, size_t count) { 123 _Copy_arrayof_conjoint_jints(from, to, count); 124 } 125 126 static void pd_arrayof_conjoint_jlongs(const HeapWord* from, HeapWord* to, size_t count) { 127 _Copy_arrayof_conjoint_jlongs(from, to, count); 128 } 129 130 static void pd_arrayof_conjoint_oops(const HeapWord* from, HeapWord* to, size_t count) { 131 assert(!UseCompressedOops, "foo!"); 132 assert(BytesPerLong == BytesPerOop, "jlongs and oops must be the same size"); 133 _Copy_arrayof_conjoint_jlongs(from, to, count); 134 } 135 136 #endif // CPU_RISCV_COPY_RISCV_HPP