[444] | 1 | /* Copyright (c) 2015-2016, ARM Limited |
---|
| 2 | All rights reserved. |
---|
| 3 | |
---|
| 4 | Redistribution and use in source and binary forms, with or without |
---|
| 5 | modification, are permitted provided that the following conditions are met: |
---|
| 6 | * Redistributions of source code must retain the above copyright |
---|
| 7 | notice, this list of conditions and the following disclaimer. |
---|
| 8 | * Redistributions in binary form must reproduce the above copyright |
---|
| 9 | notice, this list of conditions and the following disclaimer in the |
---|
| 10 | documentation and/or other materials provided with the distribution. |
---|
| 11 | * Neither the name of the company nor the names of its contributors |
---|
| 12 | may be used to endorse or promote products derived from this |
---|
| 13 | software without specific prior written permission. |
---|
| 14 | |
---|
| 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
---|
| 16 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
---|
| 17 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
---|
| 18 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
---|
| 19 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
---|
| 20 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
---|
| 21 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
---|
| 22 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
---|
| 23 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
---|
| 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
---|
| 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ |
---|
| 26 | |
---|
| 27 | /* Assumptions: |
---|
| 28 | * |
---|
| 29 | * ARMv8-a, AArch64, unaligned accesses |
---|
| 30 | * |
---|
| 31 | */ |
---|
| 32 | |
---|
| 33 | #if (defined (__OPTIMIZE_SIZE__) || defined (PREFER_SIZE_OVER_SPEED)) |
---|
| 34 | /* See rawmemchr-stub.c. */ |
---|
| 35 | #else |
---|
| 36 | |
---|
| 37 | #define L(l) .L ## l |
---|
| 38 | |
---|
| 39 | .macro def_fn f p2align=0 |
---|
| 40 | .text |
---|
| 41 | .p2align \p2align |
---|
| 42 | .global \f |
---|
| 43 | .type \f, %function |
---|
| 44 | \f: |
---|
| 45 | .endm |
---|
| 46 | |
---|
| 47 | /* Special case rawmemchr (s, 0) as strlen, otherwise tailcall memchr. |
---|
| 48 | Call strlen without setting up a full frame - it preserves x14/x15. |
---|
| 49 | */ |
---|
| 50 | |
---|
| 51 | def_fn rawmemchr p2align=5 |
---|
| 52 | .cfi_startproc |
---|
| 53 | cbz w1, L(do_strlen) |
---|
| 54 | mov x2, -1 |
---|
| 55 | b memchr |
---|
| 56 | |
---|
| 57 | L(do_strlen): |
---|
| 58 | mov x15, x30 |
---|
| 59 | .cfi_return_column x15 |
---|
| 60 | mov x14, x0 |
---|
| 61 | bl strlen |
---|
| 62 | add x0, x14, x0 |
---|
| 63 | ret x15 |
---|
| 64 | .cfi_endproc |
---|
| 65 | |
---|
| 66 | .size rawmemchr, . - rawmemchr |
---|
| 67 | #endif |
---|
| 68 | |
---|