1 /* Vector optimized 32/64 bit S/390 version of strncmp.
2 Copyright (C) 2015-2021 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-strncmp.h>
24 # include "asm-syntax.h"
28 /* int strncmp (const char *s1, const char *s2, size_t n)
29 Compare at most n characters of two strings.
44 .machinemode "zarch_nohighgprs"
46 # if !defined __s390x__
48 # endif /* !defined __s390x__ */
50 clgije %r4,0,.Lend_equal /* Nothing to do if n == 0, */
51 lghi %r5,0 /* current_len = 0. */
54 vlbb %v16,0(%r5,%r2),6 /* Load s1 to block boundary. */
55 vlbb %v17,0(%r5,%r3),6 /* Load s2 to block boundary. */
56 lcbb %r0,0(%r5,%r2),6 /* Get loaded byte count of s1. */
57 jo .Llt16_1 /* Jump away if vr is not fully loaded. */
58 lcbb %r1,0(%r5,%r3),6 /* Get loaded byte count of s2. */
59 jo .Llt16_2 /* Jump away if vr is not fully loaded. */
60 aghi %r5,16 /* Both vrs are fully loaded. */
61 clgrjhe %r5,%r4,.Llastcmp /* If current_len >= n ->last compare. */
62 vfenezbs %v18,%v16,%v17 /* Compare not equal with zero search. */
65 vlbb %v16,0(%r5,%r2),6
66 vlbb %v17,0(%r5,%r3),6
72 clgrjhe %r5,%r4,.Llastcmp
73 vfenezbs %v18,%v16,%v17
76 vlbb %v16,0(%r5,%r2),6
77 vlbb %v17,0(%r5,%r3),6
83 clgrjhe %r5,%r4,.Llastcmp
84 vfenezbs %v18,%v16,%v17
87 vlbb %v16,0(%r5,%r2),6
88 vlbb %v17,0(%r5,%r3),6
94 clgrjhe %r5,%r4,.Llastcmp
95 vfenezbs %v18,%v16,%v17
100 lcbb %r1,0(%r5,%r3),6 /* Get loaded byte count ofs2. */
102 clr %r0,%r1 /* Compare logical. */
103 locrh %r0,%r1 /* Compute minimum of bytes loaded. */
104 algfr %r5,%r0 /* Add smallest loaded bytes to current_len. */
105 clgrj %r5,%r4,10,.Llastcmp /* If current_len >= n ->last compare. */
106 vfenezbs %v18,%v16,%v17 /* Compare not equal with zero search. */
107 vlgvb %r1,%v18,7 /* Get not equal index or 16 if all equal. */
108 clrjl %r1,%r0,.Lfound /* Jump away if miscompare is within
109 loaded bytes (index < loaded-bytes) */
113 /* Use comparision result only if located within first n characters.
114 %r0: loaded byte count in vreg;
117 (current_len - n): [0...16[
118 First ignored match index: loaded bytes - (current_len-n): ]0...16]
120 slgr %r5,%r4 /* %r5 = current_len - n. */
121 slr %r0,%r5 /* %r0 = first ignored match index. */
122 vfenezbs %v18,%v16,%v17 /* Compare not equal with zero search. */
123 vlgvb %r1,%v18,7 /* Get not equal index or 16 if all equal. */
124 clrjl %r1,%r0,.Lfound /* Jump away if miscompare is within
125 loaded bytes and below n bytes. */
126 j .Lend_equal /* Miscompare after n-bytes -> end equal. */
129 /* Difference or end of string. */
140 # if ! HAVE_STRNCMP_IFUNC
141 strong_alias (STRNCMP_Z13, strncmp)
144 # if ! HAVE_STRNCMP_C && defined SHARED && IS_IN (libc)
145 strong_alias (STRNCMP_Z13, __GI_strncmp)
148 #endif /* HAVE_STRNCMP_Z13 */