lib: sbi_hart: Shorten the code to set MPV bit
PATCH v2 1/1 lib: sbi_hart: Shorten the code to set MPV bit
MPV bit is set when the value of next_virt boolean variable equals true. Since the value of next_virt is either 0 or 1, we can set MPV bit without if-else logic.
Signed-off-by Che-Chia Chang <[email protected]>
Reviewed-by Andrew Jones <[email protected]>
--
Change since v1:
- Drop the unnecessary brackets
--- lib/sbi/sbi_hart.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)
lib/sbi/sbi_hart.c +3 -10
@@ -769,19 +769,12 @@ sbi_hart_switch_mode(unsigned long arg0, unsigned long arg1,#if __riscv_xlen ==32 if (misa_extension ('H' )) { valH =csr_read (CSR_MSTATUSH ); -if (next_virt) - valH =INSERT_FIELD (valH,MSTATUSH_MPV ,1 ); -else - valH =INSERT_FIELD (valH,MSTATUSH_MPV ,0 ); + valH =INSERT_FIELD (valH,MSTATUSH_MPV , next_virt);csr_write (CSR_MSTATUSH , valH); }#else -if (misa_extension ('H' )) { -if (next_virt) - val =INSERT_FIELD (val,MSTATUS_MPV ,1 ); -else - val =INSERT_FIELD (val,MSTATUS_MPV ,0 ); - } +if (misa_extension ('H' )) + val =INSERT_FIELD (val,MSTATUS_MPV , next_virt);#endif csr_write (CSR_MSTATUS , val);csr_write (CSR_MEPC , next_addr);
Signature · 1 line
2.25.1
Anup Patel
AppliedPATCH v2 1/1 lib: sbi_hart: Shorten the code to set MPV bit
Quoted 7 lines · gagachang
MPV bit is set when the value of
next_virtboolean variable equals true. Since the value ofnext_virtis either 0 or 1, we can set MPV bit without if-else logic.Signed-off-by Che-Chia Chang <[email protected]>Reviewed-by Andrew Jones <[email protected]>
Looks good to me.
Reviewed-by Anup Patel <[email protected]>
Applied this patch to the riscv/opensbi repo.
Thanks,
Anup
Quoted 43 lines
--
Change since v1:
- Drop the unnecessary brackets--- lib/sbi/sbi_hart.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)lib/sbi/sbi_hart.c +3
-11@@ -769,19 +769,12 @@ sbi_hart_switch_mode(unsigned long arg0, unsigned long arg1,#if __riscv_xlen ==32 if (misa_extension ('H' )) { valH =csr_read (CSR_MSTATUSH ); -if (next_virt) - valH =INSERT_FIELD (valH,MSTATUSH_MPV ,1 ); -else - valH =INSERT_FIELD (valH,MSTATUSH_MPV ,0 ); + valH =INSERT_FIELD (valH,MSTATUSH_MPV , next_virt);csr_write (CSR_MSTATUSH , valH); }#else -if (misa_extension ('H' )) { -if (next_virt) - val =INSERT_FIELD (val,MSTATUS_MPV ,1 ); -else - val =INSERT_FIELD (val,MSTATUS_MPV ,0 ); - } +if (misa_extension ('H' )) + val =INSERT_FIELD (val,MSTATUS_MPV , next_virt);#endif csr_write (CSR_MSTATUS , val);csr_write (CSR_MEPC , next_addr); --2.25.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi