diff options
-rw-r--r-- | builder/picolibc.go | 20 | ||||
-rw-r--r-- | compiler/alias.go | 43 | ||||
-rw-r--r-- | compiler/compiler.go | 2 | ||||
-rw-r--r-- | compiler/intrinsics.go | 7 |
4 files changed, 27 insertions, 45 deletions
diff --git a/builder/picolibc.go b/builder/picolibc.go index d9025a41e..d0786ee3a 100644 --- a/builder/picolibc.go +++ b/builder/picolibc.go @@ -28,6 +28,8 @@ var Picolibc = Library{ "-DHAVE_ALIAS_ATTRIBUTE", "-DTINY_STDIO", "-D_IEEE_LIBM", + "-D__OBSOLETE_MATH_FLOAT=1", // use old math code that doesn't expect a FPU + "-D__OBSOLETE_MATH_DOUBLE=0", "-nostdlibinc", "-isystem", newlibDir + "/libc/include", "-I" + newlibDir + "/libc/tinystdio", @@ -325,6 +327,24 @@ var picolibcSources = []string{ "libm/common/s_scalbln.c", "libm/common/s_signbit.c", "libm/common/s_trunc.c", + "libm/common/exp.c", + "libm/common/exp2.c", + "libm/common/exp_data.c", + "libm/common/math_err_with_errno.c", + "libm/common/math_err_xflow.c", + "libm/common/math_err_uflow.c", + "libm/common/math_err_oflow.c", + "libm/common/math_err_divzero.c", + "libm/common/math_err_invalid.c", + "libm/common/math_err_may_uflow.c", + "libm/common/math_err_check_uflow.c", + "libm/common/math_err_check_oflow.c", + "libm/common/log.c", + "libm/common/log_data.c", + "libm/common/log2.c", + "libm/common/log2_data.c", + "libm/common/pow.c", + "libm/common/pow_log_data.c", "libm/math/e_acos.c", "libm/math/e_acosh.c", diff --git a/compiler/alias.go b/compiler/alias.go index 50e3f101a..9e88e3c6a 100644 --- a/compiler/alias.go +++ b/compiler/alias.go @@ -25,53 +25,10 @@ var stdlibAliases = map[string]string{ "crypto/sha512.blockAMD64": "crypto/sha512.blockGeneric", // math package - "math.Asin": "math.asin", - "math.Asinh": "math.asinh", - "math.Acos": "math.acos", - "math.Acosh": "math.acosh", - "math.Atan": "math.atan", - "math.Atanh": "math.atanh", - "math.Atan2": "math.atan2", - "math.Cbrt": "math.cbrt", - "math.Ceil": "math.ceil", - "math.archCeil": "math.ceil", - "math.Cos": "math.cos", - "math.Cosh": "math.cosh", - "math.Erf": "math.erf", - "math.Erfc": "math.erfc", - "math.Exp": "math.exp", - "math.archExp": "math.exp", - "math.Expm1": "math.expm1", - "math.Exp2": "math.exp2", - "math.archExp2": "math.exp2", - "math.Floor": "math.floor", - "math.archFloor": "math.floor", - "math.Frexp": "math.frexp", - "math.Hypot": "math.hypot", "math.archHypot": "math.hypot", - "math.Ldexp": "math.ldexp", - "math.Log": "math.log", - "math.archLog": "math.log", - "math.Log1p": "math.log1p", - "math.Log10": "math.log10", - "math.Log2": "math.log2", - "math.Max": "math.max", "math.archMax": "math.max", - "math.Min": "math.min", "math.archMin": "math.min", - "math.Mod": "math.mod", - "math.Modf": "math.modf", "math.archModf": "math.modf", - "math.Pow": "math.pow", - "math.Remainder": "math.remainder", - "math.Sin": "math.sin", - "math.Sinh": "math.sinh", - "math.Sqrt": "math.sqrt", - "math.archSqrt": "math.sqrt", - "math.Tan": "math.tan", - "math.Tanh": "math.tanh", - "math.Trunc": "math.trunc", - "math.archTrunc": "math.trunc", } // createAlias implements the function (in the builder) as a call to the alias diff --git a/compiler/compiler.go b/compiler/compiler.go index 8443c8f27..bbaf6432f 100644 --- a/compiler/compiler.go +++ b/compiler/compiler.go @@ -791,6 +791,8 @@ func (c *compilerContext) createPackage(irbuilder llvm.Builder, pkg *ssa.Package // Create the function definition. b := newBuilder(c, irbuilder, member) if _, ok := mathToLLVMMapping[member.RelString(nil)]; ok { + // The body of this function (if there is one) is ignored and + // replaced with a LLVM intrinsic call. b.defineMathOp() continue } diff --git a/compiler/intrinsics.go b/compiler/intrinsics.go index 76bdacffb..0203d441b 100644 --- a/compiler/intrinsics.go +++ b/compiler/intrinsics.go @@ -81,9 +81,12 @@ func (b *builder) createMemoryZeroImpl() { } var mathToLLVMMapping = map[string]string{ - "math.Sqrt": "llvm.sqrt.f64", - "math.Floor": "llvm.floor.f64", "math.Ceil": "llvm.ceil.f64", + "math.Exp": "llvm.exp.f64", + "math.Exp2": "llvm.exp2.f64", + "math.Floor": "llvm.floor.f64", + "math.Log": "llvm.log.f64", + "math.Sqrt": "llvm.sqrt.f64", "math.Trunc": "llvm.trunc.f64", } |