use crate::*;
const ALIGNED_ADDR: u64 = 0x3000;
const ALIGNED_ADDR2: u64 = 0x3100;
#[test]
fn test_paddusb_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, 0xdc, 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_paddusb_small_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, 0xdc, 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_paddusb_saturate_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, 0xdc, 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_paddusb_saturate_large_overflow() {
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, 0xdc, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
emu.maps.write_bytes_slice(ALIGNED_ADDR, &[0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8]);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &[0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8, 0xC8]);
emu.run(None).unwrap();
}
#[test]
fn test_paddusb_all_ones() {
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, 0xdc, 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_paddusb_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, 0xdc, 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, 0x80, 0x00, 0xFF, 0x01, 0x80,
0x56, 0xAA, 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_paddusb_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, 0xdc, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0xFE, 0xFF, 0xFD, 0xFC, 0x80, 0x7F, 0xC0, 0xBF,
0x01, 0x02, 0xFE, 0xFD, 0xAA, 0x55, 0x00, 0xFF];
let src2 = [0x01, 0x01, 0x02, 0x03, 0x7F, 0x80, 0x3F, 0x40,
0xFE, 0xFD, 0x01, 0x02, 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_paddusb_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, 0xdc, 0x03, 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_paddusb_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, 0xdc, 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_paddusb_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, 0xdc, 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 = [0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00,
0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 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_paddusb_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, 0xdc, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F];
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_paddusb_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, 0xdc, 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_paddusb_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, 0xdc, 0xc1, 0x66, 0x0f, 0xdc, 0xc1, 0x66, 0x0f, 0xdc, 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_paddusb_near_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, 0xdc, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8, 0xF7,
0xF6, 0xF5, 0xF4, 0xF3, 0xF2, 0xF1, 0xF0, 0xEF];
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_paddusb_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, 0xdc, 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, &[0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80]);
emu.run(None).unwrap();
}
#[test]
fn test_paddusb_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, 0xdc, 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 = [0x01, 0xFF, 0x10, 0xF0, 0x20, 0xE0, 0x30, 0xD0,
0x40, 0xC0, 0x50, 0xB0, 0x60, 0xA0, 0x70, 0x90];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src1);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src2);
emu.run(None).unwrap();
}
#[test]
fn test_paddusb_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, 0xdc, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80];
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_paddusw_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, 0xdd, 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_paddusw_small_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, 0xdd, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0x00, 0x10, 0x00, 0x20, 0x00, 0x30, 0x00, 0x40,
0x00, 0x50, 0x00, 0x60, 0x00, 0x70, 0x00, 0x01];
let src2 = [0x00, 0x10, 0x00, 0x20, 0x00, 0x30, 0x00, 0x40,
0x00, 0x50, 0x00, 0x60, 0x00, 0x70, 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_paddusw_saturate_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, 0xdd, 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_paddusw_saturate_large_overflow() {
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, 0xdd, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0x50, 0xC3, 0x50, 0xC3, 0x50, 0xC3, 0x50, 0xC3,
0x50, 0xC3, 0x50, 0xC3, 0x50, 0xC3, 0x50, 0xC3];
let src2 = [0x50, 0xC3, 0x50, 0xC3, 0x50, 0xC3, 0x50, 0xC3,
0x50, 0xC3, 0x50, 0xC3, 0x50, 0xC3, 0x50, 0xC3];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src1);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src2);
emu.run(None).unwrap();
}
#[test]
fn test_paddusw_all_ones() {
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, 0xdd, 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_paddusw_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, 0xdd, 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, 0x00, 0x00, 0x00, 0x80, 0x00, 0x40,
0x00, 0x00, 0xFF, 0xFF, 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_paddusw_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, 0xdd, 0x03, 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_paddusw_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, 0xdd, 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_paddusw_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, 0xdd, 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 = [0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00,
0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src1);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src2);
emu.run(None).unwrap();
}
#[test]
fn test_paddusw_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, 0xdd, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x04,
0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x00, 0x08];
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_paddusw_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, 0xdd, 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_paddusw_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, 0xdd, 0xc1, 0x66, 0x0f, 0xdd, 0xc1, 0x66, 0x0f, 0xdd, 0xc1, 0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20,
0x00, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x20];
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_paddusw_near_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, 0xdd, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0xFE, 0xFF, 0xFD, 0xFF, 0xFC, 0xFF, 0xFB, 0xFF,
0xFA, 0xFF, 0xF9, 0xFF, 0xF8, 0xFF, 0xF7, 0xFF];
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_paddusw_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, 0xdd, 0xc1,
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.maps.write_bytes_slice(ALIGNED_ADDR2, &src);
emu.run(None).unwrap();
}
#[test]
fn test_paddusw_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, 0xdd, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0xFE, 0xFF, 0x00, 0x00, 0x00, 0x80, 0x00, 0x40,
0x01, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0x00];
let src2 = [0x01, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x00, 0x40,
0xFE, 0xFF, 0x01, 0x00, 0x00, 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_paddusw_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, 0xdd, 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 = [0x00, 0x01, 0xFF, 0xFF, 0x00, 0x10, 0x00, 0xF0,
0x00, 0x20, 0x00, 0xE0, 0x00, 0x30, 0x00, 0xD0];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src1);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src2);
emu.run(None).unwrap();
}
#[test]
fn test_paddusw_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, 0xdd, 0xc1,
0xf4,
]);
emu.load_code_bytes(&full_code);
let src1 = [0x01, 0x00, 0x02, 0x00, 0x04, 0x00, 0x08, 0x00,
0x10, 0x00, 0x20, 0x00, 0x40, 0x00, 0x80, 0x00];
let src2 = [0x01, 0x00, 0x02, 0x00, 0x04, 0x00, 0x08, 0x00,
0x10, 0x00, 0x20, 0x00, 0x40, 0x00, 0x80, 0x00];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &src1);
emu.maps.write_bytes_slice(ALIGNED_ADDR2, &src2);
emu.run(None).unwrap();
}