1 /* Vector optimized 32/64 bit S/390 version of wcsncmp.
2 Copyright (C) 2015-2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #include <ifunc-wcsncmp.h>
23 # include "asm-syntax.h"
27 /* int wcsncmp (const wchar_t *s1, const wchar_t *s2, size_t n)
28 Compare at most n characters of two strings.
43 .machinemode "zarch_nohighgprs"
45 # if !defined __s390x__
47 # endif /* !defined __s390x__ */
49 clgije %r4,0,.Lend_equal /* Nothing to do if n == 0. */
51 /* Check range of n and convert to byte-count. */
53 tmhh %r4,49152 /* Test bit 0 or 1 of maxlen. */
54 lghi %r1,-4 /* Max byte-count is 18446744073709551612. */
56 tmlh %r4,49152 /* Test bit 0 or 1 of maxlen. */
57 llilf %r1,4294967292 /* Max byte-count is 4294967292. */
58 # endif /* !__s390x__ */
59 sllg %r4,%r4,2 /* Convert character-count to byte-count. */
60 locgrne %r4,%r1 /* Use max byte-count, if bit 0/1 was one. */
62 /* Check first character without vector load. */
63 lghi %r5,4 /* current_len = 4 bytes. */
68 crjne %r0,%r1,.Lend_cmp_one_char
71 vlbb %v17,0(%r5,%r3),6 /* Load s2 to block boundary. */
72 vlbb %v16,0(%r5,%r2),6 /* Load s1 to block boundary. */
73 lcbb %r0,0(%r5,%r2),6 /* Get loaded byte count of s1. */
74 jo .Llt16_1 /* Jump away if vector not fully loaded. */
75 lcbb %r1,0(%r5,%r3),6 /* Get loaded byte count of s2. */
76 jo .Llt16_2 /* Jump away if vector not fully loaded. */
77 aghi %r5,16 /* Both vectors are fully loaded. */
78 vfenezfs %v18,%v16,%v17 /* Compare not equal with zero search. */
79 clgrjhe %r5,%r4,.Llastcmp /* If current_len >= n ->last compare. */
82 vlbb %v17,0(%r5,%r3),6
83 vlbb %v16,0(%r5,%r2),6
89 vfenezfs %v18,%v16,%v17
90 clgrjhe %r5,%r4,.Llastcmp
93 vlbb %v17,0(%r5,%r3),6
94 vlbb %v16,0(%r5,%r2),6
100 vfenezfs %v18,%v16,%v17
101 clgrjhe %r5,%r4,.Llastcmp
104 vlbb %v17,0(%r5,%r3),6
105 vlbb %v16,0(%r5,%r2),6
106 lcbb %r0,0(%r5,%r2),6
108 lcbb %r1,0(%r5,%r3),6
111 vfenezfs %v18,%v16,%v17
112 clgrjhe %r5,%r4,.Llastcmp
118 lcbb %r1,0(%r5,%r3),6 /* Get loaded byte count of s2. */
120 clr %r0,%r1 /* Compare logical. */
121 locrh %r0,%r1 /* Compute minimum of bytes loaded. */
122 nill %r0,65532 /* Align bytes loaded to full characters. */
123 jz .Lcmp_one_char /* Jump away if no full char is available. */
125 algfr %r5,%r0 /* Add smallest loaded bytes to current_len. */
126 vfenezfs %v18,%v16,%v17 /* Compare not equal with zero search. */
127 clgrj %r5,%r4,10,.Llastcmp /* If current_len >= n -> last compare */
128 vlgvb %r1,%v18,7 /* Get not equal index or 16 if all equal. */
129 clrjl %r1,%r0,.Lfound /* Jump away if miscompare is within
130 loaded bytes; (index < loaded-bytes) */
134 /* At least one of both strings is not 4-byte aligned
135 and there is no full character before next block-boundary.
136 Compare one character to get over the boundary and
137 proceed with normal loop! */
138 vlef %v16,0(%r5,%r2),0 /* Load one character. */
139 lghi %r0,4 /* Loaded byte count is 4. */
140 vlef %v17,0(%r5,%r3),0
141 j .Llt_cmp /* Proceed with comparision. */
144 /* Use comparision result only if located within first n characters.
145 %r0: loaded byte count in vreg;
148 (current_len - n): [0...16[
149 First ignored match index: loaded bytes - (current_len-n): ]0...16]
151 slgr %r5,%r4 /* %r5 = current_len - n. */
152 slr %r0,%r5 /* %r0 = first ignored match index. */
153 vlgvb %r4,%v18,7 /* Get not equal index or 16 if all equal. */
154 clrjl %r4,%r0,.Lfound2 /* Jump away if miscompare is within
155 loaded bytes and below n bytes. */
161 /* Difference or end of string. */
162 /* vfenezf found an unequal element or zero.
163 This instruction compares unsigned words, but wchar_t is signed.
164 Thus we have to compare the found element again. */
165 vlgvb %r4,%v18,7 /* Extract not equal byte-index. */
167 srl %r4,2 /* And convert it to character-index. */
168 vlgvf %r0,%v16,0(%r4) /* Load character-values. */
169 vlgvf %r1,%v17,0(%r4)
179 # if ! HAVE_WCSNCMP_IFUNC
180 strong_alias (WCSNCMP_Z13, wcsncmp)