kern: use optimized memcmp/memcpy implementations

This commit is contained in:
Michael Scire 2020-07-29 16:47:20 -07:00 committed by SciresM
parent 3f17a34b67
commit 9ddb4194b3
5 changed files with 75 additions and 0 deletions

View File

@ -0,0 +1,24 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
/* Definitions for libc genericity. */
#define MESOSPHERE_LIBC_MEMCPY_GENERIC 0
#define MESOSPHERE_LIBC_MEMCMP_GENERIC 0
#define MESOSPHERE_LIBC_MEMMOVE_GENERIC 0
#define MESOSPHERE_LIBC_MEMSET_GENERIC 1
#define MESOSPHERE_LIBC_STRNCPY_GENERIC 1
#define MESOSPHERE_LIBC_STRNCMP_GENERIC 1

View File

@ -0,0 +1,26 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#if defined(ATMOSPHERE_ARCH_ARM64)
#include "kern_libc_config.arch.arm64.h"
#else
#error "Unknown architecture for libc"
#endif

View File

@ -16,6 +16,7 @@
#include <string.h> #include <string.h>
#include <stddef.h> #include <stddef.h>
#include <limits.h> #include <limits.h>
#include "kern_libc_config.h"
/* Note: copied from newlib */ /* Note: copied from newlib */
#ifdef __cplusplus #ifdef __cplusplus
@ -58,6 +59,8 @@ QUICKREF
#undef TOO_SMALL #undef TOO_SMALL
#define TOO_SMALL(LEN) ((LEN) < BIGBLOCKSIZE) #define TOO_SMALL(LEN) ((LEN) < BIGBLOCKSIZE)
#if MESOSPHERE_LIBC_MEMMOVE_GENERIC
/*SUPPRESS 20*/ /*SUPPRESS 20*/
void * void *
//__inhibit_loop_to_libcall //__inhibit_loop_to_libcall
@ -147,6 +150,8 @@ memmove (void *dst_void,
#endif /* not PREFER_SIZE_OVER_SPEED */ #endif /* not PREFER_SIZE_OVER_SPEED */
} }
#endif /* MESOSPHERE_LIBC_MEMMOVE_GENERIC */
/* /*
FUNCTION FUNCTION
<<memcpy>>---copy memory regions <<memcpy>>---copy memory regions
@ -169,6 +174,8 @@ QUICKREF
memcpy ansi pure memcpy ansi pure
*/ */
#if MESOSPHERE_LIBC_MEMCPY_GENERIC
void * void *
__attribute__((weak)) __attribute__((weak))
memcpy (void * dst0, memcpy (void * dst0,
@ -229,6 +236,8 @@ memcpy (void * dst0,
#endif /* not PREFER_SIZE_OVER_SPEED */ #endif /* not PREFER_SIZE_OVER_SPEED */
} }
#endif /* MESOSPHERE_LIBC_MEMCPY_GENERIC */
/* /*
FUNCTION FUNCTION
<<memset>>---set an area of memory <<memset>>---set an area of memory
@ -260,6 +269,8 @@ QUICKREF
#define UNALIGNED(X) ((long)X & (LBLOCKSIZE - 1)) #define UNALIGNED(X) ((long)X & (LBLOCKSIZE - 1))
#define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE) #define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE)
#if MESOSPHERE_LIBC_MEMSET_GENERIC
void * void *
__attribute__((weak)) __attribute__((weak))
memset (void *m, memset (void *m,
@ -322,6 +333,8 @@ memset (void *m,
return m; return m;
} }
#endif /* MESOSPHERE_LIBC_MEMSET_GENERIC */
/* /*
FUNCTION FUNCTION
<<memcmp>>---compare two memory areas <<memcmp>>---compare two memory areas
@ -359,6 +372,8 @@ QUICKREF
/* Threshhold for punting to the byte copier. */ /* Threshhold for punting to the byte copier. */
#define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE) #define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE)
#if MESOSPHERE_LIBC_MEMCMP_GENERIC
int int
__attribute__((weak)) __attribute__((weak))
memcmp (const void *m1, memcmp (const void *m1,
@ -421,6 +436,8 @@ memcmp (const void *m1,
#endif /* not PREFER_SIZE_OVER_SPEED */ #endif /* not PREFER_SIZE_OVER_SPEED */
} }
#endif /* MESOSPHERE_LIBC_MEMCMP_GENERIC */
/* /*
FUNCTION FUNCTION
<<strncpy>>---counted copy string <<strncpy>>---counted copy string
@ -475,6 +492,8 @@ QUICKREF
#undef TOO_SMALL #undef TOO_SMALL
#define TOO_SMALL(LEN) ((LEN) < sizeof (long)) #define TOO_SMALL(LEN) ((LEN) < sizeof (long))
#if MESOSPHERE_LIBC_STRNCMP_GENERIC
char * char *
strncpy (char *__restrict dst0, strncpy (char *__restrict dst0,
const char *__restrict src0, const char *__restrict src0,
@ -534,6 +553,8 @@ strncpy (char *__restrict dst0,
#endif /* not PREFER_SIZE_OVER_SPEED */ #endif /* not PREFER_SIZE_OVER_SPEED */
} }
#endif /* MESOSPHERE_LIBC_STRNCPY_GENERIC */
/* /*
FUNCTION FUNCTION
<<strncmp>>---character string compare <<strncmp>>---character string compare
@ -581,6 +602,8 @@ QUICKREF
#error long int is not a 32bit or 64bit byte #error long int is not a 32bit or 64bit byte
#endif #endif
#if MESOSPHERE_LIBC_STRNCMP_GENERIC
int int
strncmp (const char *s1, strncmp (const char *s1,
const char *s2, const char *s2,
@ -643,6 +666,8 @@ strncmp (const char *s1,
#endif /* not PREFER_SIZE_OVER_SPEED */ #endif /* not PREFER_SIZE_OVER_SPEED */
} }
#endif /* MESOSPHERE_LIBC_STRNCMP_GENERIC */
#ifdef __cplusplus #ifdef __cplusplus
} /* extern "C" */ } /* extern "C" */
#endif #endif