S390: Optimize strcat and wcscat.
[glibc.git] / sysdeps / s390 / multiarch / strcat-vx.S
blobba553bec2654ded58a02d8d2f3f44431c47b3a97
1 /* Vector optimized 32/64 bit S/390 version of strcat.
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)
21 # include "sysdep.h"
22 # include "asm-syntax.h"
24         .text
26 /* char * strcat (const char *dest, const char *src)
27    Concatenate two strings.
29    Register usage:
30    -r0=saved dest pointer for return
31    -r1=tmp
32    -r2=dest
33    -r3=src
34    -r4=tmp
35    -r5=current_len
36    -v16=part of src
37    -v17=index of zero
38    -v18=part of src
40 ENTRY(__strcat_vx)
41         .machine "z13"
42         .machinemode "zarch_nohighgprs"
44         lgr     %r0,%r2         /* Save destination pointer for return.  */
46         /* STRLEN
47            r1 = loaded bytes (tmp)
48            r4 = zero byte index (tmp)
49            r2 = dst
50         */
51         vlbb    %v16,0(%r2),6   /* Load s until next 4k-byte boundary.  */
52         lcbb    %r1,0(%r2),6    /* Get bytes to 4k-byte boundary or 16.  */
54         vfenezb %v16,%v16,%v16  /* Find element not equal with zero search.  */
55         vlgvb   %r5,%v16,7      /* Load zero index or 16 if not found.  */
56         clrjl   %r5,%r1,.Llen_end /* Found zero within loaded bytes, end.  */
58         /* Align s to 16 byte.  */
59         risbgn  %r1,%r2,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15.  */
60         lghi    %r5,16          /* current_len = 16.  */
61         slr     %r5,%r1         /* Compute bytes to 16bytes boundary.  */
63         /* Find zero in 16byte aligned loop.  */
64 .Llen_loop:
65         vl      %v16,0(%r5,%r2) /* Load s.  */
66         vfenezbs %v16,%v16,%v16 /* Find element not equal with zero search.  */
67         je      .Llen_found     /* Jump away if zero was found.  */
68         vl      %v16,16(%r5,%r2)
69         vfenezbs %v16,%v16,%v16
70         je      .Llen_found16
71         vl      %v16,32(%r5,%r2)
72         vfenezbs %v16,%v16,%v16
73         je      .Llen_found32
74         vl      %v16,48(%r5,%r2)
75         vfenezbs %v16,%v16,%v16
76         je      .Llen_found48
78         aghi    %r5,64
79         j       .Llen_loop      /* No zero -> loop.  */
81 .Llen_found48:
82         aghi    %r5,16
83 .Llen_found32:
84         aghi    %r5,16
85 .Llen_found16:
86         aghi    %r5,16
87 .Llen_found:
88         vlgvb   %r4,%v16,7      /* Load byte index of zero.  */
89         algr    %r5,%r4
91 .Llen_end:
92         /* STRCPY
93            %r1 = loaded bytes (tmp)
94            %r4 = zero byte index (tmp)
95            %r3 = curr src pointer
96            %r2 = curr dst pointer
97          */
98         la      %r2,0(%r5,%r2)  /* strcpy at end of dst-string.   */
100         vlbb    %v16,0(%r3),6   /* Load s until next 4k-byte boundary.  */
101         lcbb    %r1,0(%r3),6    /* Get bytes to 4k-byte boundary or 16.  */
103         vfenezb %v17,%v16,%v16  /* Find element not equal with zero search.  */
104         vlgvb   %r5,%v17,7      /* Load zero index or 16 if not found.  */
105         clrjl   %r5,%r1,.Lcpy_found_align /* If found zero within loaded bytes,
106                                              copy bytes before and return.  */
108         /* Align s to 16 byte.  */
109         risbgn  %r4,%r3,60,128+63,0 /* %r3 = bits 60-63 of %r2 'and' 15.  */
110         lghi    %r5,15          /* current_len = 15.  */
111         slr     %r5,%r4         /* Compute highest index to 16byte boundary.  */
113         vstl    %v16,%r5,0(%r2) /* Copy loaded characters - no zero.  */
114         ahi     %r5,1           /* Start loop at next character.  */
116         /* Find zero in 16byte aligned loop.  */
117 .Lcpy_loop:
118         vl      %v16,0(%r5,%r3) /* Load s.  */
119         vfenezbs %v17,%v16,%v16 /* Find element not equal with zero search.  */
120         je      .Lcpy_found_v16_0 /* Jump away if zero was found.  */
121         vl      %v18,16(%r5,%r3)/* Load next part of s.  */
122         vst     %v16,0(%r5,%r2) /* Store previous part without zero to dst.  */
123         vfenezbs %v17,%v18,%v18
124         je      .Lcpy_found_v18_16
125         vl      %v16,32(%r5,%r3)
126         vst     %v18,16(%r5,%r2)
127         vfenezbs %v17,%v16,%v16
128         je      .Lcpy_found_v16_32
129         vl      %v18,48(%r5,%r3)
130         vst     %v16,32(%r5,%r2)
131         vfenezbs %v17,%v18,%v18
132         je      .Lcpy_found_v18_48
133         vst     %v18,48(%r5,%r2)
135         aghi    %r5,64
136         j       .Lcpy_loop      /* No zero -> loop.  */
138 .Lcpy_found_v16_32:
139         aghi    %r5,32
140 .Lcpy_found_v16_0:
141         la      %r4,0(%r5,%r2)
142         vlgvb   %r1,%v17,7      /* Load byte index of zero.  */
143         vstl    %v16,%r1,0(%r4) /* Copy characters including zero.  */
144         lgr     %r2,%r0         /* Load saved dest-ptr.  */
145         br      %r14
147 .Lcpy_found_v18_48:
148         aghi    %r5,32
149 .Lcpy_found_v18_16:
150         la      %r4,16(%r5,%r2)
151         vlgvb   %r1,%v17,7      /* Load byte index of zero.  */
152         vstl    %v18,%r1,0(%r4) /* Copy characters including zero.  */
153         lgr     %r2,%r0         /* Load saved dest-ptr.  */
154         br      %r14
156 .Lcpy_found_align:
157         vstl    %v16,%r5,0(%r2) /* Copy characters including zero.  */
158         lgr     %r2,%r0         /* Load saved dest-ptr.  */
159         br      %r14
160 END(__strcat_vx)
161 #endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */