1 /* Vector Optimized 32/64 bit S/390 version of wmemset.
2 Copyright (C) 2015-2021 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-wmemset.h>
23 # include "asm-syntax.h"
27 /* wchar_t *wmemset(wchar_t *dest, wchar_t wc, size_t n)
28 Fill an array of wide-characters with a constant wide character
34 -r2=dest or current-pointer
39 -v17,v18,v19=copy of v16 for vstm
40 -v31=saved dest for return
44 .machinemode "zarch_nohighgprs"
46 # if !defined __s390x__
48 # endif /* !defined __s390x__ */
50 vlvgg %v31,%r2,0 /* Save destination pointer for return. */
53 vlvgf %v16,%r3,0 /* Generate vector with wchar_t wc. */
56 /* Check range of maxlen and convert to byte-count. */
58 tmhh %r4,49152 /* Test bit 0 or 1 of maxlen. */
59 lghi %r5,-4 /* Max byte-count is 18446744073709551612. */
61 tmlh %r4,49152 /* Test bit 0 or 1 of maxlen. */
62 llilf %r5,4294967292 /* Max byte-count is 4294967292. */
63 # endif /* !__s390x__ */
64 sllg %r4,%r4,2 /* Convert character-count to byte-count. */
65 locgrne %r4,%r5 /* Use max byte-count, if bit 0/1 was one. */
67 /* Align dest to 16 byte. */
68 risbg %r0,%r2,60,128+63,0 /* Test if s is aligned and
69 %r3 = bits 60-63 'and' 15. */
70 je .Lpreloop /* If s is aligned, loop aligned. */
71 tmll %r2,3 /* Test if s is 4-byte aligned? */
72 jne .Lfallback /* And use common-code variant if not. */
74 slr %r1,%r0 /* Compute byte count to load (16-x). */
76 locgrh %r1,%r4 /* min (byte count, n) */
77 aghik %r5,%r1,-1 /* vstl needs highest index. */
78 vstl %v16,%r5,0(%r2) /* Store remaining bytes. */
79 clgrje %r1,%r4,.Lend /* Return if n bytes where set. */
80 slgr %r4,%r1 /* Compute remaining byte count. */
84 /* Now we are 16-byte aligned. */
85 clgijl %r4,17,.Lremaining
86 srlg %r1,%r4,8 /* Split into 256byte blocks */
87 clgije %r1,0,.Lpreloop64
94 vstm %v16,%v19,64(%r2)
95 vstm %v16,%v19,128(%r2)
96 vstm %v16,%v19,192(%r2)
98 brctg %r1,.Lloop256 /* Loop until all blocks are processed. */
101 nilf %r4,255 /* Get remaining bytes */
102 je .Lend /* Skip store remaining bytes if zero. */
105 clgijl %r4,17,.Lremaining
106 clgijl %r4,33,.Lpreloop16
107 srlg %r1,%r4,5 /* Split into 32byte blocks */
113 brctg %r1,.Lloop32 /* Loop until all blocks are processed. */
116 nilf %r4,31 /* Get remaining bytes */
117 je .Lend /* Skip store remaining bytes if zero. */
120 clgijl %r4,17,.Lremaining
121 srlg %r1,%r4,4 /* Split into 16byte blocks */
126 brctg %r1,.Lloop16 /* Loop until all blocks are processed. */
129 nilf %r4,15 /* Get remaining bytes */
130 je .Lend /* Skip store remaining bytes if zero. */
133 aghi %r4,-1 /* vstl needs highest index. */
137 vlgvg %r2,%v31,0 /* Load saved dest for return value. */
140 srlg %r4,%r4,2 /* Convert byte-count to character-count. */
144 # if ! HAVE_WMEMSET_IFUNC
145 strong_alias (WMEMSET_Z13, __wmemset)
146 weak_alias (__wmemset, wmemset)
149 # if defined HAVE_S390_MIN_Z13_ZARCH_ASM_SUPPORT \
150 && defined SHARED && IS_IN (libc)
151 strong_alias (WMEMSET_Z13, __GI___wmemset)
152 weak_alias (WMEMSET_Z13, __GI_wmemset)