Skip to content

Commit 6cf55db

Browse files
committed
compiler: fix 64-bit sin and cos on AVR
1 parent 76636c9 commit 6cf55db

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
@@ -348,10 +348,6 @@ func runPlatTests(options compileopts.Options, tests []string, t *testing.T) {
348348
// Too big for AVR. Doesn't fit in flash/RAM.
349349
continue
350350

351-
case "math.go":
352-
// LLVM fails to lower one of the required library calls.
353-
continue
354-
355351
case "cgo/":
356352
// CGo function pointers don't work on AVR (needs LLVM 16 and
357353
// some compiler changes).
@@ -394,7 +390,12 @@ func runPlatTests(options compileopts.Options, tests []string, t *testing.T) {
394390
name := name // redefine to avoid race condition
395391
t.Run(name, func(t *testing.T) {
396392
t.Parallel()
397-
runTest(name, options, t, nil, nil)
393+
testOptions := options
394+
if testOptions.Target == "simavr" && name == "math.go" {
395+
// This test exceeds simavr's default 384-byte goroutine stack.
396+
testOptions.StackSize = 512
397+
}
398+
runTest(name, testOptions, t, nil, nil)
398399
})
399400
}
400401
if !strings.HasPrefix(spec.Emulator, "simavr ") {

0 commit comments

Comments
 (0)