@@ -3,7 +3,7 @@ use prettytable::{row, Table};
3
3
4
4
use crate :: {
5
5
ins:: { instruction:: Instruction , op_codes:: OpCode } ,
6
- reg:: registers:: RegisterId , utils ,
6
+ reg:: registers:: RegisterId ,
7
7
} ;
8
8
9
9
use super :: mapped_memory:: MappedMemory ;
@@ -12,7 +12,7 @@ use super::mapped_memory::MappedMemory;
12
12
pub const MEGABYTE : usize = 1024 * 1024 ;
13
13
14
14
/// The size of an instruction, in bytes.
15
- // pub const SIZE_OF_INSTRUCTION: usize = 4;
15
+ pub const SIZE_OF_INSTRUCTION : usize = 4 ;
16
16
/// The size of a u32 value, in bytes.
17
17
pub const SIZE_OF_U32 : usize = 4 ;
18
18
/// The size of a f32 value, in bytes.
@@ -313,29 +313,8 @@ impl MemoryHandler {
313
313
use Instruction as I ;
314
314
use OpCode as O ;
315
315
316
- let prefetch = self . get_range_clone ( pos, 4 ) ;
317
-
318
- let mut opcode_size = 1 ;
319
- let mut opcode_bits: [ u8 ; 4 ] = [ 0 ; 4 ] ;
320
- opcode_bits[ 3 ] = prefetch[ 0 ] ;
321
-
322
- if utils:: is_bit_set_u8 ( prefetch[ 0 ] , 8 ) {
323
- opcode_bits[ 2 ] = prefetch[ 1 ] ;
324
- opcode_size += 1 ;
325
-
326
- if utils:: is_bit_set_u8 ( prefetch[ 1 ] , 8 ) {
327
- opcode_bits[ 1 ] = prefetch[ 2 ] ;
328
- opcode_size += 1 ;
329
-
330
- if utils:: is_bit_set_u8 ( prefetch[ 2 ] , 8 ) {
331
- opcode_bits[ 0 ] = prefetch[ 3 ] ;
332
- opcode_size += 1 ;
333
- }
334
- }
335
- }
336
-
337
316
// Read the OpCode ID.
338
- let opcode_id = u32 :: from_le_bytes ( opcode_bits ) ;
317
+ let opcode_id = self . get_u32 ( pos ) ;
339
318
340
319
// Validate the opcode is one of the ones we know about.
341
320
// In the case we encounter an unrecognized opcode ID then we will
@@ -347,7 +326,7 @@ impl MemoryHandler {
347
326
348
327
// We will assert here if we can't read enough bytes to meet the expected amount.
349
328
// This means that subsequent "unsafe" reads are actually safe.
350
- let arg_bytes = self . get_range_ptr ( pos + opcode_size , arg_len) ;
329
+ let arg_bytes = self . get_range_ptr ( pos + SIZE_OF_INSTRUCTION , arg_len) ;
351
330
352
331
let mut cursor = 0 ;
353
332
0 commit comments