1/* Vector Optimized 32/64 bit S/390 version of wmemcmp. 2 Copyright (C) 2015-2022 Free Software Foundation, Inc. 3 This file is part of the GNU C Library. 4 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. 9 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. 14 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/>. */ 18 19#include <ifunc-wmemcmp.h> 20#if HAVE_WMEMCMP_Z13 21 22# include "sysdep.h" 23# include "asm-syntax.h" 24 25 .text 26 27/* int wmemcmp (const wchar_t *s1, const wchar_t *s2, size_t n) 28 Compare at most n characters of two wchar_t-arrays. 29 30 Register usage: 31 -r0=tmp 32 -r1=number of blocks 33 -r2=s1 34 -r3=s2 35 -r4=n 36 -r5=current_len 37 -v16=part of s1 38 -v17=part of s2 39 -v18=index of unequal 40*/ 41ENTRY(WMEMCMP_Z13) 42 .machine "z13" 43 .machinemode "zarch_nohighgprs" 44 45# if !defined __s390x__ 46 llgfr %r4,%r4 47# endif /* !defined __s390x__ */ 48 clgije %r4,0,.Lend_equal /* Nothing to do if n == 0. */ 49 50 /* Check range of maxlen and convert to byte-count. */ 51# ifdef __s390x__ 52 tmhh %r4,49152 /* Test bit 0 or 1 of maxlen. */ 53 lghi %r1,-4 /* Max byte-count is 18446744073709551612. */ 54# else 55 tmlh %r4,49152 /* Test bit 0 or 1 of maxlen. */ 56 llilf %r1,4294967292 /* Max byte-count is 4294967292. */ 57# endif /* !__s390x__ */ 58 sllg %r4,%r4,2 /* Convert character-count to byte-count. */ 59 locgrne %r4,%r1 /* Use max byte-count, if bit 0/1 was one. */ 60 61 lghi %r5,0 /* current_len = 0. */ 62 63 clgijh %r4,16,.Lgt16 64 65.Lremaining: 66 aghi %r4,-1 /* vstl needs highest index. */ 67 vll %v16,%r4,0(%r2) 68 vll %v17,%r4,0(%r3) 69 vfenef %v18,%v16,%v17 /* Compare not equal. */ 70 vlgvb %r1,%v18,7 /* Load unequal index or 16 if not found. */ 71 clrj %r1,%r4,12,.Lfound2 /* r1 <= r4 -> unequal within loaded 72 bytes. */ 73 74.Lend_equal: 75 lghi %r2,0 76 br %r14 77 78.Lfound: 79 /* vfenezf found an unequal element or zero. 80 This instruction compares unsigned words, but wchar_t is signed. 81 Thus we have to compare the found element again. */ 82 vlgvb %r1,%v18,7 /* Extract not equal byte-index. */ 83.Lfound2: 84 srl %r1,2 /* And convert it to character-index. */ 85 vlgvf %r0,%v16,0(%r1) /* Load character-values. */ 86 vlgvf %r1,%v17,0(%r1) 87 cr %r0,%r1 88 je .Lend_equal 89 lghi %r2,1 90 lghi %r1,-1 91 locgrl %r2,%r1 92 br %r14 93 94.Lgt16: 95 clgijh %r4,64,.Lpreloop64 96 97.Lpreloop16: 98 srlg %r1,%r4,4 /* Split into 16byte blocks */ 99.Lloop16: 100 vl %v16,0(%r5,%r2) 101 vl %v17,0(%r5,%r3) 102 aghi %r5,16 103 vfenefs %v18,%v16,%v17 /* Compare not equal. */ 104 jno .Lfound 105 brctg %r1,.Lloop16 /* Loop until all blocks are processed. */ 106 107 llgfr %r4,%r4 108 nilf %r4,15 /* Get remaining bytes */ 109 locgre %r2,%r4 110 ber %r14 111 la %r2,0(%r5,%r2) 112 la %r3,0(%r5,%r3) 113 j .Lremaining 114 115.Lpreloop64: 116 srlg %r1,%r4,6 /* Split into 64byte blocks */ 117.Lloop64: 118 vl %v16,0(%r5,%r2) 119 vl %v17,0(%r5,%r3) 120 vfenefs %v18,%v16,%v17 /* Compare not equal. */ 121 jno .Lfound 122 123 vl %v16,16(%r5,%r2) 124 vl %v17,16(%r5,%r3) 125 vfenefs %v18,%v16,%v17 126 jno .Lfound 127 128 vl %v16,32(%r5,%r2) 129 vl %v17,32(%r5,%r3) 130 vfenefs %v18,%v16,%v17 131 jno .Lfound 132 133 vl %v16,48(%r5,%r2) 134 vl %v17,48(%r5,%r3) 135 aghi %r5,64 136 vfenefs %v18,%v16,%v17 137 jno .Lfound 138 139 brctg %r1,.Lloop64 /* Loop until all blocks are processed. */ 140 141 llgfr %r4,%r4 142 nilf %r4,63 /* Get remaining bytes */ 143 locgre %r2,%r4 144 ber %r14 145 clgijh %r4,16,.Lpreloop16 146 la %r2,0(%r5,%r2) 147 la %r3,0(%r5,%r3) 148 j .Lremaining 149END(WMEMCMP_Z13) 150 151# if ! HAVE_WMEMCMP_IFUNC 152strong_alias (WMEMCMP_Z13, __wmemcmp) 153weak_alias (__wmemcmp, wmemcmp) 154# endif 155#endif 156