yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame^] | 1 | /* Copy SRC to DEST returning the address of the terminating '\0' in DEST. |
| 2 | For SPARC v7. |
| 3 | Copyright (C) 1996, 1999, 2002, 2004 Free Software Foundation, Inc. |
| 4 | This file is part of the GNU C Library. |
| 5 | Contributed by Jakub Jelinek <jj@ultra.linux.cz>. |
| 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, write to the Free |
| 19 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 20 | 02111-1307 USA. */ |
| 21 | |
| 22 | /* Normally, this uses ((xword - 0x01010101) & 0x80808080) test |
| 23 | to find out if any byte in xword could be zero. This is fast, but |
| 24 | also gives false alarm for any byte in range 0x81-0xff. It does |
| 25 | not matter for correctness, as if this test tells us there could |
| 26 | be some zero byte, we check it byte by byte, but if bytes with |
| 27 | high bits set are common in the strings, then this will give poor |
| 28 | performance. You can #define EIGHTBIT_NOT_RARE and the algorithm |
| 29 | will use one tick slower, but more precise test |
| 30 | ((xword - 0x01010101) & (~xword) & 0x80808080), |
| 31 | which does not give any false alarms (but if some bits are set, |
| 32 | one cannot assume from it which bytes are zero and which are not). |
| 33 | It is yet to be measured, what is the correct default for glibc |
| 34 | in these days for an average user. |
| 35 | */ |
| 36 | |
| 37 | .text |
| 38 | .align 4 |
| 39 | 10: ldub [%o1], %o5 |
| 40 | stb %o5, [%o0] |
| 41 | cmp %o5, 0 |
| 42 | add %o0, 1, %o0 |
| 43 | be 1f |
| 44 | add %o1, 1, %o1 |
| 45 | andcc %o1, 3, %g0 |
| 46 | be 4f |
| 47 | or %o4, %lo(0x80808080), %o3 |
| 48 | ldub [%o1], %o5 |
| 49 | stb %o5, [%o0] |
| 50 | cmp %o5, 0 |
| 51 | add %o0, 1, %o0 |
| 52 | be 1f |
| 53 | add %o1, 1, %o1 |
| 54 | andcc %o1, 3, %g0 |
| 55 | be 5f |
| 56 | sethi %hi(0x01010101), %o4 |
| 57 | ldub [%o1], %o5 |
| 58 | stb %o5, [%o0] |
| 59 | cmp %o5, 0 |
| 60 | add %o0, 1, %o0 |
| 61 | be 1f |
| 62 | add %o1, 1, %o1 |
| 63 | b 6f |
| 64 | or %o4, %lo(0x01010101), %o2 |
| 65 | 1: retl |
| 66 | add %o0, -1, %o0 |
| 67 | |
| 68 | ENTRY(stpcpy) |
| 69 | andcc %o1, 3, %g0 |
| 70 | bne 10b |
| 71 | sethi %hi(0x80808080), %o4 |
| 72 | or %o4, %lo(0x80808080), %o3 |
| 73 | 4: sethi %hi(0x01010101), %o4 |
| 74 | 5: or %o4, %lo(0x01010101), %o2 |
| 75 | 6: andcc %o0, 3, %g0 |
| 76 | bne 16f |
| 77 | sub %g0, 4, %g1 |
| 78 | |
| 79 | 11: add %g1, 4, %g1 |
| 80 | ld [%o1 + %g1], %o5 |
| 81 | sub %o5, %o2, %o4 |
| 82 | #ifdef EIGHTBIT_NOT_RARE |
| 83 | andn %o4, %o5, %o4 |
| 84 | #endif |
| 85 | andcc %o4, %o3, %g0 |
| 86 | be,a 11b |
| 87 | st %o5, [%o0 + %g1] |
| 88 | |
| 89 | /* Check every byte. */ |
| 90 | srl %o5, 24, %g5 |
| 91 | andcc %g5, 0xff, %g0 |
| 92 | be 14f |
| 93 | srl %o5, 16, %g5 |
| 94 | andcc %g5, 0xff, %g0 |
| 95 | be 13f |
| 96 | srl %o5, 8, %g5 |
| 97 | andcc %g5, 0xff, %g0 |
| 98 | be 12f |
| 99 | andcc %o5, 0xff, %g0 |
| 100 | bne 11b |
| 101 | st %o5, [%o0 + %g1] |
| 102 | add %o0, %g1, %o0 |
| 103 | retl |
| 104 | add %o0, 3, %o0 |
| 105 | 12: srl %o5, 16, %o5 |
| 106 | sth %o5, [%o0 + %g1] |
| 107 | add %g1, 2, %g1 |
| 108 | stb %g0, [%o0 + %g1] |
| 109 | retl |
| 110 | add %o0, %g1, %o0 |
| 111 | 13: srl %o5, 16, %o5 |
| 112 | sth %o5, [%o0 + %g1] |
| 113 | add %g1, 1, %g1 |
| 114 | retl |
| 115 | add %o0, %g1, %o0 |
| 116 | 14: stb %g0, [%o0 + %g1] |
| 117 | retl |
| 118 | add %o0, %g1, %o0 |
| 119 | |
| 120 | 15: srl %o5, 24, %o4 |
| 121 | srl %o5, 16, %g1 |
| 122 | stb %o4, [%o0] |
| 123 | srl %o5, 8, %g4 |
| 124 | stb %g1, [%o0 + 1] |
| 125 | stb %g4, [%o0 + 2] |
| 126 | stb %o5, [%o0 + 3] |
| 127 | add %o0, 4, %o0 |
| 128 | 16: ld [%o1], %o5 |
| 129 | sub %o5, %o2, %o4 |
| 130 | andcc %o4, %o3, %g0 |
| 131 | be 15b |
| 132 | add %o1, 4, %o1 |
| 133 | |
| 134 | /* Check every byte. */ |
| 135 | srl %o5, 24, %g5 |
| 136 | andcc %g5, 0xff, %g4 |
| 137 | be 19f |
| 138 | stb %g4, [%o0] |
| 139 | srl %o5, 16, %g5 |
| 140 | andcc %g5, 0xff, %g4 |
| 141 | be 18f |
| 142 | stb %g4, [%o0 + 1] |
| 143 | srl %o5, 8, %g5 |
| 144 | andcc %g5, 0xff, %g4 |
| 145 | be 17f |
| 146 | stb %g4, [%o0 + 2] |
| 147 | andcc %o5, 0xff, %g4 |
| 148 | stb %g4, [%o0 + 3] |
| 149 | bne 16b |
| 150 | add %o0, 4, %o0 |
| 151 | retl |
| 152 | sub %o0, 1, %o0 |
| 153 | 17: retl |
| 154 | add %o0, 2, %o0 |
| 155 | 18: retl |
| 156 | add %o0, 1, %o0 |
| 157 | 19: retl |
| 158 | nop |
| 159 | END(stpcpy) |
| 160 | |
| 161 | libc_hidden_def(stpcpy) |