Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPIO: Refactor AnyPin to contain a u8 #2854

Merged
merged 4 commits into from
Jan 3, 2025
Merged

Conversation

bugadani
Copy link
Contributor

@bugadani bugadani commented Dec 20, 2024

It seems like the compiler is WAY better at propagating a single u8 than an enum of different types. My silly little benchmark is now completely const-propagated and toggles at 1.6MHz.

As a neat bonus, we can now provide AnyPin::steal

@bugadani bugadani added the skip-changelog No changelog modification needed label Dec 20, 2024
@bugadani bugadani force-pushed the gpio-opt branch 2 times, most recently from 009ddbb to 5e80ef0 Compare December 20, 2024 13:28
@bugadani bugadani changed the title GPIO: Remove panicking match from Flex::set_level GPIO: Refactor AnyPin to contain a u8 Dec 20, 2024
@@ -3231,7 +3231,7 @@ impl Driver {
// wait
}
} else if #[cfg(esp32)] {
xtensa_lx::timer::delay(1);
xtensa_lx::timer::delay(2); // ☠️
Copy link
Contributor

@bjoernQ bjoernQ Dec 20, 2024

Choose a reason for hiding this comment

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

any idea why we need this now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really :(

@bjoernQ
Copy link
Contributor

bjoernQ commented Dec 20, 2024

I can reproduce the 1.60 MHz for the erased case 🚀

@bugadani
Copy link
Contributor Author

I can reproduce the 1.60 MHz for the erased case 🚀

The slight problem with that is, that we're not actually testing the performance of the erased GPIO, but the compilers ability to const-propagate the pin number. We need a better benchmark going forward

@bjoernQ
Copy link
Contributor

bjoernQ commented Dec 30, 2024

I can reproduce the 1.60 MHz for the erased case 🚀

The slight problem with that is, that we're not actually testing the performance of the erased GPIO, but the compilers ability to const-propagate the pin number. We need a better benchmark going forward

We are relying a lot on the toolchains' optimization and here we try to please the compiler to produce better optimizations - maybe it would be good to have benchmarks in CI to avoid regressions in future (as good as it gets since optimizations are hard to predict - we already tried something like that for direct-vectored interrupts in hil-tests but suffered from flakiness)

But I don't see a situation where this might make things worse

Copy link
Member

@MabezDev MabezDev left a comment

Choose a reason for hiding this comment

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

Nice, I'm glad this worked out! Whilst we are relying on the compiler, we kind of always are :D, but a benchmark/test for this in the future would be nice.

LGTM!

@MabezDev MabezDev enabled auto-merge January 3, 2025 14:29
@MabezDev MabezDev added this pull request to the merge queue Jan 3, 2025
Merged via the queue into esp-rs:main with commit 713cd49 Jan 3, 2025
28 checks passed
@bugadani bugadani deleted the gpio-opt branch January 3, 2025 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip-changelog No changelog modification needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants