Blame sysdeps/s390/memcpy-z900.S

Packit Service bc8896
/* memcpy - copy a block from source to destination.  31/64 bit S/390 version.
Packit 6c4009
   Copyright (C) 2012-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
Packit 6c4009
#include <sysdep.h>
Packit 6c4009
#include "asm-syntax.h"
Packit Service 289aec
#include <ifunc-memcpy.h>
Packit 6c4009
Packit 6c4009
/* INPUT PARAMETERS
Packit 6c4009
     %r2 = address of destination memory area
Packit 6c4009
     %r3 = address of source memory area
Packit 6c4009
     %r4 = number of bytes to copy.  */
Packit 6c4009
Packit Service 93dc7a
       .text
Packit Service bc8896
Packit Service bc8896
#if defined __s390x__
Packit Service bc8896
# define LTGR	ltgr
Packit Service bc8896
# define CGHI	cghi
Packit Service bc8896
# define LGR	lgr
Packit Service bc8896
# define AGHI	aghi
Packit Service bc8896
# define BRCTG	brctg
Packit Service bc8896
#else
Packit Service bc8896
# define LTGR	ltr
Packit Service bc8896
# define CGHI	chi
Packit Service bc8896
# define LGR	lr
Packit Service bc8896
# define AGHI	ahi
Packit Service bc8896
# define BRCTG	brct
Packit Service bc8896
#endif /* ! defined __s390x__  */
Packit Service bc8896
Packit Service 289aec
#if HAVE_MEMCPY_Z900_G5
Packit Service 289aec
ENTRY(MEMPCPY_Z900_G5)
Packit Service 289aec
# if defined __s390x__
Packit 6c4009
	.machine "z900"
Packit Service 289aec
# else
Packit Service bc8896
	.machine "g5"
Packit Service 289aec
# endif /* ! defined __s390x__  */
Packit Service bc8896
	LGR     %r1,%r2             # Use as dest
Packit 6c4009
	la      %r2,0(%r4,%r2)      # Return dest + n
Packit Service bc8896
	j	.L_Z900_G5_start
Packit Service 289aec
END(MEMPCPY_Z900_G5)
Packit 6c4009
Packit Service 289aec
ENTRY(MEMCPY_Z900_G5)
Packit Service 289aec
# if defined __s390x__
Packit 6c4009
	.machine "z900"
Packit Service 289aec
# else
Packit Service bc8896
	.machine "g5"
Packit Service 289aec
# endif /* ! defined __s390x__  */
Packit Service bc8896
	LGR     %r1,%r2             # r1: Use as dest ; r2: Return dest
Packit Service bc8896
.L_Z900_G5_start:
Packit Service bc8896
	LTGR    %r4,%r4
Packit Service bc8896
	je      .L_Z900_G5_4
Packit Service bc8896
	AGHI    %r4,-1
Packit Service 289aec
# if defined __s390x__
Packit Service bc8896
	srlg	%r5,%r4,8
Packit Service 289aec
# else
Packit Service bc8896
	lr	%r5,%r4
Packit Service bc8896
	srl	%r5,8
Packit Service 289aec
# endif /* ! defined __s390x__  */
Packit Service bc8896
	LTGR    %r5,%r5
Packit Service bc8896
	jne     .L_Z900_G5_13
Packit Service bc8896
.L_Z900_G5_3:
Packit Service 289aec
# if defined __s390x__
Packit Service bc8896
	larl    %r5,.L_Z900_G5_15
Packit Service 289aec
#  define Z900_G5_EX_D 0
Packit Service 289aec
# else
Packit Service bc8896
	basr    %r5,0
Packit Service bc8896
.L_Z900_G5_14:
Packit Service 289aec
#  define Z900_G5_EX_D .L_Z900_G5_15-.L_Z900_G5_14
Packit Service 289aec
# endif /* ! defined __s390x__  */
Packit Service bc8896
	ex      %r4,Z900_G5_EX_D(%r5)
Packit Service bc8896
.L_Z900_G5_4:
Packit 6c4009
	br      %r14
Packit Service bc8896
.L_Z900_G5_13:
Packit Service bc8896
	CGHI	%r5,4096            # Switch to mvcle for copies >1MB
Packit 6c4009
	jh      __memcpy_mvcle
Packit Service bc8896
.L_Z900_G5_12:
Packit 6c4009
	mvc     0(256,%r1),0(%r3)
Packit 6c4009
	la      %r1,256(%r1)
Packit 6c4009
	la      %r3,256(%r3)
Packit Service bc8896
	BRCTG   %r5,.L_Z900_G5_12
Packit Service bc8896
	j       .L_Z900_G5_3
Packit Service bc8896
.L_Z900_G5_15:
Packit 6c4009
	mvc     0(1,%r1),0(%r3)
Packit Service 289aec
END(MEMCPY_Z900_G5)
Packit Service 289aec
#endif /* HAVE_MEMCPY_Z900_G5  */
Packit 6c4009
Packit 6c4009
ENTRY(__memcpy_mvcle)
Packit 6c4009
	# Using as standalone function will result in unexpected
Packit 6c4009
	# results since the length field is incremented by 1 in order to
Packit 6c4009
	# compensate the changes already done in the functions above.
Packit Service bc8896
	LGR     %r0,%r2             # backup return dest [ + n ]
Packit Service bc8896
	AGHI    %r4,1               # length + 1
Packit Service bc8896
	LGR     %r5,%r4             # source length
Packit Service bc8896
	LGR     %r4,%r3             # source address
Packit Service bc8896
	LGR     %r2,%r1             # destination address
Packit Service bc8896
	LGR     %r3,%r5             # destination length = source length
Packit 6c4009
.L_MVCLE_1:
Packit 6c4009
	mvcle   %r2,%r4,0           # thats it, MVCLE is your friend
Packit 6c4009
	jo      .L_MVCLE_1
Packit Service bc8896
	LGR     %r2,%r0             # return destination address
Packit 6c4009
	br      %r14
Packit 6c4009
END(__memcpy_mvcle)
Packit Service bc8896
Packit Service bc8896
#undef LTGR
Packit Service bc8896
#undef CGHI
Packit Service bc8896
#undef LGR
Packit Service bc8896
#undef AGHI
Packit Service bc8896
#undef BRCTG
Packit Service 289aec
Packit Service 289aec
#if HAVE_MEMCPY_Z10
Packit Service 289aec
ENTRY(MEMPCPY_Z10)
Packit Service 289aec
	.machine "z10"
Packit Service 289aec
	.machinemode "zarch_nohighgprs"
Packit Service 289aec
	lgr     %r1,%r2         # Use as dest
Packit Service 289aec
	la      %r2,0(%r4,%r2)  # Return dest + n
Packit Service 289aec
	j	.L_Z10_start
Packit Service 289aec
END(MEMPCPY_Z10)
Packit Service 289aec
Packit Service 289aec
ENTRY(MEMCPY_Z10)
Packit Service 289aec
	.machine "z10"
Packit Service 289aec
	.machinemode "zarch_nohighgprs"
Packit Service 289aec
	lgr     %r1,%r2         # r1: Use as dest ; r2: Return dest
Packit Service 289aec
.L_Z10_start:
Packit Service 289aec
# if !defined __s390x__
Packit Service 289aec
	llgfr	%r4,%r4
Packit Service 289aec
# endif /* !defined __s390x__  */
Packit Service 289aec
	cgije   %r4,0,.L_Z10_4
Packit Service 289aec
	aghi    %r4,-1
Packit Service 289aec
	srlg    %r5,%r4,8
Packit Service 289aec
	cgijlh  %r5,0,.L_Z10_13
Packit Service 289aec
.L_Z10_3:
Packit Service 289aec
	exrl    %r4,.L_Z10_15
Packit Service 289aec
.L_Z10_4:
Packit Service 289aec
	br      %r14
Packit Service 289aec
.L_Z10_13:
Packit Service 289aec
	cgfi    %r5,65535	# Switch to mvcle for copies >16MB
Packit Service 289aec
	jh      __memcpy_mvcle
Packit Service 289aec
.L_Z10_12:
Packit Service 289aec
	pfd     1,768(%r3)
Packit Service 289aec
	pfd     2,768(%r1)
Packit Service 289aec
	mvc     0(256,%r1),0(%r3)
Packit Service 289aec
	la      %r1,256(%r1)
Packit Service 289aec
	la      %r3,256(%r3)
Packit Service 289aec
	brctg   %r5,.L_Z10_12
Packit Service 289aec
	j       .L_Z10_3
Packit Service 289aec
.L_Z10_15:
Packit Service 289aec
	mvc     0(1,%r1),0(%r3)
Packit Service 289aec
END(MEMCPY_Z10)
Packit Service 289aec
#endif /* HAVE_MEMCPY_Z10  */
Packit Service 289aec
Packit Service 289aec
#if HAVE_MEMCPY_Z196
Packit Service 289aec
ENTRY(MEMPCPY_Z196)
Packit Service 289aec
	.machine "z196"
Packit Service 289aec
	.machinemode "zarch_nohighgprs"
Packit Service 289aec
	lgr     %r1,%r2         # Use as dest
Packit Service 289aec
	la      %r2,0(%r4,%r2)  # Return dest + n
Packit Service 289aec
	j	.L_Z196_start
Packit Service 289aec
END(MEMPCPY_Z196)
Packit Service 289aec
Packit Service 289aec
ENTRY(MEMCPY_Z196)
Packit Service 289aec
	.machine "z196"
Packit Service 289aec
	.machinemode "zarch_nohighgprs"
Packit Service 289aec
	lgr     %r1,%r2         # r1: Use as dest ; r2: Return dest
Packit Service 289aec
.L_Z196_start:
Packit Service 289aec
# if !defined __s390x__
Packit Service 289aec
	llgfr	%r4,%r4
Packit Service 289aec
# endif /* !defined __s390x__  */
Packit Service 289aec
	ltgr    %r4,%r4
Packit Service 289aec
	je      .L_Z196_4
Packit Service e16165
.L_Z196_start2:
Packit Service 289aec
	aghi    %r4,-1
Packit Service eb1a41
	risbg	%r5,%r4,8,128+63,56 # r0 = r5 / 256
Packit Service 289aec
	jne     .L_Z196_5
Packit Service 289aec
.L_Z196_3:
Packit Service 289aec
	exrl    %r4,.L_Z196_14
Packit Service 289aec
.L_Z196_4:
Packit Service 289aec
	br      %r14
Packit Service 289aec
.L_Z196_5:
Packit Service eb1a41
	cgfi	%r5,255		# Switch to loop with pfd for copies >=64kB
Packit Service eb1a41
	jh	.L_Z196_6
Packit Service 289aec
.L_Z196_2:
Packit Service 289aec
	mvc     0(256,%r1),0(%r3)
Packit Service 289aec
	aghi    %r5,-1
Packit Service 289aec
	la      %r1,256(%r1)
Packit Service 289aec
	la      %r3,256(%r3)
Packit Service 289aec
	jne     .L_Z196_2
Packit Service 289aec
	j       .L_Z196_3
Packit Service eb1a41
.L_Z196_6:
Packit Service eb1a41
	cgfi    %r5,262144      # Switch to mvcle for copies >64MB
Packit Service eb1a41
	jh      __memcpy_mvcle
Packit Service eb1a41
.L_Z196_7:
Packit Service eb1a41
	pfd     1,1024(%r3)
Packit Service eb1a41
	pfd     2,1024(%r1)
Packit Service eb1a41
	mvc     0(256,%r1),0(%r3)
Packit Service eb1a41
	aghi    %r5,-1
Packit Service eb1a41
	la      %r1,256(%r1)
Packit Service eb1a41
	la      %r3,256(%r3)
Packit Service eb1a41
	jne     .L_Z196_7
Packit Service eb1a41
	j       .L_Z196_3
Packit Service 289aec
.L_Z196_14:
Packit Service 289aec
	mvc     0(1,%r1),0(%r3)
Packit Service 289aec
END(MEMCPY_Z196)
Packit Service 289aec
#endif /* HAVE_MEMCPY_Z196  */
Packit Service 289aec
Packit Service e16165
#if HAVE_MEMMOVE_Z13
Packit Service e16165
ENTRY(MEMMOVE_Z13)
Packit Service e16165
	.machine "z13"
Packit Service e16165
	.machinemode "zarch_nohighgprs"
Packit Service e16165
# if !defined __s390x__
Packit Service e16165
	/* Note: The 31bit dst and src pointers are prefixed with zeroes.  */
Packit Service e16165
	llgfr	%r4,%r4
Packit Service e16165
	llgfr	%r3,%r3
Packit Service e16165
	llgfr	%r2,%r2
Packit Service e16165
# endif /* !defined __s390x__ */
Packit Service e16165
	sgrk	%r0,%r2,%r3
Packit Service e16165
	clgijh	%r4,16,.L_MEMMOVE_Z13_LARGE
Packit Service e16165
	aghik	%r5,%r4,-1
Packit Service e16165
.L_MEMMOVE_Z13_SMALL:
Packit Service e16165
	jl .L_MEMMOVE_Z13_END		/* Jump away if len was zero.  */
Packit Service e16165
	/* Store up to 16 bytes with vll/vstl which needs the index
Packit Service e16165
	   instead of lengths.  */
Packit Service e16165
	vll	%v16,%r5,0(%r3)
Packit Service e16165
	vstl	%v16,%r5,0(%r2)
Packit Service e16165
.L_MEMMOVE_Z13_END:
Packit Service e16165
	br      %r14
Packit Service e16165
.L_MEMMOVE_Z13_LARGE:
Packit Service e16165
	lgr     %r1,%r2			/* For memcpy: r1: Use as dest ;
Packit Service e16165
					   r2: Return dest  */
Packit Service e16165
	/* The unsigned comparison (dst - src >= len) determines if we can
Packit Service e16165
	   execute the forward case with memcpy.  */
Packit Service e16165
#if ! HAVE_MEMCPY_Z196
Packit Service e16165
# error The z13 variant of memmove needs the z196 variant of memcpy!
Packit Service e16165
#endif
Packit Service e16165
	clgrjhe %r0,%r4,.L_Z196_start2
Packit Service e16165
	risbgn	%r5,%r4,4,128+63,60	/* r5 = r4 / 16  */
Packit Service e16165
	aghi	%r4,-16
Packit Service e16165
	clgijhe	%r5,8,.L_MEMMOVE_Z13_LARGE_64B
Packit Service e16165
.L_MEMMOVE_Z13_LARGE_16B_LOOP:
Packit Service e16165
	/* Store at least 16 bytes with vl/vst. The number of 16byte blocks
Packit Service e16165
	   is stored in r5.  */
Packit Service e16165
	vl	%v16,0(%r4,%r3)
Packit Service e16165
	vst	%v16,0(%r4,%r2)
Packit Service e16165
	aghi	%r4,-16
Packit Service e16165
	brctg	%r5,.L_MEMMOVE_Z13_LARGE_16B_LOOP
Packit Service e16165
	aghik	%r5,%r4,15
Packit Service e16165
	j	.L_MEMMOVE_Z13_SMALL
Packit Service e16165
.L_MEMMOVE_Z13_LARGE_64B:
Packit Service e16165
	/* Store at least 128 bytes with 4x vl/vst. The number of 64byte blocks
Packit Service e16165
	   will be stored in r0.  */
Packit Service e16165
	aghi	%r4,-48
Packit Service e16165
	srlg	%r0,%r5,2		/* r5 = %r0 / 4
Packit Service e16165
					   => Number of 64byte blocks.  */
Packit Service e16165
.L_MEMMOVE_Z13_LARGE_64B_LOOP:
Packit Service e16165
	vl	%v20,48(%r4,%r3)
Packit Service e16165
	vl	%v19,32(%r4,%r3)
Packit Service e16165
	vl	%v18,16(%r4,%r3)
Packit Service e16165
	vl	%v17,0(%r4,%r3)
Packit Service e16165
	vst	%v20,48(%r4,%r2)
Packit Service e16165
	vst	%v19,32(%r4,%r2)
Packit Service e16165
	vst	%v18,16(%r4,%r2)
Packit Service e16165
	vst	%v17,0(%r4,%r2)
Packit Service e16165
	aghi	%r4,-64
Packit Service e16165
	brctg	%r0,.L_MEMMOVE_Z13_LARGE_64B_LOOP
Packit Service e16165
	aghi	%r4,48
Packit Service e16165
	/* Recalculate the number of 16byte blocks.  */
Packit Service e16165
	risbg	%r5,%r5,62,128+63,0	/* r5 = r5 & 3
Packit Service e16165
					   => Remaining 16byte blocks.  */
Packit Service e16165
	jne	.L_MEMMOVE_Z13_LARGE_16B_LOOP
Packit Service e16165
	aghik	%r5,%r4,15
Packit Service e16165
	j	.L_MEMMOVE_Z13_SMALL
Packit Service e16165
END(MEMMOVE_Z13)
Packit Service e16165
#endif /* HAVE_MEMMOVE_Z13  */
Packit Service e16165
Packit Service f9a80f
#if HAVE_MEMMOVE_ARCH13
Packit Service f9a80f
ENTRY(MEMMOVE_ARCH13)
Packit Service f9a80f
	.machine "arch13"
Packit Service f9a80f
	.machinemode "zarch_nohighgprs"
Packit Service f9a80f
# if ! defined __s390x__
Packit Service f9a80f
	/* Note: The 31bit dst and src pointers are prefixed with zeroes.  */
Packit Service f9a80f
	llgfr	%r4,%r4
Packit Service f9a80f
	llgfr	%r3,%r3
Packit Service f9a80f
	llgfr	%r2,%r2
Packit Service f9a80f
# endif /* ! defined __s390x__ */
Packit Service f9a80f
	sgrk	%r5,%r2,%r3
Packit Service f9a80f
	aghik	%r0,%r4,-1	/* Both vstl and mvcrl needs highest index.  */
Packit Service f9a80f
	clgijh	%r4,16,.L_MEMMOVE_ARCH13_LARGE
Packit Service f9a80f
.L_MEMMOVE_ARCH13_SMALL:
Packit Service f9a80f
	jl .L_MEMMOVE_ARCH13_END /* Return if len was zero (cc of aghik).  */
Packit Service f9a80f
	/* Store up to 16 bytes with vll/vstl (needs highest index).  */
Packit Service f9a80f
	vll	%v16,%r0,0(%r3)
Packit Service f9a80f
	vstl	%v16,%r0,0(%r2)
Packit Service f9a80f
.L_MEMMOVE_ARCH13_END:
Packit Service f9a80f
	br      %r14
Packit Service f9a80f
.L_MEMMOVE_ARCH13_LARGE:
Packit Service f9a80f
	lgr     %r1,%r2	/* For memcpy: r1: Use as dest ; r2: Return dest  */
Packit Service f9a80f
	/* The unsigned comparison (dst - src >= len) determines if we can
Packit Service f9a80f
	   execute the forward case with memcpy.  */
Packit Service f9a80f
#if ! HAVE_MEMCPY_Z196
Packit Service f9a80f
# error The arch13 variant of memmove needs the z196 variant of memcpy!
Packit Service f9a80f
#endif
Packit Service f9a80f
	/* Backward case.  */
Packit Service f9a80f
	clgrjhe %r5,%r4,.L_Z196_start2
Packit Service f9a80f
	clgijh	%r0,255,.L_MEMMOVE_ARCH13_LARGER_256B
Packit Service f9a80f
	/* Move up to 256bytes with mvcrl (move right to left).  */
Packit Service f9a80f
	mvcrl	0(%r1),0(%r3)	/* Move (r0 + 1) bytes from r3 to r1.  */
Packit Service f9a80f
	br      %r14
Packit Service f9a80f
.L_MEMMOVE_ARCH13_LARGER_256B:
Packit Service f9a80f
	/* First move the "remaining" block of up to 256 bytes at the end of
Packit Service f9a80f
	   src/dst buffers.  Then move blocks of 256bytes in a loop starting
Packit Service f9a80f
	   with the block at the end.
Packit Service f9a80f
	   (If src/dst pointers are aligned e.g. to 256 bytes, then the pointers
Packit Service f9a80f
	   passed to mvcrl instructions are aligned, too)  */
Packit Service f9a80f
	risbgn	%r5,%r0,8,128+63,56	/* r5 = r0 / 256  */
Packit Service f9a80f
	risbgn	%r0,%r0,56,128+63,0	/* r0 = r0 & 0xFF  */
Packit Service f9a80f
	slgr	%r4,%r0
Packit Service f9a80f
	lay	%r1,-1(%r4,%r1)
Packit Service f9a80f
	lay	%r3,-1(%r4,%r3)
Packit Service f9a80f
	mvcrl	0(%r1),0(%r3)	/* Move (r0 + 1) bytes from r3 to r1.  */
Packit Service f9a80f
	lghi	%r0,255		/* Always copy 256 bytes in the loop below!  */
Packit Service f9a80f
.L_MEMMOVE_ARCH13_LARGE_256B_LOOP:
Packit Service f9a80f
	aghi	%r1,-256
Packit Service f9a80f
	aghi	%r3,-256
Packit Service f9a80f
	mvcrl	0(%r1),0(%r3)	/* Move (r0 + 1) bytes from r3 to r1.  */
Packit Service f9a80f
	brctg	%r5,.L_MEMMOVE_ARCH13_LARGE_256B_LOOP
Packit Service f9a80f
	br      %r14
Packit Service f9a80f
END(MEMMOVE_ARCH13)
Packit Service f9a80f
#endif /* HAVE_MEMMOVE_ARCH13  */
Packit Service f9a80f
Packit Service 289aec
#if ! HAVE_MEMCPY_IFUNC
Packit Service 289aec
/* If we don't use ifunc, define an alias for mem[p]cpy here.
Packit Service 289aec
   Otherwise see sysdeps/s390/mem[p]cpy.c.  */
Packit Service 289aec
strong_alias (MEMCPY_DEFAULT, memcpy)
Packit Service 289aec
strong_alias (MEMPCPY_DEFAULT, __mempcpy)
Packit Service 289aec
weak_alias (__mempcpy, mempcpy)
Packit Service 289aec
#endif
Packit Service 289aec
Packit Service e16165
#if ! HAVE_MEMMOVE_IFUNC
Packit Service e16165
/* If we don't use ifunc, define an alias for memmove here.
Packit Service e16165
   Otherwise see sysdeps/s390/memmove.c.  */
Packit Service e16165
# if ! HAVE_MEMMOVE_C
Packit Service e16165
/* If the c variant is needed, then sysdeps/s390/memmove-c.c
Packit Service e16165
   defines memmove.
Packit Service e16165
   Otherwise MEMMOVE_DEFAULT is implemented here and we have to define it.  */
Packit Service e16165
strong_alias (MEMMOVE_DEFAULT, memmove)
Packit Service e16165
# endif
Packit Service e16165
#endif
Packit Service e16165
Packit Service 289aec
#if defined SHARED && IS_IN (libc)
Packit Service 289aec
/* Defines the internal symbols.
Packit Service 289aec
   Compare to libc_hidden_[builtin_]def (mem[p]cpy) in string/mem[p]cpy.c.  */
Packit Service 289aec
strong_alias (MEMCPY_DEFAULT, __GI_memcpy)
Packit Service 289aec
strong_alias (MEMPCPY_DEFAULT, __GI_mempcpy)
Packit Service 289aec
strong_alias (MEMPCPY_DEFAULT, __GI___mempcpy)
Packit Service e16165
# if ! HAVE_MEMMOVE_C
Packit Service e16165
/* If the c variant is needed, then sysdeps/s390/memmove-c.c
Packit Service e16165
   defines the internal symbol.
Packit Service e16165
   Otherwise MEMMOVE_DEFAULT is implemented here and we have to define it.  */
Packit Service e16165
strong_alias (MEMMOVE_DEFAULT, __GI_memmove)
Packit Service e16165
# endif
Packit Service 289aec
#endif