|
Packit |
6c4009 |
/* Vector optimized 32/64 bit S/390 version of memrchr.
|
|
Packit |
6c4009 |
Copyright (C) 2015-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit Service |
c2cea5 |
#include <ifunc-memrchr.h>
|
|
Packit Service |
c2cea5 |
|
|
Packit Service |
c2cea5 |
#if HAVE_MEMRCHR_Z13
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# include "sysdep.h"
|
|
Packit |
6c4009 |
# include "asm-syntax.h"
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.text
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* void *memrchr (const void *s, int c, size_t n)
|
|
Packit |
6c4009 |
Scans memory for character c backwards
|
|
Packit |
6c4009 |
and returns pointer to first c.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
Register usage:
|
|
Packit |
6c4009 |
-r0=tmp
|
|
Packit |
6c4009 |
-r1=tmp
|
|
Packit |
6c4009 |
-r2=s
|
|
Packit |
6c4009 |
-r3=c
|
|
Packit |
6c4009 |
-r4=n
|
|
Packit |
6c4009 |
-r5=s in loop
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
-v16=part of s
|
|
Packit |
6c4009 |
-v17=index of found c
|
|
Packit |
6c4009 |
-v18=c replicated
|
|
Packit |
6c4009 |
-v20=permute pattern
|
|
Packit |
6c4009 |
*/
|
|
Packit Service |
c2cea5 |
ENTRY(MEMRCHR_Z13)
|
|
Packit |
6c4009 |
.machine "z13"
|
|
Packit |
6c4009 |
.machinemode "zarch_nohighgprs"
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# if !defined __s390x__
|
|
Packit |
6c4009 |
llgfr %r4,%r4
|
|
Packit |
6c4009 |
# endif /* !defined __s390x__ */
|
|
Packit |
6c4009 |
clgije %r4,0,.Lnot_found
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
vlvgb %v18,%r3,0 /* Generate vector which elements are all c.
|
|
Packit |
6c4009 |
If c > 255, c will be truncated. */
|
|
Packit |
6c4009 |
vrepb %v18,%v18,0
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
llcr %r3,%r3 /* char c_char = (char) c. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* check byte n - 1. */
|
|
Packit |
6c4009 |
llc %r0,-1(%r4,%r2)
|
|
Packit |
6c4009 |
slgfi %r4,1
|
|
Packit |
6c4009 |
clrje %r0,%r3,.Lfound_end
|
|
Packit |
6c4009 |
jh .Lnot_found /* Return NULL if n is now 0. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
larl %r1,.Lpermute_mask /* Load permute mask. */
|
|
Packit |
6c4009 |
vl %v20,0(%r1)
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* check byte n - 2. */
|
|
Packit |
6c4009 |
llc %r0,-1(%r4,%r2)
|
|
Packit |
6c4009 |
slgfi %r4,1
|
|
Packit |
6c4009 |
clrje %r0,%r3,.Lfound_end
|
|
Packit |
6c4009 |
jh .Lnot_found /* Return NULL if n is now 0. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
clgijhe %r4,64,.Lloop64 /* If n >= 64 -> loop64. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.Llt64:
|
|
Packit |
6c4009 |
/* Process n < 64 bytes. */
|
|
Packit |
6c4009 |
clgijl %r4,16,.Llt16 /* Jump away if n < 16. */
|
|
Packit |
6c4009 |
aghi %r4,-16
|
|
Packit |
6c4009 |
vl %v16,0(%r4,%r2)
|
|
Packit |
6c4009 |
vfeebs %v17,%v16,%v18
|
|
Packit |
6c4009 |
jno .Lfound0
|
|
Packit |
6c4009 |
clgijl %r4,16,.Llt16
|
|
Packit |
6c4009 |
aghi %r4,-16
|
|
Packit |
6c4009 |
vl %v16,0(%r4,%r2)
|
|
Packit |
6c4009 |
vfeebs %v17,%v16,%v18
|
|
Packit |
6c4009 |
jno .Lfound0
|
|
Packit |
6c4009 |
clgijl %r4,16,.Llt16
|
|
Packit |
6c4009 |
aghi %r4,-16
|
|
Packit |
6c4009 |
vl %v16,0(%r4,%r2)
|
|
Packit |
6c4009 |
vfeebs %v17,%v16,%v18
|
|
Packit |
6c4009 |
jno .Lfound0
|
|
Packit |
6c4009 |
.Llt16:
|
|
Packit |
6c4009 |
clgfi %r4,0 /* if remaining bytes == 0, return NULL. */
|
|
Packit |
6c4009 |
locghie %r2,0
|
|
Packit |
6c4009 |
ber %r14
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
aghi %r4,-1 /* vll needs highest index. */
|
|
Packit |
6c4009 |
vll %v16,%r4,0(%r2) /* Load remaining bytes. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Right-shift of v16 to mask bytes after highest index. */
|
|
Packit |
6c4009 |
lhi %r0,15
|
|
Packit |
6c4009 |
slr %r0,%r4 /* Compute byte count for vector shift right. */
|
|
Packit |
6c4009 |
sll %r0,3 /* Convert to bit count. */
|
|
Packit |
6c4009 |
vlvgb %v17,%r0,7
|
|
Packit |
6c4009 |
vsrlb %v16,%v16,%v17 /* Vector shift right by byte by number of bytes
|
|
Packit |
6c4009 |
specified in bits 1-4 of byte 7 in v17. */
|
|
Packit |
6c4009 |
j .Lfound_permute
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.Lfound48:
|
|
Packit |
6c4009 |
aghi %r4,16
|
|
Packit |
6c4009 |
.Lfound32:
|
|
Packit |
6c4009 |
aghi %r4,16
|
|
Packit |
6c4009 |
.Lfound16:
|
|
Packit |
6c4009 |
aghi %r4,16
|
|
Packit |
6c4009 |
.Lfound0:
|
|
Packit |
6c4009 |
la %r2,0(%r4,%r2) /* Set pointer to start of v16. */
|
|
Packit |
6c4009 |
lghi %r4,15 /* Set highest index in v16 to last index. */
|
|
Packit |
6c4009 |
.Lfound_permute:
|
|
Packit |
6c4009 |
/* Search for a c in v16 in reversed byte order. v16 contains %r4 + 1
|
|
Packit |
6c4009 |
bytes. If v16 was not fully loaded, the bytes are already
|
|
Packit |
6c4009 |
right shifted, so that the bytes in v16 can simply be reversed. */
|
|
Packit |
6c4009 |
vperm %v16,%v16,%v16,%v20 /* Permute v16 to reversed order. */
|
|
Packit |
6c4009 |
vfeeb %v16,%v16,%v18 /* Find c in reversed v16. */
|
|
Packit |
6c4009 |
vlgvb %r1,%v16,7 /* Index of c or 16 if not found. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Return NULL if there is no c in loaded bytes. */
|
|
Packit |
6c4009 |
clrjh %r1,%r4,.Lnot_found
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
slgr %r4,%r1
|
|
Packit |
6c4009 |
.Lfound_end:
|
|
Packit |
6c4009 |
la %r2,0(%r4,%r2) /* Return pointer to c. */
|
|
Packit |
6c4009 |
br %r14
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.Lnot_found:
|
|
Packit |
6c4009 |
lghi %r2,0
|
|
Packit |
6c4009 |
br %r14
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.Lpermute_mask:
|
|
Packit |
6c4009 |
.byte 0x0F,0x0E,0x0D,0x0C,0x0B,0x0A,0x09,0x08
|
|
Packit |
6c4009 |
.byte 0x07,0x06,0x05,0x04,0x03,0x02,0x01,0x00
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
.Lloop64:
|
|
Packit |
6c4009 |
aghi %r4,-64
|
|
Packit |
6c4009 |
vl %v16,48(%r4,%r2) /* Load 16bytes of memory area. */
|
|
Packit |
6c4009 |
vfeebs %v17,%v16,%v18 /* Find c. */
|
|
Packit |
6c4009 |
jno .Lfound48 /* Jump away if c was found. */
|
|
Packit |
6c4009 |
vl %v16,32(%r4,%r2)
|
|
Packit |
6c4009 |
vfeebs %v17,%v16,%v18
|
|
Packit |
6c4009 |
jno .Lfound32
|
|
Packit |
6c4009 |
vl %v16,16(%r4,%r2)
|
|
Packit |
6c4009 |
vfeebs %v17,%v16,%v18
|
|
Packit |
6c4009 |
jno .Lfound16
|
|
Packit |
6c4009 |
vl %v16,0(%r4,%r2)
|
|
Packit |
6c4009 |
vfeebs %v17,%v16,%v18
|
|
Packit |
6c4009 |
jno .Lfound0
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
clgijhe %r4,64,.Lloop64 /* If n >= 64 -> loop64. */
|
|
Packit |
6c4009 |
j .Llt64
|
|
Packit Service |
c2cea5 |
END(MEMRCHR_Z13)
|
|
Packit Service |
c2cea5 |
|
|
Packit Service |
c2cea5 |
# if ! HAVE_MEMRCHR_IFUNC
|
|
Packit Service |
c2cea5 |
strong_alias (MEMRCHR_Z13, __memrchr)
|
|
Packit Service |
c2cea5 |
weak_alias (__memrchr, memrchr)
|
|
Packit Service |
c2cea5 |
# endif
|
|
Packit Service |
c2cea5 |
|
|
Packit Service |
c2cea5 |
#endif /* HAVE_MEMRCHR_Z13 */
|