diff --git a/src/cmd/smlrc/cgmips.c b/src/cmd/smlrc/cgmips.c index 685e60f..7eb4a41 100644 --- a/src/cmd/smlrc/cgmips.c +++ b/src/cmd/smlrc/cgmips.c @@ -1210,7 +1210,7 @@ void GenPrep(int* idx) xor = '<' ^ '>'; break; case tokLEQ: case tokGEQ: - xor = tokLEQ ^ tokGEQ; break; + xor = (int)tokLEQ ^ tokGEQ; break; case tokULess: case tokUGreater: xor = tokULess ^ tokUGreater; break; @@ -2261,4 +2261,3 @@ void GenFin(void) } #endif } - diff --git a/src/cmd/smlrc/lb.c b/src/cmd/smlrc/lb.c index 47a9854..45d4762 100644 --- a/src/cmd/smlrc/lb.c +++ b/src/cmd/smlrc/lb.c @@ -152,10 +152,10 @@ int atoi(char* s) return r; } -unsigned strlen(char* str) +unsigned strlen(const char* str) { #ifndef __SMALLER_C_16__ - char* s; + const char* s; if (str == NULL) return 0; @@ -175,7 +175,7 @@ unsigned strlen(char* str) #endif } -char* strcpy(char* dst, char* src) +char* strcpy(char* dst, const char* src) { #ifndef __SMALLER_C_16__ char* p = dst; @@ -196,7 +196,7 @@ char* strcpy(char* dst, char* src) return dst; } -char* strchr(char* s, int c) +char* strchr(const char* s, int c) { #ifndef __SMALLER_C_16__ char ch = c; @@ -204,12 +204,12 @@ char* strchr(char* s, int c) while (*s) { if (*s == ch) - return s; + return (char*)s; ++s; } if (!ch) - return s; + return (char*)s; return NULL; #else @@ -230,7 +230,7 @@ char* strchr(char* s, int c) #endif } -int strcmp(char* s1, char* s2) +int strcmp(const char* s1, const char* s2) { #ifndef __SMALLER_C_16__ while (*s1 == *s2) @@ -259,7 +259,7 @@ int strcmp(char* s1, char* s2) #endif } -int strncmp(char* s1, char* s2, unsigned n) +int strncmp(const char* s1, const char* s2, unsigned n) { #ifndef __SMALLER_C_16__ if (!n) @@ -294,11 +294,11 @@ int strncmp(char* s1, char* s2, unsigned n) #endif } -void* memmove(void* dst, void* src, unsigned n) +void* memmove(void* dst, const void* src, unsigned n) { #ifndef __SMALLER_C_16__ char* d = dst; - char* s = src; + const char* s = src; if (s < d) { @@ -337,11 +337,11 @@ void* memmove(void* dst, void* src, unsigned n) return dst; } -void* memcpy(void* dst, void* src, unsigned n) +void* memcpy(void* dst, const void* src, unsigned n) { #ifndef __SMALLER_C_16__ char* p1 = dst; - char* p2 = src; + const char* p2 = src; while (n--) *p1++ = *p2++; @@ -380,11 +380,11 @@ void* memset(void* s, int c, unsigned n) } #ifdef __SMALLER_C_32__ -int memcmp(void* s1, void* s2, unsigned n) +int memcmp(const void* s1, const void* s2, unsigned n) { if (n) { - unsigned char *p1 = s1, *p2 = s2; + unsigned const char *p1 = s1, *p2 = s2; do { if (*p1++ != *p2++) @@ -591,23 +591,23 @@ int __vsprintf__(char** buf, FILE* stream, char* fmt, void* vl) return cnt; } -int vprintf(char* fmt, void* vl) +int vprintf(const char* fmt, void* vl) { - return __vsprintf__(NULL, NULL, fmt, vl); + return __vsprintf__(NULL, NULL, (char*)fmt, vl); } -int printf(char* fmt, ...) +int printf(const char* fmt, ...) { void** pp = (void**)&fmt; return vprintf(fmt, pp + 1); } -int vsprintf(char* buf, char* fmt, void* vl) +int vsprintf(char* buf, const char* fmt, void* vl) { - return __vsprintf__(&buf, NULL, fmt, vl); + return __vsprintf__(&buf, NULL, (char*)fmt, vl); } -int sprintf(char* buf, char* fmt, ...) +int sprintf(char* buf, const char* fmt, ...) { void** pp = (void**)&fmt; return vsprintf(buf, fmt, pp + 1); @@ -1755,4 +1755,3 @@ float __gesf2(float a, float b) #endif #endif /*__APPLE__*/ - diff --git a/src/cmd/smlrc/smlrc.c b/src/cmd/smlrc/smlrc.c index 97f3daa..ea3ea5f 100644 --- a/src/cmd/smlrc/smlrc.c +++ b/src/cmd/smlrc/smlrc.c @@ -124,15 +124,15 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. void exit(int); int atoi(char*); -size_t strlen(char*); -char* strcpy(char*, char*); -char* strchr(char*, int); -int strcmp(char*, char*); -int strncmp(char*, char*, size_t); -void* memmove(void*, void*, size_t); -void* memcpy(void*, void*, size_t); +size_t strlen(const char*); +char* strcpy(char*, const char*); +char* strchr(const char*, int); +int strcmp(const char*, const char*); +int strncmp(const char*, const char*, size_t); +void* memmove(void*, const void*, size_t); +void* memcpy(void*, const void*, size_t); void* memset(void*, int, size_t); -int memcmp(void*, void*, size_t); +int memcmp(const void*, const void*, size_t); int isspace(int); int isdigit(int); @@ -148,13 +148,13 @@ int fputc(int, FILE*); int fgetc(FILE*); int puts(char*); int fputs(char*, FILE*); -int sprintf(char*, char*, ...); +int sprintf(char*, const char*, ...); //int vsprintf(char*, char*, va_list); -int vsprintf(char*, char*, void*); -int printf(char*, ...); -int fprintf(FILE*, char*, ...); +int vsprintf(char*, const char*, void*); +int printf(const char*, ...); +int fprintf(FILE*, const char*, ...); //int vprintf(char*, va_list); -int vprintf(char*, void*); +int vprintf(const char*, void*); //int vfprintf(FILE*, char*, va_list); int vfprintf(FILE*, char*, void*); struct fpos_t_ @@ -8938,7 +8938,7 @@ int ParseStatement(int tok, int BrkCntTarget[2], int casesIdx) UndoNonLabelIdents(undoIdents); // remove all identifier names, except those of labels SyntaxStackCnt = undoSymbolsPtr; // remove all params and locals CurFxnLocalOfs = undoLocalOfs; // destroy on-stack local variables - } + } #endif } else if (tok == tokBreak) @@ -9470,4 +9470,3 @@ int main(int argc, char** argv) return 0; } - diff --git a/src/libc/runtime/Makefile b/src/libc/runtime/Makefile index 3cb38a9..7906f32 100644 --- a/src/libc/runtime/Makefile +++ b/src/libc/runtime/Makefile @@ -29,6 +29,7 @@ OBJS = adddf3.o \ extendsfdf2.o \ fixdfsi.o \ fixsfsi.o \ + fixunssfsi.o \ floatsidf.o \ floatsisf.o \ floatunsisf.o \ diff --git a/src/libc/runtime/fixunssfsi.c b/src/libc/runtime/fixunssfsi.c new file mode 100644 index 0000000..738c1bb --- /dev/null +++ b/src/libc/runtime/fixunssfsi.c @@ -0,0 +1,26 @@ +//===-- fixunssfsi.c - Implement __fixunssfsi -----------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file implements __fixunssfsi for the compiler_rt library. +// +//===----------------------------------------------------------------------===// + +#define SINGLE_PRECISION +#include "fp_lib.h" +typedef su_int fixuint_t; +#include "fp_fixuint_impl.inc" + +COMPILER_RT_ABI su_int __fixunssfsi(fp_t a) { return __fixuint(a); } + +#if defined(__ARM_EABI__) +#if defined(COMPILER_RT_ARMHF_TARGET) +AEABI_RTABI su_int __aeabi_f2uiz(fp_t a) { return __fixunssfsi(a); } +#else +COMPILER_RT_ALIAS(__fixunssfsi, __aeabi_f2uiz) +#endif +#endif diff --git a/src/libc/runtime/fp_fixuint_impl.inc b/src/libc/runtime/fp_fixuint_impl.inc new file mode 100644 index 0000000..cb2bf54 --- /dev/null +++ b/src/libc/runtime/fp_fixuint_impl.inc @@ -0,0 +1,38 @@ +//===-- lib/fixdfsi.c - Double-precision -> integer conversion ----*- C -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file implements float to unsigned integer conversion for the +// compiler-rt library. +// +//===----------------------------------------------------------------------===// + +#include "fp_lib.h" + +static __inline fixuint_t __fixuint(fp_t a) { + // Break a into sign, exponent, significand parts. + const rep_t aRep = toRep(a); + const rep_t aAbs = aRep & absMask; + const int sign = aRep & signBit ? -1 : 1; + const int exponent = (aAbs >> significandBits) - exponentBias; + const rep_t significand = (aAbs & significandMask) | implicitBit; + + // If either the value or the exponent is negative, the result is zero. + if (sign == -1 || exponent < 0) + return 0; + + // If the value is too large for the integer type, saturate. + if ((unsigned)exponent >= sizeof(fixuint_t) * CHAR_BIT) + return ~(fixuint_t)0; + + // If 0 <= exponent < significandBits, right shift to get the result. + // Otherwise, shift left. + if (exponent < significandBits) + return significand >> (significandBits - exponent); + else + return (fixuint_t)significand << (exponent - significandBits); +}