aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG3
-rw-r--r--src/long_mode/vex.rs108
-rw-r--r--test/long_mode/mod.rs38
3 files changed, 113 insertions, 36 deletions
diff --git a/CHANGELOG b/CHANGELOG
index fc50100..7ceeef0 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -23,6 +23,9 @@
* monitor now reports the memory access size of the monitored dword/qword.
* fix incorrect operand order for VEX-encoded vmovupd opcode 0x11.
* reject a few VEX-encoded instructions that are specific about allowed W-bits.
+ vcvtph2ps, vbroadcastf128, vmaskmovps, vmaskmovpd, vpermd, vpbroadcast{b,w,d,q}, among others
+* vpbroadcastb and vpbroadcastw should respect the L bit to select xmm/ymm vector width, but
+ always decoded as ymm.
## 2.0.0
diff --git a/src/long_mode/vex.rs b/src/long_mode/vex.rs
index b0b900a..b43b0fe 100644
--- a/src/long_mode/vex.rs
+++ b/src/long_mode/vex.rs
@@ -2093,7 +2093,11 @@ fn read_vex_instruction<
} else {
VEXOperandCode::G_E_xyLmm
}),
- 0x13 => (Opcode::VCVTPH2PS, VEXOperandCode::G_E_xyLmm),
+ 0x13 => (Opcode::VCVTPH2PS, if instruction.prefixes.vex_unchecked().w() {
+ return Err(DecodeError::InvalidOpcode);
+ } else {
+ VEXOperandCode::G_E_xyLmm
+ }),
0x16 => (Opcode::VPERMPS, if L {
if instruction.prefixes.vex_unchecked().w() {
return Err(DecodeError::InvalidOpcode);
@@ -2118,14 +2122,18 @@ fn read_vex_instruction<
(Opcode::VBROADCASTSD, if L {
VEXOperandCode::G_ymm_E_xmm
} else {
- VEXOperandCode::G_E_xmm
+ return Err(DecodeError::InvalidOpcode);
})
}
- 0x1A => (Opcode::VBROADCASTF128, if L {
- VEXOperandCode::G_ymm_M_xmm
- } else {
+ 0x1A => if instruction.prefixes.vex_unchecked().w() {
return Err(DecodeError::InvalidOpcode);
- }),
+ } else {
+ (Opcode::VBROADCASTF128, if L {
+ VEXOperandCode::G_ymm_M_xmm
+ } else {
+ return Err(DecodeError::InvalidOpcode);
+ })
+ },
0x1C => (Opcode::VPABSB, VEXOperandCode::G_E_xyLmm),
0x1D => (Opcode::VPABSW, VEXOperandCode::G_E_xyLmm),
0x1E => (Opcode::VPABSD, VEXOperandCode::G_E_xyLmm),
@@ -2167,26 +2175,42 @@ fn read_vex_instruction<
VEXOperandCode::G_M_xmm
}),
0x2B => (Opcode::VPACKUSDW, VEXOperandCode::G_V_E_xyLmm),
- 0x2C => (Opcode::VMASKMOVPS, if L {
- VEXOperandCode::G_V_M_ymm
+ 0x2C => if instruction.prefixes.vex_unchecked().w() {
+ return Err(DecodeError::InvalidOpcode);
} else {
- VEXOperandCode::G_V_M_xmm
- }),
- 0x2D => (Opcode::VMASKMOVPD, if L {
- VEXOperandCode::G_V_M_ymm
+ (Opcode::VMASKMOVPS, if L {
+ VEXOperandCode::G_V_M_ymm
+ } else {
+ VEXOperandCode::G_V_M_xmm
+ })
+ },
+ 0x2D => if instruction.prefixes.vex_unchecked().w() {
+ return Err(DecodeError::InvalidOpcode);
} else {
- VEXOperandCode::G_V_M_xmm
- }),
- 0x2E => (Opcode::VMASKMOVPS, if L {
- VEXOperandCode::M_V_G_ymm
+ (Opcode::VMASKMOVPD, if L {
+ VEXOperandCode::G_V_M_ymm
+ } else {
+ VEXOperandCode::G_V_M_xmm
+ })
+ },
+ 0x2E => if instruction.prefixes.vex_unchecked().w() {
+ return Err(DecodeError::InvalidOpcode);
} else {
- VEXOperandCode::M_V_G_xmm
- }),
- 0x2F => (Opcode::VMASKMOVPD, if L {
- VEXOperandCode::M_V_G_ymm
+ (Opcode::VMASKMOVPS, if L {
+ VEXOperandCode::M_V_G_ymm
+ } else {
+ VEXOperandCode::M_V_G_xmm
+ })
+ },
+ 0x2F => if instruction.prefixes.vex_unchecked().w() {
+ return Err(DecodeError::InvalidOpcode);
} else {
- VEXOperandCode::M_V_G_xmm
- }),
+ (Opcode::VMASKMOVPD, if L {
+ VEXOperandCode::M_V_G_ymm
+ } else {
+ VEXOperandCode::M_V_G_xmm
+ })
+ },
0x30 => (Opcode::VPMOVZXBW, if L {
VEXOperandCode::G_ymm_E_xmm
} else {
@@ -2217,11 +2241,15 @@ fn read_vex_instruction<
} else {
VEXOperandCode::G_E_xmm
}),
- 0x36 => (Opcode::VPERMD, if L {
- VEXOperandCode::G_V_E_ymm
- } else {
+ 0x36 => if instruction.prefixes.vex_unchecked().w() {
return Err(DecodeError::InvalidOpcode);
- }),
+ } else {
+ (Opcode::VPERMD, if L {
+ VEXOperandCode::G_V_E_ymm
+ } else {
+ return Err(DecodeError::InvalidOpcode);
+ })
+ },
0x37 => (Opcode::VPCMPGTQ, VEXOperandCode::G_V_E_xyLmm),
0x38 => (Opcode::VPMINSB, VEXOperandCode::G_V_E_xyLmm),
0x39 => (Opcode::VPMINSD, VEXOperandCode::G_V_E_xyLmm),
@@ -2258,8 +2286,16 @@ fn read_vex_instruction<
} else {
(Opcode::VPSLLVD, VEXOperandCode::G_V_E_xyLmm)
},
- 0x58 => (Opcode::VPBROADCASTD, VEXOperandCode::G_E_xyLmm),
- 0x59 => (Opcode::VPBROADCASTQ, VEXOperandCode::G_E_xyLmm),
+ 0x58 => if instruction.prefixes.vex_unchecked().w() {
+ return Err(DecodeError::InvalidOpcode);
+ } else {
+ (Opcode::VPBROADCASTD, VEXOperandCode::G_E_xyLmm)
+ },
+ 0x59 => if instruction.prefixes.vex_unchecked().w() {
+ return Err(DecodeError::InvalidOpcode);
+ } else {
+ (Opcode::VPBROADCASTQ, VEXOperandCode::G_E_xyLmm)
+ },
0x5A => (Opcode::VBROADCASTI128, if L {
if instruction.prefixes.vex_unchecked().w() {
return Err(DecodeError::InvalidOpcode);
@@ -2268,16 +2304,16 @@ fn read_vex_instruction<
} else {
return Err(DecodeError::InvalidOpcode);
}),
- 0x78 => (Opcode::VPBROADCASTB, if L {
- VEXOperandCode::G_E_ymm
+ 0x78 => if instruction.prefixes.vex_unchecked().w() {
+ return Err(DecodeError::InvalidOpcode);
} else {
- VEXOperandCode::G_E_ymm
- }),
- 0x79 => (Opcode::VPBROADCASTW, if L {
- VEXOperandCode::G_E_ymm
+ (Opcode::VPBROADCASTB, VEXOperandCode::G_E_xyLmm)
+ },
+ 0x79 => if instruction.prefixes.vex_unchecked().w() {
+ return Err(DecodeError::InvalidOpcode);
} else {
- VEXOperandCode::G_E_ymm
- }),
+ (Opcode::VPBROADCASTW, VEXOperandCode::G_E_xyLmm)
+ },
0x8C => {
if instruction.prefixes.vex_unchecked().w() {
(Opcode::VPMASKMOVQ, if L {
diff --git a/test/long_mode/mod.rs b/test/long_mode/mod.rs
index 2d866de..9ad0df4 100644
--- a/test/long_mode/mod.rs
+++ b/test/long_mode/mod.rs
@@ -1588,6 +1588,12 @@ fn test_vex() {
test_invalid_under(&InstDecoder::minimal(), bytes);
}
+ fn test_instr_vex_f16c(bytes: &[u8], text: &'static str) {
+ test_display_under(&InstDecoder::minimal().with_avx().with_f16c(), bytes, text);
+ test_display_under(&InstDecoder::default(), bytes, text);
+ test_invalid_under(&InstDecoder::minimal(), bytes);
+ }
+
fn test_instr_invalid(bytes: &[u8]) {
test_invalid_under(&InstDecoder::minimal().with_avx(), bytes);
test_invalid_under(&InstDecoder::default(), bytes);
@@ -1761,6 +1767,8 @@ fn test_vex() {
test_instr(&[0xc4, 0b000_00010, 0b0_1111_001, 0x0f, 0b11_001_010], "vtestpd xmm9, xmm10");
test_instr(&[0xc4, 0b000_00010, 0b0_1111_101, 0x0f, 0b11_001_010], "vtestpd ymm9, ymm10");
test_invalid(&[0xc4, 0b000_00010, 0b1_1111_101, 0x0f, 0b11_001_010]);
+ test_instr_vex_f16c(&[0xc4, 0b111_00010, 0b0_1111_001, 0x13, 0b11_001_010], "vcvtph2ps xmm1, xmm2");
+ test_invalid(&[0xc4, 0b111_00010, 0b1_1111_001, 0x13, 0b11_001_010]);
test_instr(&[0xc4, 0b000_00010, 0b0_1111_101, 0x16, 0b11_001_010], "vpermps ymm9, ymm0, ymm10");
test_instr(&[0xc4, 0b000_00010, 0b0_1111_101, 0x16, 0b00_001_010], "vpermps ymm9, ymm0, ymmword [r10]");
@@ -1780,6 +1788,7 @@ fn test_vex() {
test_invalid(&[0xc4, 0b000_00010, 0b0_0111_101, 0x19, 0b00_001_010]);
test_invalid(&[0xc4, 0b000_00010, 0b1_0111_101, 0x19, 0b00_001_010]);
test_instr(&[0xc4, 0b000_00010, 0b0_1111_101, 0x1a, 0b00_001_010], "vbroadcastf128 ymm9, xmmword [r10]");
+ test_invalid(&[0xc4, 0b000_00010, 0b1_1111_101, 0x1a, 0b00_001_010]); // vex.w=1 is invalid
test_invalid(&[0xc4, 0b000_00010, 0b1_0111_101, 0x1a, 0b00_001_010]);
test_invalid(&[0xc4, 0b000_00010, 0b1_0111_001, 0x1a, 0b00_001_010]);
test_instr(&[0xc4, 0b000_00010, 0b0_1111_101, 0x5a, 0b00_001_010], "vbroadcasti128 ymm9, xmmword [r10]");
@@ -1791,6 +1800,7 @@ fn test_vex() {
test_instr(&[0xc4, 0b000_00010, 0b0_1111_101, 0x18, 0b00_001_010], "vbroadcastss ymm9, dword [r10]");
test_invalid(&[0xc4, 0b000_00010, 0b1_0111_001, 0x18, 0b11_001_010]);
test_invalid(&[0xc4, 0b000_00010, 0b1_0111_101, 0x18, 0b11_001_010]);
+ test_invalid(&[0xc4, 0b111_00010, 0b0_1111_001, 0x19, 0b11_001_010]); // "vbroadcastsd xmm, xmm" is not legal (L!=0)
test_avx2(&[0xc4, 0b000_00010, 0b0_1111_101, 0x19, 0b11_001_010], "vbroadcastsd ymm9, xmm10");
test_instr(&[0xc4, 0b000_00010, 0b0_1111_101, 0x19, 0b00_001_010], "vbroadcastsd ymm9, qword [r10]");
test_invalid(&[0xc4, 0b000_00010, 0b1_1111_101, 0x19, 0b11_001_010]);
@@ -1842,6 +1852,19 @@ fn test_vex() {
test_avx2(&[0xc4, 0b000_00010, 0b0_0111_101, 0x2b, 0b11_001_010], "vpackusdw ymm9, ymm8, ymm10");
test_avx2(&[0xc4, 0b000_00010, 0b0_0111_101, 0x2b, 0b00_001_010], "vpackusdw ymm9, ymm8, ymmword [r10]");
+ test_instr(&[0xc4, 0b000_00010, 0b0_0111_001, 0x2c, 0b00_001_010], "vmaskmovps xmm9, xmm8, xmmword [r10]");
+ test_invalid(&[0xc4, 0b000_00010, 0b0_0111_101, 0x2c, 0b11_001_010]);
+ test_avx2(&[0xc4, 0b000_00010, 0b0_0111_101, 0x2c, 0b00_001_010], "vmaskmovps ymm9, ymm8, ymmword [r10]");
+ test_instr(&[0xc4, 0b000_00010, 0b0_0111_001, 0x2d, 0b00_001_010], "vmaskmovpd xmm9, xmm8, xmmword [r10]");
+ test_invalid(&[0xc4, 0b000_00010, 0b0_0111_101, 0x2d, 0b11_001_010]);
+ test_avx2(&[0xc4, 0b000_00010, 0b0_0111_101, 0x2d, 0b00_001_010], "vmaskmovpd ymm9, ymm8, ymmword [r10]");
+ test_instr(&[0xc4, 0b000_00010, 0b0_0111_001, 0x2e, 0b00_001_010], "vmaskmovps xmmword [r10], xmm8, xmm9");
+ test_invalid(&[0xc4, 0b000_00010, 0b0_0111_101, 0x2e, 0b11_001_010]);
+ test_avx2(&[0xc4, 0b000_00010, 0b0_0111_101, 0x2e, 0b00_001_010], "vmaskmovps ymmword [r10], ymm8, ymm9");
+ test_instr(&[0xc4, 0b000_00010, 0b0_0111_001, 0x2f, 0b00_001_010], "vmaskmovpd xmmword [r10], xmm8, xmm9");
+ test_invalid(&[0xc4, 0b000_00010, 0b0_0111_101, 0x2f, 0b11_001_010]);
+ test_avx2(&[0xc4, 0b000_00010, 0b0_0111_101, 0x2f, 0b00_001_010], "vmaskmovpd ymmword [r10], ymm8, ymm9");
+
test_instr(&[0xc4, 0b000_00010, 0b0_1111_001, 0x30, 0b11_001_010], "vpmovzxbw xmm9, xmm10");
test_instr(&[0xc4, 0b000_00010, 0b0_1111_101, 0x30, 0b11_001_010], "vpmovzxbw ymm9, xmm10");
test_instr(&[0xc4, 0b000_00010, 0b0_1111_001, 0x31, 0b11_001_010], "vpmovzxbd xmm9, xmm10");
@@ -1870,6 +1893,7 @@ fn test_vex() {
test_invalid(&[0xc4, 0b000_00010, 0b0_0111_001, 0x36, 0b11_001_010]);
test_avx2(&[0xc4, 0b000_00010, 0b0_0111_101, 0x36, 0b11_001_010], "vpermd ymm9, ymm8, ymm10");
+ test_invalid(&[0xc4, 0b000_00010, 0b1_1111_101, 0x36, 0b11_001_010]);
test_instr(&[0xc4, 0b000_00010, 0b0_0111_001, 0x37, 0b11_001_010], "vpcmpgtq xmm9, xmm8, xmm10");
test_avx2(&[0xc4, 0b000_00010, 0b0_0111_101, 0x37, 0b11_001_010], "vpcmpgtq ymm9, ymm8, ymm10");
test_instr(&[0xc4, 0b000_00010, 0b0_0111_001, 0x38, 0b11_001_010], "vpminsb xmm9, xmm8, xmm10");
@@ -1921,6 +1945,20 @@ fn test_vex() {
test_avx2(&[0xc4, 0b000_00010, 0b1_1111_001, 0x47, 0b11_001_010], "vpsllvq xmm9, xmm0, xmm10");
test_avx2(&[0xc4, 0b000_00010, 0b1_1111_101, 0x47, 0b11_001_010], "vpsllvq ymm9, ymm0, ymm10");
+ test_avx2(&[0xc4, 0b111_00010, 0b0_1111_001, 0x58, 0b11_000_001], "vpbroadcastd xmm0, xmm1");
+ test_avx2(&[0xc4, 0b111_00010, 0b0_1111_101, 0x58, 0b11_000_001], "vpbroadcastd ymm0, ymm1");
+ test_invalid(&[0xc4, 0b111_00010, 0b1_1111_001, 0x58, 0b11_000_001]);
+ test_avx2(&[0xc4, 0b111_00010, 0b0_1111_001, 0x59, 0b11_000_001], "vpbroadcastq xmm0, xmm1");
+ test_avx2(&[0xc4, 0b111_00010, 0b0_1111_101, 0x59, 0b11_000_001], "vpbroadcastq ymm0, ymm1");
+ test_invalid(&[0xc4, 0b111_00010, 0b1_1111_001, 0x59, 0b11_000_001]);
+
+ test_avx2(&[0xc4, 0b111_00010, 0b0_1111_001, 0x78, 0b11_000_001], "vpbroadcastb xmm0, xmm1");
+ test_avx2(&[0xc4, 0b111_00010, 0b0_1111_101, 0x78, 0b11_000_001], "vpbroadcastb ymm0, ymm1");
+ test_invalid(&[0xc4, 0b111_00010, 0b1_1111_001, 0x78, 0b11_000_001]);
+ test_avx2(&[0xc4, 0b111_00010, 0b0_1111_001, 0x79, 0b11_000_001], "vpbroadcastw xmm0, xmm1");
+ test_avx2(&[0xc4, 0b111_00010, 0b0_1111_101, 0x79, 0b11_000_001], "vpbroadcastw ymm0, ymm1");
+ test_invalid(&[0xc4, 0b111_00010, 0b1_1111_001, 0x79, 0b11_000_001]);
+
test_avx2(&[0xc4, 0b000_00010, 0b0_1111_001, 0x8c, 0b00_001_010], "vpmaskmovd xmm9, xmm0, xmmword [r10]");
test_avx2(&[0xc4, 0b000_00010, 0b0_1111_101, 0x8c, 0b00_001_010], "vpmaskmovd ymm9, ymm0, ymmword [r10]");
test_invalid(&[0xc4, 0b000_00010, 0b0_1111_001, 0x8c, 0b11_001_010]);