use crate::*;
const ALIGNED_ADDR: u64 = 0x3000;
#[test]
fn test_crc32_r32_r8_basic() {
let mut emu = emu64();
let code = [
0xb8, 0x00, 0x00, 0x00, 0x00, 0xb1, 0x41, 0xf2, 0x0f, 0x38, 0xf0, 0xc1, 0xf4, ];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_crc32_r32_r8_accumulate() {
let mut emu = emu64();
let code = [
0xb8, 0x00, 0x00, 0x00, 0x00, 0xb1, 0x61, 0xf2, 0x0f, 0x38, 0xf0, 0xc1, 0xb1, 0x62, 0xf2, 0x0f, 0x38, 0xf0, 0xc1, 0xb1, 0x63, 0xf2, 0x0f, 0x38, 0xf0, 0xc1, 0xf4,
];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_crc32_r32_r8_zero() {
let mut emu = emu64();
let code = [
0xb8, 0x00, 0x00, 0x00, 0x00, 0xb1, 0x00, 0xf2, 0x0f, 0x38, 0xf0, 0xc1, 0xf4,
];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_crc32_r32_r8_ff() {
let mut emu = emu64();
let code = [
0xb8, 0x00, 0x00, 0x00, 0x00, 0xb1, 0xff, 0xf2, 0x0f, 0x38, 0xf0, 0xc1, 0xf4,
];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_crc32_r32_mem8() {
let mut emu = emu64();
let code = [0x48, 0xb8];
let mut full_code = code.to_vec();
full_code.extend_from_slice(&ALIGNED_ADDR.to_le_bytes());
full_code.extend_from_slice(&[
0xb9, 0x00, 0x00, 0x00, 0x00, 0xf2, 0x0f, 0x38, 0xf0, 0x08, 0xf4,
]);
emu.load_code_bytes(&full_code);
let data: [u8; 1] = [0x42];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &data);
emu.run(None).unwrap();
}
#[test]
fn test_crc32_different_registers_r8() {
let mut emu = emu64();
let code = [
0xbb, 0x00, 0x00, 0x00, 0x00, 0xb2, 0x48, 0xf2, 0x0f, 0x38, 0xf0, 0xda, 0xf4,
];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_crc32_r32_r8_sequence() {
let mut emu = emu64();
let code = [
0xb8, 0x00, 0x00, 0x00, 0x00, 0xb1, 0x48, 0xf2, 0x0f, 0x38, 0xf0, 0xc1, 0xb1, 0x65, 0xf2, 0x0f, 0x38, 0xf0, 0xc1, 0xb1, 0x6c, 0xf2, 0x0f, 0x38, 0xf0, 0xc1, 0xf2, 0x0f, 0x38, 0xf0, 0xc1, 0xb1, 0x6f, 0xf2, 0x0f, 0x38, 0xf0, 0xc1, 0xf4,
];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_crc32_r32_r16_basic() {
let mut emu = emu64();
let code = [
0xb8, 0x00, 0x00, 0x00, 0x00, 0x66, 0xb9, 0x34, 0x12, 0x66, 0xf2, 0x0f, 0x38, 0xf1, 0xc1, 0xf4,
];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_crc32_r32_r16_accumulate() {
let mut emu = emu64();
let code = [
0xb8, 0x00, 0x00, 0x00, 0x00, 0x66, 0xb9, 0x11, 0x11, 0x66, 0xf2, 0x0f, 0x38, 0xf1, 0xc1, 0x66, 0xb9, 0x22, 0x22, 0x66, 0xf2, 0x0f, 0x38, 0xf1, 0xc1, 0xf4,
];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_crc32_r32_r16_zero() {
let mut emu = emu64();
let code = [
0xb8, 0x00, 0x00, 0x00, 0x00, 0x66, 0xb9, 0x00, 0x00, 0x66, 0xf2, 0x0f, 0x38, 0xf1, 0xc1, 0xf4,
];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_crc32_r32_r16_ffff() {
let mut emu = emu64();
let code = [
0xb8, 0x00, 0x00, 0x00, 0x00, 0x66, 0xb9, 0xff, 0xff, 0x66, 0xf2, 0x0f, 0x38, 0xf1, 0xc1, 0xf4,
];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_crc32_r32_mem16() {
let mut emu = emu64();
let code = [0x48, 0xb8];
let mut full_code = code.to_vec();
full_code.extend_from_slice(&ALIGNED_ADDR.to_le_bytes());
full_code.extend_from_slice(&[
0xb9, 0x00, 0x00, 0x00, 0x00, 0x66, 0xf2, 0x0f, 0x38, 0xf1, 0x08, 0xf4,
]);
emu.load_code_bytes(&full_code);
let data: [u8; 2] = [0x78, 0x56];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &data);
emu.run(None).unwrap();
}
#[test]
fn test_crc32_different_registers_r16() {
let mut emu = emu64();
let code = [
0xba, 0x00, 0x00, 0x00, 0x00, 0x66, 0xbb, 0xcd, 0xab, 0x66, 0xf2, 0x0f, 0x38, 0xf1, 0xd3, 0xf4,
];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_crc32_r32_r32_basic() {
let mut emu = emu64();
let code = [
0xb8, 0x00, 0x00, 0x00, 0x00, 0xb9, 0x78, 0x56, 0x34, 0x12, 0xf2, 0x0f, 0x38, 0xf1, 0xc1, 0xf4,
];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_crc32_r32_r32_accumulate() {
let mut emu = emu64();
let code = [
0xb8, 0x00, 0x00, 0x00, 0x00, 0xb9, 0x11, 0x11, 0x11, 0x11, 0xf2, 0x0f, 0x38, 0xf1, 0xc1, 0xb9, 0x22, 0x22, 0x22, 0x22, 0xf2, 0x0f, 0x38, 0xf1, 0xc1, 0xb9, 0x33, 0x33, 0x33, 0x33, 0xf2, 0x0f, 0x38, 0xf1, 0xc1, 0xf4,
];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_crc32_r32_r32_zero() {
let mut emu = emu64();
let code = [
0xb8, 0x00, 0x00, 0x00, 0x00, 0xb9, 0x00, 0x00, 0x00, 0x00, 0xf2, 0x0f, 0x38, 0xf1, 0xc1, 0xf4,
];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_crc32_r32_r32_ffffffff() {
let mut emu = emu64();
let code = [
0xb8, 0x00, 0x00, 0x00, 0x00, 0xb9, 0xff, 0xff, 0xff, 0xff, 0xf2, 0x0f, 0x38, 0xf1, 0xc1, 0xf4,
];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_crc32_r32_mem32() {
let mut emu = emu64();
let code = [0x48, 0xb8];
let mut full_code = code.to_vec();
full_code.extend_from_slice(&ALIGNED_ADDR.to_le_bytes());
full_code.extend_from_slice(&[
0xb9, 0x00, 0x00, 0x00, 0x00, 0xf2, 0x0f, 0x38, 0xf1, 0x08, 0xf4,
]);
emu.load_code_bytes(&full_code);
let data: [u8; 4] = [0xef, 0xbe, 0xad, 0xde];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &data);
emu.run(None).unwrap();
}
#[test]
fn test_crc32_different_registers_r32() {
let mut emu = emu64();
let code = [
0xbb, 0x00, 0x00, 0x00, 0x00, 0xba, 0x12, 0x34, 0x56, 0x78, 0xf2, 0x0f, 0x38, 0xf1, 0xda, 0xf4,
];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_crc32_same_register() {
let mut emu = emu64();
let code = [
0xb8, 0x11, 0x11, 0x11, 0x11, 0xf2, 0x0f, 0x38, 0xf1, 0xc0, 0xf4,
];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_crc32_r64_r8_basic() {
let mut emu = emu64();
let code = [
0x48, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb1, 0x41, 0xf2, 0x48, 0x0f, 0x38, 0xf0, 0xc1, 0xf4,
];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_crc32_r64_r8_accumulate() {
let mut emu = emu64();
let code = [
0x48, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb1, 0x31, 0xf2, 0x48, 0x0f, 0x38, 0xf0, 0xc1, 0xb1, 0x32, 0xf2, 0x48, 0x0f, 0x38, 0xf0, 0xc1, 0xb1, 0x33, 0xf2, 0x48, 0x0f, 0x38, 0xf0, 0xc1, 0xf4,
];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_crc32_r64_mem8() {
let mut emu = emu64();
let code = [0x48, 0xbb];
let mut full_code = code.to_vec();
full_code.extend_from_slice(&ALIGNED_ADDR.to_le_bytes());
full_code.extend_from_slice(&[
0x48, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf2, 0x48, 0x0f, 0x38, 0xf0, 0x03, 0xf4,
]);
emu.load_code_bytes(&full_code);
let data: [u8; 1] = [0x5A];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &data);
emu.run(None).unwrap();
}
#[test]
fn test_crc32_r64_r64_basic() {
let mut emu = emu64();
let code = [
0x48, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0xb9, 0x78, 0x56, 0x34, 0x12, 0xef, 0xcd, 0xab, 0x90, 0xf2, 0x48, 0x0f, 0x38, 0xf1, 0xc1, 0xf4,
];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_crc32_r64_r64_accumulate() {
let mut emu = emu64();
let code = [
0x48, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0xb9, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0xf2, 0x48, 0x0f, 0x38, 0xf1, 0xc1, 0x48, 0xb9, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0xf2, 0x48, 0x0f, 0x38, 0xf1, 0xc1, 0xf4,
];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_crc32_r64_r64_zero() {
let mut emu = emu64();
let code = [
0x48, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0xb9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf2, 0x48, 0x0f, 0x38, 0xf1, 0xc1, 0xf4,
];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_crc32_r64_r64_ffffffffffffffff() {
let mut emu = emu64();
let code = [
0x48, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0xb9, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf2, 0x48, 0x0f, 0x38, 0xf1, 0xc1, 0xf4,
];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_crc32_r64_mem64() {
let mut emu = emu64();
let code = [0x48, 0xbb];
let mut full_code = code.to_vec();
full_code.extend_from_slice(&ALIGNED_ADDR.to_le_bytes());
full_code.extend_from_slice(&[
0x48, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf2, 0x48, 0x0f, 0x38, 0xf1, 0x03, 0xf4,
]);
emu.load_code_bytes(&full_code);
let data: [u8; 8] = [0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &data);
emu.run(None).unwrap();
}
#[test]
fn test_crc32_r64_different_registers() {
let mut emu = emu64();
let code = [
0x48, 0xbb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0xba, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00, 0x11, 0xf2, 0x48, 0x0f, 0x38, 0xf1, 0xda, 0xf4,
];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_crc32_r64_same_register() {
let mut emu = emu64();
let code = [
0x48, 0xb8, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0xf2, 0x48, 0x0f, 0x38, 0xf1, 0xc0, 0xf4,
];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_crc32_mixed_sizes() {
let mut emu = emu64();
let code = [
0xb8, 0x00, 0x00, 0x00, 0x00, 0xb1, 0x41, 0xf2, 0x0f, 0x38, 0xf0, 0xc1, 0x66, 0xb9, 0x42, 0x43, 0x66, 0xf2, 0x0f, 0x38, 0xf1, 0xc1, 0xb9, 0x44, 0x45, 0x46, 0x47, 0xf2, 0x0f, 0x38, 0xf1, 0xc1, 0xf4,
];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_crc32_mixed_64bit_sizes() {
let mut emu = emu64();
let code = [
0x48, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb1, 0x58, 0xf2, 0x48, 0x0f, 0x38, 0xf0, 0xc1, 0x48, 0xb9, 0x59, 0x5a, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0xf2, 0x48, 0x0f, 0x38, 0xf1, 0xc1, 0xf4,
];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_crc32_mem_displacement() {
let mut emu = emu64();
let code = [0x48, 0xb8];
let mut full_code = code.to_vec();
full_code.extend_from_slice(&(ALIGNED_ADDR - 0x10).to_le_bytes());
full_code.extend_from_slice(&[
0xb9, 0x00, 0x00, 0x00, 0x00, 0xf2, 0x0f, 0x38, 0xf1, 0x48, 0x10, 0xf4,
]);
emu.load_code_bytes(&full_code);
let data: [u8; 4] = [0x12, 0x34, 0x56, 0x78];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &data);
emu.run(None).unwrap();
}
#[test]
fn test_crc32_mem_sib() {
let mut emu = emu64();
let code = [0x48, 0xb8];
let mut full_code = code.to_vec();
full_code.extend_from_slice(&ALIGNED_ADDR.to_le_bytes());
full_code.extend_from_slice(&[
0xbb, 0x08, 0x00, 0x00, 0x00, 0xb9, 0x00, 0x00, 0x00, 0x00, 0xf2, 0x0f, 0x38, 0xf1, 0x0c, 0x18, 0xf4,
]);
emu.load_code_bytes(&full_code);
let data: [u8; 12] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &data);
let actual_data: [u8; 4] = [0xaa, 0xbb, 0xcc, 0xdd];
emu.maps.write_bytes_slice(ALIGNED_ADDR + 8, &actual_data);
emu.run(None).unwrap();
}
#[test]
fn test_crc32_nonzero_initial() {
let mut emu = emu64();
let code = [
0xb8, 0xff, 0xff, 0xff, 0xff, 0xb1, 0x41, 0xf2, 0x0f, 0x38, 0xf0, 0xc1, 0xf4,
];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_crc32_specific_initial_value() {
let mut emu = emu64();
let code = [
0xb8, 0x12, 0x34, 0x56, 0x78, 0xb9, 0xab, 0xcd, 0xef, 0x90, 0xf2, 0x0f, 0x38, 0xf1, 0xc1, 0xf4,
];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_crc32_r32_r8l() {
let mut emu = emu64();
let code = [
0xb8, 0x00, 0x00, 0x00, 0x00, 0x40, 0xb6, 0x5a, 0xf2, 0x40, 0x0f, 0x38, 0xf0, 0xc6, 0xf4,
];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_crc32_with_r8_r15() {
let mut emu = emu64();
let code = [
0x49, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0xb1, 0x7f, 0xf2, 0x45, 0x0f, 0x38, 0xf0, 0xc1, 0xf4,
];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_crc32_r32_with_r8d_r9d() {
let mut emu = emu64();
let code = [
0x45, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x41, 0xb9, 0x11, 0x22, 0x33, 0x44, 0xf2, 0x45, 0x0f, 0x38, 0xf1, 0xc1, 0xf4,
];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_crc32_r64_with_r10_r11() {
let mut emu = emu64();
let code = [
0x49, 0xba, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49, 0xbb, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, 0xf2, 0x4d, 0x0f, 0x38, 0xf1, 0xd3, 0xf4,
];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_crc32_string_abc() {
let mut emu = emu64();
let code = [
0xb8, 0x00, 0x00, 0x00, 0x00, 0xb1, 0x61, 0xf2, 0x0f, 0x38, 0xf0, 0xc1, 0xb1, 0x62, 0xf2, 0x0f, 0x38, 0xf0, 0xc1, 0xb1, 0x63, 0xf2, 0x0f, 0x38, 0xf0, 0xc1, 0xf4,
];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_crc32_string_test123() {
let mut emu = emu64();
let code = [
0xb8, 0x00, 0x00, 0x00, 0x00, 0xb1, 0x74, 0xf2, 0x0f, 0x38, 0xf0, 0xc1,
0xb1, 0x65, 0xf2, 0x0f, 0x38, 0xf0, 0xc1,
0xb1, 0x73, 0xf2, 0x0f, 0x38, 0xf0, 0xc1,
0xb1, 0x74, 0xf2, 0x0f, 0x38, 0xf0, 0xc1,
0xb1, 0x31, 0xf2, 0x0f, 0x38, 0xf0, 0xc1,
0xb1, 0x32, 0xf2, 0x0f, 0x38, 0xf0, 0xc1,
0xb1, 0x33, 0xf2, 0x0f, 0x38, 0xf0, 0xc1,
0xf4,
];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_crc32_multiple_sequences() {
let mut emu = emu64();
let code = [
0xb8, 0x00, 0x00, 0x00, 0x00, 0xb1, 0x41, 0xf2, 0x0f, 0x38, 0xf0, 0xc1, 0xbb, 0x00, 0x00, 0x00, 0x00, 0xb1, 0x42, 0xf2, 0x0f, 0x38, 0xf0, 0xd9, 0xba, 0x00, 0x00, 0x00, 0x00, 0xb1, 0x43, 0xf2, 0x0f, 0x38, 0xf0, 0xd1, 0xf4,
];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}