|
Packit |
6c4009 |
/* Vector optimized 32/64 bit S/390 version of wcscspn.
|
|
Packit |
6c4009 |
Copyright (C) 2015-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 |
#if defined HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# include "sysdep.h"
|
|
Packit |
6c4009 |
# include "asm-syntax.h"
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.text
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* size_t wcscspn (const wchar_t *s, const wchar_t * reject)
|
|
Packit |
6c4009 |
The wcscspn() function calculates the length of the initial segment
|
|
Packit |
6c4009 |
of s which consists entirely of characters not in reject.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
This method checks the length of reject string. If it fits entirely
|
|
Packit |
6c4009 |
in one vector register, a fast algorithm is used, which does not need
|
|
Packit |
6c4009 |
to check multiple parts of accept-string. Otherwise a slower full
|
|
Packit |
6c4009 |
check of accept-string is used.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
register overview:
|
|
Packit |
6c4009 |
r3: pointer to start of reject-string
|
|
Packit |
6c4009 |
r2: pointer to start of search-string
|
|
Packit |
6c4009 |
r0: loaded byte count of vlbb search-string
|
|
Packit |
6c4009 |
r4: found byte index
|
|
Packit |
6c4009 |
r1: current return len
|
|
Packit |
6c4009 |
v16: search-string
|
|
Packit |
6c4009 |
v17: reject-string
|
|
Packit |
6c4009 |
v18: temp-vreg
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
ONLY FOR SLOW:
|
|
Packit |
6c4009 |
v19: first reject-string
|
|
Packit |
6c4009 |
v20: zero for preparing acc-vector
|
|
Packit |
6c4009 |
v21: global mask; 1 indicates a match between
|
|
Packit |
6c4009 |
search-string-vreg and any reject-character
|
|
Packit |
6c4009 |
v22: current mask; 1 indicates a match between
|
|
Packit |
6c4009 |
search-string-vreg and any reject-character in current acc-vreg
|
|
Packit |
6c4009 |
v30, v31: for re-/storing registers r6, r8, r9
|
|
Packit |
6c4009 |
r5: current len of reject-string
|
|
Packit |
6c4009 |
r6: zero-index in search-string or 16 if no zero
|
|
Packit |
6c4009 |
or min(zero-index, loaded byte count)
|
|
Packit |
6c4009 |
r8: >0, if former reject-string-part contains a zero,
|
|
Packit |
6c4009 |
otherwise =0;
|
|
Packit |
6c4009 |
r9: loaded byte count of vlbb reject-string
|
|
Packit |
6c4009 |
*/
|
|
Packit |
6c4009 |
ENTRY(__wcscspn_vx)
|
|
Packit |
6c4009 |
.machine "z13"
|
|
Packit |
6c4009 |
.machinemode "zarch_nohighgprs"
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
tmll %r2,3 /* Test if s is 4-byte aligned? */
|
|
Packit |
6c4009 |
jne .Lfallback /* And use common-code variant if not. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/*
|
|
Packit |
6c4009 |
Check if reject-string fits in one vreg:
|
|
Packit |
6c4009 |
----------------------------------------
|
|
Packit |
6c4009 |
*/
|
|
Packit |
6c4009 |
vlbb %v17,0(%r3),0 /* Load reject. */
|
|
Packit |
6c4009 |
lcbb %r0,0(%r3),0
|
|
Packit |
6c4009 |
jo .Lcheck_onbb /* Special case if reject
|
|
Packit |
6c4009 |
lays on block-boundary. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.Lcheck_notonbb:
|
|
Packit |
6c4009 |
lghi %r1,0 /* Zero out current len. */
|
|
Packit |
6c4009 |
vistrfs %v17,%v17 /* Fill with zeros after first zero. */
|
|
Packit |
6c4009 |
je .Lfast /* Zero found -> reject fits in one vreg. */
|
|
Packit |
6c4009 |
j .Lslow /* No zero -> reject exceeds one vreg. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.Lcheck_onbb:
|
|
Packit |
6c4009 |
/* Reject lays on block-boundary. */
|
|
Packit |
6c4009 |
nill %r0,65532 /* Recognize only fully loaded characters. */
|
|
Packit |
6c4009 |
je .Lcheck_onbb2 /* Reload vr, if we loaded no full wchar_t. */
|
|
Packit |
6c4009 |
vfenezf %v18,%v17,%v17 /* Search zero in loaded reject bytes. */
|
|
Packit |
6c4009 |
vlgvb %r4,%v18,7 /* Get index of zero or 16 if not found. */
|
|
Packit |
6c4009 |
clrjl %r4,%r0,.Lcheck_notonbb /* Zero index < loaded bytes count ->
|
|
Packit |
6c4009 |
Reject fits in one vreg;
|
|
Packit |
6c4009 |
Fill with zeros and proceed
|
|
Packit |
6c4009 |
with FAST. */
|
|
Packit |
6c4009 |
.Lcheck_onbb2:
|
|
Packit |
6c4009 |
vl %v17,0(%r3) /* Load reject, which exceeds loaded bytes. */
|
|
Packit |
6c4009 |
j .Lcheck_notonbb /* Check if reject fits in one vreg. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/*
|
|
Packit |
6c4009 |
Search s for reject in one vreg
|
|
Packit |
6c4009 |
-------------------------------
|
|
Packit |
6c4009 |
*/
|
|
Packit |
6c4009 |
.Lfast:
|
|
Packit |
6c4009 |
/* Complete reject-string in v17 and remaining bytes are zero. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
vlbb %v16,0(%r2),6 /* Load s until next 4k-byte boundary. */
|
|
Packit |
6c4009 |
lcbb %r0,0(%r2),6 /* Get bytes to 4k-byte boundary or 16. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
vfaezfs %v18,%v16,%v17,0 /* Find first element in v16
|
|
Packit |
6c4009 |
unequal to any in v17
|
|
Packit |
6c4009 |
or first zero element. */
|
|
Packit |
6c4009 |
vlgvb %r4,%v18,7 /* Load byte index of found element. */
|
|
Packit |
6c4009 |
clrjl %r4,%r0,.Lfast_loop_found2 /* If found index is within loaded
|
|
Packit |
6c4009 |
bytes, return with found element
|
|
Packit |
6c4009 |
index (=equal count). */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Align s to 16 byte. */
|
|
Packit |
6c4009 |
risbgn %r4,%r2,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15. */
|
|
Packit |
6c4009 |
lghi %r1,16 /* current_len = 16. */
|
|
Packit |
6c4009 |
slr %r1,%r4 /* Compute bytes to 16bytes boundary. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Process s in 16byte aligned loop. */
|
|
Packit |
6c4009 |
.Lfast_loop:
|
|
Packit |
6c4009 |
vl %v16,0(%r1,%r2) /* Load search-string. */
|
|
Packit |
6c4009 |
vfaezfs %v18,%v16,%v17,0 /* Find first element in v16 equal to any
|
|
Packit |
6c4009 |
in v17 or first zero element. */
|
|
Packit |
6c4009 |
jno .Lfast_loop_found
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
vl %v16,16(%r1,%r2)
|
|
Packit |
6c4009 |
vfaezfs %v18,%v16,%v17,0
|
|
Packit |
6c4009 |
jno .Lfast_loop_found16
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
vl %v16,32(%r1,%r2)
|
|
Packit |
6c4009 |
vfaezfs %v18,%v16,%v17,0
|
|
Packit |
6c4009 |
jno .Lfast_loop_found32
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
vl %v16,48(%r1,%r2)
|
|
Packit |
6c4009 |
vfaezfs %v18,%v16,%v17,0
|
|
Packit |
6c4009 |
jno .Lfast_loop_found48
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
aghi %r1,64
|
|
Packit |
6c4009 |
j .Lfast_loop /* Loop if no element was unequal to reject
|
|
Packit |
6c4009 |
and not zero. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Found equal or zero element. */
|
|
Packit |
6c4009 |
.Lfast_loop_found48:
|
|
Packit |
6c4009 |
aghi %r1,16
|
|
Packit |
6c4009 |
.Lfast_loop_found32:
|
|
Packit |
6c4009 |
aghi %r1,16
|
|
Packit |
6c4009 |
.Lfast_loop_found16:
|
|
Packit |
6c4009 |
aghi %r1,16
|
|
Packit |
6c4009 |
.Lfast_loop_found:
|
|
Packit |
6c4009 |
vlgvb %r4,%v18,7 /* Load byte index of found element or zero. */
|
|
Packit |
6c4009 |
.Lfast_loop_found2:
|
|
Packit |
6c4009 |
algrk %r2,%r1,%r4 /* Add found index to current len. */
|
|
Packit |
6c4009 |
srlg %r2,%r2,2 /* Convert byte-count to character-count. */
|
|
Packit |
6c4009 |
br %r14
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/*
|
|
Packit |
6c4009 |
Search s for reject in multiple vregs
|
|
Packit |
6c4009 |
-------------------------------------
|
|
Packit |
6c4009 |
*/
|
|
Packit |
6c4009 |
.Lslow:
|
|
Packit |
6c4009 |
/* Save registers. */
|
|
Packit |
6c4009 |
vlvgg %v30,%r6,0
|
|
Packit |
6c4009 |
vlvgp %v31,%r8,%r9
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Reject in v17 without zero. */
|
|
Packit |
6c4009 |
vlr %v19,%v17 /* Save first acc-part for a fast reload. */
|
|
Packit |
6c4009 |
vzero %v20 /* Zero for preparing acc-vector. */
|
|
Packit |
6c4009 |
vone %v24 /* One for checking result of former
|
|
Packit |
6c4009 |
string-part. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Align s to 16 byte. */
|
|
Packit |
6c4009 |
risbg %r4,%r2,60,128+63,0 /* Test if s is aligned and
|
|
Packit |
6c4009 |
%r4 = bits 60-63 'and' 15. */
|
|
Packit |
6c4009 |
je .Lslow_loop_str /* If s is aligned, loop aligned. */
|
|
Packit |
6c4009 |
lghi %r0,15
|
|
Packit |
6c4009 |
slr %r0,%r4 /* Compute highest index to load (15-x). */
|
|
Packit |
6c4009 |
vll %v16,%r0,0(%r2) /* Load up to 16byte boundary (vll needs
|
|
Packit |
6c4009 |
highest index, remaining bytes are 0). */
|
|
Packit |
6c4009 |
ahi %r0,1 /* Work with loaded byte count. */
|
|
Packit |
6c4009 |
vzero %v21 /* Zero out global mask. */
|
|
Packit |
6c4009 |
lghi %r5,0 /* Set current len of reject-string to zero. */
|
|
Packit |
6c4009 |
vfenezf %v18,%v16,%v16 /* Find zero in current string-part. */
|
|
Packit |
6c4009 |
lghi %r8,0 /* There is no zero in first reject-part. */
|
|
Packit |
6c4009 |
vlgvb %r6,%v18,7 /* Load byte index of zero or 16 if no zero. */
|
|
Packit |
6c4009 |
clije %r6,0,.Lslow_end /* If first element is zero -> return 0. */
|
|
Packit |
6c4009 |
clr %r0,%r6 /* cc==1 if loaded byte count < zero-index. */
|
|
Packit |
6c4009 |
locrl %r6,%r0 /* Load on cc==1; zero-index = lbc. */
|
|
Packit |
6c4009 |
j .Lslow_loop_acc
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Process s in 16byte aligned loop. */
|
|
Packit |
6c4009 |
.Lslow_next_str:
|
|
Packit |
6c4009 |
/* Check results of former processed str-part. */
|
|
Packit |
6c4009 |
vfeef %v18,%v21,%v24 /* Find first equal match in global mask
|
|
Packit |
6c4009 |
(ones in element). */
|
|
Packit |
6c4009 |
vlgvb %r4,%v18,7 /* Get index of first one (=equal) or 16. */
|
|
Packit |
6c4009 |
/* Equal-index < min(zero-index, loaded byte count)
|
|
Packit |
6c4009 |
-> Return pointer to equal element. */
|
|
Packit |
6c4009 |
clrjl %r4,%r6,.Lslow_index_found
|
|
Packit |
6c4009 |
/* Zero-index < loaded byte count
|
|
Packit |
6c4009 |
-> Former str-part was last str-part
|
|
Packit |
6c4009 |
-> Return null */
|
|
Packit |
6c4009 |
clrjl %r6,%r0,.Lslow_end_not_found
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* All elements are zero (=no match) -> proceed with next str-part. */
|
|
Packit |
6c4009 |
vlr %v17,%v19 /* Load first part of reject (no zero). */
|
|
Packit |
6c4009 |
algfr %r1,%r0 /* Add loaded byte count to current len. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.Lslow_loop_str:
|
|
Packit |
6c4009 |
vl %v16,0(%r1,%r2) /* Load search-string. */
|
|
Packit |
6c4009 |
lghi %r0,16 /* Loaded byte count is 16. */
|
|
Packit |
6c4009 |
vzero %v21 /* Zero out global mask. */
|
|
Packit |
6c4009 |
lghi %r5,0 /* Set current len of reject to zero. */
|
|
Packit |
6c4009 |
vfenezf %v18,%v16,%v16 /* Find zero in current string-part. */
|
|
Packit |
6c4009 |
lghi %r8,0 /* There is no zero in first reject-part. */
|
|
Packit |
6c4009 |
vlgvb %r6,%v18,7 /* Load byte index of zero or 16 if no zero. */
|
|
Packit |
6c4009 |
clije %r6,0,.Lslow_end /* If first element is zero (end of string)
|
|
Packit |
6c4009 |
-> Return current length. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.Lslow_loop_acc:
|
|
Packit |
6c4009 |
vfaef %v22,%v16,%v17,4 /* Create matching-mask (1 in mask ->
|
|
Packit |
6c4009 |
Character matches any rejected character in
|
|
Packit |
6c4009 |
this reject-string-part) IN=0, RT=1. */
|
|
Packit |
6c4009 |
vlgvf %r4,%v22,0 /* Get result of first element. */
|
|
Packit |
6c4009 |
/* First element is equal to any rejected characters?
|
|
Packit |
6c4009 |
(All other parts of reject cannot lead to a match before this one)
|
|
Packit |
6c4009 |
-> Return current len, which is pointing to this element. */
|
|
Packit |
6c4009 |
clijh %r4,0,.Lslow_end
|
|
Packit |
6c4009 |
vo %v21,%v21,%v22 /* Global-mask = global-|matching-mask. */
|
|
Packit |
6c4009 |
/* Proceed with next acc until end of acc is reached. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.Lslow_next_acc:
|
|
Packit |
6c4009 |
clijh %r8,0,.Lslow_next_str /* There was a zero in last reject-part
|
|
Packit |
6c4009 |
-> Add found index to current len
|
|
Packit |
6c4009 |
and end. */
|
|
Packit |
6c4009 |
vlbb %v17,16(%r5,%r3),6 /* Load next reject part. */
|
|
Packit |
6c4009 |
aghi %r5,16 /* Increment current len of reject-string. */
|
|
Packit |
6c4009 |
lcbb %r9,0(%r5,%r3),6 /* Get loaded byte count of reject-string. */
|
|
Packit |
6c4009 |
jo .Lslow_next_acc_onbb /* Jump away if reject-string is
|
|
Packit |
6c4009 |
on block-boundary. */
|
|
Packit |
6c4009 |
.Lslow_next_acc_notonbb:
|
|
Packit |
6c4009 |
vistrfs %v17,%v17 /* Fill with zeros after first zero. */
|
|
Packit |
6c4009 |
jo .Lslow_loop_acc /* No zero found -> no preparation needed. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.Lslow_next_acc_prepare_zero:
|
|
Packit |
6c4009 |
/* Zero in reject-part: fill zeros with first-reject-character. */
|
|
Packit |
6c4009 |
vlgvf %r8,%v17,0 /* Load first element of reject-part. */
|
|
Packit |
6c4009 |
clije %r8,0,.Lslow_next_str /* Process next str-part if first
|
|
Packit |
6c4009 |
character in this part of reject
|
|
Packit |
6c4009 |
is a zero. */
|
|
Packit |
6c4009 |
/* r8>0 -> zero found in this acc-part. */
|
|
Packit |
6c4009 |
vrepf %v18,%v17,0 /* Replicate first char accross all chars. */
|
|
Packit |
6c4009 |
vceqf %v22,%v20,%v17 /* Create a mask (v22) of null chars
|
|
Packit |
6c4009 |
by comparing with 0 (v20). */
|
|
Packit |
6c4009 |
vsel %v17,%v18,%v17,%v22 /* Replace null chars with first char. */
|
|
Packit |
6c4009 |
j .Lslow_loop_acc /* Reject-string part is prepared. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.Lslow_next_acc_onbb:
|
|
Packit |
6c4009 |
nill %r9,65532 /* Recognize only fully loaded characters. */
|
|
Packit |
6c4009 |
je .Lslow_next_acc_onbb2 /* Reload vr, if no full wchar_t
|
|
Packit |
6c4009 |
loaded. */
|
|
Packit |
6c4009 |
vfenezf %v18,%v17,%v17 /* Find zero in loaded bytes of reject part. */
|
|
Packit |
6c4009 |
vlgvb %r8,%v18,7 /* Load byte index of zero. */
|
|
Packit |
6c4009 |
clrjl %r8,%r9,.Lslow_next_acc_notonbb /* Found a zero in loaded bytes
|
|
Packit |
6c4009 |
-> Prepare vreg. */
|
|
Packit |
6c4009 |
.Lslow_next_acc_onbb2:
|
|
Packit |
6c4009 |
vl %v17,0(%r5,%r3) /* Load over boundary ... */
|
|
Packit |
6c4009 |
lghi %r8,0 /* r8=0 -> no zero in this part of acc,
|
|
Packit |
6c4009 |
check for zero is in jump-target. */
|
|
Packit |
6c4009 |
j .Lslow_next_acc_notonbb /* ... and search for zero in
|
|
Packit |
6c4009 |
fully loaded vreg again. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.Lslow_end_not_found:
|
|
Packit |
6c4009 |
algfr %r1,%r6 /* Add zero-index to current len. */
|
|
Packit |
6c4009 |
j .Lslow_end
|
|
Packit |
6c4009 |
.Lslow_index_found:
|
|
Packit |
6c4009 |
algfr %r1,%r4 /* Add found index of char to current len. */
|
|
Packit |
6c4009 |
.Lslow_end:
|
|
Packit |
6c4009 |
srlg %r2,%r1,2 /* Convert byte-count to character-count. */
|
|
Packit |
6c4009 |
/* Restore registers. */
|
|
Packit |
6c4009 |
vlgvg %r6,%v30,0
|
|
Packit |
6c4009 |
vlgvg %r8,%v31,0
|
|
Packit |
6c4009 |
vlgvg %r9,%v31,1
|
|
Packit |
6c4009 |
br %r14
|
|
Packit |
6c4009 |
.Lfallback:
|
|
Packit |
6c4009 |
jg __wcscspn_c
|
|
Packit |
6c4009 |
END(__wcscspn_vx)
|
|
Packit |
6c4009 |
#endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */
|