i386/cpu_dump: support AVX512 ZMM regs dump
PATCH v3 1/1 i386/cpu_dump: support AVX512 ZMM regs dump
Since commit fa4518741e (target-i386: Rename struct XMMReg to ZMMReg), CPUX86State.xmm_regs[] has already been extended to 512bit to support AVX512.
Also, other qemu level supports for AVX512 registers are there for years.
But in x86_cpu_dump_state(), still only dump XMM registers no matter YMM/ZMM is enabled.
This patch is to complement this, let it dump XMM/YMM/ZMM accordingly.
---
Changelog:
v3: fix some coding style issue.
v2: dump XMM/YMM/ZMM according to XSAVE state-components enablement.
target/i386/cpu-dump.c | 55 ++++++++++++++++++++++++++++++++++++-------------- target/i386/cpu.h | 11 ++++++++++ 2 files changed, 51 insertions(+), 15 deletions(-)
target/i386/cpu-dump.c +40 -15
@@ -499,21 +499,46 @@ void x86_cpu_dump_state(CPUState *cs, FILE *f, int flags)else qemu_fprintf (f," " ); } -if (env->hflags &HF_CS64_MASK ) - nb =16 ; -else - nb =8 ; -for (i=0 ;i<nb;i++) { -qemu_fprintf (f,"XMM%02d=%08x%08x%08x%08x" , - i, - env->xmm_regs[i].ZMM_L (3 ), - env->xmm_regs[i].ZMM_L (2 ), - env->xmm_regs[i].ZMM_L (1 ), - env->xmm_regs[i].ZMM_L (0 )); -if ((i &1 ) ==1 ) -qemu_fprintf (f,"\n" ); -else -qemu_fprintf (f," " ); + +if ((env->xcr0 &XFEATURE_AVX512 ) ==XFEATURE_AVX512 ) { +/* XSAVE enabled AVX512 */ + nb = (env->hflags &HF_CS64_MASK ) ?32 :8 ; +for (i =0 ; i < nb; i++) { +qemu_fprintf (f,"ZMM%02d=0x%016lx %016lx %016lx %016lx %016lx " +"%016lx %016lx %016lx\n" , + i, + env->xmm_regs[i].ZMM_Q (7 ), + env->xmm_regs[i].ZMM_Q (6 ), + env->xmm_regs[i].ZMM_Q (5 ), + env->xmm_regs[i].ZMM_Q (4 ), + env->xmm_regs[i].ZMM_Q (3 ), + env->xmm_regs[i].ZMM_Q (2 ), + env->xmm_regs[i].ZMM_Q (1 ), + env->xmm_regs[i].ZMM_Q (0 )); + } + }else if (env->xcr0 &XFEATURE_AVX ) { +/* XSAVE enabled AVX */ + nb = env->hflags &HF_CS64_MASK ?16 :8 ; +for (i =0 ; i < nb; i++) { +qemu_fprintf (f,"YMM%02d=0x%016lx %016lx %016lx %016lx\n" , + i, + env->xmm_regs[i].ZMM_Q (3 ), + env->xmm_regs[i].ZMM_Q (2 ), + env->xmm_regs[i].ZMM_Q (1 ), + env->xmm_regs[i].ZMM_Q (0 )); + } + }else {/* SSE and below cases */ + nb = env->hflags &HF_CS64_MASK ?16 :8 ; +for (i =0 ; i < nb; i++) { +qemu_fprintf (f,"XMM%02d=0x%016lx %016lx" , + i, + env->xmm_regs[i].ZMM_Q (1 ), + env->xmm_regs[i].ZMM_Q (0 )); +if ((i &1 ) ==1 ) +qemu_fprintf (f,"\n" ); +else +qemu_fprintf (f," " ); + } } }if (flags &CPU_DUMP_CODE ) {
target/i386/cpu.h +11 -0
@@ -249,6 +249,17 @@ typedef enum X86Seg {#define CR4_PKE_MASK (1U << 22)#define CR4_PKS_MASK (1U << 24) +#define XFEATURE_X87 (1UL << 0) +#define XFEATURE_SSE (1UL << 1) +#define XFEATURE_AVX (1UL << 2) +#define XFEATURE_AVX512_OPMASK (1UL << 5) +#define XFEATURE_AVX512_ZMM_Hi256 (1UL << 6) +#define XFEATURE_AVX512_Hi16_ZMM (1UL << 7) +#define XFEATURE_AVX512 (XFEATURE_AVX512_OPMASK | \ + XFEATURE_AVX512_ZMM_Hi256 | \ + XFEATURE_AVX512_Hi16_ZMM) + +#define DR6_BD (1 << 13)#define DR6_BS (1 << 14)#define DR6_BT (1 << 15)
Signature · 1 line
1.8.3.1
Quoted 6 lines · Robert Hoo
target/i386/cpu-dump.c +6
-0+if ((env->xcr0 &XFEATURE_AVX512 ) ==XFEATURE_AVX512 ) { +/* XSAVE enabled AVX512 */ + nb = (env->hflags &HF_CS64_MASK ) ?32 :8 ; +for (i =0 ; i < nb; i++) { + qemu_fprintf(f, "ZMM%02d=0x%016lx %016lx %016lx %016lx %016lx " + "%016lx %016lx %016lx\n",
target/i386/cpu-dump.c void x86_cpu_dump_state(CPUState *cs, FILE *f, int flags) · line 518
Quoted 10 lines
target/i386/cpu-dump.c +10
-0+ i, + env->xmm_regs[i].ZMM_Q (7 ), + env->xmm_regs[i].ZMM_Q (6 ), + env->xmm_regs[i].ZMM_Q (5 ), + env->xmm_regs[i].ZMM_Q (4 ), + env->xmm_regs[i].ZMM_Q (3 ), + env->xmm_regs[i].ZMM_Q (2 ), + env->xmm_regs[i].ZMM_Q (1 ), + env->xmm_regs[i].ZMM_Q(0)); + }
Dump opmask regs?
Quoted 1 line
+ } else if (
env->xcr0&XFEATURE_AVX) {
This is normally a 2-bit test.
Quoted 11 lines
target/i386/cpu-dump.c +11
-0+/* XSAVE enabled AVX */ + nb = env->hflags &HF_CS64_MASK ?16 :8 ; +for (i =0 ; i < nb; i++) { +qemu_fprintf (f,"YMM%02d=0x%016lx %016lx %016lx %016lx\n" , + i, + env->xmm_regs[i].ZMM_Q (3 ), + env->xmm_regs[i].ZMM_Q (2 ), + env->xmm_regs[i].ZMM_Q (1 ), + env->xmm_regs[i].ZMM_Q (0 )); + } + }else {/* SSE and below cases */
target/i386/cpu-dump.c void x86_cpu_dump_state(CPUState *cs, FILE *f, int flags) · line 540
Quoted 10 lines
target/i386/cpu-dump.c +10
-0+ nb = env->hflags &HF_CS64_MASK ?16 :8 ; +for (i =0 ; i < nb; i++) { +qemu_fprintf (f,"XMM%02d=0x%016lx %016lx" , + i, + env->xmm_regs[i].ZMM_Q (1 ), + env->xmm_regs[i].ZMM_Q (0 )); +if ((i &1 ) ==1 ) +qemu_fprintf (f,"\n" ); +else +qemu_fprintf (f," " );
I'd be tempted to merge that second printf into the first, with "%s" and (i & 1 ? "\n" : " "). Otherwise you'll need to add braces to that IF to satisfy checkpatch.
target/i386/cpu.h typedef enum X86Seg { · line 260
Quoted 9 lines
target/i386/cpu.h +9
-0+#define XFEATURE_X87 (1UL << 0) +#define XFEATURE_SSE (1UL << 1) +#define XFEATURE_AVX (1UL << 2) +#define XFEATURE_AVX512_OPMASK (1UL << 5) +#define XFEATURE_AVX512_ZMM_Hi256 (1UL << 6) +#define XFEATURE_AVX512_Hi16_ZMM (1UL << 7) +#define XFEATURE_AVX512 (XFEATURE_AVX512_OPMASK | \ + XFEATURE_AVX512_ZMM_Hi256 | \ + XFEATURE_AVX512_Hi16_ZMM)
Except for the last, these already exist under the name XSTATE_*_MASK.
I think you can just as well declare local variables to hold the 3 bits for the avx512 test and the 2 bits for the avx test.
r~
Quoted 19 lines · Richard Henderson
Quoted 7 lines · Robert Hoo
target/i386/cpu-dump.c +5
-0+if ((env->xcr0 &XFEATURE_AVX512 ) ==XFEATURE_AVX512 ) { +/* XSAVE enabled AVX512 */ + nb = (env->hflags &HF_CS64_MASK ) ?32 :8 ; +for (i =0 ; i < nb; i++) { + qemu_fprintf(f, "ZMM%02d=0x%016lx %016lx %016lx%016lx %016lx "
target/i386/cpu-dump.c +1
-0+ "%016lx %016lx %016lx\n",target/i386/cpu-dump.c void x86_cpu_dump_state(CPUState *cs, FILE *f, int flags) · line 518
Quoted 10 lines
target/i386/cpu-dump.c +10
-0+ i, + env->xmm_regs[i].ZMM_Q (7 ), + env->xmm_regs[i].ZMM_Q (6 ), + env->xmm_regs[i].ZMM_Q (5 ), + env->xmm_regs[i].ZMM_Q (4 ), + env->xmm_regs[i].ZMM_Q (3 ), + env->xmm_regs[i].ZMM_Q (2 ), + env->xmm_regs[i].ZMM_Q (1 ), + env->xmm_regs[i].ZMM_Q(0)); + }
Quoted 1 line
Dump opmask regs?
OK
Quoted 4 lines
Quoted 2 lines
+ } else if (
env->xcr0&XFEATURE_AVX) {This is normally a 2-bit test.
I beg your pardon. What 2 bits?
Quoted 24 lines
Quoted 13 lines
target/i386/cpu-dump.c +4
-0+/* XSAVE enabled AVX */ + nb = env->hflags &HF_CS64_MASK ?16 :8 ; +for (i =0 ; i < nb; i++) { + qemu_fprintf(f, "YMM%02d=0x%016lx %016lx %016lx%016lx\n",
target/i386/cpu-dump.c +7
-0+ i, + env->xmm_regs[i].ZMM_Q (3 ), + env->xmm_regs[i].ZMM_Q (2 ), + env->xmm_regs[i].ZMM_Q (1 ), + env->xmm_regs[i].ZMM_Q(0)); + } + }else {/* SSE and below cases */ target/i386/cpu-dump.c void x86_cpu_dump_state(CPUState *cs, FILE *f, int flags) · line 540
Quoted 10 lines
target/i386/cpu-dump.c +10
-0+ nb = env->hflags &HF_CS64_MASK ?16 :8 ; +for (i =0 ; i < nb; i++) { +qemu_fprintf (f,"XMM%02d=0x%016lx %016lx" , + i, + env->xmm_regs[i].ZMM_Q (1 ), + env->xmm_regs[i].ZMM_Q (0 )); +if ((i &1 ) ==1 ) +qemu_fprintf (f,"\n" ); +else +qemu_fprintf (f," " );
Quoted 5 lines
I'd be tempted to merge that second printf into the first, with "%s" and (i & 1
? "\n" : " "). Otherwise you'll need to add braces to that IF to satisfy
checkpatch.
Sure. I just retained previous code.
BTW, checkpatch didn't warn me on this. It escaped.:)
Quoted 13 lines
target/i386/cpu.h typedef enum X86Seg { · line 260
Quoted 10 lines
target/i386/cpu.h +9
-0+#define XFEATURE_X87 (1UL << 0) +#define XFEATURE_SSE (1UL << 1) +#define XFEATURE_AVX (1UL << 2) +#define XFEATURE_AVX512_OPMASK (1UL << 5) +#define XFEATURE_AVX512_ZMM_Hi256 (1UL << 6) +#define XFEATURE_AVX512_Hi16_ZMM (1UL << 7) +#define XFEATURE_AVX512 (XFEATURE_AVX512_OPMASK | \ + XFEATURE_AVX512_ZMM_Hi256 | \ + XFEATURE_AVX512_Hi16_ZMM)Except for the last, these already exist under the name XSTATE_*_MASK.
Ah, my poor eye sight. They even exist in the same file. Thanks pointing out.
Quoted 5 lines
I think you can just as well declare local variables to hold the 3 bits for the
avx512 test and the 2 bits for the avx test.
Sure.
Quoted 2 lines
r~
Quoted 5 lines · Robert Hoo
Quoted 3 lines
Quoted 1 line
+ } else if (
env->xcr0&XFEATURE_AVX) {This is normally a 2-bit test.
I beg your pardon. What 2 bits?
I forget the names, but isn't the usual test xcr0 & 6 == 6?
Quoted 1 line
BTW, checkpatch didn't warn me on this. It escaped.:)
Heh.
r~
Quoted 8 lines · Richard Henderson
Quoted 5 lines · Robert Hoo
Quoted 3 lines
Quoted 1 line
+ } else if (
env->xcr0&XFEATURE_AVX) {This is normally a 2-bit test.
I beg your pardon. What 2 bits?
I forget the names, but isn't the usual test xcr0 & 6 == 6?
6 stands for SSE state-component and AVX state-component. I'm not sure about this.
Can you remember where did you this "xcr0 & 6 == 6"? I can look into that.
Quoted 7 lines
Quoted 2 lines
BTW, checkpatch didn't warn me on this. It escaped.:)
Heh.
r~
Quoted 6 lines · Robert Hoo
Quoted 5 lines · Richard Henderson
Quoted 4 lines · Robert Hoo
Quoted 3 lines
Quoted 1 line
+ } else if (
env->xcr0&XFEATURE_AVX) {This is normally a 2-bit test.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
I beg your pardon. What 2 bits?
I forget the names, but isn't the usual test xcr0 & 6 == 6?
6 stands for SSE state-component and AVX state-component. I'm not sure about this.
Can you remember where did you this "xcr0 & 6 == 6"? I can look into that.
IA-64 and IA32 Software developers manual, Vol 1 Basic Architecture, Section 14.3 Detection of AVX instructions.
r~
Quoted 17 lines · Richard Henderson
Quoted 8 lines · Robert Hoo
Quoted 7 lines · Richard Henderson
Quoted 5 lines · Robert Hoo
Quoted 3 lines
Quoted 1 line
+ } else if (
env->xcr0&XFEATURE_AVX) {This is normally a 2-bit test.
I beg your pardon. What 2 bits?
Quoted 7 lines
Quoted 1 line
I forget the names, but isn't the usual test xcr0 & 6 == 6?
6 stands for SSE state-component and AVX state-component. I'm not sure about this.
Can you remember where did you this "xcr0 & 6 == 6"? I can look into
that.
Quoted 3 lines
IA-64 and IA32 Software developers manual, Vol 1 Basic Architecture, Section
14.3 Detection of AVX instructions.
OK, thanks Richard. If use the feature detection criteria here, then AVX512 case will also need XCR0[2:1]='11b'.
I'm going to send v4 soon.
Quoted 3 lines
r~