Blame sysdeps/s390/multiarch/strpbrk-vx.S

Packit Service 1c5418
/* Vector optimized 32/64 bit S/390 version of strpbrk.
Packit Service 1c5418
   Copyright (C) 2015-2018 Free Software Foundation, Inc.
Packit Service 1c5418
   This file is part of the GNU C Library.
Packit Service 1c5418
Packit Service 1c5418
   The GNU C Library is free software; you can redistribute it and/or
Packit Service 1c5418
   modify it under the terms of the GNU Lesser General Public
Packit Service 1c5418
   License as published by the Free Software Foundation; either
Packit Service 1c5418
   version 2.1 of the License, or (at your option) any later version.
Packit Service 1c5418
Packit Service 1c5418
   The GNU C Library is distributed in the hope that it will be useful,
Packit Service 1c5418
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 1c5418
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 1c5418
   Lesser General Public License for more details.
Packit Service 1c5418
Packit Service 1c5418
   You should have received a copy of the GNU Lesser General Public
Packit Service 1c5418
   License along with the GNU C Library; if not, see
Packit Service 1c5418
   <http://www.gnu.org/licenses/>.  */
Packit Service 1c5418
Packit Service 1c5418
#if defined HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc)
Packit Service 1c5418
Packit Service 1c5418
# include "sysdep.h"
Packit Service 1c5418
# include "asm-syntax.h"
Packit Service 1c5418
Packit Service 1c5418
	.text
Packit Service 1c5418
Packit Service 1c5418
/* char *strpbrk (const char *s, const char * accept)
Packit Service 1c5418
   The  strpbrk()  function locates the first occurrence in the string s
Packit Service 1c5418
   of any of the characters in the string accept and returns a pointer
Packit Service 1c5418
   to that character or NULL if not found.
Packit Service 1c5418
Packit Service 1c5418
   This method checks the length of accept string. If it fits entirely
Packit Service 1c5418
   in one vector register, a fast algorithm is used, which does not need
Packit Service 1c5418
   to check multiple parts of accept-string. Otherwise a slower full
Packit Service 1c5418
   check of accept-string is used.
Packit Service 1c5418
Packit Service 1c5418
   register overview:
Packit Service 1c5418
   r3:  pointer to start of accept-string
Packit Service 1c5418
   r2:  pointer to start of search-string
Packit Service 1c5418
   r0:  loaded byte count of vlbb search-string (32bit unsigned)
Packit Service 1c5418
   r4:  found byte index (32bit unsigned)
Packit Service 1c5418
   r1:  current return len (64bit unsigned)
Packit Service 1c5418
   v16: search-string
Packit Service 1c5418
   v17: accept-string
Packit Service 1c5418
   v18: temp-vreg
Packit Service 1c5418
Packit Service 1c5418
   ONLY FOR SLOW:
Packit Service 1c5418
   v19: first accept-string
Packit Service 1c5418
   v20: zero for preparing acc-vector
Packit Service 1c5418
   v21: global mask; 1 indicates a match between
Packit Service 1c5418
	search-string-vreg and any accept-character
Packit Service 1c5418
   v22: current mask; 1 indicates a match between
Packit Service 1c5418
	search-string-vreg and any accept-character in current acc-vreg
Packit Service 1c5418
   v24: one for result-checking of former string-part
Packit Service 1c5418
   v30, v31: for re-/storing registers r6, r8, r9
Packit Service 1c5418
   r5:  current len of accept-string
Packit Service 1c5418
   r6:  zero-index in search-string or 16 if no zero
Packit Service 1c5418
	or min(zero-index, loaded byte count)
Packit Service 1c5418
   r8:  >0, if former accept-string-part contains a zero,
Packit Service 1c5418
	otherwise =0;
Packit Service 1c5418
   r9:  loaded byte count of vlbb accept-string
Packit Service 1c5418
*/
Packit Service 1c5418
ENTRY(__strpbrk_vx)
Packit Service 1c5418
	.machine "z13"
Packit Service 1c5418
	.machinemode "zarch_nohighgprs"
Packit Service 1c5418
Packit Service 1c5418
	/*
Packit Service 1c5418
	  Check if accept-string fits in one vreg:
Packit Service 1c5418
	  ----------------------------------------
Packit Service 1c5418
	*/
Packit Service 1c5418
	vlbb	%v17,0(%r3),6	/* Load accept.  */
Packit Service 1c5418
	lghi	%r1,0		/* Zero out current len.  */
Packit Service 1c5418
	vlgvb	%r0,%v17,0	/* Get first element.  */
Packit Service 1c5418
	clije	%r0,0,.Lfast_end_null /* Return null if accept is empty.  */
Packit Service 1c5418
	lcbb	%r0,0(%r3),6
Packit Service 1c5418
	jo	.Lcheck_onbb	/* Special case if accept lays
Packit Service 1c5418
				   on block-boundary.  */
Packit Service 1c5418
.Lcheck_notonbb:
Packit Service 1c5418
	vistrbs	%v17,%v17	/* Fill with zeros after first zero.  */
Packit Service 1c5418
	je	.Lfast		/* Zero found -> accept fits in one vreg.  */
Packit Service 1c5418
	j	.Lslow		/* No zero -> accept exceeds one vreg  */
Packit Service 1c5418
Packit Service 1c5418
Packit Service 1c5418
.Lcheck_onbb:
Packit Service 1c5418
	/* Accept lays on block-boundary.  */
Packit Service 1c5418
	vfenezb	%v18,%v17,%v17	/* Search zero in loaded accept bytes.  */
Packit Service 1c5418
	vlgvb	%r4,%v18,7	/* Get index of zero or 16 if not found.  */
Packit Service 1c5418
	clrjl	%r4,%r0,.Lcheck_notonbb /* Zero index < loaded bytes count ->
Packit Service 1c5418
					    Accept fits in one vreg;
Packit Service 1c5418
					    Fill with zeros and proceed
Packit Service 1c5418
					    with FAST.  */
Packit Service 1c5418
	vl	%v17,0(%r3)	/* Load accept, which exceeds loaded bytes.  */
Packit Service 1c5418
	j	.Lcheck_notonbb /* Check if accept fits in one vreg.  */
Packit Service 1c5418
Packit Service 1c5418
Packit Service 1c5418
	/*
Packit Service 1c5418
	  Search s for accept in one vreg
Packit Service 1c5418
	  -------------------------------
Packit Service 1c5418
	*/
Packit Service 1c5418
.Lfast:
Packit Service 1c5418
	/* Complete accept-string in v17 and remaining bytes are zero.  */
Packit Service 1c5418
Packit Service 1c5418
	vlbb	%v16,0(%r2),6	/* Load s until next 4k-byte boundary.  */
Packit Service 1c5418
	lcbb	%r0,0(%r2),6	/* Get bytes to 4k-byte boundary or 16.  */
Packit Service 1c5418
Packit Service 1c5418
	vfaezbs	%v18,%v16,%v17,0 /* Find first element in v16 unequal to any
Packit Service 1c5418
				    in v17 or first zero element.  */
Packit Service 1c5418
Packit Service 1c5418
	vlgvb	%r4,%v18,7	/* Load byte index of found element.  */
Packit Service 1c5418
	/* If found index is within loaded bytes, return with found
Packit Service 1c5418
	   element index (=equal count).  */
Packit Service 1c5418
	clrjl	%r4,%r0,.Lfast_loop_found2
Packit Service 1c5418
Packit Service 1c5418
	/* Align s to 16 byte.  */
Packit Service 1c5418
	risbgn	%r4,%r2,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15.  */
Packit Service 1c5418
	lghi	%r1,16		/* current_len = 16.  */
Packit Service 1c5418
	slr	%r1,%r4		/* Compute bytes to 16bytes boundary.  */
Packit Service 1c5418
Packit Service 1c5418
	/* Process s in 16byte aligned loop.  */
Packit Service 1c5418
.Lfast_loop:
Packit Service 1c5418
	vl	%v16,0(%r1,%r2)	/* Load search-string.  */
Packit Service 1c5418
	vfaezbs	%v18,%v16,%v17,0 /* Find first element in v16 equal to any
Packit Service 1c5418
				    in v17 or first zero element.  */
Packit Service 1c5418
	jno	.Lfast_loop_found
Packit Service 1c5418
Packit Service 1c5418
	vl	%v16,16(%r1,%r2)
Packit Service 1c5418
	vfaezbs	%v18,%v16,%v17,0
Packit Service 1c5418
	jno	.Lfast_loop_found16
Packit Service 1c5418
Packit Service 1c5418
	vl	%v16,32(%r1,%r2)
Packit Service 1c5418
	vfaezbs	%v18,%v16,%v17,0
Packit Service 1c5418
	jno	.Lfast_loop_found32
Packit Service 1c5418
Packit Service 1c5418
	vl	%v16,48(%r1,%r2)
Packit Service 1c5418
	vfaezbs	%v18,%v16,%v17,0
Packit Service 1c5418
	jno	.Lfast_loop_found48
Packit Service 1c5418
Packit Service 1c5418
	aghi	%r1,64
Packit Service 1c5418
	j	.Lfast_loop	/* Loop if no element was unequal to accept
Packit Service 1c5418
				   and not zero.  */
Packit Service 1c5418
Packit Service 1c5418
	/* Found equal or zero element.  */
Packit Service 1c5418
.Lfast_loop_found48:
Packit Service 1c5418
	aghi	%r1,16
Packit Service 1c5418
.Lfast_loop_found32:
Packit Service 1c5418
	aghi	%r1,16
Packit Service 1c5418
.Lfast_loop_found16:
Packit Service 1c5418
	aghi	%r1,16
Packit Service 1c5418
.Lfast_loop_found:
Packit Service 1c5418
	vlgvb	%r4,%v18,7	/* Load byte index of found element.  */
Packit Service 1c5418
.Lfast_loop_found2:
Packit Service 1c5418
	vlgvb	%r0,%v16,0(%r4)	/* Get found element.  */
Packit Service 1c5418
	clije	%r0,0,.Lfast_end_null /* Return null if no accept-char found */
Packit Service 1c5418
	algfr	%r1,%r4		/* Add found index of char to current len.  */
Packit Service 1c5418
	la	%r2,0(%r1,%r2)	/* And return pointer to first equal char.  */
Packit Service 1c5418
	br	%r14
Packit Service 1c5418
Packit Service 1c5418
.Lfast_end_null:
Packit Service 1c5418
	lghi	%r2,0		/* Return null if no character is equal.  */
Packit Service 1c5418
	br	%r14
Packit Service 1c5418
Packit Service 1c5418
Packit Service 1c5418
Packit Service 1c5418
Packit Service 1c5418
	/*
Packit Service 1c5418
	  Search s for accept in multiple vregs
Packit Service 1c5418
	  -------------------------------------
Packit Service 1c5418
	*/
Packit Service 1c5418
.Lslow:
Packit Service 1c5418
	/* Save registers.  */
Packit Service 1c5418
	vlvgg	%v30,%r6,0
Packit Service 1c5418
	vlvgp	%v31,%r8,%r9
Packit Service 1c5418
Packit Service 1c5418
	/* accept in v17 without zero.  */
Packit Service 1c5418
	vlr	%v19,%v17	/* Save first acc-part for a fast reload.  */
Packit Service 1c5418
	vzero	%v20		/* Zero for preparing acc-vector.  */
Packit Service 1c5418
	vone	%v24		/* One for checking result of former string.  */
Packit Service 1c5418
Packit Service 1c5418
	/* Align s to 16 byte.  */
Packit Service 1c5418
	risbg	%r4,%r2,60,128+63,0 /* Test if s is aligned and
Packit Service 1c5418
				       %r4 = bits 60-63 'and' 15.  */
Packit Service 1c5418
	je	.Lslow_loop_str /* If s is aligned, loop aligned.  */
Packit Service 1c5418
	lghi	%r0,15
Packit Service 1c5418
	slr	%r0,%r4		/* Compute highest index to load (15-x).  */
Packit Service 1c5418
	vll	%v16,%r0,0(%r2) /* Load up to 16 byte boundary (vll needs
Packit Service 1c5418
				   highest index, remaining bytes are 0).  */
Packit Service 1c5418
	ahi	%r0,1		/* Work with loaded byte count.  */
Packit Service 1c5418
	vzero	%v21		/* Zero out global mask.  */
Packit Service 1c5418
	lghi	%r5,0		/* Set current len of accept-string to zero.  */
Packit Service 1c5418
	vfenezb	%v18,%v16,%v16	/* Find zero in current string-part.  */
Packit Service 1c5418
	lghi	%r8,0		/* There is no zero in first accept-part.  */
Packit Service 1c5418
	vlgvb	%r6,%v18,7	/* Load byte index of zero or 16 if no zero.  */
Packit Service 1c5418
	clije	%r6,0,.Lslow_end_null /* If first element is zero
Packit Service 1c5418
					  (end of string) -> return null */
Packit Service 1c5418
	clr	%r0,%r6		/* cc==1 if loaded byte count < zero-index.  */
Packit Service 1c5418
	locrl	%r6,%r0		/* Load on cc==1; zero-index = lbc.  */
Packit Service 1c5418
	j	.Lslow_loop_acc
Packit Service 1c5418
Packit Service 1c5418
Packit Service 1c5418
	/* Process s in 16byte aligned loop.  */
Packit Service 1c5418
.Lslow_next_str:
Packit Service 1c5418
	/* Check results of former processed str-part.  */
Packit Service 1c5418
	vfeeb	%v18,%v21,%v24	/* Find first equal match in global mask
Packit Service 1c5418
				   (ones in element).  */
Packit Service 1c5418
	vlgvb	%r4,%v18,7	/* Get index of first one (=equal)
Packit Service 1c5418
				   or 16 if no match.  */
Packit Service 1c5418
	/* Equal-index < min(zero-index, loaded byte count)
Packit Service 1c5418
	   -> return pointer to equal element.  */
Packit Service 1c5418
	clrjl	%r4,%r6,.Lslow_index_found
Packit Service 1c5418
	/* Zero-index < loaded byte count
Packit Service 1c5418
	   -> former str-part was last str-part
Packit Service 1c5418
	   -> return null */
Packit Service 1c5418
	clrjl	%r6,%r0,.Lslow_end_null
Packit Service 1c5418
	/* All elements are zero (=no match) -> proceed with next str-part.  */
Packit Service 1c5418
Packit Service 1c5418
	vlr	%v17,%v19	/* Load first part of accept (no zero).  */
Packit Service 1c5418
	algfr	%r1,%r0		/* Add loaded byte count to current len.  */
Packit Service 1c5418
Packit Service 1c5418
.Lslow_loop_str:
Packit Service 1c5418
	vl	%v16,0(%r1,%r2)	/* Load search-string */
Packit Service 1c5418
	lghi	%r0,16		/* Loaded byte count is 16.  */
Packit Service 1c5418
	vzero	%v21		/* Zero out global mask.  */
Packit Service 1c5418
	lghi	%r5,0		/* Set current len of accept to zero.  */
Packit Service 1c5418
	vfenezb	%v18,%v16,%v16	/* Find zero in current string-part.  */
Packit Service 1c5418
	lghi	%r8,0		/* There is no zero in first accept-part.  */
Packit Service 1c5418
	vlgvb	%r6,%v18,7	/* Load byte index of zero or 16 if no zero.  */
Packit Service 1c5418
	clije	%r6,0,.Lslow_end_null /* If first element is zero
Packit Service 1c5418
					  (end of string) -> return null.  */
Packit Service 1c5418
Packit Service 1c5418
.Lslow_loop_acc:
Packit Service 1c5418
	vfaeb	%v22,%v16,%v17,4 /* Create matching-mask (1 in mask ->
Packit Service 1c5418
				    Character matches any accepted character in
Packit Service 1c5418
				    this accept-string-part) IN=0, RT=1.  */
Packit Service 1c5418
	vlgvb	%r4,%v22,0	/* Get result of first element.  */
Packit Service 1c5418
	/* First element is equal to any accepted characters
Packit Service 1c5418
	   (all other parts of accept cannot lead to a match before this one)
Packit Service 1c5418
	   -> current len is pointing to first element
Packit Service 1c5418
	   -> return found  */
Packit Service 1c5418
	clijh	%r4,0,.Lslow_end_found
Packit Service 1c5418
	vo	%v21,%v21,%v22	/* Global-mask = global-|matching-mask.  */
Packit Service 1c5418
	/* Proceed with next acc until end of acc is reached.  */
Packit Service 1c5418
Packit Service 1c5418
Packit Service 1c5418
.Lslow_next_acc:
Packit Service 1c5418
	clijh	%r8,0,.Lslow_next_str /* There was a zero in the last acc-part
Packit Service 1c5418
					  -> add index to current_len and
Packit Service 1c5418
					     end.  */
Packit Service 1c5418
	vlbb	%v17,16(%r5,%r3),6 /* Load next accept part.  */
Packit Service 1c5418
	aghi	%r5,16		/* Increment current len of accept-string.  */
Packit Service 1c5418
	lcbb	%r9,0(%r5,%r3),6 /* Get loaded byte count of accept-string.  */
Packit Service 1c5418
	jo	.Lslow_next_acc_onbb /* Jump away ifaccept-string is
Packit Service 1c5418
					 on block-boundary.  */
Packit Service 1c5418
.Lslow_next_acc_notonbb:
Packit Service 1c5418
	vistrbs	%v17,%v17	/* Fill with zeros after first zero.  */
Packit Service 1c5418
	jo	.Lslow_loop_acc /* No zero found -> no preparation needed.  */
Packit Service 1c5418
Packit Service 1c5418
.Lslow_next_acc_prepare_zero:
Packit Service 1c5418
	/* Zero in accept-part: fill zeros with first-accept-character.  */
Packit Service 1c5418
	vlgvb	%r8,%v17,0	/* Load first element of acc-part.  */
Packit Service 1c5418
	clije	%r8,0,.Lslow_next_str /* Proceed with next string-part,
Packit Service 1c5418
					  if first char in this part of accept
Packit Service 1c5418
					  is a zero.  */
Packit Service 1c5418
	/* r8>0 -> zero found in this acc-part.  */
Packit Service 1c5418
	vrepb	%v18,%v17,0	/* Replicate first char accross all chars.  */
Packit Service 1c5418
	vceqb	%v22,%v20,%v17	/* Create a mask (v22) of null chars
Packit Service 1c5418
				   by comparing with 0 (v20).  */
Packit Service 1c5418
	vsel	%v17,%v18,%v17,%v22 /* Replace null chars with first char.  */
Packit Service 1c5418
	j	.Lslow_loop_acc /* Accept part is prepared -> process.  */
Packit Service 1c5418
Packit Service 1c5418
.Lslow_next_acc_onbb:
Packit Service 1c5418
	vfenezb	%v18,%v17,%v17	/* Find zero in loaded bytes of accept part.  */
Packit Service 1c5418
	vlgvb	%r8,%v18,7	/* Load byte index of zero.  */
Packit Service 1c5418
	clrjl	%r8,%r9,.Lslow_next_acc_notonbb /* Found a zero in loaded bytes
Packit Service 1c5418
						    -> Prepare vreg.  */
Packit Service 1c5418
	vl	%v17,0(%r5,%r3)	/* Load over boundary ...  */
Packit Service 1c5418
	lghi	%r8,0		/* r8=0 -> no zero in this part of acc,
Packit Service 1c5418
				   check for zero is in jump-target.  */
Packit Service 1c5418
	j	.Lslow_next_acc_notonbb /* ... and search for zero in
Packit Service 1c5418
					    fully loaded vreg again.  */
Packit Service 1c5418
Packit Service 1c5418
.Lslow_end_null:
Packit Service 1c5418
	lghi	%r1,0		/* Return null if no character is equal.  */
Packit Service 1c5418
	j	.Lslow_end
Packit Service 1c5418
Packit Service 1c5418
.Lslow_loop_found:
Packit Service 1c5418
	vlgvb	%r4,%v18,7	/* Load byte index of found element.  */
Packit Service 1c5418
	vlgvb	%r0,%v16,0(%r4)	/* Get found element.  */
Packit Service 1c5418
	clije	%r0,0,.Lslow_end_null /* Return null if no acc-char found.  */
Packit Service 1c5418
Packit Service 1c5418
.Lslow_index_found:
Packit Service 1c5418
	algfr	%r1,%r4		/* Add found index of char to current len.  */
Packit Service 1c5418
.Lslow_end_found:
Packit Service 1c5418
	la	%r1,0(%r1,%r2)	/* And return pointer to first equal char.  */
Packit Service 1c5418
Packit Service 1c5418
.Lslow_end:
Packit Service 1c5418
	/* Restore registers.  */
Packit Service 1c5418
	vlgvg	%r6,%v30,0
Packit Service 1c5418
	vlgvg	%r8,%v31,0
Packit Service 1c5418
	vlgvg	%r9,%v31,1
Packit Service 1c5418
	lgr	%r2,%r1
Packit Service 1c5418
	br	%r14
Packit Service 1c5418
END(__strpbrk_vx)
Packit Service 1c5418
#endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */