From 5020caa9c325a032f9e97741d80a64cc8bd042d0 Mon Sep 17 00:00:00 2001 From: Taylor W Date: Mon, 23 Dec 2024 16:42:57 -0600 Subject: [PATCH] C3_MATH feature (#1709) * C3_MATH feature This feature allows the usage of noclib math files even when libc is in use. If a nolibc symbol exists, it will be used in place of libc, otherwise it will default to libc. * Added MIT License notices to atan.c3 --- lib/std/math/math_nolibc/__cos.c3 | 2 +- lib/std/math/math_nolibc/__cosdf.c3 | 2 +- lib/std/math/math_nolibc/__fmod.c3 | 2 +- lib/std/math/math_nolibc/__sin.c3 | 2 +- lib/std/math/math_nolibc/__sindf.c3 | 2 +- lib/std/math/math_nolibc/__tan.c3 | 2 +- lib/std/math/math_nolibc/__tandf.c3 | 2 +- lib/std/math/math_nolibc/atan.c3 | 57 ++++++++++++++++++++++++- lib/std/math/math_nolibc/ceil.c3 | 2 +- lib/std/math/math_nolibc/cos.c3 | 2 +- lib/std/math/math_nolibc/exp2.c3 | 2 +- lib/std/math/math_nolibc/floor.c3 | 2 +- lib/std/math/math_nolibc/math_nolibc.c3 | 2 +- lib/std/math/math_nolibc/pow.c3 | 2 +- lib/std/math/math_nolibc/rempi.c3 | 2 +- lib/std/math/math_nolibc/round.c3 | 2 +- lib/std/math/math_nolibc/scalbn.c3 | 2 +- lib/std/math/math_nolibc/sin.c3 | 2 +- lib/std/math/math_nolibc/sincos.c3 | 2 +- lib/std/math/math_nolibc/tan.c3 | 2 +- lib/std/math/math_nolibc/trig.c3 | 2 +- lib/std/math/math_nolibc/trunc.c3 | 2 +- 22 files changed, 77 insertions(+), 22 deletions(-) diff --git a/lib/std/math/math_nolibc/__cos.c3 b/lib/std/math/math_nolibc/__cos.c3 index d2d588efc..44df4c5c4 100644 --- a/lib/std/math/math_nolibc/__cos.c3 +++ b/lib/std/math/math_nolibc/__cos.c3 @@ -1,4 +1,4 @@ -module std::math::nolibc @if(env::NO_LIBC); +module std::math::nolibc @if(env::NO_LIBC || $feature(C3_MATH)); /* origin: FreeBSD /usr/src/lib/msun/src/k_cos.c */ /* diff --git a/lib/std/math/math_nolibc/__cosdf.c3 b/lib/std/math/math_nolibc/__cosdf.c3 index 6b5977b2f..08e519f4a 100644 --- a/lib/std/math/math_nolibc/__cosdf.c3 +++ b/lib/std/math/math_nolibc/__cosdf.c3 @@ -1,4 +1,4 @@ -module std::math::nolibc @if(env::NO_LIBC); +module std::math::nolibc @if(env::NO_LIBC || $feature(C3_MATH)); /* origin: FreeBSD /usr/src/lib/msun/src/k_cosf.c */ /* diff --git a/lib/std/math/math_nolibc/__fmod.c3 b/lib/std/math/math_nolibc/__fmod.c3 index 2af1fb36c..1bc304b31 100644 --- a/lib/std/math/math_nolibc/__fmod.c3 +++ b/lib/std/math/math_nolibc/__fmod.c3 @@ -1,4 +1,4 @@ -module std::math::nolibc @if(env::NO_LIBC); +module std::math::nolibc @if(env::NO_LIBC || $feature(C3_MATH)); union DoubleInternal { diff --git a/lib/std/math/math_nolibc/__sin.c3 b/lib/std/math/math_nolibc/__sin.c3 index 2090fc77c..2f9e0bf59 100644 --- a/lib/std/math/math_nolibc/__sin.c3 +++ b/lib/std/math/math_nolibc/__sin.c3 @@ -1,4 +1,4 @@ -module std::math::nolibc @if(env::NO_LIBC); +module std::math::nolibc @if(env::NO_LIBC || $feature(C3_MATH)); /* origin: FreeBSD /usr/src/lib/msun/src/k_sin.c */ /* diff --git a/lib/std/math/math_nolibc/__sindf.c3 b/lib/std/math/math_nolibc/__sindf.c3 index 3ed9b936f..caac7314b 100644 --- a/lib/std/math/math_nolibc/__sindf.c3 +++ b/lib/std/math/math_nolibc/__sindf.c3 @@ -1,4 +1,4 @@ -module std::math::nolibc @if(env::NO_LIBC); +module std::math::nolibc @if(env::NO_LIBC || $feature(C3_MATH)); /* origin: FreeBSD /usr/src/lib/msun/src/k_sinf.c */ /* diff --git a/lib/std/math/math_nolibc/__tan.c3 b/lib/std/math/math_nolibc/__tan.c3 index 2dead46f9..3952d2a12 100644 --- a/lib/std/math/math_nolibc/__tan.c3 +++ b/lib/std/math/math_nolibc/__tan.c3 @@ -1,4 +1,4 @@ -module std::math::nolibc @if(env::NO_LIBC); +module std::math::nolibc @if(env::NO_LIBC || $feature(C3_MATH)); /* origin: FreeBSD /usr/src/lib/msun/src/k_tan.c */ /* diff --git a/lib/std/math/math_nolibc/__tandf.c3 b/lib/std/math/math_nolibc/__tandf.c3 index 8a03e6523..c6083f094 100644 --- a/lib/std/math/math_nolibc/__tandf.c3 +++ b/lib/std/math/math_nolibc/__tandf.c3 @@ -1,4 +1,4 @@ -module std::math::nolibc @if(env::NO_LIBC); +module std::math::nolibc @if(env::NO_LIBC || $feature(C3_MATH)); /* origin: FreeBSD /usr/src/lib/msun/src/k_tanf.c */ /* diff --git a/lib/std/math/math_nolibc/atan.c3 b/lib/std/math/math_nolibc/atan.c3 index 1a6e9a8d8..6e9e9de56 100644 --- a/lib/std/math/math_nolibc/atan.c3 +++ b/lib/std/math/math_nolibc/atan.c3 @@ -1,4 +1,16 @@ -module std::math::nolibc @if(env::NO_LIBC); +module std::math::nolibc @if(env::NO_LIBC || $feature(C3_MATH)); + +/* origin: FreeBSD /usr/src/lib/msun/src/s_atan.c */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ const double[*] ATANHI @private = { 4.63647609000806093515e-01, /* atan(0.5)hi 0x3FDDAC67, 0x0561BB4F */ @@ -89,6 +101,21 @@ fn double _atan(double x) @weak @extern("atan") @nostrip return sign ? -z : z; } +/* origin: FreeBSD /usr/src/lib/msun/src/s_atanf.c */ +/* + * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. + */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + const float[*] ATANHIF @private = { 4.6364760399e-01, /* atan(0.5)hi 0x3eed6338 */ 7.8539812565e-01, /* atan(1.0)hi 0x3f490fda */ @@ -175,6 +202,19 @@ fn float _atanf(float x) @weak @extern("atanf") @nostrip return sign ? -z : z; } +/* origin: FreeBSD /usr/src/lib/msun/src/e_atan2.c */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunSoft, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + * + */ + const PI_LO @private = 1.2246467991473531772E-16; /* 0x3CA1A626, 0x33145C07 */ macro void extract_words(double d, uint* hi, uint* lo) @private @@ -252,6 +292,21 @@ fn double _atan2(double y, double x) @weak @extern("atan2") @nostrip } } +/* origin: FreeBSD /usr/src/lib/msun/src/e_atan2f.c */ +/* + * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. + */ +/* + * ==================================================== + * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. + * + * Developed at SunPro, a Sun Microsystems, Inc. business. + * Permission to use, copy, modify, and distribute this + * software is freely granted, provided that this notice + * is preserved. + * ==================================================== + */ + const float PI_F @private = 3.1415927410e+00; /* 0x40490fdb */ const float PI_LO_F @private = -8.7422776573e-08; /* 0xb3bbbd2e */ diff --git a/lib/std/math/math_nolibc/ceil.c3 b/lib/std/math/math_nolibc/ceil.c3 index 4c0c3e046..0fd5ea500 100644 --- a/lib/std/math/math_nolibc/ceil.c3 +++ b/lib/std/math/math_nolibc/ceil.c3 @@ -1,4 +1,4 @@ -module std::math::nolibc @if(env::NO_LIBC); +module std::math::nolibc @if(env::NO_LIBC || $feature(C3_MATH)); fn double _ceil(double x) @weak @extern("ceil") @nostrip { diff --git a/lib/std/math/math_nolibc/cos.c3 b/lib/std/math/math_nolibc/cos.c3 index 2ac9bfabc..2b4cbac13 100644 --- a/lib/std/math/math_nolibc/cos.c3 +++ b/lib/std/math/math_nolibc/cos.c3 @@ -1,4 +1,4 @@ -module std::math::nolibc @if(env::NO_LIBC); +module std::math::nolibc @if(env::NO_LIBC || $feature(C3_MATH)); fn float _cosf(float x) @extern("cosf") @weak @nostrip { diff --git a/lib/std/math/math_nolibc/exp2.c3 b/lib/std/math/math_nolibc/exp2.c3 index f04fca9f2..df14507bc 100644 --- a/lib/std/math/math_nolibc/exp2.c3 +++ b/lib/std/math/math_nolibc/exp2.c3 @@ -1,4 +1,4 @@ -module std::math::nolibc @if(env::NO_LIBC); +module std::math::nolibc @if(env::NO_LIBC || $feature(C3_MATH)); macro uint _top12f(float x) @private => bitcast(x, uint) >> 20; diff --git a/lib/std/math/math_nolibc/floor.c3 b/lib/std/math/math_nolibc/floor.c3 index 475e17e49..274948fe1 100644 --- a/lib/std/math/math_nolibc/floor.c3 +++ b/lib/std/math/math_nolibc/floor.c3 @@ -1,4 +1,4 @@ -module std::math::nolibc @if(env::NO_LIBC); +module std::math::nolibc @if(env::NO_LIBC || $feature(C3_MATH)); fn double _floor(double x) @weak @extern("floor") @nostrip { diff --git a/lib/std/math/math_nolibc/math_nolibc.c3 b/lib/std/math/math_nolibc/math_nolibc.c3 index d36eed9e2..72f195cec 100644 --- a/lib/std/math/math_nolibc/math_nolibc.c3 +++ b/lib/std/math/math_nolibc/math_nolibc.c3 @@ -1,4 +1,4 @@ -module std::math::nolibc; +module std::math::nolibc @if(env::NO_LIBC || $feature(C3_MATH)); const double TOINT = 1 / math::DOUBLE_EPSILON; const double TOINT15 = 1.5 / math::DOUBLE_EPSILON; diff --git a/lib/std/math/math_nolibc/pow.c3 b/lib/std/math/math_nolibc/pow.c3 index 269fdabed..3637834b9 100644 --- a/lib/std/math/math_nolibc/pow.c3 +++ b/lib/std/math/math_nolibc/pow.c3 @@ -1,4 +1,4 @@ -module std::math::nolibc @if(env::NO_LIBC); +module std::math::nolibc @if(env::NO_LIBC || $feature(C3_MATH)); fn float powf_broken(float x, float f) @extern("powf") @weak @nostrip { diff --git a/lib/std/math/math_nolibc/rempi.c3 b/lib/std/math/math_nolibc/rempi.c3 index 812498131..66b8b90d8 100644 --- a/lib/std/math/math_nolibc/rempi.c3 +++ b/lib/std/math/math_nolibc/rempi.c3 @@ -1,4 +1,4 @@ -module std::math::nolibc @if(env::NO_LIBC); +module std::math::nolibc @if(env::NO_LIBC || $feature(C3_MATH)); import std::math; /* origin: FreeBSD /usr/src/lib/msun/src/e_rem_pio2f.c */ diff --git a/lib/std/math/math_nolibc/round.c3 b/lib/std/math/math_nolibc/round.c3 index ce6fdfcac..31ea82e58 100644 --- a/lib/std/math/math_nolibc/round.c3 +++ b/lib/std/math/math_nolibc/round.c3 @@ -1,4 +1,4 @@ -module std::math::nolibc @if(env::NO_LIBC); +module std::math::nolibc @if(env::NO_LIBC || $feature(C3_MATH)); fn double _round(double x) @extern("round") @weak @nostrip { diff --git a/lib/std/math/math_nolibc/scalbn.c3 b/lib/std/math/math_nolibc/scalbn.c3 index f8f63706a..ccd251c06 100644 --- a/lib/std/math/math_nolibc/scalbn.c3 +++ b/lib/std/math/math_nolibc/scalbn.c3 @@ -1,4 +1,4 @@ -module std::math::nolibc @if(env::NO_LIBC); +module std::math::nolibc @if(env::NO_LIBC || $feature(C3_MATH)); fn double _scalbn(double x, int n) @weak @extern("scalbn") @nostrip { diff --git a/lib/std/math/math_nolibc/sin.c3 b/lib/std/math/math_nolibc/sin.c3 index d895ca696..c91a8bae5 100644 --- a/lib/std/math/math_nolibc/sin.c3 +++ b/lib/std/math/math_nolibc/sin.c3 @@ -1,4 +1,4 @@ -module std::math::nolibc @if(env::NO_LIBC); +module std::math::nolibc @if(env::NO_LIBC || $feature(C3_MATH)); /* origin: FreeBSD /usr/src/lib/msun/src/s_sinf.c */ /* diff --git a/lib/std/math/math_nolibc/sincos.c3 b/lib/std/math/math_nolibc/sincos.c3 index 6c2aed421..70050ddfa 100644 --- a/lib/std/math/math_nolibc/sincos.c3 +++ b/lib/std/math/math_nolibc/sincos.c3 @@ -1,4 +1,4 @@ -module std::math::nolibc @if(env::NO_LIBC); +module std::math::nolibc @if(env::NO_LIBC || $feature(C3_MATH)); /* origin: FreeBSD /usr/src/lib/msun/src/s_sinf.c */ /* diff --git a/lib/std/math/math_nolibc/tan.c3 b/lib/std/math/math_nolibc/tan.c3 index 79ea73648..7d871d609 100644 --- a/lib/std/math/math_nolibc/tan.c3 +++ b/lib/std/math/math_nolibc/tan.c3 @@ -1,4 +1,4 @@ -module std::math::nolibc @if(env::NO_LIBC); +module std::math::nolibc @if(env::NO_LIBC || $feature(C3_MATH)); /* origin: FreeBSD /usr/src/lib/msun/src/s_tan.c */ /* diff --git a/lib/std/math/math_nolibc/trig.c3 b/lib/std/math/math_nolibc/trig.c3 index 334f3c3da..d3b0d7279 100644 --- a/lib/std/math/math_nolibc/trig.c3 +++ b/lib/std/math/math_nolibc/trig.c3 @@ -1,4 +1,4 @@ -module std::math::nolibc @if(env::NO_LIBC); +module std::math::nolibc @if(env::NO_LIBC || $feature(C3_MATH)); fn double sincos_broken(double x) @extern("sincos") @weak @nostrip { diff --git a/lib/std/math/math_nolibc/trunc.c3 b/lib/std/math/math_nolibc/trunc.c3 index c3065bb8f..c9fc4077f 100644 --- a/lib/std/math/math_nolibc/trunc.c3 +++ b/lib/std/math/math_nolibc/trunc.c3 @@ -1,4 +1,4 @@ -module std::math::nolibc @if(env::NO_LIBC); +module std::math::nolibc @if(env::NO_LIBC || $feature(C3_MATH)); fn double _trunc(double x) @weak @extern("trunc") @nostrip {