1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-26 08:49:37 +00:00

Eliminates non-portable use of fls.

This commit is contained in:
Thomas Harte 2019-11-09 16:03:00 -05:00
parent c4fefe1eb3
commit 5fc4e57db7
2 changed files with 16 additions and 3 deletions

View File

@ -301,7 +301,7 @@ void MFP68901::update_interrupts() {
if(interrupt_vector_ & 0x8) {
// Software interrupt mode: permit only if neither this interrupt
// nor a higher interrupt is currently in service.
const int highest_bit = 1 << (fls(firing_interrupts) - 1);
const int highest_bit = msb16(firing_interrupts);
interrupt_line_ = !(interrupt_in_service_ & ~(highest_bit - 1));
} else {
// Auto-interrupt mode; just signal.
@ -326,8 +326,7 @@ int MFP68901::acknowledge_interrupt() {
return NoAcknowledgement;
}
const int selected = fls(interrupt_pending_ & interrupt_mask_) - 1;
const int mask = 1 << selected;
const int mask = msb16(interrupt_pending_ & interrupt_mask_);
// Clear the pending bit regardless.
interrupt_pending_ &= ~mask;
@ -339,6 +338,8 @@ int MFP68901::acknowledge_interrupt() {
update_interrupts();
int selected = 0;
while((1 << selected) != mask) ++selected;
LOG("Interrupt acknowledged: " << selected);
return (interrupt_vector_ & 0xf0) | uint8_t(selected);
}

View File

@ -137,6 +137,18 @@ class MFP68901: public ClockingHint::Source {
void begin_interrupts(int interrupt);
void end_interrupts(int interrupt);
void update_interrupts();
/// @returns the most significant bit set in v, assuming it is one of the least significant 16.
inline static int msb16(int v) {
// Saturate all bits below the MSB.
v |= v >> 1;
v |= v >> 2;
v |= v >> 4;
v |= v >> 8;
// Throw away lesser bits.
return (v+1) >> 1;
}
};
}