Skip to content

Commit

Permalink
feat(riscv): avoid flash-backed LUT for irq
Browse files Browse the repository at this point in the history
Previously, the `INTERRUPT_TO_PRIORITY` constant would compile down to a
runtime lookup table called `anon.HASH.2.llvm.NUMBERS` like so:

```asm
            status & configured_interrupts[INTERRUPT_TO_PRIORITY[cpu_intr as usize - 1]];
...
40380fbc:       3c0095b7                lui     a1,0x3c009
40380fc0:       2d858593                addi    a1,a1,728 # 3c0092d8 <anon.73967c570b981c3046610ed0622f71c3.2.llvm.13737670072012269642>
40380fc4:       952e                    add     a0,a0,a1
40380fc6:       4108                    lw      a0,0(a0)
```

Which means that in order to load the `a1`th slot from the LUT, we'll
have to go out to flash to do it.

As an alternative to an `#[inline]`'d function, which is nice in the
'c3's case because it's the identity function that disappears at
runtime, instead of using a `const` INTERRUPT_TO_PRIORITY could be made
a `static`, which would allow us to place it into the `.data` section
via a linker directive.
  • Loading branch information
sethp committed May 11, 2023
1 parent fa671bb commit cda36dd
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion esp-hal-common/src/interrupt/riscv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ mod vectored {

let configured_interrupts = get_configured_interrupts(crate::get_core(), status);
let mut interrupt_mask =
status & configured_interrupts[INTERRUPT_TO_PRIORITY[cpu_intr as usize - 1]];
status & configured_interrupts[interrupt_to_priority(cpu_intr as usize)];
while interrupt_mask != 0 {
let interrupt_nr = interrupt_mask.trailing_zeros();
// Interrupt::try_from can fail if interrupt already de-asserted:
Expand Down Expand Up @@ -606,6 +606,11 @@ mod classic {
use super::{CpuInterrupt, InterruptKind, Priority};
use crate::Cpu;

#[inline(always)]
pub(super) const fn interrupt_to_priority(irq: usize) -> usize {
irq
}

pub(super) const PRIORITY_TO_INTERRUPT: [usize; 15] =
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15];

Expand Down

0 comments on commit cda36dd

Please sign in to comment.