diff options
author | Andrew Waterman <waterman@cs.berkeley.edu> | 2013-05-23 15:41:30 -0700 |
---|---|---|
committer | Andrew Waterman <waterman@cs.berkeley.edu> | 2013-05-23 15:41:30 -0700 |
commit | 8bad38e1a9321631de6ece0e150f0124e8c824b8 (patch) | |
tree | adfaf2be1c77cdb0b6c08293187db63f471e76cd | |
parent | 17058f071b6bd2e2287c825aaebd390730ec5bdc (diff) | |
download | pk-8bad38e1a9321631de6ece0e150f0124e8c824b8.zip pk-8bad38e1a9321631de6ece0e150f0124e8c824b8.tar.gz pk-8bad38e1a9321631de6ece0e150f0124e8c824b8.tar.bz2 |
use string.h functions in newlib (-lc)
-rwxr-xr-x | configure | 2 | ||||
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | pk/memset.c | 58 | ||||
-rw-r--r-- | pk/pk.mk.in | 2 | ||||
-rw-r--r-- | pk/strlen.c | 33 |
5 files changed, 3 insertions, 93 deletions
@@ -3955,6 +3955,8 @@ CFLAGS="-Wall -Os -std=gnu99 -Wno-unused" LIBS="-lgcc" +LIBS="-lc" + { $as_echo "$as_me:${as_lineno-$LINENO}: adding default configure arg: --host=riscv" >&5 diff --git a/configure.ac b/configure.ac index ebd9975..f18d6b4 100644 --- a/configure.ac +++ b/configure.ac @@ -73,6 +73,7 @@ AC_HEADER_STDC AC_SUBST([CFLAGS], ["-Wall -Os -std=gnu99 -Wno-unused"]) AC_SUBST([LIBS], ["-lgcc"]) +AC_SUBST([LIBS], ["-lc"]) AX_DEFAULT_CONFIGURE_ARG([--host=riscv]) diff --git a/pk/memset.c b/pk/memset.c deleted file mode 100644 index 56c0fa1..0000000 --- a/pk/memset.c +++ /dev/null @@ -1,58 +0,0 @@ -// See LICENSE for license details. - -#include <limits.h> -#include <string.h> - -#if ULONG_MAX != 18446744073709551615UL && ULONG_MAX != 4294967295UL -# error need sizeof(long) == 4 or sizeof(long) == 8 -#endif - -void* memset(void* m, int ch, size_t s) -{ - size_t i; - char* mem = (char*)m; - long* lmem; - - if(s < sizeof(long)) - { - for(i = 0; i < s; i++) - mem[i] = ch; - return m; - } - - long l = ch & 0xFF; - l = l | (l << 8); - l = l | (l << 16); - #if ULONG_MAX == 18446744073709551615UL - l = l | (l << 32); - #endif - - while((long)mem & (sizeof(long)-1)) - *mem++ = ch, s--; - lmem = (long*)mem; - - for(i = 0; i+7 < s/sizeof(long); i += 8) - { - lmem[i+0] = l; - lmem[i+1] = l; - lmem[i+2] = l; - lmem[i+3] = l; - lmem[i+4] = l; - lmem[i+5] = l; - lmem[i+6] = l; - lmem[i+7] = l; - } - lmem += i; - s -= i*sizeof(long); - - for(i = 0; i < s/sizeof(long); i++) - lmem[i] = l; - lmem += i; - s -= i*sizeof(long); - - mem = (char*)lmem; - for(i = 0; i < s; i++) - mem[i] = ch; - - return m; -} diff --git a/pk/pk.mk.in b/pk/pk.mk.in index ced7f7e..5a30d16 100644 --- a/pk/pk.mk.in +++ b/pk/pk.mk.in @@ -21,8 +21,6 @@ pk_c_srcs = \ frontend.c \ fp.c \ int.c \ - memset.c \ - strlen.c \ elf.c \ pk_asm_srcs = \ diff --git a/pk/strlen.c b/pk/strlen.c deleted file mode 100644 index 57794b7..0000000 --- a/pk/strlen.c +++ /dev/null @@ -1,33 +0,0 @@ -// See LICENSE for license details. - -#include <string.h> -#include <limits.h> - -#if ULONG_MAX != 18446744073709551615UL && ULONG_MAX != 4294967295UL -# error need sizeof(long) == 4 or sizeof(long) == 8 -#endif - -// from http://www-graphics.stanford.edu/~seander/bithacks.html -static inline long hasZeroByte(long l) -{ -#if ULONG_MAX == 4294967295UL - return (l - 0x01010101UL) & ~l & 0x80808080UL; -#else - return (l - 0x0101010101010101UL) & ~l & 0x8080808080808080UL; -#endif -} - -size_t strlen(const char* s) -{ - size_t i = 0; - - // use optimized version if string starts on a long boundary - if(((long)s & (sizeof(long)-1)) == 0) - while(!hasZeroByte(*(long*)(s+i))) - i += sizeof(long); - - while(s[i]) - i++; - - return i; -} |