Rahix / avr-device

Register access crate for AVR microcontrollers
Apache License 2.0
170 stars 66 forks source link

irq: Optimize interrupt save/restore #104

Closed mbuesch closed 2 years ago

mbuesch commented 2 years ago

Avoid unnecessary mask and branch instructions.

The basic reasoning behind this is that all other flags in the SREG can be clobbered without ill effects. The restore() function is an optimization fence and the compiler is not allowed to make assumptions about memory or SREG state after execution.

This avoids an and and a breq instruction or similar in every critical section.

This is an API breakage that requires an incompatible version bump. Question: Should we return a struct instead of u8? That would give us the opportunity to change semantics without breaking API in the future.

I hope I got the llvm_asm! part of restore() right. I didn't test it. What about removing all llvm_asm!?

mbuesch commented 2 years ago

I resolved all review findings. I'll rebase this again after #106 has been resolved an pulled.

mbuesch commented 2 years ago

Rebased on top of latest main and removed a couple of compiler warnings in non-avr mode.

mbuesch commented 2 years ago

Thanks again for your review. I addressed all your points.

Rahix commented 2 years ago

Got the notification for your commit above this comment. I want to break a new release soon, with all your changes, but then I'll wait a bit, still?

mbuesch commented 2 years ago

Oh, I think any name is fine. Please pick the name you feel is best. Be it udebug, ufmt or anything else. I agree that we should have a release asap. But, maybe we should include #109 in that release, too? With that applied I think this is ready for another release.

Rahix commented 2 years ago

Here you go: https://github.com/Rahix/avr-device/releases/tag/v0.4.0 :)