1/* memchr (str, ch, n) -- Return pointer to first occurrence of CH in STR less 2 than N. 3 For SPARC v7. 4 Copyright (C) 1996-2021 Free Software Foundation, Inc. 5 This file is part of the GNU C Library. 6 7 The GNU C Library is free software; you can redistribute it and/or 8 modify it under the terms of the GNU Lesser General Public 9 License as published by the Free Software Foundation; either 10 version 2.1 of the License, or (at your option) any later version. 11 12 The GNU C Library is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 Lesser General Public License for more details. 16 17 You should have received a copy of the GNU Lesser General Public 18 License along with the GNU C Library; if not, see 19 <https://www.gnu.org/licenses/>. */ 20 21#include <sysdep.h> 22 23 .text 24 .align 4 25ENTRY(__memchr) 26 andcc %o1, 0xff, %o1 27 sll %o1, 8, %g6 28 andcc %o0, 3, %g0 29 or %o1, %g6, %g6 30 sll %g6, 16, %o3 31 be 10f 32 or %o3, %g6, %g2 33 cmp %o2, 0 34 be 9f 35 sethi %hi(0x80808080), %o4 36 ldub [%o0], %g4 37 cmp %g4, %o1 38 be 1f 39 add %o0, 1, %o0 40 subcc %o2, 1, %o2 41 be 9f 42 andcc %o0, 3, %g0 43 be 4f 44 or %o4, %lo(0x80808080), %o3 45 ldub [%o0], %g4 46 cmp %g4, %o1 47 be 1f 48 add %o0, 1, %o0 49 subcc %o2, 1, %o2 50 be 9f 51 andcc %o0, 3, %g0 52 be 5f 53 sethi %hi(0x01010101), %o5 54 ldub [%o0], %g4 55 cmp %g4, %o1 56 be 1f 57 add %o0, 1, %o0 58 subcc %o2, 1, %o2 59 bne,a 7f 60 and %o2, 3, %g1 61 retl 62 clr %o0 631: retl 64 sub %o0, 1, %o0 6510: sethi %hi(0x80808080), %o4 66 or %o4, %lo(0x80808080), %o3 674: sethi %hi(0x01010101), %o5 685: and %o2, 3, %g1 697: andcc %o2, 0xfffffffc, %o2 70 be 0f 71 or %o5, %lo(0x01010101), %g6 72 ld [%o0], %g4 736: xor %g4, %g2, %g5 74 add %o0, 4, %o0 75 sub %g5, %g6, %g5 76 andcc %g5, %o3, %g0 77 bne 8f 78 subcc %o2, 4, %o2 79 bne,a 6b 80 ld [%o0], %g4 810: cmp %g1, 0 821: be 9f 83 add %o0, 4, %o0 84 ldub [%o0 - 4], %g4 85 cmp %g4, %o1 86 be 4f 87 cmp %g1, 1 88 be 9f 89 ldub [%o0 - 3], %g4 90 cmp %g4, %o1 91 be 3f 92 cmp %g1, 2 93 be 9f 94 ldub [%o0 - 2], %g4 95 cmp %g4, %o1 96 be 2f 97 nop 989: retl 99 clr %o0 100 101 /* Check every byte. */ 1028: srl %g4, 24, %g5 103 and %g5, 0xff, %g5 104 cmp %g5, %o1 105 be 4f 106 srl %g4, 16, %g5 107 and %g5, 0xff, %g5 108 cmp %g5, %o1 109 be 3f 110 srl %g4, 8, %g5 111 and %g5, 0xff, %g5 112 cmp %g5, %o1 113 be 2f 114 and %g4, 0xff, %g5 115 cmp %g5, %o1 116 be 1f 117 cmp %o2, 0 118 bne,a 6b 119 ld [%o0], %g4 120 b 1b 121 cmp %g1, 0 1221: retl 123 sub %o0, 1, %o0 1242: retl 125 sub %o0, 2, %o0 1263: retl 127 sub %o0, 3, %o0 1284: retl 129 sub %o0, 4, %o0 130END(__memchr) 131 132weak_alias (__memchr, memchr) 133libc_hidden_builtin_def (memchr) 134