1 /* Vector optimized 32/64 bit S/390 version of memchr.
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 /* void *memchr (const void *s, int c, size_t n)
27 Scans memory for character c
28 and returns pointer to first c.
44 .machinemode "zarch_nohighgprs"
46 # if !defined __s390x__
48 # endif /* !defined __s390x__ */
50 clgije %r4,0,.Lnf_end /* If len == 0 then exit. */
52 vlbb %v16,0(%r2),6 /* Load s until next 4k-byte boundary. */
53 lcbb %r0,0(%r2),6 /* Get bytes to 4k-byte boundary or 16. */
54 llgfr %r0,%r0 /* Convert 32bit to 64bit. */
56 vlvgb %v18,%r3,0 /* Generate vector which elements are all c.
57 if c > 255, c will be truncated. */
59 lghi %r5,16 /* current_len = 16. */
61 clgrjhe %r0,%r4,.Llastcmp /* If (bytes to boundary) >= n,
64 vfeebs %v17,%v16,%v18 /* Find c. */
65 vlgvb %r1,%v17,7 /* Load byte index of c. */
66 clgrjl %r1,%r0,.Lfound2 /* Found c is within loaded bytes. */
68 /* Align s to 16 byte. */
69 risbgn %r1,%r2,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15. */
70 slr %r5,%r1 /* Compute bytes to 16bytes boundary. */
72 lgr %r0,%r5 /* If %r5 + 64 < n? -> loop64. */
74 clgrjl %r0,%r4,.Lloop64
78 clgrjhe %r5,%r4,.Llastcmp /* Do last compare if curr-len >= n. */
79 vfeebs %v17,%v16,%v18 /* Find c. */
80 jl .Lfound /* Jump away if c was found. */
84 clgrjhe %r5,%r4,.Llastcmp
90 clgrjhe %r5,%r4,.Llastcmp
98 /* Use comparision result only if located within first n characters.
101 (current_len - n): [0...16[
102 first ignored match index: vr-width - (current_len - n) ]0...16]
104 vfeebs %v17,%v16,%v18 /* Find c. */
105 slgrk %r4,%r5,%r4 /* %r5 = current_len - n. */
106 lghi %r0,16 /* Register width = 16. */
107 vlgvb %r1,%v17,7 /* Extract found index or 16 if all equal. */
108 slr %r0,%r4 /* %r0 = first ignored match index. */
109 clrjl %r1,%r0,.Lfound2 /* Go away if miscompare is below n bytes. */
110 /* c not found within n-bytes. */
112 lghi %r2,0 /* Return null. */
124 vlgvb %r1,%v17,7 /* Load byte index of c. */
126 slgfi %r5,16 /* current_len -=16 */
127 algr %r5,%r1 /* Zero byte index is added to current len. */
128 la %r2,0(%r5,%r2) /* Return pointer to c. */
134 vfeebs %v17,%v16,%v18 /* Find c. */
135 jl .Lfound0 /* Jump away if c was found. */
137 vfeebs %v17,%v16,%v18
140 vfeebs %v17,%v16,%v18
143 vfeebs %v17,%v16,%v18
147 lgr %r0,%r5 /* If %r5 + 64 < n? -> loop64. */
149 clgrjl %r0,%r4,.Lloop64
154 # define memchr __memchr_c
155 # undef libc_hidden_builtin_def
156 # define libc_hidden_builtin_def(name) strong_alias(__memchr_c, __GI_memchr)
157 #endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */