]>
Commit | Line | Data |
---|---|---|
cee82e70 | 1 | /* Vector optimized 32/64 bit S/390 version of strncmp. |
f7a9f785 | 2 | Copyright (C) 2015-2016 Free Software Foundation, Inc. |
cee82e70 SL |
3 | This file is part of the GNU C Library. |
4 | ||
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. | |
9 | ||
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. | |
14 | ||
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/>. */ | |
18 | ||
19 | #if defined HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) | |
20 | ||
21 | # include "sysdep.h" | |
22 | # include "asm-syntax.h" | |
23 | ||
24 | .text | |
25 | ||
26 | /* int strncmp (const char *s1, const char *s2, size_t n) | |
27 | Compare at most n characters of two strings. | |
28 | ||
29 | Register usage: | |
30 | -r0=tmp | |
31 | -r1=tmp | |
32 | -r2=s1 | |
33 | -r3=s2 | |
34 | -r4=n | |
35 | -r5=current_len | |
36 | -v16=part of s1 | |
37 | -v17=part of s2 | |
38 | -v18=index of unequal | |
39 | */ | |
40 | ENTRY(__strncmp_vx) | |
41 | .machine "z13" | |
42 | .machinemode "zarch_nohighgprs" | |
43 | ||
44 | # if !defined __s390x__ | |
45 | llgfr %r4,%r4 | |
46 | # endif /* !defined __s390x__ */ | |
47 | ||
48 | clgije %r4,0,.Lend_equal /* Nothing to do if n == 0, */ | |
49 | lghi %r5,0 /* current_len = 0. */ | |
50 | ||
51 | .Lloop: | |
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. */ | |
61 | jno .Lfound | |
62 | ||
63 | vlbb %v16,0(%r5,%r2),6 | |
64 | vlbb %v17,0(%r5,%r3),6 | |
65 | lcbb %r0,0(%r5,%r2),6 | |
66 | jo .Llt16_1 | |
67 | lcbb %r1,0(%r5,%r3),6 | |
68 | jo .Llt16_2 | |
69 | aghi %r5,16 | |
70 | clgrjhe %r5,%r4,.Llastcmp | |
71 | vfenezbs %v18,%v16,%v17 | |
72 | jno .Lfound | |
73 | ||
74 | vlbb %v16,0(%r5,%r2),6 | |
75 | vlbb %v17,0(%r5,%r3),6 | |
76 | lcbb %r0,0(%r5,%r2),6 | |
77 | jo .Llt16_1 | |
78 | lcbb %r1,0(%r5,%r3),6 | |
79 | jo .Llt16_2 | |
80 | aghi %r5,16 | |
81 | clgrjhe %r5,%r4,.Llastcmp | |
82 | vfenezbs %v18,%v16,%v17 | |
83 | jno .Lfound | |
84 | ||
85 | vlbb %v16,0(%r5,%r2),6 | |
86 | vlbb %v17,0(%r5,%r3),6 | |
87 | lcbb %r0,0(%r5,%r2),6 | |
88 | jo .Llt16_1 | |
89 | lcbb %r1,0(%r5,%r3),6 | |
90 | jo .Llt16_2 | |
91 | aghi %r5,16 | |
92 | clgrjhe %r5,%r4,.Llastcmp | |
93 | vfenezbs %v18,%v16,%v17 | |
94 | jno .Lfound | |
95 | j .Lloop | |
96 | ||
97 | .Llt16_1: | |
98 | lcbb %r1,0(%r5,%r3),6 /* Get loaded byte count ofs2. */ | |
99 | .Llt16_2: | |
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) */ | |
108 | j .Lloop | |
109 | ||
110 | .Llastcmp: | |
111 | /* Use comparision result only if located within first n characters. | |
112 | %r0: loaded byte count in vreg; | |
113 | %r5: current_len; | |
114 | %r4: n; | |
115 | (current_len - n): [0...16[ | |
116 | First ignored match index: loaded bytes - (current_len-n): ]0...16] | |
117 | */ | |
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. */ | |
125 | ||
126 | .Lfound: | |
127 | /* Difference or end of string. */ | |
128 | je .Lend_equal | |
129 | lghi %r2,1 | |
130 | lghi %r1,-1 | |
131 | locgrl %r2,%r1 | |
132 | br %r14 | |
133 | .Lend_equal: | |
134 | lghi %r2,0 | |
135 | br %r14 | |
136 | END(__strncmp_vx) | |
137 | #endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */ |