1 /* Vector Optimized 32/64 bit S/390 version of wmemcmp.
2 Copyright (C) 2015-2016 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 wmemcmp (const wchar_t *s1, const wchar_t *s2, size_t n)
27 Compare at most n characters of two wchar_t-arrays.
42 .machinemode "zarch_nohighgprs"
44 # if !defined __s390x__
46 # endif /* !defined __s390x__ */
47 clgije %r4,0,.Lend_equal /* Nothing to do if n == 0. */
49 /* Check range of maxlen and convert to byte-count. */
51 tmhh %r4,49152 /* Test bit 0 or 1 of maxlen. */
52 lghi %r1,-4 /* Max byte-count is 18446744073709551612. */
54 tmlh %r4,49152 /* Test bit 0 or 1 of maxlen. */
55 llilf %r1,4294967292 /* Max byte-count is 4294967292. */
56 # endif /* !__s390x__ */
57 sllg %r4,%r4,2 /* Convert character-count to byte-count. */
58 locgrne %r4,%r1 /* Use max byte-count, if bit 0/1 was one. */
60 lghi %r5,0 /* current_len = 0. */
65 aghi %r4,-1 /* vstl needs highest index. */
68 vfenef %v18,%v16,%v17 /* Compare not equal. */
69 vlgvb %r1,%v18,7 /* Load unequal index or 16 if not found. */
70 clrj %r1,%r4,12,.Lfound2 /* r1 <= r4 -> unequal within loaded
78 /* vfenezf found an unequal element or zero.
79 This instruction compares unsigned words, but wchar_t is signed.
80 Thus we have to compare the found element again. */
81 vlgvb %r1,%v18,7 /* Extract not equal byte-index. */
83 srl %r1,2 /* And convert it to character-index. */
84 vlgvf %r0,%v16,0(%r1) /* Load character-values. */
94 clgijh %r4,64,.Lpreloop64
97 srlg %r1,%r4,4 /* Split into 16byte blocks */
102 vfenefs %v18,%v16,%v17 /* Compare not equal. */
104 brctg %r1,.Lloop16 /* Loop until all blocks are processed. */
107 nilf %r4,15 /* Get remaining bytes */
115 srlg %r1,%r4,6 /* Split into 64byte blocks */
119 vfenefs %v18,%v16,%v17 /* Compare not equal. */
124 vfenefs %v18,%v16,%v17
129 vfenefs %v18,%v16,%v17
135 vfenefs %v18,%v16,%v17
138 brctg %r1,.Lloop64 /* Loop until all blocks are processed. */
141 nilf %r4,63 /* Get remaining bytes */
144 clgijh %r4,16,.Lpreloop16
149 #endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */