Skip to contentSkip to conversation

target-arm: Move VLD/VST multiple into helper functions

PATCH In review Peter Maydell 3 participants 6 messages Apr 20, 2011 – Jun 6, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target-arm: Move VLD/VST multiple into helper functions

Move VLD/VST multiple into helper functions, as some cases can generate more TCG ops than the maximum per-instruction limit and certainly more than the recommended 20.

---
This patch is inspired by one from the meego tree:
http://git.linaro.org/gitweb?p=qemu/qemu-linaro.git;a=commitdiff;h=a5b2a79c7929726bac5157783de81d22793efd12
but I've reworked it to do the decoding at translate time rather than in the helper function.

It is intended to apply on top of the neon load/store UNDEF fixes:
http://patchwork.ozlabs.org/patch/91824/
http://patchwork.ozlabs.org/patch/91825/

but I thought it would be better to push it out now for review rather than waiting for those to be committed.

I hope you all like macros :-)

 target-arm/helper.h      |   40 +++++++++++++
 target-arm/neon_helper.c |  127 +++++++++++++++++++++++++++++++++++++++++
 target-arm/translate.c   |  140 +++++++++++-----------------------------------
 3 files changed, 199 insertions(+), 108 deletions(-)
target-arm/helper.h +40 -0
index ae701e8..7a25288 100644
@@ -472,4 +472,44 @@ DEF_HELPER_2(neon_qzip8, void, i32, i32)
 DEF_HELPER_2(neon_qzip16, void, i32, i32)
 DEF_HELPER_2(neon_qzip32, void, i32, i32)
 
+/* The VLD/VST multiple ops have a particular set of 'op' fields
+ * which decode into specific (nregs,interleave,spacing) combinations.
+ * There are 11 valid combinations, each of which has a helper
+ * for load and store for four operand sizes.
+ */
+#define FOREACH_VLDST_L_SIZE(OP, N, I, S) \
+    OP(st, 0, N, I, S) \
+    OP(ld, 0, N, I, S) \
+    OP(st, 1, N, I, S) \
+    OP(ld, 1, N, I, S) \
+    OP(st, 2, N, I, S) \
+    OP(ld, 2, N, I, S) \
+    OP(st, 3, N, I, S) \
+    OP(ld, 3, N, I, S)
+
+#define FOREACH_VLDST_HELPER(OP)   \
+    FOREACH_VLDST_L_SIZE(OP, 4, 4, 1) \
+    FOREACH_VLDST_L_SIZE(OP, 4, 4, 2) \
+    FOREACH_VLDST_L_SIZE(OP, 4, 1, 1) \
+    FOREACH_VLDST_L_SIZE(OP, 4, 2, 1) \
+    FOREACH_VLDST_L_SIZE(OP, 3, 3, 1) \
+    FOREACH_VLDST_L_SIZE(OP, 3, 3, 2) \
+    FOREACH_VLDST_L_SIZE(OP, 3, 1, 1) \
+    FOREACH_VLDST_L_SIZE(OP, 1, 1, 1) \
+    FOREACH_VLDST_L_SIZE(OP, 2, 2, 1) \
+    FOREACH_VLDST_L_SIZE(OP, 2, 2, 2) \
+    FOREACH_VLDST_L_SIZE(OP, 2, 1, 1)
+
+/* Get the index into a table created by FOREACH_VLDST_HELPER;
+ * the calculation has to match the order in which that macro expands things.
+ */
+#define VLDST_HELPER_INDEX(ld, sz, op) (((op) * 8) + ((sz) * 2) + (ld))
+
+#define VLDST_HELPER_NAME(ld, sz, n, i, s) neon_v##ld##_##sz##_##n##_##i##_##s
+
+#define DECLARE_VLDST_HELPER(ld, sz, n, i, s) \
+    DEF_HELPER_2(VLDST_HELPER_NAME(ld, sz, n, i, s), void, i32, i32)
+
+FOREACH_VLDST_HELPER(DECLARE_VLDST_HELPER)
+
 #include "def-helper.h"
target-arm/neon_helper.c +127 -0

130 lines not on this page · raw message

target-arm/translate.c +32 -108

173 lines not on this page · raw message

Signature · 1 line
1.7.1
#1 lore raw

Ping? The two UNDEF patches have both been applied, so this patch applies cleanly to master now.

-- PMM

Quoted 24 lines · Peter Maydell

Move VLD/VST multiple into helper functions, as some cases can generate more TCG ops than the maximum per-instruction limit and certainly more than the recommended 20.

---
This patch is inspired by one from the meego tree:
 http://git.linaro.org/gitweb?p=qemu/qemu-linaro.git;a=commitdiff;h=a5b2a79c7929726bac5157783de81d22793efd12
but I've reworked it to do the decoding at translate time rather than in the helper function.

It is intended to apply on top of the neon load/store UNDEF fixes:
http://patchwork.ozlabs.org/patch/91824/
http://patchwork.ozlabs.org/patch/91825/

but I thought it would be better to push it out now for review rather than waiting for those to be committed.

I hope you all like macros :-)

 target-arm/helper.h      |   40 +++++++++++++ target-arm/neon_helper.c |  127 +++++++++++++++++++++++++++++++++++++++++ target-arm/translate.c   |  140 +++++++++++-----------------------------------

 3 files changed, 199 insertions(+), 108 deletions(-)
#2 lore raw
In reply to Peter Maydell
Quoted 3 lines · Peter Maydell

Move VLD/VST multiple into helper functions, as some cases can generate more TCG ops than the maximum per-instruction limit and certainly more than the recommended 20.

I've had a review comment in private email that this patch slows down ffmpeg by a little over 4% (in a linux-user execution run where about 5% of instructions were an affected vld/vst). So perhaps the right approach is to increase the max-ops-per-insn limit and update the guidance in tcg/README instead?

-- PMM

#3 lore raw
Quoted 11 lines · Peter Maydell
Quoted 3 lines · Peter Maydell

Move VLD/VST multiple into helper functions, as some cases can generate more TCG ops than the maximum per-instruction limit and certainly more than the recommended 20.

I've had a review comment in private email that this patch slows down ffmpeg by a little over 4% (in a linux-user execution run where about 5% of instructions were an affected vld/vst). So perhaps the right approach is to increase the max-ops-per-insn limit and update the guidance in tcg/README instead?

Does this patch fixes a real issue (ie most probably a crash), or it is just to make the arm target compliant with the README?

Two remarks there:
- The guidance in tcg/README is probably true for complex helpers in the sense of doing a lot of logic/arithmetic operations for which the TCG instruction set if not really rich and for which the compiler can do a lot better. When the instruction is emulated mostly by load/store ops, there isn't much possible optimizations left.
- Your patch calls the slow version of the _mmu functions, which doesn't use the QEMU TLB. It is therefore normal to expect a slow down. Unfortunately the fast version of _mmu functions are not really usable from an helper, or at least they need a lot of code to convert an mmu index to the right function. It is something I have on my TODO list for some months, haven't found time to look at it.

Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#4 lore raw
Quoted 2 lines · Aurelien Jarno

Does this patch fixes a real issue (ie most probably a crash), or it is just to make the arm target compliant with the README?

I haven't actually generated a test case which would make qemu abort, but it shouldn't be hard to do so.

Quoted 6 lines

Two remarks there:
- The guidance in tcg/README is probably true for complex helpers in the sense of doing a lot of logic/arithmetic operations for which the TCG instruction set if not really rich and for which the compiler can do a lot better. When the instruction is emulated mostly by load/store ops, there isn't much possible optimizations left.

Yes. The 96 op limit to avoid overrunning the buffer is a hard one, though.

Quoted 2 lines

- Your patch calls the slow version of the _mmu functions, which doesn't use the QEMU TLB. It is therefore normal to expect a slow down.

...even for linux-user mode? That doesn't use softmmu...

Anyway, this patch is on my list to rework when I can figure out what the right approach to it is.

-- PMM

#5 lore raw
In reply to Aurelien Jarno
Quoted 6 lines · Aurelien Jarno
Quoted 4 lines · Peter Maydell
Quoted 3 lines · Peter Maydell

Move VLD/VST multiple into helper functions, as some cases can generate more TCG ops than the maximum per-instruction limit and certainly more than the recommended 20.

Quoted 8 lines
Quoted 5 lines

I've had a review comment in private email that this patch slows down ffmpeg by a little over 4% (in a linux-user execution run where about 5% of instructions were an affected vld/vst). So perhaps the right approach is to increase the max-ops-per-insn limit and update the guidance in tcg/README instead?

Does this patch fixes a real issue (ie most probably a crash), or it is just to make the arm target compliant with the README?

Yes, it (or the similar patch in meego qemu) did fix an real issue. IIRC when running pixman code where vld4.8 variant of instruction was used.

Riku