1 /* Vector optimized 32/64 bit S/390 version of wcsncmp.
2 Copyright (C) 2015-2017 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 <http://www.gnu.org/licenses/>. */
19 #if defined HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc)
22 # include "asm-syntax.h"
26 /* int wcsncmp (const wchar_t *s1, const wchar_t *s2, size_t n)
27 Compare at most n characters of two strings.
42 .machinemode "zarch_nohighgprs"
44 # if !defined __s390x__
46 # endif /* !defined __s390x__ */
48 clgije %r4,0,.Lend_equal /* Nothing to do if n == 0. */
50 /* Check range of n and convert to byte-count. */
52 tmhh %r4,49152 /* Test bit 0 or 1 of maxlen. */
53 lghi %r1,-4 /* Max byte-count is 18446744073709551612. */
55 tmlh %r4,49152 /* Test bit 0 or 1 of maxlen. */
56 llilf %r1,4294967292 /* Max byte-count is 4294967292. */
57 # endif /* !__s390x__ */
58 sllg %r4,%r4,2 /* Convert character-count to byte-count. */
59 locgrne %r4,%r1 /* Use max byte-count, if bit 0/1 was one. */
61 /* Check first character without vector load. */
62 lghi %r5,4 /* current_len = 4 bytes. */
67 crjne %r0,%r1,.Lend_cmp_one_char
70 vlbb %v17,0(%r5,%r3),6 /* Load s2 to block boundary. */
71 vlbb %v16,0(%r5,%r2),6 /* Load s1 to block boundary. */
72 lcbb %r0,0(%r5,%r2),6 /* Get loaded byte count of s1. */
73 jo .Llt16_1 /* Jump away if vector not fully loaded. */
74 lcbb %r1,0(%r5,%r3),6 /* Get loaded byte count of s2. */
75 jo .Llt16_2 /* Jump away if vector not fully loaded. */
76 aghi %r5,16 /* Both vectors are fully loaded. */
77 vfenezfs %v18,%v16,%v17 /* Compare not equal with zero search. */
78 clgrjhe %r5,%r4,.Llastcmp /* If current_len >= n ->last compare. */
81 vlbb %v17,0(%r5,%r3),6
82 vlbb %v16,0(%r5,%r2),6
88 vfenezfs %v18,%v16,%v17
89 clgrjhe %r5,%r4,.Llastcmp
92 vlbb %v17,0(%r5,%r3),6
93 vlbb %v16,0(%r5,%r2),6
99 vfenezfs %v18,%v16,%v17
100 clgrjhe %r5,%r4,.Llastcmp
103 vlbb %v17,0(%r5,%r3),6
104 vlbb %v16,0(%r5,%r2),6
105 lcbb %r0,0(%r5,%r2),6
107 lcbb %r1,0(%r5,%r3),6
110 vfenezfs %v18,%v16,%v17
111 clgrjhe %r5,%r4,.Llastcmp
117 lcbb %r1,0(%r5,%r3),6 /* Get loaded byte count of s2. */
119 clr %r0,%r1 /* Compare logical. */
120 locrh %r0,%r1 /* Compute minimum of bytes loaded. */
121 nill %r0,65532 /* Align bytes loaded to full characters. */
122 jz .Lcmp_one_char /* Jump away if no full char is available. */
124 algfr %r5,%r0 /* Add smallest loaded bytes to current_len. */
125 vfenezfs %v18,%v16,%v17 /* Compare not equal with zero search. */
126 clgrj %r5,%r4,10,.Llastcmp /* If current_len >= n -> last compare */
127 vlgvb %r1,%v18,7 /* Get not equal index or 16 if all equal. */
128 clrjl %r1,%r0,.Lfound /* Jump away if miscompare is within
129 loaded bytes; (index < loaded-bytes) */
133 /* At least one of both strings is not 4-byte aligned
134 and there is no full character before next block-boundary.
135 Compare one character to get over the boundary and
136 proceed with normal loop! */
137 vlef %v16,0(%r5,%r2),0 /* Load one character. */
138 lghi %r0,4 /* Loaded byte count is 4. */
139 vlef %v17,0(%r5,%r3),0
140 j .Llt_cmp /* Proceed with comparision. */
143 /* Use comparision result only if located within first n characters.
144 %r0: loaded byte count in vreg;
147 (current_len - n): [0...16[
148 First ignored match index: loaded bytes - (current_len-n): ]0...16]
150 slgr %r5,%r4 /* %r5 = current_len - n. */
151 slr %r0,%r5 /* %r0 = first ignored match index. */
152 vlgvb %r4,%v18,7 /* Get not equal index or 16 if all equal. */
153 clrjl %r4,%r0,.Lfound2 /* Jump away if miscompare is within
154 loaded bytes and below n bytes. */
160 /* Difference or end of string. */
161 /* vfenezf found an unequal element or zero.
162 This instruction compares unsigned words, but wchar_t is signed.
163 Thus we have to compare the found element again. */
164 vlgvb %r4,%v18,7 /* Extract not equal byte-index. */
166 srl %r4,2 /* And convert it to character-index. */
167 vlgvf %r0,%v16,0(%r4) /* Load character-values. */
168 vlgvf %r1,%v17,0(%r4)
177 #endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */