1 /* Vector optimized 32/64 bit S/390 version of strncmp.
2 Copyright (C) 2015 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 strncmp (const char *s1, const char *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, */
49 lghi %r5,0 /* current_len = 0. */
52 vlbb %v16,0(%r5,%r2),6 /* Load s1 to block boundary. */
53 vlbb %v17,0(%r5,%r3),6 /* Load s2 to block boundary. */
54 lcbb %r0,0(%r5,%r2),6 /* Get loaded byte count of s1. */
55 jo .Llt16_1 /* Jump away if vr is not fully loaded. */
56 lcbb %r1,0(%r5,%r3),6 /* Get loaded byte count of s2. */
57 jo .Llt16_2 /* Jump away if vr is not fully loaded. */
58 aghi %r5,16 /* Both vrs are fully loaded. */
59 clgrjhe %r5,%r4,.Llastcmp /* If current_len >= n ->last compare. */
60 vfenezbs %v18,%v16,%v17 /* Compare not equal with zero search. */
63 vlbb %v16,0(%r5,%r2),6
64 vlbb %v17,0(%r5,%r3),6
70 clgrjhe %r5,%r4,.Llastcmp
71 vfenezbs %v18,%v16,%v17
74 vlbb %v16,0(%r5,%r2),6
75 vlbb %v17,0(%r5,%r3),6
81 clgrjhe %r5,%r4,.Llastcmp
82 vfenezbs %v18,%v16,%v17
85 vlbb %v16,0(%r5,%r2),6
86 vlbb %v17,0(%r5,%r3),6
92 clgrjhe %r5,%r4,.Llastcmp
93 vfenezbs %v18,%v16,%v17
98 lcbb %r1,0(%r5,%r3),6 /* Get loaded byte count ofs2. */
100 clr %r0,%r1 /* Compare logical. */
101 locrh %r0,%r1 /* Compute minimum of bytes loaded. */
102 algfr %r5,%r0 /* Add smallest loaded bytes to current_len. */
103 clgrj %r5,%r4,10,.Llastcmp /* If current_len >= n ->last compare. */
104 vfenezbs %v18,%v16,%v17 /* Compare not equal with zero search. */
105 vlgvb %r1,%v18,7 /* Get not equal index or 16 if all equal. */
106 clrjl %r1,%r0,.Lfound /* Jump away if miscompare is within
107 loaded bytes (index < loaded-bytes) */
111 /* Use comparision result only if located within first n characters.
112 %r0: loaded byte count in vreg;
115 (current_len - n): [0...16[
116 First ignored match index: loaded bytes - (current_len-n): ]0...16]
118 slgr %r5,%r4 /* %r5 = current_len - n. */
119 slr %r0,%r5 /* %r0 = first ignored match index. */
120 vfenezbs %v18,%v16,%v17 /* Compare not equal with zero search. */
121 vlgvb %r1,%v18,7 /* Get not equal index or 16 if all equal. */
122 clrjl %r1,%r0,.Lfound /* Jump away if miscompare is within
123 loaded bytes and below n bytes. */
124 j .Lend_equal /* Miscompare after n-bytes -> end equal. */
127 /* Difference or end of string. */
137 #endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */