use crate::*;
const ALIGNED_ADDR: u64 = 0x3000;
const ALIGNED_ADDR2: u64 = 0x3100;
#[test]
fn test_psubsb_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, 0xe8, 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_psubsb_positive_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, 0xe8, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
emu.maps.write_bytes_slice(ALIGNED_ADDR, &[0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30]);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &[0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10]);
emu.run(None).unwrap();
}
#[test]
fn test_psubsb_negative_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, 0xe8, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
emu.maps.write_bytes_slice(ALIGNED_ADDR, &[0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0]);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &[0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0, 0xE0]);
emu.run(None).unwrap();
}
#[test]
fn test_psubsb_saturate_positive_max() {
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, 0xe8, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
emu.maps.write_bytes_slice(ALIGNED_ADDR, &[0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F]);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]);
emu.run(None).unwrap();
}
#[test]
fn test_psubsb_saturate_positive_max_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, 0xe8, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
emu.maps.write_bytes_slice(ALIGNED_ADDR, &[0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64]);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &[0x9C, 0x9C, 0x9C, 0x9C, 0x9C, 0x9C, 0x9C, 0x9C, 0x9C, 0x9C, 0x9C, 0x9C, 0x9C, 0x9C, 0x9C, 0x9C]);
emu.run(None).unwrap();
}
#[test]
fn test_psubsb_saturate_negative_min() {
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, 0xe8, 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, &[0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01]);
emu.run(None).unwrap();
}
#[test]
fn test_psubsb_saturate_negative_min_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, 0xe8, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
emu.maps.write_bytes_slice(ALIGNED_ADDR, &[0x9C, 0x9C, 0x9C, 0x9C, 0x9C, 0x9C, 0x9C, 0x9C, 0x9C, 0x9C, 0x9C, 0x9C, 0x9C, 0x9C, 0x9C, 0x9C]);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &[0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64]);
emu.run(None).unwrap();
}
#[test]
fn test_psubsb_mixed_positive_negative() {
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, 0xe8, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
emu.maps.write_bytes_slice(ALIGNED_ADDR, &[0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32, 0x32]);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &[0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E]);
emu.run(None).unwrap();
}
#[test]
fn test_psubsb_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, 0xe8, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0x7F, 0x80, 0x64, 0x9C, 0x00, 0x01, 0xFF, 0x7E,
0x81, 0x40, 0xC0, 0x7F, 0x80, 0x50, 0xA0, 0x10];
let src2 = [0xFF, 0x01, 0x9C, 0x64, 0x00, 0x01, 0xFF, 0xFF,
0x01, 0xC0, 0x40, 0xF0, 0x10, 0xD0, 0x20, 0xF0];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src1);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src2);
emu.run(None).unwrap();
}
#[test]
fn test_psubsb_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, 0xe8, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0x7E, 0x7F, 0x81, 0x80, 0x40, 0x3F, 0xC0, 0xBF,
0x7D, 0x82, 0x7C, 0x83, 0x01, 0x02, 0xFE, 0xFD];
let src2 = [0xFF, 0xFF, 0x01, 0x01, 0xC1, 0xC0, 0x40, 0x41,
0xFE, 0x02, 0xFD, 0x03, 0x82, 0x83, 0x7E, 0x7D];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src1);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src2);
emu.run(None).unwrap();
}
#[test]
fn test_psubsb_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, 0xe8, 0x03, 0xf4,
]);
emu.load_code_bytes(&full_code);
emu.maps.write_bytes_slice(ALIGNED_ADDR, &[0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F]);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]);
emu.run(None).unwrap();
}
#[test]
fn test_psubsb_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, 0xe8, 0xc0, 0xf4,
]);
emu.load_code_bytes(&full_code);
emu.maps.write_bytes_slice(ALIGNED_ADDR, &[0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40]);
emu.run(None).unwrap();
}
#[test]
fn test_psubsb_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, 0xe8, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0x7F, 0x80, 0x7F, 0x80, 0x7F, 0x80, 0x7F, 0x80,
0x7F, 0x80, 0x7F, 0x80, 0x7F, 0x80, 0x7F, 0x80];
let src2 = [0x80, 0x7F, 0x80, 0x7F, 0x80, 0x7F, 0x80, 0x7F,
0x80, 0x7F, 0x80, 0x7F, 0x80, 0x7F, 0x80, 0x7F];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src1);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src2);
emu.run(None).unwrap();
}
#[test]
fn test_psubsb_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, 0xe8, 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 = [0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src1);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src2);
emu.run(None).unwrap();
}
#[test]
fn test_psubsb_all_ff() {
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, 0xe8, 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, &[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]);
emu.run(None).unwrap();
}
#[test]
fn test_psubsb_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, 0x20, 0x66, 0x0f, 0x6f, 0x2b, 0x66, 0x0f, 0xe8, 0xe5, 0xf4,
]);
emu.load_code_bytes(&full_code);
emu.maps.write_bytes_slice(ALIGNED_ADDR, &[0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F, 0x7F]);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]);
emu.run(None).unwrap();
}
#[test]
fn test_psubsb_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, 0xe8, 0xc1, 0x66, 0x0f, 0xe8, 0xc1, 0x66, 0x0f, 0xe8, 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, &[0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10]);
emu.run(None).unwrap();
}
#[test]
fn test_psubsb_near_saturation_positive() {
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, 0xe8, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0x7E, 0x7D, 0x7C, 0x7B, 0x7A, 0x79, 0x78, 0x77,
0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x70, 0x6F];
let src2 = [0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8,
0xF7, 0xF6, 0xF5, 0xF4, 0xF3, 0xF2, 0xF1, 0xF0];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src1);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src2);
emu.run(None).unwrap();
}
#[test]
fn test_psubsb_near_saturation_negative() {
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, 0xe8, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88,
0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, 0x90];
let src2 = [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src1);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src2);
emu.run(None).unwrap();
}
#[test]
fn test_psubsw_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, 0xe9, 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_psubsw_positive_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, 0xe9, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30,
0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30];
let src2 = [0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10,
0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src1);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src2);
emu.run(None).unwrap();
}
#[test]
fn test_psubsw_negative_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, 0xe9, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF,
0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF];
let src2 = [0x00, 0xFE, 0x00, 0xFE, 0x00, 0xFE, 0x00, 0xFE,
0x00, 0xFE, 0x00, 0xFE, 0x00, 0xFE, 0x00, 0xFE];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src1);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src2);
emu.run(None).unwrap();
}
#[test]
fn test_psubsw_saturate_positive_max() {
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, 0xe9, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0xFF, 0x7F, 0xFF, 0x7F, 0xFF, 0x7F, 0xFF, 0x7F,
0xFF, 0x7F, 0xFF, 0x7F, 0xFF, 0x7F, 0xFF, 0x7F];
let src2 = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 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_psubsw_saturate_positive_max_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, 0xe9, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0x20, 0x4E, 0x20, 0x4E, 0x20, 0x4E, 0x20, 0x4E,
0x20, 0x4E, 0x20, 0x4E, 0x20, 0x4E, 0x20, 0x4E];
let src2 = [0xE0, 0xB1, 0xE0, 0xB1, 0xE0, 0xB1, 0xE0, 0xB1,
0xE0, 0xB1, 0xE0, 0xB1, 0xE0, 0xB1, 0xE0, 0xB1];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src1);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src2);
emu.run(None).unwrap();
}
#[test]
fn test_psubsw_saturate_negative_min() {
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, 0xe9, 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 = [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_psubsw_saturate_negative_min_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, 0xe9, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0xE0, 0xB1, 0xE0, 0xB1, 0xE0, 0xB1, 0xE0, 0xB1,
0xE0, 0xB1, 0xE0, 0xB1, 0xE0, 0xB1, 0xE0, 0xB1];
let src2 = [0x20, 0x4E, 0x20, 0x4E, 0x20, 0x4E, 0x20, 0x4E,
0x20, 0x4E, 0x20, 0x4E, 0x20, 0x4E, 0x20, 0x4E];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src1);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src2);
emu.run(None).unwrap();
}
#[test]
fn test_psubsw_mixed_positive_negative() {
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, 0xe9, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0xE8, 0x03, 0xE8, 0x03, 0xE8, 0x03, 0xE8, 0x03,
0xE8, 0x03, 0xE8, 0x03, 0xE8, 0x03, 0xE8, 0x03];
let src2 = [0xF4, 0x01, 0xF4, 0x01, 0xF4, 0x01, 0xF4, 0x01,
0xF4, 0x01, 0xF4, 0x01, 0xF4, 0x01, 0xF4, 0x01];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src1);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src2);
emu.run(None).unwrap();
}
#[test]
fn test_psubsw_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, 0xe9, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0xFF, 0x7F, 0x00, 0x80, 0x00, 0x40, 0x00, 0xC0,
0x00, 0x00, 0x01, 0x00, 0xFF, 0xFF, 0xFE, 0x7F];
let src2 = [0xFF, 0xFF, 0x01, 0x00, 0x01, 0xC0, 0xFF, 0x3F,
0x00, 0x00, 0x01, 0x00, 0xFF, 0xFF, 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_psubsw_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, 0xe9, 0x03, 0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0xFF, 0x7F, 0xFF, 0x7F, 0xFF, 0x7F, 0xFF, 0x7F,
0xFF, 0x7F, 0xFF, 0x7F, 0xFF, 0x7F, 0xFF, 0x7F];
let src2 = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 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_psubsw_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, 0xe9, 0xc0, 0xf4,
]);
emu.load_code_bytes(&full_code);
let src = [0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40,
0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src);
emu.run(None).unwrap();
}
#[test]
fn test_psubsw_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, 0xe9, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0xFF, 0x7F, 0x00, 0x80, 0xFF, 0x7F, 0x00, 0x80,
0xFF, 0x7F, 0x00, 0x80, 0xFF, 0x7F, 0x00, 0x80];
let src2 = [0x00, 0x80, 0xFF, 0x7F, 0x00, 0x80, 0xFF, 0x7F,
0x00, 0x80, 0xFF, 0x7F, 0x00, 0x80, 0xFF, 0x7F];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src1);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src2);
emu.run(None).unwrap();
}
#[test]
fn test_psubsw_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, 0xe9, 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, 0x10, 0x00, 0x11, 0x00, 0x12, 0x00, 0x13,
0x00, 0x14, 0x00, 0x15, 0x00, 0x16, 0x00, 0x17];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src1);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src2);
emu.run(None).unwrap();
}
#[test]
fn test_psubsw_all_ffff() {
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, 0xe9, 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, &[0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]);
emu.run(None).unwrap();
}
#[test]
fn test_psubsw_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, 0x30, 0x66, 0x0f, 0x6f, 0x3b, 0x66, 0x0f, 0xe9, 0xf7, 0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0xFF, 0x7F, 0xFF, 0x7F, 0xFF, 0x7F, 0xFF, 0x7F,
0xFF, 0x7F, 0xFF, 0x7F, 0xFF, 0x7F, 0xFF, 0x7F];
let src2 = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 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_psubsw_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, 0xe9, 0xc1, 0x66, 0x0f, 0xe9, 0xc1, 0x66, 0x0f, 0xe9, 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, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10,
0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src1);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src2);
emu.run(None).unwrap();
}
#[test]
fn test_psubsw_near_saturation_positive() {
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, 0xe9, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0xFE, 0x7F, 0xFD, 0x7F, 0xFC, 0x7F, 0xFB, 0x7F,
0xFA, 0x7F, 0xF9, 0x7F, 0xF8, 0x7F, 0xF7, 0x7F];
let src2 = [0xFF, 0xFF, 0xFE, 0xFF, 0xFD, 0xFF, 0xFC, 0xFF,
0xFB, 0xFF, 0xFA, 0xFF, 0xF9, 0xFF, 0xF8, 0xFF];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src1);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src2);
emu.run(None).unwrap();
}
#[test]
fn test_psubsw_near_saturation_negative() {
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, 0xe9, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0x01, 0x80, 0x02, 0x80, 0x03, 0x80, 0x04, 0x80,
0x05, 0x80, 0x06, 0x80, 0x07, 0x80, 0x08, 0x80];
let src2 = [0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0x00,
0x05, 0x00, 0x06, 0x00, 0x07, 0x00, 0x08, 0x00];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src1);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src2);
emu.run(None).unwrap();
}
#[test]
fn test_psubsw_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, 0xe9, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0xFE, 0x7F, 0x00, 0x80, 0x00, 0x40, 0x00, 0xC0,
0x01, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0x00];
let src2 = [0xFF, 0xFF, 0x01, 0x00, 0x01, 0xC0, 0xFF, 0x3F,
0x82, 0x80, 0xFF, 0x7F, 0x00, 0x00, 0xFF, 0xFF];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src1);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src2);
emu.run(None).unwrap();
}