aboutsummaryrefslogtreecommitdiff
path: root/test/long_mode
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2021-07-01 23:54:06 -0700
committeriximeow <me@iximeow.net>2021-07-01 23:54:06 -0700
commita781322552d9fb52b7b5e51641f49f12678f682f (patch)
treeb7ea7042d707dca8ffc322ddac4ebd5b8c475027 /test/long_mode
parent889ce5c55af062d12cdd109bac22cc05565f68a6 (diff)
reallocate OperandCode, convert disparate registers to array
also remove redundant assignments of operand_count and some OperandSpec, bulk-assign all registers and operands on entry to `read_instr`. this all, taken together, shaves off about 7 cycles per decode.
Diffstat (limited to 'test/long_mode')
-rw-r--r--test/long_mode/display.rs3
-rw-r--r--test/long_mode/evex_generated.rs8
-rw-r--r--test/long_mode/mod.rs6
-rw-r--r--test/long_mode/operand.rs14
-rw-r--r--test/long_mode/reuse_test.rs10
5 files changed, 25 insertions, 16 deletions
diff --git a/test/long_mode/display.rs b/test/long_mode/display.rs
index 4ef3f74..fc59427 100644
--- a/test/long_mode/display.rs
+++ b/test/long_mode/display.rs
@@ -12,7 +12,8 @@ fn test_display_under(decoder: &InstDecoder, data: &[u8], expected: &'static str
for b in data {
write!(hex, "{:02x}", b).unwrap();
}
- match decoder.decode(data.into_iter().map(|x| *x)) {
+ let mut reader = yaxpeax_arch::U8Reader::new(data);
+ match decoder.decode(&mut reader) {
Ok(instr) => {
let text = format!("{}", instr.display_with(DisplayStyle::C));
assert!(
diff --git a/test/long_mode/evex_generated.rs b/test/long_mode/evex_generated.rs
index 9c23e4b..dcb4e01 100644
--- a/test/long_mode/evex_generated.rs
+++ b/test/long_mode/evex_generated.rs
@@ -1,6 +1,6 @@
use std::fmt::Write;
-use yaxpeax_arch::{AddressBase, Decoder, LengthedInstruction};
+use yaxpeax_arch::{AddressBase, Decoder, U8Reader, LengthedInstruction};
use yaxpeax_x86::long_mode::InstDecoder;
#[allow(dead_code)]
@@ -9,7 +9,8 @@ fn test_invalid(data: &[u8]) {
}
fn test_invalid_under(decoder: &InstDecoder, data: &[u8]) {
- if let Ok(inst) = decoder.decode(data.into_iter().cloned()) {
+ let mut reader = U8Reader::new(data);
+ if let Ok(inst) = decoder.decode(&mut reader) {
panic!("decoded {:?} from {:02x?} under decoder {}", inst.opcode(), data, decoder);
} else {
// this is fine
@@ -26,7 +27,8 @@ fn test_display_under(decoder: &InstDecoder, data: &[u8], expected: &'static str
for b in data {
write!(hex, "{:02x}", b).unwrap();
}
- match decoder.decode(data.into_iter().map(|x| *x)) {
+ let mut reader = U8Reader::new(data);
+ match decoder.decode(&mut reader) {
Ok(instr) => {
let text = format!("{}", instr);
assert!(
diff --git a/test/long_mode/mod.rs b/test/long_mode/mod.rs
index cbd881c..1eedfec 100644
--- a/test/long_mode/mod.rs
+++ b/test/long_mode/mod.rs
@@ -16,7 +16,8 @@ fn test_invalid(data: &[u8]) {
}
fn test_invalid_under(decoder: &InstDecoder, data: &[u8]) {
- if let Ok(inst) = decoder.decode(data.into_iter().cloned()) {
+ let mut reader = yaxpeax_arch::U8Reader::new(data);
+ if let Ok(inst) = decoder.decode(&mut reader) {
panic!("decoded {:?} from {:02x?} under decoder {}", inst.opcode(), data, decoder);
} else {
// this is fine
@@ -32,7 +33,8 @@ fn test_display_under(decoder: &InstDecoder, data: &[u8], expected: &'static str
for b in data {
write!(hex, "{:02x}", b).unwrap();
}
- match decoder.decode(data.into_iter().map(|x| *x)) {
+ let mut reader = yaxpeax_arch::U8Reader::new(data);
+ match decoder.decode(&mut reader) {
Ok(instr) => {
let text = format!("{}", instr);
assert!(
diff --git a/test/long_mode/operand.rs b/test/long_mode/operand.rs
index f0300d6..77ce256 100644
--- a/test/long_mode/operand.rs
+++ b/test/long_mode/operand.rs
@@ -2,15 +2,15 @@ use yaxpeax_x86::long_mode::{Operand, RegSpec};
#[test]
fn register_widths() {
- assert_eq!(Operand::Register(RegSpec::rsp()).width(), 8);
- assert_eq!(Operand::Register(RegSpec::esp()).width(), 4);
- assert_eq!(Operand::Register(RegSpec::sp()).width(), 2);
- assert_eq!(Operand::Register(RegSpec::cl()).width(), 1);
- assert_eq!(Operand::Register(RegSpec::ch()).width(), 1);
- assert_eq!(Operand::Register(RegSpec::gs()).width(), 2);
+ assert_eq!(Operand::Register(RegSpec::rsp()).width(), Some(8));
+ assert_eq!(Operand::Register(RegSpec::esp()).width(), Some(4));
+ assert_eq!(Operand::Register(RegSpec::sp()).width(), Some(2));
+ assert_eq!(Operand::Register(RegSpec::cl()).width(), Some(1));
+ assert_eq!(Operand::Register(RegSpec::ch()).width(), Some(1));
+ assert_eq!(Operand::Register(RegSpec::gs()).width(), Some(2));
}
#[test]
fn memory_widths() {
- assert_eq!(Operand::RegDeref(RegSpec::rsp()).width(), 8);
+ assert_eq!(Operand::RegDeref(RegSpec::rsp()).width(), None);
}
diff --git a/test/long_mode/reuse_test.rs b/test/long_mode/reuse_test.rs
index 117f3fa..60a91e1 100644
--- a/test/long_mode/reuse_test.rs
+++ b/test/long_mode/reuse_test.rs
@@ -1989,17 +1989,21 @@ const INSTRUCTIONS: [&'static [u8]; 1982] = [
#[test]
fn test_against_leftover_data() {
use super::rand::{thread_rng, Rng};
+ use yaxpeax_arch::U8Reader;
let mut rng = thread_rng();
let decoder = InstDecoder::default();
for _ in 0..100000 {
let first_vec = INSTRUCTIONS[rng.gen_range(0..INSTRUCTIONS.len())];
- let first_decode = decoder.decode(first_vec.to_vec().iter().cloned()).unwrap();
+ let mut first_reader = U8Reader::new(first_vec);
+ let first_decode = decoder.decode(&mut first_reader).unwrap();
let second_vec = INSTRUCTIONS[rng.gen_range(0..INSTRUCTIONS.len())];
- let mut reused_decode = decoder.decode(second_vec.to_vec().iter().cloned()).unwrap();
- decoder.decode_into(&mut reused_decode, first_vec.to_vec().iter().cloned()).unwrap();
+ let mut second_reader = U8Reader::new(second_vec);
+ let mut reused_decode = decoder.decode(&mut second_reader).unwrap();
+ let mut first_reader = U8Reader::new(first_vec);
+ decoder.decode_into(&mut reused_decode, &mut first_reader).unwrap();
assert_eq!(first_decode, reused_decode);
}