-
-
Notifications
You must be signed in to change notification settings - Fork 17
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
interrupt: Optimize restore on AVR and MSP430 #40
Conversation
The followings are examples of the changes in code generation by this patch. before(msp430-none-elf):
after(msp430-none-elf):
before(avr-unknown-gnu-atmega328):
after(avr-unknown-gnu-atmega328):
|
cc @cr1901: I believe this solves the code size issue that you mentioned in #39 (comment). |
Your approach with no branches was originally how I wanted to do it. You will notice my implementation of So I had to keep the branch. IMO, it's still worth testing whether having
I probably should not have brought up the code size thing- I don't think your crate will have the size problem, because Footnotes
|
Sorry for the late response.
Yeah, IIUC this approach may cause problems in code where we don't know what the user will do after the interrupt is disabled, depending on how LLVM handles Clobbering And if the above is correct:
So, I think this approach is fine for
Thanks for the clarification. I probably should have asked first about whether or not it is a portable-atomic's issue.
Thanks for the testing. I can also confirm that which one is used as a state does not affect the generated code. Below is the code generated for the current main branch that uses
Footnotes
|
I'm feeling under the weather today, so I don't have much bandwidth to give thoughts, but here's a summary:
None of the other bits are considered arithmetic flags. LLVM shouldn't generate code that reads/writes to those other bits, either directly (
Based on the two bullet points above contrasting Minddump for me follows: I think there should be an explicit comment about how This assumption can't be made for a generic critical section like the one the That being said, I think the
|
Agreed. I'll add a comment about this.
Good catch, thanks! I've pushed the fix. As for AVR, bits in the status register (SREG) are modified as a side effect of arithmetic operations or others, with the exception of the I (Global Interrupt Enable) bit. So, this optimization should be fine. Actually, it seems avr-device crate recently adopted the same optimization: Rahix/avr-device@280d685 |
44: interrupt: Various improvements r=taiki-e a=taiki-e - Support RISC-V supervisor mode under `portable_atomic_s_mode` cfg > On RISC-V without A-extension, this generates code for machine-mode (M-mode) by default. If you pass the `--cfg portable_atomic_s_mode` together, this generates code for supervisor-mode (S-mode). In particular, `qemu-system-riscv*` uses [OpenSBI](https://github.com/riscv-software-src/opensbi) as the default firmware. - Support disabling FIQs on pre-v6 ARM under `portable_atomic_disable_fiq` cfg > On pre-v6 ARM, this disables only IRQs by default. For many systems (e.g., GBA) this is enough. If the system need to disable both IRQs and FIQs, you need to pass the `--cfg portable_atomic_disable_fiq` together. - Interrupt-related documentation improvements - [README.md](https://github.com/taiki-e/portable-atomic/blob/18961fab6716c3fe45e89cbf2abf46c6a10fad21/README.md#optional-cfg) - [src/imp/interrupt/README.md](https://github.com/taiki-e/portable-atomic/blob/18961fab6716c3fe45e89cbf2abf46c6a10fad21/src/imp/interrupt/README.md) - Defer mask until just before branch > This does not change the code generation, but in the actual generated code the mask is deferred until just before the branch, like this. Since there has been some misleading discussion about this in the past, we will use code that more closely matches the generated code. For MSP430 and AVR, it will be done in #40. Co-authored-by: Taiki Endo <[email protected]>
Updated comment on portable-atomic/src/imp/interrupt/msp430.rs Lines 42 to 47 in edbca26
bors r+ |
As we have already been doing for pre-v6 ARM, avoid unneeded branch and mask.
portable-atomic/src/imp/interrupt/armv4t.rs
Lines 31 to 40 in d4b2747