Update copyright dates with scripts/update-copyrights.
[glibc.git] / sysdeps / s390 / multiarch / wmemcmp-vx.S
blob40e71e5a65ecd0980e2664cf428dcb5722886e5c
1 /* Vector Optimized 32/64 bit S/390 version of wmemcmp.
2    Copyright (C) 2015-2017 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 /* int wmemcmp (const wchar_t *s1, const wchar_t *s2, size_t n)
27    Compare at most n characters of two wchar_t-arrays.
29    Register usage:
30    -r0=tmp
31    -r1=number of blocks
32    -r2=s1
33    -r3=s2
34    -r4=n
35    -r5=current_len
36    -v16=part of s1
37    -v17=part of s2
38    -v18=index of unequal
40 ENTRY(__wmemcmp_vx)
41         .machine "z13"
42         .machinemode "zarch_nohighgprs"
44 # if !defined __s390x__
45         llgfr   %r4,%r4
46 # endif /* !defined __s390x__ */
47         clgije  %r4,0,.Lend_equal /* Nothing to do if n == 0.  */
49         /* Check range of maxlen and convert to byte-count.  */
50 # ifdef __s390x__
51         tmhh    %r4,49152       /* Test bit 0 or 1 of maxlen.  */
52         lghi    %r1,-4          /* Max byte-count is 18446744073709551612.  */
53 # else
54         tmlh    %r4,49152       /* Test bit 0 or 1 of maxlen.  */
55         llilf   %r1,4294967292  /* Max byte-count is 4294967292.  */
56 # endif /* !__s390x__ */
57         sllg    %r4,%r4,2       /* Convert character-count to byte-count.  */
58         locgrne %r4,%r1         /* Use max byte-count, if bit 0/1 was one.  */
60         lghi    %r5,0           /* current_len = 0.  */
62         clgijh  %r4,16,.Lgt16
64 .Lremaining:
65         aghi    %r4,-1          /* vstl needs highest index.  */
66         vll     %v16,%r4,0(%r2)
67         vll     %v17,%r4,0(%r3)
68         vfenef  %v18,%v16,%v17  /* Compare not equal.  */
69         vlgvb   %r1,%v18,7      /* Load unequal index or 16 if not found.  */
70         clrj    %r1,%r4,12,.Lfound2 /* r1 <= r4 -> unequal within loaded
71                                         bytes.  */
73 .Lend_equal:
74         lghi    %r2,0
75         br      %r14
77 .Lfound:
78         /* vfenezf found an unequal element or zero.
79            This instruction compares unsigned words, but wchar_t is signed.
80            Thus we have to compare the found element again.  */
81         vlgvb   %r1,%v18,7      /* Extract not equal byte-index.  */
82 .Lfound2:
83         srl     %r1,2           /* And convert it to character-index.  */
84         vlgvf   %r0,%v16,0(%r1) /* Load character-values.  */
85         vlgvf   %r1,%v17,0(%r1)
86         cr      %r0,%r1
87         je      .Lend_equal
88         lghi    %r2,1
89         lghi    %r1,-1
90         locgrl  %r2,%r1
91         br      %r14
93 .Lgt16:
94         clgijh  %r4,64,.Lpreloop64
96 .Lpreloop16:
97         srlg    %r1,%r4,4       /* Split into 16byte blocks */
98 .Lloop16:
99         vl      %v16,0(%r5,%r2)
100         vl      %v17,0(%r5,%r3)
101         aghi    %r5,16
102         vfenefs %v18,%v16,%v17  /* Compare not equal.  */
103         jno     .Lfound
104         brctg   %r1,.Lloop16    /* Loop until all blocks are processed.  */
106         llgfr   %r4,%r4
107         nilf    %r4,15          /* Get remaining bytes */
108         locgre  %r2,%r4
109         ber     %r14
110         la      %r2,0(%r5,%r2)
111         la      %r3,0(%r5,%r3)
112         j       .Lremaining
114 .Lpreloop64:
115         srlg    %r1,%r4,6       /* Split into 64byte blocks */
116 .Lloop64:
117         vl      %v16,0(%r5,%r2)
118         vl      %v17,0(%r5,%r3)
119         vfenefs %v18,%v16,%v17  /* Compare not equal.  */
120         jno     .Lfound
122         vl      %v16,16(%r5,%r2)
123         vl      %v17,16(%r5,%r3)
124         vfenefs %v18,%v16,%v17
125         jno     .Lfound
127         vl      %v16,32(%r5,%r2)
128         vl      %v17,32(%r5,%r3)
129         vfenefs %v18,%v16,%v17
130         jno     .Lfound
132         vl      %v16,48(%r5,%r2)
133         vl      %v17,48(%r5,%r3)
134         aghi    %r5,64
135         vfenefs %v18,%v16,%v17
136         jno     .Lfound
138         brctg   %r1,.Lloop64    /* Loop until all blocks are processed.  */
140         llgfr   %r4,%r4
141         nilf    %r4,63          /* Get remaining bytes */
142         locgre  %r2,%r4
143         ber     %r14
144         clgijh  %r4,16,.Lpreloop16
145         la      %r2,0(%r5,%r2)
146         la      %r3,0(%r5,%r3)
147         j       .Lremaining
148 END(__wmemcmp_vx)
149 #endif /* HAVE_S390_VX_ASM_SUPPORT && IS_IN (libc) */