| 1 | /* Optimized strlen implementation using LoongArch LASX instructions. |
| 2 | Copyright (C) 2023-2024 Free Software Foundation, Inc. |
| 3 | |
| 4 | This file is part of the GNU C Library. |
| 5 | |
| 6 | The GNU C Library is free software; you can redistribute it and/or |
| 7 | modify it under the terms of the GNU Lesser General Public |
| 8 | License as published by the Free Software Foundation; either |
| 9 | version 2.1 of the License, or (at your option) any later version. |
| 10 | |
| 11 | The GNU C Library is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | Lesser General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU Lesser General Public |
| 17 | License along with the GNU C Library. If not, see |
| 18 | <https://www.gnu.org/licenses/>. */ |
| 19 | |
| 20 | #include <sysdep.h> |
| 21 | #include <sys/regdef.h> |
| 22 | #include <sys/asm.h> |
| 23 | |
| 24 | #if IS_IN (libc) && !defined __loongarch_soft_float |
| 25 | |
| 26 | # define STRLEN __strlen_lasx |
| 27 | |
| 28 | LEAF(STRLEN, 6) |
| 29 | move a1, a0 |
| 30 | bstrins.d a0, zero, 4, 0 |
| 31 | li.d t1, -1 |
| 32 | xvld xr0, a0, 0 |
| 33 | |
| 34 | xvmsknz.b xr0, xr0 |
| 35 | xvpickve.w xr1, xr0, 4 |
| 36 | vilvl.h vr0, vr1, vr0 |
| 37 | movfr2gr.s t0, fa0 # sign extend |
| 38 | |
| 39 | sra.w t0, t0, a1 |
| 40 | beq t0, t1, L(loop) |
| 41 | cto.w a0, t0 |
| 42 | jr ra |
| 43 | |
| 44 | L(loop): |
| 45 | xvld xr0, a0, 32 |
| 46 | addi.d a0, a0, 32 |
| 47 | xvsetanyeqz.b fcc0, xr0 |
| 48 | bceqz fcc0, L(loop) |
| 49 | |
| 50 | |
| 51 | xvmsknz.b xr0, xr0 |
| 52 | sub.d a0, a0, a1 |
| 53 | xvpickve.w xr1, xr0, 4 |
| 54 | vilvl.h vr0, vr1, vr0 |
| 55 | |
| 56 | movfr2gr.s t0, fa0 |
| 57 | cto.w t0, t0 |
| 58 | add.d a0, a0, t0 |
| 59 | jr ra |
| 60 | END(STRLEN) |
| 61 | |
| 62 | libc_hidden_builtin_def (STRLEN) |
| 63 | #endif |
| 64 | |