Skip to content

Commit d75039a

Browse files
committed
compiler: fix 64-bit sin and cos on AVR
1 parent b757cb5 commit d75039a

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

compiler/intrinsics.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,17 @@ func (b *builder) defineMathOp() bool {
201201
if !ok {
202202
return false
203203
}
204+
if strings.HasPrefix(b.Triple, "avr") {
205+
// LLVM assumes the traditional AVR ABI where double is 32 bits and
206+
// therefore does not provide f64 runtime libcalls for sin and cos.
207+
// TinyGo uses 64-bit doubles on AVR, which picolibc supports directly.
208+
switch b.fn.Name() {
209+
case "Cos":
210+
llvmName = "cos"
211+
case "Sin":
212+
llvmName = "sin"
213+
}
214+
}
204215
if strings.HasSuffix(b.Triple, "-wasi") || llvmutil.Version() < 19 {
205216
// We don't have a real libc for wasip2. Until that is fixed, we need to
206217
// limit math intrinsics on WASI to a subset supported natively in

main_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,10 +370,6 @@ func runPlatTests(options compileopts.Options, tests []string, t *testing.T) {
370370
// Too big for AVR. Doesn't fit in flash/RAM.
371371
continue
372372

373-
case "math.go":
374-
// LLVM fails to lower one of the required library calls.
375-
continue
376-
377373
case "cgo/":
378374
// CGo function pointers don't work on AVR (needs LLVM 16 and
379375
// some compiler changes).
@@ -432,6 +428,10 @@ func runPlatTests(options compileopts.Options, tests []string, t *testing.T) {
432428
if name == "finalizerinvariants.go" || name == "finalizerlarge.go" {
433429
testOptions.Tags = append(append([]string(nil), options.Tags...), "runtime_asserts")
434430
}
431+
if testOptions.Target == "simavr" && name == "math.go" {
432+
// This test exceeds simavr's default 384-byte goroutine stack.
433+
testOptions.StackSize = 512
434+
}
435435
runTest(name, testOptions, t, nil, nil)
436436
})
437437
}

0 commit comments

Comments
 (0)