Skip to content

machine: keep RP2 PLL calculations out of startup - #5837

Merged
deadprogram merged 1 commit into
tinygo-org:devfrom
davecheney:davecheney-compile-pll-setup-ahead
Oct 15, 2026
Merged

deadprogram merged 1 commit into
tinygo-org:devfrom
davecheney:davecheney-compile-pll-setup-ahead

Conversation

@davecheney

Copy link
Copy Markdown
Contributor

Fixes #5836

RP2040 and RP2350 PLL table generation exceeds interp's default loop limit, leaving clock calculations in firmware startup.

Split the per-product search so the calculations complete at compile time.

@dgryski

dgryski commented Oct 7, 2026

Copy link
Copy Markdown
Member

I wonder if there's some sort of pragma or compile option we could add to be able to hunt these things out across all the platforms.

@davecheney

Copy link
Copy Markdown
Contributor Author

I wonder if there's some sort of pragma or compile option we could add to be able to hunt these things out across all the platforms.

jinx; I have a sketch of a //go:compiletime pragma which will explode if the function is still present by link time.

@deadprogram

Copy link
Copy Markdown
Member

@deadprogram deadprogram added this to the 0.44 milestone Oct 9, 2026
@davecheney
davecheney force-pushed the davecheney-compile-pll-setup-ahead branch 2 times, most recently from 75b1d4c to b5ca9a7 Compare October 13, 2026 13:12
@davecheney

Copy link
Copy Markdown
Contributor Author

@deadprogram PTAL. The windows failure was caused by git on windows converting testdata/ files from \n, to \r\n automagically. There are 11 existing workarounds for this in the codebase. I added a 12th. I'm going to take a separate pass tomorrow to try to fix the underlying problem.

@deadprogram

Copy link
Copy Markdown
Member

Thanks for working on this @davecheney. I ran the tests on my local machine and took a good look. The following is edited from an automated review:

  1. Now that all: check out testdata with LF line endings on all platforms #5872 is merged, the CRLF note in rp2_pll_test.go around the package clause is no longer needed. Perhaps rebase and drop that comment, and maybe use a simple bytes.CutPrefix for package main\n?

  2. TestRP2PLLPreEvaluation alone fails on dev and passes with this change, so it already guards the regression. TestRP2PLLTable adds a lot of machinery (AST extraction, wasip1 build, wazero run) for a change that only moves the loop body into a helper. Should we keep just the pre-evaluation test?

  3. The register checks in TestRP2PLLPreEvaluation hardcode the FBDIV and POSTDIV values for the current default clocks (200 MHz on pico, 150 MHz on pico2). If someone changes a default clock later this test fails for an unrelated reason. Maybe checking only that the machine.pdTable and machine.pllsys* symbols are gone is enough?

Sounds OK?

RP2040 and RP2350 PLL table generation exceeds interp's default loop limit, leaving clock calculations in firmware startup.

Split the per-product search so the calculations complete at compile time.
@davecheney
davecheney force-pushed the davecheney-compile-pll-setup-ahead branch from b5ca9a7 to e664a9e Compare October 14, 2026 22:46
@davecheney

davecheney commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor Author

@deadprogram PTAL. I've simplified the commit, dropping most of the testing and keeping the critical part - splitting genTable into two functions. The remaining test is simply double underpants that this doesn't regress. I'm working on a replacement that will add a //go:compiletime annotation which will remove the need for the test.

@deadprogram deadprogram left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good now thank you very much @davecheney for your fine efforts. Now merging.

@deadprogram
deadprogram merged commit df440ec into tinygo-org:dev Oct 15, 2026
33 checks passed
@davecheney
davecheney deleted the davecheney-compile-pll-setup-ahead branch October 15, 2026 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RP2 PLL calculation exceeds interp's default basic-block limit

3 participants