use crate::*;
const ALIGNED_ADDR: u64 = 0x3000;
#[test]
fn test_vldmxcsr_basic() {
let mut emu = emu64();
let code = [
0xc5, 0xf8, 0xae, 0x15, 0x00, 0x40, 0x00, 0x00, 0xf4, ];
emu.load_code_bytes(&code);
let mxcsr: [u8; 4] = [0x80, 0x1f, 0x00, 0x00];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &mxcsr);
emu.run(None).unwrap();
}
#[test]
fn test_vldmxcsr_round_to_zero() {
let mut emu = emu64();
let code = [
0xc5, 0xf8, 0xae, 0x15, 0x00, 0x40, 0x00, 0x00, 0xf4, ];
emu.load_code_bytes(&code);
let mxcsr: [u8; 4] = [0x80, 0x7f, 0x00, 0x00];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &mxcsr);
emu.run(None).unwrap();
}
#[test]
fn test_vldmxcsr_round_down() {
let mut emu = emu64();
let code = [
0xc5, 0xf8, 0xae, 0x15, 0x00, 0x40, 0x00, 0x00, 0xf4, ];
emu.load_code_bytes(&code);
let mxcsr: [u8; 4] = [0x80, 0x3f, 0x00, 0x00];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &mxcsr);
emu.run(None).unwrap();
}
#[test]
fn test_vldmxcsr_round_up() {
let mut emu = emu64();
let code = [
0xc5, 0xf8, 0xae, 0x15, 0x00, 0x40, 0x00, 0x00, 0xf4, ];
emu.load_code_bytes(&code);
let mxcsr: [u8; 4] = [0x80, 0x5f, 0x00, 0x00];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &mxcsr);
emu.run(None).unwrap();
}
#[test]
fn test_vldmxcsr_flush_to_zero() {
let mut emu = emu64();
let code = [
0xc5, 0xf8, 0xae, 0x15, 0x00, 0x40, 0x00, 0x00, 0xf4, ];
emu.load_code_bytes(&code);
let mxcsr: [u8; 4] = [0x80, 0x9f, 0x00, 0x00];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &mxcsr);
emu.run(None).unwrap();
}
#[test]
fn test_vldmxcsr_denormals_are_zero() {
let mut emu = emu64();
let code = [
0xc5, 0xf8, 0xae, 0x15, 0x00, 0x40, 0x00, 0x00, 0xf4, ];
emu.load_code_bytes(&code);
let mxcsr: [u8; 4] = [0xc0, 0x1f, 0x00, 0x00];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &mxcsr);
emu.run(None).unwrap();
}
#[test]
fn test_vldmxcsr_all_exceptions_unmasked() {
let mut emu = emu64();
let code = [
0xc5, 0xf8, 0xae, 0x15, 0x00, 0x40, 0x00, 0x00, 0xf4, ];
emu.load_code_bytes(&code);
let mxcsr: [u8; 4] = [0x00, 0x1f, 0x00, 0x00];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &mxcsr);
emu.run(None).unwrap();
}
#[test]
fn test_vldmxcsr_invalid_operation_unmasked() {
let mut emu = emu64();
let code = [
0xc5, 0xf8, 0xae, 0x15, 0x00, 0x40, 0x00, 0x00, 0xf4, ];
emu.load_code_bytes(&code);
let mxcsr: [u8; 4] = [0x00, 0x1f, 0x00, 0x00];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &mxcsr);
emu.run(None).unwrap();
}
#[test]
fn test_vldmxcsr_divide_by_zero_unmasked() {
let mut emu = emu64();
let code = [
0xc5, 0xf8, 0xae, 0x15, 0x00, 0x40, 0x00, 0x00, 0xf4, ];
emu.load_code_bytes(&code);
let mxcsr: [u8; 4] = [0x80, 0x1d, 0x00, 0x00];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &mxcsr);
emu.run(None).unwrap();
}
#[test]
fn test_vldmxcsr_overflow_unmasked() {
let mut emu = emu64();
let code = [
0xc5, 0xf8, 0xae, 0x15, 0x00, 0x40, 0x00, 0x00, 0xf4, ];
emu.load_code_bytes(&code);
let mxcsr: [u8; 4] = [0x80, 0x1b, 0x00, 0x00];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &mxcsr);
emu.run(None).unwrap();
}
#[test]
fn test_vldmxcsr_underflow_unmasked() {
let mut emu = emu64();
let code = [
0xc5, 0xf8, 0xae, 0x15, 0x00, 0x40, 0x00, 0x00, 0xf4, ];
emu.load_code_bytes(&code);
let mxcsr: [u8; 4] = [0x80, 0x17, 0x00, 0x00];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &mxcsr);
emu.run(None).unwrap();
}
#[test]
fn test_vldmxcsr_precision_unmasked() {
let mut emu = emu64();
let code = [
0xc5, 0xf8, 0xae, 0x15, 0x00, 0x40, 0x00, 0x00, 0xf4, ];
emu.load_code_bytes(&code);
let mxcsr: [u8; 4] = [0x80, 0x0f, 0x00, 0x00];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &mxcsr);
emu.run(None).unwrap();
}
#[test]
fn test_vldmxcsr_multiple_loads() {
let mut emu = emu64();
let code = [
0xc5, 0xf8, 0xae, 0x15, 0x00, 0x40, 0x00, 0x00, 0xc5, 0xf8, 0xae, 0x15, 0x04, 0x40, 0x00, 0x00, 0xf4, ];
emu.load_code_bytes(&code);
let mxcsr1: [u8; 4] = [0x80, 0x1f, 0x00, 0x00];
let mxcsr2: [u8; 4] = [0x80, 0x7f, 0x00, 0x00];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &mxcsr1);
emu.maps.write_bytes_slice(ALIGNED_ADDR + 4, &mxcsr2);
emu.run(None).unwrap();
}
#[test]
fn test_vldmxcsr_before_arithmetic() {
let mut emu = emu64();
let code = [
0xc5, 0xf8, 0xae, 0x15, 0x00, 0x40, 0x00, 0x00, 0xc5, 0xf0, 0x58, 0xc2, 0xf4, ];
emu.load_code_bytes(&code);
let mxcsr: [u8; 4] = [0x80, 0x1f, 0x00, 0x00];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &mxcsr);
emu.run(None).unwrap();
}
#[test]
fn test_vldmxcsr_rax_indirect() {
let mut emu = emu64();
let code = [
0x48, 0xb8, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc5, 0xf8, 0xae, 0x10, 0xf4, ];
emu.load_code_bytes(&code);
let mxcsr: [u8; 4] = [0x80, 0x1f, 0x00, 0x00];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &mxcsr);
emu.run(None).unwrap();
}
#[test]
fn test_vldmxcsr_rbx_indirect() {
let mut emu = emu64();
let code = [
0x48, 0xbb, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc5, 0xf8, 0xae, 0x13, 0xf4, ];
emu.load_code_bytes(&code);
let mxcsr: [u8; 4] = [0x80, 0x1f, 0x00, 0x00];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &mxcsr);
emu.run(None).unwrap();
}
#[test]
fn test_vldmxcsr_rcx_indirect() {
let mut emu = emu64();
let code = [
0x48, 0xb9, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc5, 0xf8, 0xae, 0x11, 0xf4, ];
emu.load_code_bytes(&code);
let mxcsr: [u8; 4] = [0x80, 0x1f, 0x00, 0x00];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &mxcsr);
emu.run(None).unwrap();
}
#[test]
fn test_vldmxcsr_offset() {
let mut emu = emu64();
let code = [
0x48, 0xb8, 0xf0, 0x2f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc5, 0xf8, 0xae, 0x50, 0x10, 0xf4, ];
emu.load_code_bytes(&code);
let mxcsr: [u8; 4] = [0x80, 0x1f, 0x00, 0x00];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &mxcsr);
emu.run(None).unwrap();
}
#[test]
fn test_vstmxcsr_basic() {
let mut emu = emu64();
let code = [
0xc5, 0xf8, 0xae, 0x1d, 0x00, 0x40, 0x00, 0x00, 0xf4, ];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_vstmxcsr_after_load() {
let mut emu = emu64();
let code = [
0xc5, 0xf8, 0xae, 0x15, 0x00, 0x40, 0x00, 0x00, 0xc5, 0xf8, 0xae, 0x1d, 0x04, 0x40, 0x00, 0x00, 0xf4, ];
emu.load_code_bytes(&code);
let mxcsr: [u8; 4] = [0x80, 0x7f, 0x00, 0x00];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &mxcsr);
emu.run(None).unwrap();
}
#[test]
fn test_vstmxcsr_multiple_stores() {
let mut emu = emu64();
let code = [
0xc5, 0xf8, 0xae, 0x1d, 0x00, 0x40, 0x00, 0x00, 0xc5, 0xf8, 0xae, 0x1d, 0x04, 0x40, 0x00, 0x00, 0xf4, ];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_vstmxcsr_after_arithmetic() {
let mut emu = emu64();
let code = [
0xc5, 0xf0, 0x58, 0xc2, 0xc5, 0xf8, 0xae, 0x1d, 0x00, 0x40, 0x00, 0x00, 0xf4, ];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_vstmxcsr_rax_indirect() {
let mut emu = emu64();
let code = [
0x48, 0xb8, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc5, 0xf8, 0xae, 0x18, 0xf4, ];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_vstmxcsr_rbx_indirect() {
let mut emu = emu64();
let code = [
0x48, 0xbb, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc5, 0xf8, 0xae, 0x1b, 0xf4, ];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_vstmxcsr_rcx_indirect() {
let mut emu = emu64();
let code = [
0x48, 0xb9, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc5, 0xf8, 0xae, 0x19, 0xf4, ];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_vstmxcsr_offset() {
let mut emu = emu64();
let code = [
0x48, 0xb8, 0xf0, 0x2f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc5, 0xf8, 0xae, 0x58, 0x10, 0xf4, ];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_ldmxcsr_stmxcsr_roundtrip() {
let mut emu = emu64();
let code = [
0xc5, 0xf8, 0xae, 0x15, 0x00, 0x40, 0x00, 0x00, 0xc5, 0xf8, 0xae, 0x1d, 0x04, 0x40, 0x00, 0x00, 0xf4, ];
emu.load_code_bytes(&code);
let mxcsr: [u8; 4] = [0x80, 0x7f, 0x00, 0x00];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &mxcsr);
emu.run(None).unwrap();
}
#[test]
fn test_ldmxcsr_arithmetic_stmxcsr() {
let mut emu = emu64();
let code = [
0xc5, 0xf8, 0xae, 0x15, 0x00, 0x40, 0x00, 0x00, 0xc5, 0xf0, 0x58, 0xc2, 0xc5, 0xf8, 0xae, 0x1d, 0x04, 0x40, 0x00, 0x00, 0xf4, ];
emu.load_code_bytes(&code);
let mxcsr: [u8; 4] = [0x80, 0x1f, 0x00, 0x00];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &mxcsr);
emu.run(None).unwrap();
}
#[test]
fn test_multiple_ldmxcsr_stmxcsr_pairs() {
let mut emu = emu64();
let code = [
0xc5, 0xf8, 0xae, 0x15, 0x00, 0x40, 0x00, 0x00, 0xc5, 0xf8, 0xae, 0x1d, 0x08, 0x40, 0x00, 0x00, 0xc5, 0xf8, 0xae, 0x15, 0x04, 0x40, 0x00, 0x00, 0xc5, 0xf8, 0xae, 0x1d, 0x0c, 0x40, 0x00, 0x00, 0xf4, ];
emu.load_code_bytes(&code);
let mxcsr1: [u8; 4] = [0x80, 0x1f, 0x00, 0x00];
let mxcsr2: [u8; 4] = [0x80, 0x7f, 0x00, 0x00];
emu.maps.write_bytes_slice(ALIGNED_ADDR, &mxcsr1);
emu.maps.write_bytes_slice(ALIGNED_ADDR + 4, &mxcsr2);
emu.run(None).unwrap();
}
#[test]
fn test_ldmxcsr_save_restore_pattern() {
let mut emu = emu64();
let code = [
0xc5, 0xf8, 0xae, 0x1d, 0x00, 0x40, 0x00, 0x00, 0xc5, 0xf8, 0xae, 0x15, 0x04, 0x40, 0x00, 0x00, 0xc5, 0xf0, 0x58, 0xc2, 0xc5, 0xf8, 0xae, 0x15, 0x00, 0x40, 0x00, 0x00, 0xf4, ];
emu.load_code_bytes(&code);
let mxcsr_new: [u8; 4] = [0x80, 0x7f, 0x00, 0x00];
emu.maps.write_bytes_slice(ALIGNED_ADDR + 4, &mxcsr_new);
emu.run(None).unwrap();
}
#[test]
fn test_vstmxcsr_after_division() {
let mut emu = emu64();
let code = [
0xc5, 0xf0, 0x5e, 0xc2, 0xc5, 0xf8, 0xae, 0x1d, 0x00, 0x40, 0x00, 0x00, 0xf4, ];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_vstmxcsr_after_sqrt() {
let mut emu = emu64();
let code = [
0xc5, 0xf8, 0x51, 0xc1, 0xc5, 0xf8, 0xae, 0x1d, 0x00, 0x40, 0x00, 0x00, 0xf4, ];
emu.load_code_bytes(&code);
emu.run(None).unwrap();
}
#[test]
fn test_ldmxcsr_context_switch() {
let mut emu = emu64();
let code = [
0xc5, 0xf8, 0xae, 0x1d, 0x00, 0x40, 0x00, 0x00, 0xc5, 0xf8, 0xae, 0x15, 0x04, 0x40, 0x00, 0x00, 0xc5, 0xf0, 0x58, 0xc2, 0xc5, 0xf8, 0xae, 0x1d, 0x04, 0x40, 0x00, 0x00, 0xc5, 0xf8, 0xae, 0x15, 0x00, 0x40, 0x00, 0x00, 0xf4, ];
emu.load_code_bytes(&code);
let mxcsr2: [u8; 4] = [0x80, 0x7f, 0x00, 0x00];
emu.maps.write_bytes_slice(ALIGNED_ADDR + 4, &mxcsr2);
emu.run(None).unwrap();
}