Skip to content

Commit 782e26b

Browse files
committed
aml: handle DefFindSetLeftBit and DefFindSetRightBit
1 parent 763bc74 commit 782e26b

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

aml/src/lib.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ impl Interpreter {
9191
| Opcode::Xor => {
9292
self.do_binary_maths(&mut context, op)?;
9393
}
94+
Opcode::FindSetLeftBit | Opcode::FindSetRightBit => {
95+
self.do_unary_maths(&mut context, op)?;
96+
}
9497
Opcode::Increment | Opcode::Decrement => {
9598
let [Argument::Object(operand)] = &op.arguments[..] else { panic!() };
9699
let Object::Integer(operand) = operand.gain_mut() else { panic!() };
@@ -829,6 +832,41 @@ impl Interpreter {
829832

830833
Ok(())
831834
}
835+
836+
fn do_unary_maths(&self, context: &mut MethodContext, op: OpInFlight) -> Result<(), AmlError> {
837+
let [Argument::Object(operand)] = &op.arguments[..] else { Err(AmlError::InvalidOperationOnObject)? };
838+
let Object::Integer(operand) = **operand else { Err(AmlError::InvalidOperationOnObject)? };
839+
840+
let result = match op.op {
841+
Opcode::FindSetLeftBit => {
842+
if operand == 0 {
843+
0
844+
} else {
845+
/*
846+
* TODO: this is a particular instance where not respecting integers being
847+
* 32-bit on revision 1 tables does cause properly incorrect behaviour...
848+
*/
849+
operand.leading_zeros() + 1
850+
}
851+
}
852+
Opcode::FindSetRightBit => {
853+
if operand == 0 {
854+
0
855+
} else {
856+
operand.trailing_zeros() + 1
857+
}
858+
}
859+
_ => panic!(),
860+
};
861+
862+
if let Some(prev_op) = context.in_flight.last_mut() {
863+
if prev_op.arguments.len() < prev_op.expected_arguments {
864+
prev_op.arguments.push(Argument::Object(Arc::new(Object::Integer(result as u64))));
865+
}
866+
}
867+
868+
Ok(())
869+
}
832870
fn do_store(
833871
&self,
834872
context: &mut MethodContext,

0 commit comments

Comments
 (0)