0N/A/*
1879N/A * Copyright (c) 2003, 2010, 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 OS_CPU_LINUX_X86_VM_COPY_LINUX_X86_INLINE_HPP
1879N/A#define OS_CPU_LINUX_X86_VM_COPY_LINUX_X86_INLINE_HPP
1879N/A
0N/Astatic void pd_conjoint_words(HeapWord* from, HeapWord* to, size_t count) {
0N/A#ifdef AMD64
0N/A (void)memmove(to, from, count * HeapWordSize);
0N/A#else
1523N/A // Includes a zero-count check.
0N/A intx temp;
0N/A __asm__ volatile(" testl %6,%6 ;"
0N/A " jz 7f ;"
0N/A " cmpl %4,%5 ;"
0N/A " leal -4(%4,%6,4),%3;"
0N/A " jbe 1f ;"
0N/A " cmpl %7,%5 ;"
0N/A " jbe 4f ;"
0N/A "1: cmpl $32,%6 ;"
0N/A " ja 3f ;"
0N/A " subl %4,%1 ;"
0N/A "2: movl (%4),%3 ;"
0N/A " movl %7,(%5,%4,1) ;"
0N/A " addl $4,%0 ;"
0N/A " subl $1,%2 ;"
0N/A " jnz 2b ;"
0N/A " jmp 7f ;"
0N/A "3: rep; smovl ;"
0N/A " jmp 7f ;"
0N/A "4: cmpl $32,%2 ;"
0N/A " movl %7,%0 ;"
0N/A " leal -4(%5,%6,4),%1;"
0N/A " ja 6f ;"
0N/A " subl %4,%1 ;"
0N/A "5: movl (%4),%3 ;"
0N/A " movl %7,(%5,%4,1) ;"
0N/A " subl $4,%0 ;"
0N/A " subl $1,%2 ;"
0N/A " jnz 5b ;"
0N/A " jmp 7f ;"
0N/A "6: std ;"
0N/A " rep; smovl ;"
0N/A " cld ;"
0N/A "7: nop "
0N/A : "=S" (from), "=D" (to), "=c" (count), "=r" (temp)
0N/A : "0" (from), "1" (to), "2" (count), "3" (temp)
0N/A : "memory", "flags");
0N/A#endif // AMD64
0N/A}
0N/A
0N/Astatic void pd_disjoint_words(HeapWord* from, HeapWord* to, size_t count) {
0N/A#ifdef AMD64
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:
0N/A (void)memcpy(to, from, count * HeapWordSize);
0N/A break;
0N/A }
0N/A#else
1523N/A // Includes a zero-count check.
0N/A intx temp;
0N/A __asm__ volatile(" testl %6,%6 ;"
0N/A " jz 3f ;"
0N/A " cmpl $32,%6 ;"
0N/A " ja 2f ;"
0N/A " subl %4,%1 ;"
0N/A "1: movl (%4),%3 ;"
0N/A " movl %7,(%5,%4,1);"
0N/A " addl $4,%0 ;"
0N/A " subl $1,%2 ;"
0N/A " jnz 1b ;"
0N/A " jmp 3f ;"
0N/A "2: rep; smovl ;"
0N/A "3: nop "
0N/A : "=S" (from), "=D" (to), "=c" (count), "=r" (temp)
0N/A : "0" (from), "1" (to), "2" (count), "3" (temp)
0N/A : "memory", "cc");
0N/A#endif // AMD64
0N/A}
0N/A
0N/Astatic void pd_disjoint_words_atomic(HeapWord* from, HeapWord* to, size_t count) {
0N/A#ifdef AMD64
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:
0N/A while (count-- > 0) {
0N/A *to++ = *from++;
0N/A }
0N/A break;
0N/A }
0N/A#else
0N/A // pd_disjoint_words is word-atomic in this implementation.
0N/A pd_disjoint_words(from, to, count);
0N/A#endif // AMD64
0N/A}
0N/A
0N/Astatic void pd_aligned_conjoint_words(HeapWord* from, HeapWord* to, size_t count) {
1523N/A pd_conjoint_words(from, to, count);
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#ifdef AMD64
0N/A (void)memmove(to, from, count);
0N/A#else
1523N/A // Includes a zero-count check.
0N/A intx temp;
0N/A __asm__ volatile(" testl %6,%6 ;"
0N/A " jz 13f ;"
0N/A " cmpl %4,%5 ;"
0N/A " leal -1(%4,%6),%3 ;"
0N/A " jbe 1f ;"
0N/A " cmpl %7,%5 ;"
0N/A " jbe 8f ;"
0N/A "1: cmpl $3,%6 ;"
0N/A " jbe 6f ;"
0N/A " movl %6,%3 ;"
0N/A " movl $4,%2 ;"
0N/A " subl %4,%2 ;"
0N/A " andl $3,%2 ;"
0N/A " jz 2f ;"
0N/A " subl %6,%3 ;"
0N/A " rep; smovb ;"
0N/A "2: movl %7,%2 ;"
0N/A " shrl $2,%2 ;"
0N/A " jz 5f ;"
0N/A " cmpl $32,%2 ;"
0N/A " ja 4f ;"
0N/A " subl %4,%1 ;"
0N/A "3: movl (%4),%%edx ;"
0N/A " movl %%edx,(%5,%4,1);"
0N/A " addl $4,%0 ;"
0N/A " subl $1,%2 ;"
0N/A " jnz 3b ;"
0N/A " addl %4,%1 ;"
0N/A " jmp 5f ;"
0N/A "4: rep; smovl ;"
0N/A "5: movl %7,%2 ;"
0N/A " andl $3,%2 ;"
0N/A " jz 13f ;"
0N/A "6: xorl %7,%3 ;"
0N/A "7: movb (%4,%7,1),%%dl ;"
0N/A " movb %%dl,(%5,%7,1) ;"
0N/A " addl $1,%3 ;"
0N/A " subl $1,%2 ;"
0N/A " jnz 7b ;"
0N/A " jmp 13f ;"
0N/A "8: std ;"
0N/A " cmpl $12,%2 ;"
0N/A " ja 9f ;"
0N/A " movl %7,%0 ;"
0N/A " leal -1(%6,%5),%1 ;"
0N/A " jmp 11f ;"
0N/A "9: xchgl %3,%2 ;"
0N/A " movl %6,%0 ;"
0N/A " addl $1,%2 ;"
0N/A " leal -1(%7,%5),%1 ;"
0N/A " andl $3,%2 ;"
0N/A " jz 10f ;"
0N/A " subl %6,%3 ;"
0N/A " rep; smovb ;"
0N/A "10: movl %7,%2 ;"
0N/A " subl $3,%0 ;"
0N/A " shrl $2,%2 ;"
0N/A " subl $3,%1 ;"
0N/A " rep; smovl ;"
0N/A " andl $3,%3 ;"
0N/A " jz 12f ;"
0N/A " movl %7,%2 ;"
0N/A " addl $3,%0 ;"
0N/A " addl $3,%1 ;"
0N/A "11: rep; smovb ;"
0N/A "12: cld ;"
0N/A "13: nop ;"
0N/A : "=S" (from), "=D" (to), "=c" (count), "=r" (temp)
0N/A : "0" (from), "1" (to), "2" (count), "3" (temp)
0N/A : "memory", "flags", "%edx");
0N/A#endif // AMD64
0N/A}
0N/A
0N/Astatic void pd_conjoint_bytes_atomic(void* from, void* to, size_t count) {
0N/A pd_conjoint_bytes(from, to, count);
0N/A}
0N/A
0N/Astatic void pd_conjoint_jshorts_atomic(jshort* from, jshort* to, size_t count) {
0N/A _Copy_conjoint_jshorts_atomic(from, to, count);
0N/A}
0N/A
0N/Astatic void pd_conjoint_jints_atomic(jint* from, jint* to, size_t count) {
0N/A#ifdef AMD64
0N/A _Copy_conjoint_jints_atomic(from, to, count);
0N/A#else
0N/A assert(HeapWordSize == BytesPerInt, "heapwords and jints must be the same size");
0N/A // pd_conjoint_words is word-atomic in this implementation.
0N/A pd_conjoint_words((HeapWord*)from, (HeapWord*)to, count);
0N/A#endif // AMD64
0N/A}
0N/A
0N/Astatic void pd_conjoint_jlongs_atomic(jlong* from, jlong* to, size_t count) {
0N/A#ifdef AMD64
0N/A _Copy_conjoint_jlongs_atomic(from, to, count);
0N/A#else
0N/A // Guarantee use of fild/fistp or xmm regs via some asm code, because compilers won't.
0N/A if (from > to) {
0N/A while (count-- > 0) {
0N/A __asm__ volatile("fildll (%0); fistpll (%1)"
0N/A :
0N/A : "r" (from), "r" (to)
0N/A : "memory" );
0N/A ++from;
0N/A ++to;
0N/A }
0N/A } else {
0N/A while (count-- > 0) {
0N/A __asm__ volatile("fildll (%0,%2,8); fistpll (%1,%2,8)"
0N/A :
0N/A : "r" (from), "r" (to), "r" (count)
0N/A : "memory" );
0N/A }
0N/A }
0N/A#endif // AMD64
0N/A}
0N/A
0N/Astatic void pd_conjoint_oops_atomic(oop* from, oop* to, size_t count) {
0N/A#ifdef AMD64
0N/A assert(BytesPerLong == BytesPerOop, "jlongs and oops must be the same size");
0N/A _Copy_conjoint_jlongs_atomic((jlong*)from, (jlong*)to, count);
0N/A#else
0N/A assert(HeapWordSize == BytesPerOop, "heapwords and oops must be the same size");
0N/A // pd_conjoint_words is word-atomic in this implementation.
0N/A pd_conjoint_words((HeapWord*)from, (HeapWord*)to, count);
0N/A#endif // AMD64
0N/A}
0N/A
0N/Astatic void pd_arrayof_conjoint_bytes(HeapWord* from, HeapWord* to, size_t count) {
0N/A _Copy_arrayof_conjoint_bytes(from, to, count);
0N/A}
0N/A
0N/Astatic void pd_arrayof_conjoint_jshorts(HeapWord* from, HeapWord* to, size_t count) {
0N/A _Copy_arrayof_conjoint_jshorts(from, to, count);
0N/A}
0N/A
0N/Astatic void pd_arrayof_conjoint_jints(HeapWord* from, HeapWord* to, size_t count) {
0N/A#ifdef AMD64
0N/A _Copy_arrayof_conjoint_jints(from, to, count);
0N/A#else
0N/A pd_conjoint_jints_atomic((jint*)from, (jint*)to, count);
0N/A#endif // AMD64
0N/A}
0N/A
0N/Astatic void pd_arrayof_conjoint_jlongs(HeapWord* from, HeapWord* to, size_t count) {
0N/A#ifdef AMD64
0N/A _Copy_arrayof_conjoint_jlongs(from, to, count);
0N/A#else
0N/A pd_conjoint_jlongs_atomic((jlong*)from, (jlong*)to, count);
0N/A#endif // AMD64
0N/A}
0N/A
0N/Astatic void pd_arrayof_conjoint_oops(HeapWord* from, HeapWord* to, size_t count) {
0N/A#ifdef AMD64
0N/A assert(BytesPerLong == BytesPerOop, "jlongs and oops must be the same size");
0N/A _Copy_arrayof_conjoint_jlongs(from, to, count);
0N/A#else
0N/A pd_conjoint_oops_atomic((oop*)from, (oop*)to, count);
0N/A#endif // AMD64
0N/A}
1879N/A
1879N/A#endif // OS_CPU_LINUX_X86_VM_COPY_LINUX_X86_INLINE_HPP