Skip to contentSkip to conversation

x86/insn: perf tools: Add AVX-512 support to the instruction decoder

PATCH Superseded Adrian Hunter 2 participants 7 messages Jul 19, 2016 – Jul 20, 2016

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Adrian Hunter

author reviewer
#0 lore raw

cover x86/insn: perf tools: Add AVX-512 support to the instruction decoder

Hi

Here is a patch to add support for Intel's AVX-512 instructions to the instruction decoder. Also there is a patch to fix vcvtph2ps.

AVX-512 instructions are documented in Intel Architecture Instruction Set Extensions Programming Reference (February 2016).

These patches do not conflict with Dan's removal of pcommit.

Adrian Hunter (2):
x86/insn: perf tools: Fix vcvtph2ps instruction decoding x86/insn: perf tools: Add AVX-512 support to the instruction decoder

 arch/x86/include/asm/inat.h                        |   17 +-
 arch/x86/include/asm/insn.h                        |   12 +-
 arch/x86/lib/insn.c                                |   18 +-
 arch/x86/lib/x86-opcode-map.txt                    |  263 ++-
 arch/x86/tools/gen-insn-attr-x86.awk               |   11 +-
 tools/perf/arch/x86/tests/insn-x86-dat-32.c        | 1018 ++++++++++-
 tools/perf/arch/x86/tests/insn-x86-dat-64.c        |  940 +++++++++-
 tools/perf/arch/x86/tests/insn-x86-dat-src.c       | 1789 ++++++++++++++++++++
 .../util/intel-pt-decoder/gen-insn-attr-x86.awk    |   11 +-
 tools/perf/util/intel-pt-decoder/inat.h            |   17 +-
 tools/perf/util/intel-pt-decoder/insn.c            |   18 +-
 tools/perf/util/intel-pt-decoder/insn.h            |   12 +-
 .../perf/util/intel-pt-decoder/x86-opcode-map.txt  |  263 ++-
 13 files changed, 4179 insertions(+), 210 deletions(-)

Regards
Adrian

author reviewer
#1 lore raw

PATCH 1/2 x86/insn: perf tools: Fix vcvtph2ps instruction decoding

vcvtph2ps does not have an immediate operand, so remove the erroneous 'Ib' from its opcode map entry. Add vcvtph2ps to the perf tools new instructions test to verify it.

---
 arch/x86/lib/x86-opcode-map.txt                     |  2 +-
 tools/perf/arch/x86/tests/insn-x86-dat-32.c         | 10 ++++++----
 tools/perf/arch/x86/tests/insn-x86-dat-64.c         | 10 ++++++----
 tools/perf/arch/x86/tests/insn-x86-dat-src.c        |  4 ++++
 tools/perf/util/intel-pt-decoder/x86-opcode-map.txt |  2 +-
 5 files changed, 18 insertions(+), 10 deletions(-)
arch/x86/lib/x86-opcode-map.txt +1 -1
index d388de72eaca..28082de46f0d 100644
@@ -629,7 +629,7 @@ AVXcode: 2
 10: pblendvb Vdq,Wdq (66)
 11:
 12:
-13: vcvtph2ps Vx,Wx,Ib (66),(v)
+13: vcvtph2ps Vx,Wx (66),(v)
 14: blendvps Vdq,Wdq (66)
 15: blendvpd Vdq,Wdq (66)
 16: vpermps Vqq,Hqq,Wqq (66),(v)
tools/perf/arch/x86/tests/insn-x86-dat-32.c +6 -4
index 3b491cfe204e..ca08e6eb988f 100644
@@ -6,6 +6,8 @@
 
 {{0x0f, 0x31, }, 2, 0, "", "",
 "0f 31                \trdtsc  ",},
+{{0xc4, 0xe2, 0x7d, 0x13, 0xeb, }, 5, 0, "", "",
+"c4 e2 7d 13 eb       \tvcvtph2ps %xmm3,%ymm5",},
 {{0xf3, 0x0f, 0x1b, 0x00, }, 4, 0, "", "",
 "f3 0f 1b 00          \tbndmk  (%eax),%bnd0",},
 {{0xf3, 0x0f, 0x1b, 0x05, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
@@ -309,19 +311,19 @@
 {{0x0f, 0x1b, 0x84, 0x08, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
 "0f 1b 84 08 78 56 34 12 \tbndstx %bnd0,0x12345678(%eax,%ecx,1)",},
 {{0xf2, 0xe8, 0xfc, 0xff, 0xff, 0xff, }, 6, 0xfffffffc, "call", "unconditional",
-"f2 e8 fc ff ff ff    \tbnd call 3c3 <main+0x3c3>",},
+"f2 e8 fc ff ff ff    \tbnd call 3c8 <main+0x3c8>",},
 {{0xf2, 0xff, 0x10, }, 3, 0, "call", "indirect",
 "f2 ff 10             \tbnd call *(%eax)",},
 {{0xf2, 0xc3, }, 2, 0, "ret", "indirect",
 "f2 c3                \tbnd ret ",},
 {{0xf2, 0xe9, 0xfc, 0xff, 0xff, 0xff, }, 6, 0xfffffffc, "jmp", "unconditional",
-"f2 e9 fc ff ff ff    \tbnd jmp 3ce <main+0x3ce>",},
+"f2 e9 fc ff ff ff    \tbnd jmp 3d3 <main+0x3d3>",},
 {{0xf2, 0xe9, 0xfc, 0xff, 0xff, 0xff, }, 6, 0xfffffffc, "jmp", "unconditional",
-"f2 e9 fc ff ff ff    \tbnd jmp 3d4 <main+0x3d4>",},
+"f2 e9 fc ff ff ff    \tbnd jmp 3d9 <main+0x3d9>",},
 {{0xf2, 0xff, 0x21, }, 3, 0, "jmp", "indirect",
 "f2 ff 21             \tbnd jmp *(%ecx)",},
 {{0xf2, 0x0f, 0x85, 0xfc, 0xff, 0xff, 0xff, }, 7, 0xfffffffc, "jcc", "conditional",
-"f2 0f 85 fc ff ff ff \tbnd jne 3de <main+0x3de>",},
+"f2 0f 85 fc ff ff ff \tbnd jne 3e3 <main+0x3e3>",},
 {{0x0f, 0x3a, 0xcc, 0xc1, 0x00, }, 5, 0, "", "",
 "0f 3a cc c1 00       \tsha1rnds4 $0x0,%xmm1,%xmm0",},
 {{0x0f, 0x3a, 0xcc, 0xd7, 0x91, }, 5, 0, "", "",
tools/perf/arch/x86/tests/insn-x86-dat-64.c +6 -4
index 4fe7cce179c4..262d9d25a6fa 100644
@@ -6,6 +6,8 @@
 
 {{0x0f, 0x31, }, 2, 0, "", "",
 "0f 31                \trdtsc  ",},
+{{0xc4, 0xe2, 0x7d, 0x13, 0xeb, }, 5, 0, "", "",
+"c4 e2 7d 13 eb       \tvcvtph2ps %xmm3,%ymm5",},
 {{0xf3, 0x0f, 0x1b, 0x00, }, 4, 0, "", "",
 "f3 0f 1b 00          \tbndmk  (%rax),%bnd0",},
 {{0xf3, 0x41, 0x0f, 0x1b, 0x00, }, 5, 0, "", "",
@@ -325,19 +327,19 @@
 {{0x0f, 0x1b, 0x84, 0x08, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
 "0f 1b 84 08 78 56 34 12 \tbndstx %bnd0,0x12345678(%rax,%rcx,1)",},
 {{0xf2, 0xe8, 0x00, 0x00, 0x00, 0x00, }, 6, 0, "call", "unconditional",
-"f2 e8 00 00 00 00    \tbnd callq 3f6 <main+0x3f6>",},
+"f2 e8 00 00 00 00    \tbnd callq 3fb <main+0x3fb>",},
 {{0x67, 0xf2, 0xff, 0x10, }, 4, 0, "call", "indirect",
 "67 f2 ff 10          \tbnd callq *(%eax)",},
 {{0xf2, 0xc3, }, 2, 0, "ret", "indirect",
 "f2 c3                \tbnd retq ",},
 {{0xf2, 0xe9, 0x00, 0x00, 0x00, 0x00, }, 6, 0, "jmp", "unconditional",
-"f2 e9 00 00 00 00    \tbnd jmpq 402 <main+0x402>",},
+"f2 e9 00 00 00 00    \tbnd jmpq 407 <main+0x407>",},
 {{0xf2, 0xe9, 0x00, 0x00, 0x00, 0x00, }, 6, 0, "jmp", "unconditional",
-"f2 e9 00 00 00 00    \tbnd jmpq 408 <main+0x408>",},
+"f2 e9 00 00 00 00    \tbnd jmpq 40d <main+0x40d>",},
 {{0x67, 0xf2, 0xff, 0x21, }, 4, 0, "jmp", "indirect",
 "67 f2 ff 21          \tbnd jmpq *(%ecx)",},
 {{0xf2, 0x0f, 0x85, 0x00, 0x00, 0x00, 0x00, }, 7, 0, "jcc", "conditional",
-"f2 0f 85 00 00 00 00 \tbnd jne 413 <main+0x413>",},
+"f2 0f 85 00 00 00 00 \tbnd jne 418 <main+0x418>",},
 {{0x0f, 0x3a, 0xcc, 0xc1, 0x00, }, 5, 0, "", "",
 "0f 3a cc c1 00       \tsha1rnds4 $0x0,%xmm1,%xmm0",},
 {{0x0f, 0x3a, 0xcc, 0xd7, 0x91, }, 5, 0, "", "",
tools/perf/arch/x86/tests/insn-x86-dat-src.c +4 -0
index 41b1b1c62660..3cd677513e9e 100644
@@ -19,6 +19,10 @@ int main(void)
 	/* Following line is a marker for the awk script - do not change */
 	asm volatile("rdtsc"); /* Start here */
 
+	/* Test fix for vcvtph2ps in x86-opcode-map.txt */
+
+	asm volatile("vcvtph2ps %xmm3,%ymm5");
+
 #ifdef __x86_64__
 
 	/* bndmk m64, bnd */
tools/perf/util/intel-pt-decoder/x86-opcode-map.txt +1 -1
index d388de72eaca..28082de46f0d 100644
@@ -629,7 +629,7 @@ AVXcode: 2
 10: pblendvb Vdq,Wdq (66)
 11:
 12:
-13: vcvtph2ps Vx,Wx,Ib (66),(v)
+13: vcvtph2ps Vx,Wx (66),(v)
 14: blendvps Vdq,Wdq (66)
 15: blendvpd Vdq,Wdq (66)
 16: vpermps Vqq,Hqq,Wqq (66),(v)
Signature · 1 line
1.9.1
Acked-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] x86/insn: perf tools: Fix vcvtph2ps instruction decoding

Quoted 3 lines · On Tue, 19 Jul 2016 15:46:47 +0300 Adrian Hunter <[email protected]>…

vcvtph2ps does not have an immediate operand, so remove the erroneous 'Ib' from its opcode map entry. Add vcvtph2ps to the perf tools new instructions test to verify it.

Hmm, Intel SDM Vol.2D Table A-4 shows vcvtph2ps has Ib (Vol.2C Figure 5-6. also has same mistake in title), but yes, instruction set reference of VCVTPH2PS shows that has no immediate. So, I guess OPCODE MAP should be fixed.

Looks good to me:)

Thank you!

Quoted 128 lines
---
 arch/x86/lib/x86-opcode-map.txt                     |  2 +-
 tools/perf/arch/x86/tests/insn-x86-dat-32.c         | 10 ++++++----
 tools/perf/arch/x86/tests/insn-x86-dat-64.c         | 10 ++++++----
 tools/perf/arch/x86/tests/insn-x86-dat-src.c        |  4 ++++
 tools/perf/util/intel-pt-decoder/x86-opcode-map.txt |  2 +-
 5 files changed, 18 insertions(+), 10 deletions(-)
arch/x86/lib/x86-opcode-map.txt +1 -1
index d388de72eaca..28082de46f0d 100644
@@ -629,7 +629,7 @@ AVXcode: 2
 10: pblendvb Vdq,Wdq (66)
 11:
 12:
-13: vcvtph2ps Vx,Wx,Ib (66),(v)
+13: vcvtph2ps Vx,Wx (66),(v)
 14: blendvps Vdq,Wdq (66)
 15: blendvpd Vdq,Wdq (66)
 16: vpermps Vqq,Hqq,Wqq (66),(v)
tools/perf/arch/x86/tests/insn-x86-dat-32.c +6 -4
index 3b491cfe204e..ca08e6eb988f 100644
@@ -6,6 +6,8 @@
 
 {{0x0f, 0x31, }, 2, 0, "", "",
 "0f 31                \trdtsc  ",},
+{{0xc4, 0xe2, 0x7d, 0x13, 0xeb, }, 5, 0, "", "",
+"c4 e2 7d 13 eb       \tvcvtph2ps %xmm3,%ymm5",},
 {{0xf3, 0x0f, 0x1b, 0x00, }, 4, 0, "", "",
 "f3 0f 1b 00          \tbndmk  (%eax),%bnd0",},
 {{0xf3, 0x0f, 0x1b, 0x05, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
@@ -309,19 +311,19 @@
 {{0x0f, 0x1b, 0x84, 0x08, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
 "0f 1b 84 08 78 56 34 12 \tbndstx %bnd0,0x12345678(%eax,%ecx,1)",},
 {{0xf2, 0xe8, 0xfc, 0xff, 0xff, 0xff, }, 6, 0xfffffffc, "call", "unconditional",
-"f2 e8 fc ff ff ff    \tbnd call 3c3 <main+0x3c3>",},
+"f2 e8 fc ff ff ff    \tbnd call 3c8 <main+0x3c8>",},
 {{0xf2, 0xff, 0x10, }, 3, 0, "call", "indirect",
 "f2 ff 10             \tbnd call *(%eax)",},
 {{0xf2, 0xc3, }, 2, 0, "ret", "indirect",
 "f2 c3                \tbnd ret ",},
 {{0xf2, 0xe9, 0xfc, 0xff, 0xff, 0xff, }, 6, 0xfffffffc, "jmp", "unconditional",
-"f2 e9 fc ff ff ff    \tbnd jmp 3ce <main+0x3ce>",},
+"f2 e9 fc ff ff ff    \tbnd jmp 3d3 <main+0x3d3>",},
 {{0xf2, 0xe9, 0xfc, 0xff, 0xff, 0xff, }, 6, 0xfffffffc, "jmp", "unconditional",
-"f2 e9 fc ff ff ff    \tbnd jmp 3d4 <main+0x3d4>",},
+"f2 e9 fc ff ff ff    \tbnd jmp 3d9 <main+0x3d9>",},
 {{0xf2, 0xff, 0x21, }, 3, 0, "jmp", "indirect",
 "f2 ff 21             \tbnd jmp *(%ecx)",},
 {{0xf2, 0x0f, 0x85, 0xfc, 0xff, 0xff, 0xff, }, 7, 0xfffffffc, "jcc", "conditional",
-"f2 0f 85 fc ff ff ff \tbnd jne 3de <main+0x3de>",},
+"f2 0f 85 fc ff ff ff \tbnd jne 3e3 <main+0x3e3>",},
 {{0x0f, 0x3a, 0xcc, 0xc1, 0x00, }, 5, 0, "", "",
 "0f 3a cc c1 00       \tsha1rnds4 $0x0,%xmm1,%xmm0",},
 {{0x0f, 0x3a, 0xcc, 0xd7, 0x91, }, 5, 0, "", "",
tools/perf/arch/x86/tests/insn-x86-dat-64.c +6 -4
index 4fe7cce179c4..262d9d25a6fa 100644
@@ -6,6 +6,8 @@
 
 {{0x0f, 0x31, }, 2, 0, "", "",
 "0f 31                \trdtsc  ",},
+{{0xc4, 0xe2, 0x7d, 0x13, 0xeb, }, 5, 0, "", "",
+"c4 e2 7d 13 eb       \tvcvtph2ps %xmm3,%ymm5",},
 {{0xf3, 0x0f, 0x1b, 0x00, }, 4, 0, "", "",
 "f3 0f 1b 00          \tbndmk  (%rax),%bnd0",},
 {{0xf3, 0x41, 0x0f, 0x1b, 0x00, }, 5, 0, "", "",
@@ -325,19 +327,19 @@
 {{0x0f, 0x1b, 0x84, 0x08, 0x78, 0x56, 0x34, 0x12, }, 8, 0, "", "",
 "0f 1b 84 08 78 56 34 12 \tbndstx %bnd0,0x12345678(%rax,%rcx,1)",},
 {{0xf2, 0xe8, 0x00, 0x00, 0x00, 0x00, }, 6, 0, "call", "unconditional",
-"f2 e8 00 00 00 00    \tbnd callq 3f6 <main+0x3f6>",},
+"f2 e8 00 00 00 00    \tbnd callq 3fb <main+0x3fb>",},
 {{0x67, 0xf2, 0xff, 0x10, }, 4, 0, "call", "indirect",
 "67 f2 ff 10          \tbnd callq *(%eax)",},
 {{0xf2, 0xc3, }, 2, 0, "ret", "indirect",
 "f2 c3                \tbnd retq ",},
 {{0xf2, 0xe9, 0x00, 0x00, 0x00, 0x00, }, 6, 0, "jmp", "unconditional",
-"f2 e9 00 00 00 00    \tbnd jmpq 402 <main+0x402>",},
+"f2 e9 00 00 00 00    \tbnd jmpq 407 <main+0x407>",},
 {{0xf2, 0xe9, 0x00, 0x00, 0x00, 0x00, }, 6, 0, "jmp", "unconditional",
-"f2 e9 00 00 00 00    \tbnd jmpq 408 <main+0x408>",},
+"f2 e9 00 00 00 00    \tbnd jmpq 40d <main+0x40d>",},
 {{0x67, 0xf2, 0xff, 0x21, }, 4, 0, "jmp", "indirect",
 "67 f2 ff 21          \tbnd jmpq *(%ecx)",},
 {{0xf2, 0x0f, 0x85, 0x00, 0x00, 0x00, 0x00, }, 7, 0, "jcc", "conditional",
-"f2 0f 85 00 00 00 00 \tbnd jne 413 <main+0x413>",},
+"f2 0f 85 00 00 00 00 \tbnd jne 418 <main+0x418>",},
 {{0x0f, 0x3a, 0xcc, 0xc1, 0x00, }, 5, 0, "", "",
 "0f 3a cc c1 00       \tsha1rnds4 $0x0,%xmm1,%xmm0",},
 {{0x0f, 0x3a, 0xcc, 0xd7, 0x91, }, 5, 0, "", "",
tools/perf/arch/x86/tests/insn-x86-dat-src.c +4 -0
index 41b1b1c62660..3cd677513e9e 100644
@@ -19,6 +19,10 @@ int main(void)
 	/* Following line is a marker for the awk script - do not change */
 	asm volatile("rdtsc"); /* Start here */
 
+	/* Test fix for vcvtph2ps in x86-opcode-map.txt */
+
+	asm volatile("vcvtph2ps %xmm3,%ymm5");
+
 #ifdef __x86_64__
 
 	/* bndmk m64, bnd */
tools/perf/util/intel-pt-decoder/x86-opcode-map.txt +1 -1
index d388de72eaca..28082de46f0d 100644
@@ -629,7 +629,7 @@ AVXcode: 2
 10: pblendvb Vdq,Wdq (66)
 11:
 12:
-13: vcvtph2ps Vx,Wx,Ib (66),(v)
+13: vcvtph2ps Vx,Wx (66),(v)
 14: blendvps Vdq,Wdq (66)
 15: blendvpd Vdq,Wdq (66)
 16: vpermps Vqq,Hqq,Wqq (66),(v)
Signature · 1 line
1.9.1
Signature · 1 line
Masami Hiramatsu <[email protected]>
author reviewer
#3 lore raw

PATCH 2/2 x86/insn: perf tools: Add AVX-512 support to the instruction decoder

In reply to Adrian Hunter

Add support for Intel's AVX-512 instructions to the instruction decoder.

AVX-512 instructions are documented in Intel Architecture Instruction Set Extensions Programming Reference (February 2016).

AVX-512 instructions are identifed by a EVEX prefix which, for the purpose of instruction decoding, can be treated as though it were a 4-byte VEX prefix.

Existing instructions which can now accept an EVEX prefix need not be further annotated in the op code map (x86-opcode-map.txt). In the case of new instructions, the op code map is updated accordingly.

Also add associated Mask Instructions that are used to manipulate mask registers used in AVX-512 instructions.

Add a representative set of instructions to the perf tools new instructons test.

---
 arch/x86/include/asm/inat.h                        |   17 +-
 arch/x86/include/asm/insn.h                        |   12 +-
 arch/x86/lib/insn.c                                |   18 +-
 arch/x86/lib/x86-opcode-map.txt                    |  263 ++-
 arch/x86/tools/gen-insn-attr-x86.awk               |   11 +-
 tools/perf/arch/x86/tests/insn-x86-dat-32.c        | 1016 ++++++++++-
 tools/perf/arch/x86/tests/insn-x86-dat-64.c        |  938 +++++++++-
 tools/perf/arch/x86/tests/insn-x86-dat-src.c       | 1785 ++++++++++++++++++++
 .../util/intel-pt-decoder/gen-insn-attr-x86.awk    |   11 +-
 tools/perf/util/intel-pt-decoder/inat.h            |   17 +-
 tools/perf/util/intel-pt-decoder/insn.c            |   18 +-
 tools/perf/util/intel-pt-decoder/insn.h            |   12 +-
 .../perf/util/intel-pt-decoder/x86-opcode-map.txt  |  263 ++-
 13 files changed, 4171 insertions(+), 210 deletions(-)
arch/x86/include/asm/inat.h +15 -2
index 74a2e312e8a2..02aff0867211 100644
@@ -48,6 +48,7 @@
 /* AVX VEX prefixes */
 #define INAT_PFX_VEX2	13	/* 2-bytes VEX prefix */
 #define INAT_PFX_VEX3	14	/* 3-bytes VEX prefix */
+#define INAT_PFX_EVEX	15	/* EVEX prefix */
 
 #define INAT_LSTPFX_MAX	3
 #define INAT_LGCPFX_MAX	11
@@ -89,6 +90,7 @@
 #define INAT_VARIANT	(1 << (INAT_FLAG_OFFS + 4))
 #define INAT_VEXOK	(1 << (INAT_FLAG_OFFS + 5))
 #define INAT_VEXONLY	(1 << (INAT_FLAG_OFFS + 6))
+#define INAT_EVEXONLY	(1 << (INAT_FLAG_OFFS + 7))
 /* Attribute making macros for attribute tables */
 #define INAT_MAKE_PREFIX(pfx)	(pfx << INAT_PFX_OFFS)
 #define INAT_MAKE_ESCAPE(esc)	(esc << INAT_ESC_OFFS)
@@ -141,7 +143,13 @@ static inline int inat_last_prefix_id(insn_attr_t attr)
 static inline int inat_is_vex_prefix(insn_attr_t attr)
 {
 	attr &= INAT_PFX_MASK;
-	return attr == INAT_PFX_VEX2 || attr == INAT_PFX_VEX3;
+	return attr == INAT_PFX_VEX2 || attr == INAT_PFX_VEX3 ||
+	       attr == INAT_PFX_EVEX;
+}
+
+static inline int inat_is_evex_prefix(insn_attr_t attr)
+{
+	return (attr & INAT_PFX_MASK) == INAT_PFX_EVEX;
 }
 
 static inline int inat_is_vex3_prefix(insn_attr_t attr)
@@ -216,6 +224,11 @@ static inline int inat_accept_vex(insn_attr_t attr)
 
 static inline int inat_must_vex(insn_attr_t attr)
 {
-	return attr & INAT_VEXONLY;
+	return attr & (INAT_VEXONLY | INAT_EVEXONLY);
+}
+
+static inline int inat_must_evex(insn_attr_t attr)
+{
+	return attr & INAT_EVEXONLY;
 }
 #endif
arch/x86/include/asm/insn.h +11 -1
index e7814b74caf8..b3e32b010ab1 100644
@@ -91,6 +91,7 @@ struct insn {
 #define X86_VEX_B(vex)	((vex) & 0x20)	/* VEX3 Byte1 */
 #define X86_VEX_L(vex)	((vex) & 0x04)	/* VEX3 Byte2, VEX2 Byte1 */
 /* VEX bit fields */
+#define X86_EVEX_M(vex)	((vex) & 0x03)		/* EVEX Byte1 */
 #define X86_VEX3_M(vex)	((vex) & 0x1f)		/* VEX3 Byte1 */
 #define X86_VEX2_M	1			/* VEX2.M always 1 */
 #define X86_VEX_V(vex)	(((vex) & 0x78) >> 3)	/* VEX3 Byte2, VEX2 Byte1 */
@@ -133,6 +134,13 @@ static inline int insn_is_avx(struct insn *insn)
 	return (insn->vex_prefix.value != 0);
 }
 
+static inline int insn_is_evex(struct insn *insn)
+{
+	if (!insn->prefixes.got)
+		insn_get_prefixes(insn);
+	return (insn->vex_prefix.nbytes == 4);
+}
+
 /* Ensure this instruction is decoded completely */
 static inline int insn_complete(struct insn *insn)
 {
@@ -144,8 +152,10 @@ static inline insn_byte_t insn_vex_m_bits(struct insn *insn)
 {
 	if (insn->vex_prefix.nbytes == 2)	/* 2 bytes VEX */
 		return X86_VEX2_M;
-	else
+	else if (insn->vex_prefix.nbytes == 3)	/* 3 bytes VEX */
 		return X86_VEX3_M(insn->vex_prefix.bytes[1]);
+	else					/* EVEX */
+		return X86_EVEX_M(insn->vex_prefix.bytes[1]);
 }
 
 static inline insn_byte_t insn_vex_p_bits(struct insn *insn)
arch/x86/lib/insn.c +15 -3
index 1a416935bac9..1088eb8f3a5f 100644
@@ -155,14 +155,24 @@ found:
 			/*
 			 * In 32-bits mode, if the [7:6] bits (mod bits of
 			 * ModRM) on the second byte are not 11b, it is
-			 * LDS or LES.
+			 * LDS or LES or BOUND.
 			 */
 			if (X86_MODRM_MOD(b2) != 3)
 				goto vex_end;
 		}
 		insn->vex_prefix.bytes[0] = b;
 		insn->vex_prefix.bytes[1] = b2;
-		if (inat_is_vex3_prefix(attr)) {
+		if (inat_is_evex_prefix(attr)) {
+			b2 = peek_nbyte_next(insn_byte_t, insn, 2);
+			insn->vex_prefix.bytes[2] = b2;
+			b2 = peek_nbyte_next(insn_byte_t, insn, 3);
+			insn->vex_prefix.bytes[3] = b2;
+			insn->vex_prefix.nbytes = 4;
+			insn->next_byte += 4;
+			if (insn->x86_64 && X86_VEX_W(b2))
+				/* VEX.W overrides opnd_size */
+				insn->opnd_bytes = 8;
+		} else if (inat_is_vex3_prefix(attr)) {
 			b2 = peek_nbyte_next(insn_byte_t, insn, 2);
 			insn->vex_prefix.bytes[2] = b2;
 			insn->vex_prefix.nbytes = 3;
@@ -221,7 +231,9 @@ void insn_get_opcode(struct insn *insn)
 		m = insn_vex_m_bits(insn);
 		p = insn_vex_p_bits(insn);
 		insn->attr = inat_get_avx_attribute(op, m, p);
-		if (!inat_accept_vex(insn->attr) && !inat_is_group(insn->attr))
+		if ((inat_must_evex(insn->attr) && !insn_is_evex(insn)) ||
+		    (!inat_accept_vex(insn->attr) &&
+		     !inat_is_group(insn->attr)))
 			insn->attr = 0;	/* This instruction is bad */
 		goto end;	/* VEX has only 1 byte for opcode */
 	}
arch/x86/lib/x86-opcode-map.txt +171 -92

438 lines not on this page · raw message

arch/x86/tools/gen-insn-attr-x86.awk +8 -3
index 093a892026f9..a3d2c62fd805 100644
@@ -72,12 +72,14 @@ BEGIN {
 	lprefix_expr = "\\((66|F2|F3)\\)"
 	max_lprefix = 4
 
-	# All opcodes starting with lower-case 'v' or with (v1) superscript
+	# All opcodes starting with lower-case 'v', 'k' or with (v1) superscript
 	# accepts VEX prefix
-	vexok_opcode_expr = "^v.*"
+	vexok_opcode_expr = "^[vk].*"
 	vexok_expr = "\\(v1\\)"
 	# All opcodes with (v) superscript supports *only* VEX prefix
 	vexonly_expr = "\\(v\\)"
+	# All opcodes with (ev) superscript supports *only* EVEX prefix
+	evexonly_expr = "\\(ev\\)"
 
 	prefix_expr = "\\(Prefix\\)"
 	prefix_num["Operand-Size"] = "INAT_PFX_OPNDSZ"
@@ -95,6 +97,7 @@ BEGIN {
 	prefix_num["Address-Size"] = "INAT_PFX_ADDRSZ"
 	prefix_num["VEX+1byte"] = "INAT_PFX_VEX2"
 	prefix_num["VEX+2byte"] = "INAT_PFX_VEX3"
+	prefix_num["EVEX"] = "INAT_PFX_EVEX"
 
 	clear_vars()
 }
@@ -319,7 +322,9 @@ function convert_operands(count,opnd,       i,j,imm,mod)
 			flags = add_flags(flags, "INAT_MODRM")
 
 		# check VEX codes
-		if (match(ext, vexonly_expr))
+		if (match(ext, evexonly_expr))
+			flags = add_flags(flags, "INAT_VEXOK | INAT_EVEXONLY")
+		else if (match(ext, vexonly_expr))
 			flags = add_flags(flags, "INAT_VEXOK | INAT_VEXONLY")
 		else if (match(ext, vexok_expr) || match(opcode, vexok_opcode_expr))
 			flags = add_flags(flags, "INAT_VEXOK")
tools/perf/arch/x86/tests/insn-x86-dat-32.c +1012 -4

1,037 lines not on this page · raw message

tools/perf/arch/x86/tests/insn-x86-dat-64.c +934 -4

959 lines not on this page · raw message

tools/perf/arch/x86/tests/insn-x86-dat-src.c +1785 -0

426 lines not on this page · raw message

tools/perf/util/intel-pt-decoder/gen-insn-attr-x86.awk +8 -3
index 517567347aac..54e961659514 100644

Lines of this file are not shown. View the raw message.

tools/perf/util/intel-pt-decoder/inat.h +15 -2
index 611645e903a8..125ecd2a300d 100644

Lines of this file are not shown. View the raw message.

tools/perf/util/intel-pt-decoder/insn.c +15 -3
index 9f26eae6c9f0..ca983e2bea8b 100644

Lines of this file are not shown. View the raw message.

tools/perf/util/intel-pt-decoder/insn.h +11 -1
index dd12da0f4593..e23578c7b1be 100644

Lines of this file are not shown. View the raw message.

tools/perf/util/intel-pt-decoder/x86-opcode-map.txt +171 -92

263 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.9.1

Part of the diff is not shown here. View the raw message.

#4 lore raw
Quoted 13 lines · On Tue, 19 Jul 2016 15:46:48 +0300 Adrian Hunter <[email protected]>…

Add support for Intel's AVX-512 instructions to the instruction decoder.

AVX-512 instructions are documented in Intel Architecture Instruction Set Extensions Programming Reference (February 2016).

AVX-512 instructions are identifed by a EVEX prefix which, for the purpose of instruction decoding, can be treated as though it were a 4-byte VEX prefix.

Existing instructions which can now accept an EVEX prefix need not be further annotated in the op code map (x86-opcode-map.txt). In the case of new instructions, the op code map is updated accordingly.

Quoted 5 lines

Also add associated Mask Instructions that are used to manipulate mask registers used in AVX-512 instructions.

Add a representative set of instructions to the perf tools new instructons test.

Hmm, could you split this patch into 2 or 3 parts for review? One is for core-kernel, the others are for perf tools (feature adding and tests).

[..]

arch/x86/lib/x86-opcode-map.txt line 18

Quoted 11 lines
arch/x86/lib/x86-opcode-map.txt +3 -0
index 28082de46f0d..92b89fa5f414 100644
@@ -13,12 +13,17 @@
 # opcode: escape # escaped-name
 # EndTable
 #
+# mnemonics that begin with lowercase 'v' accept a VEX or EVEX prefix
+# mnemonics that begin with lowercase 'k' accept a VEX prefix
+#

Ah, nice :)

arch/x86/lib/x86-opcode-map.txt line 26

Quoted 8 lines
arch/x86/lib/x86-opcode-map.txt +2 -0
 #<group maps>
 # GrpTable: GrpXXX
 # reg:  mnemonic [operand1[,operand2...]] [(extra1)[,(extra2)...] [| 2nd-mnemonic ...]
 # EndTable
 #
 # AVX Superscripts
+#  (ev): this opcode requires EVEX prefix.
+#  (evo): this opcode accepts EVEX prefix.

Hmm, what the 'o' stands for? I thought it means "EVEX ONLY", but the comment is opposite. For example, see 'o64', which means "64bit only".
And anyway, as you said above, if all existing instructions can accept EVEX prefix, why would we need it?

arch/x86/lib/x86-opcode-map.txt line 27

Quoted 2 lines
arch/x86/lib/x86-opcode-map.txt +1 -1
-5b: vcvtdq2ps Vps,Wdq | vcvtps2dq Vdq,Wps (66) | vcvttps2dq Vdq,Wps (F3)
+5b: vcvtdq2ps Vps,Wdq | vcvtqq2ps Vps,Wqq (evo) | vcvtps2dq Vdq,Wps (66) | vcvttps2dq Vdq,Wps (F3)

Ah, I see, so that is for the instructions which change the mnemonic since byte-width is changed...

OK, so please update the above description of the superscript, like as "this opcode is changed by EVEX prefix (EVEX opcode)" etc.

Thank you,

Signature · 1 line
Masami Hiramatsu <[email protected]>
author reviewer
#5 lore raw
Quoted 58 lines · Masami Hiramatsu
Quoted 13 lines · On Tue, 19 Jul 2016 15:46:48 +0300 Adrian Hunter <[email protected]>…

Add support for Intel's AVX-512 instructions to the instruction decoder.

AVX-512 instructions are documented in Intel Architecture Instruction Set Extensions Programming Reference (February 2016).

AVX-512 instructions are identifed by a EVEX prefix which, for the purpose of instruction decoding, can be treated as though it were a 4-byte VEX prefix.

Existing instructions which can now accept an EVEX prefix need not be further annotated in the op code map (x86-opcode-map.txt). In the case of new instructions, the op code map is updated accordingly.

Quoted 5 lines

Also add associated Mask Instructions that are used to manipulate mask registers used in AVX-512 instructions.

Add a representative set of instructions to the perf tools new instructons test.

Hmm, could you split this patch into 2 or 3 parts for review? One is for core-kernel, the others are for perf tools (feature adding and tests).

[..]

arch/x86/lib/x86-opcode-map.txt line 18

Quoted 11 lines
arch/x86/lib/x86-opcode-map.txt +3 -0
index 28082de46f0d..92b89fa5f414 100644
@@ -13,12 +13,17 @@
 # opcode: escape # escaped-name
 # EndTable
 #
+# mnemonics that begin with lowercase 'v' accept a VEX or EVEX prefix
+# mnemonics that begin with lowercase 'k' accept a VEX prefix
+#

Ah, nice :)

arch/x86/lib/x86-opcode-map.txt line 26

Quoted 8 lines
arch/x86/lib/x86-opcode-map.txt +2 -0
 #<group maps>
 # GrpTable: GrpXXX
 # reg:  mnemonic [operand1[,operand2...]] [(extra1)[,(extra2)...] [| 2nd-mnemonic ...]
 # EndTable
 #
 # AVX Superscripts
+#  (ev): this opcode requires EVEX prefix.
+#  (evo): this opcode accepts EVEX prefix.

Hmm, what the 'o' stands for? I thought it means "EVEX ONLY", but the comment is opposite. For example, see 'o64', which means "64bit only".
And anyway, as you said above, if all existing instructions can accept EVEX prefix, why would we need it?

arch/x86/lib/x86-opcode-map.txt line 27

Quoted 2 lines
arch/x86/lib/x86-opcode-map.txt +1 -1
-5b: vcvtdq2ps Vps,Wdq | vcvtps2dq Vdq,Wps (66) | vcvttps2dq Vdq,Wps (F3)
+5b: vcvtdq2ps Vps,Wdq | vcvtqq2ps Vps,Wqq (evo) | vcvtps2dq Vdq,Wps (66) | vcvttps2dq Vdq,Wps (F3)
Quoted 9 lines

Ah, I see, so that is for the instructions which change the mnemonic since byte-width is changed...

OK, so please update the above description of the superscript, like as "this opcode is changed by EVEX prefix (EVEX opcode)" etc.

Thank you,

Thanks for your quick reply. I have updated the patches as you requested and sent V2.

#6 lore raw
In reply to Adrian Hunter
Quoted 7 lines · On Tue, 19 Jul 2016 15:46:46 +0300 Adrian Hunter <[email protected]>…

Hi

Here is a patch to add support for Intel's AVX-512 instructions to the instruction decoder. Also there is a patch to fix vcvtph2ps.

AVX-512 instructions are documented in Intel Architecture Instruction Set Extensions Programming Reference (February 2016).

Great job! I'll check it.

Thank you!

Quoted 26 lines

These patches do not conflict with Dan's removal of pcommit.

Adrian Hunter (2):
x86/insn: perf tools: Fix vcvtph2ps instruction decoding x86/insn: perf tools: Add AVX-512 support to the instruction decoder

 arch/x86/include/asm/inat.h                        |   17 +-
 arch/x86/include/asm/insn.h                        |   12 +-
 arch/x86/lib/insn.c                                |   18 +-
 arch/x86/lib/x86-opcode-map.txt                    |  263 ++-
 arch/x86/tools/gen-insn-attr-x86.awk               |   11 +-
 tools/perf/arch/x86/tests/insn-x86-dat-32.c        | 1018 ++++++++++-
 tools/perf/arch/x86/tests/insn-x86-dat-64.c        |  940 +++++++++-
 tools/perf/arch/x86/tests/insn-x86-dat-src.c       | 1789 ++++++++++++++++++++
 .../util/intel-pt-decoder/gen-insn-attr-x86.awk    |   11 +-
 tools/perf/util/intel-pt-decoder/inat.h            |   17 +-
 tools/perf/util/intel-pt-decoder/insn.c            |   18 +-
 tools/perf/util/intel-pt-decoder/insn.h            |   12 +-
 .../perf/util/intel-pt-decoder/x86-opcode-map.txt  |  263 ++-
 13 files changed, 4179 insertions(+), 210 deletions(-)

Regards
Adrian

Signature · 1 line
Masami Hiramatsu <[email protected]>