Path: blob/master/src/hotspot/os_cpu/bsd_x86/copy_bsd_x86.hpp
40930 views
/*1* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef OS_CPU_BSD_X86_COPY_BSD_X86_HPP25#define OS_CPU_BSD_X86_COPY_BSD_X86_HPP2627static void pd_conjoint_words(const HeapWord* from, HeapWord* to, size_t count) {28#ifdef AMD6429(void)memmove(to, from, count * HeapWordSize);30#else31// Includes a zero-count check.32intx temp;33__asm__ volatile(" testl %6,%6 ;"34" jz 7f ;"35" cmpl %4,%5 ;"36" leal -4(%4,%6,4),%3;"37" jbe 1f ;"38" cmpl %7,%5 ;"39" jbe 4f ;"40"1: cmpl $32,%6 ;"41" ja 3f ;"42" subl %4,%1 ;"43"2: movl (%4),%3 ;"44" movl %7,(%5,%4,1) ;"45" addl $4,%0 ;"46" subl $1,%2 ;"47" jnz 2b ;"48" jmp 7f ;"49"3: rep; smovl ;"50" jmp 7f ;"51"4: cmpl $32,%2 ;"52" movl %7,%0 ;"53" leal -4(%5,%6,4),%1;"54" ja 6f ;"55" subl %4,%1 ;"56"5: movl (%4),%3 ;"57" movl %7,(%5,%4,1) ;"58" subl $4,%0 ;"59" subl $1,%2 ;"60" jnz 5b ;"61" jmp 7f ;"62"6: std ;"63" rep; smovl ;"64" cld ;"65"7: nop "66: "=S" (from), "=D" (to), "=c" (count), "=r" (temp)67: "0" (from), "1" (to), "2" (count), "3" (temp)68: "memory", "flags");69#endif // AMD6470}7172static void pd_disjoint_words(const HeapWord* from, HeapWord* to, size_t count) {73#ifdef AMD6474switch (count) {75case 8: to[7] = from[7];76case 7: to[6] = from[6];77case 6: to[5] = from[5];78case 5: to[4] = from[4];79case 4: to[3] = from[3];80case 3: to[2] = from[2];81case 2: to[1] = from[1];82case 1: to[0] = from[0];83case 0: break;84default:85(void)memcpy(to, from, count * HeapWordSize);86break;87}88#else89// Includes a zero-count check.90intx temp;91__asm__ volatile(" testl %6,%6 ;"92" jz 3f ;"93" cmpl $32,%6 ;"94" ja 2f ;"95" subl %4,%1 ;"96"1: movl (%4),%3 ;"97" movl %7,(%5,%4,1);"98" addl $4,%0 ;"99" subl $1,%2 ;"100" jnz 1b ;"101" jmp 3f ;"102"2: rep; smovl ;"103"3: nop "104: "=S" (from), "=D" (to), "=c" (count), "=r" (temp)105: "0" (from), "1" (to), "2" (count), "3" (temp)106: "memory", "cc");107#endif // AMD64108}109110static void pd_disjoint_words_atomic(const HeapWord* from, HeapWord* to, size_t count) {111#ifdef AMD64112switch (count) {113case 8: to[7] = from[7];114case 7: to[6] = from[6];115case 6: to[5] = from[5];116case 5: to[4] = from[4];117case 4: to[3] = from[3];118case 3: to[2] = from[2];119case 2: to[1] = from[1];120case 1: to[0] = from[0];121case 0: break;122default:123while (count-- > 0) {124*to++ = *from++;125}126break;127}128#else129// pd_disjoint_words is word-atomic in this implementation.130pd_disjoint_words(from, to, count);131#endif // AMD64132}133134static void pd_aligned_conjoint_words(const HeapWord* from, HeapWord* to, size_t count) {135pd_conjoint_words(from, to, count);136}137138static void pd_aligned_disjoint_words(const HeapWord* from, HeapWord* to, size_t count) {139pd_disjoint_words(from, to, count);140}141142static void pd_conjoint_bytes(const void* from, void* to, size_t count) {143#ifdef AMD64144(void)memmove(to, from, count);145#else146// Includes a zero-count check.147intx temp;148__asm__ volatile(" testl %6,%6 ;"149" jz 13f ;"150" cmpl %4,%5 ;"151" leal -1(%4,%6),%3 ;"152" jbe 1f ;"153" cmpl %7,%5 ;"154" jbe 8f ;"155"1: cmpl $3,%6 ;"156" jbe 6f ;"157" movl %6,%3 ;"158" movl $4,%2 ;"159" subl %4,%2 ;"160" andl $3,%2 ;"161" jz 2f ;"162" subl %6,%3 ;"163" rep; smovb ;"164"2: movl %7,%2 ;"165" shrl $2,%2 ;"166" jz 5f ;"167" cmpl $32,%2 ;"168" ja 4f ;"169" subl %4,%1 ;"170"3: movl (%4),%%edx ;"171" movl %%edx,(%5,%4,1);"172" addl $4,%0 ;"173" subl $1,%2 ;"174" jnz 3b ;"175" addl %4,%1 ;"176" jmp 5f ;"177"4: rep; smovl ;"178"5: movl %7,%2 ;"179" andl $3,%2 ;"180" jz 13f ;"181"6: xorl %7,%3 ;"182"7: movb (%4,%7,1),%%dl ;"183" movb %%dl,(%5,%7,1) ;"184" addl $1,%3 ;"185" subl $1,%2 ;"186" jnz 7b ;"187" jmp 13f ;"188"8: std ;"189" cmpl $12,%2 ;"190" ja 9f ;"191" movl %7,%0 ;"192" leal -1(%6,%5),%1 ;"193" jmp 11f ;"194"9: xchgl %3,%2 ;"195" movl %6,%0 ;"196" addl $1,%2 ;"197" leal -1(%7,%5),%1 ;"198" andl $3,%2 ;"199" jz 10f ;"200" subl %6,%3 ;"201" rep; smovb ;"202"10: movl %7,%2 ;"203" subl $3,%0 ;"204" shrl $2,%2 ;"205" subl $3,%1 ;"206" rep; smovl ;"207" andl $3,%3 ;"208" jz 12f ;"209" movl %7,%2 ;"210" addl $3,%0 ;"211" addl $3,%1 ;"212"11: rep; smovb ;"213"12: cld ;"214"13: nop ;"215: "=S" (from), "=D" (to), "=c" (count), "=r" (temp)216: "0" (from), "1" (to), "2" (count), "3" (temp)217: "memory", "flags", "%edx");218#endif // AMD64219}220221static void pd_conjoint_bytes_atomic(const void* from, void* to, size_t count) {222pd_conjoint_bytes(from, to, count);223}224225static void pd_conjoint_jshorts_atomic(const jshort* from, jshort* to, size_t count) {226_Copy_conjoint_jshorts_atomic(from, to, count);227}228229static void pd_conjoint_jints_atomic(const jint* from, jint* to, size_t count) {230#ifdef AMD64231_Copy_conjoint_jints_atomic(from, to, count);232#else233assert(HeapWordSize == BytesPerInt, "heapwords and jints must be the same size");234// pd_conjoint_words is word-atomic in this implementation.235pd_conjoint_words((const HeapWord*)from, (HeapWord*)to, count);236#endif // AMD64237}238239static void pd_conjoint_jlongs_atomic(const jlong* from, jlong* to, size_t count) {240#ifdef AMD64241_Copy_conjoint_jlongs_atomic(from, to, count);242#else243// Guarantee use of fild/fistp or xmm regs via some asm code, because compilers won't.244if (from > to) {245while (count-- > 0) {246__asm__ volatile("fildll (%0); fistpll (%1)"247:248: "r" (from), "r" (to)249: "memory" );250++from;251++to;252}253} else {254while (count-- > 0) {255__asm__ volatile("fildll (%0,%2,8); fistpll (%1,%2,8)"256:257: "r" (from), "r" (to), "r" (count)258: "memory" );259}260}261#endif // AMD64262}263264static void pd_conjoint_oops_atomic(const oop* from, oop* to, size_t count) {265#ifdef AMD64266assert(BytesPerLong == BytesPerOop, "jlongs and oops must be the same size");267_Copy_conjoint_jlongs_atomic((const jlong*)from, (jlong*)to, count);268#else269assert(HeapWordSize == BytesPerOop, "heapwords and oops must be the same size");270// pd_conjoint_words is word-atomic in this implementation.271pd_conjoint_words((const HeapWord*)from, (HeapWord*)to, count);272#endif // AMD64273}274275static void pd_arrayof_conjoint_bytes(const HeapWord* from, HeapWord* to, size_t count) {276_Copy_arrayof_conjoint_bytes(from, to, count);277}278279static void pd_arrayof_conjoint_jshorts(const HeapWord* from, HeapWord* to, size_t count) {280_Copy_arrayof_conjoint_jshorts(from, to, count);281}282283static void pd_arrayof_conjoint_jints(const HeapWord* from, HeapWord* to, size_t count) {284#ifdef AMD64285_Copy_arrayof_conjoint_jints(from, to, count);286#else287pd_conjoint_jints_atomic((const jint*)from, (jint*)to, count);288#endif // AMD64289}290291static void pd_arrayof_conjoint_jlongs(const HeapWord* from, HeapWord* to, size_t count) {292#ifdef AMD64293_Copy_arrayof_conjoint_jlongs(from, to, count);294#else295pd_conjoint_jlongs_atomic((const jlong*)from, (jlong*)to, count);296#endif // AMD64297}298299static void pd_arrayof_conjoint_oops(const HeapWord* from, HeapWord* to, size_t count) {300#ifdef AMD64301assert(BytesPerLong == BytesPerOop, "jlongs and oops must be the same size");302_Copy_arrayof_conjoint_jlongs(from, to, count);303#else304pd_conjoint_oops_atomic((const oop*)from, (oop*)to, count);305#endif // AMD64306}307308#endif // OS_CPU_BSD_X86_COPY_BSD_X86_HPP309310311