File tree Expand file tree Collapse file tree 3 files changed +9
-8
lines changed Expand file tree Collapse file tree 3 files changed +9
-8
lines changed Original file line number Diff line number Diff line change 10
10
#define MASK (n ) (~((~0U << (n))))
11
11
12
12
#define ARRAY_SIZE (a ) (sizeof(a) / sizeof(*(a)))
13
+
14
+ /* Ensure that __builtin_clz is never called with 0 argument */
15
+ static inline int ilog2 (int x )
16
+ {
17
+ return 31 - __builtin_clz (x | 1 );
18
+ }
Original file line number Diff line number Diff line change @@ -763,9 +763,7 @@ void vm_step(vm_t *vm)
763
763
764
764
if ((vm -> sstatus_sie || !vm -> s_mode ) && (vm -> sip & vm -> sie )) {
765
765
uint32_t applicable = (vm -> sip & vm -> sie );
766
- uint8_t idx = 32 ;
767
- while (!(applicable & (1 << -- idx )))
768
- ; /* TODO: Rewrite with faster a lookup table. */
766
+ uint8_t idx = ilog2 (applicable );
769
767
vm -> exc_cause = (1U << 31 ) | idx ;
770
768
vm -> stval = 0 ;
771
769
vm_trap (vm );
Original file line number Diff line number Diff line change @@ -48,11 +48,8 @@ void u8250_update_interrupts(u8250_state_t *uart)
48
48
uart -> pending_ints &= uart -> ier ;
49
49
50
50
/* Update current interrupt (higher bits -> more priority) */
51
- if (uart -> pending_ints ) {
52
- uart -> current_int = 8 ;
53
- while (!(uart -> pending_ints & (1 << -- uart -> current_int )))
54
- ; /* TODO: Rewrite with faster lookup table. */
55
- }
51
+ if (uart -> pending_ints )
52
+ uart -> current_int = ilog2 (uart -> pending_ints );
56
53
}
57
54
58
55
void u8250_check_ready (u8250_state_t * uart )
You can’t perform that action at this time.
0 commit comments