1/* Copyright (C) 2000-2021 Free Software Foundation, Inc. 2 This file is part of the GNU C Library. 3 4 The GNU C Library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Lesser General Public 6 License as published by the Free Software Foundation; either 7 version 2.1 of the License, or (at your option) any later version. 8 9 The GNU C Library is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 14 You should have received a copy of the GNU Lesser General Public 15 License along with the GNU C Library. If not, see 16 <https://www.gnu.org/licenses/>. */ 17 18/* Return pointer to first occurrence of CH in STR. */ 19 20#include <sysdep.h> 21 22 .arch ev6 23 .set noreorder 24 .set noat 25 26ENTRY(__rawmemchr) 27#ifdef PROF 28 ldgp gp, 0(pv) 29 lda AT, _mcount 30 jsr AT, (AT), _mcount 31 .prologue 1 32#else 33 .prologue 0 34#endif 35 36 ldq_u t0, 0(a0) # L : load first quadword Latency=3 37 and a1, 0xff, t3 # E : 00000000000000ch 38 insbl a1, 1, t5 # U : 000000000000ch00 39 insbl a1, 7, a2 # U : ch00000000000000 40 41 insbl t3, 6, a3 # U : 00ch000000000000 42 or t5, t3, a1 # E : 000000000000chch 43 andnot a0, 7, v0 # E : align our loop pointer 44 lda t4, -1 # E : build garbage mask 45 46 mskqh t4, a0, t4 # U : only want relevant part of first quad 47 or a2, a3, a2 # E : chch000000000000 48 inswl a1, 2, t5 # E : 00000000chch0000 49 inswl a1, 4, a3 # E : 0000chch00000000 50 51 or a1, a2, a1 # E : chch00000000chch 52 or a3, t5, t5 # E : 0000chchchch0000 53 cmpbge zero, t4, t4 # E : bits set iff byte is garbage 54 nop # E : 55 56 /* This quad is _very_ serialized. Lots of stalling happens */ 57 or t5, a1, a1 # E : chchchchchchchch 58 xor t0, a1, t1 # E : make bytes == c zero 59 cmpbge zero, t1, t0 # E : bits set iff byte == c 60 andnot t0, t4, t0 # E : clear garbage bits 61 62 cttz t0, a2 # U0 : speculative (in case we get a match) 63 nop # E : 64 nop # E : 65 bne t0, $found # U : 66 67 /* 68 * Yuk. This loop is going to stall like crazy waiting for the 69 * data to be loaded. Not much can be done about it unless it's 70 * unrolled multiple times, which is generally unsafe. 71 */ 72$loop: 73 ldq t0, 8(v0) # L : Latency=3 74 addq v0, 8, v0 # E : 75 xor t0, a1, t1 # E : 76 cmpbge zero, t1, t0 # E : bits set iff byte == c 77 78 cttz t0, a2 # U0 : speculative (in case we get a match) 79 nop # E : 80 nop # E : 81 beq t0, $loop # U : 82 83$found: 84 negq t0, t1 # E : clear all but least set bit 85 and t0, t1, t0 # E : 86 addq v0, a2, v0 # E : Add in the bit number from above 87 ret # L0 : 88 89 END(__rawmemchr) 90 91libc_hidden_def (__rawmemchr) 92weak_alias (__rawmemchr, rawmemchr) 93