Skip to content

Commit

Permalink
add an almost complete libm implementation
Browse files Browse the repository at this point in the history
again taken from musl.

For now disabled:

 - floor, ceil: we have an asm implementation, but need to check if it's enough
 - various functions that mess with the floating point exception status.
  • Loading branch information
Christoph Hellwig committed Feb 4, 2013
1 parent 992944f commit eda9e0a
Show file tree
Hide file tree
Showing 218 changed files with 18,896 additions and 0 deletions.
211 changes: 211 additions & 0 deletions libc/build.mak
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,217 @@ libc += locale/wcsxfrm_l.o
libc += locale/wctrans_l.o
libc += locale/wctype_l.o

libc += math/__cos.o
libc += math/__cosdf.o
libc += math/__cosl.o
libc += math/__expo2.o
libc += math/__expo2f.o
libc += math/__fpclassify.o
libc += math/__fpclassifyf.o
libc += math/__fpclassifyl.o
libc += math/__invtrigl.o
libc += math/__polevll.o
libc += math/__rem_pio2.o
libc += math/__rem_pio2_large.o
libc += math/__rem_pio2f.o
libc += math/__rem_pio2l.o
libc += math/__signbit.o
libc += math/__signbitf.o
libc += math/__signbitl.o
libc += math/__sin.o
libc += math/__sindf.o
libc += math/__sinl.o
libc += math/__tan.o
libc += math/__tandf.o
libc += math/__tanl.o
libc += math/acos.o
libc += math/acosf.o
libc += math/acosh.o
libc += math/acoshf.o
libc += math/acoshl.o
libc += math/acosl.o
libc += math/asin.o
libc += math/asinf.o
libc += math/asinh.o
libc += math/asinhf.o
libc += math/asinhl.o
libc += math/asinl.o
libc += math/atan.o
libc += math/atan2.o
libc += math/atan2f.o
libc += math/atan2l.o
libc += math/atanf.o
libc += math/atanh.o
libc += math/atanhf.o
libc += math/atanhl.o
libc += math/atanl.o
libc += math/cbrt.o
libc += math/cbrtf.o
libc += math/cbrtl.o
#libc += math/ceil.o
libc += math/ceilf.o
libc += math/ceill.o
libc += math/copysign.o
libc += math/copysignf.o
libc += math/copysignl.o
libc += math/cos.o
libc += math/cosf.o
libc += math/cosh.o
libc += math/coshf.o
libc += math/coshl.o
libc += math/cosl.o
libc += math/erf.o
libc += math/erff.o
libc += math/erfl.o
libc += math/exp.o
libc += math/exp10.o
libc += math/exp10f.o
libc += math/exp10l.o
libc += math/exp2.o
libc += math/exp2f.o
libc += math/exp2l.o
libc += math/expf.o
libc += math/expl.o
libc += math/expm1.o
libc += math/expm1f.o
libc += math/expm1l.o
libc += math/fabs.o
libc += math/fabsf.o
libc += math/fabsl.o
libc += math/fdim.o
libc += math/fdimf.o
libc += math/fdiml.o
#libc += math/floor.o
libc += math/floorf.o
libc += math/floorl.o
#libc += math/fma.o
#libc += math/fmaf.o
#libc += math/fmal.o
libc += math/fmax.o
libc += math/fmaxf.o
libc += math/fmaxl.o
libc += math/fmin.o
libc += math/fminf.o
libc += math/fminl.o
libc += math/fmod.o
libc += math/fmodf.o
libc += math/fmodl.o
libc += math/frexp.o
libc += math/frexpf.o
libc += math/frexpl.o
libc += math/hypot.o
libc += math/hypotf.o
libc += math/hypotl.o
libc += math/ilogb.o
libc += math/ilogbf.o
libc += math/ilogbl.o
libc += math/j0.o
libc += math/j0f.o
libc += math/j1.o
libc += math/j1f.o
libc += math/jn.o
libc += math/jnf.o
libc += math/ldexp.o
libc += math/ldexpf.o
libc += math/ldexpl.o
libc += math/lgamma.o
libc += math/lgamma_r.o
libc += math/lgammaf.o
libc += math/lgammaf_r.o
libc += math/lgammal.o
#libc += math/llrint.o
#libc += math/llrintf.o
#libc += math/llrintl.o
libc += math/llround.o
libc += math/llroundf.o
libc += math/llroundl.o
libc += math/log.o
libc += math/log10.o
libc += math/log10f.o
libc += math/log10l.o
libc += math/log1p.o
libc += math/log1pf.o
libc += math/log1pl.o
libc += math/log2.o
libc += math/log2f.o
libc += math/log2l.o
libc += math/logb.o
libc += math/logbf.o
libc += math/logbl.o
libc += math/logf.o
libc += math/logl.o
#libc += math/lrint.o
#libc += math/lrintf.o
#libc += math/lrintl.o
libc += math/lround.o
libc += math/lroundf.o
libc += math/lroundl.o
libc += math/modf.o
libc += math/modff.o
libc += math/modfl.o
libc += math/nan.o
libc += math/nanf.o
libc += math/nanl.o
#libc += math/nearbyint.o
#libc += math/nearbyintf.o
#libc += math/nearbyintl.o
libc += math/nextafter.o
libc += math/nextafterf.o
libc += math/nextafterl.o
libc += math/nexttoward.o
libc += math/nexttowardf.o
libc += math/nexttowardl.o
libc += math/pow.o
libc += math/powf.o
libc += math/powl.o
libc += math/remainder.o
libc += math/remainderf.o
libc += math/remainderl.o
libc += math/remquo.o
libc += math/remquof.o
libc += math/remquol.o
libc += math/rint.o
libc += math/rintf.o
libc += math/rintl.o
libc += math/round.o
libc += math/roundf.o
libc += math/roundl.o
libc += math/scalb.o
libc += math/scalbf.o
libc += math/scalbln.o
libc += math/scalblnf.o
libc += math/scalblnl.o
libc += math/scalbn.o
libc += math/scalbnf.o
libc += math/scalbnl.o
libc += math/signgam.o
libc += math/significand.o
libc += math/significandf.o
libc += math/sin.o
libc += math/sincos.o
libc += math/sincosf.o
libc += math/sincosl.o
libc += math/sinf.o
libc += math/sinh.o
libc += math/sinhf.o
libc += math/sinhl.o
libc += math/sinl.o
libc += math/sqrt.o
libc += math/sqrtf.o
libc += math/sqrtl.o
libc += math/tan.o
libc += math/tanf.o
libc += math/tanh.o
libc += math/tanhf.o
libc += math/tanhl.o
libc += math/tanl.o
libc += math/tgamma.o
libc += math/tgammaf.o
libc += math/tgammal.o
libc += math/trunc.o
libc += math/truncf.o
libc += math/truncl.o

libc += misc/a64l.o
libc += misc/basename.o
libc += misc/dirname.o
Expand Down
176 changes: 176 additions & 0 deletions libc/internal/libm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
/* origin: FreeBSD /usr/src/lib/msun/src/math_private.h */
/*
* ====================================================
* 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.
* ====================================================
*/

#ifndef _LIBM_H
#define _LIBM_H

#include <stdint.h>
#include <float.h>
#include "math.h"
#include <complex.h>

#include "longdbl.h"

#include "libc.h"

union fshape {
float value;
uint32_t bits;
};

union dshape {
double value;
uint64_t bits;
};

#define FORCE_EVAL(x) do { \
if (sizeof(x) == sizeof(float)) { \
volatile float __x; \
__x = (x); \
} else if (sizeof(x) == sizeof(double)) { \
volatile double __x; \
__x = (x); \
} else { \
volatile long double __x; \
__x = (x); \
} \
} while(0)

/* Get two 32 bit ints from a double. */
#define EXTRACT_WORDS(hi,lo,d) \
do { \
union dshape __u; \
__u.value = (d); \
(hi) = __u.bits >> 32; \
(lo) = (uint32_t)__u.bits; \
} while (0)

/* Get a 64 bit int from a double. */
#define EXTRACT_WORD64(i,d) \
do { \
union dshape __u; \
__u.value = (d); \
(i) = __u.bits; \
} while (0)

/* Get the more significant 32 bit int from a double. */
#define GET_HIGH_WORD(i,d) \
do { \
union dshape __u; \
__u.value = (d); \
(i) = __u.bits >> 32; \
} while (0)

/* Get the less significant 32 bit int from a double. */
#define GET_LOW_WORD(i,d) \
do { \
union dshape __u; \
__u.value = (d); \
(i) = (uint32_t)__u.bits; \
} while (0)

/* Set a double from two 32 bit ints. */
#define INSERT_WORDS(d,hi,lo) \
do { \
union dshape __u; \
__u.bits = ((uint64_t)(hi) << 32) | (uint32_t)(lo); \
(d) = __u.value; \
} while (0)

/* Set a double from a 64 bit int. */
#define INSERT_WORD64(d,i) \
do { \
union dshape __u; \
__u.bits = (i); \
(d) = __u.value; \
} while (0)

/* Set the more significant 32 bits of a double from an int. */
#define SET_HIGH_WORD(d,hi) \
do { \
union dshape __u; \
__u.value = (d); \
__u.bits &= 0xffffffff; \
__u.bits |= (uint64_t)(hi) << 32; \
(d) = __u.value; \
} while (0)

/* Set the less significant 32 bits of a double from an int. */
#define SET_LOW_WORD(d,lo) \
do { \
union dshape __u; \
__u.value = (d); \
__u.bits &= 0xffffffff00000000ull; \
__u.bits |= (uint32_t)(lo); \
(d) = __u.value; \
} while (0)

/* Get a 32 bit int from a float. */
#define GET_FLOAT_WORD(i,d) \
do { \
union fshape __u; \
__u.value = (d); \
(i) = __u.bits; \
} while (0)

/* Set a float from a 32 bit int. */
#define SET_FLOAT_WORD(d,i) \
do { \
union fshape __u; \
__u.bits = (i); \
(d) = __u.value; \
} while (0)

/* fdlibm kernel functions */

int __rem_pio2_large(double*,double*,int,int,int);

int __rem_pio2(double,double*);
double __sin(double,double,int);
double __cos(double,double);
double __tan(double,double,int);
double __expo2(double);
double complex __ldexp_cexp(double complex,int);

int __rem_pio2f(float,double*);
float __sindf(double);
float __cosdf(double);
float __tandf(double,int);
float __expo2f(float);
float complex __ldexp_cexpf(float complex,int);

int __rem_pio2l(long double, long double *);
long double __sinl(long double, long double, int);
long double __cosl(long double, long double);
long double __tanl(long double, long double, int);

/* polynomial evaluation */
long double __polevll(long double, const long double *, int);
long double __p1evll(long double, const long double *, int);

#if 0
/* Attempt to get strict C99 semantics for assignment with non-C99 compilers. */
#define STRICT_ASSIGN(type, lval, rval) do { \
volatile type __v = (rval); \
(lval) = __v; \
} while (0)
#else
/* Should work with -fexcess-precision=standard (>=gcc-4.5) or -ffloat-store */
#define STRICT_ASSIGN(type, lval, rval) ((lval) = (type)(rval))
#endif

/* should be in math.h, which we can't include at the moment */
double scalbn(double x, int exp);
int __isnan(double x);


#endif

0 comments on commit eda9e0a

Please sign in to comment.