Skip to content

Commit 7af6d46

Browse files
committed
compiler: fix 64-bit sin and cos on AVR
1 parent 9fae0eb commit 7af6d46

2 files changed

Lines changed: 17 additions & 5 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: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,6 @@ func runPlatTests(options compileopts.Options, tests []string, t *testing.T) {
333333
// Too big for AVR. Doesn't fit in flash/RAM.
334334
continue
335335

336-
case "math.go":
337-
// LLVM fails to lower one of the required library calls.
338-
continue
339-
340336
case "cgo/":
341337
// CGo function pointers don't work on AVR (needs LLVM 16 and
342338
// some compiler changes).
@@ -379,7 +375,12 @@ func runPlatTests(options compileopts.Options, tests []string, t *testing.T) {
379375
name := name // redefine to avoid race condition
380376
t.Run(name, func(t *testing.T) {
381377
t.Parallel()
382-
runTest(name, options, t, nil, nil)
378+
testOptions := options
379+
if testOptions.Target == "simavr" && name == "math.go" {
380+
// This test exceeds simavr's default 384-byte goroutine stack.
381+
testOptions.StackSize = 512
382+
}
383+
runTest(name, testOptions, t, nil, nil)
383384
})
384385
}
385386
if !strings.HasPrefix(spec.Emulator, "simavr ") {

0 commit comments

Comments
 (0)