Skip to content
This repository was archived by the owner on Jan 9, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cbits/musl/__math_divzero.c
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 1 addition & 1 deletion cbits/musl/__math_invalid.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "libm.h"

double __math_invalid(double x)
double __kadena_math_invalid(double x)
{
return (x - x) / (x - x);
}
4 changes: 2 additions & 2 deletions cbits/musl/__math_oflow.c
Original file line number Diff line number Diff line change
@@ -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);
}
4 changes: 2 additions & 2 deletions cbits/musl/__math_uflow.c
Original file line number Diff line number Diff line change
@@ -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);
}
2 changes: 1 addition & 1 deletion cbits/musl/__math_xflow.c
Original file line number Diff line number Diff line change
@@ -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);
}
22 changes: 11 additions & 11 deletions cbits/musl/exp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion cbits/musl/exp_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cbits/musl/exp_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 5 additions & 5 deletions cbits/musl/libm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions cbits/musl/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion cbits/musl/log_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion cbits/musl/log_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ extern const struct log_data {
double chi, clo;
} tab2[1 << LOG_TABLE_BITS];
#endif
} __log_data;
} __kadena_log_data;

#endif
38 changes: 19 additions & 19 deletions cbits/musl/pow.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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. */
Expand Down
2 changes: 1 addition & 1 deletion cbits/musl/pow_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion cbits/musl/pow_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions cbits/musl/sqrt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion cbits/musl/sqrt_data.c
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
6 changes: 3 additions & 3 deletions cbits/musl/sqrt_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions tests/pact/ops.repl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down