Merge pull request #76 from memtest86plus/debrouxl/size_optimizations

Save space by inlining functions and getting rid of library functions which become unused
This commit is contained in:
martinwhitaker 2022-05-21 20:48:25 +01:00 committed by GitHub
commit 4b17a4cc0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 20 additions and 54 deletions

View File

@ -38,7 +38,6 @@ SYS_OBJS = system/cpuid.o \
system/xhci.o
LIB_OBJS = lib/barrier.o \
lib/ctype.o \
lib/div64.o \
lib/print.o \
lib/read.o \

View File

@ -38,7 +38,6 @@ SYS_OBJS = system/cpuid.o \
system/xhci.o
LIB_OBJS = lib/barrier.o \
lib/ctype.o \
lib/print.o \
lib/read.o \
lib/string.o \

View File

@ -1,27 +0,0 @@
// SPDX-License-Identifier: GPL-2.0
// Copyright (C) 2020 Martin Whitaker.
#include "ctype.h"
//------------------------------------------------------------------------------
// Public Functions
//------------------------------------------------------------------------------
int toupper(int c)
{
if (c >= 'a' && c <= 'z') {
return c + 'A' -'a';
} else {
return c;
}
}
int isdigit(int c)
{
return c >= '0' && c <= '9';
}
int isxdigit(int c)
{
return isdigit(c) || (toupper(c) >= 'A' && toupper(c) <= 'F');
}

View File

@ -14,18 +14,31 @@
* If c is a lower-case letter, returns its upper-case equivalent, otherwise
* returns c. Assumes c is an ASCII character.
*/
int toupper(int c);
static inline int toupper(int c)
{
if (c >= 'a' && c <= 'z') {
return c + 'A' -'a';
} else {
return c;
}
}
/**
* Returns 1 if c is a decimal digit, otherwise returns 0. Assumes c is an
* ASCII character.
*/
int isdigit(int c);
static inline int isdigit(int c)
{
return c >= '0' && c <= '9';
}
/**
* Returns 1 if c is a hexadecimal digit, otherwise returns 0. Assumes c is an
* ASCII character.
*/
int isxdigit(int c);
static inline int isxdigit(int c)
{
return isdigit(c) || (toupper(c) >= 'A' && toupper(c) <= 'F');
}
#endif // CTYPE_H

View File

@ -43,16 +43,6 @@ int memcmp(const void *s1, const void *s2, size_t n)
return 0;
}
void *memcpy(void *dest, const void *src, size_t n)
{
char *d = (char *)dest, *s = (char *)src;
for (size_t i = 0; i < n; i++) {
d[i] = s[i];
}
return dest;
}
void *memmove(void *dest, const void *src, size_t n)
{
char *d = (char *)dest, *s = (char *)src;
@ -74,16 +64,6 @@ void *memmove(void *dest, const void *src, size_t n)
return dest;
}
void *memset(void *s, int c, size_t n)
{
char *d = (char *)s;
for (size_t i = 0; i < n; i++) {
d[i] = c;
}
return s;
}
size_t strlen(const char *s)
{
size_t len = 0;

View File

@ -24,8 +24,9 @@ int memcmp(const void *s1, const void *s2, size_t n);
* Copies n bytes from the memory area pointed to by src to the memory area
* pointed to by dest and returns a pointer to dest. The memory areas must
* not overlap.
* void *memcpy(void *dst, const void *src, size_t n);
*/
void *memcpy(void *dst, const void *src, size_t n);
#define memcpy(d, s, n) __builtin_memcpy((d), (s), (n))
/**
* Copies n bytes from the memory area pointed to by src to the memory area
@ -37,8 +38,9 @@ void *memmove(void *dest, const void *src, size_t n);
/**
* Fills the first n bytes of the memory area pointed to by s with the byte
* value c.
* void *memset(void *s, int c, size_t n);
*/
void *memset(void *s, int c, size_t n);
#define memset(s, c, n) __builtin_memset((s), (c), (n))
/**
* Returns the string length, excluding the terminating null character.