Skip to contentSkip to conversation

tcg/ppc: Add vector opcodes

PATCH Superseded Richard Henderson 4 participants 8 messages Feb 22, 2019 – Feb 28, 2019

v1 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tcg/ppc: Add vector opcodes

This requires VSX, not just Altivec, so Power7 or later.

---

At present there are no tunables that can avoid the 64-bit element load/store requirement. As with requiring AVX1 for x86 hosts, I'm not sure it's worth inventing such a tunable for pre-power7 hosts.

Tested vs aarch64 risu test cases. It's probably worth testing this vs Mark's target/ppc conversion.

r~

---
 tcg/ppc/tcg-target.h     |  31 +-
 tcg/ppc/tcg-target.opc.h |   3 +
 tcg/ppc/tcg-target.inc.c | 604 +++++++++++++++++++++++++++++++++++----
 3 files changed, 577 insertions(+), 61 deletions(-)
 create mode 100644 tcg/ppc/tcg-target.opc.h
tcg/ppc/tcg-target.h +30 -1
index 52c1bb04b1..0b9943e7e6 100644
@@ -31,7 +31,7 @@
 # define TCG_TARGET_REG_BITS  32
 #endif
 
-#define TCG_TARGET_NB_REGS 32
+#define TCG_TARGET_NB_REGS 64
 #define TCG_TARGET_INSN_UNIT_SIZE 4
 #define TCG_TARGET_TLB_DISPLACEMENT_BITS 16
 
@@ -45,12 +45,22 @@ typedef enum {
     TCG_REG_R24, TCG_REG_R25, TCG_REG_R26, TCG_REG_R27,
     TCG_REG_R28, TCG_REG_R29, TCG_REG_R30, TCG_REG_R31,
 
+    TCG_REG_V0,  TCG_REG_V1,  TCG_REG_V2,  TCG_REG_V3,
+    TCG_REG_V4,  TCG_REG_V5,  TCG_REG_V6,  TCG_REG_V7,
+    TCG_REG_V8,  TCG_REG_V9,  TCG_REG_V10, TCG_REG_V11,
+    TCG_REG_V12, TCG_REG_V13, TCG_REG_V14, TCG_REG_V15,
+    TCG_REG_V16, TCG_REG_V17, TCG_REG_V18, TCG_REG_V19,
+    TCG_REG_V20, TCG_REG_V21, TCG_REG_V22, TCG_REG_V23,
+    TCG_REG_V24, TCG_REG_V25, TCG_REG_V26, TCG_REG_V27,
+    TCG_REG_V28, TCG_REG_V29, TCG_REG_V30, TCG_REG_V31,
+
     TCG_REG_CALL_STACK = TCG_REG_R1,
     TCG_AREG0 = TCG_REG_R27
 } TCGReg;
 
 extern bool have_isa_2_06;
 extern bool have_isa_3_00;
+extern bool have_isa_2_07_vsx;
 
 /* optional instructions automatically implemented */
 #define TCG_TARGET_HAS_ext8u_i32        0 /* andi */
@@ -124,6 +134,25 @@ extern bool have_isa_3_00;
 #define TCG_TARGET_HAS_mulsh_i64        1
 #endif
 
+/* VSX required over ALTIVEC to perform 64-bit loads.  */
+#if TCG_TARGET_REG_BITS == 64
+#define TCG_TARGET_HAS_v64              have_isa_2_07_vsx
+#define TCG_TARGET_HAS_v128             have_isa_2_07_vsx
+#define TCG_TARGET_HAS_v256             0
+#endif
+
+#define TCG_TARGET_HAS_andc_vec         1
+#define TCG_TARGET_HAS_orc_vec          1
+#define TCG_TARGET_HAS_not_vec          1
+#define TCG_TARGET_HAS_neg_vec          0
+#define TCG_TARGET_HAS_shi_vec          0
+#define TCG_TARGET_HAS_shs_vec          0
+#define TCG_TARGET_HAS_shv_vec          0
+#define TCG_TARGET_HAS_cmp_vec          1
+#define TCG_TARGET_HAS_mul_vec          1
+#define TCG_TARGET_HAS_sat_vec          1
+#define TCG_TARGET_HAS_minmax_vec       1
+
 void flush_icache_range(uintptr_t start, uintptr_t stop);
 void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t);
 
tcg/ppc/tcg-target.opc.h new file +3 -0
new file mode 100644
index 0000000000..4816a6c3d4
@@ -0,0 +1,3 @@
+/* Target-specific opcodes for host vector expansion.  These will be
+   emitted by tcg_expand_vec_op.  For those familiar with GCC internals,
+   consider these to be UNSPEC with names.  */
tcg/ppc/tcg-target.inc.c +544 -60

725 lines not on this page · raw message

Signature · 1 line
2.17.2
#1 lore raw
Quoted 11 lines · Richard Henderson

This requires VSX, not just Altivec, so Power7 or later.

---

At present there are no tunables that can avoid the 64-bit element load/store requirement. As with requiring AVX1 for x86 hosts, I'm not sure it's worth inventing such a tunable for pre-power7 hosts.

Tested vs aarch64 risu test cases. It's probably worth testing this vs Mark's target/ppc conversion.

Oooh this looks really exciting! However... I only have a G4 Mac Mini around that I use for testing which is Altivec-only :( Is it much work to support non-VSX hosts?

This leads me to a related point that came up when Howard and I were testing the PPC vector patches - how do we know at runtime which optimisations were being used, e.g. what is the value of have_avx2 on a particular CPU running QEMU?

Under Linux this isn't too bad since you can just do "cat /proc/cpuinfo | grep avx2" but it becomes more tricky when getting bug reports from Windows users who aren't particularly technical...

ATB,

Mark.

#2 lore raw
Quoted 11 lines · Mark Cave-Ayland
Quoted 9 lines · Richard Henderson

This requires VSX, not just Altivec, so Power7 or later.

---

At present there are no tunables that can avoid the 64-bit element load/store requirement. As with requiring AVX1 for x86 hosts, I'm not sure it's worth inventing such a tunable for pre-power7 hosts.

Quoted 5 lines
Quoted 2 lines

Tested vs aarch64 risu test cases. It's probably worth testing this vs Mark's target/ppc conversion.

Oooh this looks really exciting! However... I only have a G4 Mac Mini around that I use for testing which is Altivec-only :( Is it much work to support non-VSX hosts?

Hmm, dunno. I'll think about it.

Quoted 3 lines

This leads me to a related point that came up when Howard and I were testing the PPC vector patches - how do we know at runtime which optimisations were being used, e.g. what is the value of have_avx2 on a particular CPU running QEMU?

There is no way from within qemu itself.

Quoted 3 lines

Under Linux this isn't too bad since you can just do "cat /proc/cpuinfo | grep avx2" but it becomes more tricky when getting bug reports from Windows users who aren't particularly technical...

Something like:
https://www.intel.com/content/www/us/en/support/articles/000005651/processors.html

or any one of several other utilities that can display cpuid information.

r~

#3 lore raw
In reply to Mark Cave-Ayland
Quoted 11 lines · Mark Cave-Ayland
Quoted 9 lines · Richard Henderson

This requires VSX, not just Altivec, so Power7 or later.

---

At present there are no tunables that can avoid the 64-bit element load/store requirement. As with requiring AVX1 for x86 hosts, I'm not sure it's worth inventing such a tunable for pre-power7 hosts.

Quoted 6 lines
Quoted 2 lines

Tested vs aarch64 risu test cases. It's probably worth testing this vs Mark's target/ppc conversion.

Oooh this looks really exciting! However... I only have a G4 Mac Mini around that I use for testing which is Altivec-only :( Is it much work to support non-VSX hosts?

I have access to POWER8 and POWER9 machines, but I haven't worked with RISU before. If you can give me a straightforward recipe I can try running the tests.

Quoted 14 lines

This leads me to a related point that came up when Howard and I were testing the PPC vector patches - how do we know at runtime which optimisations were being used, e.g. what is the value of have_avx2 on a particular CPU running QEMU?

Under Linux this isn't too bad since you can just do "cat /proc/cpuinfo | grep avx2" but it becomes more tricky when getting bug reports from Windows users who aren't particularly technical...

ATB,

Mark.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#4 lore raw
Quoted 3 lines · David Gibson

I have access to POWER8 and POWER9 machines, but I haven't worked with RISU before. If you can give me a straightforward recipe I can try running the tests.

From

https://git.linaro.org/people/peter.maydell/risu.git

First you need to generate the test cases. It looks like the current ppc64.risu file is fairly complete, at least to some level. So:

mkdir ../risu-testcases-ppc64 ./scripts/generate_all.sh ppc64.risu ../risu-testcases-ppc64

Then record traces from real hardware to compare against:

RISU=pwd/risu ./scripts/record_traces.sh ../risu-testcases-ppc64/*.bin

Now compare QEMU against hardware:

QEMU=qemu-ppc64 RISU=pwd/risu \
./scripts/run_risu ../risu-testcases-ppc64/*.bin

Which is all hunky dory until something fails. At which point it's a matter of using qemu's -d and -dfilter options judiciously, and "objdump -b binary -m ppc64 -D foo.bin".

r~

#5 lore raw
Quoted 8 lines · Richard Henderson
Quoted 3 lines · David Gibson

I have access to POWER8 and POWER9 machines, but I haven't worked with RISU before. If you can give me a straightforward recipe I can try running the tests.

From

https://git.linaro.org/people/peter.maydell/risu.git

And I assume build it, at which point I hit this:

$ make
gcc  -Wall -D_GNU_SOURCE -DARCH=ppc64 -I /home/dwg/risu/risu -g  -o risu_ppc64.o -c risu_ppc64.c
risu_ppc64.c: In function ‘advance_pc’:
risu_ppc64.c:19:25: error: dereferencing pointer to incomplete type ‘struct pt_regs’
     uc->uc_mcontext.regs->nip += 4;
                         ^~
make: *** [Makefile:44: risu_ppc64.o] Error 1

I'm running on ppc64le (as I usually do nowadays), so I'm not sure if this is due to a difference between the ppc64 and ppc64le ABIs (and mcontext structures) or something else.

Quoted 22 lines

First you need to generate the test cases. It looks like the current ppc64.risu file is fairly complete, at least to some level. So:

mkdir ../risu-testcases-ppc64 ./scripts/generate_all.sh ppc64.risu ../risu-testcases-ppc64

Then record traces from real hardware to compare against:

RISU=pwd/risu ./scripts/record_traces.sh ../risu-testcases-ppc64/*.bin

Now compare QEMU against hardware:

QEMU=qemu-ppc64 RISU=pwd/risu \
./scripts/run_risu ../risu-testcases-ppc64/*.bin

Which is all hunky dory until something fails. At which point it's a matter of using qemu's -d and -dfilter options judiciously, and "objdump -b binary -m ppc64 -D foo.bin".

r~

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#6 lore raw
Quoted 12 lines · David Gibson
Quoted 8 lines · Richard Henderson
Quoted 3 lines · David Gibson

I have access to POWER8 and POWER9 machines, but I haven't worked with RISU before. If you can give me a straightforward recipe I can try running the tests.

From

https://git.linaro.org/people/peter.maydell/risu.git

And I assume build it, at which point I hit this:

Quoted 7 lines
$ make
gcc  -Wall -D_GNU_SOURCE -DARCH=ppc64 -I /home/dwg/risu/risu -g  -o risu_ppc64.o -c risu_ppc64.c
risu_ppc64.c: In function ‘advance_pc’:
risu_ppc64.c:19:25: error: dereferencing pointer to incomplete type ‘struct pt_regs’
     uc->uc_mcontext.regs->nip += 4;
                         ^~
make: *** [Makefile:44: risu_ppc64.o] Error 1

Dunno. Works for me.

$ uname -a
Linux gcc135.osuosl.org 4.14.0-115.2.2.el7a.ppc64le #1 SMP Wed Nov 28 21:39:33
GMT 2018 ppc64le ppc64le ppc64le GNU/Linux
$ head -2 /etc/os-release
NAME="CentOS Linux"
VERSION="7 (AltArch)"

I guess you'll need to debug this in your environment to find out what's different?

r~

#7 lore raw
In reply to Richard Henderson
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series seems to have some coding style problems. See output below for more information:

Message-id: [email protected]
Subject: [Qemu-devel] [PATCH] tcg/ppc: Add vector opcodes
Type: series

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu

 * [new tag]               patchew/[email protected] -> patchew/[email protected]
 * [new tag]               patchew/[email protected] -> patchew/[email protected]
 * [new tag]               patchew/[email protected] -> patchew/[email protected]
 * [new tag]               patchew/[email protected] -> patchew/[email protected]
 * [new tag]               patchew/[email protected] -> patchew/[email protected]

Switched to a new branch 'test'
56177b9cb7 tcg/ppc: Add vector opcodes

=== OUTPUT BEGIN ===
ERROR: spaces required around that '|' (ctx:VxV)
#187: FILE: tcg/ppc/tcg-target.inc.c:327:
+#define VX4(opc) (OPCD(4)|(opc))

                           ^

ERROR: trailing whitespace
#552: FILE: tcg/ppc/tcg-target.inc.c:2876:
+ umin_op[4] = { VMINUB, VMINUH, VMINUW, VMINUD }, $

ERROR: trailing whitespace
#553: FILE: tcg/ppc/tcg-target.inc.c:2877:
+ smin_op[4] = { VMINSB, VMINSH, VMINSW, VMINSD }, $

ERROR: trailing whitespace
#554: FILE: tcg/ppc/tcg-target.inc.c:2878:
+ umax_op[4] = { VMAXUB, VMAXUH, VMAXUW, VMAXUD }, $

WARNING: Block comments use a leading /* on a separate line #623: FILE: tcg/ppc/tcg-target.inc.c:2947:
+ /* Recall we use VSX integer loads, so the integer is right

WARNING: Block comments use * on subsequent lines
#624: FILE: tcg/ppc/tcg-target.inc.c:2948:
+ /* Recall we use VSX integer loads, so the integer is right
+ justified within the left (zero-index) double-word. */

WARNING: Block comments use a trailing */ on a separate line #624: FILE: tcg/ppc/tcg-target.inc.c:2948:
+ justified within the left (zero-index) double-word. */

WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #822:
new file mode 100644

WARNING: Block comments use a leading /* on a separate line #827: FILE: tcg/ppc/tcg-target.opc.h:1:
+/* Target-specific opcodes for host vector expansion. These will be

WARNING: Block comments use * on subsequent lines
#828: FILE: tcg/ppc/tcg-target.opc.h:2:
+/* Target-specific opcodes for host vector expansion. These will be
+ emitted by tcg_expand_vec_op. For those familiar with GCC internals,

WARNING: Block comments use a trailing */ on a separate line #829: FILE: tcg/ppc/tcg-target.opc.h:3:
+ consider these to be UNSPEC with names. */

total: 4 errors, 7 warnings, 783 lines checked

Commit 56177b9cb743 (tcg/ppc: Add vector opcodes) has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===

Test command exited with code: 1

The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]