Make improvements

- More timspec_*() and timeval_*() APIs have been introduced.
- The copyfd() function is now simplified thanks to POSIX rules.
- More Cosmo-specific APIs have been moved behind the COSMO define.
- The setitimer() polyfill for Windows NT is now much higher quality.
- Fixed build error for MODE=aarch64 due to -mstringop-strategy=loop.
- This change introduces `make MODE=nox87 toolchain` which makes it
  possible to build programs using your cosmocc toolchain that don't
  have legacy fpu instructions. This is useful, for example, if you
  want to have a ~22kb tinier blink virtual machine.
This commit is contained in:
Justine Tunney 2023-06-15 13:50:42 -07:00
parent 8dc11afcf6
commit c3440d040c
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
132 changed files with 539 additions and 587 deletions

View file

@ -143,5 +143,5 @@ double acos(double x)
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(acos, acosl);
__weak_reference(acos, acosl);
#endif

View file

@ -55,5 +55,5 @@ double acosh(double x)
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(acosh, acoshl);
__weak_reference(acosh, acoshl);
#endif

View file

@ -149,5 +149,5 @@ double asin(double x)
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(asin, asinl);
__weak_reference(asin, asinl);
#endif

View file

@ -66,5 +66,5 @@ double asinh(double x)
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(asinh, asinhl);
__weak_reference(asinh, asinhl);
#endif

View file

@ -156,5 +156,5 @@ double atan(double x)
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(atan, atanl);
__weak_reference(atan, atanl);
#endif

View file

@ -155,5 +155,5 @@ atan2(double y, double x)
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(atan2, atan2l);
__weak_reference(atan2, atan2l);
#endif

View file

@ -66,5 +66,5 @@ double atanh(double x)
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(atanh, atanhl);
__weak_reference(atanh, atanhl);
#endif

View file

@ -27,5 +27,5 @@ double cabs(double complex z) {
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(cabs, cabsl);
__weak_reference(cabs, cabsl);
#endif

View file

@ -45,5 +45,5 @@ double complex cacosh(double complex z)
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(cacosh, cacoshl);
__weak_reference(cacosh, cacoshl);
#endif

View file

@ -24,5 +24,5 @@ double carg(double complex z) {
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(carg, cargl);
__weak_reference(carg, cargl);
#endif

View file

@ -52,5 +52,5 @@ double complex casin(double complex z)
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(casin, casinl);
__weak_reference(casin, casinl);
#endif

View file

@ -147,5 +147,5 @@ double complex catan(double complex z)
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(catan, catanl);
__weak_reference(catan, catanl);
#endif

View file

@ -32,5 +32,5 @@ double copysign(double x, double y) {
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(copysign, copysignl);
__weak_reference(copysign, copysignl);
#endif

View file

@ -122,5 +122,5 @@ double cos(double x)
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(cos, cosl);
__weak_reference(cos, cosl);
#endif

View file

@ -76,3 +76,7 @@ double cosh(double x)
t = __expo2(x, 1.0);
return t;
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__weak_reference(cosh, coshl);
#endif

View file

@ -38,6 +38,7 @@
*/
#include "libc/math.h"
#include "libc/tinymath/freebsd.internal.h"
#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024)
asm(".ident\t\"\\n\\n\
FreeBSD libm (BSD-2 License)\\n\
@ -155,3 +156,5 @@ coshl(long double x)
/* |x| > o_threshold, cosh(x) overflow */
RETURNI(huge*huge);
}
#endif /* long double is long */

View file

@ -170,5 +170,5 @@ double exp(double x)
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(exp, expl);
__weak_reference(exp, expl);
#endif

View file

@ -57,5 +57,6 @@ double exp10(double x)
__strong_reference(exp10, pow10);
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(exp10, exp10l);
__weak_reference(exp10, exp10l);
__weak_reference(exp10, pow10l);
#endif

View file

@ -57,6 +57,6 @@ long double exp10l(long double x)
return powl(10.0, x);
}
__strong_reference(exp10l, pow10l);
__weak_reference(exp10l, pow10l);
#endif /* long double is long */

View file

@ -157,5 +157,5 @@ double exp2(double x)
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(exp2, exp2l);
__weak_reference(exp2, exp2l);
#endif

View file

@ -238,5 +238,5 @@ double expm1(double x)
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(expm1, expm1l);
__weak_reference(expm1, expm1l);
#endif

View file

@ -31,5 +31,5 @@ double fabs(double x) {
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(fabs, fabsl);
__weak_reference(fabs, fabsl);
#endif

View file

@ -27,5 +27,5 @@ double fdim(double x, double y) {
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(fdim, fdiml);
__weak_reference(fdim, fdiml);
#endif

View file

@ -96,5 +96,5 @@ double floor(double x)
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(floor, floorl);
__weak_reference(floor, floorl);
#endif

View file

@ -35,5 +35,5 @@ double fmin(double x, double y) {
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(fmin, fminl);
__weak_reference(fmin, fminl);
#endif

View file

@ -103,3 +103,7 @@ double fmod(double x, double y)
ux.i = uxi;
return ux.f;
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__weak_reference(fmod, fmodl);
#endif

View file

@ -27,6 +27,7 @@
*/
#include "libc/math.h"
#include "libc/tinymath/ldshape.internal.h"
#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024)
asm(".ident\t\"\\n\\n\
Musl libc (MIT License)\\n\
@ -34,10 +35,13 @@ Copyright 2005-2014 Rich Felker, et. al.\"");
asm(".include \"libc/disclaimer.inc\"");
// clang-format off
/**
* Does (𝑥 rem 𝑦) w/ round()-style rounding.
* @return remainder (-|𝑦|,|𝑦|) in %xmm0
* @define 𝑥-trunc(𝑥/𝑦)*𝑦
*/
long double fmodl(long double x, long double y) {
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
return fmod(x, y);
#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
#if (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
union ldshape ux = {x}, uy = {y};
int ex = ux.i.se & 0x7fff;
int ey = uy.i.se & 0x7fff;
@ -135,3 +139,5 @@ long double fmodl(long double x, long double y) {
#error "architecture unsupported"
#endif
}
#endif /* long double is long */

View file

@ -58,5 +58,5 @@ double frexp(double x, int *e)
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(frexp, frexpl);
__weak_reference(frexp, frexpl);
#endif

View file

@ -101,5 +101,5 @@ double hypot(double x, double y)
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(hypot, hypotl);
__weak_reference(hypot, hypotl);
#endif

View file

@ -63,5 +63,5 @@ int ilogb(double x)
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(ilogb, ilogbl);
__weak_reference(ilogb, ilogbl);
#endif

View file

@ -1,88 +0,0 @@
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
vi: set et ft=c ts=8 tw=8 fenc=utf-8 :vi
Musl Libc
Copyright © 2005-2014 Rich Felker, et al.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "libc/limits.h"
#include "libc/math.h"
#include "libc/tinymath/internal.h"
#include "libc/tinymath/ldshape.internal.h"
#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024)
asm(".ident\t\"\\n\\n\
Musl libc (MIT License)\\n\
Copyright 2005-2014 Rich Felker, et. al.\"");
asm(".include \"libc/disclaimer.inc\"");
// clang-format off
/**
* Returns log𝑥 exponent part of double.
*/
int ilogbl(long double x)
{
#if LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
// #pragma STDC FENV_ACCESS ON
union ldshape u = {x};
uint64_t m = u.i.m;
int e = u.i.se & 0x7fff;
if (!e) {
if (m == 0) {
FORCE_EVAL(0/0.0f);
return FP_ILOGB0;
}
/* subnormal x */
for (e = -0x3fff+1; m>>63 == 0; e--, m<<=1);
return e;
}
if (e == 0x7fff) {
FORCE_EVAL(0/0.0f);
return m<<1 ? FP_ILOGBNAN : INT_MAX;
}
return e - 0x3fff;
#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384
// #pragma STDC FENV_ACCESS ON
union ldshape u = {x};
int e = u.i.se & 0x7fff;
if (!e) {
if (x == 0) {
FORCE_EVAL(0/0.0f);
return FP_ILOGB0;
}
/* subnormal x */
x *= 0x1p120;
return ilogbl(x) - 120;
}
if (e == 0x7fff) {
FORCE_EVAL(0/0.0f);
u.i.se = 0;
return u.f ? FP_ILOGBNAN : INT_MAX;
}
return e - 0x3fff;
#endif
}
#endif /* long double is long */

View file

@ -27,6 +27,7 @@
*/
#include "libc/math.h"
#include "libc/tinymath/kernel.internal.h"
#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024)
asm(".ident\t\"\\n\\n\
FreeBSD libm (BSD-2 License)\\n\
@ -183,3 +184,5 @@ long double __tanl(long double x, long double y, int odd) {
#else
#error "architecture unsupported"
#endif
#endif /* long double is long */

View file

@ -142,5 +142,5 @@ double log(double x)
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(log, logl);
__weak_reference(log, logl);
#endif

View file

@ -143,5 +143,5 @@ double log10(double x)
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(log10, log10l);
__weak_reference(log10, log10l);
#endif

View file

@ -161,5 +161,5 @@ double log1p(double x)
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(log1p, log1pl);
__weak_reference(log1p, log1pl);
#endif

View file

@ -159,5 +159,5 @@ double log2(double x)
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(log2, log2l);
__weak_reference(log2, log2l);
#endif

View file

@ -23,3 +23,7 @@ double logb(double x) {
if (!x) return -1 / (x * x);
return ilogb(x);
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__weak_reference(logb, logbl);
#endif

View file

@ -45,8 +45,8 @@ __weak_reference(lrint, llrint);
#endif
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(lrint, lrintl);
__weak_reference(lrint, lrintl);
#if __SIZEOF_LONG__ == __SIZEOF_LONG_LONG__
__strong_reference(lrint, llrintl);
__weak_reference(lrint, llrintl);
#endif
#endif

View file

@ -26,5 +26,5 @@ long lround(double x) {
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(lround, lroundl);
__weak_reference(lround, lroundl);
#endif

View file

@ -33,6 +33,9 @@ Copyright 2005-2014 Rich Felker, et. al.\"");
asm(".include \"libc/disclaimer.inc\"");
// clang-format off
/**
* Returns fractional part of 𝑥.
*/
double modf(double x, double *iptr)
{
union {double f; uint64_t i;} u = {x};
@ -65,3 +68,7 @@ double modf(double x, double *iptr)
*iptr = u.f;
return x - u.f;
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__weak_reference(modf, modfl);
#endif

View file

@ -26,6 +26,7 @@
*/
#include "libc/math.h"
#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024)
asm(".ident\t\"\\n\\n\
Musl libc (MIT License)\\n\
@ -33,20 +34,11 @@ Copyright 2005-2014 Rich Felker, et. al.\"");
asm(".include \"libc/disclaimer.inc\"");
// clang-format off
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
long double modfl(long double x, long double *iptr)
{
double d;
long double r;
r = modf(x, &d);
*iptr = d;
return r;
}
#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
static const long double toint = 1/LDBL_EPSILON;
/**
* Returns fractional part of 𝑥.
*/
long double modfl(long double x, long double *iptr)
{
union {
@ -90,6 +82,4 @@ long double modfl(long double x, long double *iptr)
return -y;
}
#else
#error "architecture unsupported"
#endif
#endif /* long double is long */

View file

@ -42,5 +42,5 @@ double nearbyint(double x) {
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(nearbyint, nearbyintl);
__weak_reference(nearbyint, nearbyintl);
#endif

View file

@ -65,5 +65,5 @@ double nextafter(double x, double y)
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(nextafter, nextafterl);
__weak_reference(nextafter, nextafterl);
#endif

View file

@ -381,5 +381,5 @@ double pow(double x, double y)
__weak_reference(pow, __pow_finite);
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(pow, powl);
__weak_reference(pow, powl);
#endif

View file

@ -28,5 +28,5 @@ double remainder(double x, double y) {
__strong_reference(remainder, drem);
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(remainder, remainderl);
__weak_reference(remainder, remainderl);
#endif

View file

@ -225,3 +225,7 @@ medium:
y[1] = ty[1];
return n;
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__weak_reference(__rem_pio2, __rem_pio2l);
#endif

View file

@ -29,6 +29,7 @@
#include "libc/math.h"
#include "libc/tinymath/kernel.internal.h"
#include "libc/tinymath/ldshape.internal.h"
#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024)
asm(".ident\t\"\\n\\n\
FreeBSD libm (BSD-2 License)\\n\
@ -200,3 +201,5 @@ int __rem_pio2l(long double x, long double *y)
#else
#error "architecture unsupported"
#endif
#endif /* long double is long */

View file

@ -117,5 +117,5 @@ end:
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(remquo, remquol);
__weak_reference(remquo, remquol);
#endif

View file

@ -66,5 +66,5 @@ double rint(double x)
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(rint, rintl);
__weak_reference(rint, rintl);
#endif

View file

@ -92,5 +92,5 @@ double round(double x)
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(round, roundl);
__weak_reference(round, roundl);
#endif

View file

@ -26,5 +26,5 @@ double scalbln(double x, long n) {
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(scalbln, scalblnl);
__weak_reference(scalbln, scalblnl);
#endif

View file

@ -26,5 +26,5 @@ double significand(double x) {
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(significand, significandl);
__weak_reference(significand, significandl);
#endif

View file

@ -123,5 +123,5 @@ double sin(double x)
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(sin, sinl);
__weak_reference(sin, sinl);
#endif

View file

@ -114,5 +114,5 @@ void sincos(double x, double *sin, double *cos)
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(sincos, sincosl);
__weak_reference(sincos, sincosl);
#endif

View file

@ -75,3 +75,7 @@ double sinh(double x)
t = __expo2(absx, 2*h);
return t;
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__weak_reference(sinh, sinhl);
#endif

View file

@ -39,6 +39,7 @@
#include "libc/intrin/likely.h"
#include "libc/math.h"
#include "libc/tinymath/freebsd.internal.h"
#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024)
asm(".ident\t\"\\n\\n\
FreeBSD libm (BSD-2 License)\\n\
@ -154,3 +155,5 @@ sinhl(long double x)
/* |x| > o_threshold, sinh(x) overflow */
return x*shuge;
}
#endif /* long double is long */

View file

@ -222,5 +222,5 @@ double sqrt(double x)
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(sqrt, sqrtl);
__weak_reference(sqrt, sqrtl);
#endif

View file

@ -115,5 +115,5 @@ double tan(double x)
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(tan, tanl);
__weak_reference(tan, tanl);
#endif

View file

@ -76,3 +76,7 @@ double tanh(double x)
}
return sign ? -t : t;
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__weak_reference(tanh, tanhl);
#endif

View file

@ -39,6 +39,7 @@
#include "libc/intrin/likely.h"
#include "libc/math.h"
#include "libc/tinymath/freebsd.internal.h"
#if !(LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024)
asm(".ident\t\"\\n\\n\
FreeBSD libm (BSD-2 License)\\n\
@ -185,3 +186,5 @@ tanhl(long double x)
if (jx<0) s = -1;
RETURNI(s*z);
}
#endif /* long double is long */

View file

@ -82,5 +82,5 @@ double trunc(double x)
}
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
__strong_reference(trunc, truncl);
__weak_reference(trunc, truncl);
#endif