diff --git a/cbits/musl/__math_divzero.c b/cbits/musl/__math_divzero.c index 59d213500..568ee07cc 100644 --- a/cbits/musl/__math_divzero.c +++ b/cbits/musl/__math_divzero.c @@ -1,6 +1,6 @@ #include "libm.h" -double __math_divzero(uint32_t sign) +double __kadena_math_divzero(uint32_t sign) { return fp_barrier(sign ? -1.0 : 1.0) / 0.0; } diff --git a/cbits/musl/__math_invalid.c b/cbits/musl/__math_invalid.c index 177404900..ca1f3aff9 100644 --- a/cbits/musl/__math_invalid.c +++ b/cbits/musl/__math_invalid.c @@ -1,6 +1,6 @@ #include "libm.h" -double __math_invalid(double x) +double __kadena_math_invalid(double x) { return (x - x) / (x - x); } diff --git a/cbits/musl/__math_oflow.c b/cbits/musl/__math_oflow.c index c85dbf982..cfc67dab3 100644 --- a/cbits/musl/__math_oflow.c +++ b/cbits/musl/__math_oflow.c @@ -1,6 +1,6 @@ #include "libm.h" -double __math_oflow(uint32_t sign) +double __kadena_math_oflow(uint32_t sign) { - return __math_xflow(sign, 0x1p769); + return __kadena_math_xflow(sign, 0x1p769); } diff --git a/cbits/musl/__math_uflow.c b/cbits/musl/__math_uflow.c index b90594aee..cb2860343 100644 --- a/cbits/musl/__math_uflow.c +++ b/cbits/musl/__math_uflow.c @@ -1,6 +1,6 @@ #include "libm.h" -double __math_uflow(uint32_t sign) +double __kadena_math_uflow(uint32_t sign) { - return __math_xflow(sign, 0x1p-767); + return __kadena_math_xflow(sign, 0x1p-767); } diff --git a/cbits/musl/__math_xflow.c b/cbits/musl/__math_xflow.c index 744203c4c..5defc0d21 100644 --- a/cbits/musl/__math_xflow.c +++ b/cbits/musl/__math_xflow.c @@ -1,6 +1,6 @@ #include "libm.h" -double __math_xflow(uint32_t sign, double y) +double __kadena_math_xflow(uint32_t sign, double y) { return eval_as_double(fp_barrier(sign ? -y : y) * y); } diff --git a/cbits/musl/exp.c b/cbits/musl/exp.c index 7ebb4753a..8a5633148 100644 --- a/cbits/musl/exp.c +++ b/cbits/musl/exp.c @@ -11,15 +11,15 @@ #include "exp_data.h" #define N (1 << EXP_TABLE_BITS) -#define InvLn2N __exp_data.invln2N -#define NegLn2hiN __exp_data.negln2hiN -#define NegLn2loN __exp_data.negln2loN -#define Shift __exp_data.shift -#define T __exp_data.tab -#define C2 __exp_data.poly[5 - EXP_POLY_ORDER] -#define C3 __exp_data.poly[6 - EXP_POLY_ORDER] -#define C4 __exp_data.poly[7 - EXP_POLY_ORDER] -#define C5 __exp_data.poly[8 - EXP_POLY_ORDER] +#define InvLn2N __kadena_exp_data.invln2N +#define NegLn2hiN __kadena_exp_data.negln2hiN +#define NegLn2loN __kadena_exp_data.negln2loN +#define Shift __kadena_exp_data.shift +#define T __kadena_exp_data.tab +#define C2 __kadena_exp_data.poly[5 - EXP_POLY_ORDER] +#define C3 __kadena_exp_data.poly[6 - EXP_POLY_ORDER] +#define C4 __kadena_exp_data.poly[7 - EXP_POLY_ORDER] +#define C5 __kadena_exp_data.poly[8 - EXP_POLY_ORDER] /* Handle cases that may overflow or underflow when computing the result that is scale*(1+TMP) without intermediate rounding. The bit representation of @@ -87,9 +87,9 @@ double musl_exp(double x) if (abstop >= top12(INFINITY)) return 1.0 + x; if (asuint64(x) >> 63) - return __math_uflow(0); + return __kadena_math_uflow(0); else - return __math_oflow(0); + return __kadena_math_oflow(0); } /* Large x is special cased below. */ abstop = 0; diff --git a/cbits/musl/exp_data.c b/cbits/musl/exp_data.c index 21be0146a..33cc0fab4 100644 --- a/cbits/musl/exp_data.c +++ b/cbits/musl/exp_data.c @@ -9,7 +9,7 @@ #define N (1 << EXP_TABLE_BITS) -const struct exp_data __exp_data = { +const struct exp_data __kadena_exp_data = { // N/ln2 .invln2N = 0x1.71547652b82fep0 * N, // -ln2/N diff --git a/cbits/musl/exp_data.h b/cbits/musl/exp_data.h index a63f7935d..4edff5600 100644 --- a/cbits/musl/exp_data.h +++ b/cbits/musl/exp_data.h @@ -21,6 +21,6 @@ extern const struct exp_data { double exp2_shift; double exp2_poly[EXP2_POLY_ORDER]; uint64_t tab[2*(1 << EXP_TABLE_BITS)]; -} __exp_data; +} __kadena_exp_data; #endif diff --git a/cbits/musl/libm.h b/cbits/musl/libm.h index 3924238ca..11bc25689 100644 --- a/cbits/musl/libm.h +++ b/cbits/musl/libm.h @@ -253,11 +253,11 @@ float __math_uflowf(uint32_t); float __math_oflowf(uint32_t); float __math_divzerof(uint32_t); float __math_invalidf(float); -double __math_xflow(uint32_t, double); -double __math_uflow(uint32_t); -double __math_oflow(uint32_t); -double __math_divzero(uint32_t); -double __math_invalid(double); +double __kadena_math_xflow(uint32_t, double); +double __kadena_math_uflow(uint32_t); +double __kadena_math_oflow(uint32_t); +double __kadena_math_divzero(uint32_t); +double __kadena_math_invalid(double); #if LDBL_MANT_DIG != DBL_MANT_DIG long double __math_invalidl(long double); #endif diff --git a/cbits/musl/log.c b/cbits/musl/log.c index dd1b297ff..443cfccea 100644 --- a/cbits/musl/log.c +++ b/cbits/musl/log.c @@ -10,12 +10,12 @@ #include "libm.h" #include "log_data.h" -#define T __log_data.tab -#define T2 __log_data.tab2 -#define B __log_data.poly1 -#define A __log_data.poly -#define Ln2hi __log_data.ln2hi -#define Ln2lo __log_data.ln2lo +#define T __kadena_log_data.tab +#define T2 __kadena_log_data.tab2 +#define B __kadena_log_data.poly1 +#define A __kadena_log_data.poly +#define Ln2hi __kadena_log_data.ln2hi +#define Ln2lo __kadena_log_data.ln2lo #define N (1 << LOG_TABLE_BITS) #define OFF 0x3fe6000000000000 @@ -63,11 +63,11 @@ double musl_log(double x) if (predict_false(top - 0x0010 >= 0x7ff0 - 0x0010)) { /* x < 0x1p-1022 or inf or nan. */ if (ix * 2 == 0) - return __math_divzero(1); + return __kadena_math_divzero(1); if (ix == asuint64(INFINITY)) /* log(inf) == inf. */ return x; if ((top & 0x8000) || (top & 0x7ff0) == 0x7ff0) - return __math_invalid(x); + return __kadena_math_invalid(x); /* x is subnormal, normalize it. */ ix = asuint64(x * 0x1p52); ix -= 52ULL << 52; diff --git a/cbits/musl/log_data.c b/cbits/musl/log_data.c index 1a6ec712a..70322b4df 100644 --- a/cbits/musl/log_data.c +++ b/cbits/musl/log_data.c @@ -9,7 +9,7 @@ #define N (1 << LOG_TABLE_BITS) -const struct log_data __log_data = { +const struct log_data __kadena_log_data = { .ln2hi = 0x1.62e42fefa3800p-1, .ln2lo = 0x1.ef35793c76730p-45, .poly1 = { diff --git a/cbits/musl/log_data.h b/cbits/musl/log_data.h index 47a0dcebb..8d26fcff3 100644 --- a/cbits/musl/log_data.h +++ b/cbits/musl/log_data.h @@ -23,6 +23,6 @@ extern const struct log_data { double chi, clo; } tab2[1 << LOG_TABLE_BITS]; #endif -} __log_data; +} __kadena_log_data; #endif diff --git a/cbits/musl/pow.c b/cbits/musl/pow.c index 04f1ef89e..9c730f7b7 100644 --- a/cbits/musl/pow.c +++ b/cbits/musl/pow.c @@ -18,10 +18,10 @@ relerr_log: 1.3 * 2^-68 (Relative error of log, 1.5 * 2^-68 without fma) ulperr_exp: 0.509 ULP (ULP error of exp, 0.511 ULP without fma) */ -#define T __pow_log_data.tab -#define A __pow_log_data.poly -#define Ln2hi __pow_log_data.ln2hi -#define Ln2lo __pow_log_data.ln2lo +#define T __kadena_pow_log_data.tab +#define A __kadena_pow_log_data.poly +#define Ln2hi __kadena_pow_log_data.ln2hi +#define Ln2lo __kadena_pow_log_data.ln2lo #define N (1 << POW_LOG_TABLE_BITS) #define OFF 0x3fe6955500000000 @@ -104,16 +104,16 @@ static inline double_t log_inline(uint64_t ix, double_t *tail) #undef N #undef T #define N (1 << EXP_TABLE_BITS) -#define InvLn2N __exp_data.invln2N -#define NegLn2hiN __exp_data.negln2hiN -#define NegLn2loN __exp_data.negln2loN -#define Shift __exp_data.shift -#define T __exp_data.tab -#define C2 __exp_data.poly[5 - EXP_POLY_ORDER] -#define C3 __exp_data.poly[6 - EXP_POLY_ORDER] -#define C4 __exp_data.poly[7 - EXP_POLY_ORDER] -#define C5 __exp_data.poly[8 - EXP_POLY_ORDER] -#define C6 __exp_data.poly[9 - EXP_POLY_ORDER] +#define InvLn2N __kadena_exp_data.invln2N +#define NegLn2hiN __kadena_exp_data.negln2hiN +#define NegLn2loN __kadena_exp_data.negln2loN +#define Shift __kadena_exp_data.shift +#define T __kadena_exp_data.tab +#define C2 __kadena_exp_data.poly[5 - EXP_POLY_ORDER] +#define C3 __kadena_exp_data.poly[6 - EXP_POLY_ORDER] +#define C4 __kadena_exp_data.poly[7 - EXP_POLY_ORDER] +#define C5 __kadena_exp_data.poly[8 - EXP_POLY_ORDER] +#define C6 __kadena_exp_data.poly[9 - EXP_POLY_ORDER] /* Handle cases that may overflow or underflow when computing the result that is scale*(1+TMP) without intermediate rounding. The bit representation of @@ -183,9 +183,9 @@ static inline double exp_inline(double_t x, double_t xtail, uint32_t sign_bias) if (abstop >= top12(1024.0)) { /* Note: inf and nan are already handled. */ if (asuint64(x) >> 63) - return __math_uflow(sign_bias); + return __kadena_math_uflow(sign_bias); else - return __math_oflow(sign_bias); + return __kadena_math_oflow(sign_bias); } /* Large x is special cased below. */ abstop = 0; @@ -296,7 +296,7 @@ double musl_pow(double x, double y) /* Finite x < 0. */ int yint = checkint(iy); if (yint == 0) - return __math_invalid(x); + return __kadena_math_invalid(x); if (yint == 1) sign_bias = SIGN_BIAS; ix &= 0x7fffffffffffffff; @@ -315,8 +315,8 @@ double musl_pow(double x, double y) return 1.0; } return (ix > asuint64(1.0)) == (topy < 0x800) ? - __math_oflow(0) : - __math_uflow(0); + __kadena_math_oflow(0) : + __kadena_math_uflow(0); } if (topx == 0) { /* Normalize subnormal x so exponent becomes negative. */ diff --git a/cbits/musl/pow_data.c b/cbits/musl/pow_data.c index 81e760de1..c0517648b 100644 --- a/cbits/musl/pow_data.c +++ b/cbits/musl/pow_data.c @@ -9,7 +9,7 @@ #define N (1 << POW_LOG_TABLE_BITS) -const struct pow_log_data __pow_log_data = { +const struct pow_log_data __kadena_pow_log_data = { .ln2hi = 0x1.62e42fefa3800p-1, .ln2lo = 0x1.ef35793c76730p-45, .poly = { diff --git a/cbits/musl/pow_data.h b/cbits/musl/pow_data.h index 5f482c1f4..c94ad6891 100644 --- a/cbits/musl/pow_data.h +++ b/cbits/musl/pow_data.h @@ -17,6 +17,6 @@ extern const struct pow_log_data { struct { double invc, pad, logc, logctail; } tab[1 << POW_LOG_TABLE_BITS]; -} __pow_log_data; +} __kadena_pow_log_data; #endif diff --git a/cbits/musl/sqrt.c b/cbits/musl/sqrt.c index 0aa61b42a..dbd7797ac 100644 --- a/cbits/musl/sqrt.c +++ b/cbits/musl/sqrt.c @@ -35,7 +35,7 @@ double musl_sqrt(double x) if (ix == 0x7ff0000000000000) return x; if (ix > 0x7ff0000000000000) - return __math_invalid(x); + return __kadena_math_invalid(x); /* x is subnormal, normalize it. */ ix = asuint64(x * 0x1p52); top = ix >> 52; @@ -109,7 +109,7 @@ double musl_sqrt(double x) uint64_t r, s, d, u, i; i = (ix >> 46) % 128; - r = (uint32_t)__rsqrt_tab[i] << 16; + r = (uint32_t)__kadena_rsqrt_tab[i] << 16; /* |r sqrt(m) - 1| < 0x1.fdp-9 */ s = mul32(m>>32, r); /* |s/sqrt(m) - 1| < 0x1.fdp-9 */ diff --git a/cbits/musl/sqrt_data.c b/cbits/musl/sqrt_data.c index 61bc22f43..8c22f1972 100644 --- a/cbits/musl/sqrt_data.c +++ b/cbits/musl/sqrt_data.c @@ -1,5 +1,5 @@ #include "sqrt_data.h" -const uint16_t __rsqrt_tab[128] = { +const uint16_t __kadena_rsqrt_tab[128] = { 0xb451,0xb2f0,0xb196,0xb044,0xaef9,0xadb6,0xac79,0xab43, 0xaa14,0xa8eb,0xa7c8,0xa6aa,0xa592,0xa480,0xa373,0xa26b, 0xa168,0xa06a,0x9f70,0x9e7b,0x9d8a,0x9c9d,0x9bb5,0x9ad1, diff --git a/cbits/musl/sqrt_data.h b/cbits/musl/sqrt_data.h index 7b4bff946..3280296c9 100644 --- a/cbits/musl/sqrt_data.h +++ b/cbits/musl/sqrt_data.h @@ -6,8 +6,8 @@ /* if x in [1,2): i = (int)(64*x); if x in [2,4): i = (int)(32*x-64); - __rsqrt_tab[i]*2^-16 is estimating 1/sqrt(x) with small relative error: - |__rsqrt_tab[i]*0x1p-16*sqrt(x) - 1| < -0x1.fdp-9 < 2^-8 */ -extern const uint16_t __rsqrt_tab[128]; + __kadena_rsqrt_tab[i]*2^-16 is estimating 1/sqrt(x) with small relative error: + |__kadena_rsqrt_tab[i]*0x1p-16*sqrt(x) - 1| < -0x1.fdp-9 < 2^-8 */ +extern const uint16_t __kadena_rsqrt_tab[128]; #endif diff --git a/tests/pact/ops.repl b/tests/pact/ops.repl index eb55fe96b..6c34a78b5 100644 --- a/tests/pact/ops.repl +++ b/tests/pact/ops.repl @@ -260,6 +260,7 @@ (expect "ln 16.0" 2.772588722239781144907055931980721652507781982421875 (ln 16.0)) (expect "ln 15" 2.708050201102210063908160009304992854595184326171875 (ln 15)) (expect "ln 15.0" 2.708050201102210063908160009304992854595184326171875 (ln 15.0)) +(expect "ln 60" 4.09434456222210041431708305026404559612274169921875 (ln 60)) "===== math.exp" (expect "exp 0" 1.0 (exp 0))