From 4dfba258d98428461fc9b0248736fa097901bb67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Monestier?= Date: Wed, 18 Jun 2025 21:04:26 +0200 Subject: [PATCH] Performance: processor_t::take_interrupt() should check EXT_SSAIA The implementation of SMAIA and SSAIA extensions incurs a significant performance penalty. Better check whether EXT_SSAIA is enabled before accessing the considered CSR's Cf. commit # ddc025a80dfbb79d6bafbda6a5a456d117472d9b commit # a6708d5588ebd1b9a805ef557b38e49ba42eb851 --- riscv/processor.cc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/riscv/processor.cc b/riscv/processor.cc index ec3c9989..5e608a96 100644 --- a/riscv/processor.cc +++ b/riscv/processor.cc @@ -303,9 +303,15 @@ bool processor_t::is_handled_in_vs() void processor_t::take_interrupt(reg_t pending_interrupts) { - const reg_t s_pending_interrupts = state.nonvirtual_sip->read() & state.nonvirtual_sie->read(); - const reg_t vstopi = state.vstopi->read(); - const reg_t vs_pending_interrupt = vstopi ? (reg_t(1) << get_field(vstopi, MTOPI_IID)) : 0; + reg_t s_pending_interrupts = 0; + reg_t vstopi = 0; + reg_t vs_pending_interrupt = 0; + + if (extension_enable_table[EXT_SSAIA]) { + s_pending_interrupts = state.nonvirtual_sip->read() & state.nonvirtual_sie->read(); + vstopi = state.vstopi->read(); + vs_pending_interrupt = vstopi ? (reg_t(1) << get_field(vstopi, MTOPI_IID)) : 0; + } // Do nothing if no pending interrupts if (!pending_interrupts && !s_pending_interrupts && !vs_pending_interrupt) {