diff --git a/c/math/cmplx/complex.go b/c/math/cmplx/complex.go index c24a276e..bae82a19 100644 --- a/c/math/cmplx/complex.go +++ b/c/math/cmplx/complex.go @@ -87,3 +87,65 @@ func Tan(z complex128) complex128 func Tanh(z complex128) complex128 // ----------------------------------------------------------------------------- + +//go:linkname Absf C.cabsf +func Absf(z complex64) float32 + +//go:linkname Acosf C.cacosf +func Acosf(z complex64) complex64 + +//go:linkname Acoshf C.cacoshf +func Acoshf(z complex64) complex64 + +//go:linkname Asinf C.casinf +func Asinf(z complex64) complex64 + +//go:linkname Asinhf C.casinhf +func Asinhf(z complex64) complex64 + +//go:linkname Atanf C.catanf +func Atanf(z complex64) complex64 + +//go:linkname Atanhf C.catanhf +func Atanhf(z complex64) complex64 + +//go:linkname Cosf C.ccosf +func Cosf(z complex64) complex64 + +//go:linkname Coshf C.ccoshf +func Coshf(z complex64) complex64 + +//go:linkname Expf C.cexpf +func Expf(z complex64) complex64 + +//go:linkname Logf C.clogf +func Logf(z complex64) complex64 + +//go:linkname Log10f C.clog10f +func Log10f(z complex64) complex64 + +//go:linkname Argf C.cargf +func Argf(z complex64) float32 + +//go:linkname Phasef C.cargf +func Phasef(z complex64) float32 + +//go:linkname Powf C.cpowf +func Powf(x, y complex64) complex64 + +//go:linkname Sinf C.csinf +func Sinf(z complex64) complex64 + +//go:linkname Sinhf C.csinhf +func Sinhf(z complex64) complex64 + +//go:linkname Sqrtf C.csqrtf +func Sqrtf(z complex64) complex64 + +//go:linkname Tanf C.ctanf +func Tanf(z complex64) complex64 + +//go:linkname Tanhf C.ctanhf +func Tanhf(z complex64) complex64 + +// ----------------------------------------------------------------------------- diff --git a/cl/_testlibc/complex/in.go b/cl/_testlibc/complex/in.go new file mode 100644 index 00000000..f40cb43e --- /dev/null +++ b/cl/_testlibc/complex/in.go @@ -0,0 +1,12 @@ +package main + +import ( + "github.com/goplus/llgo/c/math/cmplx" +) + +func main() { + re := float32(3.0) + im := float32(4.0) + c := complex(re, im) + println("abs(3+4i):", cmplx.Absf(c)) +} diff --git a/cl/_testlibc/complex/out.ll b/cl/_testlibc/complex/out.ll new file mode 100644 index 00000000..45bbb198 --- /dev/null +++ b/cl/_testlibc/complex/out.ll @@ -0,0 +1,59 @@ +; ModuleID = 'main' +source_filename = "main" + +%"github.com/goplus/llgo/internal/runtime.String" = type { ptr, i64 } + +@"main.init$guard" = global i1 false, align 1 +@__llgo_argc = global i32 0, align 4 +@__llgo_argv = global ptr null, align 8 +@0 = private unnamed_addr constant [10 x i8] c"abs(3+4i):", align 1 + +define void @main.init() { +_llgo_0: + %0 = load i1, ptr @"main.init$guard", align 1 + br i1 %0, label %_llgo_2, label %_llgo_1 + +_llgo_1: ; preds = %_llgo_0 + store i1 true, ptr @"main.init$guard", align 1 + br label %_llgo_2 + +_llgo_2: ; preds = %_llgo_1, %_llgo_0 + ret void +} + +define i32 @main(i32 %0, ptr %1) { +_llgo_0: + store i32 %0, ptr @__llgo_argc, align 4 + store ptr %1, ptr @__llgo_argv, align 8 + call void @"github.com/goplus/llgo/internal/runtime.init"() + call void @main.init() + %2 = alloca { float, float }, align 8 + %3 = getelementptr inbounds { float, float }, ptr %2, i32 0, i32 0 + store float 3.000000e+00, ptr %3, align 4 + %4 = getelementptr inbounds { float, float }, ptr %2, i32 0, i32 1 + store float 4.000000e+00, ptr %4, align 4 + %5 = load { float, float }, ptr %2, align 4 + %6 = call float @cabsf({ float, float } %5) + %7 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 + %8 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %7, i32 0, i32 0 + store ptr @0, ptr %8, align 8 + %9 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %7, i32 0, i32 1 + store i64 10, ptr %9, align 4 + %10 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %7, align 8 + call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %10) + call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) + %11 = fpext float %6 to double + call void @"github.com/goplus/llgo/internal/runtime.PrintFloat"(double %11) + call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10) + ret i32 0 +} + +declare void @"github.com/goplus/llgo/internal/runtime.init"() + +declare float @cabsf({ float, float }) + +declare void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String") + +declare void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8) + +declare void @"github.com/goplus/llgo/internal/runtime.PrintFloat"(double) diff --git a/cl/_testlibgo/complex/in.go b/cl/_testlibgo/complex/in.go index 7610e171..5350a241 100644 --- a/cl/_testlibgo/complex/in.go +++ b/cl/_testlibgo/complex/in.go @@ -5,5 +5,8 @@ import ( ) func main() { - println("abs(3+4i):", cmplx.Abs(3+4i)) + re := 3.0 + im := 4.0 + c := complex(re, im) + println("abs(3+4i):", cmplx.Abs(c)) } diff --git a/cl/_testlibgo/complex/out.ll b/cl/_testlibgo/complex/out.ll index abd63e4e..15a7c871 100644 --- a/cl/_testlibgo/complex/out.ll +++ b/cl/_testlibgo/complex/out.ll @@ -28,16 +28,22 @@ _llgo_0: store ptr %1, ptr @__llgo_argv, align 8 call void @"github.com/goplus/llgo/internal/runtime.init"() call void @main.init() - %2 = call double @"math/cmplx.Abs"({ double, double } { double 3.000000e+00, double 4.000000e+00 }) - %3 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 - %4 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %3, i32 0, i32 0 - store ptr @0, ptr %4, align 8 - %5 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %3, i32 0, i32 1 - store i64 10, ptr %5, align 4 - %6 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %3, align 8 - call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %6) + %2 = alloca { double, double }, align 8 + %3 = getelementptr inbounds { double, double }, ptr %2, i32 0, i32 0 + store double 3.000000e+00, ptr %3, align 8 + %4 = getelementptr inbounds { double, double }, ptr %2, i32 0, i32 1 + store double 4.000000e+00, ptr %4, align 8 + %5 = load { double, double }, ptr %2, align 8 + %6 = call double @"math/cmplx.Abs"({ double, double } %5) + %7 = alloca %"github.com/goplus/llgo/internal/runtime.String", align 8 + %8 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %7, i32 0, i32 0 + store ptr @0, ptr %8, align 8 + %9 = getelementptr inbounds %"github.com/goplus/llgo/internal/runtime.String", ptr %7, i32 0, i32 1 + store i64 10, ptr %9, align 4 + %10 = load %"github.com/goplus/llgo/internal/runtime.String", ptr %7, align 8 + call void @"github.com/goplus/llgo/internal/runtime.PrintString"(%"github.com/goplus/llgo/internal/runtime.String" %10) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 32) - call void @"github.com/goplus/llgo/internal/runtime.PrintFloat"(double %2) + call void @"github.com/goplus/llgo/internal/runtime.PrintFloat"(double %6) call void @"github.com/goplus/llgo/internal/runtime.PrintByte"(i8 10) ret i32 0 }