mirror of
https://github.com/ARM-software/arm-trusted-firmware.git
synced 2025-04-18 02:24:18 +00:00
Merge "perf(libc): use builtin implementations where possible" into integration
This commit is contained in:
commit
25002a0042
12 changed files with 59 additions and 34 deletions
|
@ -4,7 +4,7 @@
|
|||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
/*
|
||||
* Portions copyright (c) 2018-2020, Arm Limited and Contributors.
|
||||
* Portions copyright (c) 2018-2025, Arm Limited and Contributors.
|
||||
* Portions copyright (c) 2023, Intel Corporation. All rights reserved.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
@ -14,19 +14,26 @@
|
|||
|
||||
#include <stddef.h>
|
||||
|
||||
void *memcpy(void *dst, const void *src, size_t len);
|
||||
/*
|
||||
* When conditions are right, the compiler may have a baked-in call that can be
|
||||
* inlined and that will be much more optimal than our generic implementation.
|
||||
* When it doesn't, it will emit a call to the original function for which we
|
||||
* provide an implementation.
|
||||
*/
|
||||
#define memcpy __builtin_memcpy
|
||||
#define memset __builtin_memset
|
||||
#define memcmp __builtin_memcmp
|
||||
#define memchr __builtin_memchr
|
||||
#define strcmp __builtin_strcmp
|
||||
#define strncmp __builtin_strncmp
|
||||
#define strchr __builtin_strchr
|
||||
#define strlen __builtin_strlen
|
||||
#define strrchr __builtin_strrchr
|
||||
|
||||
int memcpy_s(void *dst, size_t dsize, void *src, size_t ssize);
|
||||
void *memmove(void *dst, const void *src, size_t len);
|
||||
int memcmp(const void *s1, const void *s2, size_t len);
|
||||
int strcmp(const char *s1, const char *s2);
|
||||
int strncmp(const char *s1, const char *s2, size_t n);
|
||||
void *memchr(const void *src, int c, size_t len);
|
||||
void *memrchr(const void *src, int c, size_t len);
|
||||
char *strchr(const char *s, int c);
|
||||
void *memset(void *dst, int val, size_t count);
|
||||
size_t strlen(const char *s);
|
||||
size_t strnlen(const char *s, size_t maxlen);
|
||||
char *strrchr(const char *p, int ch);
|
||||
size_t strlcpy(char * dst, const char * src, size_t dsize);
|
||||
size_t strlcat(char * dst, const char * src, size_t dsize);
|
||||
char *strtok_r(char *s, const char *delim, char **last);
|
||||
|
|
23
include/lib/libc/string_private.h
Normal file
23
include/lib/libc/string_private.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Arm Limited and Contributors. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#ifndef STRING_PRIVATE_H
|
||||
#define STRING_PRIVATE_H
|
||||
|
||||
/* Do not include outside of the libc. Use string.h instead. */
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
int memcmp(const void *s1, const void *s2, size_t len);
|
||||
int strcmp(const char *s1, const char *s2);
|
||||
int strncmp(const char *s1, const char *s2, size_t n);
|
||||
void *memchr(const void *src, int c, size_t len);
|
||||
char *strchr(const char *s, int c);
|
||||
void *memset(void *dst, int val, size_t count);
|
||||
size_t strlen(const char *s);
|
||||
char *strrchr(const char *p, int ch);
|
||||
|
||||
#endif /* STRING_PRIVATE_H */
|
|
@ -1,11 +1,11 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Arm Limited and Contributors. All rights reserved.
|
||||
* Copyright (c) 2013-2025, Arm Limited and Contributors. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <string_private.h>
|
||||
|
||||
void *memchr(const void *src, int c, size_t len)
|
||||
{
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Arm Limited and Contributors. All rights reserved.
|
||||
* Copyright (c) 2013-2025, Arm Limited and Contributors. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <string_private.h>
|
||||
|
||||
int memcmp(const void *s1, const void *s2, size_t len)
|
||||
{
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2019, Arm Limited and Contributors. All rights reserved.
|
||||
* Copyright (c) 2013-2025, Arm Limited and Contributors. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <string_private.h>
|
||||
|
||||
void *memcpy(void *dst, const void *src, size_t len)
|
||||
{
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2023, Arm Limited and Contributors. All rights reserved.
|
||||
* Copyright (c) 2013-2025, Arm Limited and Contributors. All rights reserved.
|
||||
* Copyright (c) 2023, Intel Corporation. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
|
@ -53,12 +53,7 @@ int memcpy_s(void *dst, size_t dsize, void *src, size_t ssize)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Start copy process when there is no error
|
||||
*/
|
||||
while (ssize--) {
|
||||
d[ssize] = s[ssize];
|
||||
}
|
||||
(void)memcpy(dst, src, ssize);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
/*
|
||||
* Copyright (c) 2013-2020, Arm Limited and Contributors. All rights reserved.
|
||||
* Copyright (c) 2013-2025, Arm Limited and Contributors. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <string_private.h>
|
||||
#include <stdint.h>
|
||||
|
||||
void *memset(void *dst, int val, size_t count)
|
||||
|
|
|
@ -30,12 +30,12 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
* Portions copyright (c) 2018, Arm Limited and Contributors.
|
||||
* Portions copyright (c) 2018-2025, Arm Limited and Contributors.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <string_private.h>
|
||||
|
||||
char *
|
||||
strchr(const char *p, int ch)
|
||||
|
|
|
@ -33,11 +33,11 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
* Portions copyright (c) 2018, Arm Limited and Contributors.
|
||||
* Portions copyright (c) 2018-2025, Arm Limited and Contributors.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <string_private.h>
|
||||
|
||||
/*
|
||||
* Compare strings.
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
* Copyright (c) 2018, Arm Limited and Contributors. All rights reserved.
|
||||
* Copyright (c) 2018-2025, Arm Limited and Contributors. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <string_private.h>
|
||||
|
||||
size_t strlen(const char *s)
|
||||
{
|
||||
|
|
|
@ -30,11 +30,11 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
* Portions copyright (c) 2018, Arm Limited and Contributors.
|
||||
* Portions copyright (c) 2018-2025, Arm Limited and Contributors.
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <string_private.h>
|
||||
|
||||
int
|
||||
strncmp(const char *s1, const char *s2, size_t n)
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <string_private.h>
|
||||
|
||||
char *
|
||||
strrchr(const char *p, int ch)
|
||||
|
|
Loading…
Add table
Reference in a new issue