@@ -91,6 +91,9 @@ impl Interpreter {
91
91
| Opcode :: Xor => {
92
92
self . do_binary_maths ( & mut context, op) ?;
93
93
}
94
+ Opcode :: FindSetLeftBit | Opcode :: FindSetRightBit => {
95
+ self . do_unary_maths ( & mut context, op) ?;
96
+ }
94
97
Opcode :: Increment | Opcode :: Decrement => {
95
98
let [ Argument :: Object ( operand) ] = & op. arguments [ ..] else { panic ! ( ) } ;
96
99
let Object :: Integer ( operand) = operand. gain_mut ( ) else { panic ! ( ) } ;
@@ -829,6 +832,41 @@ impl Interpreter {
829
832
830
833
Ok ( ( ) )
831
834
}
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
+ }
832
870
fn do_store (
833
871
& self ,
834
872
context : & mut MethodContext ,
0 commit comments