1 /* Vector Optimized 32/64 bit S/390 version of wmemset.
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 /* wchar_t *wmemset(wchar_t *dest, wchar_t wc, size_t n)
27 Fill an array of wide-characters with a constant wide character
33 -r2=dest or current-pointer
38 -v17,v18,v19=copy of v16 for vstm
39 -v31=saved dest for return
43 .machinemode "zarch_nohighgprs"
45 # if !defined __s390x__
47 # endif /* !defined __s390x__ */
49 vlvgg %v31,%r2,0 /* Save destination pointer for return. */
52 vlvgf %v16,%r3,0 /* Generate vector with wchar_t wc. */
55 /* Check range of maxlen and convert to byte-count. */
57 tmhh %r4,49152 /* Test bit 0 or 1 of maxlen. */
58 lghi %r5,-4 /* Max byte-count is 18446744073709551612. */
60 tmlh %r4,49152 /* Test bit 0 or 1 of maxlen. */
61 llilf %r5,4294967292 /* Max byte-count is 4294967292. */
62 # endif /* !__s390x__ */
63 sllg %r4,%r4,2 /* Convert character-count to byte-count. */
64 locgrne %r4,%r5 /* Use max byte-count, if bit 0/1 was one. */
66 /* Align dest to 16 byte. */
67 risbg %r0,%r2,60,128+63,0 /* Test if s is aligned and
68 %r3 = bits 60-63 'and' 15. */
69 je .Lpreloop /* If s is aligned, loop aligned. */
70 tmll %r2,3 /* Test if s is 4-byte aligned? */
71 jne .Lfallback /* And use common-code variant if not. */
73 slr %r1,%r0 /* Compute byte count to load (16-x). */
75 locgrh %r1,%r4 /* min (byte count, n) */
76 aghik %r5,%r1,-1 /* vstl needs highest index. */
77 vstl %v16,%r5,0(%r2) /* Store remaining bytes. */
78 clgrje %r1,%r4,.Lend /* Return if n bytes where set. */
79 slgr %r4,%r1 /* Compute remaining byte count. */
83 /* Now we are 16-byte aligned. */
84 clgijl %r4,17,.Lremaining
85 srlg %r1,%r4,8 /* Split into 256byte blocks */
86 clgije %r1,0,.Lpreloop64
93 vstm %v16,%v19,64(%r2)
94 vstm %v16,%v19,128(%r2)
95 vstm %v16,%v19,192(%r2)
97 brctg %r1,.Lloop256 /* Loop until all blocks are processed. */
100 nilf %r4,255 /* Get remaining bytes */
101 je .Lend /* Skip store remaining bytes if zero. */
104 clgijl %r4,17,.Lremaining
105 clgijl %r4,33,.Lpreloop16
106 srlg %r1,%r4,5 /* Split into 32byte blocks */
112 brctg %r1,.Lloop32 /* Loop until all blocks are processed. */
115 nilf %r4,31 /* Get remaining bytes */
116 je .Lend /* Skip store remaining bytes if zero. */
119 clgijl %r4,17,.Lremaining
120 srlg %r1,%r4,4 /* Split into 16byte blocks */
125 brctg %r1,.Lloop16 /* Loop until all blocks are processed. */
128 nilf %r4,15 /* Get remaining bytes */
129 je .Lend /* Skip store remaining bytes if zero. */
132 aghi %r4,-1 /* vstl needs highest index. */
136 vlgvg %r2,%v31,0 /* Load saved dest for return value. */
139 srlg %r4,%r4,2 /* Convert byte-count to character-count. */
142 #endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */