Merge "string/memory functions: avoid qemu bugs/performance issues." into main am: c20bf013a1
am: 453fbd0e9a
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2806377 Change-Id: I8e081bfef46d4af869b22c423515bff9107011ba Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
7c32826486
36 changed files with 1073 additions and 96 deletions
126
libc/Android.bp
126
libc/Android.bp
|
@ -664,8 +664,9 @@ cc_library_static {
|
|||
},
|
||||
arm64: {
|
||||
srcs: [
|
||||
"upstream-openbsd/lib/libc/string/stpncpy.c",
|
||||
"upstream-openbsd/lib/libc/string/memrchr.c",
|
||||
"upstream-openbsd/lib/libc/string/strcat.c",
|
||||
"upstream-openbsd/lib/libc/string/stpncpy.c",
|
||||
"upstream-openbsd/lib/libc/string/strlcat.c",
|
||||
"upstream-openbsd/lib/libc/string/strlcpy.c",
|
||||
"upstream-openbsd/lib/libc/string/strncat.c",
|
||||
|
@ -681,7 +682,9 @@ cc_library_static {
|
|||
],
|
||||
},
|
||||
x86: {
|
||||
// This space intentionally left blank.
|
||||
srcs: [
|
||||
// x86 has custom implementations of all of these.
|
||||
],
|
||||
},
|
||||
x86_64: {
|
||||
srcs: [
|
||||
|
@ -849,29 +852,6 @@ cc_library_static {
|
|||
"arch-arm/bionic/syscall.S",
|
||||
"arch-arm/bionic/vfork.S",
|
||||
|
||||
"bionic/strchr.cpp",
|
||||
"bionic/strchrnul.cpp",
|
||||
"bionic/strnlen.c",
|
||||
"bionic/strrchr.cpp",
|
||||
|
||||
"arch-arm/generic/bionic/memcmp.S",
|
||||
"arch-arm/generic/bionic/memmove.S",
|
||||
"arch-arm/generic/bionic/memset.S",
|
||||
"arch-arm/generic/bionic/stpcpy.c",
|
||||
"arch-arm/generic/bionic/strcat.c",
|
||||
"arch-arm/generic/bionic/strcmp.S",
|
||||
"arch-arm/generic/bionic/strcpy.S",
|
||||
"arch-arm/generic/bionic/strlen.c",
|
||||
|
||||
"arch-arm/cortex-a15/bionic/memcpy.S",
|
||||
"arch-arm/cortex-a15/bionic/memmove.S",
|
||||
"arch-arm/cortex-a15/bionic/memset.S",
|
||||
"arch-arm/cortex-a15/bionic/stpcpy.S",
|
||||
"arch-arm/cortex-a15/bionic/strcat.S",
|
||||
"arch-arm/cortex-a15/bionic/strcmp.S",
|
||||
"arch-arm/cortex-a15/bionic/strcpy.S",
|
||||
"arch-arm/cortex-a15/bionic/strlen.S",
|
||||
|
||||
"arch-arm/cortex-a7/bionic/memcpy.S",
|
||||
"arch-arm/cortex-a7/bionic/memset.S",
|
||||
|
||||
|
@ -882,14 +862,37 @@ cc_library_static {
|
|||
"arch-arm/cortex-a9/bionic/strcpy.S",
|
||||
"arch-arm/cortex-a9/bionic/strlen.S",
|
||||
|
||||
"arch-arm/krait/bionic/memcpy.S",
|
||||
"arch-arm/krait/bionic/memset.S",
|
||||
"arch-arm/cortex-a15/bionic/memcpy.S",
|
||||
"arch-arm/cortex-a15/bionic/memmove.S",
|
||||
"arch-arm/cortex-a15/bionic/memset.S",
|
||||
"arch-arm/cortex-a15/bionic/stpcpy.S",
|
||||
"arch-arm/cortex-a15/bionic/strcat.S",
|
||||
"arch-arm/cortex-a15/bionic/strcmp.S",
|
||||
"arch-arm/cortex-a15/bionic/strcpy.S",
|
||||
"arch-arm/cortex-a15/bionic/strlen.S",
|
||||
|
||||
"arch-arm/cortex-a53/bionic/memcpy.S",
|
||||
|
||||
"arch-arm/cortex-a55/bionic/memcpy.S",
|
||||
|
||||
"arch-arm/generic/bionic/memcmp.S",
|
||||
"arch-arm/generic/bionic/memmove.S",
|
||||
"arch-arm/generic/bionic/memset.S",
|
||||
"arch-arm/generic/bionic/stpcpy.c",
|
||||
"arch-arm/generic/bionic/strcat.c",
|
||||
"arch-arm/generic/bionic/strcmp.S",
|
||||
"arch-arm/generic/bionic/strcpy.S",
|
||||
"arch-arm/generic/bionic/strlen.c",
|
||||
|
||||
"arch-arm/krait/bionic/memcpy.S",
|
||||
"arch-arm/krait/bionic/memset.S",
|
||||
|
||||
"arch-arm/kryo/bionic/memcpy.S",
|
||||
|
||||
"bionic/strchr.cpp",
|
||||
"bionic/strchrnul.cpp",
|
||||
"bionic/strnlen.cpp",
|
||||
"bionic/strrchr.cpp",
|
||||
],
|
||||
},
|
||||
arm64: {
|
||||
|
@ -910,27 +913,40 @@ cc_library_static {
|
|||
"arch-riscv64/bionic/syscall.S",
|
||||
"arch-riscv64/bionic/vfork.S",
|
||||
|
||||
// TODO(b/306514350): Remove this and replace with the optimized
|
||||
// version once the bug is resolved.
|
||||
"upstream-freebsd/lib/libc/string/memcmp.c",
|
||||
"arch-riscv64/string/memchr_v.S",
|
||||
"arch-riscv64/string/memcmp_v.S",
|
||||
"arch-riscv64/string/memcpy_v.S",
|
||||
"arch-riscv64/string/memmove_v.S",
|
||||
"arch-riscv64/string/memset_v.S",
|
||||
"arch-riscv64/string/stpcpy_v.S",
|
||||
"arch-riscv64/string/strcat_v.S",
|
||||
"arch-riscv64/string/strchr_v.S",
|
||||
"arch-riscv64/string/strcmp_v.S",
|
||||
"arch-riscv64/string/strcpy_v.S",
|
||||
"arch-riscv64/string/strlen_v.S",
|
||||
"arch-riscv64/string/strncat_v.S",
|
||||
"arch-riscv64/string/strncmp_v.S",
|
||||
"arch-riscv64/string/strncpy_v.S",
|
||||
"arch-riscv64/string/strnlen_v.S",
|
||||
|
||||
"arch-riscv64/string/memchr.c",
|
||||
"arch-riscv64/string/memcmp.c",
|
||||
"arch-riscv64/string/memcpy.c",
|
||||
"arch-riscv64/string/memmove.c",
|
||||
"arch-riscv64/string/memset.c",
|
||||
"arch-riscv64/string/stpcpy.c",
|
||||
"arch-riscv64/string/strcat.c",
|
||||
"arch-riscv64/string/strchr.c",
|
||||
"arch-riscv64/string/strcmp.c",
|
||||
"arch-riscv64/string/strcpy.c",
|
||||
"arch-riscv64/string/strlen.c",
|
||||
"arch-riscv64/string/strncat.c",
|
||||
"arch-riscv64/string/strncmp.c",
|
||||
"arch-riscv64/string/strncpy.c",
|
||||
"arch-riscv64/string/strnlen.c",
|
||||
|
||||
"bionic/strchrnul.cpp",
|
||||
"bionic/strrchr.cpp",
|
||||
|
||||
"arch-riscv64/string/memchr.S",
|
||||
"arch-riscv64/string/memcpy.S",
|
||||
"arch-riscv64/string/memmove.S",
|
||||
"arch-riscv64/string/memset.S",
|
||||
"arch-riscv64/string/stpcpy.S",
|
||||
"arch-riscv64/string/strcat.S",
|
||||
"arch-riscv64/string/strchr.S",
|
||||
"arch-riscv64/string/strcmp.S",
|
||||
"arch-riscv64/string/strcpy.S",
|
||||
"arch-riscv64/string/strlen.S",
|
||||
"arch-riscv64/string/strncat.S",
|
||||
"arch-riscv64/string/strncmp.S",
|
||||
"arch-riscv64/string/strncpy.S",
|
||||
"arch-riscv64/string/strnlen.S",
|
||||
],
|
||||
},
|
||||
|
||||
|
@ -945,8 +961,6 @@ cc_library_static {
|
|||
"arch-x86/bionic/vfork.S",
|
||||
"arch-x86/bionic/__x86.get_pc_thunk.S",
|
||||
|
||||
"bionic/strchrnul.cpp",
|
||||
|
||||
"arch-x86/generic/string/memcmp.S",
|
||||
"arch-x86/generic/string/strcmp.S",
|
||||
"arch-x86/generic/string/strncmp.S",
|
||||
|
@ -994,6 +1008,8 @@ cc_library_static {
|
|||
|
||||
"arch-x86/string/sse4-memcmp-slm.S",
|
||||
"arch-x86/string/sse4-wmemcmp-slm.S",
|
||||
|
||||
"bionic/strchrnul.cpp",
|
||||
],
|
||||
},
|
||||
x86_64: {
|
||||
|
@ -1005,11 +1021,6 @@ cc_library_static {
|
|||
"arch-x86_64/bionic/syscall.S",
|
||||
"arch-x86_64/bionic/vfork.S",
|
||||
|
||||
"bionic/strchr.cpp",
|
||||
"bionic/strchrnul.cpp",
|
||||
"bionic/strnlen.c",
|
||||
"bionic/strrchr.cpp",
|
||||
|
||||
"arch-x86_64/string/avx2-memset-kbl.S",
|
||||
"arch-x86_64/string/sse2-memmove-slm.S",
|
||||
"arch-x86_64/string/sse2-memset-slm.S",
|
||||
|
@ -1023,6 +1034,11 @@ cc_library_static {
|
|||
"arch-x86_64/string/sse4-memcmp-slm.S",
|
||||
"arch-x86_64/string/ssse3-strcmp-slm.S",
|
||||
"arch-x86_64/string/ssse3-strncmp-slm.S",
|
||||
|
||||
"bionic/strchr.cpp",
|
||||
"bionic/strchrnul.cpp",
|
||||
"bionic/strnlen.cpp",
|
||||
"bionic/strrchr.cpp",
|
||||
],
|
||||
},
|
||||
},
|
||||
|
@ -1540,6 +1556,9 @@ cc_library_static {
|
|||
arm64: {
|
||||
srcs: ["arch-arm64/static_function_dispatch.S"],
|
||||
},
|
||||
riscv64: {
|
||||
srcs: ["arch-riscv64/static_function_dispatch.S"]
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -1568,6 +1587,9 @@ cc_library_static {
|
|||
arm64: {
|
||||
srcs: ["arch-arm64/dynamic_function_dispatch.cpp"],
|
||||
},
|
||||
riscv64: {
|
||||
srcs: ["arch-riscv64/dynamic_function_dispatch.cpp"]
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
|
32
libc/NOTICE
32
libc/NOTICE
|
@ -2075,6 +2075,38 @@ SUCH DAMAGE.
|
|||
|
||||
-------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 1990, 1993
|
||||
The Regents of the University of California. All rights reserved.
|
||||
|
||||
This code is derived from software contributed to Berkeley by
|
||||
Mike Hibler and Chris Torek.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. Neither the name of the University nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGE.
|
||||
|
||||
-------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 1990, 1993
|
||||
The Regents of the University of California. All rights reserved.
|
||||
(c) UNIX System Laboratories, Inc.
|
||||
|
|
146
libc/arch-riscv64/dynamic_function_dispatch.cpp
Normal file
146
libc/arch-riscv64/dynamic_function_dispatch.cpp
Normal file
|
@ -0,0 +1,146 @@
|
|||
/*
|
||||
* Copyright (C) 2023 The Android Open Source Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stddef.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <private/bionic_ifuncs.h>
|
||||
|
||||
extern "C" {
|
||||
|
||||
static __always_inline int ifunc_faccessat(int dir_fd, const char* path, int mode) {
|
||||
register long a0 __asm__("a0") = dir_fd;
|
||||
register long a1 __asm__("a1") = reinterpret_cast<long>(path);
|
||||
register long a2 __asm__("a2") = mode;
|
||||
register long a7 __asm__("a7") = __NR_faccessat;
|
||||
__asm__("ecall" : "=r"(a0) : "r"(a0), "r"(a1), "r"(a2), "r"(a7) : "memory");
|
||||
return a0;
|
||||
}
|
||||
|
||||
static bool have_fast_v() {
|
||||
static bool result = []() {
|
||||
// We don't want to do a full "bogomips" test, so just check for the
|
||||
// presence of a file that would indicate that we're running in qemu.
|
||||
return ifunc_faccessat(AT_FDCWD, "/dev/hvc0", F_OK) == 0;
|
||||
}();
|
||||
return result;
|
||||
}
|
||||
|
||||
typedef void* memchr_func(const void*, int, size_t);
|
||||
DEFINE_IFUNC_FOR(memchr) {
|
||||
if (have_fast_v()) RETURN_FUNC(memchr_func, memchr_v);
|
||||
RETURN_FUNC(memchr_func, memchr_gc);
|
||||
}
|
||||
|
||||
typedef int memcmp_func(const void*, const void*, size_t);
|
||||
DEFINE_IFUNC_FOR(memcmp) {
|
||||
if (have_fast_v()) RETURN_FUNC(memcmp_func, memcmp_v);
|
||||
RETURN_FUNC(memcmp_func, memcmp_gc);
|
||||
}
|
||||
|
||||
typedef void* memcpy_func(void*, const void*, size_t);
|
||||
DEFINE_IFUNC_FOR(memcpy) {
|
||||
if (have_fast_v()) RETURN_FUNC(memcpy_func, memcpy_v);
|
||||
RETURN_FUNC(memcpy_func, memcpy_gc);
|
||||
}
|
||||
|
||||
typedef void* memmove_func(void*, const void*, size_t);
|
||||
DEFINE_IFUNC_FOR(memmove) {
|
||||
if (have_fast_v()) RETURN_FUNC(memmove_func, memmove_v);
|
||||
RETURN_FUNC(memmove_func, memmove_gc);
|
||||
}
|
||||
|
||||
typedef void* memset_func(void*, int, size_t);
|
||||
DEFINE_IFUNC_FOR(memset) {
|
||||
if (have_fast_v()) RETURN_FUNC(memset_func, memset_v);
|
||||
RETURN_FUNC(memset_func, memset_gc);
|
||||
}
|
||||
|
||||
typedef char* stpcpy_func(char*, const char*);
|
||||
DEFINE_IFUNC_FOR(stpcpy) {
|
||||
if (have_fast_v()) RETURN_FUNC(stpcpy_func, stpcpy_v);
|
||||
RETURN_FUNC(stpcpy_func, stpcpy_gc);
|
||||
}
|
||||
|
||||
typedef char* strcat_func(char*, const char*);
|
||||
DEFINE_IFUNC_FOR(strcat) {
|
||||
if (have_fast_v()) RETURN_FUNC(strcat_func, strcat_v);
|
||||
RETURN_FUNC(strcat_func, strcat_gc);
|
||||
}
|
||||
|
||||
typedef char* strchr_func(const char*, int);
|
||||
DEFINE_IFUNC_FOR(strchr) {
|
||||
if (have_fast_v()) RETURN_FUNC(strchr_func, strchr_v);
|
||||
RETURN_FUNC(strchr_func, strchr_gc);
|
||||
}
|
||||
|
||||
typedef int strcmp_func(const char*, const char*);
|
||||
DEFINE_IFUNC_FOR(strcmp) {
|
||||
if (have_fast_v()) RETURN_FUNC(strcmp_func, strcmp_v);
|
||||
RETURN_FUNC(strcmp_func, strcmp_gc);
|
||||
}
|
||||
|
||||
typedef char* strcpy_func(char*, const char*);
|
||||
DEFINE_IFUNC_FOR(strcpy) {
|
||||
if (have_fast_v()) RETURN_FUNC(strcpy_func, strcpy_v);
|
||||
RETURN_FUNC(strcpy_func, strcpy_gc);
|
||||
}
|
||||
|
||||
typedef size_t strlen_func(const char*);
|
||||
DEFINE_IFUNC_FOR(strlen) {
|
||||
if (have_fast_v()) RETURN_FUNC(strlen_func, strlen_v);
|
||||
RETURN_FUNC(strlen_func, strlen_gc);
|
||||
}
|
||||
|
||||
typedef char* strncat_func(char*, const char*, size_t);
|
||||
DEFINE_IFUNC_FOR(strncat) {
|
||||
if (have_fast_v()) RETURN_FUNC(strncat_func, strncat_v);
|
||||
RETURN_FUNC(strncat_func, strncat_gc);
|
||||
}
|
||||
|
||||
typedef int strncmp_func(const char*, const char*, size_t);
|
||||
DEFINE_IFUNC_FOR(strncmp) {
|
||||
if (have_fast_v()) RETURN_FUNC(strncmp_func, strncmp_v);
|
||||
RETURN_FUNC(strncmp_func, strncmp_gc);
|
||||
}
|
||||
|
||||
typedef char* strncpy_func(char*, const char*, size_t);
|
||||
DEFINE_IFUNC_FOR(strncpy) {
|
||||
if (have_fast_v()) RETURN_FUNC(strncpy_func, strncpy_v);
|
||||
RETURN_FUNC(strncpy_func, strncpy_gc);
|
||||
}
|
||||
|
||||
typedef size_t strnlen_func(const char*, size_t);
|
||||
DEFINE_IFUNC_FOR(strnlen) {
|
||||
if (have_fast_v()) RETURN_FUNC(strnlen_func, strnlen_v);
|
||||
RETURN_FUNC(strnlen_func, strnlen_gc);
|
||||
}
|
||||
|
||||
} // extern "C"
|
51
libc/arch-riscv64/static_function_dispatch.S
Normal file
51
libc/arch-riscv64/static_function_dispatch.S
Normal file
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright (C) 2023 The Android Open Source Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <private/bionic_asm.h>
|
||||
|
||||
#define FUNCTION_DELEGATE(name, impl) \
|
||||
ENTRY(name); \
|
||||
j impl; \
|
||||
END(name)
|
||||
|
||||
// TODO: switch to the V variants when qemu is fixed.
|
||||
FUNCTION_DELEGATE(memchr, memchr_gc)
|
||||
FUNCTION_DELEGATE(memcmp, memcmp_gc)
|
||||
FUNCTION_DELEGATE(memcpy, memcpy_gc)
|
||||
FUNCTION_DELEGATE(memmove, memmove_gc)
|
||||
FUNCTION_DELEGATE(memset, memset_gc)
|
||||
FUNCTION_DELEGATE(stpcpy, stpcpy_gc)
|
||||
FUNCTION_DELEGATE(strcat, strcat_gc)
|
||||
FUNCTION_DELEGATE(strchr, strchr_gc)
|
||||
FUNCTION_DELEGATE(strcmp, strcmp_gc)
|
||||
FUNCTION_DELEGATE(strcpy, strcpy_gc)
|
||||
FUNCTION_DELEGATE(strlen, strlen_gc)
|
||||
FUNCTION_DELEGATE(strncat, strncat_gc)
|
||||
FUNCTION_DELEGATE(strncmp, strncmp_gc)
|
||||
FUNCTION_DELEGATE(strncpy, strncpy_gc)
|
||||
FUNCTION_DELEGATE(strnlen, strnlen_gc)
|
122
libc/arch-riscv64/string/bcopy.c
Normal file
122
libc/arch-riscv64/string/bcopy.c
Normal file
|
@ -0,0 +1,122 @@
|
|||
/*-
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Chris Torek.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
typedef intptr_t word; /* "word" used for optimal copy speed */
|
||||
|
||||
#define wsize sizeof(word)
|
||||
#define wmask (wsize - 1)
|
||||
|
||||
/*
|
||||
* Copy a block of memory, handling overlap.
|
||||
*/
|
||||
#include <string.h>
|
||||
|
||||
void *
|
||||
#ifdef MEMCOPY
|
||||
memcpy_gc
|
||||
#else
|
||||
memmove_gc
|
||||
#endif
|
||||
(void *dst0, const void *src0, size_t length)
|
||||
{
|
||||
char *dst = dst0;
|
||||
const char *src = src0;
|
||||
size_t t;
|
||||
|
||||
if (length == 0 || dst == src) /* nothing to do */
|
||||
goto done;
|
||||
|
||||
/*
|
||||
* Macros: loop-t-times; and loop-t-times, t>0
|
||||
*/
|
||||
#define TLOOP(s) if (t) TLOOP1(s)
|
||||
#define TLOOP1(s) do { s; } while (--t)
|
||||
|
||||
if ((unsigned long)dst < (unsigned long)src) {
|
||||
/*
|
||||
* Copy forward.
|
||||
*/
|
||||
t = (uintptr_t)src; /* only need low bits */
|
||||
if ((t | (uintptr_t)dst) & wmask) {
|
||||
/*
|
||||
* Try to align operands. This cannot be done
|
||||
* unless the low bits match.
|
||||
*/
|
||||
if ((t ^ (uintptr_t)dst) & wmask || length < wsize)
|
||||
t = length;
|
||||
else
|
||||
t = wsize - (t & wmask);
|
||||
length -= t;
|
||||
TLOOP1(*dst++ = *src++);
|
||||
}
|
||||
/*
|
||||
* Copy whole words, then mop up any trailing bytes.
|
||||
*/
|
||||
t = length / wsize;
|
||||
TLOOP(*(word *)(void *)dst = *(const word *)(const void *)src;
|
||||
src += wsize; dst += wsize);
|
||||
t = length & wmask;
|
||||
TLOOP(*dst++ = *src++);
|
||||
} else {
|
||||
/*
|
||||
* Copy backwards. Otherwise essentially the same.
|
||||
* Alignment works as before, except that it takes
|
||||
* (t&wmask) bytes to align, not wsize-(t&wmask).
|
||||
*/
|
||||
src += length;
|
||||
dst += length;
|
||||
t = (uintptr_t)src;
|
||||
if ((t | (uintptr_t)dst) & wmask) {
|
||||
if ((t ^ (uintptr_t)dst) & wmask || length <= wsize)
|
||||
t = length;
|
||||
else
|
||||
t &= wmask;
|
||||
length -= t;
|
||||
TLOOP1(*--dst = *--src);
|
||||
}
|
||||
t = length / wsize;
|
||||
TLOOP(src -= wsize; dst -= wsize;
|
||||
*(word *)(void *)dst = *(const word *)(const void *)src);
|
||||
t = length & wmask;
|
||||
TLOOP(*--dst = *--src);
|
||||
}
|
||||
done:
|
||||
#if defined(MEMCOPY) || defined(MEMMOVE)
|
||||
return (dst0);
|
||||
#else
|
||||
return;
|
||||
#endif
|
||||
}
|
32
libc/arch-riscv64/string/memchr.c
Normal file
32
libc/arch-riscv64/string/memchr.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (C) 2023 The Android Open Source Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <upstream-openbsd/android/include/openbsd-compat.h>
|
||||
|
||||
#define memchr memchr_gc
|
||||
#include <upstream-openbsd/lib/libc/string/memchr.c>
|
|
@ -68,7 +68,7 @@
|
|||
#define vData v0
|
||||
#define vMask v8
|
||||
|
||||
ENTRY(memchr)
|
||||
ENTRY(memchr_v)
|
||||
|
||||
L(loop):
|
||||
vsetvli iVL, iNum, e8, ELEM_LMUL_SETTING, ta, ma
|
||||
|
@ -93,4 +93,4 @@ L(found):
|
|||
add iResult, pSrc, iTemp
|
||||
ret
|
||||
|
||||
END(memchr)
|
||||
END(memchr_v)
|
|
@ -32,19 +32,13 @@
|
|||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char sccsid[] = "@(#)memcmp.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Compare memory regions.
|
||||
*/
|
||||
int
|
||||
memcmp(const void *s1, const void *s2, size_t n)
|
||||
memcmp_gc(const void *s1, const void *s2, size_t n)
|
||||
{
|
||||
if (n != 0) {
|
||||
const unsigned char *p1 = s1, *p2 = s2;
|
||||
|
@ -56,4 +50,3 @@ memcmp(const void *s1, const void *s2, size_t n)
|
|||
}
|
||||
return (0);
|
||||
}
|
||||
|
106
libc/arch-riscv64/string/memcmp_v.S
Normal file
106
libc/arch-riscv64/string/memcmp_v.S
Normal file
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
* Copyright (C) 2023 The Android Open Source Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 2023 SiFive, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the company may not be used to endorse or promote
|
||||
* products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY SIFIVE INC ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL SIFIVE INC BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <private/bionic_asm.h>
|
||||
|
||||
#define iResult a0
|
||||
|
||||
#define pSrc1 a0
|
||||
#define pSrc2 a1
|
||||
#define iNum a2
|
||||
|
||||
#define iVL a3
|
||||
#define iTemp a4
|
||||
#define iTemp1 a5
|
||||
#define iTemp2 a6
|
||||
|
||||
#define ELEM_LMUL_SETTING m8
|
||||
#define vData1 v0
|
||||
#define vData2 v8
|
||||
#define vMask v16
|
||||
|
||||
ENTRY(memcmp_v)
|
||||
|
||||
L(loop):
|
||||
vsetvli iVL, iNum, e8, ELEM_LMUL_SETTING, ta, ma
|
||||
|
||||
vle8.v vData1, (pSrc1)
|
||||
vle8.v vData2, (pSrc2)
|
||||
|
||||
vmsne.vv vMask, vData1, vData2
|
||||
sub iNum, iNum, iVL
|
||||
vfirst.m iTemp, vMask
|
||||
|
||||
/* skip the loop if we find the different
|
||||
value between pSrc1 and pSrc2. */
|
||||
bgez iTemp, L(found)
|
||||
|
||||
add pSrc1, pSrc1, iVL
|
||||
add pSrc2, pSrc2, iVL
|
||||
|
||||
bnez iNum, L(loop)
|
||||
|
||||
li iResult, 0
|
||||
ret
|
||||
|
||||
L(found):
|
||||
add pSrc1, pSrc1, iTemp
|
||||
add pSrc2, pSrc2, iTemp
|
||||
lbu iTemp1, 0(pSrc1)
|
||||
lbu iTemp2, 0(pSrc2)
|
||||
sub iResult, iTemp1, iTemp2
|
||||
ret
|
||||
|
||||
END(memcmp_v)
|
2
libc/arch-riscv64/string/memcpy.c
Normal file
2
libc/arch-riscv64/string/memcpy.c
Normal file
|
@ -0,0 +1,2 @@
|
|||
#define MEMCOPY
|
||||
#include "bcopy.c"
|
|
@ -65,7 +65,7 @@
|
|||
#define ELEM_LMUL_SETTING m8
|
||||
#define vData v0
|
||||
|
||||
ENTRY(memcpy)
|
||||
ENTRY(memcpy_v)
|
||||
|
||||
mv pDstPtr, pDst
|
||||
|
||||
|
@ -82,4 +82,4 @@ L(loop):
|
|||
|
||||
ret
|
||||
|
||||
END(memcpy)
|
||||
END(memcpy_v)
|
2
libc/arch-riscv64/string/memmove.c
Normal file
2
libc/arch-riscv64/string/memmove.c
Normal file
|
@ -0,0 +1,2 @@
|
|||
#define MEMMOVE
|
||||
#include "bcopy.c"
|
|
@ -67,7 +67,7 @@
|
|||
#define ELEM_LMUL_SETTING m8
|
||||
#define vData v0
|
||||
|
||||
ENTRY(memmove)
|
||||
ENTRY(memmove_v)
|
||||
|
||||
mv pDstPtr, pDst
|
||||
|
||||
|
@ -99,4 +99,4 @@ L(backward_copy_loop):
|
|||
bnez iNum, L(backward_copy_loop)
|
||||
ret
|
||||
|
||||
END(memmove)
|
||||
END(memmove_v)
|
108
libc/arch-riscv64/string/memset.c
Normal file
108
libc/arch-riscv64/string/memset.c
Normal file
|
@ -0,0 +1,108 @@
|
|||
/*-
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Mike Hibler and Chris Torek.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#define wsize sizeof(u_long)
|
||||
#define wmask (wsize - 1)
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#define RETURN return (dst0)
|
||||
#define VAL c0
|
||||
#define WIDEVAL c
|
||||
|
||||
void *
|
||||
memset_gc(void *dst0, int c0, size_t length)
|
||||
{
|
||||
size_t t;
|
||||
u_long c;
|
||||
u_char *dst;
|
||||
|
||||
dst = dst0;
|
||||
/*
|
||||
* If not enough words, just fill bytes. A length >= 2 words
|
||||
* guarantees that at least one of them is `complete' after
|
||||
* any necessary alignment. For instance:
|
||||
*
|
||||
* |-----------|-----------|-----------|
|
||||
* |00|01|02|03|04|05|06|07|08|09|0A|00|
|
||||
* ^---------------------^
|
||||
* dst dst+length-1
|
||||
*
|
||||
* but we use a minimum of 3 here since the overhead of the code
|
||||
* to do word writes is substantial.
|
||||
*
|
||||
* TODO: This threshold might not be sensible for 64-bit u_long.
|
||||
* We should benchmark and revisit this decision.
|
||||
*/
|
||||
if (length < 3 * wsize) {
|
||||
while (length != 0) {
|
||||
*dst++ = VAL;
|
||||
--length;
|
||||
}
|
||||
RETURN;
|
||||
}
|
||||
|
||||
if ((c = (u_char)c0) != 0) { /* Fill the word. */
|
||||
c = (c << 8) | c; /* u_long is 16 bits. */
|
||||
c = (c << 16) | c; /* u_long is 32 bits. */
|
||||
c = (c << 32) | c; /* u_long is 64 bits. */
|
||||
}
|
||||
/* Align destination by filling in bytes. */
|
||||
if ((t = (long)dst & wmask) != 0) {
|
||||
t = wsize - t;
|
||||
length -= t;
|
||||
do {
|
||||
*dst++ = VAL;
|
||||
} while (--t != 0);
|
||||
}
|
||||
|
||||
/* Fill words. Length was >= 2*words so we know t >= 1 here. */
|
||||
t = length / wsize;
|
||||
do {
|
||||
*(u_long *)(void *)dst = WIDEVAL;
|
||||
dst += wsize;
|
||||
} while (--t != 0);
|
||||
|
||||
/* Mop up trailing bytes, if any. */
|
||||
t = length & wmask;
|
||||
if (t != 0)
|
||||
do {
|
||||
*dst++ = VAL;
|
||||
} while (--t != 0);
|
||||
RETURN;
|
||||
}
|
|
@ -66,7 +66,7 @@
|
|||
#define ELEM_LMUL_SETTING m8
|
||||
#define vData v0
|
||||
|
||||
ENTRY(memset)
|
||||
ENTRY(memset_v)
|
||||
|
||||
mv pDstPtr, pDst
|
||||
|
||||
|
@ -82,4 +82,4 @@ L(loop):
|
|||
|
||||
ret
|
||||
|
||||
END(memset)
|
||||
END(memset_v)
|
32
libc/arch-riscv64/string/stpcpy.c
Normal file
32
libc/arch-riscv64/string/stpcpy.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (C) 2023 The Android Open Source Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <upstream-openbsd/android/include/openbsd-compat.h>
|
||||
|
||||
#define stpcpy stpcpy_gc
|
||||
#include <upstream-openbsd/lib/libc/string/stpcpy.c>
|
|
@ -68,7 +68,7 @@
|
|||
#define vStr1 v8
|
||||
#define vStr2 v16
|
||||
|
||||
ENTRY(stpcpy)
|
||||
ENTRY(stpcpy_v)
|
||||
L(stpcpy_loop):
|
||||
vsetvli iVL, zero, e8, ELEM_LMUL_SETTING, ta, ma
|
||||
vle8ff.v vStr1, (pSrc)
|
||||
|
@ -85,4 +85,4 @@ L(stpcpy_loop):
|
|||
sub pDstPtr, pDstPtr, iCurrentVL
|
||||
add pDstPtr, pDstPtr, iActiveElemPos
|
||||
ret
|
||||
END(stpcpy)
|
||||
END(stpcpy_v)
|
32
libc/arch-riscv64/string/strcat.c
Normal file
32
libc/arch-riscv64/string/strcat.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (C) 2023 The Android Open Source Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <upstream-openbsd/android/include/openbsd-compat.h>
|
||||
|
||||
#define strcat strcat_gc
|
||||
#include <upstream-openbsd/lib/libc/string/strcat.c>
|
|
@ -69,7 +69,7 @@
|
|||
#define vStr1 v8
|
||||
#define vStr2 v16
|
||||
|
||||
ENTRY(strcat)
|
||||
ENTRY(strcat_v)
|
||||
|
||||
mv pDstPtr, pDst
|
||||
|
||||
|
@ -104,4 +104,4 @@ L(strcpy_loop):
|
|||
|
||||
ret
|
||||
|
||||
END(strcat)
|
||||
END(strcat_v)
|
43
libc/arch-riscv64/string/strchr.c
Normal file
43
libc/arch-riscv64/string/strchr.c
Normal file
|
@ -0,0 +1,43 @@
|
|||
/* $OpenBSD: strchr.c,v 1.4 2018/10/01 06:37:37 martijn Exp $ */
|
||||
/*-
|
||||
* Copyright (c) 1990 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char *
|
||||
strchr_gc(const char *p, int ch)
|
||||
{
|
||||
for (;; ++p) {
|
||||
if (*p == (char) ch)
|
||||
return((char *)p);
|
||||
if (!*p)
|
||||
return((char *)NULL);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
|
@ -69,7 +69,7 @@
|
|||
#define vMaskEnd v8
|
||||
#define vMaskCh v9
|
||||
|
||||
ENTRY(strchr)
|
||||
ENTRY(strchr_v)
|
||||
|
||||
L(strchr_loop):
|
||||
vsetvli iVL, zero, e8, ELEM_LMUL_SETTING, ta, ma
|
||||
|
@ -91,4 +91,4 @@ L(found_ch):
|
|||
add pStr, pStr, iChOffset
|
||||
ret
|
||||
|
||||
END(strchr)
|
||||
END(strchr_v)
|
47
libc/arch-riscv64/string/strcmp.c
Normal file
47
libc/arch-riscv64/string/strcmp.c
Normal file
|
@ -0,0 +1,47 @@
|
|||
/* $OpenBSD: strcmp.c,v 1.9 2015/08/31 02:53:57 guenther Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1990 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Chris Torek.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Compare strings.
|
||||
*/
|
||||
int
|
||||
strcmp_gc(const char *s1, const char *s2)
|
||||
{
|
||||
while (*s1 == *s2++)
|
||||
if (*s1++ == 0)
|
||||
return (0);
|
||||
return (*(unsigned char *)s1 - *(unsigned char *)--s2);
|
||||
}
|
|
@ -74,7 +74,7 @@
|
|||
#define vMask1 v16
|
||||
#define vMask2 v17
|
||||
|
||||
ENTRY(strcmp)
|
||||
ENTRY(strcmp_v)
|
||||
|
||||
# increase the lmul using the following sequences:
|
||||
# 1/2, 1/2, 1, 2, 4, 4, 4, ...
|
||||
|
@ -166,4 +166,4 @@ L(check2):
|
|||
sub iResult, iTemp1, iTemp2
|
||||
ret
|
||||
|
||||
END(strcmp)
|
||||
END(strcmp_v)
|
41
libc/arch-riscv64/string/strcpy.c
Normal file
41
libc/arch-riscv64/string/strcpy.c
Normal file
|
@ -0,0 +1,41 @@
|
|||
/* $OpenBSD: strcpy.c,v 1.10 2017/11/28 06:55:49 tb Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988 Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char *
|
||||
strcpy_gc(char *to, const char *from)
|
||||
{
|
||||
char *save = to;
|
||||
|
||||
for (; (*to = *from) != '\0'; ++from, ++to);
|
||||
return(save);
|
||||
}
|
|
@ -69,7 +69,7 @@
|
|||
#define vStr1 v8
|
||||
#define vStr2 v16
|
||||
|
||||
ENTRY(strcpy)
|
||||
ENTRY(strcpy_v)
|
||||
|
||||
mv pDstPtr, pDst
|
||||
|
||||
|
@ -88,4 +88,4 @@ L(strcpy_loop):
|
|||
|
||||
ret
|
||||
|
||||
END(strcpy)
|
||||
END(strcpy_v)
|
42
libc/arch-riscv64/string/strlen.c
Normal file
42
libc/arch-riscv64/string/strlen.c
Normal file
|
@ -0,0 +1,42 @@
|
|||
/* $OpenBSD: strlen.c,v 1.9 2015/08/31 02:53:57 guenther Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
size_t
|
||||
strlen_gc(const char *str)
|
||||
{
|
||||
const char *s;
|
||||
|
||||
for (s = str; *s; ++s)
|
||||
;
|
||||
return (s - str);
|
||||
}
|
|
@ -66,7 +66,7 @@
|
|||
#define vStr v0
|
||||
#define vMaskEnd v2
|
||||
|
||||
ENTRY(strlen)
|
||||
ENTRY(strlen_v)
|
||||
|
||||
mv pCopyStr, pStr
|
||||
L(loop):
|
||||
|
@ -84,4 +84,4 @@ L(loop):
|
|||
|
||||
ret
|
||||
|
||||
END(strlen)
|
||||
END(strlen_v)
|
32
libc/arch-riscv64/string/strncat.c
Normal file
32
libc/arch-riscv64/string/strncat.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (C) 2023 The Android Open Source Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <upstream-openbsd/android/include/openbsd-compat.h>
|
||||
|
||||
#define strncat strncat_gc
|
||||
#include <upstream-openbsd/lib/libc/string/strncat.c>
|
|
@ -70,7 +70,7 @@
|
|||
#define vStr1 v8
|
||||
#define vStr2 v16
|
||||
|
||||
ENTRY(strncat)
|
||||
ENTRY(strncat_v)
|
||||
|
||||
mv pDstPtr, pDst
|
||||
|
||||
|
@ -114,4 +114,4 @@ L(fill_zero):
|
|||
L(fill_zero_end):
|
||||
ret
|
||||
|
||||
END(strncat)
|
||||
END(strncat_v)
|
32
libc/arch-riscv64/string/strncmp.c
Normal file
32
libc/arch-riscv64/string/strncmp.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (C) 2023 The Android Open Source Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <upstream-openbsd/android/include/openbsd-compat.h>
|
||||
|
||||
#define strncmp strncmp_gc
|
||||
#include <upstream-openbsd/lib/libc/string/strncmp.c>
|
|
@ -71,7 +71,7 @@
|
|||
#define vMask1 v8
|
||||
#define vMask2 v9
|
||||
|
||||
ENTRY(strncmp)
|
||||
ENTRY(strncmp_v)
|
||||
|
||||
beqz iLength, L(zero_length)
|
||||
|
||||
|
@ -116,4 +116,4 @@ L(zero_length):
|
|||
li iResult, 0
|
||||
ret
|
||||
|
||||
END(strncmp)
|
||||
END(strncmp_v)
|
32
libc/arch-riscv64/string/strncpy.c
Normal file
32
libc/arch-riscv64/string/strncpy.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (C) 2023 The Android Open Source Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <upstream-openbsd/android/include/openbsd-compat.h>
|
||||
|
||||
#define strncpy strncpy_gc
|
||||
#include <upstream-openbsd/lib/libc/string/strncpy.c>
|
|
@ -71,7 +71,7 @@
|
|||
#define vStr1 v8
|
||||
#define vStr2 v16
|
||||
|
||||
ENTRY(strncpy)
|
||||
ENTRY(strncpy_v)
|
||||
|
||||
mv pDstPtr, pDst
|
||||
|
||||
|
@ -111,4 +111,4 @@ L(fill_zero_loop):
|
|||
|
||||
ret
|
||||
|
||||
END(strncpy)
|
||||
END(strncpy_v)
|
32
libc/arch-riscv64/string/strnlen.c
Normal file
32
libc/arch-riscv64/string/strnlen.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
/* $OpenBSD: strnlen.c,v 1.9 2019/01/25 00:19:25 millert Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010 Todd C. Miller <millert@openbsd.org>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
size_t
|
||||
strnlen_gc(const char *str, size_t maxlen)
|
||||
{
|
||||
const char *cp;
|
||||
|
||||
for (cp = str; maxlen != 0 && *cp != '\0'; cp++, maxlen--)
|
||||
;
|
||||
|
||||
return (size_t)(cp - str);
|
||||
}
|
|
@ -66,7 +66,7 @@
|
|||
#define vStr v0
|
||||
#define vMaskEnd v8
|
||||
|
||||
ENTRY(strnlen)
|
||||
ENTRY(strnlen_v)
|
||||
|
||||
mv pCopyStr, pStr
|
||||
mv iRetValue, iMaxlen
|
||||
|
@ -86,4 +86,4 @@ L(strnlen_loop):
|
|||
L(end_strnlen_loop):
|
||||
ret
|
||||
|
||||
END(strnlen)
|
||||
END(strnlen_v)
|
|
@ -25,14 +25,10 @@
|
|||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
size_t strnlen(const char* str, size_t maxlen)
|
||||
{
|
||||
char* p = memchr(str, 0, maxlen);
|
||||
|
||||
if (p == NULL)
|
||||
return maxlen;
|
||||
else
|
||||
return (p - str);
|
||||
size_t strnlen(const char* s, size_t n) {
|
||||
const char* p = static_cast<const char*>(memchr(s, 0, n));
|
||||
return p ? (p - s) : n;
|
||||
}
|
Loading…
Reference in a new issue