1 /* Vector optimized 32/64 bit S/390 version of wcsnlen.
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 /* size_t wcsnlen (const wchar_t *s, size_t maxlen)
27 Returns the number of characters in s or at most maxlen.
32 -r3=maxlen (number of characters to be read)
34 -r5=current_len and return_value
40 .machinemode "zarch_nohighgprs"
42 # if !defined __s390x__
44 # endif /* !defined __s390x__ */
46 clgfi %r3,0 /* if maxlen == 0, return 0. */
50 vlbb %v16,0(%r2),6 /* Load s until next 4k-byte boundary. */
51 lcbb %r1,0(%r2),6 /* Get bytes to 4k-byte boundary or 16. */
52 llgfr %r1,%r1 /* Convert 32bit to 64bit. */
54 tmll %r2,3 /* Test if s is 4-byte aligned? */
55 jne .Lfallback /* And use common-code variant if not. */
57 /* Check range of maxlen and convert to byte-count. */
59 tmhh %r3,49152 /* Test bit 0 or 1 of maxlen. */
60 lghi %r4,-4 /* Max byte-count is 18446744073709551612. */
62 tmlh %r3,49152 /* Test bit 0 or 1 of maxlen. */
63 llilf %r4,4294967292 /* Max byte-count is 4294967292. */
64 # endif /* !__s390x__ */
65 sllg %r3,%r3,2 /* Convert character-count to byte-count. */
66 locgrne %r3,%r4 /* Use max byte-count, if bit 0/1 was one. */
68 vfenezf %v16,%v16,%v16 /* Find element not equal with zero search. */
70 locgrh %r1,%r3 /* loaded_byte_count
71 = min (loaded_byte_count, maxlen) */
73 vlgvb %r5,%v16,7 /* Load zero index or 16 if not found. */
74 clrjl %r5,%r1,.Lend /* Found zero within loaded bytes -> return. */
76 clgr %r1,%r3 /* If loaded_byte_count == maxlen -> end. */
80 /* Align s to 16 byte. */
81 risbgn %r4,%r2,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15. */
82 lghi %r5,16 /* current_len = 16. */
83 slr %r5,%r4 /* Compute bytes to 16bytes boundary. */
85 lgr %r1,%r5 /* If %r5 + 64 < maxlen? -> loop64. */
87 clgrjl %r1,%r3,.Lloop64
89 /* Find zero in max 64byte with aligned s. */
91 vl %v16,0(%r5,%r2) /* Load s. */
92 vfenezfs %v16,%v16,%v16 /* Find element not equal with zero search. */
93 je .Lfound /* Jump away if zero was found. */
95 clgrjhe %r5,%r3,.Lfound /* If current_len >= maxlen -> end. */
97 vfenezfs %v16,%v16,%v16
100 clgrjhe %r5,%r3,.Lfound
102 vfenezfs %v16,%v16,%v16
105 clgrjhe %r5,%r3,.Lfound
107 vfenezfs %v16,%v16,%v16
117 vlgvb %r4,%v16,7 /* Load byte index of zero or 16 if no zero. */
121 locgrh %r5,%r3 /* Return min (current_len, maxlen). */
123 srlg %r2,%r5,2 /* Convert byte-count to character-count. */
126 /* Find zero in 16byte aligned loop. */
128 vl %v16,0(%r5,%r2) /* Load s. */
129 vfenezfs %v16,%v16,%v16 /* Find element not equal with zero search. */
130 je .Lfound /* Jump away if zero was found. */
132 vfenezfs %v16,%v16,%v16
135 vfenezfs %v16,%v16,%v16
138 vfenezfs %v16,%v16,%v16
142 lgr %r1,%r5 /* If %r5 + 64 < maxlen? -> loop64. */
144 clgrjl %r1,%r3,.Lloop64
151 #endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */