1 /* Vector Optimized 32/64 bit S/390 version of wmemcmp.
2 Copyright (C) 2015-2024 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-wmemcmp.h>
23 # include "asm-syntax.h"
27 /* int wmemcmp (const wchar_t *s1, const wchar_t *s2, size_t n)
28 Compare at most n characters of two wchar_t-arrays.
43 .machinemode "zarch_nohighgprs"
45 # if !defined __s390x__
47 # endif /* !defined __s390x__ */
48 clgije %r4,0,.Lend_equal /* Nothing to do if n == 0. */
50 /* Check range of maxlen 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 lghi %r5,0 /* current_len = 0. */
66 aghi %r4,-1 /* vstl needs highest index. */
69 vfenef %v18,%v16,%v17 /* Compare not equal. */
70 vlgvb %r1,%v18,7 /* Load unequal index or 16 if not found. */
71 clrj %r1,%r4,12,.Lfound2 /* r1 <= r4 -> unequal within loaded
79 /* vfenezf found an unequal element or zero.
80 This instruction compares unsigned words, but wchar_t is signed.
81 Thus we have to compare the found element again. */
82 vlgvb %r1,%v18,7 /* Extract not equal byte-index. */
84 srl %r1,2 /* And convert it to character-index. */
85 vlgvf %r0,%v16,0(%r1) /* Load character-values. */
95 clgijh %r4,64,.Lpreloop64
98 srlg %r1,%r4,4 /* Split into 16byte blocks */
103 vfenefs %v18,%v16,%v17 /* Compare not equal. */
105 brctg %r1,.Lloop16 /* Loop until all blocks are processed. */
108 nilf %r4,15 /* Get remaining bytes */
116 srlg %r1,%r4,6 /* Split into 64byte blocks */
120 vfenefs %v18,%v16,%v17 /* Compare not equal. */
125 vfenefs %v18,%v16,%v17
130 vfenefs %v18,%v16,%v17
136 vfenefs %v18,%v16,%v17
139 brctg %r1,.Lloop64 /* Loop until all blocks are processed. */
142 nilf %r4,63 /* Get remaining bytes */
145 clgijh %r4,16,.Lpreloop16
151 # if ! HAVE_WMEMCMP_IFUNC
152 strong_alias (WMEMCMP_Z13, __wmemcmp)
153 weak_alias (__wmemcmp, wmemcmp)