use crate::*;
const ALIGNED_ADDR: u64 = 0x3000;
const ALIGNED_ADDR2: u64 = 0x3100;
#[test]
fn test_psubusb_all_zeros() {
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(&[0x48, 0xbb]);
full_code.extend_from_slice(&ALIGNED_ADDR2.to_le_bytes());
full_code.extend_from_slice(&[
0x66, 0x0f, 0x6f, 0x00, 0x66, 0x0f, 0x6f, 0x0b, 0x66, 0x0f, 0xd8, 0xc1, 0xf4, ]);
emu.load_code_bytes(&full_code);
emu.maps.write_bytes_slice(ALIGNED_ADDR, &[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
emu.run(None).unwrap();
}
#[test]
fn test_psubusb_no_saturation() {
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(&[0x48, 0xbb]);
full_code.extend_from_slice(&ALIGNED_ADDR2.to_le_bytes());
full_code.extend_from_slice(&[
0x66, 0x0f, 0x6f, 0x00,
0x66, 0x0f, 0x6f, 0x0b,
0x66, 0x0f, 0xd8, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
emu.maps.write_bytes_slice(ALIGNED_ADDR, &[0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50]);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &[0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30]);
emu.run(None).unwrap();
}
#[test]
fn test_psubusb_saturate_to_zero() {
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(&[0x48, 0xbb]);
full_code.extend_from_slice(&ALIGNED_ADDR2.to_le_bytes());
full_code.extend_from_slice(&[
0x66, 0x0f, 0x6f, 0x00,
0x66, 0x0f, 0x6f, 0x0b,
0x66, 0x0f, 0xd8, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
emu.maps.write_bytes_slice(ALIGNED_ADDR, &[0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10]);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &[0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20]);
emu.run(None).unwrap();
}
#[test]
fn test_psubusb_exact_zero() {
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(&[0x48, 0xbb]);
full_code.extend_from_slice(&ALIGNED_ADDR2.to_le_bytes());
full_code.extend_from_slice(&[
0x66, 0x0f, 0x6f, 0x00,
0x66, 0x0f, 0x6f, 0x0b,
0x66, 0x0f, 0xd8, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
emu.maps.write_bytes_slice(ALIGNED_ADDR, &[0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50]);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &[0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50]);
emu.run(None).unwrap();
}
#[test]
fn test_psubusb_max_values() {
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(&[0x48, 0xbb]);
full_code.extend_from_slice(&ALIGNED_ADDR2.to_le_bytes());
full_code.extend_from_slice(&[
0x66, 0x0f, 0x6f, 0x00,
0x66, 0x0f, 0x6f, 0x0b,
0x66, 0x0f, 0xd8, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
emu.maps.write_bytes_slice(ALIGNED_ADDR, &[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &[0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01]);
emu.run(None).unwrap();
}
#[test]
fn test_psubusb_various_saturation_cases() {
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(&[0x48, 0xbb]);
full_code.extend_from_slice(&ALIGNED_ADDR2.to_le_bytes());
full_code.extend_from_slice(&[
0x66, 0x0f, 0x6f, 0x00,
0x66, 0x0f, 0x6f, 0x0b,
0x66, 0x0f, 0xd8, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0xFF, 0x00, 0xC8, 0x80, 0x00, 0x01, 0xFE, 0x7F,
0xAA, 0x55, 0xFF, 0xFF, 0x80, 0x90, 0xA0, 0x10];
let src2 = [0x01, 0x00, 0xC8, 0x81, 0x01, 0xFF, 0x01, 0x80,
0x56, 0xAB, 0x01, 0x10, 0x90, 0x30, 0xE0, 0x70];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src1);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src2);
emu.run(None).unwrap();
}
#[test]
fn test_psubusb_boundary_values() {
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(&[0x48, 0xbb]);
full_code.extend_from_slice(&ALIGNED_ADDR2.to_le_bytes());
full_code.extend_from_slice(&[
0x66, 0x0f, 0x6f, 0x00,
0x66, 0x0f, 0x6f, 0x0b,
0x66, 0x0f, 0xd8, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0x01, 0x00, 0x02, 0x01, 0x80, 0x7F, 0xC0, 0xBF,
0x01, 0x02, 0xFE, 0xFD, 0xAA, 0x55, 0x00, 0xFF];
let src2 = [0x01, 0x01, 0x02, 0x02, 0x7F, 0x80, 0x3F, 0x40,
0x02, 0x03, 0xFF, 0xFE, 0x55, 0xAA, 0xFF, 0x00];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src1);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src2);
emu.run(None).unwrap();
}
#[test]
fn test_psubusb_memory_operand() {
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(&[0x48, 0xbb]);
full_code.extend_from_slice(&ALIGNED_ADDR2.to_le_bytes());
full_code.extend_from_slice(&[
0x66, 0x0f, 0x6f, 0x00,
0x66, 0x0f, 0xd8, 0x03,
0xf4,
]);
emu.load_code_bytes(&full_code);
emu.maps.write_bytes_slice(ALIGNED_ADDR, &[0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10]);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &[0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20]);
emu.run(None).unwrap();
}
#[test]
fn test_psubusb_xmm_self() {
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(&[
0x66, 0x0f, 0x6f, 0x00,
0x66, 0x0f, 0xd8, 0xc0,
0xf4,
]);
emu.load_code_bytes(&full_code);
emu.maps.write_bytes_slice(ALIGNED_ADDR, &[0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80]);
emu.run(None).unwrap();
}
#[test]
fn test_psubusb_alternating_pattern() {
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(&[0x48, 0xbb]);
full_code.extend_from_slice(&ALIGNED_ADDR2.to_le_bytes());
full_code.extend_from_slice(&[
0x66, 0x0f, 0x6f, 0x00,
0x66, 0x0f, 0x6f, 0x0b,
0x66, 0x0f, 0xd8, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00,
0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00];
let src2 = [0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF,
0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src1);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src2);
emu.run(None).unwrap();
}
#[test]
fn test_psubusb_incremental_values() {
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(&[0x48, 0xbb]);
full_code.extend_from_slice(&ALIGNED_ADDR2.to_le_bytes());
full_code.extend_from_slice(&[
0x66, 0x0f, 0x6f, 0x00,
0x66, 0x0f, 0x6f, 0x0b,
0x66, 0x0f, 0xd8, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F];
let src2 = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src1);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src2);
emu.run(None).unwrap();
}
#[test]
fn test_psubusb_different_registers() {
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(&[0x48, 0xbb]);
full_code.extend_from_slice(&ALIGNED_ADDR2.to_le_bytes());
full_code.extend_from_slice(&[
0x66, 0x0f, 0x6f, 0x10,
0x66, 0x0f, 0x6f, 0x1b,
0x66, 0x0f, 0xd8, 0xd3,
0xf4,
]);
emu.load_code_bytes(&full_code);
emu.maps.write_bytes_slice(ALIGNED_ADDR, &[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &[0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01]);
emu.run(None).unwrap();
}
#[test]
fn test_psubusb_sequential_operations() {
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(&[0x48, 0xbb]);
full_code.extend_from_slice(&ALIGNED_ADDR2.to_le_bytes());
full_code.extend_from_slice(&[
0x66, 0x0f, 0x6f, 0x00,
0x66, 0x0f, 0x6f, 0x0b,
0x66, 0x0f, 0xd8, 0xc1,
0x66, 0x0f, 0xd8, 0xc1,
0x66, 0x0f, 0xd8, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
emu.maps.write_bytes_slice(ALIGNED_ADDR, &[0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0, 0xA0]);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &[0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30]);
emu.run(None).unwrap();
}
#[test]
fn test_psubusb_near_zero() {
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(&[0x48, 0xbb]);
full_code.extend_from_slice(&ALIGNED_ADDR2.to_le_bytes());
full_code.extend_from_slice(&[
0x66, 0x0f, 0x6f, 0x00,
0x66, 0x0f, 0x6f, 0x0b,
0x66, 0x0f, 0xd8, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10];
let src2 = [0x01, 0x02, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src1);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src2);
emu.run(None).unwrap();
}
#[test]
fn test_psubusb_halfway_values() {
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(&[0x48, 0xbb]);
full_code.extend_from_slice(&ALIGNED_ADDR2.to_le_bytes());
full_code.extend_from_slice(&[
0x66, 0x0f, 0x6f, 0x00,
0x66, 0x0f, 0x6f, 0x0b,
0x66, 0x0f, 0xd8, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
emu.maps.write_bytes_slice(ALIGNED_ADDR, &[0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80]);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &[0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40]);
emu.run(None).unwrap();
}
#[test]
fn test_psubusb_mixed_small_large() {
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(&[0x48, 0xbb]);
full_code.extend_from_slice(&ALIGNED_ADDR2.to_le_bytes());
full_code.extend_from_slice(&[
0x66, 0x0f, 0x6f, 0x00,
0x66, 0x0f, 0x6f, 0x0b,
0x66, 0x0f, 0xd8, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0x01, 0xFF, 0x10, 0xF0, 0x20, 0xE0, 0x30, 0xD0,
0x40, 0xC0, 0x50, 0xB0, 0x60, 0xA0, 0x70, 0x90];
let src2 = [0x02, 0x00, 0x20, 0x10, 0x30, 0x20, 0x40, 0x30,
0x50, 0x40, 0x60, 0x50, 0x70, 0x60, 0x80, 0x70];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src1);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src2);
emu.run(None).unwrap();
}
#[test]
fn test_psubusb_powers_of_two() {
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(&[0x48, 0xbb]);
full_code.extend_from_slice(&ALIGNED_ADDR2.to_le_bytes());
full_code.extend_from_slice(&[
0x66, 0x0f, 0x6f, 0x00,
0x66, 0x0f, 0x6f, 0x0b,
0x66, 0x0f, 0xd8, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01,
0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01];
let src2 = [0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src1);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src2);
emu.run(None).unwrap();
}
#[test]
fn test_psubusw_all_zeros() {
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(&[0x48, 0xbb]);
full_code.extend_from_slice(&ALIGNED_ADDR2.to_le_bytes());
full_code.extend_from_slice(&[
0x66, 0x0f, 0x6f, 0x00,
0x66, 0x0f, 0x6f, 0x0b,
0x66, 0x0f, 0xd9, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
emu.maps.write_bytes_slice(ALIGNED_ADDR, &[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
emu.run(None).unwrap();
}
#[test]
fn test_psubusw_no_saturation() {
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(&[0x48, 0xbb]);
full_code.extend_from_slice(&ALIGNED_ADDR2.to_le_bytes());
full_code.extend_from_slice(&[
0x66, 0x0f, 0x6f, 0x00,
0x66, 0x0f, 0x6f, 0x0b,
0x66, 0x0f, 0xd9, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0x00, 0x50, 0x00, 0x50, 0x00, 0x50, 0x00, 0x50,
0x00, 0x50, 0x00, 0x50, 0x00, 0x50, 0x00, 0x50];
let src2 = [0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30,
0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src1);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src2);
emu.run(None).unwrap();
}
#[test]
fn test_psubusw_saturate_to_zero() {
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(&[0x48, 0xbb]);
full_code.extend_from_slice(&ALIGNED_ADDR2.to_le_bytes());
full_code.extend_from_slice(&[
0x66, 0x0f, 0x6f, 0x00,
0x66, 0x0f, 0x6f, 0x0b,
0x66, 0x0f, 0xd9, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10,
0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10];
let src2 = [0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20,
0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src1);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src2);
emu.run(None).unwrap();
}
#[test]
fn test_psubusw_exact_zero() {
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(&[0x48, 0xbb]);
full_code.extend_from_slice(&ALIGNED_ADDR2.to_le_bytes());
full_code.extend_from_slice(&[
0x66, 0x0f, 0x6f, 0x00,
0x66, 0x0f, 0x6f, 0x0b,
0x66, 0x0f, 0xd9, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src = [0x00, 0x50, 0x00, 0x50, 0x00, 0x50, 0x00, 0x50,
0x00, 0x50, 0x00, 0x50, 0x00, 0x50, 0x00, 0x50];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src);
emu.run(None).unwrap();
}
#[test]
fn test_psubusw_max_values() {
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(&[0x48, 0xbb]);
full_code.extend_from_slice(&ALIGNED_ADDR2.to_le_bytes());
full_code.extend_from_slice(&[
0x66, 0x0f, 0x6f, 0x00,
0x66, 0x0f, 0x6f, 0x0b,
0x66, 0x0f, 0xd9, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF];
let src2 = [0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src1);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src2);
emu.run(None).unwrap();
}
#[test]
fn test_psubusw_various_saturation_cases() {
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(&[0x48, 0xbb]);
full_code.extend_from_slice(&ALIGNED_ADDR2.to_le_bytes());
full_code.extend_from_slice(&[
0x66, 0x0f, 0x6f, 0x00,
0x66, 0x0f, 0x6f, 0x0b,
0x66, 0x0f, 0xd9, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0xFF, 0xFF, 0x00, 0x00, 0x00, 0x80, 0x00, 0x40,
0x00, 0x00, 0x01, 0x00, 0xFF, 0xFF, 0xFE, 0xFF];
let src2 = [0x01, 0x00, 0x01, 0x00, 0x01, 0x80, 0xFF, 0x40,
0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0xFF, 0xFF];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src1);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src2);
emu.run(None).unwrap();
}
#[test]
fn test_psubusw_memory_operand() {
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(&[0x48, 0xbb]);
full_code.extend_from_slice(&ALIGNED_ADDR2.to_le_bytes());
full_code.extend_from_slice(&[
0x66, 0x0f, 0x6f, 0x00,
0x66, 0x0f, 0xd9, 0x03,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10,
0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10];
let src2 = [0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20,
0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src1);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src2);
emu.run(None).unwrap();
}
#[test]
fn test_psubusw_xmm_self() {
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(&[
0x66, 0x0f, 0x6f, 0x00,
0x66, 0x0f, 0xd9, 0xc0,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src = [0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80,
0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src);
emu.run(None).unwrap();
}
#[test]
fn test_psubusw_alternating_pattern() {
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(&[0x48, 0xbb]);
full_code.extend_from_slice(&ALIGNED_ADDR2.to_le_bytes());
full_code.extend_from_slice(&[
0x66, 0x0f, 0x6f, 0x00,
0x66, 0x0f, 0x6f, 0x0b,
0x66, 0x0f, 0xd9, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00,
0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00];
let src2 = [0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF,
0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src1);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src2);
emu.run(None).unwrap();
}
#[test]
fn test_psubusw_incremental_values() {
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(&[0x48, 0xbb]);
full_code.extend_from_slice(&ALIGNED_ADDR2.to_le_bytes());
full_code.extend_from_slice(&[
0x66, 0x0f, 0x6f, 0x00,
0x66, 0x0f, 0x6f, 0x0b,
0x66, 0x0f, 0xd9, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0x00, 0x20, 0x00, 0x21, 0x00, 0x22, 0x00, 0x23,
0x00, 0x24, 0x00, 0x25, 0x00, 0x26, 0x00, 0x27];
let src2 = [0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03,
0x00, 0x04, 0x00, 0x05, 0x00, 0x06, 0x00, 0x07];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src1);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src2);
emu.run(None).unwrap();
}
#[test]
fn test_psubusw_different_registers() {
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(&[0x48, 0xbb]);
full_code.extend_from_slice(&ALIGNED_ADDR2.to_le_bytes());
full_code.extend_from_slice(&[
0x66, 0x0f, 0x6f, 0x38,
0x66, 0x0f, 0x6f, 0x03,
0x66, 0x0f, 0xd9, 0xf8,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF];
let src2 = [0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00,
0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src1);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src2);
emu.run(None).unwrap();
}
#[test]
fn test_psubusw_sequential_operations() {
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(&[0x48, 0xbb]);
full_code.extend_from_slice(&ALIGNED_ADDR2.to_le_bytes());
full_code.extend_from_slice(&[
0x66, 0x0f, 0x6f, 0x00,
0x66, 0x0f, 0x6f, 0x0b,
0x66, 0x0f, 0xd9, 0xc1,
0x66, 0x0f, 0xd9, 0xc1,
0x66, 0x0f, 0xd9, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0x00, 0xA0, 0x00, 0xA0, 0x00, 0xA0, 0x00, 0xA0,
0x00, 0xA0, 0x00, 0xA0, 0x00, 0xA0, 0x00, 0xA0];
let src2 = [0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30,
0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src1);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src2);
emu.run(None).unwrap();
}
#[test]
fn test_psubusw_near_zero() {
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(&[0x48, 0xbb]);
full_code.extend_from_slice(&ALIGNED_ADDR2.to_le_bytes());
full_code.extend_from_slice(&[
0x66, 0x0f, 0x6f, 0x00,
0x66, 0x0f, 0x6f, 0x0b,
0x66, 0x0f, 0xd9, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0x00,
0x05, 0x00, 0x06, 0x00, 0x07, 0x00, 0x08, 0x00];
let src2 = [0x01, 0x00, 0x03, 0x00, 0x04, 0x00, 0x05, 0x00,
0x06, 0x00, 0x07, 0x00, 0x08, 0x00, 0x09, 0x00];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src1);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src2);
emu.run(None).unwrap();
}
#[test]
fn test_psubusw_halfway_values() {
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(&[0x48, 0xbb]);
full_code.extend_from_slice(&ALIGNED_ADDR2.to_le_bytes());
full_code.extend_from_slice(&[
0x66, 0x0f, 0x6f, 0x00,
0x66, 0x0f, 0x6f, 0x0b,
0x66, 0x0f, 0xd9, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80,
0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80];
let src2 = [0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40,
0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src1);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src2);
emu.run(None).unwrap();
}
#[test]
fn test_psubusw_boundary_values() {
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(&[0x48, 0xbb]);
full_code.extend_from_slice(&ALIGNED_ADDR2.to_le_bytes());
full_code.extend_from_slice(&[
0x66, 0x0f, 0x6f, 0x00,
0x66, 0x0f, 0x6f, 0x0b,
0x66, 0x0f, 0xd9, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0x01, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x40,
0x01, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0x00];
let src2 = [0x01, 0x00, 0x01, 0x00, 0x01, 0x80, 0xFF, 0x40,
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src1);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src2);
emu.run(None).unwrap();
}
#[test]
fn test_psubusw_mixed_small_large() {
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(&[0x48, 0xbb]);
full_code.extend_from_slice(&ALIGNED_ADDR2.to_le_bytes());
full_code.extend_from_slice(&[
0x66, 0x0f, 0x6f, 0x00,
0x66, 0x0f, 0x6f, 0x0b,
0x66, 0x0f, 0xd9, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0x00, 0x01, 0xFF, 0xFF, 0x00, 0x10, 0x00, 0xF0,
0x00, 0x20, 0x00, 0xE0, 0x00, 0x30, 0x00, 0xD0];
let src2 = [0x01, 0x01, 0x00, 0x00, 0x01, 0x10, 0xFF, 0xF0,
0x01, 0x20, 0xFF, 0xE0, 0x01, 0x30, 0xFF, 0xD0];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src1);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src2);
emu.run(None).unwrap();
}
#[test]
fn test_psubusw_powers_of_two() {
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(&[0x48, 0xbb]);
full_code.extend_from_slice(&ALIGNED_ADDR2.to_le_bytes());
full_code.extend_from_slice(&[
0x66, 0x0f, 0x6f, 0x00,
0x66, 0x0f, 0x6f, 0x0b,
0x66, 0x0f, 0xd9, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0x00, 0x80, 0x00, 0x40, 0x00, 0x20, 0x00, 0x10,
0x00, 0x08, 0x00, 0x04, 0x00, 0x02, 0x00, 0x01];
let src2 = [0x00, 0x01, 0x00, 0x02, 0x00, 0x04, 0x00, 0x08,
0x00, 0x10, 0x00, 0x20, 0x00, 0x40, 0x00, 0x80];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src1);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src2);
emu.run(None).unwrap();
}