0N/A/*
2846N/A * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#ifndef CPU_SPARC_VM_COPY_SPARC_HPP
1879N/A#define CPU_SPARC_VM_COPY_SPARC_HPP
1879N/A
0N/A// Inline functions for memory copy and fill.
0N/A
0N/Astatic void pd_conjoint_words(HeapWord* from, HeapWord* to, size_t count) {
0N/A (void)memmove(to, from, count * HeapWordSize);
0N/A}
0N/A
0N/Astatic void pd_disjoint_words(HeapWord* from, HeapWord* to, size_t count) {
0N/A switch (count) {
0N/A case 8: to[7] = from[7];
0N/A case 7: to[6] = from[6];
0N/A case 6: to[5] = from[5];
0N/A case 5: to[4] = from[4];
0N/A case 4: to[3] = from[3];
0N/A case 3: to[2] = from[2];
0N/A case 2: to[1] = from[1];
0N/A case 1: to[0] = from[0];
0N/A case 0: break;
0N/A default: (void)memcpy(to, from, count * HeapWordSize);
0N/A break;
0N/A }
0N/A}
0N/A
0N/Astatic void pd_disjoint_words_atomic(HeapWord* from, HeapWord* to, size_t count) {
0N/A switch (count) {
0N/A case 8: to[7] = from[7];
0N/A case 7: to[6] = from[6];
0N/A case 6: to[5] = from[5];
0N/A case 5: to[4] = from[4];
0N/A case 4: to[3] = from[3];
0N/A case 3: to[2] = from[2];
0N/A case 2: to[1] = from[1];
0N/A case 1: to[0] = from[0];
0N/A case 0: break;
0N/A default: while (count-- > 0) {
0N/A *to++ = *from++;
0N/A }
0N/A break;
0N/A }
0N/A}
0N/A
0N/Astatic void pd_aligned_conjoint_words(HeapWord* from, HeapWord* to, size_t count) {
0N/A (void)memmove(to, from, count * HeapWordSize);
0N/A}
0N/A
0N/Astatic void pd_aligned_disjoint_words(HeapWord* from, HeapWord* to, size_t count) {
0N/A pd_disjoint_words(from, to, count);
0N/A}
0N/A
0N/Astatic void pd_conjoint_bytes(void* from, void* to, size_t count) {
0N/A (void)memmove(to, from, count);
0N/A}
0N/A
0N/Astatic void pd_conjoint_bytes_atomic(void* from, void* to, size_t count) {
0N/A (void)memmove(to, from, count);
0N/A}
0N/A
0N/Astatic void pd_conjoint_jshorts_atomic(jshort* from, jshort* to, size_t count) {
2846N/A if (from > to) {
2846N/A while (count-- > 0) {
2846N/A // Copy forwards
2846N/A *to++ = *from++;
2846N/A }
2846N/A } else {
2846N/A from += count - 1;
2846N/A to += count - 1;
2846N/A while (count-- > 0) {
2846N/A // Copy backwards
2846N/A *to-- = *from--;
2846N/A }
2846N/A }
0N/A}
0N/A
0N/Astatic void pd_conjoint_jints_atomic(jint* from, jint* to, size_t count) {
2846N/A if (from > to) {
2846N/A while (count-- > 0) {
2846N/A // Copy forwards
2846N/A *to++ = *from++;
2846N/A }
2846N/A } else {
2846N/A from += count - 1;
2846N/A to += count - 1;
2846N/A while (count-- > 0) {
2846N/A // Copy backwards
2846N/A *to-- = *from--;
2846N/A }
2846N/A }
0N/A}
0N/A
0N/Astatic void pd_conjoint_jlongs_atomic(jlong* from, jlong* to, size_t count) {
0N/A#ifdef _LP64
0N/A assert(BytesPerLong == BytesPerOop, "jlongs and oops must be the same size");
0N/A pd_conjoint_oops_atomic((oop*)from, (oop*)to, count);
0N/A#else
0N/A // Guarantee use of ldd/std via some asm code, because compiler won't.
0N/A // See solaris_sparc.il.
0N/A _Copy_conjoint_jlongs_atomic(from, to, count);
0N/A#endif
0N/A}
0N/A
0N/Astatic void pd_conjoint_oops_atomic(oop* from, oop* to, size_t count) {
0N/A // Do better than this: inline memmove body NEEDS CLEANUP
0N/A if (from > to) {
0N/A while (count-- > 0) {
0N/A // Copy forwards
0N/A *to++ = *from++;
0N/A }
0N/A } else {
0N/A from += count - 1;
0N/A to += count - 1;
0N/A while (count-- > 0) {
0N/A // Copy backwards
0N/A *to-- = *from--;
0N/A }
0N/A }
0N/A}
0N/A
0N/Astatic void pd_arrayof_conjoint_bytes(HeapWord* from, HeapWord* to, size_t count) {
0N/A pd_conjoint_bytes_atomic(from, to, count);
0N/A}
0N/A
0N/Astatic void pd_arrayof_conjoint_jshorts(HeapWord* from, HeapWord* to, size_t count) {
0N/A pd_conjoint_jshorts_atomic((jshort*)from, (jshort*)to, count);
0N/A}
0N/A
0N/Astatic void pd_arrayof_conjoint_jints(HeapWord* from, HeapWord* to, size_t count) {
0N/A pd_conjoint_jints_atomic((jint*)from, (jint*)to, count);
0N/A}
0N/A
0N/Astatic void pd_arrayof_conjoint_jlongs(HeapWord* from, HeapWord* to, size_t count) {
0N/A pd_conjoint_jlongs_atomic((jlong*)from, (jlong*)to, count);
0N/A}
0N/A
0N/Astatic void pd_arrayof_conjoint_oops(HeapWord* from, HeapWord* to, size_t count) {
0N/A pd_conjoint_oops_atomic((oop*)from, (oop*)to, count);
0N/A}
0N/A
0N/Astatic void pd_fill_to_words(HeapWord* tohw, size_t count, juint value) {
113N/A#ifdef _LP64
113N/A guarantee(mask_bits((uintptr_t)tohw, right_n_bits(LogBytesPerLong)) == 0,
113N/A "unaligned fill words");
113N/A julong* to = (julong*)tohw;
113N/A julong v = ((julong)value << 32) | value;
113N/A while (count-- > 0) {
113N/A *to++ = v;
113N/A }
113N/A#else // _LP64
113N/A juint* to = (juint*)tohw;
113N/A while (count-- > 0) {
113N/A *to++ = value;
113N/A }
113N/A#endif // _LP64
0N/A}
0N/A
2726N/Atypedef void (*_zero_Fn)(HeapWord* to, size_t count);
2726N/A
0N/Astatic void pd_fill_to_aligned_words(HeapWord* tohw, size_t count, juint value) {
1491N/A assert(MinObjAlignmentInBytes >= BytesPerLong, "need alternate implementation");
0N/A
2726N/A if (value == 0 && UseBlockZeroing &&
2726N/A (count > (BlockZeroingLowLimit >> LogHeapWordSize))) {
2726N/A // Call it only when block zeroing is used
2726N/A ((_zero_Fn)StubRoutines::zero_aligned_words())(tohw, count);
2726N/A } else {
0N/A julong* to = (julong*)tohw;
0N/A julong v = ((julong)value << 32) | value;
0N/A // If count is odd, odd will be equal to 1 on 32-bit platform
0N/A // and be equal to 0 on 64-bit platform.
0N/A size_t odd = count % (BytesPerLong / HeapWordSize) ;
0N/A
1491N/A size_t aligned_count = align_object_offset(count - odd) / HeapWordsPerLong;
0N/A julong* end = ((julong*)tohw) + aligned_count - 1;
0N/A while (to <= end) {
0N/A DEBUG_ONLY(count -= BytesPerLong / HeapWordSize ;)
0N/A *to++ = v;
0N/A }
0N/A assert(count == odd, "bad bounds on loop filling to aligned words");
0N/A if (odd) {
0N/A *((juint*)to) = value;
0N/A
0N/A }
2726N/A }
0N/A}
0N/A
0N/Astatic void pd_fill_to_bytes(void* to, size_t count, jubyte value) {
0N/A (void)memset(to, value, count);
0N/A}
0N/A
0N/Astatic void pd_zero_to_words(HeapWord* tohw, size_t count) {
0N/A pd_fill_to_words(tohw, count, 0);
0N/A}
0N/A
0N/Astatic void pd_zero_to_bytes(void* to, size_t count) {
0N/A (void)memset(to, 0, count);
0N/A}
1879N/A
1879N/A#endif // CPU_SPARC_VM_COPY_SPARC_HPP