Skip to contentSkip to conversation

i386/cpu_dump: support AVX512 ZMM regs dump

PATCH Superseded Robert Hoo 2 participants 4 messages Mar 22, 2021 – Mar 23, 2021

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Robert Hoo

author
#0 lore raw

PATCH 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. This patch is just to complement this part, let it dump ZMM of 512bits.

---
 target/i386/cpu-dump.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)
target/i386/cpu-dump.c +13 -10
index aac21f1..789e774 100644
@@ -499,17 +499,20 @@ 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",
+
+        nb = sizeof(env->xmm_regs) / sizeof(env->xmm_regs[0]);
+        for (i = 0; i < nb; i++) {
+            qemu_fprintf(f, "ZMM%02d=0x%016lx %016lx %016lx %016lx %016lx "
+                            "%016lx %016lx %016lx",
                          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));
+                         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));
             if ((i & 1) == 1)
                 qemu_fprintf(f, "\n");
             else
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 7 lines · Robert Hoo

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. This patch is just to complement this part, let it dump ZMM of 512bits.

I think you should examine the state of the cpu to determine what of SSE, AVX or AVX512 is currently enabled, then dump that.

target/i386/cpu-dump.c void x86_cpu_dump_state(CPUState *cs, FILE *f, int flags) · line 503

Quoted 8 lines
target/i386/cpu-dump.c +2 -6
-        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",
+
+        nb = sizeof(env->xmm_regs) / sizeof(env->xmm_regs[0]);

E.g., you're dumping all of the registers in 32-bit mode, which is restricted to 8 registers, not 32.

r~

author
#2 lore raw
Quoted 12 lines · Richard Henderson
Quoted 10 lines · Robert Hoo

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. This patch is just to complement this part, let it dump ZMM of 512bits.

Quoted 3 lines

I think you should examine the state of the cpu to determine what of SSE, AVX
or AVX512 is currently enabled, then dump that.

Thanks Richard for review.

Uh, looks like the existing code doesn't have this logic yet. OK, I'm to add this logic.

Quoted 10 lines

target/i386/cpu-dump.c void x86_cpu_dump_state(CPUState *cs, FILE *f, int flags) · line 503

Quoted 9 lines
target/i386/cpu-dump.c +2 -6
-        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",
+
+        nb = sizeof(env->xmm_regs) / sizeof(env->xmm_regs[0]);
Quoted 3 lines

E.g., you're dumping all of the registers in 32-bit mode, which is restricted
to 8 registers, not 32.

In typedef struct CPUX86State {
...
ZMMReg xmm_regs[CPU_NB_REGS == 8 ? 8 : 32];
...
}

where in cpu.h

#define CPU_NB_REGS64 16
#define CPU_NB_REGS32 8

#ifdef TARGET_X86_64
#define CPU_NB_REGS CPU_NB_REGS64
#else
#define CPU_NB_REGS CPU_NB_REGS32
#endif

so the register number is 8 in 32-bit mode and 32 in 64-bit mode.

Quoted 3 lines

r~

#3 lore raw
Quoted 13 lines · Robert Hoo
Quoted 12 lines · Richard Henderson
Quoted 10 lines · Robert Hoo

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. This patch is just to complement this part, let it dump ZMM of 512bits.

Quoted 8 lines
Quoted 3 lines

I think you should examine the state of the cpu to determine what of SSE, AVX
or AVX512 is currently enabled, then dump that.

Thanks Richard for review.

Uh, looks like the existing code doesn't have this logic yet. OK, I'm to add this logic.

Correct.

Quoted 24 lines
Quoted 9 lines

target/i386/cpu-dump.c void x86_cpu_dump_state(CPUState *cs, FILE *f, int flags) · line 503

Quoted 8 lines
target/i386/cpu-dump.c +2 -6
-        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",
+
+        nb = sizeof(env->xmm_regs) / sizeof(env->xmm_regs[0]);
Quoted 3 lines

E.g., you're dumping all of the registers in 32-bit mode, which is restricted
to 8 registers, not 32.

In typedef struct CPUX86State {
...
ZMMReg xmm_regs[CPU_NB_REGS == 8 ? 8 : 32];
...
}

where in cpu.h

#define CPU_NB_REGS64 16
#define CPU_NB_REGS32 8

Quoted 7 lines

#ifdef TARGET_X86_64
#define CPU_NB_REGS CPU_NB_REGS64
#else
#define CPU_NB_REGS CPU_NB_REGS32
#endif

so the register number is 8 in 32-bit mode and 32 in 64-bit mode.

The array size is the maximum. But of course a 64-bit cpu can be put into 32-bit mode. You removed the exact check for that, using HF_CS64_MASK, quoted above.

r~