Read bits only once.

This commit is contained in:
David Craven 2017-11-20 14:14:01 +01:00
parent b42411e64a
commit bb41b209a6
No known key found for this signature in database
GPG Key ID: 33B9E9FDE28D2C23
1 changed files with 3 additions and 2 deletions

View File

@ -283,8 +283,9 @@ impl mcause::R {
#[inline(always)]
/// Trap Cause
pub fn cause(&self) -> Trap {
let code = self.bits() & !(1 << 31);
match self.bits() & (1 << 31) == 1 << 31 {
let bits = self.bits();
let code = bits & !(1 << 31);
match bits & (1 << 31) == 1 << 31 {
true => Trap::Interrupt(Interrupt::from(code)),
false => Trap::Exception(Exception::from(code)),
}