1 | The following changes since commit c52d69e7dbaaed0ffdef8125e79218672c30161d: | 1 | The following changes since commit 627634031092e1514f363fd8659a579398de0f0e: |
---|---|---|---|
2 | 2 | ||
3 | Merge remote-tracking branch 'remotes/cschoenebeck/tags/pull-9p-20211027' into staging (2021-10-27 11:45:18 -0700) | 3 | Merge tag 'buildsys-qom-qdev-ui-20230227' of https://github.com/philmd/qemu into staging (2023-02-28 15:09:18 +0000) |
4 | 4 | ||
5 | are available in the Git repository at: | 5 | are available in the Git repository at: |
6 | 6 | ||
7 | https://gitlab.com/rth7680/qemu.git tags/pull-tcg-20211027 | 7 | https://gitlab.com/rth7680/qemu.git tags/pull-tcg-20230228 |
8 | 8 | ||
9 | for you to fetch changes up to 820c025f0dcacf2f3c12735b1f162893fbfa7bc6: | 9 | for you to fetch changes up to c7fbf10db8718d2eba87712bc3410b671157a377: |
10 | 10 | ||
11 | tcg/optimize: Propagate sign info for shifting (2021-10-27 17:11:23 -0700) | 11 | tcg: Update docs/devel/tcg-ops.rst for temporary changes (2023-02-28 10:36:19 -1000) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | Improvements to qemu/int128 | 14 | helper-head: Add fpu/softfloat-types.h |
15 | Fixes for 128/64 division. | 15 | softmmu: Use memmove in flatview_write_continue |
16 | Cleanup tcg/optimize.c | 16 | tcg: Add sign param to probe_access_flags, probe_access_full |
17 | Optimize redundant sign extensions | 17 | tcg: Convert TARGET_TB_PCREL to CF_PCREL |
18 | tcg: Simplify temporary lifetimes for translators | ||
18 | 19 | ||
19 | ---------------------------------------------------------------- | 20 | ---------------------------------------------------------------- |
20 | Frédéric Pétrot (1): | 21 | Akihiko Odaki (1): |
21 | qemu/int128: Add int128_{not,xor} | 22 | softmmu: Use memmove in flatview_write_continue |
22 | 23 | ||
23 | Luis Pires (4): | 24 | Anton Johansson via (27): |
24 | host-utils: move checks out of divu128/divs128 | 25 | include/exec: Introduce `CF_PCREL` |
25 | host-utils: move udiv_qrnnd() to host-utils | 26 | target/i386: set `CF_PCREL` in `x86_cpu_realizefn` |
26 | host-utils: add 128-bit quotient support to divu128/divs128 | 27 | target/arm: set `CF_PCREL` in `arm_cpu_realizefn` |
27 | host-utils: add unit tests for divu128/divs128 | 28 | accel/tcg: Replace `TARGET_TB_PCREL` with `CF_PCREL` |
29 | include/exec: Replace `TARGET_TB_PCREL` with `CF_PCREL` | ||
30 | target/arm: Replace `TARGET_TB_PCREL` with `CF_PCREL` | ||
31 | target/i386: Replace `TARGET_TB_PCREL` with `CF_PCREL` | ||
32 | include/exec: Remove `TARGET_TB_PCREL` define | ||
33 | target/arm: Remove `TARGET_TB_PCREL` define | ||
34 | target/i386: Remove `TARGET_TB_PCREL` define | ||
35 | accel/tcg: Move jmp-cache `CF_PCREL` checks to caller | ||
36 | accel/tcg: Replace `tb_pc()` with `tb->pc` | ||
37 | target/tricore: Replace `tb_pc()` with `tb->pc` | ||
38 | target/sparc: Replace `tb_pc()` with `tb->pc` | ||
39 | target/sh4: Replace `tb_pc()` with `tb->pc` | ||
40 | target/rx: Replace `tb_pc()` with `tb->pc` | ||
41 | target/riscv: Replace `tb_pc()` with `tb->pc` | ||
42 | target/openrisc: Replace `tb_pc()` with `tb->pc` | ||
43 | target/mips: Replace `tb_pc()` with `tb->pc` | ||
44 | target/microblaze: Replace `tb_pc()` with `tb->pc` | ||
45 | target/loongarch: Replace `tb_pc()` with `tb->pc` | ||
46 | target/i386: Replace `tb_pc()` with `tb->pc` | ||
47 | target/hppa: Replace `tb_pc()` with `tb->pc` | ||
48 | target/hexagon: Replace `tb_pc()` with `tb->pc` | ||
49 | target/avr: Replace `tb_pc()` with `tb->pc` | ||
50 | target/arm: Replace `tb_pc()` with `tb->pc` | ||
51 | include/exec: Remove `tb_pc()` | ||
28 | 52 | ||
29 | Richard Henderson (51): | 53 | Daniel Henrique Barboza (1): |
30 | tcg/optimize: Rename "mask" to "z_mask" | 54 | accel/tcg: Add 'size' param to probe_access_flags() |
31 | tcg/optimize: Split out OptContext | ||
32 | tcg/optimize: Remove do_default label | ||
33 | tcg/optimize: Change tcg_opt_gen_{mov,movi} interface | ||
34 | tcg/optimize: Move prev_mb into OptContext | ||
35 | tcg/optimize: Split out init_arguments | ||
36 | tcg/optimize: Split out copy_propagate | ||
37 | tcg/optimize: Split out fold_call | ||
38 | tcg/optimize: Drop nb_oargs, nb_iargs locals | ||
39 | tcg/optimize: Change fail return for do_constant_folding_cond* | ||
40 | tcg/optimize: Return true from tcg_opt_gen_{mov,movi} | ||
41 | tcg/optimize: Split out finish_folding | ||
42 | tcg/optimize: Use a boolean to avoid a mass of continues | ||
43 | tcg/optimize: Split out fold_mb, fold_qemu_{ld,st} | ||
44 | tcg/optimize: Split out fold_const{1,2} | ||
45 | tcg/optimize: Split out fold_setcond2 | ||
46 | tcg/optimize: Split out fold_brcond2 | ||
47 | tcg/optimize: Split out fold_brcond | ||
48 | tcg/optimize: Split out fold_setcond | ||
49 | tcg/optimize: Split out fold_mulu2_i32 | ||
50 | tcg/optimize: Split out fold_addsub2_i32 | ||
51 | tcg/optimize: Split out fold_movcond | ||
52 | tcg/optimize: Split out fold_extract2 | ||
53 | tcg/optimize: Split out fold_extract, fold_sextract | ||
54 | tcg/optimize: Split out fold_deposit | ||
55 | tcg/optimize: Split out fold_count_zeros | ||
56 | tcg/optimize: Split out fold_bswap | ||
57 | tcg/optimize: Split out fold_dup, fold_dup2 | ||
58 | tcg/optimize: Split out fold_mov | ||
59 | tcg/optimize: Split out fold_xx_to_i | ||
60 | tcg/optimize: Split out fold_xx_to_x | ||
61 | tcg/optimize: Split out fold_xi_to_i | ||
62 | tcg/optimize: Add type to OptContext | ||
63 | tcg/optimize: Split out fold_to_not | ||
64 | tcg/optimize: Split out fold_sub_to_neg | ||
65 | tcg/optimize: Split out fold_xi_to_x | ||
66 | tcg/optimize: Split out fold_ix_to_i | ||
67 | tcg/optimize: Split out fold_masks | ||
68 | tcg/optimize: Expand fold_mulu2_i32 to all 4-arg multiplies | ||
69 | tcg/optimize: Expand fold_addsub2_i32 to 64-bit ops | ||
70 | tcg/optimize: Sink commutative operand swapping into fold functions | ||
71 | tcg/optimize: Stop forcing z_mask to "garbage" for 32-bit values | ||
72 | tcg/optimize: Use fold_xx_to_i for orc | ||
73 | tcg/optimize: Use fold_xi_to_x for mul | ||
74 | tcg/optimize: Use fold_xi_to_x for div | ||
75 | tcg/optimize: Use fold_xx_to_i for rem | ||
76 | tcg/optimize: Optimize sign extensions | ||
77 | tcg/optimize: Propagate sign info for logical operations | ||
78 | tcg/optimize: Propagate sign info for setcond | ||
79 | tcg/optimize: Propagate sign info for bit counting | ||
80 | tcg/optimize: Propagate sign info for shifting | ||
81 | 55 | ||
82 | include/fpu/softfloat-macros.h | 82 -- | 56 | Philippe Mathieu-Daudé (1): |
83 | include/hw/clock.h | 5 +- | 57 | exec/helper-head: Include missing "fpu/softfloat-types.h" header |
84 | include/qemu/host-utils.h | 121 +- | ||
85 | include/qemu/int128.h | 20 + | ||
86 | target/ppc/int_helper.c | 23 +- | ||
87 | tcg/optimize.c | 2644 ++++++++++++++++++++++++---------------- | ||
88 | tests/unit/test-div128.c | 197 +++ | ||
89 | util/host-utils.c | 147 ++- | ||
90 | tests/unit/meson.build | 1 + | ||
91 | 9 files changed, 2053 insertions(+), 1187 deletions(-) | ||
92 | create mode 100644 tests/unit/test-div128.c | ||
93 | 58 | ||
59 | Richard Henderson (32): | ||
60 | accel/tcg: Add 'size' param to probe_access_full | ||
61 | tcg: Adjust TCGContext.temps_in_use check | ||
62 | accel/tcg: Pass max_insn to gen_intermediate_code by pointer | ||
63 | accel/tcg: Use more accurate max_insns for tb_overflow | ||
64 | tcg: Remove branch-to-next regardless of reference count | ||
65 | tcg: Rename TEMP_LOCAL to TEMP_TB | ||
66 | tcg: Use noinline for major tcg_gen_code subroutines | ||
67 | tcg: Add liveness_pass_0 | ||
68 | tcg: Remove TEMP_NORMAL | ||
69 | tcg: Pass TCGTempKind to tcg_temp_new_internal | ||
70 | tcg: Use tcg_constant_i32 in tcg_gen_io_start | ||
71 | tcg: Add tcg_gen_movi_ptr | ||
72 | tcg: Add tcg_temp_ebb_new_{i32,i64,ptr} | ||
73 | tcg: Use tcg_temp_ebb_new_* in tcg/ | ||
74 | tcg: Use tcg_constant_ptr in do_dup | ||
75 | accel/tcg/plugin: Use tcg_temp_ebb_* | ||
76 | accel/tcg/plugin: Tidy plugin_gen_disable_mem_helpers | ||
77 | tcg: Don't re-use TEMP_TB temporaries | ||
78 | tcg: Change default temp lifetime to TEMP_TB | ||
79 | target/arm: Drop copies in gen_sve_{ldr,str} | ||
80 | target/arm: Don't use tcg_temp_local_new_* | ||
81 | target/cris: Don't use tcg_temp_local_new | ||
82 | target/hexagon: Don't use tcg_temp_local_new_* | ||
83 | target/hexagon/idef-parser: Drop gen_tmp_local | ||
84 | target/hppa: Don't use tcg_temp_local_new | ||
85 | target/i386: Don't use tcg_temp_local_new | ||
86 | target/mips: Don't use tcg_temp_local_new | ||
87 | target/ppc: Don't use tcg_temp_local_new | ||
88 | target/xtensa: Don't use tcg_temp_local_new_* | ||
89 | exec/gen-icount: Don't use tcg_temp_local_new_i32 | ||
90 | tcg: Remove tcg_temp_local_new_*, tcg_const_local_* | ||
91 | tcg: Update docs/devel/tcg-ops.rst for temporary changes | ||
92 | |||
93 | docs/devel/tcg-ops.rst | 230 +++++++++++++---------- | ||
94 | target/hexagon/idef-parser/README.rst | 4 +- | ||
95 | accel/tcg/internal.h | 10 +- | ||
96 | accel/tcg/tb-jmp-cache.h | 42 +---- | ||
97 | include/exec/cpu-defs.h | 3 - | ||
98 | include/exec/exec-all.h | 26 +-- | ||
99 | include/exec/gen-icount.h | 12 +- | ||
100 | include/exec/helper-head.h | 2 + | ||
101 | include/exec/translator.h | 4 +- | ||
102 | include/tcg/tcg-op.h | 7 +- | ||
103 | include/tcg/tcg.h | 64 ++++--- | ||
104 | target/arm/cpu-param.h | 2 - | ||
105 | target/arm/tcg/translate-a64.h | 1 - | ||
106 | target/arm/tcg/translate.h | 2 +- | ||
107 | target/hexagon/gen_tcg.h | 4 +- | ||
108 | target/i386/cpu-param.h | 4 - | ||
109 | accel/stubs/tcg-stub.c | 2 +- | ||
110 | accel/tcg/cpu-exec.c | 62 ++++-- | ||
111 | accel/tcg/cputlb.c | 21 ++- | ||
112 | accel/tcg/perf.c | 2 +- | ||
113 | accel/tcg/plugin-gen.c | 32 ++-- | ||
114 | accel/tcg/tb-maint.c | 10 +- | ||
115 | accel/tcg/translate-all.c | 18 +- | ||
116 | accel/tcg/translator.c | 6 +- | ||
117 | accel/tcg/user-exec.c | 5 +- | ||
118 | semihosting/uaccess.c | 2 +- | ||
119 | softmmu/physmem.c | 2 +- | ||
120 | target/alpha/translate.c | 2 +- | ||
121 | target/arm/cpu.c | 17 +- | ||
122 | target/arm/ptw.c | 4 +- | ||
123 | target/arm/tcg/mte_helper.c | 4 +- | ||
124 | target/arm/tcg/sve_helper.c | 4 +- | ||
125 | target/arm/tcg/translate-a64.c | 16 +- | ||
126 | target/arm/tcg/translate-sve.c | 38 +--- | ||
127 | target/arm/tcg/translate.c | 14 +- | ||
128 | target/avr/cpu.c | 3 +- | ||
129 | target/avr/translate.c | 2 +- | ||
130 | target/cris/translate.c | 8 +- | ||
131 | target/hexagon/cpu.c | 4 +- | ||
132 | target/hexagon/genptr.c | 16 +- | ||
133 | target/hexagon/idef-parser/parser-helpers.c | 26 +-- | ||
134 | target/hexagon/translate.c | 4 +- | ||
135 | target/hppa/cpu.c | 8 +- | ||
136 | target/hppa/translate.c | 5 +- | ||
137 | target/i386/cpu.c | 5 + | ||
138 | target/i386/helper.c | 2 +- | ||
139 | target/i386/tcg/sysemu/excp_helper.c | 4 +- | ||
140 | target/i386/tcg/tcg-cpu.c | 8 +- | ||
141 | target/i386/tcg/translate.c | 55 +++--- | ||
142 | target/loongarch/cpu.c | 6 +- | ||
143 | target/loongarch/translate.c | 2 +- | ||
144 | target/m68k/translate.c | 2 +- | ||
145 | target/microblaze/cpu.c | 4 +- | ||
146 | target/microblaze/translate.c | 2 +- | ||
147 | target/mips/tcg/exception.c | 3 +- | ||
148 | target/mips/tcg/sysemu/special_helper.c | 2 +- | ||
149 | target/mips/tcg/translate.c | 59 ++---- | ||
150 | target/nios2/translate.c | 2 +- | ||
151 | target/openrisc/cpu.c | 4 +- | ||
152 | target/openrisc/translate.c | 2 +- | ||
153 | target/ppc/translate.c | 8 +- | ||
154 | target/riscv/cpu.c | 7 +- | ||
155 | target/riscv/translate.c | 2 +- | ||
156 | target/rx/cpu.c | 3 +- | ||
157 | target/rx/translate.c | 2 +- | ||
158 | target/s390x/tcg/mem_helper.c | 2 +- | ||
159 | target/s390x/tcg/translate.c | 2 +- | ||
160 | target/sh4/cpu.c | 6 +- | ||
161 | target/sh4/translate.c | 2 +- | ||
162 | target/sparc/cpu.c | 4 +- | ||
163 | target/sparc/translate.c | 2 +- | ||
164 | target/tricore/cpu.c | 3 +- | ||
165 | target/tricore/translate.c | 2 +- | ||
166 | target/xtensa/translate.c | 18 +- | ||
167 | tcg/optimize.c | 2 +- | ||
168 | tcg/tcg-op-gvec.c | 189 ++++++++++--------- | ||
169 | tcg/tcg-op.c | 258 ++++++++++++------------- | ||
170 | tcg/tcg.c | 280 ++++++++++++++++------------ | ||
171 | target/cris/translate_v10.c.inc | 10 +- | ||
172 | target/mips/tcg/nanomips_translate.c.inc | 4 +- | ||
173 | target/ppc/translate/spe-impl.c.inc | 8 +- | ||
174 | target/ppc/translate/vmx-impl.c.inc | 4 +- | ||
175 | target/hexagon/README | 8 +- | ||
176 | target/hexagon/gen_tcg_funcs.py | 18 +- | ||
177 | 84 files changed, 870 insertions(+), 890 deletions(-) | ||
178 | diff view generated by jsdifflib |
1 | Most of these are handled by creating a fold_const2_commutative | 1 | From: Philippe Mathieu-Daudé <philmd@linaro.org> |
---|---|---|---|
2 | to handle all of the binary operators. The rest were already | ||
3 | handled on a case-by-case basis in the switch, and have their | ||
4 | own fold function in which to place the call. | ||
5 | 2 | ||
6 | We now have only one major switch on TCGOpcode. | 3 | 'dh_ctype_f32' is defined as 'float32', itself declared |
4 | in "fpu/softfloat-types.h". Include this header to avoid | ||
5 | when refactoring other headers: | ||
7 | 6 | ||
8 | Introduce NO_DEST and a block comment for swap_commutative in | 7 | In file included from include/exec/helper-proto.h:7, |
9 | order to make the handling of brcond and movcond opcodes cleaner. | 8 | from include/tcg/tcg-op.h:29, |
9 | from ../../tcg/tcg-op-vec.c:22: | ||
10 | include/exec/helper-head.h:44:22: error: unknown type name ‘float32’; did you mean ‘_Float32’? | ||
11 | 44 | #define dh_ctype_f32 float32 | ||
12 | | ^~~~~~~ | ||
10 | 13 | ||
11 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | 14 | Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
15 | Message-Id: <20221216225202.25664-1-philmd@linaro.org> | ||
12 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 16 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
13 | --- | 17 | --- |
14 | tcg/optimize.c | 142 ++++++++++++++++++++++++------------------------- | 18 | include/exec/helper-head.h | 2 ++ |
15 | 1 file changed, 70 insertions(+), 72 deletions(-) | 19 | 1 file changed, 2 insertions(+) |
16 | 20 | ||
17 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 21 | diff --git a/include/exec/helper-head.h b/include/exec/helper-head.h |
18 | index XXXXXXX..XXXXXXX 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/tcg/optimize.c | 23 | --- a/include/exec/helper-head.h |
20 | +++ b/tcg/optimize.c | 24 | +++ b/include/exec/helper-head.h |
21 | @@ -XXX,XX +XXX,XX @@ static int do_constant_folding_cond2(TCGArg *p1, TCGArg *p2, TCGCond c) | 25 | @@ -XXX,XX +XXX,XX @@ |
22 | return -1; | 26 | #ifndef EXEC_HELPER_HEAD_H |
23 | } | 27 | #define EXEC_HELPER_HEAD_H |
24 | 28 | ||
25 | +/** | 29 | +#include "fpu/softfloat-types.h" |
26 | + * swap_commutative: | ||
27 | + * @dest: TCGArg of the destination argument, or NO_DEST. | ||
28 | + * @p1: first paired argument | ||
29 | + * @p2: second paired argument | ||
30 | + * | ||
31 | + * If *@p1 is a constant and *@p2 is not, swap. | ||
32 | + * If *@p2 matches @dest, swap. | ||
33 | + * Return true if a swap was performed. | ||
34 | + */ | ||
35 | + | 30 | + |
36 | +#define NO_DEST temp_arg(NULL) | 31 | #define HELPER(name) glue(helper_, name) |
37 | + | 32 | |
38 | static bool swap_commutative(TCGArg dest, TCGArg *p1, TCGArg *p2) | 33 | /* Some types that make sense in C, but not for TCG. */ |
39 | { | ||
40 | TCGArg a1 = *p1, a2 = *p2; | ||
41 | @@ -XXX,XX +XXX,XX @@ static bool fold_const2(OptContext *ctx, TCGOp *op) | ||
42 | return false; | ||
43 | } | ||
44 | |||
45 | +static bool fold_const2_commutative(OptContext *ctx, TCGOp *op) | ||
46 | +{ | ||
47 | + swap_commutative(op->args[0], &op->args[1], &op->args[2]); | ||
48 | + return fold_const2(ctx, op); | ||
49 | +} | ||
50 | + | ||
51 | static bool fold_masks(OptContext *ctx, TCGOp *op) | ||
52 | { | ||
53 | uint64_t a_mask = ctx->a_mask; | ||
54 | @@ -XXX,XX +XXX,XX @@ static bool fold_xx_to_x(OptContext *ctx, TCGOp *op) | ||
55 | |||
56 | static bool fold_add(OptContext *ctx, TCGOp *op) | ||
57 | { | ||
58 | - if (fold_const2(ctx, op) || | ||
59 | + if (fold_const2_commutative(ctx, op) || | ||
60 | fold_xi_to_x(ctx, op, 0)) { | ||
61 | return true; | ||
62 | } | ||
63 | @@ -XXX,XX +XXX,XX @@ static bool fold_addsub2(OptContext *ctx, TCGOp *op, bool add) | ||
64 | |||
65 | static bool fold_add2(OptContext *ctx, TCGOp *op) | ||
66 | { | ||
67 | + /* Note that the high and low parts may be independently swapped. */ | ||
68 | + swap_commutative(op->args[0], &op->args[2], &op->args[4]); | ||
69 | + swap_commutative(op->args[1], &op->args[3], &op->args[5]); | ||
70 | + | ||
71 | return fold_addsub2(ctx, op, true); | ||
72 | } | ||
73 | |||
74 | @@ -XXX,XX +XXX,XX @@ static bool fold_and(OptContext *ctx, TCGOp *op) | ||
75 | { | ||
76 | uint64_t z1, z2; | ||
77 | |||
78 | - if (fold_const2(ctx, op) || | ||
79 | + if (fold_const2_commutative(ctx, op) || | ||
80 | fold_xi_to_i(ctx, op, 0) || | ||
81 | fold_xi_to_x(ctx, op, -1) || | ||
82 | fold_xx_to_x(ctx, op)) { | ||
83 | @@ -XXX,XX +XXX,XX @@ static bool fold_andc(OptContext *ctx, TCGOp *op) | ||
84 | static bool fold_brcond(OptContext *ctx, TCGOp *op) | ||
85 | { | ||
86 | TCGCond cond = op->args[2]; | ||
87 | - int i = do_constant_folding_cond(ctx->type, op->args[0], op->args[1], cond); | ||
88 | + int i; | ||
89 | |||
90 | + if (swap_commutative(NO_DEST, &op->args[0], &op->args[1])) { | ||
91 | + op->args[2] = cond = tcg_swap_cond(cond); | ||
92 | + } | ||
93 | + | ||
94 | + i = do_constant_folding_cond(ctx->type, op->args[0], op->args[1], cond); | ||
95 | if (i == 0) { | ||
96 | tcg_op_remove(ctx->tcg, op); | ||
97 | return true; | ||
98 | @@ -XXX,XX +XXX,XX @@ static bool fold_brcond(OptContext *ctx, TCGOp *op) | ||
99 | static bool fold_brcond2(OptContext *ctx, TCGOp *op) | ||
100 | { | ||
101 | TCGCond cond = op->args[4]; | ||
102 | - int i = do_constant_folding_cond2(&op->args[0], &op->args[2], cond); | ||
103 | TCGArg label = op->args[5]; | ||
104 | - int inv = 0; | ||
105 | + int i, inv = 0; | ||
106 | |||
107 | + if (swap_commutative2(&op->args[0], &op->args[2])) { | ||
108 | + op->args[4] = cond = tcg_swap_cond(cond); | ||
109 | + } | ||
110 | + | ||
111 | + i = do_constant_folding_cond2(&op->args[0], &op->args[2], cond); | ||
112 | if (i >= 0) { | ||
113 | goto do_brcond_const; | ||
114 | } | ||
115 | @@ -XXX,XX +XXX,XX @@ static bool fold_dup2(OptContext *ctx, TCGOp *op) | ||
116 | |||
117 | static bool fold_eqv(OptContext *ctx, TCGOp *op) | ||
118 | { | ||
119 | - if (fold_const2(ctx, op) || | ||
120 | + if (fold_const2_commutative(ctx, op) || | ||
121 | fold_xi_to_x(ctx, op, -1) || | ||
122 | fold_xi_to_not(ctx, op, 0)) { | ||
123 | return true; | ||
124 | @@ -XXX,XX +XXX,XX @@ static bool fold_mov(OptContext *ctx, TCGOp *op) | ||
125 | static bool fold_movcond(OptContext *ctx, TCGOp *op) | ||
126 | { | ||
127 | TCGCond cond = op->args[5]; | ||
128 | - int i = do_constant_folding_cond(ctx->type, op->args[1], op->args[2], cond); | ||
129 | + int i; | ||
130 | |||
131 | + if (swap_commutative(NO_DEST, &op->args[1], &op->args[2])) { | ||
132 | + op->args[5] = cond = tcg_swap_cond(cond); | ||
133 | + } | ||
134 | + /* | ||
135 | + * Canonicalize the "false" input reg to match the destination reg so | ||
136 | + * that the tcg backend can implement a "move if true" operation. | ||
137 | + */ | ||
138 | + if (swap_commutative(op->args[0], &op->args[4], &op->args[3])) { | ||
139 | + op->args[5] = cond = tcg_invert_cond(cond); | ||
140 | + } | ||
141 | + | ||
142 | + i = do_constant_folding_cond(ctx->type, op->args[1], op->args[2], cond); | ||
143 | if (i >= 0) { | ||
144 | return tcg_opt_gen_mov(ctx, op, op->args[0], op->args[4 - i]); | ||
145 | } | ||
146 | @@ -XXX,XX +XXX,XX @@ static bool fold_mul(OptContext *ctx, TCGOp *op) | ||
147 | |||
148 | static bool fold_mul_highpart(OptContext *ctx, TCGOp *op) | ||
149 | { | ||
150 | - if (fold_const2(ctx, op) || | ||
151 | + if (fold_const2_commutative(ctx, op) || | ||
152 | fold_xi_to_i(ctx, op, 0)) { | ||
153 | return true; | ||
154 | } | ||
155 | @@ -XXX,XX +XXX,XX @@ static bool fold_mul_highpart(OptContext *ctx, TCGOp *op) | ||
156 | |||
157 | static bool fold_multiply2(OptContext *ctx, TCGOp *op) | ||
158 | { | ||
159 | + swap_commutative(op->args[0], &op->args[2], &op->args[3]); | ||
160 | + | ||
161 | if (arg_is_const(op->args[2]) && arg_is_const(op->args[3])) { | ||
162 | uint64_t a = arg_info(op->args[2])->val; | ||
163 | uint64_t b = arg_info(op->args[3])->val; | ||
164 | @@ -XXX,XX +XXX,XX @@ static bool fold_multiply2(OptContext *ctx, TCGOp *op) | ||
165 | |||
166 | static bool fold_nand(OptContext *ctx, TCGOp *op) | ||
167 | { | ||
168 | - if (fold_const2(ctx, op) || | ||
169 | + if (fold_const2_commutative(ctx, op) || | ||
170 | fold_xi_to_not(ctx, op, -1)) { | ||
171 | return true; | ||
172 | } | ||
173 | @@ -XXX,XX +XXX,XX @@ static bool fold_neg(OptContext *ctx, TCGOp *op) | ||
174 | |||
175 | static bool fold_nor(OptContext *ctx, TCGOp *op) | ||
176 | { | ||
177 | - if (fold_const2(ctx, op) || | ||
178 | + if (fold_const2_commutative(ctx, op) || | ||
179 | fold_xi_to_not(ctx, op, 0)) { | ||
180 | return true; | ||
181 | } | ||
182 | @@ -XXX,XX +XXX,XX @@ static bool fold_not(OptContext *ctx, TCGOp *op) | ||
183 | |||
184 | static bool fold_or(OptContext *ctx, TCGOp *op) | ||
185 | { | ||
186 | - if (fold_const2(ctx, op) || | ||
187 | + if (fold_const2_commutative(ctx, op) || | ||
188 | fold_xi_to_x(ctx, op, 0) || | ||
189 | fold_xx_to_x(ctx, op)) { | ||
190 | return true; | ||
191 | @@ -XXX,XX +XXX,XX @@ static bool fold_remainder(OptContext *ctx, TCGOp *op) | ||
192 | static bool fold_setcond(OptContext *ctx, TCGOp *op) | ||
193 | { | ||
194 | TCGCond cond = op->args[3]; | ||
195 | - int i = do_constant_folding_cond(ctx->type, op->args[1], op->args[2], cond); | ||
196 | + int i; | ||
197 | |||
198 | + if (swap_commutative(op->args[0], &op->args[1], &op->args[2])) { | ||
199 | + op->args[3] = cond = tcg_swap_cond(cond); | ||
200 | + } | ||
201 | + | ||
202 | + i = do_constant_folding_cond(ctx->type, op->args[1], op->args[2], cond); | ||
203 | if (i >= 0) { | ||
204 | return tcg_opt_gen_movi(ctx, op, op->args[0], i); | ||
205 | } | ||
206 | @@ -XXX,XX +XXX,XX @@ static bool fold_setcond(OptContext *ctx, TCGOp *op) | ||
207 | static bool fold_setcond2(OptContext *ctx, TCGOp *op) | ||
208 | { | ||
209 | TCGCond cond = op->args[5]; | ||
210 | - int i = do_constant_folding_cond2(&op->args[1], &op->args[3], cond); | ||
211 | - int inv = 0; | ||
212 | + int i, inv = 0; | ||
213 | |||
214 | + if (swap_commutative2(&op->args[1], &op->args[3])) { | ||
215 | + op->args[5] = cond = tcg_swap_cond(cond); | ||
216 | + } | ||
217 | + | ||
218 | + i = do_constant_folding_cond2(&op->args[1], &op->args[3], cond); | ||
219 | if (i >= 0) { | ||
220 | goto do_setcond_const; | ||
221 | } | ||
222 | @@ -XXX,XX +XXX,XX @@ static bool fold_tcg_ld(OptContext *ctx, TCGOp *op) | ||
223 | |||
224 | static bool fold_xor(OptContext *ctx, TCGOp *op) | ||
225 | { | ||
226 | - if (fold_const2(ctx, op) || | ||
227 | + if (fold_const2_commutative(ctx, op) || | ||
228 | fold_xx_to_i(ctx, op, 0) || | ||
229 | fold_xi_to_x(ctx, op, 0) || | ||
230 | fold_xi_to_not(ctx, op, -1)) { | ||
231 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
232 | ctx.type = TCG_TYPE_I32; | ||
233 | } | ||
234 | |||
235 | - /* For commutative operations make constant second argument */ | ||
236 | - switch (opc) { | ||
237 | - CASE_OP_32_64_VEC(add): | ||
238 | - CASE_OP_32_64_VEC(mul): | ||
239 | - CASE_OP_32_64_VEC(and): | ||
240 | - CASE_OP_32_64_VEC(or): | ||
241 | - CASE_OP_32_64_VEC(xor): | ||
242 | - CASE_OP_32_64(eqv): | ||
243 | - CASE_OP_32_64(nand): | ||
244 | - CASE_OP_32_64(nor): | ||
245 | - CASE_OP_32_64(muluh): | ||
246 | - CASE_OP_32_64(mulsh): | ||
247 | - swap_commutative(op->args[0], &op->args[1], &op->args[2]); | ||
248 | - break; | ||
249 | - CASE_OP_32_64(brcond): | ||
250 | - if (swap_commutative(-1, &op->args[0], &op->args[1])) { | ||
251 | - op->args[2] = tcg_swap_cond(op->args[2]); | ||
252 | - } | ||
253 | - break; | ||
254 | - CASE_OP_32_64(setcond): | ||
255 | - if (swap_commutative(op->args[0], &op->args[1], &op->args[2])) { | ||
256 | - op->args[3] = tcg_swap_cond(op->args[3]); | ||
257 | - } | ||
258 | - break; | ||
259 | - CASE_OP_32_64(movcond): | ||
260 | - if (swap_commutative(-1, &op->args[1], &op->args[2])) { | ||
261 | - op->args[5] = tcg_swap_cond(op->args[5]); | ||
262 | - } | ||
263 | - /* For movcond, we canonicalize the "false" input reg to match | ||
264 | - the destination reg so that the tcg backend can implement | ||
265 | - a "move if true" operation. */ | ||
266 | - if (swap_commutative(op->args[0], &op->args[4], &op->args[3])) { | ||
267 | - op->args[5] = tcg_invert_cond(op->args[5]); | ||
268 | - } | ||
269 | - break; | ||
270 | - CASE_OP_32_64(add2): | ||
271 | - swap_commutative(op->args[0], &op->args[2], &op->args[4]); | ||
272 | - swap_commutative(op->args[1], &op->args[3], &op->args[5]); | ||
273 | - break; | ||
274 | - CASE_OP_32_64(mulu2): | ||
275 | - CASE_OP_32_64(muls2): | ||
276 | - swap_commutative(op->args[0], &op->args[2], &op->args[3]); | ||
277 | - break; | ||
278 | - case INDEX_op_brcond2_i32: | ||
279 | - if (swap_commutative2(&op->args[0], &op->args[2])) { | ||
280 | - op->args[4] = tcg_swap_cond(op->args[4]); | ||
281 | - } | ||
282 | - break; | ||
283 | - case INDEX_op_setcond2_i32: | ||
284 | - if (swap_commutative2(&op->args[1], &op->args[3])) { | ||
285 | - op->args[5] = tcg_swap_cond(op->args[5]); | ||
286 | - } | ||
287 | - break; | ||
288 | - default: | ||
289 | - break; | ||
290 | - } | ||
291 | - | ||
292 | /* Assume all bits affected, and no bits known zero. */ | ||
293 | ctx.a_mask = -1; | ||
294 | ctx.z_mask = -1; | ||
295 | -- | 34 | -- |
296 | 2.25.1 | 35 | 2.34.1 |
297 | 36 | ||
298 | 37 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Akihiko Odaki <akihiko.odaki@daynix.com> | ||
1 | 2 | ||
3 | We found a case where the source passed to flatview_write_continue() may | ||
4 | overlap with the destination when fuzzing igb, a new proposed network | ||
5 | device with sanitizers. | ||
6 | |||
7 | igb uses pci_dma_map() to get Tx packet, and pci_dma_write() to write Rx | ||
8 | buffer. While pci_dma_write() is usually used to write data from | ||
9 | memory not mapped to the guest, if igb is configured to perform | ||
10 | loopback, the data will be sourced from the guest memory. The source and | ||
11 | destination can overlap and the usage of memcpy() will be invalid in | ||
12 | such a case. | ||
13 | |||
14 | While we do not really have to deal with such an invalid request for | ||
15 | igb, detecting the overlap in igb code beforehand requires complex code, | ||
16 | and only covers this specific case. Instead, just replace memcpy() with | ||
17 | memmove() to tolerate overlaps. Using memmove() will slightly damage the | ||
18 | performance as it will need to check overlaps before using SIMD | ||
19 | instructions for copying, but the cost should be negligible, considering | ||
20 | the inherent complexity of flatview_write_continue(). | ||
21 | |||
22 | The test cases generated by the fuzzer is available at: | ||
23 | https://patchew.org/QEMU/20230129053316.1071513-1-alxndr@bu.edu/ | ||
24 | |||
25 | The fixed test case is: | ||
26 | fuzz/crash_47dfe62d9f911bf523ff48cd441b61c0013ed805 | ||
27 | |||
28 | Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com> | ||
29 | Acked-by: Alexander Bulekov <alxndr@bu.edu> | ||
30 | Acked-by: David Hildenbrand <david@redhat.com> | ||
31 | Message-Id: <20230131030155.18932-1-akihiko.odaki@daynix.com> | ||
32 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
33 | --- | ||
34 | softmmu/physmem.c | 2 +- | ||
35 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
36 | |||
37 | diff --git a/softmmu/physmem.c b/softmmu/physmem.c | ||
38 | index XXXXXXX..XXXXXXX 100644 | ||
39 | --- a/softmmu/physmem.c | ||
40 | +++ b/softmmu/physmem.c | ||
41 | @@ -XXX,XX +XXX,XX @@ static MemTxResult flatview_write_continue(FlatView *fv, hwaddr addr, | ||
42 | } else { | ||
43 | /* RAM case */ | ||
44 | ram_ptr = qemu_ram_ptr_length(mr->ram_block, addr1, &l, false); | ||
45 | - memcpy(ram_ptr, buf, l); | ||
46 | + memmove(ram_ptr, buf, l); | ||
47 | invalidate_and_set_dirty(mr, addr1, l); | ||
48 | } | ||
49 | |||
50 | -- | ||
51 | 2.34.1 | diff view generated by jsdifflib |
1 | Even though there is only one user, place this more complex | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | conversion into its own helper. | ||
3 | 2 | ||
4 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | 3 | probe_access_flags() as it is today uses probe_access_full(), which in |
4 | turn uses probe_access_internal() with size = 0. probe_access_internal() | ||
5 | then uses the size to call the tlb_fill() callback for the given CPU. | ||
6 | This size param ('fault_size' as probe_access_internal() calls it) is | ||
7 | ignored by most existing .tlb_fill callback implementations, e.g. | ||
8 | arm_cpu_tlb_fill(), ppc_cpu_tlb_fill(), x86_cpu_tlb_fill() and | ||
9 | mips_cpu_tlb_fill() to name a few. | ||
10 | |||
11 | But RISC-V riscv_cpu_tlb_fill() actually uses it. The 'size' parameter | ||
12 | is used to check for PMP (Physical Memory Protection) access. This is | ||
13 | necessary because PMP does not make any guarantees about all the bytes | ||
14 | of the same page having the same permissions, i.e. the same page can | ||
15 | have different PMP properties, so we're forced to make sub-page range | ||
16 | checks. To allow RISC-V emulation to do a probe_acess_flags() that | ||
17 | covers PMP, we need to either add a 'size' param to the existing | ||
18 | probe_acess_flags() or create a new interface (e.g. | ||
19 | probe_access_range_flags). | ||
20 | |||
21 | There are quite a few probe_* APIs already, so let's add a 'size' param | ||
22 | to probe_access_flags() and re-use this API. This is done by open coding | ||
23 | what probe_access_full() does inside probe_acess_flags() and passing the | ||
24 | 'size' param to probe_acess_internal(). Existing probe_access_flags() | ||
25 | callers use size = 0 to not change their current API usage. 'size' is | ||
26 | asserted to enforce single page access like probe_access() already does. | ||
27 | |||
28 | No behavioral changes intended. | ||
29 | |||
30 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
31 | Message-Id: <20230223234427.521114-2-dbarboza@ventanamicro.com> | ||
32 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 33 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
6 | --- | 34 | --- |
7 | tcg/optimize.c | 89 ++++++++++++++++++++++++++------------------------ | 35 | include/exec/exec-all.h | 3 ++- |
8 | 1 file changed, 47 insertions(+), 42 deletions(-) | 36 | accel/stubs/tcg-stub.c | 2 +- |
37 | accel/tcg/cputlb.c | 17 ++++++++++++++--- | ||
38 | accel/tcg/user-exec.c | 5 +++-- | ||
39 | semihosting/uaccess.c | 2 +- | ||
40 | target/arm/ptw.c | 2 +- | ||
41 | target/arm/tcg/sve_helper.c | 2 +- | ||
42 | target/s390x/tcg/mem_helper.c | 2 +- | ||
43 | 8 files changed, 24 insertions(+), 11 deletions(-) | ||
9 | 44 | ||
10 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 45 | diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h |
11 | index XXXXXXX..XXXXXXX 100644 | 46 | index XXXXXXX..XXXXXXX 100644 |
12 | --- a/tcg/optimize.c | 47 | --- a/include/exec/exec-all.h |
13 | +++ b/tcg/optimize.c | 48 | +++ b/include/exec/exec-all.h |
14 | @@ -XXX,XX +XXX,XX @@ static bool fold_nand(OptContext *ctx, TCGOp *op) | 49 | @@ -XXX,XX +XXX,XX @@ static inline void *probe_read(CPUArchState *env, target_ulong addr, int size, |
15 | 50 | * probe_access_flags: | |
16 | static bool fold_neg(OptContext *ctx, TCGOp *op) | 51 | * @env: CPUArchState |
52 | * @addr: guest virtual address to look up | ||
53 | + * @size: size of the access | ||
54 | * @access_type: read, write or execute permission | ||
55 | * @mmu_idx: MMU index to use for lookup | ||
56 | * @nonfault: suppress the fault | ||
57 | @@ -XXX,XX +XXX,XX @@ static inline void *probe_read(CPUArchState *env, target_ulong addr, int size, | ||
58 | * Do handle clean pages, so exclude TLB_NOTDIRY from the returned flags. | ||
59 | * For simplicity, all "mmio-like" flags are folded to TLB_MMIO. | ||
60 | */ | ||
61 | -int probe_access_flags(CPUArchState *env, target_ulong addr, | ||
62 | +int probe_access_flags(CPUArchState *env, target_ulong addr, int size, | ||
63 | MMUAccessType access_type, int mmu_idx, | ||
64 | bool nonfault, void **phost, uintptr_t retaddr); | ||
65 | |||
66 | diff --git a/accel/stubs/tcg-stub.c b/accel/stubs/tcg-stub.c | ||
67 | index XXXXXXX..XXXXXXX 100644 | ||
68 | --- a/accel/stubs/tcg-stub.c | ||
69 | +++ b/accel/stubs/tcg-stub.c | ||
70 | @@ -XXX,XX +XXX,XX @@ void tcg_flush_jmp_cache(CPUState *cpu) | ||
17 | { | 71 | { |
18 | - return fold_const1(ctx, op); | ||
19 | + if (fold_const1(ctx, op)) { | ||
20 | + return true; | ||
21 | + } | ||
22 | + /* | ||
23 | + * Because of fold_sub_to_neg, we want to always return true, | ||
24 | + * via finish_folding. | ||
25 | + */ | ||
26 | + finish_folding(ctx, op); | ||
27 | + return true; | ||
28 | } | 72 | } |
29 | 73 | ||
30 | static bool fold_nor(OptContext *ctx, TCGOp *op) | 74 | -int probe_access_flags(CPUArchState *env, target_ulong addr, |
31 | @@ -XXX,XX +XXX,XX @@ static bool fold_shift(OptContext *ctx, TCGOp *op) | 75 | +int probe_access_flags(CPUArchState *env, target_ulong addr, int size, |
32 | return fold_const2(ctx, op); | 76 | MMUAccessType access_type, int mmu_idx, |
77 | bool nonfault, void **phost, uintptr_t retaddr) | ||
78 | { | ||
79 | diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c | ||
80 | index XXXXXXX..XXXXXXX 100644 | ||
81 | --- a/accel/tcg/cputlb.c | ||
82 | +++ b/accel/tcg/cputlb.c | ||
83 | @@ -XXX,XX +XXX,XX @@ int probe_access_full(CPUArchState *env, target_ulong addr, | ||
84 | return flags; | ||
33 | } | 85 | } |
34 | 86 | ||
35 | +static bool fold_sub_to_neg(OptContext *ctx, TCGOp *op) | 87 | -int probe_access_flags(CPUArchState *env, target_ulong addr, |
36 | +{ | 88 | +int probe_access_flags(CPUArchState *env, target_ulong addr, int size, |
37 | + TCGOpcode neg_op; | 89 | MMUAccessType access_type, int mmu_idx, |
38 | + bool have_neg; | 90 | bool nonfault, void **phost, uintptr_t retaddr) |
91 | { | ||
92 | CPUTLBEntryFull *full; | ||
93 | + int flags; | ||
94 | |||
95 | - return probe_access_full(env, addr, access_type, mmu_idx, | ||
96 | - nonfault, phost, &full, retaddr); | ||
97 | + g_assert(-(addr | TARGET_PAGE_MASK) >= size); | ||
39 | + | 98 | + |
40 | + if (!arg_is_const(op->args[1]) || arg_info(op->args[1])->val != 0) { | 99 | + flags = probe_access_internal(env, addr, size, access_type, mmu_idx, |
41 | + return false; | 100 | + nonfault, phost, &full, retaddr); |
101 | + | ||
102 | + /* Handle clean RAM pages. */ | ||
103 | + if (unlikely(flags & TLB_NOTDIRTY)) { | ||
104 | + notdirty_write(env_cpu(env), addr, 1, full, retaddr); | ||
105 | + flags &= ~TLB_NOTDIRTY; | ||
42 | + } | 106 | + } |
43 | + | 107 | + |
44 | + switch (ctx->type) { | 108 | + return flags; |
45 | + case TCG_TYPE_I32: | 109 | } |
46 | + neg_op = INDEX_op_neg_i32; | 110 | |
47 | + have_neg = TCG_TARGET_HAS_neg_i32; | 111 | void *probe_access(CPUArchState *env, target_ulong addr, int size, |
48 | + break; | 112 | diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c |
49 | + case TCG_TYPE_I64: | 113 | index XXXXXXX..XXXXXXX 100644 |
50 | + neg_op = INDEX_op_neg_i64; | 114 | --- a/accel/tcg/user-exec.c |
51 | + have_neg = TCG_TARGET_HAS_neg_i64; | 115 | +++ b/accel/tcg/user-exec.c |
52 | + break; | 116 | @@ -XXX,XX +XXX,XX @@ static int probe_access_internal(CPUArchState *env, target_ulong addr, |
53 | + case TCG_TYPE_V64: | 117 | cpu_loop_exit_sigsegv(env_cpu(env), addr, access_type, maperr, ra); |
54 | + case TCG_TYPE_V128: | 118 | } |
55 | + case TCG_TYPE_V256: | 119 | |
56 | + neg_op = INDEX_op_neg_vec; | 120 | -int probe_access_flags(CPUArchState *env, target_ulong addr, |
57 | + have_neg = (TCG_TARGET_HAS_neg_vec && | 121 | +int probe_access_flags(CPUArchState *env, target_ulong addr, int size, |
58 | + tcg_can_emit_vec_op(neg_op, ctx->type, TCGOP_VECE(op)) > 0); | 122 | MMUAccessType access_type, int mmu_idx, |
59 | + break; | 123 | bool nonfault, void **phost, uintptr_t ra) |
60 | + default: | ||
61 | + g_assert_not_reached(); | ||
62 | + } | ||
63 | + if (have_neg) { | ||
64 | + op->opc = neg_op; | ||
65 | + op->args[1] = op->args[2]; | ||
66 | + return fold_neg(ctx, op); | ||
67 | + } | ||
68 | + return false; | ||
69 | +} | ||
70 | + | ||
71 | static bool fold_sub(OptContext *ctx, TCGOp *op) | ||
72 | { | 124 | { |
73 | if (fold_const2(ctx, op) || | 125 | int flags; |
74 | - fold_xx_to_i(ctx, op, 0)) { | 126 | |
75 | + fold_xx_to_i(ctx, op, 0) || | 127 | - flags = probe_access_internal(env, addr, 0, access_type, nonfault, ra); |
76 | + fold_sub_to_neg(ctx, op)) { | 128 | + g_assert(-(addr | TARGET_PAGE_MASK) >= size); |
77 | return true; | 129 | + flags = probe_access_internal(env, addr, size, access_type, nonfault, ra); |
78 | } | 130 | *phost = flags ? NULL : g2h(env_cpu(env), addr); |
79 | return false; | 131 | return flags; |
80 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | 132 | } |
81 | continue; | 133 | diff --git a/semihosting/uaccess.c b/semihosting/uaccess.c |
82 | } | 134 | index XXXXXXX..XXXXXXX 100644 |
83 | break; | 135 | --- a/semihosting/uaccess.c |
84 | - CASE_OP_32_64_VEC(sub): | 136 | +++ b/semihosting/uaccess.c |
85 | - { | 137 | @@ -XXX,XX +XXX,XX @@ ssize_t softmmu_strlen_user(CPUArchState *env, target_ulong addr) |
86 | - TCGOpcode neg_op; | 138 | /* Find the number of bytes remaining in the page. */ |
87 | - bool have_neg; | 139 | left_in_page = TARGET_PAGE_SIZE - (addr & ~TARGET_PAGE_MASK); |
88 | - | 140 | |
89 | - if (arg_is_const(op->args[2])) { | 141 | - flags = probe_access_flags(env, addr, MMU_DATA_LOAD, |
90 | - /* Proceed with possible constant folding. */ | 142 | + flags = probe_access_flags(env, addr, 0, MMU_DATA_LOAD, |
91 | - break; | 143 | mmu_idx, true, &h, 0); |
92 | - } | 144 | if (flags & TLB_INVALID_MASK) { |
93 | - switch (ctx.type) { | 145 | return -1; |
94 | - case TCG_TYPE_I32: | 146 | diff --git a/target/arm/ptw.c b/target/arm/ptw.c |
95 | - neg_op = INDEX_op_neg_i32; | 147 | index XXXXXXX..XXXXXXX 100644 |
96 | - have_neg = TCG_TARGET_HAS_neg_i32; | 148 | --- a/target/arm/ptw.c |
97 | - break; | 149 | +++ b/target/arm/ptw.c |
98 | - case TCG_TYPE_I64: | 150 | @@ -XXX,XX +XXX,XX @@ static uint64_t arm_casq_ptw(CPUARMState *env, uint64_t old_val, |
99 | - neg_op = INDEX_op_neg_i64; | 151 | void *discard; |
100 | - have_neg = TCG_TARGET_HAS_neg_i64; | 152 | |
101 | - break; | 153 | env->tlb_fi = fi; |
102 | - case TCG_TYPE_V64: | 154 | - flags = probe_access_flags(env, ptw->out_virt, MMU_DATA_STORE, |
103 | - case TCG_TYPE_V128: | 155 | + flags = probe_access_flags(env, ptw->out_virt, 0, MMU_DATA_STORE, |
104 | - case TCG_TYPE_V256: | 156 | arm_to_core_mmu_idx(ptw->in_ptw_idx), |
105 | - neg_op = INDEX_op_neg_vec; | 157 | true, &discard, 0); |
106 | - have_neg = tcg_can_emit_vec_op(neg_op, ctx.type, | 158 | env->tlb_fi = NULL; |
107 | - TCGOP_VECE(op)) > 0; | 159 | diff --git a/target/arm/tcg/sve_helper.c b/target/arm/tcg/sve_helper.c |
108 | - break; | 160 | index XXXXXXX..XXXXXXX 100644 |
109 | - default: | 161 | --- a/target/arm/tcg/sve_helper.c |
110 | - g_assert_not_reached(); | 162 | +++ b/target/arm/tcg/sve_helper.c |
111 | - } | 163 | @@ -XXX,XX +XXX,XX @@ bool sve_probe_page(SVEHostPage *info, bool nofault, CPUARMState *env, |
112 | - if (!have_neg) { | 164 | addr = useronly_clean_ptr(addr); |
113 | - break; | 165 | |
114 | - } | 166 | #ifdef CONFIG_USER_ONLY |
115 | - if (arg_is_const(op->args[1]) | 167 | - flags = probe_access_flags(env, addr, access_type, mmu_idx, nofault, |
116 | - && arg_info(op->args[1])->val == 0) { | 168 | + flags = probe_access_flags(env, addr, 0, access_type, mmu_idx, nofault, |
117 | - op->opc = neg_op; | 169 | &info->host, retaddr); |
118 | - reset_temp(op->args[0]); | 170 | #else |
119 | - op->args[1] = op->args[2]; | 171 | CPUTLBEntryFull *full; |
120 | - continue; | 172 | diff --git a/target/s390x/tcg/mem_helper.c b/target/s390x/tcg/mem_helper.c |
121 | - } | 173 | index XXXXXXX..XXXXXXX 100644 |
122 | - } | 174 | --- a/target/s390x/tcg/mem_helper.c |
123 | - break; | 175 | +++ b/target/s390x/tcg/mem_helper.c |
124 | default: | 176 | @@ -XXX,XX +XXX,XX @@ static inline int s390_probe_access(CPUArchState *env, target_ulong addr, |
125 | break; | 177 | int mmu_idx, bool nonfault, |
126 | } | 178 | void **phost, uintptr_t ra) |
179 | { | ||
180 | - int flags = probe_access_flags(env, addr, access_type, mmu_idx, | ||
181 | + int flags = probe_access_flags(env, addr, 0, access_type, mmu_idx, | ||
182 | nonfault, phost, ra); | ||
183 | |||
184 | if (unlikely(flags & TLB_INVALID_MASK)) { | ||
127 | -- | 185 | -- |
128 | 2.25.1 | 186 | 2.34.1 |
129 | |||
130 | diff view generated by jsdifflib |
1 | Pull the "op r, 0, b => movi r, 0" optimization into a function, | 1 | Change to match the recent change to probe_access_flags. |
---|---|---|---|
2 | and use it in fold_shift. | 2 | All existing callers updated to supply 0, so no change in behaviour. |
3 | 3 | ||
4 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | 4 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 5 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
7 | --- | 7 | --- |
8 | tcg/optimize.c | 28 ++++++++++------------------ | 8 | include/exec/exec-all.h | 2 +- |
9 | 1 file changed, 10 insertions(+), 18 deletions(-) | 9 | accel/tcg/cputlb.c | 4 ++-- |
10 | target/arm/ptw.c | 2 +- | ||
11 | target/arm/tcg/mte_helper.c | 4 ++-- | ||
12 | target/arm/tcg/sve_helper.c | 2 +- | ||
13 | target/arm/tcg/translate-a64.c | 2 +- | ||
14 | target/i386/tcg/sysemu/excp_helper.c | 4 ++-- | ||
15 | 7 files changed, 10 insertions(+), 10 deletions(-) | ||
10 | 16 | ||
11 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 17 | diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h |
12 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/tcg/optimize.c | 19 | --- a/include/exec/exec-all.h |
14 | +++ b/tcg/optimize.c | 20 | +++ b/include/exec/exec-all.h |
15 | @@ -XXX,XX +XXX,XX @@ static bool fold_to_not(OptContext *ctx, TCGOp *op, int idx) | 21 | @@ -XXX,XX +XXX,XX @@ int probe_access_flags(CPUArchState *env, target_ulong addr, int size, |
16 | return false; | 22 | * and must be consumed or copied immediately, before any further |
23 | * access or changes to TLB @mmu_idx. | ||
24 | */ | ||
25 | -int probe_access_full(CPUArchState *env, target_ulong addr, | ||
26 | +int probe_access_full(CPUArchState *env, target_ulong addr, int size, | ||
27 | MMUAccessType access_type, int mmu_idx, | ||
28 | bool nonfault, void **phost, | ||
29 | CPUTLBEntryFull **pfull, uintptr_t retaddr); | ||
30 | diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c | ||
31 | index XXXXXXX..XXXXXXX 100644 | ||
32 | --- a/accel/tcg/cputlb.c | ||
33 | +++ b/accel/tcg/cputlb.c | ||
34 | @@ -XXX,XX +XXX,XX @@ static int probe_access_internal(CPUArchState *env, target_ulong addr, | ||
35 | return flags; | ||
17 | } | 36 | } |
18 | 37 | ||
19 | +/* If the binary operation has first argument @i, fold to @i. */ | 38 | -int probe_access_full(CPUArchState *env, target_ulong addr, |
20 | +static bool fold_ix_to_i(OptContext *ctx, TCGOp *op, uint64_t i) | 39 | +int probe_access_full(CPUArchState *env, target_ulong addr, int size, |
21 | +{ | 40 | MMUAccessType access_type, int mmu_idx, |
22 | + if (arg_is_const(op->args[1]) && arg_info(op->args[1])->val == i) { | 41 | bool nonfault, void **phost, CPUTLBEntryFull **pfull, |
23 | + return tcg_opt_gen_movi(ctx, op, op->args[0], i); | 42 | uintptr_t retaddr) |
24 | + } | ||
25 | + return false; | ||
26 | +} | ||
27 | + | ||
28 | /* If the binary operation has first argument @i, fold to NOT. */ | ||
29 | static bool fold_ix_to_not(OptContext *ctx, TCGOp *op, uint64_t i) | ||
30 | { | 43 | { |
31 | @@ -XXX,XX +XXX,XX @@ static bool fold_sextract(OptContext *ctx, TCGOp *op) | 44 | - int flags = probe_access_internal(env, addr, 0, access_type, mmu_idx, |
32 | static bool fold_shift(OptContext *ctx, TCGOp *op) | 45 | + int flags = probe_access_internal(env, addr, size, access_type, mmu_idx, |
33 | { | 46 | nonfault, phost, pfull, retaddr); |
34 | if (fold_const2(ctx, op) || | 47 | |
35 | + fold_ix_to_i(ctx, op, 0) || | 48 | /* Handle clean RAM pages. */ |
36 | fold_xi_to_x(ctx, op, 0)) { | 49 | diff --git a/target/arm/ptw.c b/target/arm/ptw.c |
37 | return true; | 50 | index XXXXXXX..XXXXXXX 100644 |
51 | --- a/target/arm/ptw.c | ||
52 | +++ b/target/arm/ptw.c | ||
53 | @@ -XXX,XX +XXX,XX @@ static bool S1_ptw_translate(CPUARMState *env, S1Translate *ptw, | ||
54 | int flags; | ||
55 | |||
56 | env->tlb_fi = fi; | ||
57 | - flags = probe_access_full(env, addr, MMU_DATA_LOAD, | ||
58 | + flags = probe_access_full(env, addr, 0, MMU_DATA_LOAD, | ||
59 | arm_to_core_mmu_idx(s2_mmu_idx), | ||
60 | true, &ptw->out_host, &full, 0); | ||
61 | env->tlb_fi = NULL; | ||
62 | diff --git a/target/arm/tcg/mte_helper.c b/target/arm/tcg/mte_helper.c | ||
63 | index XXXXXXX..XXXXXXX 100644 | ||
64 | --- a/target/arm/tcg/mte_helper.c | ||
65 | +++ b/target/arm/tcg/mte_helper.c | ||
66 | @@ -XXX,XX +XXX,XX @@ static uint8_t *allocation_tag_mem(CPUARMState *env, int ptr_mmu_idx, | ||
67 | * valid. Indicate to probe_access_flags no-fault, then assert that | ||
68 | * we received a valid page. | ||
69 | */ | ||
70 | - flags = probe_access_full(env, ptr, ptr_access, ptr_mmu_idx, | ||
71 | + flags = probe_access_full(env, ptr, 0, ptr_access, ptr_mmu_idx, | ||
72 | ra == 0, &host, &full, ra); | ||
73 | assert(!(flags & TLB_INVALID_MASK)); | ||
74 | |||
75 | @@ -XXX,XX +XXX,XX @@ static uint8_t *allocation_tag_mem(CPUARMState *env, int ptr_mmu_idx, | ||
76 | */ | ||
77 | in_page = -(ptr | TARGET_PAGE_MASK); | ||
78 | if (unlikely(ptr_size > in_page)) { | ||
79 | - flags |= probe_access_full(env, ptr + in_page, ptr_access, | ||
80 | + flags |= probe_access_full(env, ptr + in_page, 0, ptr_access, | ||
81 | ptr_mmu_idx, ra == 0, &host, &full, ra); | ||
82 | assert(!(flags & TLB_INVALID_MASK)); | ||
38 | } | 83 | } |
39 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | 84 | diff --git a/target/arm/tcg/sve_helper.c b/target/arm/tcg/sve_helper.c |
40 | break; | 85 | index XXXXXXX..XXXXXXX 100644 |
41 | } | 86 | --- a/target/arm/tcg/sve_helper.c |
42 | 87 | +++ b/target/arm/tcg/sve_helper.c | |
43 | - /* Simplify expressions for "shift/rot r, 0, a => movi r, 0", | 88 | @@ -XXX,XX +XXX,XX @@ bool sve_probe_page(SVEHostPage *info, bool nofault, CPUARMState *env, |
44 | - and "sub r, 0, a => neg r, a" case. */ | 89 | &info->host, retaddr); |
45 | - switch (opc) { | 90 | #else |
46 | - CASE_OP_32_64(shl): | 91 | CPUTLBEntryFull *full; |
47 | - CASE_OP_32_64(shr): | 92 | - flags = probe_access_full(env, addr, access_type, mmu_idx, nofault, |
48 | - CASE_OP_32_64(sar): | 93 | + flags = probe_access_full(env, addr, 0, access_type, mmu_idx, nofault, |
49 | - CASE_OP_32_64(rotl): | 94 | &info->host, &full, retaddr); |
50 | - CASE_OP_32_64(rotr): | 95 | #endif |
51 | - if (arg_is_const(op->args[1]) | 96 | info->flags = flags; |
52 | - && arg_info(op->args[1])->val == 0) { | 97 | diff --git a/target/arm/tcg/translate-a64.c b/target/arm/tcg/translate-a64.c |
53 | - tcg_opt_gen_movi(&ctx, op, op->args[0], 0); | 98 | index XXXXXXX..XXXXXXX 100644 |
54 | - continue; | 99 | --- a/target/arm/tcg/translate-a64.c |
55 | - } | 100 | +++ b/target/arm/tcg/translate-a64.c |
56 | - break; | 101 | @@ -XXX,XX +XXX,XX @@ static bool is_guarded_page(CPUARMState *env, DisasContext *s) |
57 | - default: | 102 | * that the TLB entry must be present and valid, and thus this |
58 | - break; | 103 | * access will never raise an exception. |
59 | - } | 104 | */ |
60 | - | 105 | - flags = probe_access_full(env, addr, MMU_INST_FETCH, mmu_idx, |
61 | /* Simplify using known-zero bits. Currently only ops with a single | 106 | + flags = probe_access_full(env, addr, 0, MMU_INST_FETCH, mmu_idx, |
62 | output argument is supported. */ | 107 | false, &host, &full, 0); |
63 | z_mask = -1; | 108 | assert(!(flags & TLB_INVALID_MASK)); |
109 | |||
110 | diff --git a/target/i386/tcg/sysemu/excp_helper.c b/target/i386/tcg/sysemu/excp_helper.c | ||
111 | index XXXXXXX..XXXXXXX 100644 | ||
112 | --- a/target/i386/tcg/sysemu/excp_helper.c | ||
113 | +++ b/target/i386/tcg/sysemu/excp_helper.c | ||
114 | @@ -XXX,XX +XXX,XX @@ static bool ptw_translate(PTETranslate *inout, hwaddr addr) | ||
115 | int flags; | ||
116 | |||
117 | inout->gaddr = addr; | ||
118 | - flags = probe_access_full(inout->env, addr, MMU_DATA_STORE, | ||
119 | + flags = probe_access_full(inout->env, addr, 0, MMU_DATA_STORE, | ||
120 | inout->ptw_idx, true, &inout->haddr, &full, 0); | ||
121 | |||
122 | if (unlikely(flags & TLB_INVALID_MASK)) { | ||
123 | @@ -XXX,XX +XXX,XX @@ do_check_protect_pse36: | ||
124 | CPUTLBEntryFull *full; | ||
125 | int flags, nested_page_size; | ||
126 | |||
127 | - flags = probe_access_full(env, paddr, access_type, | ||
128 | + flags = probe_access_full(env, paddr, 0, access_type, | ||
129 | MMU_NESTED_IDX, true, | ||
130 | &pte_trans.haddr, &full, 0); | ||
131 | if (unlikely(flags & TLB_INVALID_MASK)) { | ||
64 | -- | 132 | -- |
65 | 2.25.1 | 133 | 2.34.1 |
66 | 134 | ||
67 | 135 | diff view generated by jsdifflib |
1 | Pull the "op r, a, 0 => movi r, 0" optimization into a function, | 1 | From: Anton Johansson via <qemu-devel@nongnu.org> |
---|---|---|---|
2 | and use it in the outer opcode fold functions. | ||
3 | 2 | ||
4 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | 3 | Adds a new field to TranslationBlock.cflags denoting whether or not the |
5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 4 | instructions of a given translation block are pc-relative. This field |
5 | aims to replace the macro `TARGET_TB_PCREL`. | ||
6 | |||
7 | Signed-off-by: Anton Johansson <anjo@rev.ng> | ||
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
9 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
10 | Message-Id: <20230227135202.9710-2-anjo@rev.ng> | ||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 11 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
7 | --- | 12 | --- |
8 | tcg/optimize.c | 38 ++++++++++++++++++++------------------ | 13 | include/exec/exec-all.h | 1 + |
9 | 1 file changed, 20 insertions(+), 18 deletions(-) | 14 | 1 file changed, 1 insertion(+) |
10 | 15 | ||
11 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 16 | diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h |
12 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/tcg/optimize.c | 18 | --- a/include/exec/exec-all.h |
14 | +++ b/tcg/optimize.c | 19 | +++ b/include/exec/exec-all.h |
15 | @@ -XXX,XX +XXX,XX @@ static bool fold_const2(OptContext *ctx, TCGOp *op) | 20 | @@ -XXX,XX +XXX,XX @@ struct TranslationBlock { |
16 | return false; | 21 | #define CF_INVALID 0x00040000 /* TB is stale. Set with @jmp_lock held */ |
17 | } | 22 | #define CF_PARALLEL 0x00080000 /* Generate code for a parallel context */ |
18 | 23 | #define CF_NOIRQ 0x00100000 /* Generate an uninterruptible TB */ | |
19 | +/* If the binary operation has second argument @i, fold to @i. */ | 24 | +#define CF_PCREL 0x00200000 /* Opcodes in TB are PC-relative */ |
20 | +static bool fold_xi_to_i(OptContext *ctx, TCGOp *op, uint64_t i) | 25 | #define CF_CLUSTER_MASK 0xff000000 /* Top 8 bits are cluster ID */ |
21 | +{ | 26 | #define CF_CLUSTER_SHIFT 24 |
22 | + if (arg_is_const(op->args[2]) && arg_info(op->args[2])->val == i) { | 27 | |
23 | + return tcg_opt_gen_movi(ctx, op, op->args[0], i); | ||
24 | + } | ||
25 | + return false; | ||
26 | +} | ||
27 | + | ||
28 | /* If the binary operation has both arguments equal, fold to @i. */ | ||
29 | static bool fold_xx_to_i(OptContext *ctx, TCGOp *op, uint64_t i) | ||
30 | { | ||
31 | @@ -XXX,XX +XXX,XX @@ static bool fold_add2_i32(OptContext *ctx, TCGOp *op) | ||
32 | static bool fold_and(OptContext *ctx, TCGOp *op) | ||
33 | { | ||
34 | if (fold_const2(ctx, op) || | ||
35 | + fold_xi_to_i(ctx, op, 0) || | ||
36 | fold_xx_to_x(ctx, op)) { | ||
37 | return true; | ||
38 | } | ||
39 | @@ -XXX,XX +XXX,XX @@ static bool fold_movcond(OptContext *ctx, TCGOp *op) | ||
40 | |||
41 | static bool fold_mul(OptContext *ctx, TCGOp *op) | ||
42 | { | ||
43 | - return fold_const2(ctx, op); | ||
44 | + if (fold_const2(ctx, op) || | ||
45 | + fold_xi_to_i(ctx, op, 0)) { | ||
46 | + return true; | ||
47 | + } | ||
48 | + return false; | ||
49 | } | ||
50 | |||
51 | static bool fold_mul_highpart(OptContext *ctx, TCGOp *op) | ||
52 | { | ||
53 | - return fold_const2(ctx, op); | ||
54 | + if (fold_const2(ctx, op) || | ||
55 | + fold_xi_to_i(ctx, op, 0)) { | ||
56 | + return true; | ||
57 | + } | ||
58 | + return false; | ||
59 | } | ||
60 | |||
61 | static bool fold_mulu2_i32(OptContext *ctx, TCGOp *op) | ||
62 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
63 | continue; | ||
64 | } | ||
65 | |||
66 | - /* Simplify expression for "op r, a, 0 => movi r, 0" cases */ | ||
67 | - switch (opc) { | ||
68 | - CASE_OP_32_64_VEC(and): | ||
69 | - CASE_OP_32_64_VEC(mul): | ||
70 | - CASE_OP_32_64(muluh): | ||
71 | - CASE_OP_32_64(mulsh): | ||
72 | - if (arg_is_const(op->args[2]) | ||
73 | - && arg_info(op->args[2])->val == 0) { | ||
74 | - tcg_opt_gen_movi(&ctx, op, op->args[0], 0); | ||
75 | - continue; | ||
76 | - } | ||
77 | - break; | ||
78 | - default: | ||
79 | - break; | ||
80 | - } | ||
81 | - | ||
82 | /* | ||
83 | * Process each opcode. | ||
84 | * Sorted alphabetically by opcode as much as possible. | ||
85 | -- | 28 | -- |
86 | 2.25.1 | 29 | 2.34.1 |
87 | 30 | ||
88 | 31 | diff view generated by jsdifflib |
1 | Pull the "op r, a, a => mov r, a" optimization into a function, | 1 | From: Anton Johansson via <qemu-devel@nongnu.org> |
---|---|---|---|
2 | and use it in the outer opcode fold functions. | ||
3 | 2 | ||
4 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | 3 | Signed-off-by: Anton Johansson <anjo@rev.ng> |
5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 4 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
5 | Message-Id: <20230227135202.9710-3-anjo@rev.ng> | ||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
7 | --- | 7 | --- |
8 | tcg/optimize.c | 39 ++++++++++++++++++++++++--------------- | 8 | target/i386/cpu.c | 5 +++++ |
9 | 1 file changed, 24 insertions(+), 15 deletions(-) | 9 | 1 file changed, 5 insertions(+) |
10 | 10 | ||
11 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 11 | diff --git a/target/i386/cpu.c b/target/i386/cpu.c |
12 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/tcg/optimize.c | 13 | --- a/target/i386/cpu.c |
14 | +++ b/tcg/optimize.c | 14 | +++ b/target/i386/cpu.c |
15 | @@ -XXX,XX +XXX,XX @@ static bool fold_xx_to_i(OptContext *ctx, TCGOp *op, uint64_t i) | 15 | @@ -XXX,XX +XXX,XX @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp) |
16 | return false; | 16 | static bool ht_warned; |
17 | } | 17 | unsigned requested_lbr_fmt; |
18 | 18 | ||
19 | +/* If the binary operation has both arguments equal, fold to identity. */ | 19 | + /* Use pc-relative instructions in system-mode */ |
20 | +static bool fold_xx_to_x(OptContext *ctx, TCGOp *op) | 20 | +#ifndef CONFIG_USER_ONLY |
21 | +{ | 21 | + cs->tcg_cflags |= CF_PCREL; |
22 | + if (args_are_copies(op->args[1], op->args[2])) { | 22 | +#endif |
23 | + return tcg_opt_gen_mov(ctx, op, op->args[0], op->args[1]); | ||
24 | + } | ||
25 | + return false; | ||
26 | +} | ||
27 | + | 23 | + |
28 | /* | 24 | if (cpu->apic_id == UNASSIGNED_APIC_ID) { |
29 | * These outermost fold_<op> functions are sorted alphabetically. | 25 | error_setg(errp, "apic-id property was not initialized properly"); |
30 | + * | 26 | return; |
31 | + * The ordering of the transformations should be: | ||
32 | + * 1) those that produce a constant | ||
33 | + * 2) those that produce a copy | ||
34 | + * 3) those that produce information about the result value. | ||
35 | */ | ||
36 | |||
37 | static bool fold_add(OptContext *ctx, TCGOp *op) | ||
38 | @@ -XXX,XX +XXX,XX @@ static bool fold_add2_i32(OptContext *ctx, TCGOp *op) | ||
39 | |||
40 | static bool fold_and(OptContext *ctx, TCGOp *op) | ||
41 | { | ||
42 | - return fold_const2(ctx, op); | ||
43 | + if (fold_const2(ctx, op) || | ||
44 | + fold_xx_to_x(ctx, op)) { | ||
45 | + return true; | ||
46 | + } | ||
47 | + return false; | ||
48 | } | ||
49 | |||
50 | static bool fold_andc(OptContext *ctx, TCGOp *op) | ||
51 | @@ -XXX,XX +XXX,XX @@ static bool fold_not(OptContext *ctx, TCGOp *op) | ||
52 | |||
53 | static bool fold_or(OptContext *ctx, TCGOp *op) | ||
54 | { | ||
55 | - return fold_const2(ctx, op); | ||
56 | + if (fold_const2(ctx, op) || | ||
57 | + fold_xx_to_x(ctx, op)) { | ||
58 | + return true; | ||
59 | + } | ||
60 | + return false; | ||
61 | } | ||
62 | |||
63 | static bool fold_orc(OptContext *ctx, TCGOp *op) | ||
64 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
65 | break; | ||
66 | } | ||
67 | |||
68 | - /* Simplify expression for "op r, a, a => mov r, a" cases */ | ||
69 | - switch (opc) { | ||
70 | - CASE_OP_32_64_VEC(or): | ||
71 | - CASE_OP_32_64_VEC(and): | ||
72 | - if (args_are_copies(op->args[1], op->args[2])) { | ||
73 | - tcg_opt_gen_mov(&ctx, op, op->args[0], op->args[1]); | ||
74 | - continue; | ||
75 | - } | ||
76 | - break; | ||
77 | - default: | ||
78 | - break; | ||
79 | - } | ||
80 | - | ||
81 | /* | ||
82 | * Process each opcode. | ||
83 | * Sorted alphabetically by opcode as much as possible. | ||
84 | -- | 27 | -- |
85 | 2.25.1 | 28 | 2.34.1 |
86 | 29 | ||
87 | 30 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Anton Johansson via <qemu-devel@nongnu.org> | ||
1 | 2 | ||
3 | Signed-off-by: Anton Johansson <anjo@rev.ng> | ||
4 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
5 | Message-Id: <20230227135202.9710-4-anjo@rev.ng> | ||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | --- | ||
8 | target/arm/cpu.c | 5 +++++ | ||
9 | 1 file changed, 5 insertions(+) | ||
10 | |||
11 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | ||
12 | index XXXXXXX..XXXXXXX 100644 | ||
13 | --- a/target/arm/cpu.c | ||
14 | +++ b/target/arm/cpu.c | ||
15 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) | ||
16 | Error *local_err = NULL; | ||
17 | bool no_aa32 = false; | ||
18 | |||
19 | + /* Use pc-relative instructions in system-mode */ | ||
20 | +#ifndef CONFIG_USER_ONLY | ||
21 | + cs->tcg_cflags |= CF_PCREL; | ||
22 | +#endif | ||
23 | + | ||
24 | /* If we needed to query the host kernel for the CPU features | ||
25 | * then it's possible that might have failed in the initfn, but | ||
26 | * this is the first point where we can report it. | ||
27 | -- | ||
28 | 2.34.1 | ||
29 | |||
30 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | From: Anton Johansson via <qemu-devel@nongnu.org> | |
2 | |||
3 | Signed-off-by: Anton Johansson <anjo@rev.ng> | ||
4 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
5 | Message-Id: <20230227135202.9710-5-anjo@rev.ng> | ||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | --- | ||
8 | accel/tcg/internal.h | 10 ++++---- | ||
9 | accel/tcg/tb-jmp-cache.h | 48 +++++++++++++++++++-------------------- | ||
10 | accel/tcg/cpu-exec.c | 8 +++---- | ||
11 | accel/tcg/perf.c | 2 +- | ||
12 | accel/tcg/tb-maint.c | 8 +++---- | ||
13 | accel/tcg/translate-all.c | 14 ++++++------ | ||
14 | 6 files changed, 44 insertions(+), 46 deletions(-) | ||
15 | |||
16 | diff --git a/accel/tcg/internal.h b/accel/tcg/internal.h | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/accel/tcg/internal.h | ||
19 | +++ b/accel/tcg/internal.h | ||
20 | @@ -XXX,XX +XXX,XX @@ void cpu_restore_state_from_tb(CPUState *cpu, TranslationBlock *tb, | ||
21 | /* Return the current PC from CPU, which may be cached in TB. */ | ||
22 | static inline target_ulong log_pc(CPUState *cpu, const TranslationBlock *tb) | ||
23 | { | ||
24 | -#if TARGET_TB_PCREL | ||
25 | - return cpu->cc->get_pc(cpu); | ||
26 | -#else | ||
27 | - return tb_pc(tb); | ||
28 | -#endif | ||
29 | + if (tb_cflags(tb) & CF_PCREL) { | ||
30 | + return cpu->cc->get_pc(cpu); | ||
31 | + } else { | ||
32 | + return tb_pc(tb); | ||
33 | + } | ||
34 | } | ||
35 | |||
36 | extern int64_t max_delay; | ||
37 | diff --git a/accel/tcg/tb-jmp-cache.h b/accel/tcg/tb-jmp-cache.h | ||
38 | index XXXXXXX..XXXXXXX 100644 | ||
39 | --- a/accel/tcg/tb-jmp-cache.h | ||
40 | +++ b/accel/tcg/tb-jmp-cache.h | ||
41 | @@ -XXX,XX +XXX,XX @@ | ||
42 | |||
43 | /* | ||
44 | * Accessed in parallel; all accesses to 'tb' must be atomic. | ||
45 | - * For TARGET_TB_PCREL, accesses to 'pc' must be protected by | ||
46 | - * a load_acquire/store_release to 'tb'. | ||
47 | + * For CF_PCREL, accesses to 'pc' must be protected by a | ||
48 | + * load_acquire/store_release to 'tb'. | ||
49 | */ | ||
50 | struct CPUJumpCache { | ||
51 | struct rcu_head rcu; | ||
52 | struct { | ||
53 | TranslationBlock *tb; | ||
54 | -#if TARGET_TB_PCREL | ||
55 | target_ulong pc; | ||
56 | -#endif | ||
57 | } array[TB_JMP_CACHE_SIZE]; | ||
58 | }; | ||
59 | |||
60 | static inline TranslationBlock * | ||
61 | -tb_jmp_cache_get_tb(CPUJumpCache *jc, uint32_t hash) | ||
62 | +tb_jmp_cache_get_tb(CPUJumpCache *jc, uint32_t cflags, uint32_t hash) | ||
63 | { | ||
64 | -#if TARGET_TB_PCREL | ||
65 | - /* Use acquire to ensure current load of pc from jc. */ | ||
66 | - return qatomic_load_acquire(&jc->array[hash].tb); | ||
67 | -#else | ||
68 | - /* Use rcu_read to ensure current load of pc from *tb. */ | ||
69 | - return qatomic_rcu_read(&jc->array[hash].tb); | ||
70 | -#endif | ||
71 | + if (cflags & CF_PCREL) { | ||
72 | + /* Use acquire to ensure current load of pc from jc. */ | ||
73 | + return qatomic_load_acquire(&jc->array[hash].tb); | ||
74 | + } else { | ||
75 | + /* Use rcu_read to ensure current load of pc from *tb. */ | ||
76 | + return qatomic_rcu_read(&jc->array[hash].tb); | ||
77 | + } | ||
78 | } | ||
79 | |||
80 | static inline target_ulong | ||
81 | tb_jmp_cache_get_pc(CPUJumpCache *jc, uint32_t hash, TranslationBlock *tb) | ||
82 | { | ||
83 | -#if TARGET_TB_PCREL | ||
84 | - return jc->array[hash].pc; | ||
85 | -#else | ||
86 | - return tb_pc(tb); | ||
87 | -#endif | ||
88 | + if (tb_cflags(tb) & CF_PCREL) { | ||
89 | + return jc->array[hash].pc; | ||
90 | + } else { | ||
91 | + return tb_pc(tb); | ||
92 | + } | ||
93 | } | ||
94 | |||
95 | static inline void | ||
96 | tb_jmp_cache_set(CPUJumpCache *jc, uint32_t hash, | ||
97 | TranslationBlock *tb, target_ulong pc) | ||
98 | { | ||
99 | -#if TARGET_TB_PCREL | ||
100 | - jc->array[hash].pc = pc; | ||
101 | - /* Use store_release on tb to ensure pc is written first. */ | ||
102 | - qatomic_store_release(&jc->array[hash].tb, tb); | ||
103 | -#else | ||
104 | - /* Use the pc value already stored in tb->pc. */ | ||
105 | - qatomic_set(&jc->array[hash].tb, tb); | ||
106 | -#endif | ||
107 | + if (tb_cflags(tb) & CF_PCREL) { | ||
108 | + jc->array[hash].pc = pc; | ||
109 | + /* Use store_release on tb to ensure pc is written first. */ | ||
110 | + qatomic_store_release(&jc->array[hash].tb, tb); | ||
111 | + } else{ | ||
112 | + /* Use the pc value already stored in tb->pc. */ | ||
113 | + qatomic_set(&jc->array[hash].tb, tb); | ||
114 | + } | ||
115 | } | ||
116 | |||
117 | #endif /* ACCEL_TCG_TB_JMP_CACHE_H */ | ||
118 | diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c | ||
119 | index XXXXXXX..XXXXXXX 100644 | ||
120 | --- a/accel/tcg/cpu-exec.c | ||
121 | +++ b/accel/tcg/cpu-exec.c | ||
122 | @@ -XXX,XX +XXX,XX @@ static bool tb_lookup_cmp(const void *p, const void *d) | ||
123 | const TranslationBlock *tb = p; | ||
124 | const struct tb_desc *desc = d; | ||
125 | |||
126 | - if ((TARGET_TB_PCREL || tb_pc(tb) == desc->pc) && | ||
127 | + if ((tb_cflags(tb) & CF_PCREL || tb_pc(tb) == desc->pc) && | ||
128 | tb_page_addr0(tb) == desc->page_addr0 && | ||
129 | tb->cs_base == desc->cs_base && | ||
130 | tb->flags == desc->flags && | ||
131 | @@ -XXX,XX +XXX,XX @@ static TranslationBlock *tb_htable_lookup(CPUState *cpu, target_ulong pc, | ||
132 | return NULL; | ||
133 | } | ||
134 | desc.page_addr0 = phys_pc; | ||
135 | - h = tb_hash_func(phys_pc, (TARGET_TB_PCREL ? 0 : pc), | ||
136 | + h = tb_hash_func(phys_pc, (cflags & CF_PCREL ? 0 : pc), | ||
137 | flags, cflags, *cpu->trace_dstate); | ||
138 | return qht_lookup_custom(&tb_ctx.htable, &desc, h, tb_lookup_cmp); | ||
139 | } | ||
140 | @@ -XXX,XX +XXX,XX @@ static inline TranslationBlock *tb_lookup(CPUState *cpu, target_ulong pc, | ||
141 | |||
142 | hash = tb_jmp_cache_hash_func(pc); | ||
143 | jc = cpu->tb_jmp_cache; | ||
144 | - tb = tb_jmp_cache_get_tb(jc, hash); | ||
145 | + tb = tb_jmp_cache_get_tb(jc, cflags, hash); | ||
146 | |||
147 | if (likely(tb && | ||
148 | tb_jmp_cache_get_pc(jc, hash, tb) == pc && | ||
149 | @@ -XXX,XX +XXX,XX @@ cpu_tb_exec(CPUState *cpu, TranslationBlock *itb, int *tb_exit) | ||
150 | if (cc->tcg_ops->synchronize_from_tb) { | ||
151 | cc->tcg_ops->synchronize_from_tb(cpu, last_tb); | ||
152 | } else { | ||
153 | - assert(!TARGET_TB_PCREL); | ||
154 | + tcg_debug_assert(!(tb_cflags(last_tb) & CF_PCREL)); | ||
155 | assert(cc->set_pc); | ||
156 | cc->set_pc(cpu, tb_pc(last_tb)); | ||
157 | } | ||
158 | diff --git a/accel/tcg/perf.c b/accel/tcg/perf.c | ||
159 | index XXXXXXX..XXXXXXX 100644 | ||
160 | --- a/accel/tcg/perf.c | ||
161 | +++ b/accel/tcg/perf.c | ||
162 | @@ -XXX,XX +XXX,XX @@ void perf_report_code(uint64_t guest_pc, TranslationBlock *tb, | ||
163 | for (insn = 0; insn < tb->icount; insn++) { | ||
164 | /* FIXME: This replicates the restore_state_to_opc() logic. */ | ||
165 | q[insn].address = tcg_ctx->gen_insn_data[insn][0]; | ||
166 | - if (TARGET_TB_PCREL) { | ||
167 | + if (tb_cflags(tb) & CF_PCREL) { | ||
168 | q[insn].address |= (guest_pc & TARGET_PAGE_MASK); | ||
169 | } else { | ||
170 | #if defined(TARGET_I386) | ||
171 | diff --git a/accel/tcg/tb-maint.c b/accel/tcg/tb-maint.c | ||
172 | index XXXXXXX..XXXXXXX 100644 | ||
173 | --- a/accel/tcg/tb-maint.c | ||
174 | +++ b/accel/tcg/tb-maint.c | ||
175 | @@ -XXX,XX +XXX,XX @@ static bool tb_cmp(const void *ap, const void *bp) | ||
176 | const TranslationBlock *a = ap; | ||
177 | const TranslationBlock *b = bp; | ||
178 | |||
179 | - return ((TARGET_TB_PCREL || tb_pc(a) == tb_pc(b)) && | ||
180 | + return ((tb_cflags(a) & CF_PCREL || tb_pc(a) == tb_pc(b)) && | ||
181 | a->cs_base == b->cs_base && | ||
182 | a->flags == b->flags && | ||
183 | (tb_cflags(a) & ~CF_INVALID) == (tb_cflags(b) & ~CF_INVALID) && | ||
184 | @@ -XXX,XX +XXX,XX @@ static void tb_jmp_cache_inval_tb(TranslationBlock *tb) | ||
185 | { | ||
186 | CPUState *cpu; | ||
187 | |||
188 | - if (TARGET_TB_PCREL) { | ||
189 | + if (tb_cflags(tb) & CF_PCREL) { | ||
190 | /* A TB may be at any virtual address */ | ||
191 | CPU_FOREACH(cpu) { | ||
192 | tcg_flush_jmp_cache(cpu); | ||
193 | @@ -XXX,XX +XXX,XX @@ static void do_tb_phys_invalidate(TranslationBlock *tb, bool rm_from_page_list) | ||
194 | |||
195 | /* remove the TB from the hash list */ | ||
196 | phys_pc = tb_page_addr0(tb); | ||
197 | - h = tb_hash_func(phys_pc, (TARGET_TB_PCREL ? 0 : tb_pc(tb)), | ||
198 | + h = tb_hash_func(phys_pc, (orig_cflags & CF_PCREL ? 0 : tb_pc(tb)), | ||
199 | tb->flags, orig_cflags, tb->trace_vcpu_dstate); | ||
200 | if (!qht_remove(&tb_ctx.htable, tb, h)) { | ||
201 | return; | ||
202 | @@ -XXX,XX +XXX,XX @@ TranslationBlock *tb_link_page(TranslationBlock *tb, tb_page_addr_t phys_pc, | ||
203 | tb_record(tb, p, p2); | ||
204 | |||
205 | /* add in the hash table */ | ||
206 | - h = tb_hash_func(phys_pc, (TARGET_TB_PCREL ? 0 : tb_pc(tb)), | ||
207 | + h = tb_hash_func(phys_pc, (tb->cflags & CF_PCREL ? 0 : tb_pc(tb)), | ||
208 | tb->flags, tb->cflags, tb->trace_vcpu_dstate); | ||
209 | qht_insert(&tb_ctx.htable, tb, h, &existing_tb); | ||
210 | |||
211 | diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c | ||
212 | index XXXXXXX..XXXXXXX 100644 | ||
213 | --- a/accel/tcg/translate-all.c | ||
214 | +++ b/accel/tcg/translate-all.c | ||
215 | @@ -XXX,XX +XXX,XX @@ static int encode_search(TranslationBlock *tb, uint8_t *block) | ||
216 | |||
217 | for (j = 0; j < TARGET_INSN_START_WORDS; ++j) { | ||
218 | if (i == 0) { | ||
219 | - prev = (!TARGET_TB_PCREL && j == 0 ? tb_pc(tb) : 0); | ||
220 | + prev = (!(tb_cflags(tb) & CF_PCREL) && j == 0 ? tb_pc(tb) : 0); | ||
221 | } else { | ||
222 | prev = tcg_ctx->gen_insn_data[i - 1][j]; | ||
223 | } | ||
224 | @@ -XXX,XX +XXX,XX @@ static int cpu_unwind_data_from_tb(TranslationBlock *tb, uintptr_t host_pc, | ||
225 | } | ||
226 | |||
227 | memset(data, 0, sizeof(uint64_t) * TARGET_INSN_START_WORDS); | ||
228 | - if (!TARGET_TB_PCREL) { | ||
229 | + if (!(tb_cflags(tb) & CF_PCREL)) { | ||
230 | data[0] = tb_pc(tb); | ||
231 | } | ||
232 | |||
233 | @@ -XXX,XX +XXX,XX @@ TranslationBlock *tb_gen_code(CPUState *cpu, | ||
234 | |||
235 | gen_code_buf = tcg_ctx->code_gen_ptr; | ||
236 | tb->tc.ptr = tcg_splitwx_to_rx(gen_code_buf); | ||
237 | -#if !TARGET_TB_PCREL | ||
238 | - tb->pc = pc; | ||
239 | -#endif | ||
240 | + if (!(cflags & CF_PCREL)) { | ||
241 | + tb->pc = pc; | ||
242 | + } | ||
243 | tb->cs_base = cs_base; | ||
244 | tb->flags = flags; | ||
245 | tb->cflags = cflags; | ||
246 | @@ -XXX,XX +XXX,XX @@ TranslationBlock *tb_gen_code(CPUState *cpu, | ||
247 | tb->tc.size = gen_code_size; | ||
248 | |||
249 | /* | ||
250 | - * For TARGET_TB_PCREL, attribute all executions of the generated | ||
251 | - * code to its first mapping. | ||
252 | + * For CF_PCREL, attribute all executions of the generated code | ||
253 | + * to its first mapping. | ||
254 | */ | ||
255 | perf_report_code(pc, tb, tcg_splitwx_to_rx(gen_code_buf)); | ||
256 | |||
257 | -- | ||
258 | 2.34.1 | ||
259 | |||
260 | diff view generated by jsdifflib |
1 | This is the final entry in the main switch that was in a | 1 | From: Anton Johansson via <qemu-devel@nongnu.org> |
---|---|---|---|
2 | different form. After this, we have the option to convert | ||
3 | the switch into a function dispatch table. | ||
4 | 2 | ||
5 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | 3 | Signed-off-by: Anton Johansson <anjo@rev.ng> |
6 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 4 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
5 | Message-Id: <20230227135202.9710-6-anjo@rev.ng> | ||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
8 | --- | 7 | --- |
9 | tcg/optimize.c | 27 ++++++++++++++------------- | 8 | include/exec/exec-all.h | 27 +++++++++++---------------- |
10 | 1 file changed, 14 insertions(+), 13 deletions(-) | 9 | 1 file changed, 11 insertions(+), 16 deletions(-) |
11 | 10 | ||
12 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 11 | diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h |
13 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/tcg/optimize.c | 13 | --- a/include/exec/exec-all.h |
15 | +++ b/tcg/optimize.c | 14 | +++ b/include/exec/exec-all.h |
16 | @@ -XXX,XX +XXX,XX @@ static bool fold_mb(OptContext *ctx, TCGOp *op) | 15 | @@ -XXX,XX +XXX,XX @@ struct tb_tc { |
17 | return true; | 16 | }; |
17 | |||
18 | struct TranslationBlock { | ||
19 | -#if !TARGET_TB_PCREL | ||
20 | /* | ||
21 | * Guest PC corresponding to this block. This must be the true | ||
22 | * virtual address. Therefore e.g. x86 stores EIP + CS_BASE, and | ||
23 | * targets like Arm, MIPS, HP-PA, which reuse low bits for ISA or | ||
24 | * privilege, must store those bits elsewhere. | ||
25 | * | ||
26 | - * If TARGET_TB_PCREL, the opcodes for the TranslationBlock are | ||
27 | - * written such that the TB is associated only with the physical | ||
28 | - * page and may be run in any virtual address context. In this case, | ||
29 | - * PC must always be taken from ENV in a target-specific manner. | ||
30 | + * If CF_PCREL, the opcodes for the TranslationBlock are written | ||
31 | + * such that the TB is associated only with the physical page and | ||
32 | + * may be run in any virtual address context. In this case, PC | ||
33 | + * must always be taken from ENV in a target-specific manner. | ||
34 | * Unwind information is taken as offsets from the page, to be | ||
35 | * deposited into the "current" PC. | ||
36 | */ | ||
37 | target_ulong pc; | ||
38 | -#endif | ||
39 | |||
40 | /* | ||
41 | * Target-specific data associated with the TranslationBlock, e.g.: | ||
42 | @@ -XXX,XX +XXX,XX @@ struct TranslationBlock { | ||
43 | uintptr_t jmp_dest[2]; | ||
44 | }; | ||
45 | |||
46 | -/* Hide the read to avoid ifdefs for TARGET_TB_PCREL. */ | ||
47 | -static inline target_ulong tb_pc(const TranslationBlock *tb) | ||
48 | -{ | ||
49 | -#if TARGET_TB_PCREL | ||
50 | - qemu_build_not_reached(); | ||
51 | -#else | ||
52 | - return tb->pc; | ||
53 | -#endif | ||
54 | -} | ||
55 | - | ||
56 | /* Hide the qatomic_read to make code a little easier on the eyes */ | ||
57 | static inline uint32_t tb_cflags(const TranslationBlock *tb) | ||
58 | { | ||
59 | return qatomic_read(&tb->cflags); | ||
18 | } | 60 | } |
19 | 61 | ||
20 | +static bool fold_mov(OptContext *ctx, TCGOp *op) | 62 | +/* Hide the read to avoid ifdefs for CF_PCREL. */ |
63 | +static inline target_ulong tb_pc(const TranslationBlock *tb) | ||
21 | +{ | 64 | +{ |
22 | + return tcg_opt_gen_mov(ctx, op, op->args[0], op->args[1]); | 65 | + assert(!(tb_cflags(tb) & CF_PCREL)); |
66 | + return tb->pc; | ||
23 | +} | 67 | +} |
24 | + | 68 | + |
25 | static bool fold_movcond(OptContext *ctx, TCGOp *op) | 69 | static inline tb_page_addr_t tb_page_addr0(const TranslationBlock *tb) |
26 | { | 70 | { |
27 | TCGOpcode opc = op->opc; | 71 | #ifdef CONFIG_USER_ONLY |
28 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
29 | break; | ||
30 | } | ||
31 | |||
32 | - /* Propagate constants through copy operations and do constant | ||
33 | - folding. Constants will be substituted to arguments by register | ||
34 | - allocator where needed and possible. Also detect copies. */ | ||
35 | + /* | ||
36 | + * Process each opcode. | ||
37 | + * Sorted alphabetically by opcode as much as possible. | ||
38 | + */ | ||
39 | switch (opc) { | ||
40 | - CASE_OP_32_64_VEC(mov): | ||
41 | - done = tcg_opt_gen_mov(&ctx, op, op->args[0], op->args[1]); | ||
42 | - break; | ||
43 | - | ||
44 | - default: | ||
45 | - break; | ||
46 | - | ||
47 | - /* ---------------------------------------------------------- */ | ||
48 | - /* Sorted alphabetically by opcode as much as possible. */ | ||
49 | - | ||
50 | CASE_OP_32_64_VEC(add): | ||
51 | done = fold_add(&ctx, op); | ||
52 | break; | ||
53 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
54 | case INDEX_op_mb: | ||
55 | done = fold_mb(&ctx, op); | ||
56 | break; | ||
57 | + CASE_OP_32_64_VEC(mov): | ||
58 | + done = fold_mov(&ctx, op); | ||
59 | + break; | ||
60 | CASE_OP_32_64(movcond): | ||
61 | done = fold_movcond(&ctx, op); | ||
62 | break; | ||
63 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
64 | CASE_OP_32_64_VEC(xor): | ||
65 | done = fold_xor(&ctx, op); | ||
66 | break; | ||
67 | + default: | ||
68 | + break; | ||
69 | } | ||
70 | |||
71 | if (!done) { | ||
72 | -- | 72 | -- |
73 | 2.25.1 | 73 | 2.34.1 |
74 | 74 | ||
75 | 75 | diff view generated by jsdifflib |
1 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | 1 | From: Anton Johansson via <qemu-devel@nongnu.org> |
---|---|---|---|
2 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 2 | |
3 | Signed-off-by: Anton Johansson <anjo@rev.ng> | ||
4 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
5 | Message-Id: <20230227135202.9710-7-anjo@rev.ng> | ||
3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
4 | --- | 7 | --- |
5 | tcg/optimize.c | 53 +++++++++++++++++++++++++++++--------------------- | 8 | target/arm/tcg/translate.h | 2 +- |
6 | 1 file changed, 31 insertions(+), 22 deletions(-) | 9 | target/arm/cpu.c | 8 ++++---- |
10 | target/arm/tcg/translate-a64.c | 8 ++++---- | ||
11 | target/arm/tcg/translate.c | 6 +++--- | ||
12 | 4 files changed, 12 insertions(+), 12 deletions(-) | ||
7 | 13 | ||
8 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 14 | diff --git a/target/arm/tcg/translate.h b/target/arm/tcg/translate.h |
9 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
10 | --- a/tcg/optimize.c | 16 | --- a/target/arm/tcg/translate.h |
11 | +++ b/tcg/optimize.c | 17 | +++ b/target/arm/tcg/translate.h |
12 | @@ -XXX,XX +XXX,XX @@ static bool fold_divide(OptContext *ctx, TCGOp *op) | 18 | @@ -XXX,XX +XXX,XX @@ typedef struct DisasContext { |
13 | return fold_const2(ctx, op); | 19 | /* The address of the current instruction being translated. */ |
14 | } | 20 | target_ulong pc_curr; |
15 | 21 | /* | |
16 | +static bool fold_dup(OptContext *ctx, TCGOp *op) | 22 | - * For TARGET_TB_PCREL, the full value of cpu_pc is not known |
17 | +{ | 23 | + * For CF_PCREL, the full value of cpu_pc is not known |
18 | + if (arg_is_const(op->args[1])) { | 24 | * (although the page offset is known). For convenience, the |
19 | + uint64_t t = arg_info(op->args[1])->val; | 25 | * translation loop uses the full virtual address that triggered |
20 | + t = dup_const(TCGOP_VECE(op), t); | 26 | * the translation, from base.pc_start through pc_curr. |
21 | + return tcg_opt_gen_movi(ctx, op, op->args[0], t); | 27 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c |
22 | + } | 28 | index XXXXXXX..XXXXXXX 100644 |
23 | + return false; | 29 | --- a/target/arm/cpu.c |
24 | +} | 30 | +++ b/target/arm/cpu.c |
25 | + | 31 | @@ -XXX,XX +XXX,XX @@ static vaddr arm_cpu_get_pc(CPUState *cs) |
26 | +static bool fold_dup2(OptContext *ctx, TCGOp *op) | 32 | void arm_cpu_synchronize_from_tb(CPUState *cs, |
27 | +{ | 33 | const TranslationBlock *tb) |
28 | + if (arg_is_const(op->args[1]) && arg_is_const(op->args[2])) { | ||
29 | + uint64_t t = deposit64(arg_info(op->args[1])->val, 32, 32, | ||
30 | + arg_info(op->args[2])->val); | ||
31 | + return tcg_opt_gen_movi(ctx, op, op->args[0], t); | ||
32 | + } | ||
33 | + | ||
34 | + if (args_are_copies(op->args[1], op->args[2])) { | ||
35 | + op->opc = INDEX_op_dup_vec; | ||
36 | + TCGOP_VECE(op) = MO_32; | ||
37 | + } | ||
38 | + return false; | ||
39 | +} | ||
40 | + | ||
41 | static bool fold_eqv(OptContext *ctx, TCGOp *op) | ||
42 | { | 34 | { |
43 | return fold_const2(ctx, op); | 35 | - /* The program counter is always up to date with TARGET_TB_PCREL. */ |
44 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | 36 | - if (!TARGET_TB_PCREL) { |
45 | done = tcg_opt_gen_mov(&ctx, op, op->args[0], op->args[1]); | 37 | + /* The program counter is always up to date with CF_PCREL. */ |
46 | break; | 38 | + if (!(tb_cflags(tb) & CF_PCREL)) { |
47 | 39 | CPUARMState *env = cs->env_ptr; | |
48 | - case INDEX_op_dup_vec: | 40 | /* |
49 | - if (arg_is_const(op->args[1])) { | 41 | * It's OK to look at env for the current mode here, because it's |
50 | - tmp = arg_info(op->args[1])->val; | 42 | @@ -XXX,XX +XXX,XX @@ void arm_restore_state_to_opc(CPUState *cs, |
51 | - tmp = dup_const(TCGOP_VECE(op), tmp); | 43 | CPUARMState *env = cs->env_ptr; |
52 | - tcg_opt_gen_movi(&ctx, op, op->args[0], tmp); | 44 | |
53 | - continue; | 45 | if (is_a64(env)) { |
54 | - } | 46 | - if (TARGET_TB_PCREL) { |
55 | - break; | 47 | + if (tb_cflags(tb) & CF_PCREL) { |
56 | - | 48 | env->pc = (env->pc & TARGET_PAGE_MASK) | data[0]; |
57 | - case INDEX_op_dup2_vec: | 49 | } else { |
58 | - assert(TCG_TARGET_REG_BITS == 32); | 50 | env->pc = data[0]; |
59 | - if (arg_is_const(op->args[1]) && arg_is_const(op->args[2])) { | 51 | @@ -XXX,XX +XXX,XX @@ void arm_restore_state_to_opc(CPUState *cs, |
60 | - tcg_opt_gen_movi(&ctx, op, op->args[0], | 52 | env->condexec_bits = 0; |
61 | - deposit64(arg_info(op->args[1])->val, 32, 32, | 53 | env->exception.syndrome = data[2] << ARM_INSN_START_WORD2_SHIFT; |
62 | - arg_info(op->args[2])->val)); | 54 | } else { |
63 | - continue; | 55 | - if (TARGET_TB_PCREL) { |
64 | - } else if (args_are_copies(op->args[1], op->args[2])) { | 56 | + if (tb_cflags(tb) & CF_PCREL) { |
65 | - op->opc = INDEX_op_dup_vec; | 57 | env->regs[15] = (env->regs[15] & TARGET_PAGE_MASK) | data[0]; |
66 | - TCGOP_VECE(op) = MO_32; | 58 | } else { |
67 | - } | 59 | env->regs[15] = data[0]; |
68 | - break; | 60 | diff --git a/target/arm/tcg/translate-a64.c b/target/arm/tcg/translate-a64.c |
69 | - | 61 | index XXXXXXX..XXXXXXX 100644 |
70 | default: | 62 | --- a/target/arm/tcg/translate-a64.c |
71 | break; | 63 | +++ b/target/arm/tcg/translate-a64.c |
72 | 64 | @@ -XXX,XX +XXX,XX @@ static void reset_btype(DisasContext *s) | |
73 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | 65 | static void gen_pc_plus_diff(DisasContext *s, TCGv_i64 dest, target_long diff) |
74 | CASE_OP_32_64(divu): | 66 | { |
75 | done = fold_divide(&ctx, op); | 67 | assert(s->pc_save != -1); |
76 | break; | 68 | - if (TARGET_TB_PCREL) { |
77 | + case INDEX_op_dup_vec: | 69 | + if (tb_cflags(s->base.tb) & CF_PCREL) { |
78 | + done = fold_dup(&ctx, op); | 70 | tcg_gen_addi_i64(dest, cpu_pc, (s->pc_curr - s->pc_save) + diff); |
79 | + break; | 71 | } else { |
80 | + case INDEX_op_dup2_vec: | 72 | tcg_gen_movi_i64(dest, s->pc_curr + diff); |
81 | + done = fold_dup2(&ctx, op); | 73 | @@ -XXX,XX +XXX,XX @@ static void gen_goto_tb(DisasContext *s, int n, int64_t diff) |
82 | + break; | 74 | * update to pc to the unlinked path. A long chain of links |
83 | CASE_OP_32_64(eqv): | 75 | * can thus avoid many updates to the PC. |
84 | done = fold_eqv(&ctx, op); | 76 | */ |
85 | break; | 77 | - if (TARGET_TB_PCREL) { |
78 | + if (tb_cflags(s->base.tb) & CF_PCREL) { | ||
79 | gen_a64_update_pc(s, diff); | ||
80 | tcg_gen_goto_tb(n); | ||
81 | } else { | ||
82 | @@ -XXX,XX +XXX,XX @@ static void disas_pc_rel_adr(DisasContext *s, uint32_t insn) | ||
83 | if (page) { | ||
84 | /* ADRP (page based) */ | ||
85 | offset <<= 12; | ||
86 | - /* The page offset is ok for TARGET_TB_PCREL. */ | ||
87 | + /* The page offset is ok for CF_PCREL. */ | ||
88 | offset -= s->pc_curr & 0xfff; | ||
89 | } | ||
90 | |||
91 | @@ -XXX,XX +XXX,XX @@ static void aarch64_tr_insn_start(DisasContextBase *dcbase, CPUState *cpu) | ||
92 | DisasContext *dc = container_of(dcbase, DisasContext, base); | ||
93 | target_ulong pc_arg = dc->base.pc_next; | ||
94 | |||
95 | - if (TARGET_TB_PCREL) { | ||
96 | + if (tb_cflags(dcbase->tb) & CF_PCREL) { | ||
97 | pc_arg &= ~TARGET_PAGE_MASK; | ||
98 | } | ||
99 | tcg_gen_insn_start(pc_arg, 0, 0); | ||
100 | diff --git a/target/arm/tcg/translate.c b/target/arm/tcg/translate.c | ||
101 | index XXXXXXX..XXXXXXX 100644 | ||
102 | --- a/target/arm/tcg/translate.c | ||
103 | +++ b/target/arm/tcg/translate.c | ||
104 | @@ -XXX,XX +XXX,XX @@ static target_long jmp_diff(DisasContext *s, target_long diff) | ||
105 | static void gen_pc_plus_diff(DisasContext *s, TCGv_i32 var, target_long diff) | ||
106 | { | ||
107 | assert(s->pc_save != -1); | ||
108 | - if (TARGET_TB_PCREL) { | ||
109 | + if (tb_cflags(s->base.tb) & CF_PCREL) { | ||
110 | tcg_gen_addi_i32(var, cpu_R[15], (s->pc_curr - s->pc_save) + diff); | ||
111 | } else { | ||
112 | tcg_gen_movi_i32(var, s->pc_curr + diff); | ||
113 | @@ -XXX,XX +XXX,XX @@ static void gen_goto_tb(DisasContext *s, int n, target_long diff) | ||
114 | * update to pc to the unlinked path. A long chain of links | ||
115 | * can thus avoid many updates to the PC. | ||
116 | */ | ||
117 | - if (TARGET_TB_PCREL) { | ||
118 | + if (tb_cflags(s->base.tb) & CF_PCREL) { | ||
119 | gen_update_pc(s, diff); | ||
120 | tcg_gen_goto_tb(n); | ||
121 | } else { | ||
122 | @@ -XXX,XX +XXX,XX @@ static void arm_tr_insn_start(DisasContextBase *dcbase, CPUState *cpu) | ||
123 | uint32_t condexec_bits; | ||
124 | target_ulong pc_arg = dc->base.pc_next; | ||
125 | |||
126 | - if (TARGET_TB_PCREL) { | ||
127 | + if (tb_cflags(dcbase->tb) & CF_PCREL) { | ||
128 | pc_arg &= ~TARGET_PAGE_MASK; | ||
129 | } | ||
130 | if (dc->eci) { | ||
86 | -- | 131 | -- |
87 | 2.25.1 | 132 | 2.34.1 |
88 | 133 | ||
89 | 134 | diff view generated by jsdifflib |
1 | The result is either 0 or 1, which means that we have | 1 | From: Anton Johansson via <qemu-devel@nongnu.org> |
---|---|---|---|
2 | a 2 bit signed result, and thus 62 bits of sign. | ||
3 | For clarity, use the smask_from_zmask function. | ||
4 | 2 | ||
5 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 3 | Signed-off-by: Anton Johansson <anjo@rev.ng> |
6 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | 4 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
5 | Message-Id: <20230227135202.9710-8-anjo@rev.ng> | ||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
8 | --- | 7 | --- |
9 | tcg/optimize.c | 2 ++ | 8 | target/i386/helper.c | 2 +- |
10 | 1 file changed, 2 insertions(+) | 9 | target/i386/tcg/tcg-cpu.c | 6 +++--- |
10 | target/i386/tcg/translate.c | 26 +++++++++++++------------- | ||
11 | 3 files changed, 17 insertions(+), 17 deletions(-) | ||
11 | 12 | ||
12 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 13 | diff --git a/target/i386/helper.c b/target/i386/helper.c |
13 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/tcg/optimize.c | 15 | --- a/target/i386/helper.c |
15 | +++ b/tcg/optimize.c | 16 | +++ b/target/i386/helper.c |
16 | @@ -XXX,XX +XXX,XX @@ static bool fold_setcond(OptContext *ctx, TCGOp *op) | 17 | @@ -XXX,XX +XXX,XX @@ static inline target_ulong get_memio_eip(CPUX86State *env) |
17 | } | 18 | } |
18 | 19 | ||
19 | ctx->z_mask = 1; | 20 | /* Per x86_restore_state_to_opc. */ |
20 | + ctx->s_mask = smask_from_zmask(1); | 21 | - if (TARGET_TB_PCREL) { |
21 | return false; | 22 | + if (cs->tcg_cflags & CF_PCREL) { |
23 | return (env->eip & TARGET_PAGE_MASK) | data[0]; | ||
24 | } else { | ||
25 | return data[0] - env->segs[R_CS].base; | ||
26 | diff --git a/target/i386/tcg/tcg-cpu.c b/target/i386/tcg/tcg-cpu.c | ||
27 | index XXXXXXX..XXXXXXX 100644 | ||
28 | --- a/target/i386/tcg/tcg-cpu.c | ||
29 | +++ b/target/i386/tcg/tcg-cpu.c | ||
30 | @@ -XXX,XX +XXX,XX @@ static void x86_cpu_exec_exit(CPUState *cs) | ||
31 | static void x86_cpu_synchronize_from_tb(CPUState *cs, | ||
32 | const TranslationBlock *tb) | ||
33 | { | ||
34 | - /* The instruction pointer is always up to date with TARGET_TB_PCREL. */ | ||
35 | - if (!TARGET_TB_PCREL) { | ||
36 | + /* The instruction pointer is always up to date with CF_PCREL. */ | ||
37 | + if (!(tb_cflags(tb) & CF_PCREL)) { | ||
38 | CPUX86State *env = cs->env_ptr; | ||
39 | env->eip = tb_pc(tb) - tb->cs_base; | ||
40 | } | ||
41 | @@ -XXX,XX +XXX,XX @@ static void x86_restore_state_to_opc(CPUState *cs, | ||
42 | CPUX86State *env = &cpu->env; | ||
43 | int cc_op = data[1]; | ||
44 | |||
45 | - if (TARGET_TB_PCREL) { | ||
46 | + if (tb_cflags(tb) & CF_PCREL) { | ||
47 | env->eip = (env->eip & TARGET_PAGE_MASK) | data[0]; | ||
48 | } else { | ||
49 | env->eip = data[0] - tb->cs_base; | ||
50 | diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c | ||
51 | index XXXXXXX..XXXXXXX 100644 | ||
52 | --- a/target/i386/tcg/translate.c | ||
53 | +++ b/target/i386/tcg/translate.c | ||
54 | @@ -XXX,XX +XXX,XX @@ static inline void gen_op_st_rm_T0_A0(DisasContext *s, int idx, int d) | ||
55 | static void gen_update_eip_cur(DisasContext *s) | ||
56 | { | ||
57 | assert(s->pc_save != -1); | ||
58 | - if (TARGET_TB_PCREL) { | ||
59 | + if (tb_cflags(s->base.tb) & CF_PCREL) { | ||
60 | tcg_gen_addi_tl(cpu_eip, cpu_eip, s->base.pc_next - s->pc_save); | ||
61 | } else { | ||
62 | tcg_gen_movi_tl(cpu_eip, s->base.pc_next - s->cs_base); | ||
63 | @@ -XXX,XX +XXX,XX @@ static void gen_update_eip_cur(DisasContext *s) | ||
64 | static void gen_update_eip_next(DisasContext *s) | ||
65 | { | ||
66 | assert(s->pc_save != -1); | ||
67 | - if (TARGET_TB_PCREL) { | ||
68 | + if (tb_cflags(s->base.tb) & CF_PCREL) { | ||
69 | tcg_gen_addi_tl(cpu_eip, cpu_eip, s->pc - s->pc_save); | ||
70 | } else { | ||
71 | tcg_gen_movi_tl(cpu_eip, s->pc - s->cs_base); | ||
72 | @@ -XXX,XX +XXX,XX @@ static TCGv_i32 eip_next_i32(DisasContext *s) | ||
73 | if (CODE64(s)) { | ||
74 | return tcg_constant_i32(-1); | ||
75 | } | ||
76 | - if (TARGET_TB_PCREL) { | ||
77 | + if (tb_cflags(s->base.tb) & CF_PCREL) { | ||
78 | TCGv_i32 ret = tcg_temp_new_i32(); | ||
79 | tcg_gen_trunc_tl_i32(ret, cpu_eip); | ||
80 | tcg_gen_addi_i32(ret, ret, s->pc - s->pc_save); | ||
81 | @@ -XXX,XX +XXX,XX @@ static TCGv_i32 eip_next_i32(DisasContext *s) | ||
82 | static TCGv eip_next_tl(DisasContext *s) | ||
83 | { | ||
84 | assert(s->pc_save != -1); | ||
85 | - if (TARGET_TB_PCREL) { | ||
86 | + if (tb_cflags(s->base.tb) & CF_PCREL) { | ||
87 | TCGv ret = tcg_temp_new(); | ||
88 | tcg_gen_addi_tl(ret, cpu_eip, s->pc - s->pc_save); | ||
89 | return ret; | ||
90 | @@ -XXX,XX +XXX,XX @@ static TCGv eip_next_tl(DisasContext *s) | ||
91 | static TCGv eip_cur_tl(DisasContext *s) | ||
92 | { | ||
93 | assert(s->pc_save != -1); | ||
94 | - if (TARGET_TB_PCREL) { | ||
95 | + if (tb_cflags(s->base.tb) & CF_PCREL) { | ||
96 | TCGv ret = tcg_temp_new(); | ||
97 | tcg_gen_addi_tl(ret, cpu_eip, s->base.pc_next - s->pc_save); | ||
98 | return ret; | ||
99 | @@ -XXX,XX +XXX,XX @@ static void gen_rot_rm_T1(DisasContext *s, MemOp ot, int op1, int is_right) | ||
100 | tcg_temp_free_i32(t0); | ||
101 | tcg_temp_free_i32(t1); | ||
102 | |||
103 | - /* The CC_OP value is no longer predictable. */ | ||
104 | + /* The CC_OP value is no longer predictable. */ | ||
105 | set_cc_op(s, CC_OP_DYNAMIC); | ||
22 | } | 106 | } |
23 | 107 | ||
24 | @@ -XXX,XX +XXX,XX @@ static bool fold_setcond2(OptContext *ctx, TCGOp *op) | 108 | @@ -XXX,XX +XXX,XX @@ static void gen_rotc_rm_T1(DisasContext *s, MemOp ot, int op1, |
109 | gen_op_ld_v(s, ot, s->T0, s->A0); | ||
110 | else | ||
111 | gen_op_mov_v_reg(s, ot, s->T0, op1); | ||
112 | - | ||
113 | + | ||
114 | if (is_right) { | ||
115 | switch (ot) { | ||
116 | case MO_8: | ||
117 | @@ -XXX,XX +XXX,XX @@ static TCGv gen_lea_modrm_1(DisasContext *s, AddressParts a, bool is_vsib) | ||
118 | ea = cpu_regs[a.base]; | ||
25 | } | 119 | } |
26 | 120 | if (!ea) { | |
27 | ctx->z_mask = 1; | 121 | - if (TARGET_TB_PCREL && a.base == -2) { |
28 | + ctx->s_mask = smask_from_zmask(1); | 122 | + if (tb_cflags(s->base.tb) & CF_PCREL && a.base == -2) { |
29 | return false; | 123 | /* With cpu_eip ~= pc_save, the expression is pc-relative. */ |
30 | 124 | tcg_gen_addi_tl(s->A0, cpu_eip, a.disp - s->pc_save); | |
31 | do_setcond_const: | 125 | } else { |
126 | @@ -XXX,XX +XXX,XX @@ static void gen_jmp_rel(DisasContext *s, MemOp ot, int diff, int tb_num) | ||
127 | if (!CODE64(s)) { | ||
128 | if (ot == MO_16) { | ||
129 | mask = 0xffff; | ||
130 | - if (TARGET_TB_PCREL && CODE32(s)) { | ||
131 | + if (tb_cflags(s->base.tb) & CF_PCREL && CODE32(s)) { | ||
132 | use_goto_tb = false; | ||
133 | } | ||
134 | } else { | ||
135 | @@ -XXX,XX +XXX,XX @@ static void gen_jmp_rel(DisasContext *s, MemOp ot, int diff, int tb_num) | ||
136 | gen_update_cc_op(s); | ||
137 | set_cc_op(s, CC_OP_DYNAMIC); | ||
138 | |||
139 | - if (TARGET_TB_PCREL) { | ||
140 | + if (tb_cflags(s->base.tb) & CF_PCREL) { | ||
141 | tcg_gen_addi_tl(cpu_eip, cpu_eip, new_pc - s->pc_save); | ||
142 | /* | ||
143 | * If we can prove the branch does not leave the page and we have | ||
144 | @@ -XXX,XX +XXX,XX @@ static void gen_jmp_rel(DisasContext *s, MemOp ot, int diff, int tb_num) | ||
145 | translator_use_goto_tb(&s->base, new_eip + s->cs_base)) { | ||
146 | /* jump to same page: we can use a direct jump */ | ||
147 | tcg_gen_goto_tb(tb_num); | ||
148 | - if (!TARGET_TB_PCREL) { | ||
149 | + if (!(tb_cflags(s->base.tb) & CF_PCREL)) { | ||
150 | tcg_gen_movi_tl(cpu_eip, new_eip); | ||
151 | } | ||
152 | tcg_gen_exit_tb(s->base.tb, tb_num); | ||
153 | s->base.is_jmp = DISAS_NORETURN; | ||
154 | } else { | ||
155 | - if (!TARGET_TB_PCREL) { | ||
156 | + if (!(tb_cflags(s->base.tb) & CF_PCREL)) { | ||
157 | tcg_gen_movi_tl(cpu_eip, new_eip); | ||
158 | } | ||
159 | if (s->jmp_opt) { | ||
160 | @@ -XXX,XX +XXX,XX @@ static void i386_tr_insn_start(DisasContextBase *dcbase, CPUState *cpu) | ||
161 | target_ulong pc_arg = dc->base.pc_next; | ||
162 | |||
163 | dc->prev_insn_end = tcg_last_op(); | ||
164 | - if (TARGET_TB_PCREL) { | ||
165 | + if (tb_cflags(dcbase->tb) & CF_PCREL) { | ||
166 | pc_arg -= dc->cs_base; | ||
167 | pc_arg &= ~TARGET_PAGE_MASK; | ||
168 | } | ||
32 | -- | 169 | -- |
33 | 2.25.1 | 170 | 2.34.1 |
34 | 171 | ||
35 | 172 | diff view generated by jsdifflib |
1 | For constant shifts, we can simply shift the s_mask. | 1 | From: Anton Johansson via <qemu-devel@nongnu.org> |
---|---|---|---|
2 | 2 | ||
3 | For variable shifts, we know that sar does not reduce | 3 | Signed-off-by: Anton Johansson <anjo@rev.ng> |
4 | the s_mask, which helps for sequences like | 4 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
5 | 5 | Message-Id: <20230227135202.9710-9-anjo@rev.ng> | |
6 | ext32s_i64 t, in | ||
7 | sar_i64 t, t, v | ||
8 | ext32s_i64 out, t | ||
9 | |||
10 | allowing the final extend to be eliminated. | ||
11 | |||
12 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | ||
13 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | ||
14 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
15 | --- | 7 | --- |
16 | tcg/optimize.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++--- | 8 | include/exec/cpu-defs.h | 3 --- |
17 | 1 file changed, 47 insertions(+), 3 deletions(-) | 9 | 1 file changed, 3 deletions(-) |
18 | 10 | ||
19 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 11 | diff --git a/include/exec/cpu-defs.h b/include/exec/cpu-defs.h |
20 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/tcg/optimize.c | 13 | --- a/include/exec/cpu-defs.h |
22 | +++ b/tcg/optimize.c | 14 | +++ b/include/exec/cpu-defs.h |
23 | @@ -XXX,XX +XXX,XX @@ static uint64_t smask_from_zmask(uint64_t zmask) | 15 | @@ -XXX,XX +XXX,XX @@ |
24 | return ~(~0ull >> rep); | 16 | # error TARGET_PAGE_BITS must be defined in cpu-param.h |
25 | } | 17 | # endif |
26 | 18 | #endif | |
27 | +/* | 19 | -#ifndef TARGET_TB_PCREL |
28 | + * Recreate a properly left-aligned smask after manipulation. | 20 | -# define TARGET_TB_PCREL 0 |
29 | + * Some bit-shuffling, particularly shifts and rotates, may | 21 | -#endif |
30 | + * retain sign bits on the left, but may scatter disconnected | 22 | |
31 | + * sign bits on the right. Retain only what remains to the left. | 23 | #define TARGET_LONG_SIZE (TARGET_LONG_BITS / 8) |
32 | + */ | ||
33 | +static uint64_t smask_from_smask(int64_t smask) | ||
34 | +{ | ||
35 | + /* Only the 1 bits are significant for smask */ | ||
36 | + return smask_from_zmask(~smask); | ||
37 | +} | ||
38 | + | ||
39 | static inline TempOptInfo *ts_info(TCGTemp *ts) | ||
40 | { | ||
41 | return ts->state_ptr; | ||
42 | @@ -XXX,XX +XXX,XX @@ static bool fold_sextract(OptContext *ctx, TCGOp *op) | ||
43 | |||
44 | static bool fold_shift(OptContext *ctx, TCGOp *op) | ||
45 | { | ||
46 | + uint64_t s_mask, z_mask, sign; | ||
47 | + | ||
48 | if (fold_const2(ctx, op) || | ||
49 | fold_ix_to_i(ctx, op, 0) || | ||
50 | fold_xi_to_x(ctx, op, 0)) { | ||
51 | return true; | ||
52 | } | ||
53 | |||
54 | + s_mask = arg_info(op->args[1])->s_mask; | ||
55 | + z_mask = arg_info(op->args[1])->z_mask; | ||
56 | + | ||
57 | if (arg_is_const(op->args[2])) { | ||
58 | - ctx->z_mask = do_constant_folding(op->opc, ctx->type, | ||
59 | - arg_info(op->args[1])->z_mask, | ||
60 | - arg_info(op->args[2])->val); | ||
61 | + int sh = arg_info(op->args[2])->val; | ||
62 | + | ||
63 | + ctx->z_mask = do_constant_folding(op->opc, ctx->type, z_mask, sh); | ||
64 | + | ||
65 | + s_mask = do_constant_folding(op->opc, ctx->type, s_mask, sh); | ||
66 | + ctx->s_mask = smask_from_smask(s_mask); | ||
67 | + | ||
68 | return fold_masks(ctx, op); | ||
69 | } | ||
70 | + | ||
71 | + switch (op->opc) { | ||
72 | + CASE_OP_32_64(sar): | ||
73 | + /* | ||
74 | + * Arithmetic right shift will not reduce the number of | ||
75 | + * input sign repetitions. | ||
76 | + */ | ||
77 | + ctx->s_mask = s_mask; | ||
78 | + break; | ||
79 | + CASE_OP_32_64(shr): | ||
80 | + /* | ||
81 | + * If the sign bit is known zero, then logical right shift | ||
82 | + * will not reduced the number of input sign repetitions. | ||
83 | + */ | ||
84 | + sign = (s_mask & -s_mask) >> 1; | ||
85 | + if (!(z_mask & sign)) { | ||
86 | + ctx->s_mask = s_mask; | ||
87 | + } | ||
88 | + break; | ||
89 | + default: | ||
90 | + break; | ||
91 | + } | ||
92 | + | ||
93 | return false; | ||
94 | } | ||
95 | 24 | ||
96 | -- | 25 | -- |
97 | 2.25.1 | 26 | 2.34.1 |
98 | 27 | ||
99 | 28 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Anton Johansson via <qemu-devel@nongnu.org> | ||
1 | 2 | ||
3 | Signed-off-by: Anton Johansson <anjo@rev.ng> | ||
4 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
5 | Message-Id: <20230227135202.9710-10-anjo@rev.ng> | ||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | --- | ||
8 | target/arm/cpu-param.h | 2 -- | ||
9 | 1 file changed, 2 deletions(-) | ||
10 | |||
11 | diff --git a/target/arm/cpu-param.h b/target/arm/cpu-param.h | ||
12 | index XXXXXXX..XXXXXXX 100644 | ||
13 | --- a/target/arm/cpu-param.h | ||
14 | +++ b/target/arm/cpu-param.h | ||
15 | @@ -XXX,XX +XXX,XX @@ | ||
16 | # define TARGET_PAGE_BITS_VARY | ||
17 | # define TARGET_PAGE_BITS_MIN 10 | ||
18 | |||
19 | -# define TARGET_TB_PCREL 1 | ||
20 | - | ||
21 | /* | ||
22 | * Cache the attrs and shareability fields from the page table entry. | ||
23 | * | ||
24 | -- | ||
25 | 2.34.1 | ||
26 | |||
27 | diff view generated by jsdifflib |
1 | From: Luis Pires <luis.pires@eldorado.org.br> | 1 | From: Anton Johansson via <qemu-devel@nongnu.org> |
---|---|---|---|
2 | 2 | ||
3 | These will be used to implement new decimal floating point | 3 | Signed-off-by: Anton Johansson <anjo@rev.ng> |
4 | instructions from Power ISA 3.1. | 4 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
5 | 5 | Message-Id: <20230227135202.9710-11-anjo@rev.ng> | |
6 | The remainder is now returned directly by divu128/divs128, | ||
7 | freeing up phigh to receive the high 64 bits of the quotient. | ||
8 | |||
9 | Signed-off-by: Luis Pires <luis.pires@eldorado.org.br> | ||
10 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
11 | Message-Id: <20211025191154.350831-4-luis.pires@eldorado.org.br> | ||
12 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
13 | --- | 7 | --- |
14 | include/hw/clock.h | 6 +- | 8 | target/i386/cpu-param.h | 4 ---- |
15 | include/qemu/host-utils.h | 20 ++++-- | 9 | 1 file changed, 4 deletions(-) |
16 | target/ppc/int_helper.c | 9 +-- | ||
17 | util/host-utils.c | 133 +++++++++++++++++++++++++------------- | ||
18 | 4 files changed, 108 insertions(+), 60 deletions(-) | ||
19 | 10 | ||
20 | diff --git a/include/hw/clock.h b/include/hw/clock.h | 11 | diff --git a/target/i386/cpu-param.h b/target/i386/cpu-param.h |
21 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
22 | --- a/include/hw/clock.h | 13 | --- a/target/i386/cpu-param.h |
23 | +++ b/include/hw/clock.h | 14 | +++ b/target/i386/cpu-param.h |
24 | @@ -XXX,XX +XXX,XX @@ static inline uint64_t clock_ns_to_ticks(const Clock *clk, uint64_t ns) | 15 | @@ -XXX,XX +XXX,XX @@ |
25 | if (clk->period == 0) { | 16 | #define TARGET_PAGE_BITS 12 |
26 | return 0; | 17 | #define NB_MMU_MODES 5 |
27 | } | 18 | |
28 | - /* | 19 | -#ifndef CONFIG_USER_ONLY |
29 | - * BUG: when CONFIG_INT128 is not defined, the current implementation of | 20 | -# define TARGET_TB_PCREL 1 |
30 | - * divu128 does not return a valid truncated quotient, so the result will | 21 | -#endif |
31 | - * be wrong. | ||
32 | - */ | ||
33 | + | ||
34 | divu128(&lo, &hi, clk->period); | ||
35 | return lo; | ||
36 | } | ||
37 | diff --git a/include/qemu/host-utils.h b/include/qemu/host-utils.h | ||
38 | index XXXXXXX..XXXXXXX 100644 | ||
39 | --- a/include/qemu/host-utils.h | ||
40 | +++ b/include/qemu/host-utils.h | ||
41 | @@ -XXX,XX +XXX,XX @@ static inline uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c) | ||
42 | return (__int128_t)a * b / c; | ||
43 | } | ||
44 | |||
45 | -static inline void divu128(uint64_t *plow, uint64_t *phigh, uint64_t divisor) | ||
46 | +static inline uint64_t divu128(uint64_t *plow, uint64_t *phigh, | ||
47 | + uint64_t divisor) | ||
48 | { | ||
49 | __uint128_t dividend = ((__uint128_t)*phigh << 64) | *plow; | ||
50 | __uint128_t result = dividend / divisor; | ||
51 | + | ||
52 | *plow = result; | ||
53 | - *phigh = dividend % divisor; | ||
54 | + *phigh = result >> 64; | ||
55 | + return dividend % divisor; | ||
56 | } | ||
57 | |||
58 | -static inline void divs128(int64_t *plow, int64_t *phigh, int64_t divisor) | ||
59 | +static inline int64_t divs128(uint64_t *plow, int64_t *phigh, | ||
60 | + int64_t divisor) | ||
61 | { | ||
62 | - __int128_t dividend = ((__int128_t)*phigh << 64) | (uint64_t)*plow; | ||
63 | + __int128_t dividend = ((__int128_t)*phigh << 64) | *plow; | ||
64 | __int128_t result = dividend / divisor; | ||
65 | + | ||
66 | *plow = result; | ||
67 | - *phigh = dividend % divisor; | ||
68 | + *phigh = result >> 64; | ||
69 | + return dividend % divisor; | ||
70 | } | ||
71 | #else | ||
72 | void muls64(uint64_t *plow, uint64_t *phigh, int64_t a, int64_t b); | ||
73 | void mulu64(uint64_t *plow, uint64_t *phigh, uint64_t a, uint64_t b); | ||
74 | -void divu128(uint64_t *plow, uint64_t *phigh, uint64_t divisor); | ||
75 | -void divs128(int64_t *plow, int64_t *phigh, int64_t divisor); | ||
76 | +uint64_t divu128(uint64_t *plow, uint64_t *phigh, uint64_t divisor); | ||
77 | +int64_t divs128(uint64_t *plow, int64_t *phigh, int64_t divisor); | ||
78 | |||
79 | static inline uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c) | ||
80 | { | ||
81 | diff --git a/target/ppc/int_helper.c b/target/ppc/int_helper.c | ||
82 | index XXXXXXX..XXXXXXX 100644 | ||
83 | --- a/target/ppc/int_helper.c | ||
84 | +++ b/target/ppc/int_helper.c | ||
85 | @@ -XXX,XX +XXX,XX @@ uint64_t helper_divdeu(CPUPPCState *env, uint64_t ra, uint64_t rb, uint32_t oe) | ||
86 | |||
87 | uint64_t helper_divde(CPUPPCState *env, uint64_t rau, uint64_t rbu, uint32_t oe) | ||
88 | { | ||
89 | - int64_t rt = 0; | ||
90 | + uint64_t rt = 0; | ||
91 | int64_t ra = (int64_t)rau; | ||
92 | int64_t rb = (int64_t)rbu; | ||
93 | int overflow = 0; | ||
94 | @@ -XXX,XX +XXX,XX @@ uint32_t helper_bcdcfsq(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) | ||
95 | int cr; | ||
96 | uint64_t lo_value; | ||
97 | uint64_t hi_value; | ||
98 | + uint64_t rem; | ||
99 | ppc_avr_t ret = { .u64 = { 0, 0 } }; | ||
100 | |||
101 | if (b->VsrSD(0) < 0) { | ||
102 | @@ -XXX,XX +XXX,XX @@ uint32_t helper_bcdcfsq(ppc_avr_t *r, ppc_avr_t *b, uint32_t ps) | ||
103 | * In that case, we leave r unchanged. | ||
104 | */ | ||
105 | } else { | ||
106 | - divu128(&lo_value, &hi_value, 1000000000000000ULL); | ||
107 | + rem = divu128(&lo_value, &hi_value, 1000000000000000ULL); | ||
108 | |||
109 | - for (i = 1; i < 16; hi_value /= 10, i++) { | ||
110 | - bcd_put_digit(&ret, hi_value % 10, i); | ||
111 | + for (i = 1; i < 16; rem /= 10, i++) { | ||
112 | + bcd_put_digit(&ret, rem % 10, i); | ||
113 | } | ||
114 | |||
115 | for (; i < 32; lo_value /= 10, i++) { | ||
116 | diff --git a/util/host-utils.c b/util/host-utils.c | ||
117 | index XXXXXXX..XXXXXXX 100644 | ||
118 | --- a/util/host-utils.c | ||
119 | +++ b/util/host-utils.c | ||
120 | @@ -XXX,XX +XXX,XX @@ void muls64 (uint64_t *plow, uint64_t *phigh, int64_t a, int64_t b) | ||
121 | } | ||
122 | |||
123 | /* | ||
124 | - * Unsigned 128-by-64 division. Returns quotient via plow and | ||
125 | - * remainder via phigh. | ||
126 | - * The result must fit in 64 bits (plow) - otherwise, the result | ||
127 | - * is undefined. | ||
128 | - * This function will cause a division by zero if passed a zero divisor. | ||
129 | + * Unsigned 128-by-64 division. | ||
130 | + * Returns the remainder. | ||
131 | + * Returns quotient via plow and phigh. | ||
132 | + * Also returns the remainder via the function return value. | ||
133 | */ | ||
134 | -void divu128(uint64_t *plow, uint64_t *phigh, uint64_t divisor) | ||
135 | +uint64_t divu128(uint64_t *plow, uint64_t *phigh, uint64_t divisor) | ||
136 | { | ||
137 | uint64_t dhi = *phigh; | ||
138 | uint64_t dlo = *plow; | ||
139 | - unsigned i; | ||
140 | - uint64_t carry = 0; | ||
141 | + uint64_t rem, dhighest; | ||
142 | + int sh; | ||
143 | |||
144 | if (divisor == 0 || dhi == 0) { | ||
145 | *plow = dlo / divisor; | ||
146 | - *phigh = dlo % divisor; | ||
147 | + *phigh = 0; | ||
148 | + return dlo % divisor; | ||
149 | } else { | ||
150 | + sh = clz64(divisor); | ||
151 | |||
152 | - for (i = 0; i < 64; i++) { | ||
153 | - carry = dhi >> 63; | ||
154 | - dhi = (dhi << 1) | (dlo >> 63); | ||
155 | - if (carry || (dhi >= divisor)) { | ||
156 | - dhi -= divisor; | ||
157 | - carry = 1; | ||
158 | - } else { | ||
159 | - carry = 0; | ||
160 | + if (dhi < divisor) { | ||
161 | + if (sh != 0) { | ||
162 | + /* normalize the divisor, shifting the dividend accordingly */ | ||
163 | + divisor <<= sh; | ||
164 | + dhi = (dhi << sh) | (dlo >> (64 - sh)); | ||
165 | + dlo <<= sh; | ||
166 | } | ||
167 | - dlo = (dlo << 1) | carry; | ||
168 | + | ||
169 | + *phigh = 0; | ||
170 | + *plow = udiv_qrnnd(&rem, dhi, dlo, divisor); | ||
171 | + } else { | ||
172 | + if (sh != 0) { | ||
173 | + /* normalize the divisor, shifting the dividend accordingly */ | ||
174 | + divisor <<= sh; | ||
175 | + dhighest = dhi >> (64 - sh); | ||
176 | + dhi = (dhi << sh) | (dlo >> (64 - sh)); | ||
177 | + dlo <<= sh; | ||
178 | + | ||
179 | + *phigh = udiv_qrnnd(&dhi, dhighest, dhi, divisor); | ||
180 | + } else { | ||
181 | + /** | ||
182 | + * dhi >= divisor | ||
183 | + * Since the MSB of divisor is set (sh == 0), | ||
184 | + * (dhi - divisor) < divisor | ||
185 | + * | ||
186 | + * Thus, the high part of the quotient is 1, and we can | ||
187 | + * calculate the low part with a single call to udiv_qrnnd | ||
188 | + * after subtracting divisor from dhi | ||
189 | + */ | ||
190 | + dhi -= divisor; | ||
191 | + *phigh = 1; | ||
192 | + } | ||
193 | + | ||
194 | + *plow = udiv_qrnnd(&rem, dhi, dlo, divisor); | ||
195 | } | ||
196 | |||
197 | - *plow = dlo; | ||
198 | - *phigh = dhi; | ||
199 | + /* | ||
200 | + * since the dividend/divisor might have been normalized, | ||
201 | + * the remainder might also have to be shifted back | ||
202 | + */ | ||
203 | + return rem >> sh; | ||
204 | } | ||
205 | } | ||
206 | |||
207 | /* | ||
208 | - * Signed 128-by-64 division. Returns quotient via plow and | ||
209 | - * remainder via phigh. | ||
210 | - * The result must fit in 64 bits (plow) - otherwise, the result | ||
211 | - * is undefined. | ||
212 | - * This function will cause a division by zero if passed a zero divisor. | ||
213 | + * Signed 128-by-64 division. | ||
214 | + * Returns quotient via plow and phigh. | ||
215 | + * Also returns the remainder via the function return value. | ||
216 | */ | ||
217 | -void divs128(int64_t *plow, int64_t *phigh, int64_t divisor) | ||
218 | +int64_t divs128(uint64_t *plow, int64_t *phigh, int64_t divisor) | ||
219 | { | ||
220 | - int sgn_dvdnd = *phigh < 0; | ||
221 | - int sgn_divsr = divisor < 0; | ||
222 | + bool neg_quotient = false, neg_remainder = false; | ||
223 | + uint64_t unsig_hi = *phigh, unsig_lo = *plow; | ||
224 | + uint64_t rem; | ||
225 | |||
226 | - if (sgn_dvdnd) { | ||
227 | - *plow = ~(*plow); | ||
228 | - *phigh = ~(*phigh); | ||
229 | - if (*plow == (int64_t)-1) { | ||
230 | + if (*phigh < 0) { | ||
231 | + neg_quotient = !neg_quotient; | ||
232 | + neg_remainder = !neg_remainder; | ||
233 | + | ||
234 | + if (unsig_lo == 0) { | ||
235 | + unsig_hi = -unsig_hi; | ||
236 | + } else { | ||
237 | + unsig_hi = ~unsig_hi; | ||
238 | + unsig_lo = -unsig_lo; | ||
239 | + } | ||
240 | + } | ||
241 | + | ||
242 | + if (divisor < 0) { | ||
243 | + neg_quotient = !neg_quotient; | ||
244 | + | ||
245 | + divisor = -divisor; | ||
246 | + } | ||
247 | + | ||
248 | + rem = divu128(&unsig_lo, &unsig_hi, (uint64_t)divisor); | ||
249 | + | ||
250 | + if (neg_quotient) { | ||
251 | + if (unsig_lo == 0) { | ||
252 | + *phigh = -unsig_hi; | ||
253 | *plow = 0; | ||
254 | - (*phigh)++; | ||
255 | - } else { | ||
256 | - (*plow)++; | ||
257 | - } | ||
258 | + } else { | ||
259 | + *phigh = ~unsig_hi; | ||
260 | + *plow = -unsig_lo; | ||
261 | + } | ||
262 | + } else { | ||
263 | + *phigh = unsig_hi; | ||
264 | + *plow = unsig_lo; | ||
265 | } | ||
266 | |||
267 | - if (sgn_divsr) { | ||
268 | - divisor = 0 - divisor; | ||
269 | - } | ||
270 | - | 22 | - |
271 | - divu128((uint64_t *)plow, (uint64_t *)phigh, (uint64_t)divisor); | ||
272 | - | ||
273 | - if (sgn_dvdnd ^ sgn_divsr) { | ||
274 | - *plow = 0 - *plow; | ||
275 | + if (neg_remainder) { | ||
276 | + return -rem; | ||
277 | + } else { | ||
278 | + return rem; | ||
279 | } | ||
280 | } | ||
281 | #endif | 23 | #endif |
282 | -- | 24 | -- |
283 | 2.25.1 | 25 | 2.34.1 |
284 | 26 | ||
285 | 27 | diff view generated by jsdifflib |
1 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | 1 | From: Anton Johansson via <qemu-devel@nongnu.org> |
---|---|---|---|
2 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 2 | |
3 | tb-jmp-cache.h contains a few small functions that only exist to hide a | ||
4 | CF_PCREL check, however the caller often already performs such a check. | ||
5 | |||
6 | This patch moves CF_PCREL checks from the callee to the caller, and also | ||
7 | removes these functions which now only hide an access of the jmp-cache. | ||
8 | |||
9 | Signed-off-by: Anton Johansson <anjo@rev.ng> | ||
10 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
11 | Message-Id: <20230227135202.9710-12-anjo@rev.ng> | ||
3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 12 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
4 | --- | 13 | --- |
5 | tcg/optimize.c | 27 ++++++++++++++++----------- | 14 | accel/tcg/tb-jmp-cache.h | 36 --------------------------- |
6 | 1 file changed, 16 insertions(+), 11 deletions(-) | 15 | accel/tcg/cpu-exec.c | 54 +++++++++++++++++++++++++++++----------- |
16 | 2 files changed, 40 insertions(+), 50 deletions(-) | ||
7 | 17 | ||
8 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 18 | diff --git a/accel/tcg/tb-jmp-cache.h b/accel/tcg/tb-jmp-cache.h |
9 | index XXXXXXX..XXXXXXX 100644 | 19 | index XXXXXXX..XXXXXXX 100644 |
10 | --- a/tcg/optimize.c | 20 | --- a/accel/tcg/tb-jmp-cache.h |
11 | +++ b/tcg/optimize.c | 21 | +++ b/accel/tcg/tb-jmp-cache.h |
12 | @@ -XXX,XX +XXX,XX @@ static bool fold_brcond2(OptContext *ctx, TCGOp *op) | 22 | @@ -XXX,XX +XXX,XX @@ struct CPUJumpCache { |
13 | return false; | 23 | } array[TB_JMP_CACHE_SIZE]; |
24 | }; | ||
25 | |||
26 | -static inline TranslationBlock * | ||
27 | -tb_jmp_cache_get_tb(CPUJumpCache *jc, uint32_t cflags, uint32_t hash) | ||
28 | -{ | ||
29 | - if (cflags & CF_PCREL) { | ||
30 | - /* Use acquire to ensure current load of pc from jc. */ | ||
31 | - return qatomic_load_acquire(&jc->array[hash].tb); | ||
32 | - } else { | ||
33 | - /* Use rcu_read to ensure current load of pc from *tb. */ | ||
34 | - return qatomic_rcu_read(&jc->array[hash].tb); | ||
35 | - } | ||
36 | -} | ||
37 | - | ||
38 | -static inline target_ulong | ||
39 | -tb_jmp_cache_get_pc(CPUJumpCache *jc, uint32_t hash, TranslationBlock *tb) | ||
40 | -{ | ||
41 | - if (tb_cflags(tb) & CF_PCREL) { | ||
42 | - return jc->array[hash].pc; | ||
43 | - } else { | ||
44 | - return tb_pc(tb); | ||
45 | - } | ||
46 | -} | ||
47 | - | ||
48 | -static inline void | ||
49 | -tb_jmp_cache_set(CPUJumpCache *jc, uint32_t hash, | ||
50 | - TranslationBlock *tb, target_ulong pc) | ||
51 | -{ | ||
52 | - if (tb_cflags(tb) & CF_PCREL) { | ||
53 | - jc->array[hash].pc = pc; | ||
54 | - /* Use store_release on tb to ensure pc is written first. */ | ||
55 | - qatomic_store_release(&jc->array[hash].tb, tb); | ||
56 | - } else{ | ||
57 | - /* Use the pc value already stored in tb->pc. */ | ||
58 | - qatomic_set(&jc->array[hash].tb, tb); | ||
59 | - } | ||
60 | -} | ||
61 | - | ||
62 | #endif /* ACCEL_TCG_TB_JMP_CACHE_H */ | ||
63 | diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c | ||
64 | index XXXXXXX..XXXXXXX 100644 | ||
65 | --- a/accel/tcg/cpu-exec.c | ||
66 | +++ b/accel/tcg/cpu-exec.c | ||
67 | @@ -XXX,XX +XXX,XX @@ static inline TranslationBlock *tb_lookup(CPUState *cpu, target_ulong pc, | ||
68 | |||
69 | hash = tb_jmp_cache_hash_func(pc); | ||
70 | jc = cpu->tb_jmp_cache; | ||
71 | - tb = tb_jmp_cache_get_tb(jc, cflags, hash); | ||
72 | |||
73 | - if (likely(tb && | ||
74 | - tb_jmp_cache_get_pc(jc, hash, tb) == pc && | ||
75 | - tb->cs_base == cs_base && | ||
76 | - tb->flags == flags && | ||
77 | - tb->trace_vcpu_dstate == *cpu->trace_dstate && | ||
78 | - tb_cflags(tb) == cflags)) { | ||
79 | - return tb; | ||
80 | + if (cflags & CF_PCREL) { | ||
81 | + /* Use acquire to ensure current load of pc from jc. */ | ||
82 | + tb = qatomic_load_acquire(&jc->array[hash].tb); | ||
83 | + | ||
84 | + if (likely(tb && | ||
85 | + jc->array[hash].pc == pc && | ||
86 | + tb->cs_base == cs_base && | ||
87 | + tb->flags == flags && | ||
88 | + tb->trace_vcpu_dstate == *cpu->trace_dstate && | ||
89 | + tb_cflags(tb) == cflags)) { | ||
90 | + return tb; | ||
91 | + } | ||
92 | + tb = tb_htable_lookup(cpu, pc, cs_base, flags, cflags); | ||
93 | + if (tb == NULL) { | ||
94 | + return NULL; | ||
95 | + } | ||
96 | + jc->array[hash].pc = pc; | ||
97 | + /* Use store_release on tb to ensure pc is written first. */ | ||
98 | + qatomic_store_release(&jc->array[hash].tb, tb); | ||
99 | + } else { | ||
100 | + /* Use rcu_read to ensure current load of pc from *tb. */ | ||
101 | + tb = qatomic_rcu_read(&jc->array[hash].tb); | ||
102 | + | ||
103 | + if (likely(tb && | ||
104 | + tb_pc(tb) == pc && | ||
105 | + tb->cs_base == cs_base && | ||
106 | + tb->flags == flags && | ||
107 | + tb->trace_vcpu_dstate == *cpu->trace_dstate && | ||
108 | + tb_cflags(tb) == cflags)) { | ||
109 | + return tb; | ||
110 | + } | ||
111 | + tb = tb_htable_lookup(cpu, pc, cs_base, flags, cflags); | ||
112 | + if (tb == NULL) { | ||
113 | + return NULL; | ||
114 | + } | ||
115 | + /* Use the pc value already stored in tb->pc. */ | ||
116 | + qatomic_set(&jc->array[hash].tb, tb); | ||
117 | } | ||
118 | - tb = tb_htable_lookup(cpu, pc, cs_base, flags, cflags); | ||
119 | - if (tb == NULL) { | ||
120 | - return NULL; | ||
121 | - } | ||
122 | - tb_jmp_cache_set(jc, hash, tb, pc); | ||
123 | + | ||
124 | return tb; | ||
14 | } | 125 | } |
15 | 126 | ||
16 | +static bool fold_bswap(OptContext *ctx, TCGOp *op) | 127 | @@ -XXX,XX +XXX,XX @@ cpu_exec_loop(CPUState *cpu, SyncClocks *sc) |
17 | +{ | 128 | * for the fast lookup |
18 | + if (arg_is_const(op->args[1])) { | 129 | */ |
19 | + uint64_t t = arg_info(op->args[1])->val; | 130 | h = tb_jmp_cache_hash_func(pc); |
20 | + | 131 | - tb_jmp_cache_set(cpu->tb_jmp_cache, h, tb, pc); |
21 | + t = do_constant_folding(op->opc, t, op->args[2]); | 132 | + /* Use the pc value already stored in tb->pc. */ |
22 | + return tcg_opt_gen_movi(ctx, op, op->args[0], t); | 133 | + qatomic_set(&cpu->tb_jmp_cache->array[h].tb, tb); |
23 | + } | ||
24 | + return false; | ||
25 | +} | ||
26 | + | ||
27 | static bool fold_call(OptContext *ctx, TCGOp *op) | ||
28 | { | ||
29 | TCGContext *s = ctx->tcg; | ||
30 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
31 | } | 134 | } |
32 | break; | 135 | |
33 | 136 | #ifndef CONFIG_USER_ONLY | |
34 | - CASE_OP_32_64(bswap16): | ||
35 | - CASE_OP_32_64(bswap32): | ||
36 | - case INDEX_op_bswap64_i64: | ||
37 | - if (arg_is_const(op->args[1])) { | ||
38 | - tmp = do_constant_folding(opc, arg_info(op->args[1])->val, | ||
39 | - op->args[2]); | ||
40 | - tcg_opt_gen_movi(&ctx, op, op->args[0], tmp); | ||
41 | - continue; | ||
42 | - } | ||
43 | - break; | ||
44 | - | ||
45 | default: | ||
46 | break; | ||
47 | |||
48 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
49 | case INDEX_op_brcond2_i32: | ||
50 | done = fold_brcond2(&ctx, op); | ||
51 | break; | ||
52 | + CASE_OP_32_64(bswap16): | ||
53 | + CASE_OP_32_64(bswap32): | ||
54 | + case INDEX_op_bswap64_i64: | ||
55 | + done = fold_bswap(&ctx, op); | ||
56 | + break; | ||
57 | CASE_OP_32_64(clz): | ||
58 | CASE_OP_32_64(ctz): | ||
59 | done = fold_count_zeros(&ctx, op); | ||
60 | -- | 137 | -- |
61 | 2.25.1 | 138 | 2.34.1 |
62 | 139 | ||
63 | 140 | diff view generated by jsdifflib |
1 | From: Luis Pires <luis.pires@eldorado.org.br> | 1 | From: Anton Johansson via <qemu-devel@nongnu.org> |
---|---|---|---|
2 | 2 | ||
3 | In preparation for changing the divu128/divs128 implementations | 3 | Signed-off-by: Anton Johansson <anjo@rev.ng> |
4 | to allow for quotients larger than 64 bits, move the div-by-zero | 4 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
5 | and overflow checks to the callers. | 5 | Message-Id: <20230227135202.9710-13-anjo@rev.ng> |
6 | |||
7 | Signed-off-by: Luis Pires <luis.pires@eldorado.org.br> | ||
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
9 | Message-Id: <20211025191154.350831-2-luis.pires@eldorado.org.br> | ||
10 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
11 | --- | 7 | --- |
12 | include/hw/clock.h | 5 +++-- | 8 | accel/tcg/internal.h | 2 +- |
13 | include/qemu/host-utils.h | 34 ++++++++++++--------------------- | 9 | accel/tcg/cpu-exec.c | 6 +++--- |
14 | target/ppc/int_helper.c | 14 +++++++++----- | 10 | accel/tcg/tb-maint.c | 8 ++++---- |
15 | util/host-utils.c | 40 ++++++++++++++++++--------------------- | 11 | accel/tcg/translate-all.c | 4 ++-- |
16 | 4 files changed, 42 insertions(+), 51 deletions(-) | 12 | 4 files changed, 10 insertions(+), 10 deletions(-) |
17 | 13 | ||
18 | diff --git a/include/hw/clock.h b/include/hw/clock.h | 14 | diff --git a/accel/tcg/internal.h b/accel/tcg/internal.h |
19 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/include/hw/clock.h | 16 | --- a/accel/tcg/internal.h |
21 | +++ b/include/hw/clock.h | 17 | +++ b/accel/tcg/internal.h |
22 | @@ -XXX,XX +XXX,XX @@ static inline uint64_t clock_ns_to_ticks(const Clock *clk, uint64_t ns) | 18 | @@ -XXX,XX +XXX,XX @@ static inline target_ulong log_pc(CPUState *cpu, const TranslationBlock *tb) |
23 | return 0; | 19 | if (tb_cflags(tb) & CF_PCREL) { |
24 | } | 20 | return cpu->cc->get_pc(cpu); |
25 | /* | ||
26 | - * Ignore divu128() return value as we've caught div-by-zero and don't | ||
27 | - * need different behaviour for overflow. | ||
28 | + * BUG: when CONFIG_INT128 is not defined, the current implementation of | ||
29 | + * divu128 does not return a valid truncated quotient, so the result will | ||
30 | + * be wrong. | ||
31 | */ | ||
32 | divu128(&lo, &hi, clk->period); | ||
33 | return lo; | ||
34 | diff --git a/include/qemu/host-utils.h b/include/qemu/host-utils.h | ||
35 | index XXXXXXX..XXXXXXX 100644 | ||
36 | --- a/include/qemu/host-utils.h | ||
37 | +++ b/include/qemu/host-utils.h | ||
38 | @@ -XXX,XX +XXX,XX @@ static inline uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c) | ||
39 | return (__int128_t)a * b / c; | ||
40 | } | ||
41 | |||
42 | -static inline int divu128(uint64_t *plow, uint64_t *phigh, uint64_t divisor) | ||
43 | +static inline void divu128(uint64_t *plow, uint64_t *phigh, uint64_t divisor) | ||
44 | { | ||
45 | - if (divisor == 0) { | ||
46 | - return 1; | ||
47 | - } else { | ||
48 | - __uint128_t dividend = ((__uint128_t)*phigh << 64) | *plow; | ||
49 | - __uint128_t result = dividend / divisor; | ||
50 | - *plow = result; | ||
51 | - *phigh = dividend % divisor; | ||
52 | - return result > UINT64_MAX; | ||
53 | - } | ||
54 | + __uint128_t dividend = ((__uint128_t)*phigh << 64) | *plow; | ||
55 | + __uint128_t result = dividend / divisor; | ||
56 | + *plow = result; | ||
57 | + *phigh = dividend % divisor; | ||
58 | } | ||
59 | |||
60 | -static inline int divs128(int64_t *plow, int64_t *phigh, int64_t divisor) | ||
61 | +static inline void divs128(int64_t *plow, int64_t *phigh, int64_t divisor) | ||
62 | { | ||
63 | - if (divisor == 0) { | ||
64 | - return 1; | ||
65 | - } else { | ||
66 | - __int128_t dividend = ((__int128_t)*phigh << 64) | (uint64_t)*plow; | ||
67 | - __int128_t result = dividend / divisor; | ||
68 | - *plow = result; | ||
69 | - *phigh = dividend % divisor; | ||
70 | - return result != *plow; | ||
71 | - } | ||
72 | + __int128_t dividend = ((__int128_t)*phigh << 64) | (uint64_t)*plow; | ||
73 | + __int128_t result = dividend / divisor; | ||
74 | + *plow = result; | ||
75 | + *phigh = dividend % divisor; | ||
76 | } | ||
77 | #else | ||
78 | void muls64(uint64_t *plow, uint64_t *phigh, int64_t a, int64_t b); | ||
79 | void mulu64(uint64_t *plow, uint64_t *phigh, uint64_t a, uint64_t b); | ||
80 | -int divu128(uint64_t *plow, uint64_t *phigh, uint64_t divisor); | ||
81 | -int divs128(int64_t *plow, int64_t *phigh, int64_t divisor); | ||
82 | +void divu128(uint64_t *plow, uint64_t *phigh, uint64_t divisor); | ||
83 | +void divs128(int64_t *plow, int64_t *phigh, int64_t divisor); | ||
84 | |||
85 | static inline uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c) | ||
86 | { | ||
87 | diff --git a/target/ppc/int_helper.c b/target/ppc/int_helper.c | ||
88 | index XXXXXXX..XXXXXXX 100644 | ||
89 | --- a/target/ppc/int_helper.c | ||
90 | +++ b/target/ppc/int_helper.c | ||
91 | @@ -XXX,XX +XXX,XX @@ uint64_t helper_divdeu(CPUPPCState *env, uint64_t ra, uint64_t rb, uint32_t oe) | ||
92 | uint64_t rt = 0; | ||
93 | int overflow = 0; | ||
94 | |||
95 | - overflow = divu128(&rt, &ra, rb); | ||
96 | - | ||
97 | - if (unlikely(overflow)) { | ||
98 | + if (unlikely(rb == 0 || ra >= rb)) { | ||
99 | + overflow = 1; | ||
100 | rt = 0; /* Undefined */ | ||
101 | + } else { | ||
102 | + divu128(&rt, &ra, rb); | ||
103 | } | ||
104 | |||
105 | if (oe) { | ||
106 | @@ -XXX,XX +XXX,XX @@ uint64_t helper_divde(CPUPPCState *env, uint64_t rau, uint64_t rbu, uint32_t oe) | ||
107 | int64_t rt = 0; | ||
108 | int64_t ra = (int64_t)rau; | ||
109 | int64_t rb = (int64_t)rbu; | ||
110 | - int overflow = divs128(&rt, &ra, rb); | ||
111 | + int overflow = 0; | ||
112 | |||
113 | - if (unlikely(overflow)) { | ||
114 | + if (unlikely(rb == 0 || uabs64(ra) >= uabs64(rb))) { | ||
115 | + overflow = 1; | ||
116 | rt = 0; /* Undefined */ | ||
117 | + } else { | ||
118 | + divs128(&rt, &ra, rb); | ||
119 | } | ||
120 | |||
121 | if (oe) { | ||
122 | diff --git a/util/host-utils.c b/util/host-utils.c | ||
123 | index XXXXXXX..XXXXXXX 100644 | ||
124 | --- a/util/host-utils.c | ||
125 | +++ b/util/host-utils.c | ||
126 | @@ -XXX,XX +XXX,XX @@ void muls64 (uint64_t *plow, uint64_t *phigh, int64_t a, int64_t b) | ||
127 | *phigh = rh; | ||
128 | } | ||
129 | |||
130 | -/* Unsigned 128x64 division. Returns 1 if overflow (divide by zero or */ | ||
131 | -/* quotient exceeds 64 bits). Otherwise returns quotient via plow and */ | ||
132 | -/* remainder via phigh. */ | ||
133 | -int divu128(uint64_t *plow, uint64_t *phigh, uint64_t divisor) | ||
134 | +/* | ||
135 | + * Unsigned 128-by-64 division. Returns quotient via plow and | ||
136 | + * remainder via phigh. | ||
137 | + * The result must fit in 64 bits (plow) - otherwise, the result | ||
138 | + * is undefined. | ||
139 | + * This function will cause a division by zero if passed a zero divisor. | ||
140 | + */ | ||
141 | +void divu128(uint64_t *plow, uint64_t *phigh, uint64_t divisor) | ||
142 | { | ||
143 | uint64_t dhi = *phigh; | ||
144 | uint64_t dlo = *plow; | ||
145 | unsigned i; | ||
146 | uint64_t carry = 0; | ||
147 | |||
148 | - if (divisor == 0) { | ||
149 | - return 1; | ||
150 | - } else if (dhi == 0) { | ||
151 | + if (divisor == 0 || dhi == 0) { | ||
152 | *plow = dlo / divisor; | ||
153 | *phigh = dlo % divisor; | ||
154 | - return 0; | ||
155 | - } else if (dhi >= divisor) { | ||
156 | - return 1; | ||
157 | } else { | 21 | } else { |
158 | 22 | - return tb_pc(tb); | |
159 | for (i = 0; i < 64; i++) { | 23 | + return tb->pc; |
160 | @@ -XXX,XX +XXX,XX @@ int divu128(uint64_t *plow, uint64_t *phigh, uint64_t divisor) | ||
161 | |||
162 | *plow = dlo; | ||
163 | *phigh = dhi; | ||
164 | - return 0; | ||
165 | } | 24 | } |
166 | } | 25 | } |
167 | 26 | ||
168 | -int divs128(int64_t *plow, int64_t *phigh, int64_t divisor) | 27 | diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c |
169 | +/* | 28 | index XXXXXXX..XXXXXXX 100644 |
170 | + * Signed 128-by-64 division. Returns quotient via plow and | 29 | --- a/accel/tcg/cpu-exec.c |
171 | + * remainder via phigh. | 30 | +++ b/accel/tcg/cpu-exec.c |
172 | + * The result must fit in 64 bits (plow) - otherwise, the result | 31 | @@ -XXX,XX +XXX,XX @@ static bool tb_lookup_cmp(const void *p, const void *d) |
173 | + * is undefined. | 32 | const TranslationBlock *tb = p; |
174 | + * This function will cause a division by zero if passed a zero divisor. | 33 | const struct tb_desc *desc = d; |
175 | + */ | 34 | |
176 | +void divs128(int64_t *plow, int64_t *phigh, int64_t divisor) | 35 | - if ((tb_cflags(tb) & CF_PCREL || tb_pc(tb) == desc->pc) && |
177 | { | 36 | + if ((tb_cflags(tb) & CF_PCREL || tb->pc == desc->pc) && |
178 | int sgn_dvdnd = *phigh < 0; | 37 | tb_page_addr0(tb) == desc->page_addr0 && |
179 | int sgn_divsr = divisor < 0; | 38 | tb->cs_base == desc->cs_base && |
180 | - int overflow = 0; | 39 | tb->flags == desc->flags && |
181 | 40 | @@ -XXX,XX +XXX,XX @@ static inline TranslationBlock *tb_lookup(CPUState *cpu, target_ulong pc, | |
182 | if (sgn_dvdnd) { | 41 | tb = qatomic_rcu_read(&jc->array[hash].tb); |
183 | *plow = ~(*plow); | 42 | |
184 | @@ -XXX,XX +XXX,XX @@ int divs128(int64_t *plow, int64_t *phigh, int64_t divisor) | 43 | if (likely(tb && |
185 | divisor = 0 - divisor; | 44 | - tb_pc(tb) == pc && |
45 | + tb->pc == pc && | ||
46 | tb->cs_base == cs_base && | ||
47 | tb->flags == flags && | ||
48 | tb->trace_vcpu_dstate == *cpu->trace_dstate && | ||
49 | @@ -XXX,XX +XXX,XX @@ cpu_tb_exec(CPUState *cpu, TranslationBlock *itb, int *tb_exit) | ||
50 | } else { | ||
51 | tcg_debug_assert(!(tb_cflags(last_tb) & CF_PCREL)); | ||
52 | assert(cc->set_pc); | ||
53 | - cc->set_pc(cpu, tb_pc(last_tb)); | ||
54 | + cc->set_pc(cpu, last_tb->pc); | ||
55 | } | ||
56 | if (qemu_loglevel_mask(CPU_LOG_EXEC)) { | ||
57 | target_ulong pc = log_pc(cpu, last_tb); | ||
58 | diff --git a/accel/tcg/tb-maint.c b/accel/tcg/tb-maint.c | ||
59 | index XXXXXXX..XXXXXXX 100644 | ||
60 | --- a/accel/tcg/tb-maint.c | ||
61 | +++ b/accel/tcg/tb-maint.c | ||
62 | @@ -XXX,XX +XXX,XX @@ static bool tb_cmp(const void *ap, const void *bp) | ||
63 | const TranslationBlock *a = ap; | ||
64 | const TranslationBlock *b = bp; | ||
65 | |||
66 | - return ((tb_cflags(a) & CF_PCREL || tb_pc(a) == tb_pc(b)) && | ||
67 | + return ((tb_cflags(a) & CF_PCREL || a->pc == b->pc) && | ||
68 | a->cs_base == b->cs_base && | ||
69 | a->flags == b->flags && | ||
70 | (tb_cflags(a) & ~CF_INVALID) == (tb_cflags(b) & ~CF_INVALID) && | ||
71 | @@ -XXX,XX +XXX,XX @@ static void tb_jmp_cache_inval_tb(TranslationBlock *tb) | ||
72 | tcg_flush_jmp_cache(cpu); | ||
73 | } | ||
74 | } else { | ||
75 | - uint32_t h = tb_jmp_cache_hash_func(tb_pc(tb)); | ||
76 | + uint32_t h = tb_jmp_cache_hash_func(tb->pc); | ||
77 | |||
78 | CPU_FOREACH(cpu) { | ||
79 | CPUJumpCache *jc = cpu->tb_jmp_cache; | ||
80 | @@ -XXX,XX +XXX,XX @@ static void do_tb_phys_invalidate(TranslationBlock *tb, bool rm_from_page_list) | ||
81 | |||
82 | /* remove the TB from the hash list */ | ||
83 | phys_pc = tb_page_addr0(tb); | ||
84 | - h = tb_hash_func(phys_pc, (orig_cflags & CF_PCREL ? 0 : tb_pc(tb)), | ||
85 | + h = tb_hash_func(phys_pc, (orig_cflags & CF_PCREL ? 0 : tb->pc), | ||
86 | tb->flags, orig_cflags, tb->trace_vcpu_dstate); | ||
87 | if (!qht_remove(&tb_ctx.htable, tb, h)) { | ||
88 | return; | ||
89 | @@ -XXX,XX +XXX,XX @@ TranslationBlock *tb_link_page(TranslationBlock *tb, tb_page_addr_t phys_pc, | ||
90 | tb_record(tb, p, p2); | ||
91 | |||
92 | /* add in the hash table */ | ||
93 | - h = tb_hash_func(phys_pc, (tb->cflags & CF_PCREL ? 0 : tb_pc(tb)), | ||
94 | + h = tb_hash_func(phys_pc, (tb->cflags & CF_PCREL ? 0 : tb->pc), | ||
95 | tb->flags, tb->cflags, tb->trace_vcpu_dstate); | ||
96 | qht_insert(&tb_ctx.htable, tb, h, &existing_tb); | ||
97 | |||
98 | diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c | ||
99 | index XXXXXXX..XXXXXXX 100644 | ||
100 | --- a/accel/tcg/translate-all.c | ||
101 | +++ b/accel/tcg/translate-all.c | ||
102 | @@ -XXX,XX +XXX,XX @@ static int encode_search(TranslationBlock *tb, uint8_t *block) | ||
103 | |||
104 | for (j = 0; j < TARGET_INSN_START_WORDS; ++j) { | ||
105 | if (i == 0) { | ||
106 | - prev = (!(tb_cflags(tb) & CF_PCREL) && j == 0 ? tb_pc(tb) : 0); | ||
107 | + prev = (!(tb_cflags(tb) & CF_PCREL) && j == 0 ? tb->pc : 0); | ||
108 | } else { | ||
109 | prev = tcg_ctx->gen_insn_data[i - 1][j]; | ||
110 | } | ||
111 | @@ -XXX,XX +XXX,XX @@ static int cpu_unwind_data_from_tb(TranslationBlock *tb, uintptr_t host_pc, | ||
112 | |||
113 | memset(data, 0, sizeof(uint64_t) * TARGET_INSN_START_WORDS); | ||
114 | if (!(tb_cflags(tb) & CF_PCREL)) { | ||
115 | - data[0] = tb_pc(tb); | ||
116 | + data[0] = tb->pc; | ||
186 | } | 117 | } |
187 | 118 | ||
188 | - overflow = divu128((uint64_t *)plow, (uint64_t *)phigh, (uint64_t)divisor); | 119 | /* |
189 | + divu128((uint64_t *)plow, (uint64_t *)phigh, (uint64_t)divisor); | ||
190 | |||
191 | if (sgn_dvdnd ^ sgn_divsr) { | ||
192 | *plow = 0 - *plow; | ||
193 | } | ||
194 | - | ||
195 | - if (!overflow) { | ||
196 | - if ((*plow < 0) ^ (sgn_dvdnd ^ sgn_divsr)) { | ||
197 | - overflow = 1; | ||
198 | - } | ||
199 | - } | ||
200 | - | ||
201 | - return overflow; | ||
202 | } | ||
203 | #endif | ||
204 | |||
205 | -- | 120 | -- |
206 | 2.25.1 | 121 | 2.34.1 |
207 | 122 | ||
208 | 123 | diff view generated by jsdifflib |
1 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | 1 | From: Anton Johansson via <qemu-devel@nongnu.org> |
---|---|---|---|
2 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 2 | |
3 | Signed-off-by: Anton Johansson <anjo@rev.ng> | ||
4 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
5 | Message-Id: <20230227135202.9710-14-anjo@rev.ng> | ||
3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
4 | --- | 7 | --- |
5 | tcg/optimize.c | 32 ++++++++++++++++++-------------- | 8 | target/tricore/cpu.c | 3 ++- |
6 | 1 file changed, 18 insertions(+), 14 deletions(-) | 9 | 1 file changed, 2 insertions(+), 1 deletion(-) |
7 | 10 | ||
8 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 11 | diff --git a/target/tricore/cpu.c b/target/tricore/cpu.c |
9 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
10 | --- a/tcg/optimize.c | 13 | --- a/target/tricore/cpu.c |
11 | +++ b/tcg/optimize.c | 14 | +++ b/target/tricore/cpu.c |
12 | @@ -XXX,XX +XXX,XX @@ static bool fold_call(OptContext *ctx, TCGOp *op) | 15 | @@ -XXX,XX +XXX,XX @@ static void tricore_cpu_synchronize_from_tb(CPUState *cs, |
13 | return true; | 16 | TriCoreCPU *cpu = TRICORE_CPU(cs); |
17 | CPUTriCoreState *env = &cpu->env; | ||
18 | |||
19 | - env->PC = tb_pc(tb); | ||
20 | + tcg_debug_assert(!(cs->tcg_cflags & CF_PCREL)); | ||
21 | + env->PC = tb->pc; | ||
14 | } | 22 | } |
15 | 23 | ||
16 | +static bool fold_count_zeros(OptContext *ctx, TCGOp *op) | 24 | static void tricore_restore_state_to_opc(CPUState *cs, |
17 | +{ | ||
18 | + if (arg_is_const(op->args[1])) { | ||
19 | + uint64_t t = arg_info(op->args[1])->val; | ||
20 | + | ||
21 | + if (t != 0) { | ||
22 | + t = do_constant_folding(op->opc, t, 0); | ||
23 | + return tcg_opt_gen_movi(ctx, op, op->args[0], t); | ||
24 | + } | ||
25 | + return tcg_opt_gen_mov(ctx, op, op->args[0], op->args[2]); | ||
26 | + } | ||
27 | + return false; | ||
28 | +} | ||
29 | + | ||
30 | static bool fold_ctpop(OptContext *ctx, TCGOp *op) | ||
31 | { | ||
32 | return fold_const1(ctx, op); | ||
33 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
34 | } | ||
35 | break; | ||
36 | |||
37 | - CASE_OP_32_64(clz): | ||
38 | - CASE_OP_32_64(ctz): | ||
39 | - if (arg_is_const(op->args[1])) { | ||
40 | - TCGArg v = arg_info(op->args[1])->val; | ||
41 | - if (v != 0) { | ||
42 | - tmp = do_constant_folding(opc, v, 0); | ||
43 | - tcg_opt_gen_movi(&ctx, op, op->args[0], tmp); | ||
44 | - } else { | ||
45 | - tcg_opt_gen_mov(&ctx, op, op->args[0], op->args[2]); | ||
46 | - } | ||
47 | - continue; | ||
48 | - } | ||
49 | - break; | ||
50 | - | ||
51 | default: | ||
52 | break; | ||
53 | |||
54 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
55 | case INDEX_op_brcond2_i32: | ||
56 | done = fold_brcond2(&ctx, op); | ||
57 | break; | ||
58 | + CASE_OP_32_64(clz): | ||
59 | + CASE_OP_32_64(ctz): | ||
60 | + done = fold_count_zeros(&ctx, op); | ||
61 | + break; | ||
62 | CASE_OP_32_64(ctpop): | ||
63 | done = fold_ctpop(&ctx, op); | ||
64 | break; | ||
65 | -- | 25 | -- |
66 | 2.25.1 | 26 | 2.34.1 |
67 | 27 | ||
68 | 28 | diff view generated by jsdifflib |
1 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | 1 | From: Anton Johansson via <qemu-devel@nongnu.org> |
---|---|---|---|
2 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 2 | |
3 | Signed-off-by: Anton Johansson <anjo@rev.ng> | ||
4 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
5 | Message-Id: <20230227135202.9710-15-anjo@rev.ng> | ||
3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
4 | --- | 7 | --- |
5 | tcg/optimize.c | 25 +++++++++++++++---------- | 8 | target/sparc/cpu.c | 4 +++- |
6 | 1 file changed, 15 insertions(+), 10 deletions(-) | 9 | 1 file changed, 3 insertions(+), 1 deletion(-) |
7 | 10 | ||
8 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 11 | diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c |
9 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
10 | --- a/tcg/optimize.c | 13 | --- a/target/sparc/cpu.c |
11 | +++ b/tcg/optimize.c | 14 | +++ b/target/sparc/cpu.c |
12 | @@ -XXX,XX +XXX,XX @@ static bool fold_ctpop(OptContext *ctx, TCGOp *op) | 15 | @@ -XXX,XX +XXX,XX @@ |
13 | return fold_const1(ctx, op); | 16 | #include "exec/exec-all.h" |
17 | #include "hw/qdev-properties.h" | ||
18 | #include "qapi/visitor.h" | ||
19 | +#include "tcg/tcg.h" | ||
20 | |||
21 | //#define DEBUG_FEATURES | ||
22 | |||
23 | @@ -XXX,XX +XXX,XX @@ static void sparc_cpu_synchronize_from_tb(CPUState *cs, | ||
24 | { | ||
25 | SPARCCPU *cpu = SPARC_CPU(cs); | ||
26 | |||
27 | - cpu->env.pc = tb_pc(tb); | ||
28 | + tcg_debug_assert(!(cs->tcg_cflags & CF_PCREL)); | ||
29 | + cpu->env.pc = tb->pc; | ||
30 | cpu->env.npc = tb->cs_base; | ||
14 | } | 31 | } |
15 | 32 | ||
16 | +static bool fold_deposit(OptContext *ctx, TCGOp *op) | ||
17 | +{ | ||
18 | + if (arg_is_const(op->args[1]) && arg_is_const(op->args[2])) { | ||
19 | + uint64_t t1 = arg_info(op->args[1])->val; | ||
20 | + uint64_t t2 = arg_info(op->args[2])->val; | ||
21 | + | ||
22 | + t1 = deposit64(t1, op->args[3], op->args[4], t2); | ||
23 | + return tcg_opt_gen_movi(ctx, op, op->args[0], t1); | ||
24 | + } | ||
25 | + return false; | ||
26 | +} | ||
27 | + | ||
28 | static bool fold_divide(OptContext *ctx, TCGOp *op) | ||
29 | { | ||
30 | return fold_const2(ctx, op); | ||
31 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
32 | } | ||
33 | break; | ||
34 | |||
35 | - CASE_OP_32_64(deposit): | ||
36 | - if (arg_is_const(op->args[1]) && arg_is_const(op->args[2])) { | ||
37 | - tmp = deposit64(arg_info(op->args[1])->val, | ||
38 | - op->args[3], op->args[4], | ||
39 | - arg_info(op->args[2])->val); | ||
40 | - tcg_opt_gen_movi(&ctx, op, op->args[0], tmp); | ||
41 | - continue; | ||
42 | - } | ||
43 | - break; | ||
44 | - | ||
45 | default: | ||
46 | break; | ||
47 | |||
48 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
49 | CASE_OP_32_64(ctpop): | ||
50 | done = fold_ctpop(&ctx, op); | ||
51 | break; | ||
52 | + CASE_OP_32_64(deposit): | ||
53 | + done = fold_deposit(&ctx, op); | ||
54 | + break; | ||
55 | CASE_OP_32_64(div): | ||
56 | CASE_OP_32_64(divu): | ||
57 | done = fold_divide(&ctx, op); | ||
58 | -- | 33 | -- |
59 | 2.25.1 | 34 | 2.34.1 |
60 | 35 | ||
61 | 36 | diff view generated by jsdifflib |
1 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | 1 | From: Anton Johansson via <qemu-devel@nongnu.org> |
---|---|---|---|
2 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 2 | |
3 | Signed-off-by: Anton Johansson <anjo@rev.ng> | ||
4 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
5 | Message-Id: <20230227135202.9710-16-anjo@rev.ng> | ||
3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
4 | --- | 7 | --- |
5 | tcg/optimize.c | 48 ++++++++++++++++++++++++++++++------------------ | 8 | target/sh4/cpu.c | 6 ++++-- |
6 | 1 file changed, 30 insertions(+), 18 deletions(-) | 9 | 1 file changed, 4 insertions(+), 2 deletions(-) |
7 | 10 | ||
8 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 11 | diff --git a/target/sh4/cpu.c b/target/sh4/cpu.c |
9 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
10 | --- a/tcg/optimize.c | 13 | --- a/target/sh4/cpu.c |
11 | +++ b/tcg/optimize.c | 14 | +++ b/target/sh4/cpu.c |
12 | @@ -XXX,XX +XXX,XX @@ static bool fold_eqv(OptContext *ctx, TCGOp *op) | 15 | @@ -XXX,XX +XXX,XX @@ |
13 | return fold_const2(ctx, op); | 16 | #include "migration/vmstate.h" |
17 | #include "exec/exec-all.h" | ||
18 | #include "fpu/softfloat-helpers.h" | ||
19 | +#include "tcg/tcg.h" | ||
20 | |||
21 | static void superh_cpu_set_pc(CPUState *cs, vaddr value) | ||
22 | { | ||
23 | @@ -XXX,XX +XXX,XX @@ static void superh_cpu_synchronize_from_tb(CPUState *cs, | ||
24 | { | ||
25 | SuperHCPU *cpu = SUPERH_CPU(cs); | ||
26 | |||
27 | - cpu->env.pc = tb_pc(tb); | ||
28 | + tcg_debug_assert(!(cs->tcg_cflags & CF_PCREL)); | ||
29 | + cpu->env.pc = tb->pc; | ||
30 | cpu->env.flags = tb->flags & TB_FLAG_ENVFLAGS_MASK; | ||
14 | } | 31 | } |
15 | 32 | ||
16 | +static bool fold_extract(OptContext *ctx, TCGOp *op) | 33 | @@ -XXX,XX +XXX,XX @@ static bool superh_io_recompile_replay_branch(CPUState *cs, |
17 | +{ | 34 | CPUSH4State *env = &cpu->env; |
18 | + if (arg_is_const(op->args[1])) { | 35 | |
19 | + uint64_t t; | 36 | if ((env->flags & (TB_FLAG_DELAY_SLOT | TB_FLAG_DELAY_SLOT_COND)) |
20 | + | 37 | - && env->pc != tb_pc(tb)) { |
21 | + t = arg_info(op->args[1])->val; | 38 | + && !(cs->tcg_cflags & CF_PCREL) && env->pc != tb->pc) { |
22 | + t = extract64(t, op->args[2], op->args[3]); | 39 | env->pc -= 2; |
23 | + return tcg_opt_gen_movi(ctx, op, op->args[0], t); | 40 | env->flags &= ~(TB_FLAG_DELAY_SLOT | TB_FLAG_DELAY_SLOT_COND); |
24 | + } | 41 | return true; |
25 | + return false; | ||
26 | +} | ||
27 | + | ||
28 | static bool fold_extract2(OptContext *ctx, TCGOp *op) | ||
29 | { | ||
30 | if (arg_is_const(op->args[1]) && arg_is_const(op->args[2])) { | ||
31 | @@ -XXX,XX +XXX,XX @@ static bool fold_setcond2(OptContext *ctx, TCGOp *op) | ||
32 | return tcg_opt_gen_movi(ctx, op, op->args[0], i); | ||
33 | } | ||
34 | |||
35 | +static bool fold_sextract(OptContext *ctx, TCGOp *op) | ||
36 | +{ | ||
37 | + if (arg_is_const(op->args[1])) { | ||
38 | + uint64_t t; | ||
39 | + | ||
40 | + t = arg_info(op->args[1])->val; | ||
41 | + t = sextract64(t, op->args[2], op->args[3]); | ||
42 | + return tcg_opt_gen_movi(ctx, op, op->args[0], t); | ||
43 | + } | ||
44 | + return false; | ||
45 | +} | ||
46 | + | ||
47 | static bool fold_shift(OptContext *ctx, TCGOp *op) | ||
48 | { | ||
49 | return fold_const2(ctx, op); | ||
50 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
51 | } | ||
52 | break; | ||
53 | |||
54 | - CASE_OP_32_64(extract): | ||
55 | - if (arg_is_const(op->args[1])) { | ||
56 | - tmp = extract64(arg_info(op->args[1])->val, | ||
57 | - op->args[2], op->args[3]); | ||
58 | - tcg_opt_gen_movi(&ctx, op, op->args[0], tmp); | ||
59 | - continue; | ||
60 | - } | ||
61 | - break; | ||
62 | - | ||
63 | - CASE_OP_32_64(sextract): | ||
64 | - if (arg_is_const(op->args[1])) { | ||
65 | - tmp = sextract64(arg_info(op->args[1])->val, | ||
66 | - op->args[2], op->args[3]); | ||
67 | - tcg_opt_gen_movi(&ctx, op, op->args[0], tmp); | ||
68 | - continue; | ||
69 | - } | ||
70 | - break; | ||
71 | - | ||
72 | default: | ||
73 | break; | ||
74 | |||
75 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
76 | CASE_OP_32_64(eqv): | ||
77 | done = fold_eqv(&ctx, op); | ||
78 | break; | ||
79 | + CASE_OP_32_64(extract): | ||
80 | + done = fold_extract(&ctx, op); | ||
81 | + break; | ||
82 | CASE_OP_32_64(extract2): | ||
83 | done = fold_extract2(&ctx, op); | ||
84 | break; | ||
85 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
86 | case INDEX_op_setcond2_i32: | ||
87 | done = fold_setcond2(&ctx, op); | ||
88 | break; | ||
89 | + CASE_OP_32_64(sextract): | ||
90 | + done = fold_sextract(&ctx, op); | ||
91 | + break; | ||
92 | CASE_OP_32_64_VEC(sub): | ||
93 | done = fold_sub(&ctx, op); | ||
94 | break; | ||
95 | -- | 42 | -- |
96 | 2.25.1 | 43 | 2.34.1 |
97 | 44 | ||
98 | 45 | diff view generated by jsdifflib |
1 | The results are generally 6 bit unsigned values, though | 1 | From: Anton Johansson via <qemu-devel@nongnu.org> |
---|---|---|---|
2 | the count leading and trailing bits may produce any value | ||
3 | for a zero input. | ||
4 | 2 | ||
5 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 3 | Signed-off-by: Anton Johansson <anjo@rev.ng> |
6 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | 4 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
5 | Message-Id: <20230227135202.9710-17-anjo@rev.ng> | ||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
8 | --- | 7 | --- |
9 | tcg/optimize.c | 3 ++- | 8 | target/rx/cpu.c | 3 ++- |
10 | 1 file changed, 2 insertions(+), 1 deletion(-) | 9 | 1 file changed, 2 insertions(+), 1 deletion(-) |
11 | 10 | ||
12 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 11 | diff --git a/target/rx/cpu.c b/target/rx/cpu.c |
13 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/tcg/optimize.c | 13 | --- a/target/rx/cpu.c |
15 | +++ b/tcg/optimize.c | 14 | +++ b/target/rx/cpu.c |
16 | @@ -XXX,XX +XXX,XX @@ static bool fold_count_zeros(OptContext *ctx, TCGOp *op) | 15 | @@ -XXX,XX +XXX,XX @@ static void rx_cpu_synchronize_from_tb(CPUState *cs, |
17 | g_assert_not_reached(); | 16 | { |
18 | } | 17 | RXCPU *cpu = RX_CPU(cs); |
19 | ctx->z_mask = arg_info(op->args[2])->z_mask | z_mask; | 18 | |
20 | - | 19 | - cpu->env.pc = tb_pc(tb); |
21 | + ctx->s_mask = smask_from_zmask(ctx->z_mask); | 20 | + tcg_debug_assert(!(cs->tcg_cflags & CF_PCREL)); |
22 | return false; | 21 | + cpu->env.pc = tb->pc; |
23 | } | 22 | } |
24 | 23 | ||
25 | @@ -XXX,XX +XXX,XX @@ static bool fold_ctpop(OptContext *ctx, TCGOp *op) | 24 | static void rx_restore_state_to_opc(CPUState *cs, |
26 | default: | ||
27 | g_assert_not_reached(); | ||
28 | } | ||
29 | + ctx->s_mask = smask_from_zmask(ctx->z_mask); | ||
30 | return false; | ||
31 | } | ||
32 | |||
33 | -- | 25 | -- |
34 | 2.25.1 | 26 | 2.34.1 |
35 | 27 | ||
36 | 28 | diff view generated by jsdifflib |
1 | Compute the type of the operation early. | 1 | From: Anton Johansson via <qemu-devel@nongnu.org> |
---|---|---|---|
2 | 2 | ||
3 | There are at least 4 places that used a def->flags ladder | 3 | Signed-off-by: Anton Johansson <anjo@rev.ng> |
4 | to determine the type of the operation being optimized. | 4 | Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com> |
5 | 5 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | |
6 | There were two places that assumed !TCG_OPF_64BIT means | 6 | Message-Id: <20230227135202.9710-18-anjo@rev.ng> |
7 | TCG_TYPE_I32, and so could potentially compute incorrect | ||
8 | results for vector operations. | ||
9 | |||
10 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | ||
11 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
12 | --- | 8 | --- |
13 | tcg/optimize.c | 149 +++++++++++++++++++++++++++++-------------------- | 9 | target/riscv/cpu.c | 7 +++++-- |
14 | 1 file changed, 89 insertions(+), 60 deletions(-) | 10 | 1 file changed, 5 insertions(+), 2 deletions(-) |
15 | 11 | ||
16 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 12 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
17 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/tcg/optimize.c | 14 | --- a/target/riscv/cpu.c |
19 | +++ b/tcg/optimize.c | 15 | +++ b/target/riscv/cpu.c |
20 | @@ -XXX,XX +XXX,XX @@ typedef struct OptContext { | 16 | @@ -XXX,XX +XXX,XX @@ |
21 | 17 | #include "fpu/softfloat-helpers.h" | |
22 | /* In flight values from optimization. */ | 18 | #include "sysemu/kvm.h" |
23 | uint64_t z_mask; | 19 | #include "kvm_riscv.h" |
24 | + TCGType type; | 20 | +#include "tcg/tcg.h" |
25 | } OptContext; | 21 | |
26 | 22 | /* RISC-V CPU definitions */ | |
27 | static inline TempOptInfo *ts_info(TCGTemp *ts) | 23 | |
28 | @@ -XXX,XX +XXX,XX @@ static bool tcg_opt_gen_mov(OptContext *ctx, TCGOp *op, TCGArg dst, TCGArg src) | 24 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_synchronize_from_tb(CPUState *cs, |
29 | { | 25 | CPURISCVState *env = &cpu->env; |
30 | TCGTemp *dst_ts = arg_temp(dst); | 26 | RISCVMXL xl = FIELD_EX32(tb->flags, TB_FLAGS, XL); |
31 | TCGTemp *src_ts = arg_temp(src); | 27 | |
32 | - const TCGOpDef *def; | 28 | + tcg_debug_assert(!(cs->tcg_cflags & CF_PCREL)); |
33 | TempOptInfo *di; | ||
34 | TempOptInfo *si; | ||
35 | uint64_t z_mask; | ||
36 | @@ -XXX,XX +XXX,XX @@ static bool tcg_opt_gen_mov(OptContext *ctx, TCGOp *op, TCGArg dst, TCGArg src) | ||
37 | reset_ts(dst_ts); | ||
38 | di = ts_info(dst_ts); | ||
39 | si = ts_info(src_ts); | ||
40 | - def = &tcg_op_defs[op->opc]; | ||
41 | - if (def->flags & TCG_OPF_VECTOR) { | ||
42 | - new_op = INDEX_op_mov_vec; | ||
43 | - } else if (def->flags & TCG_OPF_64BIT) { | ||
44 | - new_op = INDEX_op_mov_i64; | ||
45 | - } else { | ||
46 | + | 29 | + |
47 | + switch (ctx->type) { | 30 | if (xl == MXL_RV32) { |
48 | + case TCG_TYPE_I32: | 31 | - env->pc = (int32_t)tb_pc(tb); |
49 | new_op = INDEX_op_mov_i32; | 32 | + env->pc = (int32_t) tb->pc; |
50 | + break; | 33 | } else { |
51 | + case TCG_TYPE_I64: | 34 | - env->pc = tb_pc(tb); |
52 | + new_op = INDEX_op_mov_i64; | 35 | + env->pc = tb->pc; |
53 | + break; | ||
54 | + case TCG_TYPE_V64: | ||
55 | + case TCG_TYPE_V128: | ||
56 | + case TCG_TYPE_V256: | ||
57 | + /* TCGOP_VECL and TCGOP_VECE remain unchanged. */ | ||
58 | + new_op = INDEX_op_mov_vec; | ||
59 | + break; | ||
60 | + default: | ||
61 | + g_assert_not_reached(); | ||
62 | } | ||
63 | op->opc = new_op; | ||
64 | - /* TCGOP_VECL and TCGOP_VECE remain unchanged. */ | ||
65 | op->args[0] = dst; | ||
66 | op->args[1] = src; | ||
67 | |||
68 | @@ -XXX,XX +XXX,XX @@ static bool tcg_opt_gen_mov(OptContext *ctx, TCGOp *op, TCGArg dst, TCGArg src) | ||
69 | static bool tcg_opt_gen_movi(OptContext *ctx, TCGOp *op, | ||
70 | TCGArg dst, uint64_t val) | ||
71 | { | ||
72 | - const TCGOpDef *def = &tcg_op_defs[op->opc]; | ||
73 | - TCGType type; | ||
74 | - TCGTemp *tv; | ||
75 | - | ||
76 | - if (def->flags & TCG_OPF_VECTOR) { | ||
77 | - type = TCGOP_VECL(op) + TCG_TYPE_V64; | ||
78 | - } else if (def->flags & TCG_OPF_64BIT) { | ||
79 | - type = TCG_TYPE_I64; | ||
80 | - } else { | ||
81 | - type = TCG_TYPE_I32; | ||
82 | - } | ||
83 | - | ||
84 | /* Convert movi to mov with constant temp. */ | ||
85 | - tv = tcg_constant_internal(type, val); | ||
86 | + TCGTemp *tv = tcg_constant_internal(ctx->type, val); | ||
87 | + | ||
88 | init_ts_info(ctx, tv); | ||
89 | return tcg_opt_gen_mov(ctx, op, dst, temp_arg(tv)); | ||
90 | } | ||
91 | @@ -XXX,XX +XXX,XX @@ static uint64_t do_constant_folding_2(TCGOpcode op, uint64_t x, uint64_t y) | ||
92 | } | 36 | } |
93 | } | 37 | } |
94 | 38 | ||
95 | -static uint64_t do_constant_folding(TCGOpcode op, uint64_t x, uint64_t y) | ||
96 | +static uint64_t do_constant_folding(TCGOpcode op, TCGType type, | ||
97 | + uint64_t x, uint64_t y) | ||
98 | { | ||
99 | - const TCGOpDef *def = &tcg_op_defs[op]; | ||
100 | uint64_t res = do_constant_folding_2(op, x, y); | ||
101 | - if (!(def->flags & TCG_OPF_64BIT)) { | ||
102 | + if (type == TCG_TYPE_I32) { | ||
103 | res = (int32_t)res; | ||
104 | } | ||
105 | return res; | ||
106 | @@ -XXX,XX +XXX,XX @@ static bool do_constant_folding_cond_eq(TCGCond c) | ||
107 | * Return -1 if the condition can't be simplified, | ||
108 | * and the result of the condition (0 or 1) if it can. | ||
109 | */ | ||
110 | -static int do_constant_folding_cond(TCGOpcode op, TCGArg x, | ||
111 | +static int do_constant_folding_cond(TCGType type, TCGArg x, | ||
112 | TCGArg y, TCGCond c) | ||
113 | { | ||
114 | uint64_t xv = arg_info(x)->val; | ||
115 | uint64_t yv = arg_info(y)->val; | ||
116 | |||
117 | if (arg_is_const(x) && arg_is_const(y)) { | ||
118 | - const TCGOpDef *def = &tcg_op_defs[op]; | ||
119 | - tcg_debug_assert(!(def->flags & TCG_OPF_VECTOR)); | ||
120 | - if (def->flags & TCG_OPF_64BIT) { | ||
121 | - return do_constant_folding_cond_64(xv, yv, c); | ||
122 | - } else { | ||
123 | + switch (type) { | ||
124 | + case TCG_TYPE_I32: | ||
125 | return do_constant_folding_cond_32(xv, yv, c); | ||
126 | + case TCG_TYPE_I64: | ||
127 | + return do_constant_folding_cond_64(xv, yv, c); | ||
128 | + default: | ||
129 | + /* Only scalar comparisons are optimizable */ | ||
130 | + return -1; | ||
131 | } | ||
132 | } else if (args_are_copies(x, y)) { | ||
133 | return do_constant_folding_cond_eq(c); | ||
134 | @@ -XXX,XX +XXX,XX @@ static bool fold_const1(OptContext *ctx, TCGOp *op) | ||
135 | uint64_t t; | ||
136 | |||
137 | t = arg_info(op->args[1])->val; | ||
138 | - t = do_constant_folding(op->opc, t, 0); | ||
139 | + t = do_constant_folding(op->opc, ctx->type, t, 0); | ||
140 | return tcg_opt_gen_movi(ctx, op, op->args[0], t); | ||
141 | } | ||
142 | return false; | ||
143 | @@ -XXX,XX +XXX,XX @@ static bool fold_const2(OptContext *ctx, TCGOp *op) | ||
144 | uint64_t t1 = arg_info(op->args[1])->val; | ||
145 | uint64_t t2 = arg_info(op->args[2])->val; | ||
146 | |||
147 | - t1 = do_constant_folding(op->opc, t1, t2); | ||
148 | + t1 = do_constant_folding(op->opc, ctx->type, t1, t2); | ||
149 | return tcg_opt_gen_movi(ctx, op, op->args[0], t1); | ||
150 | } | ||
151 | return false; | ||
152 | @@ -XXX,XX +XXX,XX @@ static bool fold_andc(OptContext *ctx, TCGOp *op) | ||
153 | static bool fold_brcond(OptContext *ctx, TCGOp *op) | ||
154 | { | ||
155 | TCGCond cond = op->args[2]; | ||
156 | - int i = do_constant_folding_cond(op->opc, op->args[0], op->args[1], cond); | ||
157 | + int i = do_constant_folding_cond(ctx->type, op->args[0], op->args[1], cond); | ||
158 | |||
159 | if (i == 0) { | ||
160 | tcg_op_remove(ctx->tcg, op); | ||
161 | @@ -XXX,XX +XXX,XX @@ static bool fold_brcond2(OptContext *ctx, TCGOp *op) | ||
162 | * Simplify EQ/NE comparisons where one of the pairs | ||
163 | * can be simplified. | ||
164 | */ | ||
165 | - i = do_constant_folding_cond(INDEX_op_brcond_i32, op->args[0], | ||
166 | + i = do_constant_folding_cond(TCG_TYPE_I32, op->args[0], | ||
167 | op->args[2], cond); | ||
168 | switch (i ^ inv) { | ||
169 | case 0: | ||
170 | @@ -XXX,XX +XXX,XX @@ static bool fold_brcond2(OptContext *ctx, TCGOp *op) | ||
171 | goto do_brcond_high; | ||
172 | } | ||
173 | |||
174 | - i = do_constant_folding_cond(INDEX_op_brcond_i32, op->args[1], | ||
175 | + i = do_constant_folding_cond(TCG_TYPE_I32, op->args[1], | ||
176 | op->args[3], cond); | ||
177 | switch (i ^ inv) { | ||
178 | case 0: | ||
179 | @@ -XXX,XX +XXX,XX @@ static bool fold_bswap(OptContext *ctx, TCGOp *op) | ||
180 | if (arg_is_const(op->args[1])) { | ||
181 | uint64_t t = arg_info(op->args[1])->val; | ||
182 | |||
183 | - t = do_constant_folding(op->opc, t, op->args[2]); | ||
184 | + t = do_constant_folding(op->opc, ctx->type, t, op->args[2]); | ||
185 | return tcg_opt_gen_movi(ctx, op, op->args[0], t); | ||
186 | } | ||
187 | return false; | ||
188 | @@ -XXX,XX +XXX,XX @@ static bool fold_count_zeros(OptContext *ctx, TCGOp *op) | ||
189 | uint64_t t = arg_info(op->args[1])->val; | ||
190 | |||
191 | if (t != 0) { | ||
192 | - t = do_constant_folding(op->opc, t, 0); | ||
193 | + t = do_constant_folding(op->opc, ctx->type, t, 0); | ||
194 | return tcg_opt_gen_movi(ctx, op, op->args[0], t); | ||
195 | } | ||
196 | return tcg_opt_gen_mov(ctx, op, op->args[0], op->args[2]); | ||
197 | @@ -XXX,XX +XXX,XX @@ static bool fold_mov(OptContext *ctx, TCGOp *op) | ||
198 | |||
199 | static bool fold_movcond(OptContext *ctx, TCGOp *op) | ||
200 | { | ||
201 | - TCGOpcode opc = op->opc; | ||
202 | TCGCond cond = op->args[5]; | ||
203 | - int i = do_constant_folding_cond(opc, op->args[1], op->args[2], cond); | ||
204 | + int i = do_constant_folding_cond(ctx->type, op->args[1], op->args[2], cond); | ||
205 | |||
206 | if (i >= 0) { | ||
207 | return tcg_opt_gen_mov(ctx, op, op->args[0], op->args[4 - i]); | ||
208 | @@ -XXX,XX +XXX,XX @@ static bool fold_movcond(OptContext *ctx, TCGOp *op) | ||
209 | if (arg_is_const(op->args[3]) && arg_is_const(op->args[4])) { | ||
210 | uint64_t tv = arg_info(op->args[3])->val; | ||
211 | uint64_t fv = arg_info(op->args[4])->val; | ||
212 | + TCGOpcode opc; | ||
213 | |||
214 | - opc = (opc == INDEX_op_movcond_i32 | ||
215 | - ? INDEX_op_setcond_i32 : INDEX_op_setcond_i64); | ||
216 | + switch (ctx->type) { | ||
217 | + case TCG_TYPE_I32: | ||
218 | + opc = INDEX_op_setcond_i32; | ||
219 | + break; | ||
220 | + case TCG_TYPE_I64: | ||
221 | + opc = INDEX_op_setcond_i64; | ||
222 | + break; | ||
223 | + default: | ||
224 | + g_assert_not_reached(); | ||
225 | + } | ||
226 | |||
227 | if (tv == 1 && fv == 0) { | ||
228 | op->opc = opc; | ||
229 | @@ -XXX,XX +XXX,XX @@ static bool fold_remainder(OptContext *ctx, TCGOp *op) | ||
230 | static bool fold_setcond(OptContext *ctx, TCGOp *op) | ||
231 | { | ||
232 | TCGCond cond = op->args[3]; | ||
233 | - int i = do_constant_folding_cond(op->opc, op->args[1], op->args[2], cond); | ||
234 | + int i = do_constant_folding_cond(ctx->type, op->args[1], op->args[2], cond); | ||
235 | |||
236 | if (i >= 0) { | ||
237 | return tcg_opt_gen_movi(ctx, op, op->args[0], i); | ||
238 | @@ -XXX,XX +XXX,XX @@ static bool fold_setcond2(OptContext *ctx, TCGOp *op) | ||
239 | * Simplify EQ/NE comparisons where one of the pairs | ||
240 | * can be simplified. | ||
241 | */ | ||
242 | - i = do_constant_folding_cond(INDEX_op_setcond_i32, op->args[1], | ||
243 | + i = do_constant_folding_cond(TCG_TYPE_I32, op->args[1], | ||
244 | op->args[3], cond); | ||
245 | switch (i ^ inv) { | ||
246 | case 0: | ||
247 | @@ -XXX,XX +XXX,XX @@ static bool fold_setcond2(OptContext *ctx, TCGOp *op) | ||
248 | goto do_setcond_high; | ||
249 | } | ||
250 | |||
251 | - i = do_constant_folding_cond(INDEX_op_setcond_i32, op->args[2], | ||
252 | + i = do_constant_folding_cond(TCG_TYPE_I32, op->args[2], | ||
253 | op->args[4], cond); | ||
254 | switch (i ^ inv) { | ||
255 | case 0: | ||
256 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
257 | init_arguments(&ctx, op, def->nb_oargs + def->nb_iargs); | ||
258 | copy_propagate(&ctx, op, def->nb_oargs, def->nb_iargs); | ||
259 | |||
260 | + /* Pre-compute the type of the operation. */ | ||
261 | + if (def->flags & TCG_OPF_VECTOR) { | ||
262 | + ctx.type = TCG_TYPE_V64 + TCGOP_VECL(op); | ||
263 | + } else if (def->flags & TCG_OPF_64BIT) { | ||
264 | + ctx.type = TCG_TYPE_I64; | ||
265 | + } else { | ||
266 | + ctx.type = TCG_TYPE_I32; | ||
267 | + } | ||
268 | + | ||
269 | /* For commutative operations make constant second argument */ | ||
270 | switch (opc) { | ||
271 | CASE_OP_32_64_VEC(add): | ||
272 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
273 | /* Proceed with possible constant folding. */ | ||
274 | break; | ||
275 | } | ||
276 | - if (opc == INDEX_op_sub_i32) { | ||
277 | + switch (ctx.type) { | ||
278 | + case TCG_TYPE_I32: | ||
279 | neg_op = INDEX_op_neg_i32; | ||
280 | have_neg = TCG_TARGET_HAS_neg_i32; | ||
281 | - } else if (opc == INDEX_op_sub_i64) { | ||
282 | + break; | ||
283 | + case TCG_TYPE_I64: | ||
284 | neg_op = INDEX_op_neg_i64; | ||
285 | have_neg = TCG_TARGET_HAS_neg_i64; | ||
286 | - } else if (TCG_TARGET_HAS_neg_vec) { | ||
287 | - TCGType type = TCGOP_VECL(op) + TCG_TYPE_V64; | ||
288 | - unsigned vece = TCGOP_VECE(op); | ||
289 | - neg_op = INDEX_op_neg_vec; | ||
290 | - have_neg = tcg_can_emit_vec_op(neg_op, type, vece) > 0; | ||
291 | - } else { | ||
292 | break; | ||
293 | + case TCG_TYPE_V64: | ||
294 | + case TCG_TYPE_V128: | ||
295 | + case TCG_TYPE_V256: | ||
296 | + neg_op = INDEX_op_neg_vec; | ||
297 | + have_neg = tcg_can_emit_vec_op(neg_op, ctx.type, | ||
298 | + TCGOP_VECE(op)) > 0; | ||
299 | + break; | ||
300 | + default: | ||
301 | + g_assert_not_reached(); | ||
302 | } | ||
303 | if (!have_neg) { | ||
304 | break; | ||
305 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
306 | TCGOpcode not_op; | ||
307 | bool have_not; | ||
308 | |||
309 | - if (def->flags & TCG_OPF_VECTOR) { | ||
310 | - not_op = INDEX_op_not_vec; | ||
311 | - have_not = TCG_TARGET_HAS_not_vec; | ||
312 | - } else if (def->flags & TCG_OPF_64BIT) { | ||
313 | - not_op = INDEX_op_not_i64; | ||
314 | - have_not = TCG_TARGET_HAS_not_i64; | ||
315 | - } else { | ||
316 | + switch (ctx.type) { | ||
317 | + case TCG_TYPE_I32: | ||
318 | not_op = INDEX_op_not_i32; | ||
319 | have_not = TCG_TARGET_HAS_not_i32; | ||
320 | + break; | ||
321 | + case TCG_TYPE_I64: | ||
322 | + not_op = INDEX_op_not_i64; | ||
323 | + have_not = TCG_TARGET_HAS_not_i64; | ||
324 | + break; | ||
325 | + case TCG_TYPE_V64: | ||
326 | + case TCG_TYPE_V128: | ||
327 | + case TCG_TYPE_V256: | ||
328 | + not_op = INDEX_op_not_vec; | ||
329 | + have_not = TCG_TARGET_HAS_not_vec; | ||
330 | + break; | ||
331 | + default: | ||
332 | + g_assert_not_reached(); | ||
333 | } | ||
334 | if (!have_not) { | ||
335 | break; | ||
336 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
337 | below, we can ignore high bits, but for further optimizations we | ||
338 | need to record that the high bits contain garbage. */ | ||
339 | partmask = z_mask; | ||
340 | - if (!(def->flags & TCG_OPF_64BIT)) { | ||
341 | + if (ctx.type == TCG_TYPE_I32) { | ||
342 | z_mask |= ~(tcg_target_ulong)0xffffffffu; | ||
343 | partmask &= 0xffffffffu; | ||
344 | affected &= 0xffffffffu; | ||
345 | -- | 39 | -- |
346 | 2.25.1 | 40 | 2.34.1 |
347 | 41 | ||
348 | 42 | diff view generated by jsdifflib |
1 | Recognize the constant function for remainder. | 1 | From: Anton Johansson via <qemu-devel@nongnu.org> |
---|---|---|---|
2 | 2 | ||
3 | Suggested-by: Luis Pires <luis.pires@eldorado.org.br> | 3 | Signed-off-by: Anton Johansson <anjo@rev.ng> |
4 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 4 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
5 | Message-Id: <20230227135202.9710-19-anjo@rev.ng> | ||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
6 | --- | 7 | --- |
7 | tcg/optimize.c | 6 +++++- | 8 | target/openrisc/cpu.c | 4 +++- |
8 | 1 file changed, 5 insertions(+), 1 deletion(-) | 9 | 1 file changed, 3 insertions(+), 1 deletion(-) |
9 | 10 | ||
10 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 11 | diff --git a/target/openrisc/cpu.c b/target/openrisc/cpu.c |
11 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
12 | --- a/tcg/optimize.c | 13 | --- a/target/openrisc/cpu.c |
13 | +++ b/tcg/optimize.c | 14 | +++ b/target/openrisc/cpu.c |
14 | @@ -XXX,XX +XXX,XX @@ static bool fold_qemu_st(OptContext *ctx, TCGOp *op) | 15 | @@ -XXX,XX +XXX,XX @@ |
15 | 16 | #include "qemu/qemu-print.h" | |
16 | static bool fold_remainder(OptContext *ctx, TCGOp *op) | 17 | #include "cpu.h" |
18 | #include "exec/exec-all.h" | ||
19 | +#include "tcg/tcg.h" | ||
20 | |||
21 | static void openrisc_cpu_set_pc(CPUState *cs, vaddr value) | ||
17 | { | 22 | { |
18 | - return fold_const2(ctx, op); | 23 | @@ -XXX,XX +XXX,XX @@ static void openrisc_cpu_synchronize_from_tb(CPUState *cs, |
19 | + if (fold_const2(ctx, op) || | 24 | { |
20 | + fold_xx_to_i(ctx, op, 0)) { | 25 | OpenRISCCPU *cpu = OPENRISC_CPU(cs); |
21 | + return true; | 26 | |
22 | + } | 27 | - cpu->env.pc = tb_pc(tb); |
23 | + return false; | 28 | + tcg_debug_assert(!(cs->tcg_cflags & CF_PCREL)); |
29 | + cpu->env.pc = tb->pc; | ||
24 | } | 30 | } |
25 | 31 | ||
26 | static bool fold_setcond(OptContext *ctx, TCGOp *op) | 32 | static void openrisc_restore_state_to_opc(CPUState *cs, |
27 | -- | 33 | -- |
28 | 2.25.1 | 34 | 2.34.1 |
29 | 35 | ||
30 | 36 | diff view generated by jsdifflib |
1 | Recognize the constant function for or-complement. | 1 | From: Anton Johansson via <qemu-devel@nongnu.org> |
---|---|---|---|
2 | 2 | ||
3 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 3 | Signed-off-by: Anton Johansson <anjo@rev.ng> |
4 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | 4 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 5 | Message-Id: <20230227135202.9710-20-anjo@rev.ng> |
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
7 | --- | 7 | --- |
8 | tcg/optimize.c | 1 + | 8 | target/mips/tcg/exception.c | 3 ++- |
9 | 1 file changed, 1 insertion(+) | 9 | target/mips/tcg/sysemu/special_helper.c | 2 +- |
10 | 2 files changed, 3 insertions(+), 2 deletions(-) | ||
10 | 11 | ||
11 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 12 | diff --git a/target/mips/tcg/exception.c b/target/mips/tcg/exception.c |
12 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/tcg/optimize.c | 14 | --- a/target/mips/tcg/exception.c |
14 | +++ b/tcg/optimize.c | 15 | +++ b/target/mips/tcg/exception.c |
15 | @@ -XXX,XX +XXX,XX @@ static bool fold_or(OptContext *ctx, TCGOp *op) | 16 | @@ -XXX,XX +XXX,XX @@ void mips_cpu_synchronize_from_tb(CPUState *cs, const TranslationBlock *tb) |
16 | static bool fold_orc(OptContext *ctx, TCGOp *op) | 17 | MIPSCPU *cpu = MIPS_CPU(cs); |
17 | { | 18 | CPUMIPSState *env = &cpu->env; |
18 | if (fold_const2(ctx, op) || | 19 | |
19 | + fold_xx_to_i(ctx, op, -1) || | 20 | - env->active_tc.PC = tb_pc(tb); |
20 | fold_xi_to_x(ctx, op, -1) || | 21 | + tcg_debug_assert(!(cs->tcg_cflags & CF_PCREL)); |
21 | fold_ix_to_not(ctx, op, 0)) { | 22 | + env->active_tc.PC = tb->pc; |
23 | env->hflags &= ~MIPS_HFLAG_BMASK; | ||
24 | env->hflags |= tb->flags & MIPS_HFLAG_BMASK; | ||
25 | } | ||
26 | diff --git a/target/mips/tcg/sysemu/special_helper.c b/target/mips/tcg/sysemu/special_helper.c | ||
27 | index XXXXXXX..XXXXXXX 100644 | ||
28 | --- a/target/mips/tcg/sysemu/special_helper.c | ||
29 | +++ b/target/mips/tcg/sysemu/special_helper.c | ||
30 | @@ -XXX,XX +XXX,XX @@ bool mips_io_recompile_replay_branch(CPUState *cs, const TranslationBlock *tb) | ||
31 | CPUMIPSState *env = &cpu->env; | ||
32 | |||
33 | if ((env->hflags & MIPS_HFLAG_BMASK) != 0 | ||
34 | - && env->active_tc.PC != tb_pc(tb)) { | ||
35 | + && !(cs->tcg_cflags & CF_PCREL) && env->active_tc.PC != tb->pc) { | ||
36 | env->active_tc.PC -= (env->hflags & MIPS_HFLAG_B16 ? 2 : 4); | ||
37 | env->hflags &= ~MIPS_HFLAG_BMASK; | ||
22 | return true; | 38 | return true; |
23 | -- | 39 | -- |
24 | 2.25.1 | 40 | 2.34.1 |
25 | 41 | ||
26 | 42 | diff view generated by jsdifflib |
1 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | 1 | From: Anton Johansson via <qemu-devel@nongnu.org> |
---|---|---|---|
2 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 2 | |
3 | Signed-off-by: Anton Johansson <anjo@rev.ng> | ||
4 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
5 | Message-Id: <20230227135202.9710-21-anjo@rev.ng> | ||
3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
4 | --- | 7 | --- |
5 | tcg/optimize.c | 39 ++++++++++++++++++++++----------------- | 8 | target/microblaze/cpu.c | 4 +++- |
6 | 1 file changed, 22 insertions(+), 17 deletions(-) | 9 | 1 file changed, 3 insertions(+), 1 deletion(-) |
7 | 10 | ||
8 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 11 | diff --git a/target/microblaze/cpu.c b/target/microblaze/cpu.c |
9 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
10 | --- a/tcg/optimize.c | 13 | --- a/target/microblaze/cpu.c |
11 | +++ b/tcg/optimize.c | 14 | +++ b/target/microblaze/cpu.c |
12 | @@ -XXX,XX +XXX,XX @@ static bool fold_eqv(OptContext *ctx, TCGOp *op) | 15 | @@ -XXX,XX +XXX,XX @@ |
13 | return fold_const2(ctx, op); | 16 | #include "exec/exec-all.h" |
17 | #include "exec/gdbstub.h" | ||
18 | #include "fpu/softfloat-helpers.h" | ||
19 | +#include "tcg/tcg.h" | ||
20 | |||
21 | static const struct { | ||
22 | const char *name; | ||
23 | @@ -XXX,XX +XXX,XX @@ static void mb_cpu_synchronize_from_tb(CPUState *cs, | ||
24 | { | ||
25 | MicroBlazeCPU *cpu = MICROBLAZE_CPU(cs); | ||
26 | |||
27 | - cpu->env.pc = tb_pc(tb); | ||
28 | + tcg_debug_assert(!(cs->tcg_cflags & CF_PCREL)); | ||
29 | + cpu->env.pc = tb->pc; | ||
30 | cpu->env.iflags = tb->flags & IFLAGS_TB_MASK; | ||
14 | } | 31 | } |
15 | 32 | ||
16 | +static bool fold_extract2(OptContext *ctx, TCGOp *op) | ||
17 | +{ | ||
18 | + if (arg_is_const(op->args[1]) && arg_is_const(op->args[2])) { | ||
19 | + uint64_t v1 = arg_info(op->args[1])->val; | ||
20 | + uint64_t v2 = arg_info(op->args[2])->val; | ||
21 | + int shr = op->args[3]; | ||
22 | + | ||
23 | + if (op->opc == INDEX_op_extract2_i64) { | ||
24 | + v1 >>= shr; | ||
25 | + v2 <<= 64 - shr; | ||
26 | + } else { | ||
27 | + v1 = (uint32_t)v1 >> shr; | ||
28 | + v2 = (int32_t)v2 << (32 - shr); | ||
29 | + } | ||
30 | + return tcg_opt_gen_movi(ctx, op, op->args[0], v1 | v2); | ||
31 | + } | ||
32 | + return false; | ||
33 | +} | ||
34 | + | ||
35 | static bool fold_exts(OptContext *ctx, TCGOp *op) | ||
36 | { | ||
37 | return fold_const1(ctx, op); | ||
38 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
39 | } | ||
40 | break; | ||
41 | |||
42 | - CASE_OP_32_64(extract2): | ||
43 | - if (arg_is_const(op->args[1]) && arg_is_const(op->args[2])) { | ||
44 | - uint64_t v1 = arg_info(op->args[1])->val; | ||
45 | - uint64_t v2 = arg_info(op->args[2])->val; | ||
46 | - int shr = op->args[3]; | ||
47 | - | ||
48 | - if (opc == INDEX_op_extract2_i64) { | ||
49 | - tmp = (v1 >> shr) | (v2 << (64 - shr)); | ||
50 | - } else { | ||
51 | - tmp = (int32_t)(((uint32_t)v1 >> shr) | | ||
52 | - ((uint32_t)v2 << (32 - shr))); | ||
53 | - } | ||
54 | - tcg_opt_gen_movi(&ctx, op, op->args[0], tmp); | ||
55 | - continue; | ||
56 | - } | ||
57 | - break; | ||
58 | - | ||
59 | default: | ||
60 | break; | ||
61 | |||
62 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
63 | CASE_OP_32_64(eqv): | ||
64 | done = fold_eqv(&ctx, op); | ||
65 | break; | ||
66 | + CASE_OP_32_64(extract2): | ||
67 | + done = fold_extract2(&ctx, op); | ||
68 | + break; | ||
69 | CASE_OP_32_64(ext8s): | ||
70 | CASE_OP_32_64(ext16s): | ||
71 | case INDEX_op_ext32s_i64: | ||
72 | -- | 33 | -- |
73 | 2.25.1 | 34 | 2.34.1 |
74 | 35 | ||
75 | 36 | diff view generated by jsdifflib |
1 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | 1 | From: Anton Johansson via <qemu-devel@nongnu.org> |
---|---|---|---|
2 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 2 | |
3 | Signed-off-by: Anton Johansson <anjo@rev.ng> | ||
4 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
5 | Message-Id: <20230227135202.9710-22-anjo@rev.ng> | ||
3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
4 | --- | 7 | --- |
5 | tcg/optimize.c | 56 ++++++++++++++++++++++++++++---------------------- | 8 | target/loongarch/cpu.c | 6 ++++-- |
6 | 1 file changed, 31 insertions(+), 25 deletions(-) | 9 | 1 file changed, 4 insertions(+), 2 deletions(-) |
7 | 10 | ||
8 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 11 | diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c |
9 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
10 | --- a/tcg/optimize.c | 13 | --- a/target/loongarch/cpu.c |
11 | +++ b/tcg/optimize.c | 14 | +++ b/target/loongarch/cpu.c |
12 | @@ -XXX,XX +XXX,XX @@ static bool fold_mb(OptContext *ctx, TCGOp *op) | 15 | @@ -XXX,XX +XXX,XX @@ |
13 | return true; | 16 | #include "fpu/softfloat-helpers.h" |
17 | #include "cpu-csr.h" | ||
18 | #include "sysemu/reset.h" | ||
19 | +#include "tcg/tcg.h" | ||
20 | |||
21 | const char * const regnames[32] = { | ||
22 | "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", | ||
23 | @@ -XXX,XX +XXX,XX @@ static void loongarch_cpu_synchronize_from_tb(CPUState *cs, | ||
24 | LoongArchCPU *cpu = LOONGARCH_CPU(cs); | ||
25 | CPULoongArchState *env = &cpu->env; | ||
26 | |||
27 | - env->pc = tb_pc(tb); | ||
28 | + tcg_debug_assert(!(cs->tcg_cflags & CF_PCREL)); | ||
29 | + env->pc = tb->pc; | ||
14 | } | 30 | } |
15 | 31 | ||
16 | +static bool fold_movcond(OptContext *ctx, TCGOp *op) | 32 | static void loongarch_restore_state_to_opc(CPUState *cs, |
17 | +{ | 33 | @@ -XXX,XX +XXX,XX @@ static ObjectClass *loongarch_cpu_class_by_name(const char *cpu_model) |
18 | + TCGOpcode opc = op->opc; | 34 | |
19 | + TCGCond cond = op->args[5]; | 35 | oc = object_class_by_name(cpu_model); |
20 | + int i = do_constant_folding_cond(opc, op->args[1], op->args[2], cond); | 36 | if (!oc) { |
21 | + | 37 | - g_autofree char *typename |
22 | + if (i >= 0) { | 38 | + g_autofree char *typename |
23 | + return tcg_opt_gen_mov(ctx, op, op->args[0], op->args[4 - i]); | 39 | = g_strdup_printf(LOONGARCH_CPU_TYPE_NAME("%s"), cpu_model); |
24 | + } | 40 | oc = object_class_by_name(typename); |
25 | + | 41 | if (!oc) { |
26 | + if (arg_is_const(op->args[3]) && arg_is_const(op->args[4])) { | ||
27 | + uint64_t tv = arg_info(op->args[3])->val; | ||
28 | + uint64_t fv = arg_info(op->args[4])->val; | ||
29 | + | ||
30 | + opc = (opc == INDEX_op_movcond_i32 | ||
31 | + ? INDEX_op_setcond_i32 : INDEX_op_setcond_i64); | ||
32 | + | ||
33 | + if (tv == 1 && fv == 0) { | ||
34 | + op->opc = opc; | ||
35 | + op->args[3] = cond; | ||
36 | + } else if (fv == 1 && tv == 0) { | ||
37 | + op->opc = opc; | ||
38 | + op->args[3] = tcg_invert_cond(cond); | ||
39 | + } | ||
40 | + } | ||
41 | + return false; | ||
42 | +} | ||
43 | + | ||
44 | static bool fold_mul(OptContext *ctx, TCGOp *op) | ||
45 | { | ||
46 | return fold_const2(ctx, op); | ||
47 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
48 | } | ||
49 | break; | ||
50 | |||
51 | - CASE_OP_32_64(movcond): | ||
52 | - i = do_constant_folding_cond(opc, op->args[1], | ||
53 | - op->args[2], op->args[5]); | ||
54 | - if (i >= 0) { | ||
55 | - tcg_opt_gen_mov(&ctx, op, op->args[0], op->args[4 - i]); | ||
56 | - continue; | ||
57 | - } | ||
58 | - if (arg_is_const(op->args[3]) && arg_is_const(op->args[4])) { | ||
59 | - uint64_t tv = arg_info(op->args[3])->val; | ||
60 | - uint64_t fv = arg_info(op->args[4])->val; | ||
61 | - TCGCond cond = op->args[5]; | ||
62 | - | ||
63 | - if (fv == 1 && tv == 0) { | ||
64 | - cond = tcg_invert_cond(cond); | ||
65 | - } else if (!(tv == 1 && fv == 0)) { | ||
66 | - break; | ||
67 | - } | ||
68 | - op->args[3] = cond; | ||
69 | - op->opc = opc = (opc == INDEX_op_movcond_i32 | ||
70 | - ? INDEX_op_setcond_i32 | ||
71 | - : INDEX_op_setcond_i64); | ||
72 | - } | ||
73 | - break; | ||
74 | - | ||
75 | - | ||
76 | default: | ||
77 | break; | ||
78 | |||
79 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
80 | case INDEX_op_mb: | ||
81 | done = fold_mb(&ctx, op); | ||
82 | break; | ||
83 | + CASE_OP_32_64(movcond): | ||
84 | + done = fold_movcond(&ctx, op); | ||
85 | + break; | ||
86 | CASE_OP_32_64(mul): | ||
87 | done = fold_mul(&ctx, op); | ||
88 | break; | ||
89 | -- | 42 | -- |
90 | 2.25.1 | 43 | 2.34.1 |
91 | 44 | ||
92 | 45 | diff view generated by jsdifflib |
1 | Return -1 instead of 2 for failure, so that we can | 1 | From: Anton Johansson via <qemu-devel@nongnu.org> |
---|---|---|---|
2 | use comparisons against 0 for all cases. | ||
3 | 2 | ||
4 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | 3 | Signed-off-by: Anton Johansson <anjo@rev.ng> |
5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 4 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
5 | Message-Id: <20230227135202.9710-23-anjo@rev.ng> | ||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
7 | --- | 7 | --- |
8 | tcg/optimize.c | 145 +++++++++++++++++++++++++------------------------ | 8 | target/i386/tcg/tcg-cpu.c | 2 +- |
9 | 1 file changed, 74 insertions(+), 71 deletions(-) | 9 | 1 file changed, 1 insertion(+), 1 deletion(-) |
10 | 10 | ||
11 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 11 | diff --git a/target/i386/tcg/tcg-cpu.c b/target/i386/tcg/tcg-cpu.c |
12 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/tcg/optimize.c | 13 | --- a/target/i386/tcg/tcg-cpu.c |
14 | +++ b/tcg/optimize.c | 14 | +++ b/target/i386/tcg/tcg-cpu.c |
15 | @@ -XXX,XX +XXX,XX @@ static bool do_constant_folding_cond_eq(TCGCond c) | 15 | @@ -XXX,XX +XXX,XX @@ static void x86_cpu_synchronize_from_tb(CPUState *cs, |
16 | /* The instruction pointer is always up to date with CF_PCREL. */ | ||
17 | if (!(tb_cflags(tb) & CF_PCREL)) { | ||
18 | CPUX86State *env = cs->env_ptr; | ||
19 | - env->eip = tb_pc(tb) - tb->cs_base; | ||
20 | + env->eip = tb->pc - tb->cs_base; | ||
16 | } | 21 | } |
17 | } | 22 | } |
18 | 23 | ||
19 | -/* Return 2 if the condition can't be simplified, and the result | ||
20 | - of the condition (0 or 1) if it can */ | ||
21 | -static TCGArg do_constant_folding_cond(TCGOpcode op, TCGArg x, | ||
22 | - TCGArg y, TCGCond c) | ||
23 | +/* | ||
24 | + * Return -1 if the condition can't be simplified, | ||
25 | + * and the result of the condition (0 or 1) if it can. | ||
26 | + */ | ||
27 | +static int do_constant_folding_cond(TCGOpcode op, TCGArg x, | ||
28 | + TCGArg y, TCGCond c) | ||
29 | { | ||
30 | uint64_t xv = arg_info(x)->val; | ||
31 | uint64_t yv = arg_info(y)->val; | ||
32 | @@ -XXX,XX +XXX,XX @@ static TCGArg do_constant_folding_cond(TCGOpcode op, TCGArg x, | ||
33 | case TCG_COND_GEU: | ||
34 | return 1; | ||
35 | default: | ||
36 | - return 2; | ||
37 | + return -1; | ||
38 | } | ||
39 | } | ||
40 | - return 2; | ||
41 | + return -1; | ||
42 | } | ||
43 | |||
44 | -/* Return 2 if the condition can't be simplified, and the result | ||
45 | - of the condition (0 or 1) if it can */ | ||
46 | -static TCGArg do_constant_folding_cond2(TCGArg *p1, TCGArg *p2, TCGCond c) | ||
47 | +/* | ||
48 | + * Return -1 if the condition can't be simplified, | ||
49 | + * and the result of the condition (0 or 1) if it can. | ||
50 | + */ | ||
51 | +static int do_constant_folding_cond2(TCGArg *p1, TCGArg *p2, TCGCond c) | ||
52 | { | ||
53 | TCGArg al = p1[0], ah = p1[1]; | ||
54 | TCGArg bl = p2[0], bh = p2[1]; | ||
55 | @@ -XXX,XX +XXX,XX @@ static TCGArg do_constant_folding_cond2(TCGArg *p1, TCGArg *p2, TCGCond c) | ||
56 | if (args_are_copies(al, bl) && args_are_copies(ah, bh)) { | ||
57 | return do_constant_folding_cond_eq(c); | ||
58 | } | ||
59 | - return 2; | ||
60 | + return -1; | ||
61 | } | ||
62 | |||
63 | static bool swap_commutative(TCGArg dest, TCGArg *p1, TCGArg *p2) | ||
64 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
65 | break; | ||
66 | |||
67 | CASE_OP_32_64(setcond): | ||
68 | - tmp = do_constant_folding_cond(opc, op->args[1], | ||
69 | - op->args[2], op->args[3]); | ||
70 | - if (tmp != 2) { | ||
71 | - tcg_opt_gen_movi(&ctx, op, op->args[0], tmp); | ||
72 | + i = do_constant_folding_cond(opc, op->args[1], | ||
73 | + op->args[2], op->args[3]); | ||
74 | + if (i >= 0) { | ||
75 | + tcg_opt_gen_movi(&ctx, op, op->args[0], i); | ||
76 | continue; | ||
77 | } | ||
78 | break; | ||
79 | |||
80 | CASE_OP_32_64(brcond): | ||
81 | - tmp = do_constant_folding_cond(opc, op->args[0], | ||
82 | - op->args[1], op->args[2]); | ||
83 | - switch (tmp) { | ||
84 | - case 0: | ||
85 | + i = do_constant_folding_cond(opc, op->args[0], | ||
86 | + op->args[1], op->args[2]); | ||
87 | + if (i == 0) { | ||
88 | tcg_op_remove(s, op); | ||
89 | continue; | ||
90 | - case 1: | ||
91 | + } else if (i > 0) { | ||
92 | memset(&ctx.temps_used, 0, sizeof(ctx.temps_used)); | ||
93 | op->opc = opc = INDEX_op_br; | ||
94 | op->args[0] = op->args[3]; | ||
95 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
96 | break; | ||
97 | |||
98 | CASE_OP_32_64(movcond): | ||
99 | - tmp = do_constant_folding_cond(opc, op->args[1], | ||
100 | - op->args[2], op->args[5]); | ||
101 | - if (tmp != 2) { | ||
102 | - tcg_opt_gen_mov(&ctx, op, op->args[0], op->args[4-tmp]); | ||
103 | + i = do_constant_folding_cond(opc, op->args[1], | ||
104 | + op->args[2], op->args[5]); | ||
105 | + if (i >= 0) { | ||
106 | + tcg_opt_gen_mov(&ctx, op, op->args[0], op->args[4 - i]); | ||
107 | continue; | ||
108 | } | ||
109 | if (arg_is_const(op->args[3]) && arg_is_const(op->args[4])) { | ||
110 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
111 | break; | ||
112 | |||
113 | case INDEX_op_brcond2_i32: | ||
114 | - tmp = do_constant_folding_cond2(&op->args[0], &op->args[2], | ||
115 | - op->args[4]); | ||
116 | - if (tmp == 0) { | ||
117 | + i = do_constant_folding_cond2(&op->args[0], &op->args[2], | ||
118 | + op->args[4]); | ||
119 | + if (i == 0) { | ||
120 | do_brcond_false: | ||
121 | tcg_op_remove(s, op); | ||
122 | continue; | ||
123 | } | ||
124 | - if (tmp == 1) { | ||
125 | + if (i > 0) { | ||
126 | do_brcond_true: | ||
127 | op->opc = opc = INDEX_op_br; | ||
128 | op->args[0] = op->args[5]; | ||
129 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
130 | if (op->args[4] == TCG_COND_EQ) { | ||
131 | /* Simplify EQ comparisons where one of the pairs | ||
132 | can be simplified. */ | ||
133 | - tmp = do_constant_folding_cond(INDEX_op_brcond_i32, | ||
134 | - op->args[0], op->args[2], | ||
135 | - TCG_COND_EQ); | ||
136 | - if (tmp == 0) { | ||
137 | + i = do_constant_folding_cond(INDEX_op_brcond_i32, | ||
138 | + op->args[0], op->args[2], | ||
139 | + TCG_COND_EQ); | ||
140 | + if (i == 0) { | ||
141 | goto do_brcond_false; | ||
142 | - } else if (tmp == 1) { | ||
143 | + } else if (i > 0) { | ||
144 | goto do_brcond_high; | ||
145 | } | ||
146 | - tmp = do_constant_folding_cond(INDEX_op_brcond_i32, | ||
147 | - op->args[1], op->args[3], | ||
148 | - TCG_COND_EQ); | ||
149 | - if (tmp == 0) { | ||
150 | + i = do_constant_folding_cond(INDEX_op_brcond_i32, | ||
151 | + op->args[1], op->args[3], | ||
152 | + TCG_COND_EQ); | ||
153 | + if (i == 0) { | ||
154 | goto do_brcond_false; | ||
155 | - } else if (tmp != 1) { | ||
156 | + } else if (i < 0) { | ||
157 | break; | ||
158 | } | ||
159 | do_brcond_low: | ||
160 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
161 | if (op->args[4] == TCG_COND_NE) { | ||
162 | /* Simplify NE comparisons where one of the pairs | ||
163 | can be simplified. */ | ||
164 | - tmp = do_constant_folding_cond(INDEX_op_brcond_i32, | ||
165 | - op->args[0], op->args[2], | ||
166 | - TCG_COND_NE); | ||
167 | - if (tmp == 0) { | ||
168 | + i = do_constant_folding_cond(INDEX_op_brcond_i32, | ||
169 | + op->args[0], op->args[2], | ||
170 | + TCG_COND_NE); | ||
171 | + if (i == 0) { | ||
172 | goto do_brcond_high; | ||
173 | - } else if (tmp == 1) { | ||
174 | + } else if (i > 0) { | ||
175 | goto do_brcond_true; | ||
176 | } | ||
177 | - tmp = do_constant_folding_cond(INDEX_op_brcond_i32, | ||
178 | - op->args[1], op->args[3], | ||
179 | - TCG_COND_NE); | ||
180 | - if (tmp == 0) { | ||
181 | + i = do_constant_folding_cond(INDEX_op_brcond_i32, | ||
182 | + op->args[1], op->args[3], | ||
183 | + TCG_COND_NE); | ||
184 | + if (i == 0) { | ||
185 | goto do_brcond_low; | ||
186 | - } else if (tmp == 1) { | ||
187 | + } else if (i > 0) { | ||
188 | goto do_brcond_true; | ||
189 | } | ||
190 | } | ||
191 | break; | ||
192 | |||
193 | case INDEX_op_setcond2_i32: | ||
194 | - tmp = do_constant_folding_cond2(&op->args[1], &op->args[3], | ||
195 | - op->args[5]); | ||
196 | - if (tmp != 2) { | ||
197 | + i = do_constant_folding_cond2(&op->args[1], &op->args[3], | ||
198 | + op->args[5]); | ||
199 | + if (i >= 0) { | ||
200 | do_setcond_const: | ||
201 | - tcg_opt_gen_movi(&ctx, op, op->args[0], tmp); | ||
202 | + tcg_opt_gen_movi(&ctx, op, op->args[0], i); | ||
203 | continue; | ||
204 | } | ||
205 | if ((op->args[5] == TCG_COND_LT || op->args[5] == TCG_COND_GE) | ||
206 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
207 | if (op->args[5] == TCG_COND_EQ) { | ||
208 | /* Simplify EQ comparisons where one of the pairs | ||
209 | can be simplified. */ | ||
210 | - tmp = do_constant_folding_cond(INDEX_op_setcond_i32, | ||
211 | - op->args[1], op->args[3], | ||
212 | - TCG_COND_EQ); | ||
213 | - if (tmp == 0) { | ||
214 | + i = do_constant_folding_cond(INDEX_op_setcond_i32, | ||
215 | + op->args[1], op->args[3], | ||
216 | + TCG_COND_EQ); | ||
217 | + if (i == 0) { | ||
218 | goto do_setcond_const; | ||
219 | - } else if (tmp == 1) { | ||
220 | + } else if (i > 0) { | ||
221 | goto do_setcond_high; | ||
222 | } | ||
223 | - tmp = do_constant_folding_cond(INDEX_op_setcond_i32, | ||
224 | - op->args[2], op->args[4], | ||
225 | - TCG_COND_EQ); | ||
226 | - if (tmp == 0) { | ||
227 | + i = do_constant_folding_cond(INDEX_op_setcond_i32, | ||
228 | + op->args[2], op->args[4], | ||
229 | + TCG_COND_EQ); | ||
230 | + if (i == 0) { | ||
231 | goto do_setcond_high; | ||
232 | - } else if (tmp != 1) { | ||
233 | + } else if (i < 0) { | ||
234 | break; | ||
235 | } | ||
236 | do_setcond_low: | ||
237 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
238 | if (op->args[5] == TCG_COND_NE) { | ||
239 | /* Simplify NE comparisons where one of the pairs | ||
240 | can be simplified. */ | ||
241 | - tmp = do_constant_folding_cond(INDEX_op_setcond_i32, | ||
242 | - op->args[1], op->args[3], | ||
243 | - TCG_COND_NE); | ||
244 | - if (tmp == 0) { | ||
245 | + i = do_constant_folding_cond(INDEX_op_setcond_i32, | ||
246 | + op->args[1], op->args[3], | ||
247 | + TCG_COND_NE); | ||
248 | + if (i == 0) { | ||
249 | goto do_setcond_high; | ||
250 | - } else if (tmp == 1) { | ||
251 | + } else if (i > 0) { | ||
252 | goto do_setcond_const; | ||
253 | } | ||
254 | - tmp = do_constant_folding_cond(INDEX_op_setcond_i32, | ||
255 | - op->args[2], op->args[4], | ||
256 | - TCG_COND_NE); | ||
257 | - if (tmp == 0) { | ||
258 | + i = do_constant_folding_cond(INDEX_op_setcond_i32, | ||
259 | + op->args[2], op->args[4], | ||
260 | + TCG_COND_NE); | ||
261 | + if (i == 0) { | ||
262 | goto do_setcond_low; | ||
263 | - } else if (tmp == 1) { | ||
264 | + } else if (i > 0) { | ||
265 | goto do_setcond_const; | ||
266 | } | ||
267 | } | ||
268 | -- | 24 | -- |
269 | 2.25.1 | 25 | 2.34.1 |
270 | 26 | ||
271 | 27 | diff view generated by jsdifflib |
1 | Add two additional helpers, fold_add2_i32 and fold_sub2_i32 | 1 | From: Anton Johansson via <qemu-devel@nongnu.org> |
---|---|---|---|
2 | which will not be simple wrappers forever. | ||
3 | 2 | ||
4 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | 3 | Signed-off-by: Anton Johansson <anjo@rev.ng> |
5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 4 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
5 | Message-Id: <20230227135202.9710-24-anjo@rev.ng> | ||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
7 | --- | 7 | --- |
8 | tcg/optimize.c | 70 +++++++++++++++++++++++++++++++------------------- | 8 | target/hppa/cpu.c | 8 +++++--- |
9 | 1 file changed, 44 insertions(+), 26 deletions(-) | 9 | 1 file changed, 5 insertions(+), 3 deletions(-) |
10 | 10 | ||
11 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 11 | diff --git a/target/hppa/cpu.c b/target/hppa/cpu.c |
12 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/tcg/optimize.c | 13 | --- a/target/hppa/cpu.c |
14 | +++ b/tcg/optimize.c | 14 | +++ b/target/hppa/cpu.c |
15 | @@ -XXX,XX +XXX,XX @@ static bool fold_add(OptContext *ctx, TCGOp *op) | 15 | @@ -XXX,XX +XXX,XX @@ |
16 | return fold_const2(ctx, op); | 16 | #include "qemu/module.h" |
17 | } | 17 | #include "exec/exec-all.h" |
18 | 18 | #include "fpu/softfloat.h" | |
19 | +static bool fold_addsub2_i32(OptContext *ctx, TCGOp *op, bool add) | 19 | - |
20 | +{ | 20 | +#include "tcg/tcg.h" |
21 | + if (arg_is_const(op->args[2]) && arg_is_const(op->args[3]) && | 21 | |
22 | + arg_is_const(op->args[4]) && arg_is_const(op->args[5])) { | 22 | static void hppa_cpu_set_pc(CPUState *cs, vaddr value) |
23 | + uint32_t al = arg_info(op->args[2])->val; | 23 | { |
24 | + uint32_t ah = arg_info(op->args[3])->val; | 24 | @@ -XXX,XX +XXX,XX @@ static void hppa_cpu_synchronize_from_tb(CPUState *cs, |
25 | + uint32_t bl = arg_info(op->args[4])->val; | 25 | { |
26 | + uint32_t bh = arg_info(op->args[5])->val; | 26 | HPPACPU *cpu = HPPA_CPU(cs); |
27 | + uint64_t a = ((uint64_t)ah << 32) | al; | 27 | |
28 | + uint64_t b = ((uint64_t)bh << 32) | bl; | 28 | + tcg_debug_assert(!(cs->tcg_cflags & CF_PCREL)); |
29 | + TCGArg rl, rh; | ||
30 | + TCGOp *op2 = tcg_op_insert_before(ctx->tcg, op, INDEX_op_mov_i32); | ||
31 | + | 29 | + |
32 | + if (add) { | 30 | #ifdef CONFIG_USER_ONLY |
33 | + a += b; | 31 | - cpu->env.iaoq_f = tb_pc(tb); |
34 | + } else { | 32 | + cpu->env.iaoq_f = tb->pc; |
35 | + a -= b; | 33 | cpu->env.iaoq_b = tb->cs_base; |
36 | + } | 34 | #else |
37 | + | 35 | /* Recover the IAOQ values from the GVA + PRIV. */ |
38 | + rl = op->args[0]; | 36 | @@ -XXX,XX +XXX,XX @@ static void hppa_cpu_synchronize_from_tb(CPUState *cs, |
39 | + rh = op->args[1]; | 37 | int32_t diff = cs_base; |
40 | + tcg_opt_gen_movi(ctx, op, rl, (int32_t)a); | 38 | |
41 | + tcg_opt_gen_movi(ctx, op2, rh, (int32_t)(a >> 32)); | 39 | cpu->env.iasq_f = iasq_f; |
42 | + return true; | 40 | - cpu->env.iaoq_f = (tb_pc(tb) & ~iasq_f) + priv; |
43 | + } | 41 | + cpu->env.iaoq_f = (tb->pc & ~iasq_f) + priv; |
44 | + return false; | 42 | if (diff) { |
45 | +} | 43 | cpu->env.iaoq_b = cpu->env.iaoq_f + diff; |
46 | + | 44 | } |
47 | +static bool fold_add2_i32(OptContext *ctx, TCGOp *op) | ||
48 | +{ | ||
49 | + return fold_addsub2_i32(ctx, op, true); | ||
50 | +} | ||
51 | + | ||
52 | static bool fold_and(OptContext *ctx, TCGOp *op) | ||
53 | { | ||
54 | return fold_const2(ctx, op); | ||
55 | @@ -XXX,XX +XXX,XX @@ static bool fold_sub(OptContext *ctx, TCGOp *op) | ||
56 | return fold_const2(ctx, op); | ||
57 | } | ||
58 | |||
59 | +static bool fold_sub2_i32(OptContext *ctx, TCGOp *op) | ||
60 | +{ | ||
61 | + return fold_addsub2_i32(ctx, op, false); | ||
62 | +} | ||
63 | + | ||
64 | static bool fold_xor(OptContext *ctx, TCGOp *op) | ||
65 | { | ||
66 | return fold_const2(ctx, op); | ||
67 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
68 | } | ||
69 | break; | ||
70 | |||
71 | - case INDEX_op_add2_i32: | ||
72 | - case INDEX_op_sub2_i32: | ||
73 | - if (arg_is_const(op->args[2]) && arg_is_const(op->args[3]) | ||
74 | - && arg_is_const(op->args[4]) && arg_is_const(op->args[5])) { | ||
75 | - uint32_t al = arg_info(op->args[2])->val; | ||
76 | - uint32_t ah = arg_info(op->args[3])->val; | ||
77 | - uint32_t bl = arg_info(op->args[4])->val; | ||
78 | - uint32_t bh = arg_info(op->args[5])->val; | ||
79 | - uint64_t a = ((uint64_t)ah << 32) | al; | ||
80 | - uint64_t b = ((uint64_t)bh << 32) | bl; | ||
81 | - TCGArg rl, rh; | ||
82 | - TCGOp *op2 = tcg_op_insert_before(s, op, INDEX_op_mov_i32); | ||
83 | - | ||
84 | - if (opc == INDEX_op_add2_i32) { | ||
85 | - a += b; | ||
86 | - } else { | ||
87 | - a -= b; | ||
88 | - } | ||
89 | - | ||
90 | - rl = op->args[0]; | ||
91 | - rh = op->args[1]; | ||
92 | - tcg_opt_gen_movi(&ctx, op, rl, (int32_t)a); | ||
93 | - tcg_opt_gen_movi(&ctx, op2, rh, (int32_t)(a >> 32)); | ||
94 | - continue; | ||
95 | - } | ||
96 | - break; | ||
97 | |||
98 | default: | ||
99 | break; | ||
100 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
101 | CASE_OP_32_64_VEC(add): | ||
102 | done = fold_add(&ctx, op); | ||
103 | break; | ||
104 | + case INDEX_op_add2_i32: | ||
105 | + done = fold_add2_i32(&ctx, op); | ||
106 | + break; | ||
107 | CASE_OP_32_64_VEC(and): | ||
108 | done = fold_and(&ctx, op); | ||
109 | break; | ||
110 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
111 | CASE_OP_32_64_VEC(sub): | ||
112 | done = fold_sub(&ctx, op); | ||
113 | break; | ||
114 | + case INDEX_op_sub2_i32: | ||
115 | + done = fold_sub2_i32(&ctx, op); | ||
116 | + break; | ||
117 | CASE_OP_32_64_VEC(xor): | ||
118 | done = fold_xor(&ctx, op); | ||
119 | break; | ||
120 | -- | 45 | -- |
121 | 2.25.1 | 46 | 2.34.1 |
122 | 47 | ||
123 | 48 | diff view generated by jsdifflib |
1 | Rename to fold_multiply2, and handle muls2_i32, mulu2_i64, | 1 | From: Anton Johansson via <qemu-devel@nongnu.org> |
---|---|---|---|
2 | and muls2_i64. | ||
3 | 2 | ||
4 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | 3 | Signed-off-by: Anton Johansson <anjo@rev.ng> |
5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 4 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
5 | Reviewed-by: Taylor Simpson <tsimpson@quicinc.com> | ||
6 | Message-Id: <20230227135202.9710-25-anjo@rev.ng> | ||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
7 | --- | 8 | --- |
8 | tcg/optimize.c | 44 +++++++++++++++++++++++++++++++++++--------- | 9 | target/hexagon/cpu.c | 4 +++- |
9 | 1 file changed, 35 insertions(+), 9 deletions(-) | 10 | 1 file changed, 3 insertions(+), 1 deletion(-) |
10 | 11 | ||
11 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 12 | diff --git a/target/hexagon/cpu.c b/target/hexagon/cpu.c |
12 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/tcg/optimize.c | 14 | --- a/target/hexagon/cpu.c |
14 | +++ b/tcg/optimize.c | 15 | +++ b/target/hexagon/cpu.c |
15 | @@ -XXX,XX +XXX,XX @@ static bool fold_mul_highpart(OptContext *ctx, TCGOp *op) | 16 | @@ -XXX,XX +XXX,XX @@ |
16 | return false; | 17 | #include "qapi/error.h" |
18 | #include "hw/qdev-properties.h" | ||
19 | #include "fpu/softfloat-helpers.h" | ||
20 | +#include "tcg/tcg.h" | ||
21 | |||
22 | static void hexagon_v67_cpu_init(Object *obj) | ||
23 | { | ||
24 | @@ -XXX,XX +XXX,XX @@ static void hexagon_cpu_synchronize_from_tb(CPUState *cs, | ||
25 | { | ||
26 | HexagonCPU *cpu = HEXAGON_CPU(cs); | ||
27 | CPUHexagonState *env = &cpu->env; | ||
28 | - env->gpr[HEX_REG_PC] = tb_pc(tb); | ||
29 | + tcg_debug_assert(!(cs->tcg_cflags & CF_PCREL)); | ||
30 | + env->gpr[HEX_REG_PC] = tb->pc; | ||
17 | } | 31 | } |
18 | 32 | ||
19 | -static bool fold_mulu2_i32(OptContext *ctx, TCGOp *op) | 33 | static bool hexagon_cpu_has_work(CPUState *cs) |
20 | +static bool fold_multiply2(OptContext *ctx, TCGOp *op) | ||
21 | { | ||
22 | if (arg_is_const(op->args[2]) && arg_is_const(op->args[3])) { | ||
23 | - uint32_t a = arg_info(op->args[2])->val; | ||
24 | - uint32_t b = arg_info(op->args[3])->val; | ||
25 | - uint64_t r = (uint64_t)a * b; | ||
26 | + uint64_t a = arg_info(op->args[2])->val; | ||
27 | + uint64_t b = arg_info(op->args[3])->val; | ||
28 | + uint64_t h, l; | ||
29 | TCGArg rl, rh; | ||
30 | - TCGOp *op2 = tcg_op_insert_before(ctx->tcg, op, INDEX_op_mov_i32); | ||
31 | + TCGOp *op2; | ||
32 | + | ||
33 | + switch (op->opc) { | ||
34 | + case INDEX_op_mulu2_i32: | ||
35 | + l = (uint64_t)(uint32_t)a * (uint32_t)b; | ||
36 | + h = (int32_t)(l >> 32); | ||
37 | + l = (int32_t)l; | ||
38 | + break; | ||
39 | + case INDEX_op_muls2_i32: | ||
40 | + l = (int64_t)(int32_t)a * (int32_t)b; | ||
41 | + h = l >> 32; | ||
42 | + l = (int32_t)l; | ||
43 | + break; | ||
44 | + case INDEX_op_mulu2_i64: | ||
45 | + mulu64(&l, &h, a, b); | ||
46 | + break; | ||
47 | + case INDEX_op_muls2_i64: | ||
48 | + muls64(&l, &h, a, b); | ||
49 | + break; | ||
50 | + default: | ||
51 | + g_assert_not_reached(); | ||
52 | + } | ||
53 | |||
54 | rl = op->args[0]; | ||
55 | rh = op->args[1]; | ||
56 | - tcg_opt_gen_movi(ctx, op, rl, (int32_t)r); | ||
57 | - tcg_opt_gen_movi(ctx, op2, rh, (int32_t)(r >> 32)); | ||
58 | + | ||
59 | + /* The proper opcode is supplied by tcg_opt_gen_mov. */ | ||
60 | + op2 = tcg_op_insert_before(ctx->tcg, op, 0); | ||
61 | + | ||
62 | + tcg_opt_gen_movi(ctx, op, rl, l); | ||
63 | + tcg_opt_gen_movi(ctx, op2, rh, h); | ||
64 | return true; | ||
65 | } | ||
66 | return false; | ||
67 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
68 | CASE_OP_32_64(muluh): | ||
69 | done = fold_mul_highpart(&ctx, op); | ||
70 | break; | ||
71 | - case INDEX_op_mulu2_i32: | ||
72 | - done = fold_mulu2_i32(&ctx, op); | ||
73 | + CASE_OP_32_64(muls2): | ||
74 | + CASE_OP_32_64(mulu2): | ||
75 | + done = fold_multiply2(&ctx, op); | ||
76 | break; | ||
77 | CASE_OP_32_64(nand): | ||
78 | done = fold_nand(&ctx, op); | ||
79 | -- | 34 | -- |
80 | 2.25.1 | 35 | 2.34.1 |
81 | 36 | ||
82 | 37 | diff view generated by jsdifflib |
1 | Recognize the identity function for low-part multiply. | 1 | From: Anton Johansson via <qemu-devel@nongnu.org> |
---|---|---|---|
2 | 2 | ||
3 | Suggested-by: Luis Pires <luis.pires@eldorado.org.br> | 3 | Signed-off-by: Anton Johansson <anjo@rev.ng> |
4 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | 4 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 5 | Message-Id: <20230227135202.9710-26-anjo@rev.ng> |
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
7 | --- | 7 | --- |
8 | tcg/optimize.c | 3 ++- | 8 | target/avr/cpu.c | 3 ++- |
9 | 1 file changed, 2 insertions(+), 1 deletion(-) | 9 | 1 file changed, 2 insertions(+), 1 deletion(-) |
10 | 10 | ||
11 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 11 | diff --git a/target/avr/cpu.c b/target/avr/cpu.c |
12 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/tcg/optimize.c | 13 | --- a/target/avr/cpu.c |
14 | +++ b/tcg/optimize.c | 14 | +++ b/target/avr/cpu.c |
15 | @@ -XXX,XX +XXX,XX @@ static bool fold_movcond(OptContext *ctx, TCGOp *op) | 15 | @@ -XXX,XX +XXX,XX @@ static void avr_cpu_synchronize_from_tb(CPUState *cs, |
16 | static bool fold_mul(OptContext *ctx, TCGOp *op) | 16 | AVRCPU *cpu = AVR_CPU(cs); |
17 | { | 17 | CPUAVRState *env = &cpu->env; |
18 | if (fold_const2(ctx, op) || | 18 | |
19 | - fold_xi_to_i(ctx, op, 0)) { | 19 | - env->pc_w = tb_pc(tb) / 2; /* internally PC points to words */ |
20 | + fold_xi_to_i(ctx, op, 0) || | 20 | + tcg_debug_assert(!(cs->tcg_cflags & CF_PCREL)); |
21 | + fold_xi_to_x(ctx, op, 1)) { | 21 | + env->pc_w = tb->pc / 2; /* internally PC points to words */ |
22 | return true; | 22 | } |
23 | } | 23 | |
24 | return false; | 24 | static void avr_restore_state_to_opc(CPUState *cs, |
25 | -- | 25 | -- |
26 | 2.25.1 | 26 | 2.34.1 |
27 | 27 | ||
28 | 28 | diff view generated by jsdifflib |
1 | This will expose the variable to subroutines that | 1 | From: Anton Johansson via <qemu-devel@nongnu.org> |
---|---|---|---|
2 | will be broken out of tcg_optimize. | ||
3 | 2 | ||
4 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 3 | Signed-off-by: Anton Johansson <anjo@rev.ng> |
5 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | 4 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
6 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 5 | Message-Id: <20230227135202.9710-27-anjo@rev.ng> |
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
8 | --- | 7 | --- |
9 | tcg/optimize.c | 11 ++++++----- | 8 | target/arm/cpu.c | 4 ++-- |
10 | 1 file changed, 6 insertions(+), 5 deletions(-) | 9 | 1 file changed, 2 insertions(+), 2 deletions(-) |
11 | 10 | ||
12 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 11 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c |
13 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/tcg/optimize.c | 13 | --- a/target/arm/cpu.c |
15 | +++ b/tcg/optimize.c | 14 | +++ b/target/arm/cpu.c |
16 | @@ -XXX,XX +XXX,XX @@ typedef struct TempOptInfo { | 15 | @@ -XXX,XX +XXX,XX @@ void arm_cpu_synchronize_from_tb(CPUState *cs, |
17 | 16 | * never possible for an AArch64 TB to chain to an AArch32 TB. | |
18 | typedef struct OptContext { | 17 | */ |
19 | TCGContext *tcg; | 18 | if (is_a64(env)) { |
20 | + TCGOp *prev_mb; | 19 | - env->pc = tb_pc(tb); |
21 | TCGTempSet temps_used; | 20 | + env->pc = tb->pc; |
22 | } OptContext; | 21 | } else { |
23 | 22 | - env->regs[15] = tb_pc(tb); | |
24 | @@ -XXX,XX +XXX,XX @@ static bool swap_commutative2(TCGArg *p1, TCGArg *p2) | 23 | + env->regs[15] = tb->pc; |
25 | void tcg_optimize(TCGContext *s) | ||
26 | { | ||
27 | int nb_temps, nb_globals, i; | ||
28 | - TCGOp *op, *op_next, *prev_mb = NULL; | ||
29 | + TCGOp *op, *op_next; | ||
30 | OptContext ctx = { .tcg = s }; | ||
31 | |||
32 | /* Array VALS has an element for each temp. | ||
33 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
34 | } | ||
35 | |||
36 | /* Eliminate duplicate and redundant fence instructions. */ | ||
37 | - if (prev_mb) { | ||
38 | + if (ctx.prev_mb) { | ||
39 | switch (opc) { | ||
40 | case INDEX_op_mb: | ||
41 | /* Merge two barriers of the same type into one, | ||
42 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
43 | * barrier. This is stricter than specified but for | ||
44 | * the purposes of TCG is better than not optimizing. | ||
45 | */ | ||
46 | - prev_mb->args[0] |= op->args[0]; | ||
47 | + ctx.prev_mb->args[0] |= op->args[0]; | ||
48 | tcg_op_remove(s, op); | ||
49 | break; | ||
50 | |||
51 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
52 | case INDEX_op_qemu_st_i64: | ||
53 | case INDEX_op_call: | ||
54 | /* Opcodes that touch guest memory stop the optimization. */ | ||
55 | - prev_mb = NULL; | ||
56 | + ctx.prev_mb = NULL; | ||
57 | break; | ||
58 | } | ||
59 | } else if (opc == INDEX_op_mb) { | ||
60 | - prev_mb = op; | ||
61 | + ctx.prev_mb = op; | ||
62 | } | 24 | } |
63 | } | 25 | } |
64 | } | 26 | } |
65 | -- | 27 | -- |
66 | 2.25.1 | 28 | 2.34.1 |
67 | 29 | ||
68 | 30 | diff view generated by jsdifflib |
1 | There was no real reason for calls to have separate code here. | 1 | From: Anton Johansson via <qemu-devel@nongnu.org> |
---|---|---|---|
2 | Unify init for calls vs non-calls using the call path, which | ||
3 | handles TCG_CALL_DUMMY_ARG. | ||
4 | 2 | ||
5 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 3 | Signed-off-by: Anton Johansson <anjo@rev.ng> |
6 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | 4 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
7 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 5 | Message-Id: <20230227135202.9710-28-anjo@rev.ng> |
8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
9 | --- | 7 | --- |
10 | tcg/optimize.c | 25 +++++++++++-------------- | 8 | include/exec/exec-all.h | 7 ------- |
11 | 1 file changed, 11 insertions(+), 14 deletions(-) | 9 | 1 file changed, 7 deletions(-) |
12 | 10 | ||
13 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 11 | diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h |
14 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/tcg/optimize.c | 13 | --- a/include/exec/exec-all.h |
16 | +++ b/tcg/optimize.c | 14 | +++ b/include/exec/exec-all.h |
17 | @@ -XXX,XX +XXX,XX @@ static void init_ts_info(OptContext *ctx, TCGTemp *ts) | 15 | @@ -XXX,XX +XXX,XX @@ static inline uint32_t tb_cflags(const TranslationBlock *tb) |
18 | } | 16 | return qatomic_read(&tb->cflags); |
19 | } | 17 | } |
20 | 18 | ||
21 | -static void init_arg_info(OptContext *ctx, TCGArg arg) | 19 | -/* Hide the read to avoid ifdefs for CF_PCREL. */ |
20 | -static inline target_ulong tb_pc(const TranslationBlock *tb) | ||
22 | -{ | 21 | -{ |
23 | - init_ts_info(ctx, arg_temp(arg)); | 22 | - assert(!(tb_cflags(tb) & CF_PCREL)); |
23 | - return tb->pc; | ||
24 | -} | 24 | -} |
25 | - | 25 | - |
26 | static TCGTemp *find_better_copy(TCGContext *s, TCGTemp *ts) | 26 | static inline tb_page_addr_t tb_page_addr0(const TranslationBlock *tb) |
27 | { | 27 | { |
28 | TCGTemp *i, *g, *l; | 28 | #ifdef CONFIG_USER_ONLY |
29 | @@ -XXX,XX +XXX,XX @@ static bool swap_commutative2(TCGArg *p1, TCGArg *p2) | ||
30 | return false; | ||
31 | } | ||
32 | |||
33 | +static void init_arguments(OptContext *ctx, TCGOp *op, int nb_args) | ||
34 | +{ | ||
35 | + for (int i = 0; i < nb_args; i++) { | ||
36 | + TCGTemp *ts = arg_temp(op->args[i]); | ||
37 | + if (ts) { | ||
38 | + init_ts_info(ctx, ts); | ||
39 | + } | ||
40 | + } | ||
41 | +} | ||
42 | + | ||
43 | /* Propagate constants and copies, fold constant expressions. */ | ||
44 | void tcg_optimize(TCGContext *s) | ||
45 | { | ||
46 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
47 | if (opc == INDEX_op_call) { | ||
48 | nb_oargs = TCGOP_CALLO(op); | ||
49 | nb_iargs = TCGOP_CALLI(op); | ||
50 | - for (i = 0; i < nb_oargs + nb_iargs; i++) { | ||
51 | - TCGTemp *ts = arg_temp(op->args[i]); | ||
52 | - if (ts) { | ||
53 | - init_ts_info(&ctx, ts); | ||
54 | - } | ||
55 | - } | ||
56 | } else { | ||
57 | nb_oargs = def->nb_oargs; | ||
58 | nb_iargs = def->nb_iargs; | ||
59 | - for (i = 0; i < nb_oargs + nb_iargs; i++) { | ||
60 | - init_arg_info(&ctx, op->args[i]); | ||
61 | - } | ||
62 | } | ||
63 | + init_arguments(&ctx, op, nb_oargs + nb_iargs); | ||
64 | |||
65 | /* Do copy propagation */ | ||
66 | for (i = nb_oargs; i < nb_oargs + nb_iargs; i++) { | ||
67 | -- | 29 | -- |
68 | 2.25.1 | 30 | 2.34.1 |
69 | 31 | ||
70 | 32 | diff view generated by jsdifflib |
1 | This will allow callers to tail call to these functions | 1 | Change the temps_in_use check to use assert not fprintf. |
---|---|---|---|
2 | and return true indicating processing complete. | 2 | Move the assert for double-free before the check for count, |
3 | since that is the more immediate problem. | ||
3 | 4 | ||
4 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 5 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
5 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | ||
6 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
8 | --- | 7 | --- |
9 | tcg/optimize.c | 9 +++++---- | 8 | tcg/tcg.c | 12 +++++------- |
10 | 1 file changed, 5 insertions(+), 4 deletions(-) | 9 | 1 file changed, 5 insertions(+), 7 deletions(-) |
11 | 10 | ||
12 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 11 | diff --git a/tcg/tcg.c b/tcg/tcg.c |
13 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/tcg/optimize.c | 13 | --- a/tcg/tcg.c |
15 | +++ b/tcg/optimize.c | 14 | +++ b/tcg/tcg.c |
16 | @@ -XXX,XX +XXX,XX @@ static bool args_are_copies(TCGArg arg1, TCGArg arg2) | 15 | @@ -XXX,XX +XXX,XX @@ void tcg_temp_free_internal(TCGTemp *ts) |
17 | return ts_are_copies(arg_temp(arg1), arg_temp(arg2)); | 16 | g_assert_not_reached(); |
18 | } | ||
19 | |||
20 | -static void tcg_opt_gen_mov(OptContext *ctx, TCGOp *op, TCGArg dst, TCGArg src) | ||
21 | +static bool tcg_opt_gen_mov(OptContext *ctx, TCGOp *op, TCGArg dst, TCGArg src) | ||
22 | { | ||
23 | TCGTemp *dst_ts = arg_temp(dst); | ||
24 | TCGTemp *src_ts = arg_temp(src); | ||
25 | @@ -XXX,XX +XXX,XX @@ static void tcg_opt_gen_mov(OptContext *ctx, TCGOp *op, TCGArg dst, TCGArg src) | ||
26 | |||
27 | if (ts_are_copies(dst_ts, src_ts)) { | ||
28 | tcg_op_remove(ctx->tcg, op); | ||
29 | - return; | ||
30 | + return true; | ||
31 | } | 17 | } |
32 | 18 | ||
33 | reset_ts(dst_ts); | 19 | -#if defined(CONFIG_DEBUG_TCG) |
34 | @@ -XXX,XX +XXX,XX @@ static void tcg_opt_gen_mov(OptContext *ctx, TCGOp *op, TCGArg dst, TCGArg src) | 20 | - s->temps_in_use--; |
35 | di->is_const = si->is_const; | 21 | - if (s->temps_in_use < 0) { |
36 | di->val = si->val; | 22 | - fprintf(stderr, "More temporaries freed than allocated!\n"); |
37 | } | 23 | - } |
38 | + return true; | 24 | -#endif |
39 | } | 25 | - |
40 | 26 | tcg_debug_assert(ts->temp_allocated != 0); | |
41 | -static void tcg_opt_gen_movi(OptContext *ctx, TCGOp *op, | 27 | ts->temp_allocated = 0; |
42 | +static bool tcg_opt_gen_movi(OptContext *ctx, TCGOp *op, | 28 | |
43 | TCGArg dst, uint64_t val) | 29 | +#if defined(CONFIG_DEBUG_TCG) |
44 | { | 30 | + assert(s->temps_in_use > 0); |
45 | const TCGOpDef *def = &tcg_op_defs[op->opc]; | 31 | + s->temps_in_use--; |
46 | @@ -XXX,XX +XXX,XX @@ static void tcg_opt_gen_movi(OptContext *ctx, TCGOp *op, | 32 | +#endif |
47 | /* Convert movi to mov with constant temp. */ | 33 | + |
48 | tv = tcg_constant_internal(type, val); | 34 | idx = temp_idx(ts); |
49 | init_ts_info(ctx, tv); | 35 | k = ts->base_type + (ts->kind == TEMP_NORMAL ? 0 : TCG_TYPE_COUNT); |
50 | - tcg_opt_gen_mov(ctx, op, dst, temp_arg(tv)); | 36 | set_bit(idx, s->free_temps[k].l); |
51 | + return tcg_opt_gen_mov(ctx, op, dst, temp_arg(tv)); | ||
52 | } | ||
53 | |||
54 | static uint64_t do_constant_folding_2(TCGOpcode op, uint64_t x, uint64_t y) | ||
55 | -- | 37 | -- |
56 | 2.25.1 | 38 | 2.34.1 |
57 | 39 | ||
58 | 40 | diff view generated by jsdifflib |
1 | Calls are special in that they have a variable number | 1 | In preparation for returning the number of insns generated |
---|---|---|---|
2 | of arguments, and need to be able to clobber globals. | 2 | via the same pointer. Adjust only the prototypes so far. |
3 | 3 | ||
4 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 4 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
5 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | ||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
7 | --- | 6 | --- |
8 | tcg/optimize.c | 63 ++++++++++++++++++++++++++++++++------------------ | 7 | include/exec/translator.h | 4 ++-- |
9 | 1 file changed, 41 insertions(+), 22 deletions(-) | 8 | accel/tcg/translate-all.c | 2 +- |
9 | accel/tcg/translator.c | 4 ++-- | ||
10 | target/alpha/translate.c | 2 +- | ||
11 | target/arm/tcg/translate.c | 2 +- | ||
12 | target/avr/translate.c | 2 +- | ||
13 | target/cris/translate.c | 2 +- | ||
14 | target/hexagon/translate.c | 2 +- | ||
15 | target/hppa/translate.c | 2 +- | ||
16 | target/i386/tcg/translate.c | 2 +- | ||
17 | target/loongarch/translate.c | 2 +- | ||
18 | target/m68k/translate.c | 2 +- | ||
19 | target/microblaze/translate.c | 2 +- | ||
20 | target/mips/tcg/translate.c | 2 +- | ||
21 | target/nios2/translate.c | 2 +- | ||
22 | target/openrisc/translate.c | 2 +- | ||
23 | target/ppc/translate.c | 2 +- | ||
24 | target/riscv/translate.c | 2 +- | ||
25 | target/rx/translate.c | 2 +- | ||
26 | target/s390x/tcg/translate.c | 2 +- | ||
27 | target/sh4/translate.c | 2 +- | ||
28 | target/sparc/translate.c | 2 +- | ||
29 | target/tricore/translate.c | 2 +- | ||
30 | target/xtensa/translate.c | 2 +- | ||
31 | 24 files changed, 26 insertions(+), 26 deletions(-) | ||
10 | 32 | ||
11 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 33 | diff --git a/include/exec/translator.h b/include/exec/translator.h |
12 | index XXXXXXX..XXXXXXX 100644 | 34 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/tcg/optimize.c | 35 | --- a/include/exec/translator.h |
14 | +++ b/tcg/optimize.c | 36 | +++ b/include/exec/translator.h |
15 | @@ -XXX,XX +XXX,XX @@ static void copy_propagate(OptContext *ctx, TCGOp *op, | 37 | @@ -XXX,XX +XXX,XX @@ |
16 | } | 38 | * This function must be provided by the target, which should create |
39 | * the target-specific DisasContext, and then invoke translator_loop. | ||
40 | */ | ||
41 | -void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns, | ||
42 | +void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int *max_insns, | ||
43 | target_ulong pc, void *host_pc); | ||
44 | |||
45 | /** | ||
46 | @@ -XXX,XX +XXX,XX @@ typedef struct TranslatorOps { | ||
47 | * - When single-stepping is enabled (system-wide or on the current vCPU). | ||
48 | * - When too many instructions have been translated. | ||
49 | */ | ||
50 | -void translator_loop(CPUState *cpu, TranslationBlock *tb, int max_insns, | ||
51 | +void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns, | ||
52 | target_ulong pc, void *host_pc, | ||
53 | const TranslatorOps *ops, DisasContextBase *db); | ||
54 | |||
55 | diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c | ||
56 | index XXXXXXX..XXXXXXX 100644 | ||
57 | --- a/accel/tcg/translate-all.c | ||
58 | +++ b/accel/tcg/translate-all.c | ||
59 | @@ -XXX,XX +XXX,XX @@ static int setjmp_gen_code(CPUArchState *env, TranslationBlock *tb, | ||
60 | tcg_func_start(tcg_ctx); | ||
61 | |||
62 | tcg_ctx->cpu = env_cpu(env); | ||
63 | - gen_intermediate_code(env_cpu(env), tb, *max_insns, pc, host_pc); | ||
64 | + gen_intermediate_code(env_cpu(env), tb, max_insns, pc, host_pc); | ||
65 | assert(tb->size != 0); | ||
66 | tcg_ctx->cpu = NULL; | ||
67 | *max_insns = tb->icount; | ||
68 | diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c | ||
69 | index XXXXXXX..XXXXXXX 100644 | ||
70 | --- a/accel/tcg/translator.c | ||
71 | +++ b/accel/tcg/translator.c | ||
72 | @@ -XXX,XX +XXX,XX @@ bool translator_use_goto_tb(DisasContextBase *db, target_ulong dest) | ||
73 | return ((db->pc_first ^ dest) & TARGET_PAGE_MASK) == 0; | ||
17 | } | 74 | } |
18 | 75 | ||
19 | +static bool fold_call(OptContext *ctx, TCGOp *op) | 76 | -void translator_loop(CPUState *cpu, TranslationBlock *tb, int max_insns, |
20 | +{ | 77 | +void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns, |
21 | + TCGContext *s = ctx->tcg; | 78 | target_ulong pc, void *host_pc, |
22 | + int nb_oargs = TCGOP_CALLO(op); | 79 | const TranslatorOps *ops, DisasContextBase *db) |
23 | + int nb_iargs = TCGOP_CALLI(op); | 80 | { |
24 | + int flags, i; | 81 | @@ -XXX,XX +XXX,XX @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int max_insns, |
25 | + | 82 | db->pc_next = pc; |
26 | + init_arguments(ctx, op, nb_oargs + nb_iargs); | 83 | db->is_jmp = DISAS_NEXT; |
27 | + copy_propagate(ctx, op, nb_oargs, nb_iargs); | 84 | db->num_insns = 0; |
28 | + | 85 | - db->max_insns = max_insns; |
29 | + /* If the function reads or writes globals, reset temp data. */ | 86 | + db->max_insns = *max_insns; |
30 | + flags = tcg_call_flags(op); | 87 | db->singlestep_enabled = cflags & CF_SINGLE_STEP; |
31 | + if (!(flags & (TCG_CALL_NO_READ_GLOBALS | TCG_CALL_NO_WRITE_GLOBALS))) { | 88 | db->host_addr[0] = host_pc; |
32 | + int nb_globals = s->nb_globals; | 89 | db->host_addr[1] = NULL; |
33 | + | 90 | diff --git a/target/alpha/translate.c b/target/alpha/translate.c |
34 | + for (i = 0; i < nb_globals; i++) { | 91 | index XXXXXXX..XXXXXXX 100644 |
35 | + if (test_bit(i, ctx->temps_used.l)) { | 92 | --- a/target/alpha/translate.c |
36 | + reset_ts(&ctx->tcg->temps[i]); | 93 | +++ b/target/alpha/translate.c |
37 | + } | 94 | @@ -XXX,XX +XXX,XX @@ static const TranslatorOps alpha_tr_ops = { |
38 | + } | 95 | .disas_log = alpha_tr_disas_log, |
39 | + } | 96 | }; |
40 | + | 97 | |
41 | + /* Reset temp data for outputs. */ | 98 | -void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns, |
42 | + for (i = 0; i < nb_oargs; i++) { | 99 | +void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int *max_insns, |
43 | + reset_temp(op->args[i]); | 100 | target_ulong pc, void *host_pc) |
44 | + } | 101 | { |
45 | + | 102 | DisasContext dc; |
46 | + /* Stop optimizing MB across calls. */ | 103 | diff --git a/target/arm/tcg/translate.c b/target/arm/tcg/translate.c |
47 | + ctx->prev_mb = NULL; | 104 | index XXXXXXX..XXXXXXX 100644 |
48 | + return true; | 105 | --- a/target/arm/tcg/translate.c |
49 | +} | 106 | +++ b/target/arm/tcg/translate.c |
50 | + | 107 | @@ -XXX,XX +XXX,XX @@ static const TranslatorOps thumb_translator_ops = { |
51 | /* Propagate constants and copies, fold constant expressions. */ | 108 | }; |
52 | void tcg_optimize(TCGContext *s) | 109 | |
53 | { | 110 | /* generate intermediate code for basic block 'tb'. */ |
54 | - int nb_temps, nb_globals, i; | 111 | -void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns, |
55 | + int nb_temps, i; | 112 | +void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int *max_insns, |
56 | TCGOp *op, *op_next; | 113 | target_ulong pc, void *host_pc) |
57 | OptContext ctx = { .tcg = s }; | 114 | { |
58 | 115 | DisasContext dc = { }; | |
59 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | 116 | diff --git a/target/avr/translate.c b/target/avr/translate.c |
60 | available through the doubly linked circular list. */ | 117 | index XXXXXXX..XXXXXXX 100644 |
61 | 118 | --- a/target/avr/translate.c | |
62 | nb_temps = s->nb_temps; | 119 | +++ b/target/avr/translate.c |
63 | - nb_globals = s->nb_globals; | 120 | @@ -XXX,XX +XXX,XX @@ static const TranslatorOps avr_tr_ops = { |
64 | - | 121 | .disas_log = avr_tr_disas_log, |
65 | for (i = 0; i < nb_temps; ++i) { | 122 | }; |
66 | s->temps[i].state_ptr = NULL; | 123 | |
67 | } | 124 | -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, |
68 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | 125 | +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int *max_insns, |
69 | uint64_t z_mask, partmask, affected, tmp; | 126 | target_ulong pc, void *host_pc) |
70 | int nb_oargs, nb_iargs; | 127 | { |
71 | TCGOpcode opc = op->opc; | 128 | DisasContext dc = { }; |
72 | - const TCGOpDef *def = &tcg_op_defs[opc]; | 129 | diff --git a/target/cris/translate.c b/target/cris/translate.c |
73 | + const TCGOpDef *def; | 130 | index XXXXXXX..XXXXXXX 100644 |
74 | 131 | --- a/target/cris/translate.c | |
75 | - /* Count the arguments, and initialize the temps that are | 132 | +++ b/target/cris/translate.c |
76 | - going to be used */ | 133 | @@ -XXX,XX +XXX,XX @@ static const TranslatorOps cris_tr_ops = { |
77 | + /* Calls are special. */ | 134 | .disas_log = cris_tr_disas_log, |
78 | if (opc == INDEX_op_call) { | 135 | }; |
79 | - nb_oargs = TCGOP_CALLO(op); | 136 | |
80 | - nb_iargs = TCGOP_CALLI(op); | 137 | -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, |
81 | - } else { | 138 | +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int *max_insns, |
82 | - nb_oargs = def->nb_oargs; | 139 | target_ulong pc, void *host_pc) |
83 | - nb_iargs = def->nb_iargs; | 140 | { |
84 | + fold_call(&ctx, op); | 141 | DisasContext dc; |
85 | + continue; | 142 | diff --git a/target/hexagon/translate.c b/target/hexagon/translate.c |
86 | } | 143 | index XXXXXXX..XXXXXXX 100644 |
87 | + | 144 | --- a/target/hexagon/translate.c |
88 | + def = &tcg_op_defs[opc]; | 145 | +++ b/target/hexagon/translate.c |
89 | + nb_oargs = def->nb_oargs; | 146 | @@ -XXX,XX +XXX,XX @@ static const TranslatorOps hexagon_tr_ops = { |
90 | + nb_iargs = def->nb_iargs; | 147 | .disas_log = hexagon_tr_disas_log, |
91 | init_arguments(&ctx, op, nb_oargs + nb_iargs); | 148 | }; |
92 | copy_propagate(&ctx, op, nb_oargs, nb_iargs); | 149 | |
93 | 150 | -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, | |
94 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | 151 | +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int *max_insns, |
95 | if (def->flags & TCG_OPF_BB_END) { | 152 | target_ulong pc, void *host_pc) |
96 | memset(&ctx.temps_used, 0, sizeof(ctx.temps_used)); | 153 | { |
97 | } else { | 154 | DisasContext ctx; |
98 | - if (opc == INDEX_op_call && | 155 | diff --git a/target/hppa/translate.c b/target/hppa/translate.c |
99 | - !(tcg_call_flags(op) | 156 | index XXXXXXX..XXXXXXX 100644 |
100 | - & (TCG_CALL_NO_READ_GLOBALS | TCG_CALL_NO_WRITE_GLOBALS))) { | 157 | --- a/target/hppa/translate.c |
101 | - for (i = 0; i < nb_globals; i++) { | 158 | +++ b/target/hppa/translate.c |
102 | - if (test_bit(i, ctx.temps_used.l)) { | 159 | @@ -XXX,XX +XXX,XX @@ static const TranslatorOps hppa_tr_ops = { |
103 | - reset_ts(&s->temps[i]); | 160 | .disas_log = hppa_tr_disas_log, |
104 | - } | 161 | }; |
105 | - } | 162 | |
106 | - } | 163 | -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, |
107 | - | 164 | +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int *max_insns, |
108 | for (i = 0; i < nb_oargs; i++) { | 165 | target_ulong pc, void *host_pc) |
109 | reset_temp(op->args[i]); | 166 | { |
110 | /* Save the corresponding known-zero bits mask for the | 167 | DisasContext ctx; |
111 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | 168 | diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c |
112 | case INDEX_op_qemu_st_i32: | 169 | index XXXXXXX..XXXXXXX 100644 |
113 | case INDEX_op_qemu_st8_i32: | 170 | --- a/target/i386/tcg/translate.c |
114 | case INDEX_op_qemu_st_i64: | 171 | +++ b/target/i386/tcg/translate.c |
115 | - case INDEX_op_call: | 172 | @@ -XXX,XX +XXX,XX @@ static const TranslatorOps i386_tr_ops = { |
116 | /* Opcodes that touch guest memory stop the optimization. */ | 173 | }; |
117 | ctx.prev_mb = NULL; | 174 | |
118 | break; | 175 | /* generate intermediate code for basic block 'tb'. */ |
176 | -void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns, | ||
177 | +void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int *max_insns, | ||
178 | target_ulong pc, void *host_pc) | ||
179 | { | ||
180 | DisasContext dc; | ||
181 | diff --git a/target/loongarch/translate.c b/target/loongarch/translate.c | ||
182 | index XXXXXXX..XXXXXXX 100644 | ||
183 | --- a/target/loongarch/translate.c | ||
184 | +++ b/target/loongarch/translate.c | ||
185 | @@ -XXX,XX +XXX,XX @@ static const TranslatorOps loongarch_tr_ops = { | ||
186 | .disas_log = loongarch_tr_disas_log, | ||
187 | }; | ||
188 | |||
189 | -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, | ||
190 | +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int *max_insns, | ||
191 | target_ulong pc, void *host_pc) | ||
192 | { | ||
193 | DisasContext ctx; | ||
194 | diff --git a/target/m68k/translate.c b/target/m68k/translate.c | ||
195 | index XXXXXXX..XXXXXXX 100644 | ||
196 | --- a/target/m68k/translate.c | ||
197 | +++ b/target/m68k/translate.c | ||
198 | @@ -XXX,XX +XXX,XX @@ static const TranslatorOps m68k_tr_ops = { | ||
199 | .disas_log = m68k_tr_disas_log, | ||
200 | }; | ||
201 | |||
202 | -void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns, | ||
203 | +void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int *max_insns, | ||
204 | target_ulong pc, void *host_pc) | ||
205 | { | ||
206 | DisasContext dc; | ||
207 | diff --git a/target/microblaze/translate.c b/target/microblaze/translate.c | ||
208 | index XXXXXXX..XXXXXXX 100644 | ||
209 | --- a/target/microblaze/translate.c | ||
210 | +++ b/target/microblaze/translate.c | ||
211 | @@ -XXX,XX +XXX,XX @@ static const TranslatorOps mb_tr_ops = { | ||
212 | .disas_log = mb_tr_disas_log, | ||
213 | }; | ||
214 | |||
215 | -void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns, | ||
216 | +void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int *max_insns, | ||
217 | target_ulong pc, void *host_pc) | ||
218 | { | ||
219 | DisasContext dc; | ||
220 | diff --git a/target/mips/tcg/translate.c b/target/mips/tcg/translate.c | ||
221 | index XXXXXXX..XXXXXXX 100644 | ||
222 | --- a/target/mips/tcg/translate.c | ||
223 | +++ b/target/mips/tcg/translate.c | ||
224 | @@ -XXX,XX +XXX,XX @@ static const TranslatorOps mips_tr_ops = { | ||
225 | .disas_log = mips_tr_disas_log, | ||
226 | }; | ||
227 | |||
228 | -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, | ||
229 | +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int *max_insns, | ||
230 | target_ulong pc, void *host_pc) | ||
231 | { | ||
232 | DisasContext ctx; | ||
233 | diff --git a/target/nios2/translate.c b/target/nios2/translate.c | ||
234 | index XXXXXXX..XXXXXXX 100644 | ||
235 | --- a/target/nios2/translate.c | ||
236 | +++ b/target/nios2/translate.c | ||
237 | @@ -XXX,XX +XXX,XX @@ static const TranslatorOps nios2_tr_ops = { | ||
238 | .disas_log = nios2_tr_disas_log, | ||
239 | }; | ||
240 | |||
241 | -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, | ||
242 | +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int *max_insns, | ||
243 | target_ulong pc, void *host_pc) | ||
244 | { | ||
245 | DisasContext dc; | ||
246 | diff --git a/target/openrisc/translate.c b/target/openrisc/translate.c | ||
247 | index XXXXXXX..XXXXXXX 100644 | ||
248 | --- a/target/openrisc/translate.c | ||
249 | +++ b/target/openrisc/translate.c | ||
250 | @@ -XXX,XX +XXX,XX @@ static const TranslatorOps openrisc_tr_ops = { | ||
251 | .disas_log = openrisc_tr_disas_log, | ||
252 | }; | ||
253 | |||
254 | -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, | ||
255 | +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int *max_insns, | ||
256 | target_ulong pc, void *host_pc) | ||
257 | { | ||
258 | DisasContext ctx; | ||
259 | diff --git a/target/ppc/translate.c b/target/ppc/translate.c | ||
260 | index XXXXXXX..XXXXXXX 100644 | ||
261 | --- a/target/ppc/translate.c | ||
262 | +++ b/target/ppc/translate.c | ||
263 | @@ -XXX,XX +XXX,XX @@ static const TranslatorOps ppc_tr_ops = { | ||
264 | .disas_log = ppc_tr_disas_log, | ||
265 | }; | ||
266 | |||
267 | -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, | ||
268 | +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int *max_insns, | ||
269 | target_ulong pc, void *host_pc) | ||
270 | { | ||
271 | DisasContext ctx; | ||
272 | diff --git a/target/riscv/translate.c b/target/riscv/translate.c | ||
273 | index XXXXXXX..XXXXXXX 100644 | ||
274 | --- a/target/riscv/translate.c | ||
275 | +++ b/target/riscv/translate.c | ||
276 | @@ -XXX,XX +XXX,XX @@ static const TranslatorOps riscv_tr_ops = { | ||
277 | .disas_log = riscv_tr_disas_log, | ||
278 | }; | ||
279 | |||
280 | -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, | ||
281 | +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int *max_insns, | ||
282 | target_ulong pc, void *host_pc) | ||
283 | { | ||
284 | DisasContext ctx; | ||
285 | diff --git a/target/rx/translate.c b/target/rx/translate.c | ||
286 | index XXXXXXX..XXXXXXX 100644 | ||
287 | --- a/target/rx/translate.c | ||
288 | +++ b/target/rx/translate.c | ||
289 | @@ -XXX,XX +XXX,XX @@ static const TranslatorOps rx_tr_ops = { | ||
290 | .disas_log = rx_tr_disas_log, | ||
291 | }; | ||
292 | |||
293 | -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, | ||
294 | +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int *max_insns, | ||
295 | target_ulong pc, void *host_pc) | ||
296 | { | ||
297 | DisasContext dc; | ||
298 | diff --git a/target/s390x/tcg/translate.c b/target/s390x/tcg/translate.c | ||
299 | index XXXXXXX..XXXXXXX 100644 | ||
300 | --- a/target/s390x/tcg/translate.c | ||
301 | +++ b/target/s390x/tcg/translate.c | ||
302 | @@ -XXX,XX +XXX,XX @@ static const TranslatorOps s390x_tr_ops = { | ||
303 | .disas_log = s390x_tr_disas_log, | ||
304 | }; | ||
305 | |||
306 | -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, | ||
307 | +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int *max_insns, | ||
308 | target_ulong pc, void *host_pc) | ||
309 | { | ||
310 | DisasContext dc; | ||
311 | diff --git a/target/sh4/translate.c b/target/sh4/translate.c | ||
312 | index XXXXXXX..XXXXXXX 100644 | ||
313 | --- a/target/sh4/translate.c | ||
314 | +++ b/target/sh4/translate.c | ||
315 | @@ -XXX,XX +XXX,XX @@ static const TranslatorOps sh4_tr_ops = { | ||
316 | .disas_log = sh4_tr_disas_log, | ||
317 | }; | ||
318 | |||
319 | -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, | ||
320 | +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int *max_insns, | ||
321 | target_ulong pc, void *host_pc) | ||
322 | { | ||
323 | DisasContext ctx; | ||
324 | diff --git a/target/sparc/translate.c b/target/sparc/translate.c | ||
325 | index XXXXXXX..XXXXXXX 100644 | ||
326 | --- a/target/sparc/translate.c | ||
327 | +++ b/target/sparc/translate.c | ||
328 | @@ -XXX,XX +XXX,XX @@ static const TranslatorOps sparc_tr_ops = { | ||
329 | .disas_log = sparc_tr_disas_log, | ||
330 | }; | ||
331 | |||
332 | -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, | ||
333 | +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int *max_insns, | ||
334 | target_ulong pc, void *host_pc) | ||
335 | { | ||
336 | DisasContext dc = {}; | ||
337 | diff --git a/target/tricore/translate.c b/target/tricore/translate.c | ||
338 | index XXXXXXX..XXXXXXX 100644 | ||
339 | --- a/target/tricore/translate.c | ||
340 | +++ b/target/tricore/translate.c | ||
341 | @@ -XXX,XX +XXX,XX @@ static const TranslatorOps tricore_tr_ops = { | ||
342 | }; | ||
343 | |||
344 | |||
345 | -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, | ||
346 | +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int *max_insns, | ||
347 | target_ulong pc, void *host_pc) | ||
348 | { | ||
349 | DisasContext ctx; | ||
350 | diff --git a/target/xtensa/translate.c b/target/xtensa/translate.c | ||
351 | index XXXXXXX..XXXXXXX 100644 | ||
352 | --- a/target/xtensa/translate.c | ||
353 | +++ b/target/xtensa/translate.c | ||
354 | @@ -XXX,XX +XXX,XX @@ static const TranslatorOps xtensa_translator_ops = { | ||
355 | .disas_log = xtensa_tr_disas_log, | ||
356 | }; | ||
357 | |||
358 | -void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns, | ||
359 | +void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int *max_insns, | ||
360 | target_ulong pc, void *host_pc) | ||
361 | { | ||
362 | DisasContext dc = {}; | ||
119 | -- | 363 | -- |
120 | 2.25.1 | 364 | 2.34.1 |
121 | 365 | ||
122 | 366 | diff view generated by jsdifflib |
1 | Sign repetitions are perforce all identical, whether they are 1 or 0. | 1 | Write back the number of insns that we attempt to translate, |
---|---|---|---|
2 | Bitwise operations preserve the relative quantity of the repetitions. | 2 | so that if we longjmp out we have a more accurate limit for |
3 | the next attempt. This results in fewer restarts when some | ||
4 | limit is consumed by few instructions. | ||
3 | 5 | ||
4 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 6 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
5 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | ||
6 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
8 | --- | 8 | --- |
9 | tcg/optimize.c | 29 +++++++++++++++++++++++++++++ | 9 | accel/tcg/translator.c | 2 +- |
10 | 1 file changed, 29 insertions(+) | 10 | 1 file changed, 1 insertion(+), 1 deletion(-) |
11 | 11 | ||
12 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 12 | diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c |
13 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/tcg/optimize.c | 14 | --- a/accel/tcg/translator.c |
15 | +++ b/tcg/optimize.c | 15 | +++ b/accel/tcg/translator.c |
16 | @@ -XXX,XX +XXX,XX @@ static bool fold_and(OptContext *ctx, TCGOp *op) | 16 | @@ -XXX,XX +XXX,XX @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns, |
17 | z2 = arg_info(op->args[2])->z_mask; | 17 | plugin_enabled = plugin_gen_tb_start(cpu, db, cflags & CF_MEMI_ONLY); |
18 | ctx->z_mask = z1 & z2; | 18 | |
19 | 19 | while (true) { | |
20 | + /* | 20 | - db->num_insns++; |
21 | + * Sign repetitions are perforce all identical, whether they are 1 or 0. | 21 | + *max_insns = ++db->num_insns; |
22 | + * Bitwise operations preserve the relative quantity of the repetitions. | 22 | ops->insn_start(db, cpu); |
23 | + */ | 23 | tcg_debug_assert(db->is_jmp == DISAS_NEXT); /* no early exit */ |
24 | + ctx->s_mask = arg_info(op->args[1])->s_mask | ||
25 | + & arg_info(op->args[2])->s_mask; | ||
26 | + | ||
27 | /* | ||
28 | * Known-zeros does not imply known-ones. Therefore unless | ||
29 | * arg2 is constant, we can't infer affected bits from it. | ||
30 | @@ -XXX,XX +XXX,XX @@ static bool fold_andc(OptContext *ctx, TCGOp *op) | ||
31 | } | ||
32 | ctx->z_mask = z1; | ||
33 | |||
34 | + ctx->s_mask = arg_info(op->args[1])->s_mask | ||
35 | + & arg_info(op->args[2])->s_mask; | ||
36 | return fold_masks(ctx, op); | ||
37 | } | ||
38 | |||
39 | @@ -XXX,XX +XXX,XX @@ static bool fold_eqv(OptContext *ctx, TCGOp *op) | ||
40 | fold_xi_to_not(ctx, op, 0)) { | ||
41 | return true; | ||
42 | } | ||
43 | + | ||
44 | + ctx->s_mask = arg_info(op->args[1])->s_mask | ||
45 | + & arg_info(op->args[2])->s_mask; | ||
46 | return false; | ||
47 | } | ||
48 | |||
49 | @@ -XXX,XX +XXX,XX @@ static bool fold_movcond(OptContext *ctx, TCGOp *op) | ||
50 | |||
51 | ctx->z_mask = arg_info(op->args[3])->z_mask | ||
52 | | arg_info(op->args[4])->z_mask; | ||
53 | + ctx->s_mask = arg_info(op->args[3])->s_mask | ||
54 | + & arg_info(op->args[4])->s_mask; | ||
55 | |||
56 | if (arg_is_const(op->args[3]) && arg_is_const(op->args[4])) { | ||
57 | uint64_t tv = arg_info(op->args[3])->val; | ||
58 | @@ -XXX,XX +XXX,XX @@ static bool fold_nand(OptContext *ctx, TCGOp *op) | ||
59 | fold_xi_to_not(ctx, op, -1)) { | ||
60 | return true; | ||
61 | } | ||
62 | + | ||
63 | + ctx->s_mask = arg_info(op->args[1])->s_mask | ||
64 | + & arg_info(op->args[2])->s_mask; | ||
65 | return false; | ||
66 | } | ||
67 | |||
68 | @@ -XXX,XX +XXX,XX @@ static bool fold_nor(OptContext *ctx, TCGOp *op) | ||
69 | fold_xi_to_not(ctx, op, 0)) { | ||
70 | return true; | ||
71 | } | ||
72 | + | ||
73 | + ctx->s_mask = arg_info(op->args[1])->s_mask | ||
74 | + & arg_info(op->args[2])->s_mask; | ||
75 | return false; | ||
76 | } | ||
77 | |||
78 | @@ -XXX,XX +XXX,XX @@ static bool fold_not(OptContext *ctx, TCGOp *op) | ||
79 | return true; | ||
80 | } | ||
81 | |||
82 | + ctx->s_mask = arg_info(op->args[1])->s_mask; | ||
83 | + | ||
84 | /* Because of fold_to_not, we want to always return true, via finish. */ | ||
85 | finish_folding(ctx, op); | ||
86 | return true; | ||
87 | @@ -XXX,XX +XXX,XX @@ static bool fold_or(OptContext *ctx, TCGOp *op) | ||
88 | |||
89 | ctx->z_mask = arg_info(op->args[1])->z_mask | ||
90 | | arg_info(op->args[2])->z_mask; | ||
91 | + ctx->s_mask = arg_info(op->args[1])->s_mask | ||
92 | + & arg_info(op->args[2])->s_mask; | ||
93 | return fold_masks(ctx, op); | ||
94 | } | ||
95 | |||
96 | @@ -XXX,XX +XXX,XX @@ static bool fold_orc(OptContext *ctx, TCGOp *op) | ||
97 | fold_ix_to_not(ctx, op, 0)) { | ||
98 | return true; | ||
99 | } | ||
100 | + | ||
101 | + ctx->s_mask = arg_info(op->args[1])->s_mask | ||
102 | + & arg_info(op->args[2])->s_mask; | ||
103 | return false; | ||
104 | } | ||
105 | |||
106 | @@ -XXX,XX +XXX,XX @@ static bool fold_xor(OptContext *ctx, TCGOp *op) | ||
107 | |||
108 | ctx->z_mask = arg_info(op->args[1])->z_mask | ||
109 | | arg_info(op->args[2])->z_mask; | ||
110 | + ctx->s_mask = arg_info(op->args[1])->s_mask | ||
111 | + & arg_info(op->args[2])->s_mask; | ||
112 | return fold_masks(ctx, op); | ||
113 | } | ||
114 | 24 | ||
115 | -- | 25 | -- |
116 | 2.25.1 | 26 | 2.34.1 |
117 | 27 | ||
118 | 28 | diff view generated by jsdifflib |
1 | Rather than try to keep these up-to-date across folding, | 1 | Just because the label reference count is more than 1 does |
---|---|---|---|
2 | re-read nb_oargs at the end, after re-reading the opcode. | 2 | not mean we cannot remove a branch-to-next. By doing this |
3 | first, the label reference count may drop to 0, and then | ||
4 | the label itself gets removed as before. | ||
3 | 5 | ||
4 | A couple of asserts need dropping, but that will take care | 6 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
5 | of itself as we split the function further. | ||
6 | |||
7 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | ||
8 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | ||
9 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
10 | --- | 8 | --- |
11 | tcg/optimize.c | 14 ++++---------- | 9 | tcg/tcg.c | 33 +++++++++++++++++---------------- |
12 | 1 file changed, 4 insertions(+), 10 deletions(-) | 10 | 1 file changed, 17 insertions(+), 16 deletions(-) |
13 | 11 | ||
14 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 12 | diff --git a/tcg/tcg.c b/tcg/tcg.c |
15 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/tcg/optimize.c | 14 | --- a/tcg/tcg.c |
17 | +++ b/tcg/optimize.c | 15 | +++ b/tcg/tcg.c |
18 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | 16 | @@ -XXX,XX +XXX,XX @@ TCGOp *tcg_op_insert_after(TCGContext *s, TCGOp *old_op, |
17 | /* Reachable analysis : remove unreachable code. */ | ||
18 | static void reachable_code_pass(TCGContext *s) | ||
19 | { | ||
20 | - TCGOp *op, *op_next; | ||
21 | + TCGOp *op, *op_next, *op_prev; | ||
22 | bool dead = false; | ||
19 | 23 | ||
20 | QTAILQ_FOREACH_SAFE(op, &s->ops, link, op_next) { | 24 | QTAILQ_FOREACH_SAFE(op, &s->ops, link, op_next) { |
21 | uint64_t z_mask, partmask, affected, tmp; | 25 | @@ -XXX,XX +XXX,XX @@ static void reachable_code_pass(TCGContext *s) |
22 | - int nb_oargs, nb_iargs; | 26 | switch (op->opc) { |
23 | TCGOpcode opc = op->opc; | 27 | case INDEX_op_set_label: |
24 | const TCGOpDef *def; | 28 | label = arg_label(op->args[0]); |
25 | 29 | + | |
26 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | 30 | + /* |
27 | } | 31 | + * Optimization can fold conditional branches to unconditional. |
28 | 32 | + * If we find a label which is preceded by an unconditional | |
29 | def = &tcg_op_defs[opc]; | 33 | + * branch to next, remove the branch. We couldn't do this when |
30 | - nb_oargs = def->nb_oargs; | 34 | + * processing the branch because any dead code between the branch |
31 | - nb_iargs = def->nb_iargs; | 35 | + * and label had not yet been removed. |
32 | - init_arguments(&ctx, op, nb_oargs + nb_iargs); | 36 | + */ |
33 | - copy_propagate(&ctx, op, nb_oargs, nb_iargs); | 37 | + op_prev = QTAILQ_PREV(op, link); |
34 | + init_arguments(&ctx, op, def->nb_oargs + def->nb_iargs); | 38 | + if (op_prev->opc == INDEX_op_br && |
35 | + copy_propagate(&ctx, op, def->nb_oargs, def->nb_iargs); | 39 | + label == arg_label(op_prev->args[0])) { |
36 | 40 | + tcg_op_remove(s, op_prev); | |
37 | /* For commutative operations make constant second argument */ | 41 | + /* Fall through means insns become live again. */ |
38 | switch (opc) { | 42 | + dead = false; |
39 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | 43 | + } |
40 | 44 | + | |
41 | CASE_OP_32_64(qemu_ld): | 45 | if (label->refs == 0) { |
42 | { | 46 | /* |
43 | - MemOpIdx oi = op->args[nb_oargs + nb_iargs]; | 47 | * While there is an occasional backward branch, virtually |
44 | + MemOpIdx oi = op->args[def->nb_oargs + def->nb_iargs]; | 48 | @@ -XXX,XX +XXX,XX @@ static void reachable_code_pass(TCGContext *s) |
45 | MemOp mop = get_memop(oi); | 49 | /* Once we see a label, insns become live again. */ |
46 | if (!(mop & MO_SIGN)) { | 50 | dead = false; |
47 | z_mask = (2ULL << ((8 << (mop & MO_SIZE)) - 1)) - 1; | 51 | remove = false; |
48 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | 52 | - |
49 | } | 53 | - /* |
50 | 54 | - * Optimization can fold conditional branches to unconditional. | |
51 | if (partmask == 0) { | 55 | - * If we find a label with one reference which is preceded by |
52 | - tcg_debug_assert(nb_oargs == 1); | 56 | - * an unconditional branch to it, remove both. This needed to |
53 | tcg_opt_gen_movi(&ctx, op, op->args[0], 0); | 57 | - * wait until the dead code in between them was removed. |
54 | continue; | 58 | - */ |
55 | } | 59 | - if (label->refs == 1) { |
56 | if (affected == 0) { | 60 | - TCGOp *op_prev = QTAILQ_PREV(op, link); |
57 | - tcg_debug_assert(nb_oargs == 1); | 61 | - if (op_prev->opc == INDEX_op_br && |
58 | tcg_opt_gen_mov(&ctx, op, op->args[0], op->args[1]); | 62 | - label == arg_label(op_prev->args[0])) { |
59 | continue; | 63 | - tcg_op_remove(s, op_prev); |
60 | } | 64 | - remove = true; |
61 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | 65 | - } |
62 | } else if (args_are_copies(op->args[1], op->args[2])) { | 66 | - } |
63 | op->opc = INDEX_op_dup_vec; | ||
64 | TCGOP_VECE(op) = MO_32; | ||
65 | - nb_iargs = 1; | ||
66 | } | 67 | } |
67 | break; | 68 | break; |
68 | 69 | ||
69 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
70 | op->opc = opc = (opc == INDEX_op_movcond_i32 | ||
71 | ? INDEX_op_setcond_i32 | ||
72 | : INDEX_op_setcond_i64); | ||
73 | - nb_iargs = 2; | ||
74 | } | ||
75 | break; | ||
76 | |||
77 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
78 | if (def->flags & TCG_OPF_BB_END) { | ||
79 | memset(&ctx.temps_used, 0, sizeof(ctx.temps_used)); | ||
80 | } else { | ||
81 | + int nb_oargs = def->nb_oargs; | ||
82 | for (i = 0; i < nb_oargs; i++) { | ||
83 | reset_temp(op->args[i]); | ||
84 | /* Save the corresponding known-zero bits mask for the | ||
85 | -- | 70 | -- |
86 | 2.25.1 | 71 | 2.34.1 |
87 | 72 | ||
88 | 73 | diff view generated by jsdifflib |
1 | Certain targets, like riscv, produce signed 32-bit results. | 1 | Use TEMP_TB as that is more explicit about the default |
---|---|---|---|
2 | This can lead to lots of redundant extensions as values are | 2 | lifetime of the data. While "global" and "local" used |
3 | manipulated. | 3 | to be contrasting, we have more lifetimes than that now. |
4 | 4 | ||
5 | Begin by tracking only the obvious sign-extensions, and | 5 | Do not yet rename tcg_temp_local_new_*, just the enum. |
6 | converting them to simple copies when possible. | ||
7 | 6 | ||
8 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 7 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
9 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | ||
10 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
11 | --- | 9 | --- |
12 | tcg/optimize.c | 123 ++++++++++++++++++++++++++++++++++++++++--------- | 10 | include/tcg/tcg.h | 12 ++++++++---- |
13 | 1 file changed, 102 insertions(+), 21 deletions(-) | 11 | tcg/optimize.c | 2 +- |
12 | tcg/tcg.c | 18 +++++++++--------- | ||
13 | 3 files changed, 18 insertions(+), 14 deletions(-) | ||
14 | 14 | ||
15 | diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/include/tcg/tcg.h | ||
18 | +++ b/include/tcg/tcg.h | ||
19 | @@ -XXX,XX +XXX,XX @@ typedef enum TCGTempVal { | ||
20 | typedef enum TCGTempKind { | ||
21 | /* Temp is dead at the end of all basic blocks. */ | ||
22 | TEMP_NORMAL, | ||
23 | - /* Temp is live across conditional branch, but dead otherwise. */ | ||
24 | + /* | ||
25 | + * Temp is dead at the end of the extended basic block (EBB), | ||
26 | + * the single-entry multiple-exit region that falls through | ||
27 | + * conditional branches. | ||
28 | + */ | ||
29 | TEMP_EBB, | ||
30 | - /* Temp is saved across basic blocks but dead at the end of TBs. */ | ||
31 | - TEMP_LOCAL, | ||
32 | - /* Temp is saved across both basic blocks and translation blocks. */ | ||
33 | + /* Temp is live across the entire translation block, but dead at end. */ | ||
34 | + TEMP_TB, | ||
35 | + /* Temp is live across the entire translation block, and between them. */ | ||
36 | TEMP_GLOBAL, | ||
37 | /* Temp is in a fixed register. */ | ||
38 | TEMP_FIXED, | ||
15 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 39 | diff --git a/tcg/optimize.c b/tcg/optimize.c |
16 | index XXXXXXX..XXXXXXX 100644 | 40 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/tcg/optimize.c | 41 | --- a/tcg/optimize.c |
18 | +++ b/tcg/optimize.c | 42 | +++ b/tcg/optimize.c |
19 | @@ -XXX,XX +XXX,XX @@ typedef struct TempOptInfo { | 43 | @@ -XXX,XX +XXX,XX @@ static TCGTemp *find_better_copy(TCGContext *s, TCGTemp *ts) |
20 | TCGTemp *next_copy; | 44 | } else if (i->kind > ts->kind) { |
21 | uint64_t val; | 45 | if (i->kind == TEMP_GLOBAL) { |
22 | uint64_t z_mask; /* mask bit is 0 if and only if value bit is 0 */ | 46 | g = i; |
23 | + uint64_t s_mask; /* a left-aligned mask of clrsb(value) bits. */ | 47 | - } else if (i->kind == TEMP_LOCAL) { |
24 | } TempOptInfo; | 48 | + } else if (i->kind == TEMP_TB) { |
25 | 49 | l = i; | |
26 | typedef struct OptContext { | 50 | } |
27 | @@ -XXX,XX +XXX,XX @@ typedef struct OptContext { | 51 | } |
28 | /* In flight values from optimization. */ | 52 | diff --git a/tcg/tcg.c b/tcg/tcg.c |
29 | uint64_t a_mask; /* mask bit is 0 iff value identical to first input */ | 53 | index XXXXXXX..XXXXXXX 100644 |
30 | uint64_t z_mask; /* mask bit is 0 iff value bit is 0 */ | 54 | --- a/tcg/tcg.c |
31 | + uint64_t s_mask; /* mask of clrsb(value) bits */ | 55 | +++ b/tcg/tcg.c |
32 | TCGType type; | 56 | @@ -XXX,XX +XXX,XX @@ TCGTemp *tcg_global_mem_new_internal(TCGType type, TCGv_ptr base, |
33 | } OptContext; | 57 | TCGTemp *tcg_temp_new_internal(TCGType type, bool temp_local) |
34 | |||
35 | +/* Calculate the smask for a specific value. */ | ||
36 | +static uint64_t smask_from_value(uint64_t value) | ||
37 | +{ | ||
38 | + int rep = clrsb64(value); | ||
39 | + return ~(~0ull >> rep); | ||
40 | +} | ||
41 | + | ||
42 | +/* | ||
43 | + * Calculate the smask for a given set of known-zeros. | ||
44 | + * If there are lots of zeros on the left, we can consider the remainder | ||
45 | + * an unsigned field, and thus the corresponding signed field is one bit | ||
46 | + * larger. | ||
47 | + */ | ||
48 | +static uint64_t smask_from_zmask(uint64_t zmask) | ||
49 | +{ | ||
50 | + /* | ||
51 | + * Only the 0 bits are significant for zmask, thus the msb itself | ||
52 | + * must be zero, else we have no sign information. | ||
53 | + */ | ||
54 | + int rep = clz64(zmask); | ||
55 | + if (rep == 0) { | ||
56 | + return 0; | ||
57 | + } | ||
58 | + rep -= 1; | ||
59 | + return ~(~0ull >> rep); | ||
60 | +} | ||
61 | + | ||
62 | static inline TempOptInfo *ts_info(TCGTemp *ts) | ||
63 | { | 58 | { |
64 | return ts->state_ptr; | 59 | TCGContext *s = tcg_ctx; |
65 | @@ -XXX,XX +XXX,XX @@ static void reset_ts(TCGTemp *ts) | 60 | - TCGTempKind kind = temp_local ? TEMP_LOCAL : TEMP_NORMAL; |
66 | ti->prev_copy = ts; | 61 | + TCGTempKind kind = temp_local ? TEMP_TB : TEMP_NORMAL; |
67 | ti->is_const = false; | 62 | TCGTemp *ts; |
68 | ti->z_mask = -1; | 63 | int idx, k; |
69 | + ti->s_mask = 0; | 64 | |
70 | } | 65 | @@ -XXX,XX +XXX,XX @@ void tcg_temp_free_internal(TCGTemp *ts) |
71 | |||
72 | static void reset_temp(TCGArg arg) | ||
73 | @@ -XXX,XX +XXX,XX @@ static void init_ts_info(OptContext *ctx, TCGTemp *ts) | ||
74 | ti->is_const = true; | ||
75 | ti->val = ts->val; | ||
76 | ti->z_mask = ts->val; | ||
77 | + ti->s_mask = smask_from_value(ts->val); | ||
78 | } else { | ||
79 | ti->is_const = false; | ||
80 | ti->z_mask = -1; | ||
81 | + ti->s_mask = 0; | ||
82 | } | ||
83 | } | ||
84 | |||
85 | @@ -XXX,XX +XXX,XX @@ static bool tcg_opt_gen_mov(OptContext *ctx, TCGOp *op, TCGArg dst, TCGArg src) | ||
86 | op->args[1] = src; | ||
87 | |||
88 | di->z_mask = si->z_mask; | ||
89 | + di->s_mask = si->s_mask; | ||
90 | |||
91 | if (src_ts->type == dst_ts->type) { | ||
92 | TempOptInfo *ni = ts_info(si->next_copy); | ||
93 | @@ -XXX,XX +XXX,XX @@ static void finish_folding(OptContext *ctx, TCGOp *op) | ||
94 | |||
95 | nb_oargs = def->nb_oargs; | ||
96 | for (i = 0; i < nb_oargs; i++) { | ||
97 | - reset_temp(op->args[i]); | ||
98 | + TCGTemp *ts = arg_temp(op->args[i]); | ||
99 | + reset_ts(ts); | ||
100 | /* | ||
101 | - * Save the corresponding known-zero bits mask for the | ||
102 | + * Save the corresponding known-zero/sign bits mask for the | ||
103 | * first output argument (only one supported so far). | ||
104 | */ | 66 | */ |
105 | if (i == 0) { | 67 | return; |
106 | - arg_info(op->args[i])->z_mask = ctx->z_mask; | 68 | case TEMP_NORMAL: |
107 | + ts_info(ts)->z_mask = ctx->z_mask; | 69 | - case TEMP_LOCAL: |
108 | + ts_info(ts)->s_mask = ctx->s_mask; | 70 | + case TEMP_TB: |
109 | } | ||
110 | } | ||
111 | } | ||
112 | @@ -XXX,XX +XXX,XX @@ static bool fold_masks(OptContext *ctx, TCGOp *op) | ||
113 | { | ||
114 | uint64_t a_mask = ctx->a_mask; | ||
115 | uint64_t z_mask = ctx->z_mask; | ||
116 | + uint64_t s_mask = ctx->s_mask; | ||
117 | |||
118 | /* | ||
119 | * 32-bit ops generate 32-bit results, which for the purpose of | ||
120 | @@ -XXX,XX +XXX,XX @@ static bool fold_masks(OptContext *ctx, TCGOp *op) | ||
121 | if (ctx->type == TCG_TYPE_I32) { | ||
122 | a_mask = (int32_t)a_mask; | ||
123 | z_mask = (int32_t)z_mask; | ||
124 | + s_mask |= MAKE_64BIT_MASK(32, 32); | ||
125 | ctx->z_mask = z_mask; | ||
126 | + ctx->s_mask = s_mask; | ||
127 | } | ||
128 | |||
129 | if (z_mask == 0) { | ||
130 | @@ -XXX,XX +XXX,XX @@ static bool fold_brcond2(OptContext *ctx, TCGOp *op) | ||
131 | |||
132 | static bool fold_bswap(OptContext *ctx, TCGOp *op) | ||
133 | { | ||
134 | - uint64_t z_mask, sign; | ||
135 | + uint64_t z_mask, s_mask, sign; | ||
136 | |||
137 | if (arg_is_const(op->args[1])) { | ||
138 | uint64_t t = arg_info(op->args[1])->val; | ||
139 | @@ -XXX,XX +XXX,XX @@ static bool fold_bswap(OptContext *ctx, TCGOp *op) | ||
140 | } | ||
141 | |||
142 | z_mask = arg_info(op->args[1])->z_mask; | ||
143 | + | ||
144 | switch (op->opc) { | ||
145 | case INDEX_op_bswap16_i32: | ||
146 | case INDEX_op_bswap16_i64: | ||
147 | @@ -XXX,XX +XXX,XX @@ static bool fold_bswap(OptContext *ctx, TCGOp *op) | ||
148 | default: | ||
149 | g_assert_not_reached(); | ||
150 | } | ||
151 | + s_mask = smask_from_zmask(z_mask); | ||
152 | |||
153 | switch (op->args[2] & (TCG_BSWAP_OZ | TCG_BSWAP_OS)) { | ||
154 | case TCG_BSWAP_OZ: | ||
155 | @@ -XXX,XX +XXX,XX @@ static bool fold_bswap(OptContext *ctx, TCGOp *op) | ||
156 | /* If the sign bit may be 1, force all the bits above to 1. */ | ||
157 | if (z_mask & sign) { | ||
158 | z_mask |= sign; | ||
159 | + s_mask = sign << 1; | ||
160 | } | ||
161 | break; | ||
162 | default: | ||
163 | /* The high bits are undefined: force all bits above the sign to 1. */ | ||
164 | z_mask |= sign << 1; | ||
165 | + s_mask = 0; | ||
166 | break; | ||
167 | } | ||
168 | ctx->z_mask = z_mask; | ||
169 | + ctx->s_mask = s_mask; | ||
170 | |||
171 | return fold_masks(ctx, op); | ||
172 | } | ||
173 | @@ -XXX,XX +XXX,XX @@ static bool fold_eqv(OptContext *ctx, TCGOp *op) | ||
174 | static bool fold_extract(OptContext *ctx, TCGOp *op) | ||
175 | { | ||
176 | uint64_t z_mask_old, z_mask; | ||
177 | + int pos = op->args[2]; | ||
178 | + int len = op->args[3]; | ||
179 | |||
180 | if (arg_is_const(op->args[1])) { | ||
181 | uint64_t t; | ||
182 | |||
183 | t = arg_info(op->args[1])->val; | ||
184 | - t = extract64(t, op->args[2], op->args[3]); | ||
185 | + t = extract64(t, pos, len); | ||
186 | return tcg_opt_gen_movi(ctx, op, op->args[0], t); | ||
187 | } | ||
188 | |||
189 | z_mask_old = arg_info(op->args[1])->z_mask; | ||
190 | - z_mask = extract64(z_mask_old, op->args[2], op->args[3]); | ||
191 | - if (op->args[2] == 0) { | ||
192 | + z_mask = extract64(z_mask_old, pos, len); | ||
193 | + if (pos == 0) { | ||
194 | ctx->a_mask = z_mask_old ^ z_mask; | ||
195 | } | ||
196 | ctx->z_mask = z_mask; | ||
197 | + ctx->s_mask = smask_from_zmask(z_mask); | ||
198 | |||
199 | return fold_masks(ctx, op); | ||
200 | } | ||
201 | @@ -XXX,XX +XXX,XX @@ static bool fold_extract2(OptContext *ctx, TCGOp *op) | ||
202 | |||
203 | static bool fold_exts(OptContext *ctx, TCGOp *op) | ||
204 | { | ||
205 | - uint64_t z_mask_old, z_mask, sign; | ||
206 | + uint64_t s_mask_old, s_mask, z_mask, sign; | ||
207 | bool type_change = false; | ||
208 | |||
209 | if (fold_const1(ctx, op)) { | ||
210 | return true; | ||
211 | } | ||
212 | |||
213 | - z_mask_old = z_mask = arg_info(op->args[1])->z_mask; | ||
214 | + z_mask = arg_info(op->args[1])->z_mask; | ||
215 | + s_mask = arg_info(op->args[1])->s_mask; | ||
216 | + s_mask_old = s_mask; | ||
217 | |||
218 | switch (op->opc) { | ||
219 | CASE_OP_32_64(ext8s): | ||
220 | @@ -XXX,XX +XXX,XX @@ static bool fold_exts(OptContext *ctx, TCGOp *op) | ||
221 | |||
222 | if (z_mask & sign) { | ||
223 | z_mask |= sign; | ||
224 | - } else if (!type_change) { | ||
225 | - ctx->a_mask = z_mask_old ^ z_mask; | ||
226 | } | ||
227 | + s_mask |= sign << 1; | ||
228 | + | ||
229 | ctx->z_mask = z_mask; | ||
230 | + ctx->s_mask = s_mask; | ||
231 | + if (!type_change) { | ||
232 | + ctx->a_mask = s_mask & ~s_mask_old; | ||
233 | + } | ||
234 | |||
235 | return fold_masks(ctx, op); | ||
236 | } | ||
237 | @@ -XXX,XX +XXX,XX @@ static bool fold_extu(OptContext *ctx, TCGOp *op) | ||
238 | } | ||
239 | |||
240 | ctx->z_mask = z_mask; | ||
241 | + ctx->s_mask = smask_from_zmask(z_mask); | ||
242 | if (!type_change) { | ||
243 | ctx->a_mask = z_mask_old ^ z_mask; | ||
244 | } | ||
245 | @@ -XXX,XX +XXX,XX @@ static bool fold_qemu_ld(OptContext *ctx, TCGOp *op) | ||
246 | MemOp mop = get_memop(oi); | ||
247 | int width = 8 * memop_size(mop); | ||
248 | |||
249 | - if (!(mop & MO_SIGN) && width < 64) { | ||
250 | - ctx->z_mask = MAKE_64BIT_MASK(0, width); | ||
251 | + if (width < 64) { | ||
252 | + ctx->s_mask = MAKE_64BIT_MASK(width, 64 - width); | ||
253 | + if (!(mop & MO_SIGN)) { | ||
254 | + ctx->z_mask = MAKE_64BIT_MASK(0, width); | ||
255 | + ctx->s_mask <<= 1; | ||
256 | + } | ||
257 | } | ||
258 | |||
259 | /* Opcodes that touch guest memory stop the mb optimization. */ | ||
260 | @@ -XXX,XX +XXX,XX @@ static bool fold_setcond2(OptContext *ctx, TCGOp *op) | ||
261 | |||
262 | static bool fold_sextract(OptContext *ctx, TCGOp *op) | ||
263 | { | ||
264 | - int64_t z_mask_old, z_mask; | ||
265 | + uint64_t z_mask, s_mask, s_mask_old; | ||
266 | + int pos = op->args[2]; | ||
267 | + int len = op->args[3]; | ||
268 | |||
269 | if (arg_is_const(op->args[1])) { | ||
270 | uint64_t t; | ||
271 | |||
272 | t = arg_info(op->args[1])->val; | ||
273 | - t = sextract64(t, op->args[2], op->args[3]); | ||
274 | + t = sextract64(t, pos, len); | ||
275 | return tcg_opt_gen_movi(ctx, op, op->args[0], t); | ||
276 | } | ||
277 | |||
278 | - z_mask_old = arg_info(op->args[1])->z_mask; | ||
279 | - z_mask = sextract64(z_mask_old, op->args[2], op->args[3]); | ||
280 | - if (op->args[2] == 0 && z_mask >= 0) { | ||
281 | - ctx->a_mask = z_mask_old ^ z_mask; | ||
282 | - } | ||
283 | + z_mask = arg_info(op->args[1])->z_mask; | ||
284 | + z_mask = sextract64(z_mask, pos, len); | ||
285 | ctx->z_mask = z_mask; | ||
286 | |||
287 | + s_mask_old = arg_info(op->args[1])->s_mask; | ||
288 | + s_mask = sextract64(s_mask_old, pos, len); | ||
289 | + s_mask |= MAKE_64BIT_MASK(len, 64 - len); | ||
290 | + ctx->s_mask = s_mask; | ||
291 | + | ||
292 | + if (pos == 0) { | ||
293 | + ctx->a_mask = s_mask & ~s_mask_old; | ||
294 | + } | ||
295 | + | ||
296 | return fold_masks(ctx, op); | ||
297 | } | ||
298 | |||
299 | @@ -XXX,XX +XXX,XX @@ static bool fold_tcg_ld(OptContext *ctx, TCGOp *op) | ||
300 | { | ||
301 | /* We can't do any folding with a load, but we can record bits. */ | ||
302 | switch (op->opc) { | ||
303 | + CASE_OP_32_64(ld8s): | ||
304 | + ctx->s_mask = MAKE_64BIT_MASK(8, 56); | ||
305 | + break; | ||
306 | CASE_OP_32_64(ld8u): | ||
307 | ctx->z_mask = MAKE_64BIT_MASK(0, 8); | ||
308 | + ctx->s_mask = MAKE_64BIT_MASK(9, 55); | ||
309 | + break; | ||
310 | + CASE_OP_32_64(ld16s): | ||
311 | + ctx->s_mask = MAKE_64BIT_MASK(16, 48); | ||
312 | break; | ||
313 | CASE_OP_32_64(ld16u): | ||
314 | ctx->z_mask = MAKE_64BIT_MASK(0, 16); | ||
315 | + ctx->s_mask = MAKE_64BIT_MASK(17, 47); | ||
316 | + break; | ||
317 | + case INDEX_op_ld32s_i64: | ||
318 | + ctx->s_mask = MAKE_64BIT_MASK(32, 32); | ||
319 | break; | ||
320 | case INDEX_op_ld32u_i64: | ||
321 | ctx->z_mask = MAKE_64BIT_MASK(0, 32); | ||
322 | + ctx->s_mask = MAKE_64BIT_MASK(33, 31); | ||
323 | break; | 71 | break; |
324 | default: | 72 | default: |
325 | g_assert_not_reached(); | 73 | g_assert_not_reached(); |
326 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | 74 | @@ -XXX,XX +XXX,XX @@ static void tcg_reg_alloc_start(TCGContext *s) |
327 | ctx.type = TCG_TYPE_I32; | 75 | case TEMP_EBB: |
328 | } | 76 | val = TEMP_VAL_DEAD; |
329 | 77 | /* fall through */ | |
330 | - /* Assume all bits affected, and no bits known zero. */ | 78 | - case TEMP_LOCAL: |
331 | + /* Assume all bits affected, no bits known zero, no sign reps. */ | 79 | + case TEMP_TB: |
332 | ctx.a_mask = -1; | 80 | ts->mem_allocated = 0; |
333 | ctx.z_mask = -1; | ||
334 | + ctx.s_mask = 0; | ||
335 | |||
336 | /* | ||
337 | * Process each opcode. | ||
338 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
339 | case INDEX_op_extrh_i64_i32: | ||
340 | done = fold_extu(&ctx, op); | ||
341 | break; | 81 | break; |
342 | + CASE_OP_32_64(ld8s): | 82 | default: |
343 | CASE_OP_32_64(ld8u): | 83 | @@ -XXX,XX +XXX,XX @@ static char *tcg_get_arg_str_ptr(TCGContext *s, char *buf, int buf_size, |
344 | + CASE_OP_32_64(ld16s): | 84 | case TEMP_GLOBAL: |
345 | CASE_OP_32_64(ld16u): | 85 | pstrcpy(buf, buf_size, ts->name); |
346 | + case INDEX_op_ld32s_i64: | 86 | break; |
347 | case INDEX_op_ld32u_i64: | 87 | - case TEMP_LOCAL: |
348 | done = fold_tcg_ld(&ctx, op); | 88 | + case TEMP_TB: |
89 | snprintf(buf, buf_size, "loc%d", idx - s->nb_globals); | ||
90 | break; | ||
91 | case TEMP_EBB: | ||
92 | @@ -XXX,XX +XXX,XX @@ static void la_bb_end(TCGContext *s, int ng, int nt) | ||
93 | switch (ts->kind) { | ||
94 | case TEMP_FIXED: | ||
95 | case TEMP_GLOBAL: | ||
96 | - case TEMP_LOCAL: | ||
97 | + case TEMP_TB: | ||
98 | state = TS_DEAD | TS_MEM; | ||
349 | break; | 99 | break; |
100 | case TEMP_NORMAL: | ||
101 | @@ -XXX,XX +XXX,XX @@ static void la_bb_sync(TCGContext *s, int ng, int nt) | ||
102 | int state; | ||
103 | |||
104 | switch (ts->kind) { | ||
105 | - case TEMP_LOCAL: | ||
106 | + case TEMP_TB: | ||
107 | state = ts->state; | ||
108 | ts->state = state | TS_MEM; | ||
109 | if (state != TS_DEAD) { | ||
110 | @@ -XXX,XX +XXX,XX @@ static void temp_free_or_dead(TCGContext *s, TCGTemp *ts, int free_or_dead) | ||
111 | case TEMP_FIXED: | ||
112 | return; | ||
113 | case TEMP_GLOBAL: | ||
114 | - case TEMP_LOCAL: | ||
115 | + case TEMP_TB: | ||
116 | new_type = TEMP_VAL_MEM; | ||
117 | break; | ||
118 | case TEMP_NORMAL: | ||
119 | @@ -XXX,XX +XXX,XX @@ static void tcg_reg_alloc_bb_end(TCGContext *s, TCGRegSet allocated_regs) | ||
120 | TCGTemp *ts = &s->temps[i]; | ||
121 | |||
122 | switch (ts->kind) { | ||
123 | - case TEMP_LOCAL: | ||
124 | + case TEMP_TB: | ||
125 | temp_save(s, ts, allocated_regs); | ||
126 | break; | ||
127 | case TEMP_NORMAL: | ||
128 | @@ -XXX,XX +XXX,XX @@ static void tcg_reg_alloc_cbranch(TCGContext *s, TCGRegSet allocated_regs) | ||
129 | * Keep tcg_debug_asserts for safety. | ||
130 | */ | ||
131 | switch (ts->kind) { | ||
132 | - case TEMP_LOCAL: | ||
133 | + case TEMP_TB: | ||
134 | tcg_debug_assert(ts->val_type != TEMP_VAL_REG || ts->mem_coherent); | ||
135 | break; | ||
136 | case TEMP_NORMAL: | ||
350 | -- | 137 | -- |
351 | 2.25.1 | 138 | 2.34.1 |
352 | 139 | ||
353 | 140 | diff view generated by jsdifflib |
1 | Prepare for tracking different masks by renaming this one. | 1 | This makes it easier to assign blame with perf. |
---|---|---|---|
2 | 2 | ||
3 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 3 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
4 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | 4 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
7 | --- | 6 | --- |
8 | tcg/optimize.c | 142 +++++++++++++++++++++++++------------------------ | 7 | tcg/tcg.c | 9 ++++++--- |
9 | 1 file changed, 72 insertions(+), 70 deletions(-) | 8 | 1 file changed, 6 insertions(+), 3 deletions(-) |
10 | 9 | ||
11 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 10 | diff --git a/tcg/tcg.c b/tcg/tcg.c |
12 | index XXXXXXX..XXXXXXX 100644 | 11 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/tcg/optimize.c | 12 | --- a/tcg/tcg.c |
14 | +++ b/tcg/optimize.c | 13 | +++ b/tcg/tcg.c |
15 | @@ -XXX,XX +XXX,XX @@ typedef struct TempOptInfo { | 14 | @@ -XXX,XX +XXX,XX @@ TCGOp *tcg_op_insert_after(TCGContext *s, TCGOp *old_op, |
16 | TCGTemp *prev_copy; | ||
17 | TCGTemp *next_copy; | ||
18 | uint64_t val; | ||
19 | - uint64_t mask; | ||
20 | + uint64_t z_mask; /* mask bit is 0 if and only if value bit is 0 */ | ||
21 | } TempOptInfo; | ||
22 | |||
23 | static inline TempOptInfo *ts_info(TCGTemp *ts) | ||
24 | @@ -XXX,XX +XXX,XX @@ static void reset_ts(TCGTemp *ts) | ||
25 | ti->next_copy = ts; | ||
26 | ti->prev_copy = ts; | ||
27 | ti->is_const = false; | ||
28 | - ti->mask = -1; | ||
29 | + ti->z_mask = -1; | ||
30 | } | 15 | } |
31 | 16 | ||
32 | static void reset_temp(TCGArg arg) | 17 | /* Reachable analysis : remove unreachable code. */ |
33 | @@ -XXX,XX +XXX,XX @@ static void init_ts_info(TCGTempSet *temps_used, TCGTemp *ts) | 18 | -static void reachable_code_pass(TCGContext *s) |
34 | if (ts->kind == TEMP_CONST) { | 19 | +static void __attribute__((noinline)) |
35 | ti->is_const = true; | 20 | +reachable_code_pass(TCGContext *s) |
36 | ti->val = ts->val; | 21 | { |
37 | - ti->mask = ts->val; | 22 | TCGOp *op, *op_next, *op_prev; |
38 | + ti->z_mask = ts->val; | 23 | bool dead = false; |
39 | if (TCG_TARGET_REG_BITS > 32 && ts->type == TCG_TYPE_I32) { | 24 | @@ -XXX,XX +XXX,XX @@ static void la_cross_call(TCGContext *s, int nt) |
40 | /* High bits of a 32-bit quantity are garbage. */ | 25 | /* Liveness analysis : update the opc_arg_life array to tell if a |
41 | - ti->mask |= ~0xffffffffull; | 26 | given input arguments is dead. Instructions updating dead |
42 | + ti->z_mask |= ~0xffffffffull; | 27 | temporaries are removed. */ |
43 | } | 28 | -static void liveness_pass_1(TCGContext *s) |
44 | } else { | 29 | +static void __attribute__((noinline)) |
45 | ti->is_const = false; | 30 | +liveness_pass_1(TCGContext *s) |
46 | - ti->mask = -1; | 31 | { |
47 | + ti->z_mask = -1; | 32 | int nb_globals = s->nb_globals; |
48 | } | 33 | int nb_temps = s->nb_temps; |
34 | @@ -XXX,XX +XXX,XX @@ static void liveness_pass_1(TCGContext *s) | ||
49 | } | 35 | } |
50 | 36 | ||
51 | @@ -XXX,XX +XXX,XX @@ static void tcg_opt_gen_mov(TCGContext *s, TCGOp *op, TCGArg dst, TCGArg src) | 37 | /* Liveness analysis: Convert indirect regs to direct temporaries. */ |
52 | const TCGOpDef *def; | 38 | -static bool liveness_pass_2(TCGContext *s) |
53 | TempOptInfo *di; | 39 | +static bool __attribute__((noinline)) |
54 | TempOptInfo *si; | 40 | +liveness_pass_2(TCGContext *s) |
55 | - uint64_t mask; | 41 | { |
56 | + uint64_t z_mask; | 42 | int nb_globals = s->nb_globals; |
57 | TCGOpcode new_op; | 43 | int nb_temps, i; |
58 | |||
59 | if (ts_are_copies(dst_ts, src_ts)) { | ||
60 | @@ -XXX,XX +XXX,XX @@ static void tcg_opt_gen_mov(TCGContext *s, TCGOp *op, TCGArg dst, TCGArg src) | ||
61 | op->args[0] = dst; | ||
62 | op->args[1] = src; | ||
63 | |||
64 | - mask = si->mask; | ||
65 | + z_mask = si->z_mask; | ||
66 | if (TCG_TARGET_REG_BITS > 32 && new_op == INDEX_op_mov_i32) { | ||
67 | /* High bits of the destination are now garbage. */ | ||
68 | - mask |= ~0xffffffffull; | ||
69 | + z_mask |= ~0xffffffffull; | ||
70 | } | ||
71 | - di->mask = mask; | ||
72 | + di->z_mask = z_mask; | ||
73 | |||
74 | if (src_ts->type == dst_ts->type) { | ||
75 | TempOptInfo *ni = ts_info(si->next_copy); | ||
76 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
77 | } | ||
78 | |||
79 | QTAILQ_FOREACH_SAFE(op, &s->ops, link, op_next) { | ||
80 | - uint64_t mask, partmask, affected, tmp; | ||
81 | + uint64_t z_mask, partmask, affected, tmp; | ||
82 | int nb_oargs, nb_iargs; | ||
83 | TCGOpcode opc = op->opc; | ||
84 | const TCGOpDef *def = &tcg_op_defs[opc]; | ||
85 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
86 | |||
87 | /* Simplify using known-zero bits. Currently only ops with a single | ||
88 | output argument is supported. */ | ||
89 | - mask = -1; | ||
90 | + z_mask = -1; | ||
91 | affected = -1; | ||
92 | switch (opc) { | ||
93 | CASE_OP_32_64(ext8s): | ||
94 | - if ((arg_info(op->args[1])->mask & 0x80) != 0) { | ||
95 | + if ((arg_info(op->args[1])->z_mask & 0x80) != 0) { | ||
96 | break; | ||
97 | } | ||
98 | QEMU_FALLTHROUGH; | ||
99 | CASE_OP_32_64(ext8u): | ||
100 | - mask = 0xff; | ||
101 | + z_mask = 0xff; | ||
102 | goto and_const; | ||
103 | CASE_OP_32_64(ext16s): | ||
104 | - if ((arg_info(op->args[1])->mask & 0x8000) != 0) { | ||
105 | + if ((arg_info(op->args[1])->z_mask & 0x8000) != 0) { | ||
106 | break; | ||
107 | } | ||
108 | QEMU_FALLTHROUGH; | ||
109 | CASE_OP_32_64(ext16u): | ||
110 | - mask = 0xffff; | ||
111 | + z_mask = 0xffff; | ||
112 | goto and_const; | ||
113 | case INDEX_op_ext32s_i64: | ||
114 | - if ((arg_info(op->args[1])->mask & 0x80000000) != 0) { | ||
115 | + if ((arg_info(op->args[1])->z_mask & 0x80000000) != 0) { | ||
116 | break; | ||
117 | } | ||
118 | QEMU_FALLTHROUGH; | ||
119 | case INDEX_op_ext32u_i64: | ||
120 | - mask = 0xffffffffU; | ||
121 | + z_mask = 0xffffffffU; | ||
122 | goto and_const; | ||
123 | |||
124 | CASE_OP_32_64(and): | ||
125 | - mask = arg_info(op->args[2])->mask; | ||
126 | + z_mask = arg_info(op->args[2])->z_mask; | ||
127 | if (arg_is_const(op->args[2])) { | ||
128 | and_const: | ||
129 | - affected = arg_info(op->args[1])->mask & ~mask; | ||
130 | + affected = arg_info(op->args[1])->z_mask & ~z_mask; | ||
131 | } | ||
132 | - mask = arg_info(op->args[1])->mask & mask; | ||
133 | + z_mask = arg_info(op->args[1])->z_mask & z_mask; | ||
134 | break; | ||
135 | |||
136 | case INDEX_op_ext_i32_i64: | ||
137 | - if ((arg_info(op->args[1])->mask & 0x80000000) != 0) { | ||
138 | + if ((arg_info(op->args[1])->z_mask & 0x80000000) != 0) { | ||
139 | break; | ||
140 | } | ||
141 | QEMU_FALLTHROUGH; | ||
142 | case INDEX_op_extu_i32_i64: | ||
143 | /* We do not compute affected as it is a size changing op. */ | ||
144 | - mask = (uint32_t)arg_info(op->args[1])->mask; | ||
145 | + z_mask = (uint32_t)arg_info(op->args[1])->z_mask; | ||
146 | break; | ||
147 | |||
148 | CASE_OP_32_64(andc): | ||
149 | /* Known-zeros does not imply known-ones. Therefore unless | ||
150 | op->args[2] is constant, we can't infer anything from it. */ | ||
151 | if (arg_is_const(op->args[2])) { | ||
152 | - mask = ~arg_info(op->args[2])->mask; | ||
153 | + z_mask = ~arg_info(op->args[2])->z_mask; | ||
154 | goto and_const; | ||
155 | } | ||
156 | /* But we certainly know nothing outside args[1] may be set. */ | ||
157 | - mask = arg_info(op->args[1])->mask; | ||
158 | + z_mask = arg_info(op->args[1])->z_mask; | ||
159 | break; | ||
160 | |||
161 | case INDEX_op_sar_i32: | ||
162 | if (arg_is_const(op->args[2])) { | ||
163 | tmp = arg_info(op->args[2])->val & 31; | ||
164 | - mask = (int32_t)arg_info(op->args[1])->mask >> tmp; | ||
165 | + z_mask = (int32_t)arg_info(op->args[1])->z_mask >> tmp; | ||
166 | } | ||
167 | break; | ||
168 | case INDEX_op_sar_i64: | ||
169 | if (arg_is_const(op->args[2])) { | ||
170 | tmp = arg_info(op->args[2])->val & 63; | ||
171 | - mask = (int64_t)arg_info(op->args[1])->mask >> tmp; | ||
172 | + z_mask = (int64_t)arg_info(op->args[1])->z_mask >> tmp; | ||
173 | } | ||
174 | break; | ||
175 | |||
176 | case INDEX_op_shr_i32: | ||
177 | if (arg_is_const(op->args[2])) { | ||
178 | tmp = arg_info(op->args[2])->val & 31; | ||
179 | - mask = (uint32_t)arg_info(op->args[1])->mask >> tmp; | ||
180 | + z_mask = (uint32_t)arg_info(op->args[1])->z_mask >> tmp; | ||
181 | } | ||
182 | break; | ||
183 | case INDEX_op_shr_i64: | ||
184 | if (arg_is_const(op->args[2])) { | ||
185 | tmp = arg_info(op->args[2])->val & 63; | ||
186 | - mask = (uint64_t)arg_info(op->args[1])->mask >> tmp; | ||
187 | + z_mask = (uint64_t)arg_info(op->args[1])->z_mask >> tmp; | ||
188 | } | ||
189 | break; | ||
190 | |||
191 | case INDEX_op_extrl_i64_i32: | ||
192 | - mask = (uint32_t)arg_info(op->args[1])->mask; | ||
193 | + z_mask = (uint32_t)arg_info(op->args[1])->z_mask; | ||
194 | break; | ||
195 | case INDEX_op_extrh_i64_i32: | ||
196 | - mask = (uint64_t)arg_info(op->args[1])->mask >> 32; | ||
197 | + z_mask = (uint64_t)arg_info(op->args[1])->z_mask >> 32; | ||
198 | break; | ||
199 | |||
200 | CASE_OP_32_64(shl): | ||
201 | if (arg_is_const(op->args[2])) { | ||
202 | tmp = arg_info(op->args[2])->val & (TCG_TARGET_REG_BITS - 1); | ||
203 | - mask = arg_info(op->args[1])->mask << tmp; | ||
204 | + z_mask = arg_info(op->args[1])->z_mask << tmp; | ||
205 | } | ||
206 | break; | ||
207 | |||
208 | CASE_OP_32_64(neg): | ||
209 | /* Set to 1 all bits to the left of the rightmost. */ | ||
210 | - mask = -(arg_info(op->args[1])->mask | ||
211 | - & -arg_info(op->args[1])->mask); | ||
212 | + z_mask = -(arg_info(op->args[1])->z_mask | ||
213 | + & -arg_info(op->args[1])->z_mask); | ||
214 | break; | ||
215 | |||
216 | CASE_OP_32_64(deposit): | ||
217 | - mask = deposit64(arg_info(op->args[1])->mask, | ||
218 | - op->args[3], op->args[4], | ||
219 | - arg_info(op->args[2])->mask); | ||
220 | + z_mask = deposit64(arg_info(op->args[1])->z_mask, | ||
221 | + op->args[3], op->args[4], | ||
222 | + arg_info(op->args[2])->z_mask); | ||
223 | break; | ||
224 | |||
225 | CASE_OP_32_64(extract): | ||
226 | - mask = extract64(arg_info(op->args[1])->mask, | ||
227 | - op->args[2], op->args[3]); | ||
228 | + z_mask = extract64(arg_info(op->args[1])->z_mask, | ||
229 | + op->args[2], op->args[3]); | ||
230 | if (op->args[2] == 0) { | ||
231 | - affected = arg_info(op->args[1])->mask & ~mask; | ||
232 | + affected = arg_info(op->args[1])->z_mask & ~z_mask; | ||
233 | } | ||
234 | break; | ||
235 | CASE_OP_32_64(sextract): | ||
236 | - mask = sextract64(arg_info(op->args[1])->mask, | ||
237 | - op->args[2], op->args[3]); | ||
238 | - if (op->args[2] == 0 && (tcg_target_long)mask >= 0) { | ||
239 | - affected = arg_info(op->args[1])->mask & ~mask; | ||
240 | + z_mask = sextract64(arg_info(op->args[1])->z_mask, | ||
241 | + op->args[2], op->args[3]); | ||
242 | + if (op->args[2] == 0 && (tcg_target_long)z_mask >= 0) { | ||
243 | + affected = arg_info(op->args[1])->z_mask & ~z_mask; | ||
244 | } | ||
245 | break; | ||
246 | |||
247 | CASE_OP_32_64(or): | ||
248 | CASE_OP_32_64(xor): | ||
249 | - mask = arg_info(op->args[1])->mask | arg_info(op->args[2])->mask; | ||
250 | + z_mask = arg_info(op->args[1])->z_mask | ||
251 | + | arg_info(op->args[2])->z_mask; | ||
252 | break; | ||
253 | |||
254 | case INDEX_op_clz_i32: | ||
255 | case INDEX_op_ctz_i32: | ||
256 | - mask = arg_info(op->args[2])->mask | 31; | ||
257 | + z_mask = arg_info(op->args[2])->z_mask | 31; | ||
258 | break; | ||
259 | |||
260 | case INDEX_op_clz_i64: | ||
261 | case INDEX_op_ctz_i64: | ||
262 | - mask = arg_info(op->args[2])->mask | 63; | ||
263 | + z_mask = arg_info(op->args[2])->z_mask | 63; | ||
264 | break; | ||
265 | |||
266 | case INDEX_op_ctpop_i32: | ||
267 | - mask = 32 | 31; | ||
268 | + z_mask = 32 | 31; | ||
269 | break; | ||
270 | case INDEX_op_ctpop_i64: | ||
271 | - mask = 64 | 63; | ||
272 | + z_mask = 64 | 63; | ||
273 | break; | ||
274 | |||
275 | CASE_OP_32_64(setcond): | ||
276 | case INDEX_op_setcond2_i32: | ||
277 | - mask = 1; | ||
278 | + z_mask = 1; | ||
279 | break; | ||
280 | |||
281 | CASE_OP_32_64(movcond): | ||
282 | - mask = arg_info(op->args[3])->mask | arg_info(op->args[4])->mask; | ||
283 | + z_mask = arg_info(op->args[3])->z_mask | ||
284 | + | arg_info(op->args[4])->z_mask; | ||
285 | break; | ||
286 | |||
287 | CASE_OP_32_64(ld8u): | ||
288 | - mask = 0xff; | ||
289 | + z_mask = 0xff; | ||
290 | break; | ||
291 | CASE_OP_32_64(ld16u): | ||
292 | - mask = 0xffff; | ||
293 | + z_mask = 0xffff; | ||
294 | break; | ||
295 | case INDEX_op_ld32u_i64: | ||
296 | - mask = 0xffffffffu; | ||
297 | + z_mask = 0xffffffffu; | ||
298 | break; | ||
299 | |||
300 | CASE_OP_32_64(qemu_ld): | ||
301 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
302 | MemOpIdx oi = op->args[nb_oargs + nb_iargs]; | ||
303 | MemOp mop = get_memop(oi); | ||
304 | if (!(mop & MO_SIGN)) { | ||
305 | - mask = (2ULL << ((8 << (mop & MO_SIZE)) - 1)) - 1; | ||
306 | + z_mask = (2ULL << ((8 << (mop & MO_SIZE)) - 1)) - 1; | ||
307 | } | ||
308 | } | ||
309 | break; | ||
310 | |||
311 | CASE_OP_32_64(bswap16): | ||
312 | - mask = arg_info(op->args[1])->mask; | ||
313 | - if (mask <= 0xffff) { | ||
314 | + z_mask = arg_info(op->args[1])->z_mask; | ||
315 | + if (z_mask <= 0xffff) { | ||
316 | op->args[2] |= TCG_BSWAP_IZ; | ||
317 | } | ||
318 | - mask = bswap16(mask); | ||
319 | + z_mask = bswap16(z_mask); | ||
320 | switch (op->args[2] & (TCG_BSWAP_OZ | TCG_BSWAP_OS)) { | ||
321 | case TCG_BSWAP_OZ: | ||
322 | break; | ||
323 | case TCG_BSWAP_OS: | ||
324 | - mask = (int16_t)mask; | ||
325 | + z_mask = (int16_t)z_mask; | ||
326 | break; | ||
327 | default: /* undefined high bits */ | ||
328 | - mask |= MAKE_64BIT_MASK(16, 48); | ||
329 | + z_mask |= MAKE_64BIT_MASK(16, 48); | ||
330 | break; | ||
331 | } | ||
332 | break; | ||
333 | |||
334 | case INDEX_op_bswap32_i64: | ||
335 | - mask = arg_info(op->args[1])->mask; | ||
336 | - if (mask <= 0xffffffffu) { | ||
337 | + z_mask = arg_info(op->args[1])->z_mask; | ||
338 | + if (z_mask <= 0xffffffffu) { | ||
339 | op->args[2] |= TCG_BSWAP_IZ; | ||
340 | } | ||
341 | - mask = bswap32(mask); | ||
342 | + z_mask = bswap32(z_mask); | ||
343 | switch (op->args[2] & (TCG_BSWAP_OZ | TCG_BSWAP_OS)) { | ||
344 | case TCG_BSWAP_OZ: | ||
345 | break; | ||
346 | case TCG_BSWAP_OS: | ||
347 | - mask = (int32_t)mask; | ||
348 | + z_mask = (int32_t)z_mask; | ||
349 | break; | ||
350 | default: /* undefined high bits */ | ||
351 | - mask |= MAKE_64BIT_MASK(32, 32); | ||
352 | + z_mask |= MAKE_64BIT_MASK(32, 32); | ||
353 | break; | ||
354 | } | ||
355 | break; | ||
356 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
357 | /* 32-bit ops generate 32-bit results. For the result is zero test | ||
358 | below, we can ignore high bits, but for further optimizations we | ||
359 | need to record that the high bits contain garbage. */ | ||
360 | - partmask = mask; | ||
361 | + partmask = z_mask; | ||
362 | if (!(def->flags & TCG_OPF_64BIT)) { | ||
363 | - mask |= ~(tcg_target_ulong)0xffffffffu; | ||
364 | + z_mask |= ~(tcg_target_ulong)0xffffffffu; | ||
365 | partmask &= 0xffffffffu; | ||
366 | affected &= 0xffffffffu; | ||
367 | } | ||
368 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
369 | vs the high word of the input. */ | ||
370 | do_setcond_high: | ||
371 | reset_temp(op->args[0]); | ||
372 | - arg_info(op->args[0])->mask = 1; | ||
373 | + arg_info(op->args[0])->z_mask = 1; | ||
374 | op->opc = INDEX_op_setcond_i32; | ||
375 | op->args[1] = op->args[2]; | ||
376 | op->args[2] = op->args[4]; | ||
377 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
378 | } | ||
379 | do_setcond_low: | ||
380 | reset_temp(op->args[0]); | ||
381 | - arg_info(op->args[0])->mask = 1; | ||
382 | + arg_info(op->args[0])->z_mask = 1; | ||
383 | op->opc = INDEX_op_setcond_i32; | ||
384 | op->args[2] = op->args[3]; | ||
385 | op->args[3] = op->args[5]; | ||
386 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
387 | /* Default case: we know nothing about operation (or were unable | ||
388 | to compute the operation result) so no propagation is done. | ||
389 | We trash everything if the operation is the end of a basic | ||
390 | - block, otherwise we only trash the output args. "mask" is | ||
391 | + block, otherwise we only trash the output args. "z_mask" is | ||
392 | the non-zero bits mask for the first output arg. */ | ||
393 | if (def->flags & TCG_OPF_BB_END) { | ||
394 | memset(&temps_used, 0, sizeof(temps_used)); | ||
395 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
396 | /* Save the corresponding known-zero bits mask for the | ||
397 | first output argument (only one supported so far). */ | ||
398 | if (i == 0) { | ||
399 | - arg_info(op->args[i])->mask = mask; | ||
400 | + arg_info(op->args[i])->z_mask = z_mask; | ||
401 | } | ||
402 | } | ||
403 | } | ||
404 | -- | 44 | -- |
405 | 2.25.1 | 45 | 2.34.1 |
406 | 46 | ||
407 | 47 | diff view generated by jsdifflib |
1 | Copy z_mask into OptContext, for writeback to the | 1 | Attempt to reduce the lifetime of TEMP_TB. |
---|---|---|---|
2 | first output within the new function. | ||
3 | 2 | ||
4 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 3 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> |
5 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | ||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
7 | --- | 5 | --- |
8 | tcg/optimize.c | 49 +++++++++++++++++++++++++++++++++---------------- | 6 | tcg/tcg.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
9 | 1 file changed, 33 insertions(+), 16 deletions(-) | 7 | 1 file changed, 70 insertions(+) |
10 | 8 | ||
11 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 9 | diff --git a/tcg/tcg.c b/tcg/tcg.c |
12 | index XXXXXXX..XXXXXXX 100644 | 10 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/tcg/optimize.c | 11 | --- a/tcg/tcg.c |
14 | +++ b/tcg/optimize.c | 12 | +++ b/tcg/tcg.c |
15 | @@ -XXX,XX +XXX,XX @@ typedef struct OptContext { | 13 | @@ -XXX,XX +XXX,XX @@ static void la_cross_call(TCGContext *s, int nt) |
16 | TCGContext *tcg; | ||
17 | TCGOp *prev_mb; | ||
18 | TCGTempSet temps_used; | ||
19 | + | ||
20 | + /* In flight values from optimization. */ | ||
21 | + uint64_t z_mask; | ||
22 | } OptContext; | ||
23 | |||
24 | static inline TempOptInfo *ts_info(TCGTemp *ts) | ||
25 | @@ -XXX,XX +XXX,XX @@ static void copy_propagate(OptContext *ctx, TCGOp *op, | ||
26 | } | 14 | } |
27 | } | 15 | } |
28 | 16 | ||
29 | +static void finish_folding(OptContext *ctx, TCGOp *op) | 17 | +/* |
18 | + * Liveness analysis: Verify the lifetime of TEMP_TB, and reduce | ||
19 | + * to TEMP_EBB, if possible. | ||
20 | + */ | ||
21 | +static void __attribute__((noinline)) | ||
22 | +liveness_pass_0(TCGContext *s) | ||
30 | +{ | 23 | +{ |
31 | + const TCGOpDef *def = &tcg_op_defs[op->opc]; | 24 | + void * const multiple_ebb = (void *)(uintptr_t)-1; |
32 | + int i, nb_oargs; | 25 | + int nb_temps = s->nb_temps; |
26 | + TCGOp *op, *ebb; | ||
27 | + | ||
28 | + for (int i = s->nb_globals; i < nb_temps; ++i) { | ||
29 | + s->temps[i].state_ptr = NULL; | ||
30 | + } | ||
33 | + | 31 | + |
34 | + /* | 32 | + /* |
35 | + * For an opcode that ends a BB, reset all temp data. | 33 | + * Represent each EBB by the op at which it begins. In the case of |
36 | + * We do no cross-BB optimization. | 34 | + * the first EBB, this is the first op, otherwise it is a label. |
35 | + * Collect the uses of each TEMP_TB: NULL for unused, EBB for use | ||
36 | + * within a single EBB, else MULTIPLE_EBB. | ||
37 | + */ | 37 | + */ |
38 | + if (def->flags & TCG_OPF_BB_END) { | 38 | + ebb = QTAILQ_FIRST(&s->ops); |
39 | + memset(&ctx->temps_used, 0, sizeof(ctx->temps_used)); | 39 | + QTAILQ_FOREACH(op, &s->ops, link) { |
40 | + ctx->prev_mb = NULL; | 40 | + const TCGOpDef *def; |
41 | + return; | 41 | + int nb_oargs, nb_iargs; |
42 | + | ||
43 | + switch (op->opc) { | ||
44 | + case INDEX_op_set_label: | ||
45 | + ebb = op; | ||
46 | + continue; | ||
47 | + case INDEX_op_discard: | ||
48 | + continue; | ||
49 | + case INDEX_op_call: | ||
50 | + nb_oargs = TCGOP_CALLO(op); | ||
51 | + nb_iargs = TCGOP_CALLI(op); | ||
52 | + break; | ||
53 | + default: | ||
54 | + def = &tcg_op_defs[op->opc]; | ||
55 | + nb_oargs = def->nb_oargs; | ||
56 | + nb_iargs = def->nb_iargs; | ||
57 | + break; | ||
58 | + } | ||
59 | + | ||
60 | + for (int i = 0; i < nb_oargs + nb_iargs; ++i) { | ||
61 | + TCGTemp *ts = arg_temp(op->args[i]); | ||
62 | + | ||
63 | + if (ts->kind != TEMP_TB) { | ||
64 | + continue; | ||
65 | + } | ||
66 | + if (ts->state_ptr == NULL) { | ||
67 | + ts->state_ptr = ebb; | ||
68 | + } else if (ts->state_ptr != ebb) { | ||
69 | + ts->state_ptr = multiple_ebb; | ||
70 | + } | ||
71 | + } | ||
42 | + } | 72 | + } |
43 | + | 73 | + |
44 | + nb_oargs = def->nb_oargs; | 74 | + /* |
45 | + for (i = 0; i < nb_oargs; i++) { | 75 | + * For TEMP_TB that turned out not to be used beyond one EBB, |
46 | + reset_temp(op->args[i]); | 76 | + * reduce the liveness to TEMP_EBB. |
47 | + /* | 77 | + */ |
48 | + * Save the corresponding known-zero bits mask for the | 78 | + for (int i = s->nb_globals; i < nb_temps; ++i) { |
49 | + * first output argument (only one supported so far). | 79 | + TCGTemp *ts = &s->temps[i]; |
50 | + */ | 80 | + if (ts->kind == TEMP_TB && ts->state_ptr != multiple_ebb) { |
51 | + if (i == 0) { | 81 | + ts->kind = TEMP_EBB; |
52 | + arg_info(op->args[i])->z_mask = ctx->z_mask; | ||
53 | + } | 82 | + } |
54 | + } | 83 | + } |
55 | +} | 84 | +} |
56 | + | 85 | + |
57 | static bool fold_call(OptContext *ctx, TCGOp *op) | 86 | /* Liveness analysis : update the opc_arg_life array to tell if a |
58 | { | 87 | given input arguments is dead. Instructions updating dead |
59 | TCGContext *s = ctx->tcg; | 88 | temporaries are removed. */ |
60 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | 89 | @@ -XXX,XX +XXX,XX @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb, target_ulong pc_start) |
61 | partmask &= 0xffffffffu; | 90 | #endif |
62 | affected &= 0xffffffffu; | 91 | |
63 | } | 92 | reachable_code_pass(s); |
64 | + ctx.z_mask = z_mask; | 93 | + liveness_pass_0(s); |
65 | 94 | liveness_pass_1(s); | |
66 | if (partmask == 0) { | 95 | |
67 | tcg_opt_gen_movi(&ctx, op, op->args[0], 0); | 96 | if (s->nb_indirects > 0) { |
68 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
69 | break; | ||
70 | } | ||
71 | |||
72 | - /* Some of the folding above can change opc. */ | ||
73 | - opc = op->opc; | ||
74 | - def = &tcg_op_defs[opc]; | ||
75 | - if (def->flags & TCG_OPF_BB_END) { | ||
76 | - memset(&ctx.temps_used, 0, sizeof(ctx.temps_used)); | ||
77 | - } else { | ||
78 | - int nb_oargs = def->nb_oargs; | ||
79 | - for (i = 0; i < nb_oargs; i++) { | ||
80 | - reset_temp(op->args[i]); | ||
81 | - /* Save the corresponding known-zero bits mask for the | ||
82 | - first output argument (only one supported so far). */ | ||
83 | - if (i == 0) { | ||
84 | - arg_info(op->args[i])->z_mask = z_mask; | ||
85 | - } | ||
86 | - } | ||
87 | - } | ||
88 | + finish_folding(&ctx, op); | ||
89 | |||
90 | /* Eliminate duplicate and redundant fence instructions. */ | ||
91 | if (ctx.prev_mb) { | ||
92 | -- | 97 | -- |
93 | 2.25.1 | 98 | 2.34.1 |
94 | 99 | ||
95 | 100 | diff view generated by jsdifflib |
1 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | 1 | TEMP_NORMAL is a subset of TEMP_EBB. Promote single basic |
---|---|---|---|
2 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 2 | block temps to single extended basic block. |
3 | |||
4 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
4 | --- | 6 | --- |
5 | tcg/optimize.c | 37 +++++++++++++++++++++---------------- | 7 | include/tcg/tcg.h | 2 -- |
6 | 1 file changed, 21 insertions(+), 16 deletions(-) | 8 | tcg/tcg.c | 19 +++---------------- |
9 | 2 files changed, 3 insertions(+), 18 deletions(-) | ||
7 | 10 | ||
8 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 11 | diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h |
9 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
10 | --- a/tcg/optimize.c | 13 | --- a/include/tcg/tcg.h |
11 | +++ b/tcg/optimize.c | 14 | +++ b/include/tcg/tcg.h |
12 | @@ -XXX,XX +XXX,XX @@ static bool fold_mul_highpart(OptContext *ctx, TCGOp *op) | 15 | @@ -XXX,XX +XXX,XX @@ typedef enum TCGTempVal { |
13 | return fold_const2(ctx, op); | 16 | } TCGTempVal; |
17 | |||
18 | typedef enum TCGTempKind { | ||
19 | - /* Temp is dead at the end of all basic blocks. */ | ||
20 | - TEMP_NORMAL, | ||
21 | /* | ||
22 | * Temp is dead at the end of the extended basic block (EBB), | ||
23 | * the single-entry multiple-exit region that falls through | ||
24 | diff --git a/tcg/tcg.c b/tcg/tcg.c | ||
25 | index XXXXXXX..XXXXXXX 100644 | ||
26 | --- a/tcg/tcg.c | ||
27 | +++ b/tcg/tcg.c | ||
28 | @@ -XXX,XX +XXX,XX @@ TCGTemp *tcg_global_mem_new_internal(TCGType type, TCGv_ptr base, | ||
29 | TCGTemp *tcg_temp_new_internal(TCGType type, bool temp_local) | ||
30 | { | ||
31 | TCGContext *s = tcg_ctx; | ||
32 | - TCGTempKind kind = temp_local ? TEMP_TB : TEMP_NORMAL; | ||
33 | + TCGTempKind kind = temp_local ? TEMP_TB : TEMP_EBB; | ||
34 | TCGTemp *ts; | ||
35 | int idx, k; | ||
36 | |||
37 | @@ -XXX,XX +XXX,XX @@ void tcg_temp_free_internal(TCGTemp *ts) | ||
38 | * silently ignore free. | ||
39 | */ | ||
40 | return; | ||
41 | - case TEMP_NORMAL: | ||
42 | + case TEMP_EBB: | ||
43 | case TEMP_TB: | ||
44 | break; | ||
45 | default: | ||
46 | @@ -XXX,XX +XXX,XX @@ void tcg_temp_free_internal(TCGTemp *ts) | ||
47 | #endif | ||
48 | |||
49 | idx = temp_idx(ts); | ||
50 | - k = ts->base_type + (ts->kind == TEMP_NORMAL ? 0 : TCG_TYPE_COUNT); | ||
51 | + k = ts->base_type + (ts->kind == TEMP_EBB ? 0 : TCG_TYPE_COUNT); | ||
52 | set_bit(idx, s->free_temps[k].l); | ||
14 | } | 53 | } |
15 | 54 | ||
16 | +static bool fold_mulu2_i32(OptContext *ctx, TCGOp *op) | 55 | @@ -XXX,XX +XXX,XX @@ static void tcg_reg_alloc_start(TCGContext *s) |
17 | +{ | 56 | break; |
18 | + if (arg_is_const(op->args[2]) && arg_is_const(op->args[3])) { | 57 | case TEMP_GLOBAL: |
19 | + uint32_t a = arg_info(op->args[2])->val; | 58 | break; |
20 | + uint32_t b = arg_info(op->args[3])->val; | 59 | - case TEMP_NORMAL: |
21 | + uint64_t r = (uint64_t)a * b; | 60 | case TEMP_EBB: |
22 | + TCGArg rl, rh; | 61 | val = TEMP_VAL_DEAD; |
23 | + TCGOp *op2 = tcg_op_insert_before(ctx->tcg, op, INDEX_op_mov_i32); | 62 | /* fall through */ |
24 | + | 63 | @@ -XXX,XX +XXX,XX @@ static char *tcg_get_arg_str_ptr(TCGContext *s, char *buf, int buf_size, |
25 | + rl = op->args[0]; | 64 | snprintf(buf, buf_size, "loc%d", idx - s->nb_globals); |
26 | + rh = op->args[1]; | 65 | break; |
27 | + tcg_opt_gen_movi(ctx, op, rl, (int32_t)r); | 66 | case TEMP_EBB: |
28 | + tcg_opt_gen_movi(ctx, op2, rh, (int32_t)(r >> 32)); | 67 | - snprintf(buf, buf_size, "ebb%d", idx - s->nb_globals); |
29 | + return true; | 68 | - break; |
30 | + } | 69 | - case TEMP_NORMAL: |
31 | + return false; | 70 | snprintf(buf, buf_size, "tmp%d", idx - s->nb_globals); |
32 | +} | 71 | break; |
33 | + | 72 | case TEMP_CONST: |
34 | static bool fold_nand(OptContext *ctx, TCGOp *op) | 73 | @@ -XXX,XX +XXX,XX @@ static void la_bb_end(TCGContext *s, int ng, int nt) |
35 | { | 74 | case TEMP_TB: |
36 | return fold_const2(ctx, op); | 75 | state = TS_DEAD | TS_MEM; |
37 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | 76 | break; |
77 | - case TEMP_NORMAL: | ||
78 | case TEMP_EBB: | ||
79 | case TEMP_CONST: | ||
80 | state = TS_DEAD; | ||
81 | @@ -XXX,XX +XXX,XX @@ static void la_bb_sync(TCGContext *s, int ng, int nt) | ||
82 | continue; | ||
38 | } | 83 | } |
39 | break; | 84 | break; |
40 | 85 | - case TEMP_NORMAL: | |
41 | - case INDEX_op_mulu2_i32: | 86 | - s->temps[i].state = TS_DEAD; |
42 | - if (arg_is_const(op->args[2]) && arg_is_const(op->args[3])) { | ||
43 | - uint32_t a = arg_info(op->args[2])->val; | ||
44 | - uint32_t b = arg_info(op->args[3])->val; | ||
45 | - uint64_t r = (uint64_t)a * b; | ||
46 | - TCGArg rl, rh; | ||
47 | - TCGOp *op2 = tcg_op_insert_before(s, op, INDEX_op_mov_i32); | ||
48 | - | ||
49 | - rl = op->args[0]; | ||
50 | - rh = op->args[1]; | ||
51 | - tcg_opt_gen_movi(&ctx, op, rl, (int32_t)r); | ||
52 | - tcg_opt_gen_movi(&ctx, op2, rh, (int32_t)(r >> 32)); | ||
53 | - continue; | ||
54 | - } | ||
55 | - break; | 87 | - break; |
56 | - | 88 | case TEMP_EBB: |
57 | default: | 89 | case TEMP_CONST: |
90 | continue; | ||
91 | @@ -XXX,XX +XXX,XX @@ static void temp_free_or_dead(TCGContext *s, TCGTemp *ts, int free_or_dead) | ||
92 | case TEMP_TB: | ||
93 | new_type = TEMP_VAL_MEM; | ||
94 | break; | ||
95 | - case TEMP_NORMAL: | ||
96 | case TEMP_EBB: | ||
97 | new_type = free_or_dead < 0 ? TEMP_VAL_MEM : TEMP_VAL_DEAD; | ||
98 | break; | ||
99 | @@ -XXX,XX +XXX,XX @@ static void tcg_reg_alloc_bb_end(TCGContext *s, TCGRegSet allocated_regs) | ||
100 | case TEMP_TB: | ||
101 | temp_save(s, ts, allocated_regs); | ||
58 | break; | 102 | break; |
59 | 103 | - case TEMP_NORMAL: | |
60 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | 104 | case TEMP_EBB: |
61 | CASE_OP_32_64(muluh): | 105 | /* The liveness analysis already ensures that temps are dead. |
62 | done = fold_mul_highpart(&ctx, op); | 106 | Keep an tcg_debug_assert for safety. */ |
107 | @@ -XXX,XX +XXX,XX @@ static void tcg_reg_alloc_cbranch(TCGContext *s, TCGRegSet allocated_regs) | ||
108 | case TEMP_TB: | ||
109 | tcg_debug_assert(ts->val_type != TEMP_VAL_REG || ts->mem_coherent); | ||
63 | break; | 110 | break; |
64 | + case INDEX_op_mulu2_i32: | 111 | - case TEMP_NORMAL: |
65 | + done = fold_mulu2_i32(&ctx, op); | 112 | - tcg_debug_assert(ts->val_type == TEMP_VAL_DEAD); |
66 | + break; | 113 | - break; |
67 | CASE_OP_32_64(nand): | 114 | case TEMP_EBB: |
68 | done = fold_nand(&ctx, op); | 115 | case TEMP_CONST: |
69 | break; | 116 | break; |
70 | -- | 117 | -- |
71 | 2.25.1 | 118 | 2.34.1 |
72 | 119 | ||
73 | 120 | diff view generated by jsdifflib |
1 | Pull the "op r, a, a => movi r, 0" optimization into a function, | 1 | While the argument can only be TEMP_EBB or TEMP_TB, |
---|---|---|---|
2 | and use it in the outer opcode fold functions. | 2 | it's more obvious this way. |
3 | 3 | ||
4 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | 4 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
7 | --- | 6 | --- |
8 | tcg/optimize.c | 41 ++++++++++++++++++++++++----------------- | 7 | include/tcg/tcg.h | 18 +++++++++--------- |
9 | 1 file changed, 24 insertions(+), 17 deletions(-) | 8 | tcg/tcg.c | 8 ++++---- |
9 | 2 files changed, 13 insertions(+), 13 deletions(-) | ||
10 | 10 | ||
11 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 11 | diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h |
12 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/tcg/optimize.c | 13 | --- a/include/tcg/tcg.h |
14 | +++ b/tcg/optimize.c | 14 | +++ b/include/tcg/tcg.h |
15 | @@ -XXX,XX +XXX,XX @@ static bool fold_const2(OptContext *ctx, TCGOp *op) | 15 | @@ -XXX,XX +XXX,XX @@ void tcg_set_frame(TCGContext *s, TCGReg reg, intptr_t start, intptr_t size); |
16 | return false; | 16 | |
17 | TCGTemp *tcg_global_mem_new_internal(TCGType, TCGv_ptr, | ||
18 | intptr_t, const char *); | ||
19 | -TCGTemp *tcg_temp_new_internal(TCGType, bool); | ||
20 | +TCGTemp *tcg_temp_new_internal(TCGType, TCGTempKind); | ||
21 | void tcg_temp_free_internal(TCGTemp *); | ||
22 | TCGv_vec tcg_temp_new_vec(TCGType type); | ||
23 | TCGv_vec tcg_temp_new_vec_matching(TCGv_vec match); | ||
24 | @@ -XXX,XX +XXX,XX @@ static inline TCGv_i32 tcg_global_mem_new_i32(TCGv_ptr reg, intptr_t offset, | ||
25 | |||
26 | static inline TCGv_i32 tcg_temp_new_i32(void) | ||
27 | { | ||
28 | - TCGTemp *t = tcg_temp_new_internal(TCG_TYPE_I32, false); | ||
29 | + TCGTemp *t = tcg_temp_new_internal(TCG_TYPE_I32, TEMP_EBB); | ||
30 | return temp_tcgv_i32(t); | ||
17 | } | 31 | } |
18 | 32 | ||
19 | +/* If the binary operation has both arguments equal, fold to @i. */ | 33 | static inline TCGv_i32 tcg_temp_local_new_i32(void) |
20 | +static bool fold_xx_to_i(OptContext *ctx, TCGOp *op, uint64_t i) | ||
21 | +{ | ||
22 | + if (args_are_copies(op->args[1], op->args[2])) { | ||
23 | + return tcg_opt_gen_movi(ctx, op, op->args[0], i); | ||
24 | + } | ||
25 | + return false; | ||
26 | +} | ||
27 | + | ||
28 | /* | ||
29 | * These outermost fold_<op> functions are sorted alphabetically. | ||
30 | */ | ||
31 | @@ -XXX,XX +XXX,XX @@ static bool fold_and(OptContext *ctx, TCGOp *op) | ||
32 | |||
33 | static bool fold_andc(OptContext *ctx, TCGOp *op) | ||
34 | { | 34 | { |
35 | - return fold_const2(ctx, op); | 35 | - TCGTemp *t = tcg_temp_new_internal(TCG_TYPE_I32, true); |
36 | + if (fold_const2(ctx, op) || | 36 | + TCGTemp *t = tcg_temp_new_internal(TCG_TYPE_I32, TEMP_TB); |
37 | + fold_xx_to_i(ctx, op, 0)) { | 37 | return temp_tcgv_i32(t); |
38 | + return true; | ||
39 | + } | ||
40 | + return false; | ||
41 | } | 38 | } |
42 | 39 | ||
43 | static bool fold_brcond(OptContext *ctx, TCGOp *op) | 40 | @@ -XXX,XX +XXX,XX @@ static inline TCGv_i64 tcg_global_mem_new_i64(TCGv_ptr reg, intptr_t offset, |
44 | @@ -XXX,XX +XXX,XX @@ static bool fold_shift(OptContext *ctx, TCGOp *op) | 41 | |
45 | 42 | static inline TCGv_i64 tcg_temp_new_i64(void) | |
46 | static bool fold_sub(OptContext *ctx, TCGOp *op) | ||
47 | { | 43 | { |
48 | - return fold_const2(ctx, op); | 44 | - TCGTemp *t = tcg_temp_new_internal(TCG_TYPE_I64, false); |
49 | + if (fold_const2(ctx, op) || | 45 | + TCGTemp *t = tcg_temp_new_internal(TCG_TYPE_I64, TEMP_EBB); |
50 | + fold_xx_to_i(ctx, op, 0)) { | 46 | return temp_tcgv_i64(t); |
51 | + return true; | ||
52 | + } | ||
53 | + return false; | ||
54 | } | 47 | } |
55 | 48 | ||
56 | static bool fold_sub2_i32(OptContext *ctx, TCGOp *op) | 49 | static inline TCGv_i64 tcg_temp_local_new_i64(void) |
57 | @@ -XXX,XX +XXX,XX @@ static bool fold_sub2_i32(OptContext *ctx, TCGOp *op) | ||
58 | |||
59 | static bool fold_xor(OptContext *ctx, TCGOp *op) | ||
60 | { | 50 | { |
61 | - return fold_const2(ctx, op); | 51 | - TCGTemp *t = tcg_temp_new_internal(TCG_TYPE_I64, true); |
62 | + if (fold_const2(ctx, op) || | 52 | + TCGTemp *t = tcg_temp_new_internal(TCG_TYPE_I64, TEMP_TB); |
63 | + fold_xx_to_i(ctx, op, 0)) { | 53 | return temp_tcgv_i64(t); |
64 | + return true; | ||
65 | + } | ||
66 | + return false; | ||
67 | } | 54 | } |
68 | 55 | ||
69 | /* Propagate constants and copies, fold constant expressions. */ | 56 | static inline TCGv_i128 tcg_temp_new_i128(void) |
70 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | 57 | { |
71 | break; | 58 | - TCGTemp *t = tcg_temp_new_internal(TCG_TYPE_I128, false); |
72 | } | 59 | + TCGTemp *t = tcg_temp_new_internal(TCG_TYPE_I128, TEMP_EBB); |
73 | 60 | return temp_tcgv_i128(t); | |
74 | - /* Simplify expression for "op r, a, a => movi r, 0" cases */ | 61 | } |
75 | - switch (opc) { | 62 | |
76 | - CASE_OP_32_64_VEC(andc): | 63 | static inline TCGv_i128 tcg_temp_local_new_i128(void) |
77 | - CASE_OP_32_64_VEC(sub): | 64 | { |
78 | - CASE_OP_32_64_VEC(xor): | 65 | - TCGTemp *t = tcg_temp_new_internal(TCG_TYPE_I128, true); |
79 | - if (args_are_copies(op->args[1], op->args[2])) { | 66 | + TCGTemp *t = tcg_temp_new_internal(TCG_TYPE_I128, TEMP_TB); |
80 | - tcg_opt_gen_movi(&ctx, op, op->args[0], 0); | 67 | return temp_tcgv_i128(t); |
81 | - continue; | 68 | } |
82 | - } | 69 | |
83 | - break; | 70 | @@ -XXX,XX +XXX,XX @@ static inline TCGv_ptr tcg_global_mem_new_ptr(TCGv_ptr reg, intptr_t offset, |
84 | - default: | 71 | |
85 | - break; | 72 | static inline TCGv_ptr tcg_temp_new_ptr(void) |
86 | - } | 73 | { |
87 | - | 74 | - TCGTemp *t = tcg_temp_new_internal(TCG_TYPE_PTR, false); |
88 | /* | 75 | + TCGTemp *t = tcg_temp_new_internal(TCG_TYPE_PTR, TEMP_EBB); |
89 | * Process each opcode. | 76 | return temp_tcgv_ptr(t); |
90 | * Sorted alphabetically by opcode as much as possible. | 77 | } |
78 | |||
79 | static inline TCGv_ptr tcg_temp_local_new_ptr(void) | ||
80 | { | ||
81 | - TCGTemp *t = tcg_temp_new_internal(TCG_TYPE_PTR, true); | ||
82 | + TCGTemp *t = tcg_temp_new_internal(TCG_TYPE_PTR, TEMP_TB); | ||
83 | return temp_tcgv_ptr(t); | ||
84 | } | ||
85 | |||
86 | diff --git a/tcg/tcg.c b/tcg/tcg.c | ||
87 | index XXXXXXX..XXXXXXX 100644 | ||
88 | --- a/tcg/tcg.c | ||
89 | +++ b/tcg/tcg.c | ||
90 | @@ -XXX,XX +XXX,XX @@ TCGTemp *tcg_global_mem_new_internal(TCGType type, TCGv_ptr base, | ||
91 | return ts; | ||
92 | } | ||
93 | |||
94 | -TCGTemp *tcg_temp_new_internal(TCGType type, bool temp_local) | ||
95 | +TCGTemp *tcg_temp_new_internal(TCGType type, TCGTempKind kind) | ||
96 | { | ||
97 | TCGContext *s = tcg_ctx; | ||
98 | - TCGTempKind kind = temp_local ? TEMP_TB : TEMP_EBB; | ||
99 | + bool temp_local = kind == TEMP_TB; | ||
100 | TCGTemp *ts; | ||
101 | int idx, k; | ||
102 | |||
103 | @@ -XXX,XX +XXX,XX @@ TCGv_vec tcg_temp_new_vec(TCGType type) | ||
104 | } | ||
105 | #endif | ||
106 | |||
107 | - t = tcg_temp_new_internal(type, 0); | ||
108 | + t = tcg_temp_new_internal(type, TEMP_EBB); | ||
109 | return temp_tcgv_vec(t); | ||
110 | } | ||
111 | |||
112 | @@ -XXX,XX +XXX,XX @@ TCGv_vec tcg_temp_new_vec_matching(TCGv_vec match) | ||
113 | |||
114 | tcg_debug_assert(t->temp_allocated != 0); | ||
115 | |||
116 | - t = tcg_temp_new_internal(t->base_type, 0); | ||
117 | + t = tcg_temp_new_internal(t->base_type, TEMP_EBB); | ||
118 | return temp_tcgv_vec(t); | ||
119 | } | ||
120 | |||
91 | -- | 121 | -- |
92 | 2.25.1 | 122 | 2.34.1 |
93 | 123 | ||
94 | 124 | diff view generated by jsdifflib |
1 | Recognize the identity function for division. | 1 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
---|---|---|---|
2 | 2 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | |
3 | Suggested-by: Luis Pires <luis.pires@eldorado.org.br> | ||
4 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | ||
5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
7 | --- | 4 | --- |
8 | tcg/optimize.c | 6 +++++- | 5 | include/exec/gen-icount.h | 4 +--- |
9 | 1 file changed, 5 insertions(+), 1 deletion(-) | 6 | 1 file changed, 1 insertion(+), 3 deletions(-) |
10 | 7 | ||
11 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 8 | diff --git a/include/exec/gen-icount.h b/include/exec/gen-icount.h |
12 | index XXXXXXX..XXXXXXX 100644 | 9 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/tcg/optimize.c | 10 | --- a/include/exec/gen-icount.h |
14 | +++ b/tcg/optimize.c | 11 | +++ b/include/exec/gen-icount.h |
15 | @@ -XXX,XX +XXX,XX @@ static bool fold_deposit(OptContext *ctx, TCGOp *op) | 12 | @@ -XXX,XX +XXX,XX @@ static TCGOp *icount_start_insn; |
16 | 13 | ||
17 | static bool fold_divide(OptContext *ctx, TCGOp *op) | 14 | static inline void gen_io_start(void) |
18 | { | 15 | { |
19 | - return fold_const2(ctx, op); | 16 | - TCGv_i32 tmp = tcg_const_i32(1); |
20 | + if (fold_const2(ctx, op) || | 17 | - tcg_gen_st_i32(tmp, cpu_env, |
21 | + fold_xi_to_x(ctx, op, 1)) { | 18 | + tcg_gen_st_i32(tcg_constant_i32(1), cpu_env, |
22 | + return true; | 19 | offsetof(ArchCPU, parent_obj.can_do_io) - |
23 | + } | 20 | offsetof(ArchCPU, env)); |
24 | + return false; | 21 | - tcg_temp_free_i32(tmp); |
25 | } | 22 | } |
26 | 23 | ||
27 | static bool fold_dup(OptContext *ctx, TCGOp *op) | 24 | static inline void gen_tb_start(const TranslationBlock *tb) |
28 | -- | 25 | -- |
29 | 2.25.1 | 26 | 2.34.1 |
30 | 27 | ||
31 | 28 | diff view generated by jsdifflib |
1 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | 1 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
---|---|---|---|
2 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 2 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
4 | --- | 3 | --- |
5 | tcg/optimize.c | 23 ++++++++++++++--------- | 4 | include/tcg/tcg-op.h | 5 +++++ |
6 | 1 file changed, 14 insertions(+), 9 deletions(-) | 5 | 1 file changed, 5 insertions(+) |
7 | 6 | ||
8 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 7 | diff --git a/include/tcg/tcg-op.h b/include/tcg/tcg-op.h |
9 | index XXXXXXX..XXXXXXX 100644 | 8 | index XXXXXXX..XXXXXXX 100644 |
10 | --- a/tcg/optimize.c | 9 | --- a/include/tcg/tcg-op.h |
11 | +++ b/tcg/optimize.c | 10 | +++ b/include/tcg/tcg-op.h |
12 | @@ -XXX,XX +XXX,XX @@ static bool fold_remainder(OptContext *ctx, TCGOp *op) | 11 | @@ -XXX,XX +XXX,XX @@ static inline void tcg_gen_mov_ptr(TCGv_ptr d, TCGv_ptr s) |
13 | return fold_const2(ctx, op); | 12 | glue(tcg_gen_mov_,PTR)((NAT)d, (NAT)s); |
14 | } | 13 | } |
15 | 14 | ||
16 | +static bool fold_setcond(OptContext *ctx, TCGOp *op) | 15 | +static inline void tcg_gen_movi_ptr(TCGv_ptr d, intptr_t s) |
17 | +{ | 16 | +{ |
18 | + TCGCond cond = op->args[3]; | 17 | + glue(tcg_gen_movi_,PTR)((NAT)d, s); |
19 | + int i = do_constant_folding_cond(op->opc, op->args[1], op->args[2], cond); | ||
20 | + | ||
21 | + if (i >= 0) { | ||
22 | + return tcg_opt_gen_movi(ctx, op, op->args[0], i); | ||
23 | + } | ||
24 | + return false; | ||
25 | +} | 18 | +} |
26 | + | 19 | + |
27 | static bool fold_setcond2(OptContext *ctx, TCGOp *op) | 20 | static inline void tcg_gen_brcondi_ptr(TCGCond cond, TCGv_ptr a, |
21 | intptr_t b, TCGLabel *label) | ||
28 | { | 22 | { |
29 | TCGCond cond = op->args[5]; | ||
30 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
31 | } | ||
32 | break; | ||
33 | |||
34 | - CASE_OP_32_64(setcond): | ||
35 | - i = do_constant_folding_cond(opc, op->args[1], | ||
36 | - op->args[2], op->args[3]); | ||
37 | - if (i >= 0) { | ||
38 | - tcg_opt_gen_movi(&ctx, op, op->args[0], i); | ||
39 | - continue; | ||
40 | - } | ||
41 | - break; | ||
42 | - | ||
43 | CASE_OP_32_64(movcond): | ||
44 | i = do_constant_folding_cond(opc, op->args[1], | ||
45 | op->args[2], op->args[5]); | ||
46 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
47 | CASE_OP_32_64(shr): | ||
48 | done = fold_shift(&ctx, op); | ||
49 | break; | ||
50 | + CASE_OP_32_64(setcond): | ||
51 | + done = fold_setcond(&ctx, op); | ||
52 | + break; | ||
53 | case INDEX_op_setcond2_i32: | ||
54 | done = fold_setcond2(&ctx, op); | ||
55 | break; | ||
56 | -- | 23 | -- |
57 | 2.25.1 | 24 | 2.34.1 |
58 | 25 | ||
59 | 26 | diff view generated by jsdifflib |
1 | From: Frédéric Pétrot <frederic.petrot@univ-grenoble-alpes.fr> | 1 | TCG internals will want to be able to allocate and reuse |
---|---|---|---|
2 | explicitly life-limited temporaries. | ||
2 | 3 | ||
3 | Addition of not and xor on 128-bit integers. | 4 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
4 | |||
5 | Signed-off-by: Frédéric Pétrot <frederic.petrot@univ-grenoble-alpes.fr> | ||
6 | Co-authored-by: Fabien Portas <fabien.portas@grenoble-inp.org> | ||
7 | Message-Id: <20211025122818.168890-3-frederic.petrot@univ-grenoble-alpes.fr> | ||
8 | [rth: Split out logical operations.] | ||
9 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
10 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
11 | --- | 6 | --- |
12 | include/qemu/int128.h | 20 ++++++++++++++++++++ | 7 | include/tcg/tcg.h | 28 ++++++++++++++++++++++++++++ |
13 | 1 file changed, 20 insertions(+) | 8 | 1 file changed, 28 insertions(+) |
14 | 9 | ||
15 | diff --git a/include/qemu/int128.h b/include/qemu/int128.h | 10 | diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h |
16 | index XXXXXXX..XXXXXXX 100644 | 11 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/include/qemu/int128.h | 12 | --- a/include/tcg/tcg.h |
18 | +++ b/include/qemu/int128.h | 13 | +++ b/include/tcg/tcg.h |
19 | @@ -XXX,XX +XXX,XX @@ static inline Int128 int128_exts64(int64_t a) | 14 | @@ -XXX,XX +XXX,XX @@ static inline TCGv_i32 tcg_global_mem_new_i32(TCGv_ptr reg, intptr_t offset, |
20 | return a; | 15 | return temp_tcgv_i32(t); |
21 | } | 16 | } |
22 | 17 | ||
23 | +static inline Int128 int128_not(Int128 a) | 18 | +/* Used only by tcg infrastructure: tcg-op.c or plugin-gen.c */ |
19 | +static inline TCGv_i32 tcg_temp_ebb_new_i32(void) | ||
24 | +{ | 20 | +{ |
25 | + return ~a; | 21 | + TCGTemp *t = tcg_temp_new_internal(TCG_TYPE_I32, TEMP_EBB); |
22 | + return temp_tcgv_i32(t); | ||
26 | +} | 23 | +} |
27 | + | 24 | + |
28 | static inline Int128 int128_and(Int128 a, Int128 b) | 25 | static inline TCGv_i32 tcg_temp_new_i32(void) |
29 | { | 26 | { |
30 | return a & b; | 27 | TCGTemp *t = tcg_temp_new_internal(TCG_TYPE_I32, TEMP_EBB); |
31 | @@ -XXX,XX +XXX,XX @@ static inline Int128 int128_or(Int128 a, Int128 b) | 28 | @@ -XXX,XX +XXX,XX @@ static inline TCGv_i64 tcg_global_mem_new_i64(TCGv_ptr reg, intptr_t offset, |
32 | return a | b; | 29 | return temp_tcgv_i64(t); |
33 | } | 30 | } |
34 | 31 | ||
35 | +static inline Int128 int128_xor(Int128 a, Int128 b) | 32 | +/* Used only by tcg infrastructure: tcg-op.c or plugin-gen.c */ |
33 | +static inline TCGv_i64 tcg_temp_ebb_new_i64(void) | ||
36 | +{ | 34 | +{ |
37 | + return a ^ b; | 35 | + TCGTemp *t = tcg_temp_new_internal(TCG_TYPE_I64, TEMP_EBB); |
36 | + return temp_tcgv_i64(t); | ||
38 | +} | 37 | +} |
39 | + | 38 | + |
40 | static inline Int128 int128_rshift(Int128 a, int n) | 39 | static inline TCGv_i64 tcg_temp_new_i64(void) |
41 | { | 40 | { |
42 | return a >> n; | 41 | TCGTemp *t = tcg_temp_new_internal(TCG_TYPE_I64, TEMP_EBB); |
43 | @@ -XXX,XX +XXX,XX @@ static inline Int128 int128_exts64(int64_t a) | 42 | @@ -XXX,XX +XXX,XX @@ static inline TCGv_i64 tcg_temp_local_new_i64(void) |
44 | return int128_make128(a, (a < 0) ? -1 : 0); | 43 | return temp_tcgv_i64(t); |
45 | } | 44 | } |
46 | 45 | ||
47 | +static inline Int128 int128_not(Int128 a) | 46 | +/* Used only by tcg infrastructure: tcg-op.c or plugin-gen.c */ |
47 | +static inline TCGv_i128 tcg_temp_ebb_new_i128(void) | ||
48 | +{ | 48 | +{ |
49 | + return int128_make128(~a.lo, ~a.hi); | 49 | + TCGTemp *t = tcg_temp_new_internal(TCG_TYPE_I128, TEMP_EBB); |
50 | + return temp_tcgv_i128(t); | ||
50 | +} | 51 | +} |
51 | + | 52 | + |
52 | static inline Int128 int128_and(Int128 a, Int128 b) | 53 | static inline TCGv_i128 tcg_temp_new_i128(void) |
53 | { | 54 | { |
54 | return int128_make128(a.lo & b.lo, a.hi & b.hi); | 55 | TCGTemp *t = tcg_temp_new_internal(TCG_TYPE_I128, TEMP_EBB); |
55 | @@ -XXX,XX +XXX,XX @@ static inline Int128 int128_or(Int128 a, Int128 b) | 56 | @@ -XXX,XX +XXX,XX @@ static inline TCGv_ptr tcg_global_mem_new_ptr(TCGv_ptr reg, intptr_t offset, |
56 | return int128_make128(a.lo | b.lo, a.hi | b.hi); | 57 | return temp_tcgv_ptr(t); |
57 | } | 58 | } |
58 | 59 | ||
59 | +static inline Int128 int128_xor(Int128 a, Int128 b) | 60 | +/* Used only by tcg infrastructure: tcg-op.c or plugin-gen.c */ |
61 | +static inline TCGv_ptr tcg_temp_ebb_new_ptr(void) | ||
60 | +{ | 62 | +{ |
61 | + return int128_make128(a.lo ^ b.lo, a.hi ^ b.hi); | 63 | + TCGTemp *t = tcg_temp_new_internal(TCG_TYPE_PTR, TEMP_EBB); |
64 | + return temp_tcgv_ptr(t); | ||
62 | +} | 65 | +} |
63 | + | 66 | + |
64 | static inline Int128 int128_rshift(Int128 a, int n) | 67 | static inline TCGv_ptr tcg_temp_new_ptr(void) |
65 | { | 68 | { |
66 | int64_t h; | 69 | TCGTemp *t = tcg_temp_new_internal(TCG_TYPE_PTR, TEMP_EBB); |
67 | -- | 70 | -- |
68 | 2.25.1 | 71 | 2.34.1 |
69 | 72 | ||
70 | 73 | diff view generated by jsdifflib |
1 | This "garbage" setting pre-dates the addition of the type | 1 | All of these have obvious and quite local scope. |
---|---|---|---|
2 | changing opcodes INDEX_op_ext_i32_i64, INDEX_op_extu_i32_i64, | ||
3 | and INDEX_op_extr{l,h}_i64_i32. | ||
4 | 2 | ||
5 | So now we have a definitive points at which to adjust z_mask | 3 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
6 | to eliminate such bits from the 32-bit operands. | ||
7 | |||
8 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | ||
9 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | ||
10 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
11 | --- | 5 | --- |
12 | tcg/optimize.c | 35 ++++++++++++++++------------------- | 6 | tcg/tcg-op-gvec.c | 186 ++++++++++++++++----------------- |
13 | 1 file changed, 16 insertions(+), 19 deletions(-) | 7 | tcg/tcg-op.c | 258 +++++++++++++++++++++++----------------------- |
8 | tcg/tcg.c | 2 +- | ||
9 | 3 files changed, 223 insertions(+), 223 deletions(-) | ||
14 | 10 | ||
15 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 11 | diff --git a/tcg/tcg-op-gvec.c b/tcg/tcg-op-gvec.c |
16 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/tcg/optimize.c | 13 | --- a/tcg/tcg-op-gvec.c |
18 | +++ b/tcg/optimize.c | 14 | +++ b/tcg/tcg-op-gvec.c |
19 | @@ -XXX,XX +XXX,XX @@ static void init_ts_info(OptContext *ctx, TCGTemp *ts) | 15 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_2_ool(uint32_t dofs, uint32_t aofs, |
20 | ti->is_const = true; | 16 | TCGv_ptr a0, a1; |
21 | ti->val = ts->val; | 17 | TCGv_i32 desc = tcg_constant_i32(simd_desc(oprsz, maxsz, data)); |
22 | ti->z_mask = ts->val; | 18 | |
23 | - if (TCG_TARGET_REG_BITS > 32 && ts->type == TCG_TYPE_I32) { | 19 | - a0 = tcg_temp_new_ptr(); |
24 | - /* High bits of a 32-bit quantity are garbage. */ | 20 | - a1 = tcg_temp_new_ptr(); |
25 | - ti->z_mask |= ~0xffffffffull; | 21 | + a0 = tcg_temp_ebb_new_ptr(); |
26 | - } | 22 | + a1 = tcg_temp_ebb_new_ptr(); |
27 | } else { | 23 | |
28 | ti->is_const = false; | 24 | tcg_gen_addi_ptr(a0, cpu_env, dofs); |
29 | ti->z_mask = -1; | 25 | tcg_gen_addi_ptr(a1, cpu_env, aofs); |
30 | @@ -XXX,XX +XXX,XX @@ static bool tcg_opt_gen_mov(OptContext *ctx, TCGOp *op, TCGArg dst, TCGArg src) | 26 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_2i_ool(uint32_t dofs, uint32_t aofs, TCGv_i64 c, |
31 | TCGTemp *src_ts = arg_temp(src); | 27 | TCGv_ptr a0, a1; |
32 | TempOptInfo *di; | 28 | TCGv_i32 desc = tcg_constant_i32(simd_desc(oprsz, maxsz, data)); |
33 | TempOptInfo *si; | 29 | |
34 | - uint64_t z_mask; | 30 | - a0 = tcg_temp_new_ptr(); |
35 | TCGOpcode new_op; | 31 | - a1 = tcg_temp_new_ptr(); |
36 | 32 | + a0 = tcg_temp_ebb_new_ptr(); | |
37 | if (ts_are_copies(dst_ts, src_ts)) { | 33 | + a1 = tcg_temp_ebb_new_ptr(); |
38 | @@ -XXX,XX +XXX,XX @@ static bool tcg_opt_gen_mov(OptContext *ctx, TCGOp *op, TCGArg dst, TCGArg src) | 34 | |
39 | op->args[0] = dst; | 35 | tcg_gen_addi_ptr(a0, cpu_env, dofs); |
40 | op->args[1] = src; | 36 | tcg_gen_addi_ptr(a1, cpu_env, aofs); |
41 | 37 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_3_ool(uint32_t dofs, uint32_t aofs, uint32_t bofs, | |
42 | - z_mask = si->z_mask; | 38 | TCGv_ptr a0, a1, a2; |
43 | - if (TCG_TARGET_REG_BITS > 32 && new_op == INDEX_op_mov_i32) { | 39 | TCGv_i32 desc = tcg_constant_i32(simd_desc(oprsz, maxsz, data)); |
44 | - /* High bits of the destination are now garbage. */ | 40 | |
45 | - z_mask |= ~0xffffffffull; | 41 | - a0 = tcg_temp_new_ptr(); |
46 | - } | 42 | - a1 = tcg_temp_new_ptr(); |
47 | - di->z_mask = z_mask; | 43 | - a2 = tcg_temp_new_ptr(); |
48 | + di->z_mask = si->z_mask; | 44 | + a0 = tcg_temp_ebb_new_ptr(); |
49 | 45 | + a1 = tcg_temp_ebb_new_ptr(); | |
50 | if (src_ts->type == dst_ts->type) { | 46 | + a2 = tcg_temp_ebb_new_ptr(); |
51 | TempOptInfo *ni = ts_info(si->next_copy); | 47 | |
52 | @@ -XXX,XX +XXX,XX @@ static bool tcg_opt_gen_mov(OptContext *ctx, TCGOp *op, TCGArg dst, TCGArg src) | 48 | tcg_gen_addi_ptr(a0, cpu_env, dofs); |
53 | static bool tcg_opt_gen_movi(OptContext *ctx, TCGOp *op, | 49 | tcg_gen_addi_ptr(a1, cpu_env, aofs); |
54 | TCGArg dst, uint64_t val) | 50 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_4_ool(uint32_t dofs, uint32_t aofs, uint32_t bofs, |
55 | { | 51 | TCGv_ptr a0, a1, a2, a3; |
56 | - /* Convert movi to mov with constant temp. */ | 52 | TCGv_i32 desc = tcg_constant_i32(simd_desc(oprsz, maxsz, data)); |
57 | - TCGTemp *tv = tcg_constant_internal(ctx->type, val); | 53 | |
58 | + TCGTemp *tv; | 54 | - a0 = tcg_temp_new_ptr(); |
59 | 55 | - a1 = tcg_temp_new_ptr(); | |
60 | + if (ctx->type == TCG_TYPE_I32) { | 56 | - a2 = tcg_temp_new_ptr(); |
61 | + val = (int32_t)val; | 57 | - a3 = tcg_temp_new_ptr(); |
62 | + } | 58 | + a0 = tcg_temp_ebb_new_ptr(); |
63 | + | 59 | + a1 = tcg_temp_ebb_new_ptr(); |
64 | + /* Convert movi to mov with constant temp. */ | 60 | + a2 = tcg_temp_ebb_new_ptr(); |
65 | + tv = tcg_constant_internal(ctx->type, val); | 61 | + a3 = tcg_temp_ebb_new_ptr(); |
66 | init_ts_info(ctx, tv); | 62 | |
67 | return tcg_opt_gen_mov(ctx, op, dst, temp_arg(tv)); | 63 | tcg_gen_addi_ptr(a0, cpu_env, dofs); |
68 | } | 64 | tcg_gen_addi_ptr(a1, cpu_env, aofs); |
69 | @@ -XXX,XX +XXX,XX @@ static bool fold_masks(OptContext *ctx, TCGOp *op) | 65 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_5_ool(uint32_t dofs, uint32_t aofs, uint32_t bofs, |
70 | uint64_t z_mask = ctx->z_mask; | 66 | TCGv_ptr a0, a1, a2, a3, a4; |
67 | TCGv_i32 desc = tcg_constant_i32(simd_desc(oprsz, maxsz, data)); | ||
68 | |||
69 | - a0 = tcg_temp_new_ptr(); | ||
70 | - a1 = tcg_temp_new_ptr(); | ||
71 | - a2 = tcg_temp_new_ptr(); | ||
72 | - a3 = tcg_temp_new_ptr(); | ||
73 | - a4 = tcg_temp_new_ptr(); | ||
74 | + a0 = tcg_temp_ebb_new_ptr(); | ||
75 | + a1 = tcg_temp_ebb_new_ptr(); | ||
76 | + a2 = tcg_temp_ebb_new_ptr(); | ||
77 | + a3 = tcg_temp_ebb_new_ptr(); | ||
78 | + a4 = tcg_temp_ebb_new_ptr(); | ||
79 | |||
80 | tcg_gen_addi_ptr(a0, cpu_env, dofs); | ||
81 | tcg_gen_addi_ptr(a1, cpu_env, aofs); | ||
82 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_2_ptr(uint32_t dofs, uint32_t aofs, | ||
83 | TCGv_ptr a0, a1; | ||
84 | TCGv_i32 desc = tcg_constant_i32(simd_desc(oprsz, maxsz, data)); | ||
85 | |||
86 | - a0 = tcg_temp_new_ptr(); | ||
87 | - a1 = tcg_temp_new_ptr(); | ||
88 | + a0 = tcg_temp_ebb_new_ptr(); | ||
89 | + a1 = tcg_temp_ebb_new_ptr(); | ||
90 | |||
91 | tcg_gen_addi_ptr(a0, cpu_env, dofs); | ||
92 | tcg_gen_addi_ptr(a1, cpu_env, aofs); | ||
93 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_3_ptr(uint32_t dofs, uint32_t aofs, uint32_t bofs, | ||
94 | TCGv_ptr a0, a1, a2; | ||
95 | TCGv_i32 desc = tcg_constant_i32(simd_desc(oprsz, maxsz, data)); | ||
96 | |||
97 | - a0 = tcg_temp_new_ptr(); | ||
98 | - a1 = tcg_temp_new_ptr(); | ||
99 | - a2 = tcg_temp_new_ptr(); | ||
100 | + a0 = tcg_temp_ebb_new_ptr(); | ||
101 | + a1 = tcg_temp_ebb_new_ptr(); | ||
102 | + a2 = tcg_temp_ebb_new_ptr(); | ||
103 | |||
104 | tcg_gen_addi_ptr(a0, cpu_env, dofs); | ||
105 | tcg_gen_addi_ptr(a1, cpu_env, aofs); | ||
106 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_4_ptr(uint32_t dofs, uint32_t aofs, uint32_t bofs, | ||
107 | TCGv_ptr a0, a1, a2, a3; | ||
108 | TCGv_i32 desc = tcg_constant_i32(simd_desc(oprsz, maxsz, data)); | ||
109 | |||
110 | - a0 = tcg_temp_new_ptr(); | ||
111 | - a1 = tcg_temp_new_ptr(); | ||
112 | - a2 = tcg_temp_new_ptr(); | ||
113 | - a3 = tcg_temp_new_ptr(); | ||
114 | + a0 = tcg_temp_ebb_new_ptr(); | ||
115 | + a1 = tcg_temp_ebb_new_ptr(); | ||
116 | + a2 = tcg_temp_ebb_new_ptr(); | ||
117 | + a3 = tcg_temp_ebb_new_ptr(); | ||
118 | |||
119 | tcg_gen_addi_ptr(a0, cpu_env, dofs); | ||
120 | tcg_gen_addi_ptr(a1, cpu_env, aofs); | ||
121 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_5_ptr(uint32_t dofs, uint32_t aofs, uint32_t bofs, | ||
122 | TCGv_ptr a0, a1, a2, a3, a4; | ||
123 | TCGv_i32 desc = tcg_constant_i32(simd_desc(oprsz, maxsz, data)); | ||
124 | |||
125 | - a0 = tcg_temp_new_ptr(); | ||
126 | - a1 = tcg_temp_new_ptr(); | ||
127 | - a2 = tcg_temp_new_ptr(); | ||
128 | - a3 = tcg_temp_new_ptr(); | ||
129 | - a4 = tcg_temp_new_ptr(); | ||
130 | + a0 = tcg_temp_ebb_new_ptr(); | ||
131 | + a1 = tcg_temp_ebb_new_ptr(); | ||
132 | + a2 = tcg_temp_ebb_new_ptr(); | ||
133 | + a3 = tcg_temp_ebb_new_ptr(); | ||
134 | + a4 = tcg_temp_ebb_new_ptr(); | ||
135 | |||
136 | tcg_gen_addi_ptr(a0, cpu_env, dofs); | ||
137 | tcg_gen_addi_ptr(a1, cpu_env, aofs); | ||
138 | @@ -XXX,XX +XXX,XX @@ static void do_dup(unsigned vece, uint32_t dofs, uint32_t oprsz, | ||
139 | be simple enough. */ | ||
140 | if (TCG_TARGET_REG_BITS == 64 | ||
141 | && (vece != MO_32 || !check_size_impl(oprsz, 4))) { | ||
142 | - t_64 = tcg_temp_new_i64(); | ||
143 | + t_64 = tcg_temp_ebb_new_i64(); | ||
144 | tcg_gen_extu_i32_i64(t_64, in_32); | ||
145 | tcg_gen_dup_i64(vece, t_64, t_64); | ||
146 | } else { | ||
147 | - t_32 = tcg_temp_new_i32(); | ||
148 | + t_32 = tcg_temp_ebb_new_i32(); | ||
149 | tcg_gen_dup_i32(vece, t_32, in_32); | ||
150 | } | ||
151 | } else if (in_64) { | ||
152 | /* We are given a 64-bit variable input. */ | ||
153 | - t_64 = tcg_temp_new_i64(); | ||
154 | + t_64 = tcg_temp_ebb_new_i64(); | ||
155 | tcg_gen_dup_i64(vece, t_64, in_64); | ||
156 | } else { | ||
157 | /* We are given a constant input. */ | ||
158 | @@ -XXX,XX +XXX,XX @@ static void do_dup(unsigned vece, uint32_t dofs, uint32_t oprsz, | ||
159 | } | ||
160 | |||
161 | /* Otherwise implement out of line. */ | ||
162 | - t_ptr = tcg_temp_new_ptr(); | ||
163 | + t_ptr = tcg_temp_ebb_new_ptr(); | ||
164 | tcg_gen_addi_ptr(t_ptr, cpu_env, dofs); | ||
71 | 165 | ||
72 | /* | 166 | /* |
73 | - * 32-bit ops generate 32-bit results. For the result is zero test | 167 | @@ -XXX,XX +XXX,XX @@ static void do_dup(unsigned vece, uint32_t dofs, uint32_t oprsz, |
74 | - * below, we can ignore high bits, but for further optimizations we | 168 | if (in_32) { |
75 | - * need to record that the high bits contain garbage. | 169 | t_val = in_32; |
76 | + * 32-bit ops generate 32-bit results, which for the purpose of | 170 | } else if (in_64) { |
77 | + * simplifying tcg are sign-extended. Certainly that's how we | 171 | - t_val = tcg_temp_new_i32(); |
78 | + * represent our constants elsewhere. Note that the bits will | 172 | + t_val = tcg_temp_ebb_new_i32(); |
79 | + * be reset properly for a 64-bit value when encountering the | 173 | tcg_gen_extrl_i64_i32(t_val, in_64); |
80 | + * type changing opcodes. | 174 | } else { |
81 | */ | 175 | t_val = tcg_constant_i32(in_c); |
82 | if (ctx->type == TCG_TYPE_I32) { | 176 | @@ -XXX,XX +XXX,XX @@ static void do_dup(unsigned vece, uint32_t dofs, uint32_t oprsz, |
83 | - ctx->z_mask |= MAKE_64BIT_MASK(32, 32); | 177 | if (in_32) { |
84 | - a_mask &= MAKE_64BIT_MASK(0, 32); | 178 | fns[vece](t_ptr, t_desc, in_32); |
85 | - z_mask &= MAKE_64BIT_MASK(0, 32); | 179 | } else if (in_64) { |
86 | + a_mask = (int32_t)a_mask; | 180 | - t_32 = tcg_temp_new_i32(); |
87 | + z_mask = (int32_t)z_mask; | 181 | + t_32 = tcg_temp_ebb_new_i32(); |
88 | + ctx->z_mask = z_mask; | 182 | tcg_gen_extrl_i64_i32(t_32, in_64); |
183 | fns[vece](t_ptr, t_desc, t_32); | ||
184 | tcg_temp_free_i32(t_32); | ||
185 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_dup_mem(unsigned vece, uint32_t dofs, uint32_t aofs, | ||
186 | do_dup_store(type, dofs, oprsz, maxsz, t_vec); | ||
187 | tcg_temp_free_vec(t_vec); | ||
188 | } else if (vece <= MO_32) { | ||
189 | - TCGv_i32 in = tcg_temp_new_i32(); | ||
190 | + TCGv_i32 in = tcg_temp_ebb_new_i32(); | ||
191 | switch (vece) { | ||
192 | case MO_8: | ||
193 | tcg_gen_ld8u_i32(in, cpu_env, aofs); | ||
194 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_dup_mem(unsigned vece, uint32_t dofs, uint32_t aofs, | ||
195 | do_dup(vece, dofs, oprsz, maxsz, in, NULL, 0); | ||
196 | tcg_temp_free_i32(in); | ||
197 | } else { | ||
198 | - TCGv_i64 in = tcg_temp_new_i64(); | ||
199 | + TCGv_i64 in = tcg_temp_ebb_new_i64(); | ||
200 | tcg_gen_ld_i64(in, cpu_env, aofs); | ||
201 | do_dup(vece, dofs, oprsz, maxsz, NULL, in, 0); | ||
202 | tcg_temp_free_i64(in); | ||
203 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_dup_mem(unsigned vece, uint32_t dofs, uint32_t aofs, | ||
204 | } | ||
205 | tcg_temp_free_vec(in); | ||
206 | } else { | ||
207 | - TCGv_i64 in0 = tcg_temp_new_i64(); | ||
208 | - TCGv_i64 in1 = tcg_temp_new_i64(); | ||
209 | + TCGv_i64 in0 = tcg_temp_ebb_new_i64(); | ||
210 | + TCGv_i64 in1 = tcg_temp_ebb_new_i64(); | ||
211 | |||
212 | tcg_gen_ld_i64(in0, cpu_env, aofs); | ||
213 | tcg_gen_ld_i64(in1, cpu_env, aofs + 8); | ||
214 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_dup_mem(unsigned vece, uint32_t dofs, uint32_t aofs, | ||
215 | int j; | ||
216 | |||
217 | for (j = 0; j < 4; ++j) { | ||
218 | - in[j] = tcg_temp_new_i64(); | ||
219 | + in[j] = tcg_temp_ebb_new_i64(); | ||
220 | tcg_gen_ld_i64(in[j], cpu_env, aofs + j * 8); | ||
221 | } | ||
222 | for (i = (aofs == dofs) * 32; i < oprsz; i += 32) { | ||
223 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_not(unsigned vece, uint32_t dofs, uint32_t aofs, | ||
224 | the 64-bit operation. */ | ||
225 | static void gen_addv_mask(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b, TCGv_i64 m) | ||
226 | { | ||
227 | - TCGv_i64 t1 = tcg_temp_new_i64(); | ||
228 | - TCGv_i64 t2 = tcg_temp_new_i64(); | ||
229 | - TCGv_i64 t3 = tcg_temp_new_i64(); | ||
230 | + TCGv_i64 t1 = tcg_temp_ebb_new_i64(); | ||
231 | + TCGv_i64 t2 = tcg_temp_ebb_new_i64(); | ||
232 | + TCGv_i64 t3 = tcg_temp_ebb_new_i64(); | ||
233 | |||
234 | tcg_gen_andc_i64(t1, a, m); | ||
235 | tcg_gen_andc_i64(t2, b, m); | ||
236 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_vec_add8_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b) | ||
237 | void tcg_gen_vec_add8_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b) | ||
238 | { | ||
239 | TCGv_i32 m = tcg_constant_i32((int32_t)dup_const(MO_8, 0x80)); | ||
240 | - TCGv_i32 t1 = tcg_temp_new_i32(); | ||
241 | - TCGv_i32 t2 = tcg_temp_new_i32(); | ||
242 | - TCGv_i32 t3 = tcg_temp_new_i32(); | ||
243 | + TCGv_i32 t1 = tcg_temp_ebb_new_i32(); | ||
244 | + TCGv_i32 t2 = tcg_temp_ebb_new_i32(); | ||
245 | + TCGv_i32 t3 = tcg_temp_ebb_new_i32(); | ||
246 | |||
247 | tcg_gen_andc_i32(t1, a, m); | ||
248 | tcg_gen_andc_i32(t2, b, m); | ||
249 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_vec_add16_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b) | ||
250 | |||
251 | void tcg_gen_vec_add16_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b) | ||
252 | { | ||
253 | - TCGv_i32 t1 = tcg_temp_new_i32(); | ||
254 | - TCGv_i32 t2 = tcg_temp_new_i32(); | ||
255 | + TCGv_i32 t1 = tcg_temp_ebb_new_i32(); | ||
256 | + TCGv_i32 t2 = tcg_temp_ebb_new_i32(); | ||
257 | |||
258 | tcg_gen_andi_i32(t1, a, ~0xffff); | ||
259 | tcg_gen_add_i32(t2, a, b); | ||
260 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_vec_add16_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b) | ||
261 | |||
262 | void tcg_gen_vec_add32_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b) | ||
263 | { | ||
264 | - TCGv_i64 t1 = tcg_temp_new_i64(); | ||
265 | - TCGv_i64 t2 = tcg_temp_new_i64(); | ||
266 | + TCGv_i64 t1 = tcg_temp_ebb_new_i64(); | ||
267 | + TCGv_i64 t2 = tcg_temp_ebb_new_i64(); | ||
268 | |||
269 | tcg_gen_andi_i64(t1, a, ~0xffffffffull); | ||
270 | tcg_gen_add_i64(t2, a, b); | ||
271 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_subs(unsigned vece, uint32_t dofs, uint32_t aofs, | ||
272 | Compare gen_addv_mask above. */ | ||
273 | static void gen_subv_mask(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b, TCGv_i64 m) | ||
274 | { | ||
275 | - TCGv_i64 t1 = tcg_temp_new_i64(); | ||
276 | - TCGv_i64 t2 = tcg_temp_new_i64(); | ||
277 | - TCGv_i64 t3 = tcg_temp_new_i64(); | ||
278 | + TCGv_i64 t1 = tcg_temp_ebb_new_i64(); | ||
279 | + TCGv_i64 t2 = tcg_temp_ebb_new_i64(); | ||
280 | + TCGv_i64 t3 = tcg_temp_ebb_new_i64(); | ||
281 | |||
282 | tcg_gen_or_i64(t1, a, m); | ||
283 | tcg_gen_andc_i64(t2, b, m); | ||
284 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_vec_sub8_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b) | ||
285 | void tcg_gen_vec_sub8_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b) | ||
286 | { | ||
287 | TCGv_i32 m = tcg_constant_i32((int32_t)dup_const(MO_8, 0x80)); | ||
288 | - TCGv_i32 t1 = tcg_temp_new_i32(); | ||
289 | - TCGv_i32 t2 = tcg_temp_new_i32(); | ||
290 | - TCGv_i32 t3 = tcg_temp_new_i32(); | ||
291 | + TCGv_i32 t1 = tcg_temp_ebb_new_i32(); | ||
292 | + TCGv_i32 t2 = tcg_temp_ebb_new_i32(); | ||
293 | + TCGv_i32 t3 = tcg_temp_ebb_new_i32(); | ||
294 | |||
295 | tcg_gen_or_i32(t1, a, m); | ||
296 | tcg_gen_andc_i32(t2, b, m); | ||
297 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_vec_sub16_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b) | ||
298 | |||
299 | void tcg_gen_vec_sub16_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b) | ||
300 | { | ||
301 | - TCGv_i32 t1 = tcg_temp_new_i32(); | ||
302 | - TCGv_i32 t2 = tcg_temp_new_i32(); | ||
303 | + TCGv_i32 t1 = tcg_temp_ebb_new_i32(); | ||
304 | + TCGv_i32 t2 = tcg_temp_ebb_new_i32(); | ||
305 | |||
306 | tcg_gen_andi_i32(t1, b, ~0xffff); | ||
307 | tcg_gen_sub_i32(t2, a, b); | ||
308 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_vec_sub16_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b) | ||
309 | |||
310 | void tcg_gen_vec_sub32_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b) | ||
311 | { | ||
312 | - TCGv_i64 t1 = tcg_temp_new_i64(); | ||
313 | - TCGv_i64 t2 = tcg_temp_new_i64(); | ||
314 | + TCGv_i64 t1 = tcg_temp_ebb_new_i64(); | ||
315 | + TCGv_i64 t2 = tcg_temp_ebb_new_i64(); | ||
316 | |||
317 | tcg_gen_andi_i64(t1, b, ~0xffffffffull); | ||
318 | tcg_gen_sub_i64(t2, a, b); | ||
319 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_umax(unsigned vece, uint32_t dofs, uint32_t aofs, | ||
320 | Compare gen_subv_mask above. */ | ||
321 | static void gen_negv_mask(TCGv_i64 d, TCGv_i64 b, TCGv_i64 m) | ||
322 | { | ||
323 | - TCGv_i64 t2 = tcg_temp_new_i64(); | ||
324 | - TCGv_i64 t3 = tcg_temp_new_i64(); | ||
325 | + TCGv_i64 t2 = tcg_temp_ebb_new_i64(); | ||
326 | + TCGv_i64 t3 = tcg_temp_ebb_new_i64(); | ||
327 | |||
328 | tcg_gen_andc_i64(t3, m, b); | ||
329 | tcg_gen_andc_i64(t2, b, m); | ||
330 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_vec_neg16_i64(TCGv_i64 d, TCGv_i64 b) | ||
331 | |||
332 | void tcg_gen_vec_neg32_i64(TCGv_i64 d, TCGv_i64 b) | ||
333 | { | ||
334 | - TCGv_i64 t1 = tcg_temp_new_i64(); | ||
335 | - TCGv_i64 t2 = tcg_temp_new_i64(); | ||
336 | + TCGv_i64 t1 = tcg_temp_ebb_new_i64(); | ||
337 | + TCGv_i64 t2 = tcg_temp_ebb_new_i64(); | ||
338 | |||
339 | tcg_gen_andi_i64(t1, b, ~0xffffffffull); | ||
340 | tcg_gen_neg_i64(t2, b); | ||
341 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_neg(unsigned vece, uint32_t dofs, uint32_t aofs, | ||
342 | |||
343 | static void gen_absv_mask(TCGv_i64 d, TCGv_i64 b, unsigned vece) | ||
344 | { | ||
345 | - TCGv_i64 t = tcg_temp_new_i64(); | ||
346 | + TCGv_i64 t = tcg_temp_ebb_new_i64(); | ||
347 | int nbit = 8 << vece; | ||
348 | |||
349 | /* Create -1 for each negative element. */ | ||
350 | @@ -XXX,XX +XXX,XX @@ static const GVecGen2s gop_ands = { | ||
351 | void tcg_gen_gvec_ands(unsigned vece, uint32_t dofs, uint32_t aofs, | ||
352 | TCGv_i64 c, uint32_t oprsz, uint32_t maxsz) | ||
353 | { | ||
354 | - TCGv_i64 tmp = tcg_temp_new_i64(); | ||
355 | + TCGv_i64 tmp = tcg_temp_ebb_new_i64(); | ||
356 | tcg_gen_dup_i64(vece, tmp, c); | ||
357 | tcg_gen_gvec_2s(dofs, aofs, oprsz, maxsz, tmp, &gop_ands); | ||
358 | tcg_temp_free_i64(tmp); | ||
359 | @@ -XXX,XX +XXX,XX @@ static const GVecGen2s gop_xors = { | ||
360 | void tcg_gen_gvec_xors(unsigned vece, uint32_t dofs, uint32_t aofs, | ||
361 | TCGv_i64 c, uint32_t oprsz, uint32_t maxsz) | ||
362 | { | ||
363 | - TCGv_i64 tmp = tcg_temp_new_i64(); | ||
364 | + TCGv_i64 tmp = tcg_temp_ebb_new_i64(); | ||
365 | tcg_gen_dup_i64(vece, tmp, c); | ||
366 | tcg_gen_gvec_2s(dofs, aofs, oprsz, maxsz, tmp, &gop_xors); | ||
367 | tcg_temp_free_i64(tmp); | ||
368 | @@ -XXX,XX +XXX,XX @@ static const GVecGen2s gop_ors = { | ||
369 | void tcg_gen_gvec_ors(unsigned vece, uint32_t dofs, uint32_t aofs, | ||
370 | TCGv_i64 c, uint32_t oprsz, uint32_t maxsz) | ||
371 | { | ||
372 | - TCGv_i64 tmp = tcg_temp_new_i64(); | ||
373 | + TCGv_i64 tmp = tcg_temp_ebb_new_i64(); | ||
374 | tcg_gen_dup_i64(vece, tmp, c); | ||
375 | tcg_gen_gvec_2s(dofs, aofs, oprsz, maxsz, tmp, &gop_ors); | ||
376 | tcg_temp_free_i64(tmp); | ||
377 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_vec_sar8i_i64(TCGv_i64 d, TCGv_i64 a, int64_t c) | ||
378 | { | ||
379 | uint64_t s_mask = dup_const(MO_8, 0x80 >> c); | ||
380 | uint64_t c_mask = dup_const(MO_8, 0xff >> c); | ||
381 | - TCGv_i64 s = tcg_temp_new_i64(); | ||
382 | + TCGv_i64 s = tcg_temp_ebb_new_i64(); | ||
383 | |||
384 | tcg_gen_shri_i64(d, a, c); | ||
385 | tcg_gen_andi_i64(s, d, s_mask); /* isolate (shifted) sign bit */ | ||
386 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_vec_sar16i_i64(TCGv_i64 d, TCGv_i64 a, int64_t c) | ||
387 | { | ||
388 | uint64_t s_mask = dup_const(MO_16, 0x8000 >> c); | ||
389 | uint64_t c_mask = dup_const(MO_16, 0xffff >> c); | ||
390 | - TCGv_i64 s = tcg_temp_new_i64(); | ||
391 | + TCGv_i64 s = tcg_temp_ebb_new_i64(); | ||
392 | |||
393 | tcg_gen_shri_i64(d, a, c); | ||
394 | tcg_gen_andi_i64(s, d, s_mask); /* isolate (shifted) sign bit */ | ||
395 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_vec_sar8i_i32(TCGv_i32 d, TCGv_i32 a, int32_t c) | ||
396 | { | ||
397 | uint32_t s_mask = dup_const(MO_8, 0x80 >> c); | ||
398 | uint32_t c_mask = dup_const(MO_8, 0xff >> c); | ||
399 | - TCGv_i32 s = tcg_temp_new_i32(); | ||
400 | + TCGv_i32 s = tcg_temp_ebb_new_i32(); | ||
401 | |||
402 | tcg_gen_shri_i32(d, a, c); | ||
403 | tcg_gen_andi_i32(s, d, s_mask); /* isolate (shifted) sign bit */ | ||
404 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_vec_sar16i_i32(TCGv_i32 d, TCGv_i32 a, int32_t c) | ||
405 | { | ||
406 | uint32_t s_mask = dup_const(MO_16, 0x8000 >> c); | ||
407 | uint32_t c_mask = dup_const(MO_16, 0xffff >> c); | ||
408 | - TCGv_i32 s = tcg_temp_new_i32(); | ||
409 | + TCGv_i32 s = tcg_temp_ebb_new_i32(); | ||
410 | |||
411 | tcg_gen_shri_i32(d, a, c); | ||
412 | tcg_gen_andi_i32(s, d, s_mask); /* isolate (shifted) sign bit */ | ||
413 | @@ -XXX,XX +XXX,XX @@ do_gvec_shifts(unsigned vece, uint32_t dofs, uint32_t aofs, TCGv_i32 shift, | ||
414 | TCGv_vec v_shift = tcg_temp_new_vec(type); | ||
415 | |||
416 | if (vece == MO_64) { | ||
417 | - TCGv_i64 sh64 = tcg_temp_new_i64(); | ||
418 | + TCGv_i64 sh64 = tcg_temp_ebb_new_i64(); | ||
419 | tcg_gen_extu_i32_i64(sh64, shift); | ||
420 | tcg_gen_dup_i64_vec(MO_64, v_shift, sh64); | ||
421 | tcg_temp_free_i64(sh64); | ||
422 | @@ -XXX,XX +XXX,XX @@ do_gvec_shifts(unsigned vece, uint32_t dofs, uint32_t aofs, TCGv_i32 shift, | ||
423 | if (vece == MO_32 && check_size_impl(oprsz, 4)) { | ||
424 | expand_2s_i32(dofs, aofs, oprsz, shift, false, g->fni4); | ||
425 | } else if (vece == MO_64 && check_size_impl(oprsz, 8)) { | ||
426 | - TCGv_i64 sh64 = tcg_temp_new_i64(); | ||
427 | + TCGv_i64 sh64 = tcg_temp_ebb_new_i64(); | ||
428 | tcg_gen_extu_i32_i64(sh64, shift); | ||
429 | expand_2s_i64(dofs, aofs, oprsz, sh64, false, g->fni8); | ||
430 | tcg_temp_free_i64(sh64); | ||
431 | } else { | ||
432 | - TCGv_ptr a0 = tcg_temp_new_ptr(); | ||
433 | - TCGv_ptr a1 = tcg_temp_new_ptr(); | ||
434 | - TCGv_i32 desc = tcg_temp_new_i32(); | ||
435 | + TCGv_ptr a0 = tcg_temp_ebb_new_ptr(); | ||
436 | + TCGv_ptr a1 = tcg_temp_ebb_new_ptr(); | ||
437 | + TCGv_i32 desc = tcg_temp_ebb_new_i32(); | ||
438 | |||
439 | tcg_gen_shli_i32(desc, shift, SIMD_DATA_SHIFT); | ||
440 | tcg_gen_ori_i32(desc, desc, simd_desc(oprsz, maxsz, 0)); | ||
441 | @@ -XXX,XX +XXX,XX @@ static void tcg_gen_shlv_mod_vec(unsigned vece, TCGv_vec d, | ||
442 | |||
443 | static void tcg_gen_shl_mod_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b) | ||
444 | { | ||
445 | - TCGv_i32 t = tcg_temp_new_i32(); | ||
446 | + TCGv_i32 t = tcg_temp_ebb_new_i32(); | ||
447 | |||
448 | tcg_gen_andi_i32(t, b, 31); | ||
449 | tcg_gen_shl_i32(d, a, t); | ||
450 | @@ -XXX,XX +XXX,XX @@ static void tcg_gen_shl_mod_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b) | ||
451 | |||
452 | static void tcg_gen_shl_mod_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b) | ||
453 | { | ||
454 | - TCGv_i64 t = tcg_temp_new_i64(); | ||
455 | + TCGv_i64 t = tcg_temp_ebb_new_i64(); | ||
456 | |||
457 | tcg_gen_andi_i64(t, b, 63); | ||
458 | tcg_gen_shl_i64(d, a, t); | ||
459 | @@ -XXX,XX +XXX,XX @@ static void tcg_gen_shrv_mod_vec(unsigned vece, TCGv_vec d, | ||
460 | |||
461 | static void tcg_gen_shr_mod_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b) | ||
462 | { | ||
463 | - TCGv_i32 t = tcg_temp_new_i32(); | ||
464 | + TCGv_i32 t = tcg_temp_ebb_new_i32(); | ||
465 | |||
466 | tcg_gen_andi_i32(t, b, 31); | ||
467 | tcg_gen_shr_i32(d, a, t); | ||
468 | @@ -XXX,XX +XXX,XX @@ static void tcg_gen_shr_mod_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b) | ||
469 | |||
470 | static void tcg_gen_shr_mod_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b) | ||
471 | { | ||
472 | - TCGv_i64 t = tcg_temp_new_i64(); | ||
473 | + TCGv_i64 t = tcg_temp_ebb_new_i64(); | ||
474 | |||
475 | tcg_gen_andi_i64(t, b, 63); | ||
476 | tcg_gen_shr_i64(d, a, t); | ||
477 | @@ -XXX,XX +XXX,XX @@ static void tcg_gen_sarv_mod_vec(unsigned vece, TCGv_vec d, | ||
478 | |||
479 | static void tcg_gen_sar_mod_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b) | ||
480 | { | ||
481 | - TCGv_i32 t = tcg_temp_new_i32(); | ||
482 | + TCGv_i32 t = tcg_temp_ebb_new_i32(); | ||
483 | |||
484 | tcg_gen_andi_i32(t, b, 31); | ||
485 | tcg_gen_sar_i32(d, a, t); | ||
486 | @@ -XXX,XX +XXX,XX @@ static void tcg_gen_sar_mod_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b) | ||
487 | |||
488 | static void tcg_gen_sar_mod_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b) | ||
489 | { | ||
490 | - TCGv_i64 t = tcg_temp_new_i64(); | ||
491 | + TCGv_i64 t = tcg_temp_ebb_new_i64(); | ||
492 | |||
493 | tcg_gen_andi_i64(t, b, 63); | ||
494 | tcg_gen_sar_i64(d, a, t); | ||
495 | @@ -XXX,XX +XXX,XX @@ static void tcg_gen_rotlv_mod_vec(unsigned vece, TCGv_vec d, | ||
496 | |||
497 | static void tcg_gen_rotl_mod_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b) | ||
498 | { | ||
499 | - TCGv_i32 t = tcg_temp_new_i32(); | ||
500 | + TCGv_i32 t = tcg_temp_ebb_new_i32(); | ||
501 | |||
502 | tcg_gen_andi_i32(t, b, 31); | ||
503 | tcg_gen_rotl_i32(d, a, t); | ||
504 | @@ -XXX,XX +XXX,XX @@ static void tcg_gen_rotl_mod_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b) | ||
505 | |||
506 | static void tcg_gen_rotl_mod_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b) | ||
507 | { | ||
508 | - TCGv_i64 t = tcg_temp_new_i64(); | ||
509 | + TCGv_i64 t = tcg_temp_ebb_new_i64(); | ||
510 | |||
511 | tcg_gen_andi_i64(t, b, 63); | ||
512 | tcg_gen_rotl_i64(d, a, t); | ||
513 | @@ -XXX,XX +XXX,XX @@ static void tcg_gen_rotrv_mod_vec(unsigned vece, TCGv_vec d, | ||
514 | |||
515 | static void tcg_gen_rotr_mod_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b) | ||
516 | { | ||
517 | - TCGv_i32 t = tcg_temp_new_i32(); | ||
518 | + TCGv_i32 t = tcg_temp_ebb_new_i32(); | ||
519 | |||
520 | tcg_gen_andi_i32(t, b, 31); | ||
521 | tcg_gen_rotr_i32(d, a, t); | ||
522 | @@ -XXX,XX +XXX,XX @@ static void tcg_gen_rotr_mod_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b) | ||
523 | |||
524 | static void tcg_gen_rotr_mod_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b) | ||
525 | { | ||
526 | - TCGv_i64 t = tcg_temp_new_i64(); | ||
527 | + TCGv_i64 t = tcg_temp_ebb_new_i64(); | ||
528 | |||
529 | tcg_gen_andi_i64(t, b, 63); | ||
530 | tcg_gen_rotr_i64(d, a, t); | ||
531 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_rotrv(unsigned vece, uint32_t dofs, uint32_t aofs, | ||
532 | static void expand_cmp_i32(uint32_t dofs, uint32_t aofs, uint32_t bofs, | ||
533 | uint32_t oprsz, TCGCond cond) | ||
534 | { | ||
535 | - TCGv_i32 t0 = tcg_temp_new_i32(); | ||
536 | - TCGv_i32 t1 = tcg_temp_new_i32(); | ||
537 | + TCGv_i32 t0 = tcg_temp_ebb_new_i32(); | ||
538 | + TCGv_i32 t1 = tcg_temp_ebb_new_i32(); | ||
539 | uint32_t i; | ||
540 | |||
541 | for (i = 0; i < oprsz; i += 4) { | ||
542 | @@ -XXX,XX +XXX,XX @@ static void expand_cmp_i32(uint32_t dofs, uint32_t aofs, uint32_t bofs, | ||
543 | static void expand_cmp_i64(uint32_t dofs, uint32_t aofs, uint32_t bofs, | ||
544 | uint32_t oprsz, TCGCond cond) | ||
545 | { | ||
546 | - TCGv_i64 t0 = tcg_temp_new_i64(); | ||
547 | - TCGv_i64 t1 = tcg_temp_new_i64(); | ||
548 | + TCGv_i64 t0 = tcg_temp_ebb_new_i64(); | ||
549 | + TCGv_i64 t1 = tcg_temp_ebb_new_i64(); | ||
550 | uint32_t i; | ||
551 | |||
552 | for (i = 0; i < oprsz; i += 8) { | ||
553 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_cmp(TCGCond cond, unsigned vece, uint32_t dofs, | ||
554 | |||
555 | static void tcg_gen_bitsel_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b, TCGv_i64 c) | ||
556 | { | ||
557 | - TCGv_i64 t = tcg_temp_new_i64(); | ||
558 | + TCGv_i64 t = tcg_temp_ebb_new_i64(); | ||
559 | |||
560 | tcg_gen_and_i64(t, b, a); | ||
561 | tcg_gen_andc_i64(d, c, a); | ||
562 | diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c | ||
563 | index XXXXXXX..XXXXXXX 100644 | ||
564 | --- a/tcg/tcg-op.c | ||
565 | +++ b/tcg/tcg-op.c | ||
566 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_div_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) | ||
567 | if (TCG_TARGET_HAS_div_i32) { | ||
568 | tcg_gen_op3_i32(INDEX_op_div_i32, ret, arg1, arg2); | ||
569 | } else if (TCG_TARGET_HAS_div2_i32) { | ||
570 | - TCGv_i32 t0 = tcg_temp_new_i32(); | ||
571 | + TCGv_i32 t0 = tcg_temp_ebb_new_i32(); | ||
572 | tcg_gen_sari_i32(t0, arg1, 31); | ||
573 | tcg_gen_op5_i32(INDEX_op_div2_i32, ret, t0, arg1, t0, arg2); | ||
574 | tcg_temp_free_i32(t0); | ||
575 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_rem_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) | ||
576 | if (TCG_TARGET_HAS_rem_i32) { | ||
577 | tcg_gen_op3_i32(INDEX_op_rem_i32, ret, arg1, arg2); | ||
578 | } else if (TCG_TARGET_HAS_div_i32) { | ||
579 | - TCGv_i32 t0 = tcg_temp_new_i32(); | ||
580 | + TCGv_i32 t0 = tcg_temp_ebb_new_i32(); | ||
581 | tcg_gen_op3_i32(INDEX_op_div_i32, t0, arg1, arg2); | ||
582 | tcg_gen_mul_i32(t0, t0, arg2); | ||
583 | tcg_gen_sub_i32(ret, arg1, t0); | ||
584 | tcg_temp_free_i32(t0); | ||
585 | } else if (TCG_TARGET_HAS_div2_i32) { | ||
586 | - TCGv_i32 t0 = tcg_temp_new_i32(); | ||
587 | + TCGv_i32 t0 = tcg_temp_ebb_new_i32(); | ||
588 | tcg_gen_sari_i32(t0, arg1, 31); | ||
589 | tcg_gen_op5_i32(INDEX_op_div2_i32, t0, ret, arg1, t0, arg2); | ||
590 | tcg_temp_free_i32(t0); | ||
591 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_divu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) | ||
592 | if (TCG_TARGET_HAS_div_i32) { | ||
593 | tcg_gen_op3_i32(INDEX_op_divu_i32, ret, arg1, arg2); | ||
594 | } else if (TCG_TARGET_HAS_div2_i32) { | ||
595 | - TCGv_i32 t0 = tcg_temp_new_i32(); | ||
596 | + TCGv_i32 t0 = tcg_temp_ebb_new_i32(); | ||
597 | tcg_gen_movi_i32(t0, 0); | ||
598 | tcg_gen_op5_i32(INDEX_op_divu2_i32, ret, t0, arg1, t0, arg2); | ||
599 | tcg_temp_free_i32(t0); | ||
600 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_remu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) | ||
601 | if (TCG_TARGET_HAS_rem_i32) { | ||
602 | tcg_gen_op3_i32(INDEX_op_remu_i32, ret, arg1, arg2); | ||
603 | } else if (TCG_TARGET_HAS_div_i32) { | ||
604 | - TCGv_i32 t0 = tcg_temp_new_i32(); | ||
605 | + TCGv_i32 t0 = tcg_temp_ebb_new_i32(); | ||
606 | tcg_gen_op3_i32(INDEX_op_divu_i32, t0, arg1, arg2); | ||
607 | tcg_gen_mul_i32(t0, t0, arg2); | ||
608 | tcg_gen_sub_i32(ret, arg1, t0); | ||
609 | tcg_temp_free_i32(t0); | ||
610 | } else if (TCG_TARGET_HAS_div2_i32) { | ||
611 | - TCGv_i32 t0 = tcg_temp_new_i32(); | ||
612 | + TCGv_i32 t0 = tcg_temp_ebb_new_i32(); | ||
613 | tcg_gen_movi_i32(t0, 0); | ||
614 | tcg_gen_op5_i32(INDEX_op_divu2_i32, t0, ret, arg1, t0, arg2); | ||
615 | tcg_temp_free_i32(t0); | ||
616 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_andc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) | ||
617 | if (TCG_TARGET_HAS_andc_i32) { | ||
618 | tcg_gen_op3_i32(INDEX_op_andc_i32, ret, arg1, arg2); | ||
619 | } else { | ||
620 | - TCGv_i32 t0 = tcg_temp_new_i32(); | ||
621 | + TCGv_i32 t0 = tcg_temp_ebb_new_i32(); | ||
622 | tcg_gen_not_i32(t0, arg2); | ||
623 | tcg_gen_and_i32(ret, arg1, t0); | ||
624 | tcg_temp_free_i32(t0); | ||
625 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_orc_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) | ||
626 | if (TCG_TARGET_HAS_orc_i32) { | ||
627 | tcg_gen_op3_i32(INDEX_op_orc_i32, ret, arg1, arg2); | ||
628 | } else { | ||
629 | - TCGv_i32 t0 = tcg_temp_new_i32(); | ||
630 | + TCGv_i32 t0 = tcg_temp_ebb_new_i32(); | ||
631 | tcg_gen_not_i32(t0, arg2); | ||
632 | tcg_gen_or_i32(ret, arg1, t0); | ||
633 | tcg_temp_free_i32(t0); | ||
634 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_clz_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) | ||
635 | if (TCG_TARGET_HAS_clz_i32) { | ||
636 | tcg_gen_op3_i32(INDEX_op_clz_i32, ret, arg1, arg2); | ||
637 | } else if (TCG_TARGET_HAS_clz_i64) { | ||
638 | - TCGv_i64 t1 = tcg_temp_new_i64(); | ||
639 | - TCGv_i64 t2 = tcg_temp_new_i64(); | ||
640 | + TCGv_i64 t1 = tcg_temp_ebb_new_i64(); | ||
641 | + TCGv_i64 t2 = tcg_temp_ebb_new_i64(); | ||
642 | tcg_gen_extu_i32_i64(t1, arg1); | ||
643 | tcg_gen_extu_i32_i64(t2, arg2); | ||
644 | tcg_gen_addi_i64(t2, t2, 32); | ||
645 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_ctz_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) | ||
646 | if (TCG_TARGET_HAS_ctz_i32) { | ||
647 | tcg_gen_op3_i32(INDEX_op_ctz_i32, ret, arg1, arg2); | ||
648 | } else if (TCG_TARGET_HAS_ctz_i64) { | ||
649 | - TCGv_i64 t1 = tcg_temp_new_i64(); | ||
650 | - TCGv_i64 t2 = tcg_temp_new_i64(); | ||
651 | + TCGv_i64 t1 = tcg_temp_ebb_new_i64(); | ||
652 | + TCGv_i64 t2 = tcg_temp_ebb_new_i64(); | ||
653 | tcg_gen_extu_i32_i64(t1, arg1); | ||
654 | tcg_gen_extu_i32_i64(t2, arg2); | ||
655 | tcg_gen_ctz_i64(t1, t1, t2); | ||
656 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_ctz_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) | ||
657 | || TCG_TARGET_HAS_ctpop_i64 | ||
658 | || TCG_TARGET_HAS_clz_i32 | ||
659 | || TCG_TARGET_HAS_clz_i64) { | ||
660 | - TCGv_i32 z, t = tcg_temp_new_i32(); | ||
661 | + TCGv_i32 z, t = tcg_temp_ebb_new_i32(); | ||
662 | |||
663 | if (TCG_TARGET_HAS_ctpop_i32 || TCG_TARGET_HAS_ctpop_i64) { | ||
664 | tcg_gen_subi_i32(t, arg1, 1); | ||
665 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_ctzi_i32(TCGv_i32 ret, TCGv_i32 arg1, uint32_t arg2) | ||
666 | { | ||
667 | if (!TCG_TARGET_HAS_ctz_i32 && TCG_TARGET_HAS_ctpop_i32 && arg2 == 32) { | ||
668 | /* This equivalence has the advantage of not requiring a fixup. */ | ||
669 | - TCGv_i32 t = tcg_temp_new_i32(); | ||
670 | + TCGv_i32 t = tcg_temp_ebb_new_i32(); | ||
671 | tcg_gen_subi_i32(t, arg1, 1); | ||
672 | tcg_gen_andc_i32(t, t, arg1); | ||
673 | tcg_gen_ctpop_i32(ret, t); | ||
674 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_ctzi_i32(TCGv_i32 ret, TCGv_i32 arg1, uint32_t arg2) | ||
675 | void tcg_gen_clrsb_i32(TCGv_i32 ret, TCGv_i32 arg) | ||
676 | { | ||
677 | if (TCG_TARGET_HAS_clz_i32) { | ||
678 | - TCGv_i32 t = tcg_temp_new_i32(); | ||
679 | + TCGv_i32 t = tcg_temp_ebb_new_i32(); | ||
680 | tcg_gen_sari_i32(t, arg, 31); | ||
681 | tcg_gen_xor_i32(t, t, arg); | ||
682 | tcg_gen_clzi_i32(t, t, 32); | ||
683 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_ctpop_i32(TCGv_i32 ret, TCGv_i32 arg1) | ||
684 | if (TCG_TARGET_HAS_ctpop_i32) { | ||
685 | tcg_gen_op2_i32(INDEX_op_ctpop_i32, ret, arg1); | ||
686 | } else if (TCG_TARGET_HAS_ctpop_i64) { | ||
687 | - TCGv_i64 t = tcg_temp_new_i64(); | ||
688 | + TCGv_i64 t = tcg_temp_ebb_new_i64(); | ||
689 | tcg_gen_extu_i32_i64(t, arg1); | ||
690 | tcg_gen_ctpop_i64(t, t); | ||
691 | tcg_gen_extrl_i64_i32(ret, t); | ||
692 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_rotl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) | ||
693 | } else { | ||
694 | TCGv_i32 t0, t1; | ||
695 | |||
696 | - t0 = tcg_temp_new_i32(); | ||
697 | - t1 = tcg_temp_new_i32(); | ||
698 | + t0 = tcg_temp_ebb_new_i32(); | ||
699 | + t1 = tcg_temp_ebb_new_i32(); | ||
700 | tcg_gen_shl_i32(t0, arg1, arg2); | ||
701 | tcg_gen_subfi_i32(t1, 32, arg2); | ||
702 | tcg_gen_shr_i32(t1, arg1, t1); | ||
703 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_rotli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2) | ||
704 | tcg_gen_rotl_i32(ret, arg1, tcg_constant_i32(arg2)); | ||
705 | } else { | ||
706 | TCGv_i32 t0, t1; | ||
707 | - t0 = tcg_temp_new_i32(); | ||
708 | - t1 = tcg_temp_new_i32(); | ||
709 | + t0 = tcg_temp_ebb_new_i32(); | ||
710 | + t1 = tcg_temp_ebb_new_i32(); | ||
711 | tcg_gen_shli_i32(t0, arg1, arg2); | ||
712 | tcg_gen_shri_i32(t1, arg1, 32 - arg2); | ||
713 | tcg_gen_or_i32(ret, t0, t1); | ||
714 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_rotr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) | ||
715 | } else { | ||
716 | TCGv_i32 t0, t1; | ||
717 | |||
718 | - t0 = tcg_temp_new_i32(); | ||
719 | - t1 = tcg_temp_new_i32(); | ||
720 | + t0 = tcg_temp_ebb_new_i32(); | ||
721 | + t1 = tcg_temp_ebb_new_i32(); | ||
722 | tcg_gen_shr_i32(t0, arg1, arg2); | ||
723 | tcg_gen_subfi_i32(t1, 32, arg2); | ||
724 | tcg_gen_shl_i32(t1, arg1, t1); | ||
725 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_deposit_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2, | ||
726 | return; | ||
89 | } | 727 | } |
90 | 728 | ||
91 | if (z_mask == 0) { | 729 | - t1 = tcg_temp_new_i32(); |
730 | + t1 = tcg_temp_ebb_new_i32(); | ||
731 | |||
732 | if (TCG_TARGET_HAS_extract2_i32) { | ||
733 | if (ofs + len == 32) { | ||
734 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_extract2_i32(TCGv_i32 ret, TCGv_i32 al, TCGv_i32 ah, | ||
735 | } else if (TCG_TARGET_HAS_extract2_i32) { | ||
736 | tcg_gen_op4i_i32(INDEX_op_extract2_i32, ret, al, ah, ofs); | ||
737 | } else { | ||
738 | - TCGv_i32 t0 = tcg_temp_new_i32(); | ||
739 | + TCGv_i32 t0 = tcg_temp_ebb_new_i32(); | ||
740 | tcg_gen_shri_i32(t0, al, ofs); | ||
741 | tcg_gen_deposit_i32(ret, t0, ah, 32 - ofs, ofs); | ||
742 | tcg_temp_free_i32(t0); | ||
743 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_movcond_i32(TCGCond cond, TCGv_i32 ret, TCGv_i32 c1, | ||
744 | } else if (TCG_TARGET_HAS_movcond_i32) { | ||
745 | tcg_gen_op6i_i32(INDEX_op_movcond_i32, ret, c1, c2, v1, v2, cond); | ||
746 | } else { | ||
747 | - TCGv_i32 t0 = tcg_temp_new_i32(); | ||
748 | - TCGv_i32 t1 = tcg_temp_new_i32(); | ||
749 | + TCGv_i32 t0 = tcg_temp_ebb_new_i32(); | ||
750 | + TCGv_i32 t1 = tcg_temp_ebb_new_i32(); | ||
751 | tcg_gen_setcond_i32(cond, t0, c1, c2); | ||
752 | tcg_gen_neg_i32(t0, t0); | ||
753 | tcg_gen_and_i32(t1, v1, t0); | ||
754 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_add2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 al, | ||
755 | if (TCG_TARGET_HAS_add2_i32) { | ||
756 | tcg_gen_op6_i32(INDEX_op_add2_i32, rl, rh, al, ah, bl, bh); | ||
757 | } else { | ||
758 | - TCGv_i64 t0 = tcg_temp_new_i64(); | ||
759 | - TCGv_i64 t1 = tcg_temp_new_i64(); | ||
760 | + TCGv_i64 t0 = tcg_temp_ebb_new_i64(); | ||
761 | + TCGv_i64 t1 = tcg_temp_ebb_new_i64(); | ||
762 | tcg_gen_concat_i32_i64(t0, al, ah); | ||
763 | tcg_gen_concat_i32_i64(t1, bl, bh); | ||
764 | tcg_gen_add_i64(t0, t0, t1); | ||
765 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_sub2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 al, | ||
766 | if (TCG_TARGET_HAS_sub2_i32) { | ||
767 | tcg_gen_op6_i32(INDEX_op_sub2_i32, rl, rh, al, ah, bl, bh); | ||
768 | } else { | ||
769 | - TCGv_i64 t0 = tcg_temp_new_i64(); | ||
770 | - TCGv_i64 t1 = tcg_temp_new_i64(); | ||
771 | + TCGv_i64 t0 = tcg_temp_ebb_new_i64(); | ||
772 | + TCGv_i64 t1 = tcg_temp_ebb_new_i64(); | ||
773 | tcg_gen_concat_i32_i64(t0, al, ah); | ||
774 | tcg_gen_concat_i32_i64(t1, bl, bh); | ||
775 | tcg_gen_sub_i64(t0, t0, t1); | ||
776 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_mulu2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2) | ||
777 | if (TCG_TARGET_HAS_mulu2_i32) { | ||
778 | tcg_gen_op4_i32(INDEX_op_mulu2_i32, rl, rh, arg1, arg2); | ||
779 | } else if (TCG_TARGET_HAS_muluh_i32) { | ||
780 | - TCGv_i32 t = tcg_temp_new_i32(); | ||
781 | + TCGv_i32 t = tcg_temp_ebb_new_i32(); | ||
782 | tcg_gen_op3_i32(INDEX_op_mul_i32, t, arg1, arg2); | ||
783 | tcg_gen_op3_i32(INDEX_op_muluh_i32, rh, arg1, arg2); | ||
784 | tcg_gen_mov_i32(rl, t); | ||
785 | tcg_temp_free_i32(t); | ||
786 | } else if (TCG_TARGET_REG_BITS == 64) { | ||
787 | - TCGv_i64 t0 = tcg_temp_new_i64(); | ||
788 | - TCGv_i64 t1 = tcg_temp_new_i64(); | ||
789 | + TCGv_i64 t0 = tcg_temp_ebb_new_i64(); | ||
790 | + TCGv_i64 t1 = tcg_temp_ebb_new_i64(); | ||
791 | tcg_gen_extu_i32_i64(t0, arg1); | ||
792 | tcg_gen_extu_i32_i64(t1, arg2); | ||
793 | tcg_gen_mul_i64(t0, t0, t1); | ||
794 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_muls2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2) | ||
795 | if (TCG_TARGET_HAS_muls2_i32) { | ||
796 | tcg_gen_op4_i32(INDEX_op_muls2_i32, rl, rh, arg1, arg2); | ||
797 | } else if (TCG_TARGET_HAS_mulsh_i32) { | ||
798 | - TCGv_i32 t = tcg_temp_new_i32(); | ||
799 | + TCGv_i32 t = tcg_temp_ebb_new_i32(); | ||
800 | tcg_gen_op3_i32(INDEX_op_mul_i32, t, arg1, arg2); | ||
801 | tcg_gen_op3_i32(INDEX_op_mulsh_i32, rh, arg1, arg2); | ||
802 | tcg_gen_mov_i32(rl, t); | ||
803 | tcg_temp_free_i32(t); | ||
804 | } else if (TCG_TARGET_REG_BITS == 32) { | ||
805 | - TCGv_i32 t0 = tcg_temp_new_i32(); | ||
806 | - TCGv_i32 t1 = tcg_temp_new_i32(); | ||
807 | - TCGv_i32 t2 = tcg_temp_new_i32(); | ||
808 | - TCGv_i32 t3 = tcg_temp_new_i32(); | ||
809 | + TCGv_i32 t0 = tcg_temp_ebb_new_i32(); | ||
810 | + TCGv_i32 t1 = tcg_temp_ebb_new_i32(); | ||
811 | + TCGv_i32 t2 = tcg_temp_ebb_new_i32(); | ||
812 | + TCGv_i32 t3 = tcg_temp_ebb_new_i32(); | ||
813 | tcg_gen_mulu2_i32(t0, t1, arg1, arg2); | ||
814 | /* Adjust for negative inputs. */ | ||
815 | tcg_gen_sari_i32(t2, arg1, 31); | ||
816 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_muls2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2) | ||
817 | tcg_temp_free_i32(t2); | ||
818 | tcg_temp_free_i32(t3); | ||
819 | } else { | ||
820 | - TCGv_i64 t0 = tcg_temp_new_i64(); | ||
821 | - TCGv_i64 t1 = tcg_temp_new_i64(); | ||
822 | + TCGv_i64 t0 = tcg_temp_ebb_new_i64(); | ||
823 | + TCGv_i64 t1 = tcg_temp_ebb_new_i64(); | ||
824 | tcg_gen_ext_i32_i64(t0, arg1); | ||
825 | tcg_gen_ext_i32_i64(t1, arg2); | ||
826 | tcg_gen_mul_i64(t0, t0, t1); | ||
827 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_muls2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2) | ||
828 | void tcg_gen_mulsu2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2) | ||
829 | { | ||
830 | if (TCG_TARGET_REG_BITS == 32) { | ||
831 | - TCGv_i32 t0 = tcg_temp_new_i32(); | ||
832 | - TCGv_i32 t1 = tcg_temp_new_i32(); | ||
833 | - TCGv_i32 t2 = tcg_temp_new_i32(); | ||
834 | + TCGv_i32 t0 = tcg_temp_ebb_new_i32(); | ||
835 | + TCGv_i32 t1 = tcg_temp_ebb_new_i32(); | ||
836 | + TCGv_i32 t2 = tcg_temp_ebb_new_i32(); | ||
837 | tcg_gen_mulu2_i32(t0, t1, arg1, arg2); | ||
838 | /* Adjust for negative input for the signed arg1. */ | ||
839 | tcg_gen_sari_i32(t2, arg1, 31); | ||
840 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_mulsu2_i32(TCGv_i32 rl, TCGv_i32 rh, TCGv_i32 arg1, TCGv_i32 arg2) | ||
841 | tcg_temp_free_i32(t1); | ||
842 | tcg_temp_free_i32(t2); | ||
843 | } else { | ||
844 | - TCGv_i64 t0 = tcg_temp_new_i64(); | ||
845 | - TCGv_i64 t1 = tcg_temp_new_i64(); | ||
846 | + TCGv_i64 t0 = tcg_temp_ebb_new_i64(); | ||
847 | + TCGv_i64 t1 = tcg_temp_ebb_new_i64(); | ||
848 | tcg_gen_ext_i32_i64(t0, arg1); | ||
849 | tcg_gen_extu_i32_i64(t1, arg2); | ||
850 | tcg_gen_mul_i64(t0, t0, t1); | ||
851 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg, int flags) | ||
852 | if (TCG_TARGET_HAS_bswap16_i32) { | ||
853 | tcg_gen_op3i_i32(INDEX_op_bswap16_i32, ret, arg, flags); | ||
854 | } else { | ||
855 | - TCGv_i32 t0 = tcg_temp_new_i32(); | ||
856 | - TCGv_i32 t1 = tcg_temp_new_i32(); | ||
857 | + TCGv_i32 t0 = tcg_temp_ebb_new_i32(); | ||
858 | + TCGv_i32 t1 = tcg_temp_ebb_new_i32(); | ||
859 | |||
860 | tcg_gen_shri_i32(t0, arg, 8); | ||
861 | if (!(flags & TCG_BSWAP_IZ)) { | ||
862 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_bswap32_i32(TCGv_i32 ret, TCGv_i32 arg) | ||
863 | if (TCG_TARGET_HAS_bswap32_i32) { | ||
864 | tcg_gen_op3i_i32(INDEX_op_bswap32_i32, ret, arg, 0); | ||
865 | } else { | ||
866 | - TCGv_i32 t0 = tcg_temp_new_i32(); | ||
867 | - TCGv_i32 t1 = tcg_temp_new_i32(); | ||
868 | + TCGv_i32 t0 = tcg_temp_ebb_new_i32(); | ||
869 | + TCGv_i32 t1 = tcg_temp_ebb_new_i32(); | ||
870 | TCGv_i32 t2 = tcg_constant_i32(0x00ff00ff); | ||
871 | |||
872 | /* arg = abcd */ | ||
873 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_umax_i32(TCGv_i32 ret, TCGv_i32 a, TCGv_i32 b) | ||
874 | |||
875 | void tcg_gen_abs_i32(TCGv_i32 ret, TCGv_i32 a) | ||
876 | { | ||
877 | - TCGv_i32 t = tcg_temp_new_i32(); | ||
878 | + TCGv_i32 t = tcg_temp_ebb_new_i32(); | ||
879 | |||
880 | tcg_gen_sari_i32(t, a, 31); | ||
881 | tcg_gen_xor_i32(ret, a, t); | ||
882 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2) | ||
883 | TCGv_i64 t0; | ||
884 | TCGv_i32 t1; | ||
885 | |||
886 | - t0 = tcg_temp_new_i64(); | ||
887 | - t1 = tcg_temp_new_i32(); | ||
888 | + t0 = tcg_temp_ebb_new_i64(); | ||
889 | + t1 = tcg_temp_ebb_new_i32(); | ||
890 | |||
891 | tcg_gen_mulu2_i32(TCGV_LOW(t0), TCGV_HIGH(t0), | ||
892 | TCGV_LOW(arg1), TCGV_LOW(arg2)); | ||
893 | @@ -XXX,XX +XXX,XX @@ static inline void tcg_gen_shifti_i64(TCGv_i64 ret, TCGv_i64 arg1, | ||
894 | tcg_gen_extract2_i32(TCGV_HIGH(ret), | ||
895 | TCGV_LOW(arg1), TCGV_HIGH(arg1), 32 - c); | ||
896 | } else { | ||
897 | - TCGv_i32 t0 = tcg_temp_new_i32(); | ||
898 | + TCGv_i32 t0 = tcg_temp_ebb_new_i32(); | ||
899 | tcg_gen_shri_i32(t0, TCGV_LOW(arg1), 32 - c); | ||
900 | tcg_gen_deposit_i32(TCGV_HIGH(ret), t0, | ||
901 | TCGV_HIGH(arg1), c, 32 - c); | ||
902 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2) | ||
903 | if (TCG_TARGET_HAS_div_i64) { | ||
904 | tcg_gen_op3_i64(INDEX_op_div_i64, ret, arg1, arg2); | ||
905 | } else if (TCG_TARGET_HAS_div2_i64) { | ||
906 | - TCGv_i64 t0 = tcg_temp_new_i64(); | ||
907 | + TCGv_i64 t0 = tcg_temp_ebb_new_i64(); | ||
908 | tcg_gen_sari_i64(t0, arg1, 63); | ||
909 | tcg_gen_op5_i64(INDEX_op_div2_i64, ret, t0, arg1, t0, arg2); | ||
910 | tcg_temp_free_i64(t0); | ||
911 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2) | ||
912 | if (TCG_TARGET_HAS_rem_i64) { | ||
913 | tcg_gen_op3_i64(INDEX_op_rem_i64, ret, arg1, arg2); | ||
914 | } else if (TCG_TARGET_HAS_div_i64) { | ||
915 | - TCGv_i64 t0 = tcg_temp_new_i64(); | ||
916 | + TCGv_i64 t0 = tcg_temp_ebb_new_i64(); | ||
917 | tcg_gen_op3_i64(INDEX_op_div_i64, t0, arg1, arg2); | ||
918 | tcg_gen_mul_i64(t0, t0, arg2); | ||
919 | tcg_gen_sub_i64(ret, arg1, t0); | ||
920 | tcg_temp_free_i64(t0); | ||
921 | } else if (TCG_TARGET_HAS_div2_i64) { | ||
922 | - TCGv_i64 t0 = tcg_temp_new_i64(); | ||
923 | + TCGv_i64 t0 = tcg_temp_ebb_new_i64(); | ||
924 | tcg_gen_sari_i64(t0, arg1, 63); | ||
925 | tcg_gen_op5_i64(INDEX_op_div2_i64, t0, ret, arg1, t0, arg2); | ||
926 | tcg_temp_free_i64(t0); | ||
927 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2) | ||
928 | if (TCG_TARGET_HAS_div_i64) { | ||
929 | tcg_gen_op3_i64(INDEX_op_divu_i64, ret, arg1, arg2); | ||
930 | } else if (TCG_TARGET_HAS_div2_i64) { | ||
931 | - TCGv_i64 t0 = tcg_temp_new_i64(); | ||
932 | + TCGv_i64 t0 = tcg_temp_ebb_new_i64(); | ||
933 | tcg_gen_movi_i64(t0, 0); | ||
934 | tcg_gen_op5_i64(INDEX_op_divu2_i64, ret, t0, arg1, t0, arg2); | ||
935 | tcg_temp_free_i64(t0); | ||
936 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2) | ||
937 | if (TCG_TARGET_HAS_rem_i64) { | ||
938 | tcg_gen_op3_i64(INDEX_op_remu_i64, ret, arg1, arg2); | ||
939 | } else if (TCG_TARGET_HAS_div_i64) { | ||
940 | - TCGv_i64 t0 = tcg_temp_new_i64(); | ||
941 | + TCGv_i64 t0 = tcg_temp_ebb_new_i64(); | ||
942 | tcg_gen_op3_i64(INDEX_op_divu_i64, t0, arg1, arg2); | ||
943 | tcg_gen_mul_i64(t0, t0, arg2); | ||
944 | tcg_gen_sub_i64(ret, arg1, t0); | ||
945 | tcg_temp_free_i64(t0); | ||
946 | } else if (TCG_TARGET_HAS_div2_i64) { | ||
947 | - TCGv_i64 t0 = tcg_temp_new_i64(); | ||
948 | + TCGv_i64 t0 = tcg_temp_ebb_new_i64(); | ||
949 | tcg_gen_movi_i64(t0, 0); | ||
950 | tcg_gen_op5_i64(INDEX_op_divu2_i64, t0, ret, arg1, t0, arg2); | ||
951 | tcg_temp_free_i64(t0); | ||
952 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_bswap16_i64(TCGv_i64 ret, TCGv_i64 arg, int flags) | ||
953 | } else if (TCG_TARGET_HAS_bswap16_i64) { | ||
954 | tcg_gen_op3i_i64(INDEX_op_bswap16_i64, ret, arg, flags); | ||
955 | } else { | ||
956 | - TCGv_i64 t0 = tcg_temp_new_i64(); | ||
957 | - TCGv_i64 t1 = tcg_temp_new_i64(); | ||
958 | + TCGv_i64 t0 = tcg_temp_ebb_new_i64(); | ||
959 | + TCGv_i64 t1 = tcg_temp_ebb_new_i64(); | ||
960 | |||
961 | tcg_gen_shri_i64(t0, arg, 8); | ||
962 | if (!(flags & TCG_BSWAP_IZ)) { | ||
963 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg, int flags) | ||
964 | } else if (TCG_TARGET_HAS_bswap32_i64) { | ||
965 | tcg_gen_op3i_i64(INDEX_op_bswap32_i64, ret, arg, flags); | ||
966 | } else { | ||
967 | - TCGv_i64 t0 = tcg_temp_new_i64(); | ||
968 | - TCGv_i64 t1 = tcg_temp_new_i64(); | ||
969 | + TCGv_i64 t0 = tcg_temp_ebb_new_i64(); | ||
970 | + TCGv_i64 t1 = tcg_temp_ebb_new_i64(); | ||
971 | TCGv_i64 t2 = tcg_constant_i64(0x00ff00ff); | ||
972 | |||
973 | /* arg = xxxxabcd */ | ||
974 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg) | ||
975 | { | ||
976 | if (TCG_TARGET_REG_BITS == 32) { | ||
977 | TCGv_i32 t0, t1; | ||
978 | - t0 = tcg_temp_new_i32(); | ||
979 | - t1 = tcg_temp_new_i32(); | ||
980 | + t0 = tcg_temp_ebb_new_i32(); | ||
981 | + t1 = tcg_temp_ebb_new_i32(); | ||
982 | |||
983 | tcg_gen_bswap32_i32(t0, TCGV_LOW(arg)); | ||
984 | tcg_gen_bswap32_i32(t1, TCGV_HIGH(arg)); | ||
985 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg) | ||
986 | } else if (TCG_TARGET_HAS_bswap64_i64) { | ||
987 | tcg_gen_op3i_i64(INDEX_op_bswap64_i64, ret, arg, 0); | ||
988 | } else { | ||
989 | - TCGv_i64 t0 = tcg_temp_new_i64(); | ||
990 | - TCGv_i64 t1 = tcg_temp_new_i64(); | ||
991 | - TCGv_i64 t2 = tcg_temp_new_i64(); | ||
992 | + TCGv_i64 t0 = tcg_temp_ebb_new_i64(); | ||
993 | + TCGv_i64 t1 = tcg_temp_ebb_new_i64(); | ||
994 | + TCGv_i64 t2 = tcg_temp_ebb_new_i64(); | ||
995 | |||
996 | /* arg = abcdefgh */ | ||
997 | tcg_gen_movi_i64(t2, 0x00ff00ff00ff00ffull); | ||
998 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_bswap64_i64(TCGv_i64 ret, TCGv_i64 arg) | ||
999 | void tcg_gen_hswap_i64(TCGv_i64 ret, TCGv_i64 arg) | ||
1000 | { | ||
1001 | uint64_t m = 0x0000ffff0000ffffull; | ||
1002 | - TCGv_i64 t0 = tcg_temp_new_i64(); | ||
1003 | - TCGv_i64 t1 = tcg_temp_new_i64(); | ||
1004 | + TCGv_i64 t0 = tcg_temp_ebb_new_i64(); | ||
1005 | + TCGv_i64 t1 = tcg_temp_ebb_new_i64(); | ||
1006 | |||
1007 | /* See include/qemu/bitops.h, hswap64. */ | ||
1008 | tcg_gen_rotli_i64(t1, arg, 32); | ||
1009 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_andc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2) | ||
1010 | } else if (TCG_TARGET_HAS_andc_i64) { | ||
1011 | tcg_gen_op3_i64(INDEX_op_andc_i64, ret, arg1, arg2); | ||
1012 | } else { | ||
1013 | - TCGv_i64 t0 = tcg_temp_new_i64(); | ||
1014 | + TCGv_i64 t0 = tcg_temp_ebb_new_i64(); | ||
1015 | tcg_gen_not_i64(t0, arg2); | ||
1016 | tcg_gen_and_i64(ret, arg1, t0); | ||
1017 | tcg_temp_free_i64(t0); | ||
1018 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_orc_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2) | ||
1019 | } else if (TCG_TARGET_HAS_orc_i64) { | ||
1020 | tcg_gen_op3_i64(INDEX_op_orc_i64, ret, arg1, arg2); | ||
1021 | } else { | ||
1022 | - TCGv_i64 t0 = tcg_temp_new_i64(); | ||
1023 | + TCGv_i64 t0 = tcg_temp_ebb_new_i64(); | ||
1024 | tcg_gen_not_i64(t0, arg2); | ||
1025 | tcg_gen_or_i64(ret, arg1, t0); | ||
1026 | tcg_temp_free_i64(t0); | ||
1027 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_clzi_i64(TCGv_i64 ret, TCGv_i64 arg1, uint64_t arg2) | ||
1028 | if (TCG_TARGET_REG_BITS == 32 | ||
1029 | && TCG_TARGET_HAS_clz_i32 | ||
1030 | && arg2 <= 0xffffffffu) { | ||
1031 | - TCGv_i32 t = tcg_temp_new_i32(); | ||
1032 | + TCGv_i32 t = tcg_temp_ebb_new_i32(); | ||
1033 | tcg_gen_clzi_i32(t, TCGV_LOW(arg1), arg2 - 32); | ||
1034 | tcg_gen_addi_i32(t, t, 32); | ||
1035 | tcg_gen_clz_i32(TCGV_LOW(ret), TCGV_HIGH(arg1), t); | ||
1036 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_ctz_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2) | ||
1037 | if (TCG_TARGET_HAS_ctz_i64) { | ||
1038 | tcg_gen_op3_i64(INDEX_op_ctz_i64, ret, arg1, arg2); | ||
1039 | } else if (TCG_TARGET_HAS_ctpop_i64 || TCG_TARGET_HAS_clz_i64) { | ||
1040 | - TCGv_i64 z, t = tcg_temp_new_i64(); | ||
1041 | + TCGv_i64 z, t = tcg_temp_ebb_new_i64(); | ||
1042 | |||
1043 | if (TCG_TARGET_HAS_ctpop_i64) { | ||
1044 | tcg_gen_subi_i64(t, arg1, 1); | ||
1045 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_ctzi_i64(TCGv_i64 ret, TCGv_i64 arg1, uint64_t arg2) | ||
1046 | if (TCG_TARGET_REG_BITS == 32 | ||
1047 | && TCG_TARGET_HAS_ctz_i32 | ||
1048 | && arg2 <= 0xffffffffu) { | ||
1049 | - TCGv_i32 t32 = tcg_temp_new_i32(); | ||
1050 | + TCGv_i32 t32 = tcg_temp_ebb_new_i32(); | ||
1051 | tcg_gen_ctzi_i32(t32, TCGV_HIGH(arg1), arg2 - 32); | ||
1052 | tcg_gen_addi_i32(t32, t32, 32); | ||
1053 | tcg_gen_ctz_i32(TCGV_LOW(ret), TCGV_LOW(arg1), t32); | ||
1054 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_ctzi_i64(TCGv_i64 ret, TCGv_i64 arg1, uint64_t arg2) | ||
1055 | && TCG_TARGET_HAS_ctpop_i64 | ||
1056 | && arg2 == 64) { | ||
1057 | /* This equivalence has the advantage of not requiring a fixup. */ | ||
1058 | - TCGv_i64 t = tcg_temp_new_i64(); | ||
1059 | + TCGv_i64 t = tcg_temp_ebb_new_i64(); | ||
1060 | tcg_gen_subi_i64(t, arg1, 1); | ||
1061 | tcg_gen_andc_i64(t, t, arg1); | ||
1062 | tcg_gen_ctpop_i64(ret, t); | ||
1063 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_ctzi_i64(TCGv_i64 ret, TCGv_i64 arg1, uint64_t arg2) | ||
1064 | void tcg_gen_clrsb_i64(TCGv_i64 ret, TCGv_i64 arg) | ||
1065 | { | ||
1066 | if (TCG_TARGET_HAS_clz_i64 || TCG_TARGET_HAS_clz_i32) { | ||
1067 | - TCGv_i64 t = tcg_temp_new_i64(); | ||
1068 | + TCGv_i64 t = tcg_temp_ebb_new_i64(); | ||
1069 | tcg_gen_sari_i64(t, arg, 63); | ||
1070 | tcg_gen_xor_i64(t, t, arg); | ||
1071 | tcg_gen_clzi_i64(t, t, 64); | ||
1072 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_rotl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2) | ||
1073 | tcg_gen_op3_i64(INDEX_op_rotl_i64, ret, arg1, arg2); | ||
1074 | } else { | ||
1075 | TCGv_i64 t0, t1; | ||
1076 | - t0 = tcg_temp_new_i64(); | ||
1077 | - t1 = tcg_temp_new_i64(); | ||
1078 | + t0 = tcg_temp_ebb_new_i64(); | ||
1079 | + t1 = tcg_temp_ebb_new_i64(); | ||
1080 | tcg_gen_shl_i64(t0, arg1, arg2); | ||
1081 | tcg_gen_subfi_i64(t1, 64, arg2); | ||
1082 | tcg_gen_shr_i64(t1, arg1, t1); | ||
1083 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_rotli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2) | ||
1084 | tcg_gen_rotl_i64(ret, arg1, tcg_constant_i64(arg2)); | ||
1085 | } else { | ||
1086 | TCGv_i64 t0, t1; | ||
1087 | - t0 = tcg_temp_new_i64(); | ||
1088 | - t1 = tcg_temp_new_i64(); | ||
1089 | + t0 = tcg_temp_ebb_new_i64(); | ||
1090 | + t1 = tcg_temp_ebb_new_i64(); | ||
1091 | tcg_gen_shli_i64(t0, arg1, arg2); | ||
1092 | tcg_gen_shri_i64(t1, arg1, 64 - arg2); | ||
1093 | tcg_gen_or_i64(ret, t0, t1); | ||
1094 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_rotr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2) | ||
1095 | tcg_gen_op3_i64(INDEX_op_rotr_i64, ret, arg1, arg2); | ||
1096 | } else { | ||
1097 | TCGv_i64 t0, t1; | ||
1098 | - t0 = tcg_temp_new_i64(); | ||
1099 | - t1 = tcg_temp_new_i64(); | ||
1100 | + t0 = tcg_temp_ebb_new_i64(); | ||
1101 | + t1 = tcg_temp_ebb_new_i64(); | ||
1102 | tcg_gen_shr_i64(t0, arg1, arg2); | ||
1103 | tcg_gen_subfi_i64(t1, 64, arg2); | ||
1104 | tcg_gen_shl_i64(t1, arg1, t1); | ||
1105 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_deposit_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2, | ||
1106 | } | ||
1107 | } | ||
1108 | |||
1109 | - t1 = tcg_temp_new_i64(); | ||
1110 | + t1 = tcg_temp_ebb_new_i64(); | ||
1111 | |||
1112 | if (TCG_TARGET_HAS_extract2_i64) { | ||
1113 | if (ofs + len == 64) { | ||
1114 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_sextract_i64(TCGv_i64 ret, TCGv_i64 arg, | ||
1115 | tcg_gen_sextract_i32(TCGV_HIGH(ret), TCGV_HIGH(arg), 0, len - 32); | ||
1116 | return; | ||
1117 | } else if (len > 32) { | ||
1118 | - TCGv_i32 t = tcg_temp_new_i32(); | ||
1119 | + TCGv_i32 t = tcg_temp_ebb_new_i32(); | ||
1120 | /* Extract the bits for the high word normally. */ | ||
1121 | tcg_gen_sextract_i32(t, TCGV_HIGH(arg), ofs + 32, len - 32); | ||
1122 | /* Shift the field down for the low part. */ | ||
1123 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_extract2_i64(TCGv_i64 ret, TCGv_i64 al, TCGv_i64 ah, | ||
1124 | } else if (TCG_TARGET_HAS_extract2_i64) { | ||
1125 | tcg_gen_op4i_i64(INDEX_op_extract2_i64, ret, al, ah, ofs); | ||
1126 | } else { | ||
1127 | - TCGv_i64 t0 = tcg_temp_new_i64(); | ||
1128 | + TCGv_i64 t0 = tcg_temp_ebb_new_i64(); | ||
1129 | tcg_gen_shri_i64(t0, al, ofs); | ||
1130 | tcg_gen_deposit_i64(ret, t0, ah, 64 - ofs, ofs); | ||
1131 | tcg_temp_free_i64(t0); | ||
1132 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_movcond_i64(TCGCond cond, TCGv_i64 ret, TCGv_i64 c1, | ||
1133 | } else if (cond == TCG_COND_NEVER) { | ||
1134 | tcg_gen_mov_i64(ret, v2); | ||
1135 | } else if (TCG_TARGET_REG_BITS == 32) { | ||
1136 | - TCGv_i32 t0 = tcg_temp_new_i32(); | ||
1137 | - TCGv_i32 t1 = tcg_temp_new_i32(); | ||
1138 | + TCGv_i32 t0 = tcg_temp_ebb_new_i32(); | ||
1139 | + TCGv_i32 t1 = tcg_temp_ebb_new_i32(); | ||
1140 | tcg_gen_op6i_i32(INDEX_op_setcond2_i32, t0, | ||
1141 | TCGV_LOW(c1), TCGV_HIGH(c1), | ||
1142 | TCGV_LOW(c2), TCGV_HIGH(c2), cond); | ||
1143 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_movcond_i64(TCGCond cond, TCGv_i64 ret, TCGv_i64 c1, | ||
1144 | } else if (TCG_TARGET_HAS_movcond_i64) { | ||
1145 | tcg_gen_op6i_i64(INDEX_op_movcond_i64, ret, c1, c2, v1, v2, cond); | ||
1146 | } else { | ||
1147 | - TCGv_i64 t0 = tcg_temp_new_i64(); | ||
1148 | - TCGv_i64 t1 = tcg_temp_new_i64(); | ||
1149 | + TCGv_i64 t0 = tcg_temp_ebb_new_i64(); | ||
1150 | + TCGv_i64 t1 = tcg_temp_ebb_new_i64(); | ||
1151 | tcg_gen_setcond_i64(cond, t0, c1, c2); | ||
1152 | tcg_gen_neg_i64(t0, t0); | ||
1153 | tcg_gen_and_i64(t1, v1, t0); | ||
1154 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_add2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 al, | ||
1155 | if (TCG_TARGET_HAS_add2_i64) { | ||
1156 | tcg_gen_op6_i64(INDEX_op_add2_i64, rl, rh, al, ah, bl, bh); | ||
1157 | } else { | ||
1158 | - TCGv_i64 t0 = tcg_temp_new_i64(); | ||
1159 | - TCGv_i64 t1 = tcg_temp_new_i64(); | ||
1160 | + TCGv_i64 t0 = tcg_temp_ebb_new_i64(); | ||
1161 | + TCGv_i64 t1 = tcg_temp_ebb_new_i64(); | ||
1162 | tcg_gen_add_i64(t0, al, bl); | ||
1163 | tcg_gen_setcond_i64(TCG_COND_LTU, t1, t0, al); | ||
1164 | tcg_gen_add_i64(rh, ah, bh); | ||
1165 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_sub2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 al, | ||
1166 | if (TCG_TARGET_HAS_sub2_i64) { | ||
1167 | tcg_gen_op6_i64(INDEX_op_sub2_i64, rl, rh, al, ah, bl, bh); | ||
1168 | } else { | ||
1169 | - TCGv_i64 t0 = tcg_temp_new_i64(); | ||
1170 | - TCGv_i64 t1 = tcg_temp_new_i64(); | ||
1171 | + TCGv_i64 t0 = tcg_temp_ebb_new_i64(); | ||
1172 | + TCGv_i64 t1 = tcg_temp_ebb_new_i64(); | ||
1173 | tcg_gen_sub_i64(t0, al, bl); | ||
1174 | tcg_gen_setcond_i64(TCG_COND_LTU, t1, al, bl); | ||
1175 | tcg_gen_sub_i64(rh, ah, bh); | ||
1176 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_mulu2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2) | ||
1177 | if (TCG_TARGET_HAS_mulu2_i64) { | ||
1178 | tcg_gen_op4_i64(INDEX_op_mulu2_i64, rl, rh, arg1, arg2); | ||
1179 | } else if (TCG_TARGET_HAS_muluh_i64) { | ||
1180 | - TCGv_i64 t = tcg_temp_new_i64(); | ||
1181 | + TCGv_i64 t = tcg_temp_ebb_new_i64(); | ||
1182 | tcg_gen_op3_i64(INDEX_op_mul_i64, t, arg1, arg2); | ||
1183 | tcg_gen_op3_i64(INDEX_op_muluh_i64, rh, arg1, arg2); | ||
1184 | tcg_gen_mov_i64(rl, t); | ||
1185 | tcg_temp_free_i64(t); | ||
1186 | } else { | ||
1187 | - TCGv_i64 t0 = tcg_temp_new_i64(); | ||
1188 | + TCGv_i64 t0 = tcg_temp_ebb_new_i64(); | ||
1189 | tcg_gen_mul_i64(t0, arg1, arg2); | ||
1190 | gen_helper_muluh_i64(rh, arg1, arg2); | ||
1191 | tcg_gen_mov_i64(rl, t0); | ||
1192 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_muls2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2) | ||
1193 | if (TCG_TARGET_HAS_muls2_i64) { | ||
1194 | tcg_gen_op4_i64(INDEX_op_muls2_i64, rl, rh, arg1, arg2); | ||
1195 | } else if (TCG_TARGET_HAS_mulsh_i64) { | ||
1196 | - TCGv_i64 t = tcg_temp_new_i64(); | ||
1197 | + TCGv_i64 t = tcg_temp_ebb_new_i64(); | ||
1198 | tcg_gen_op3_i64(INDEX_op_mul_i64, t, arg1, arg2); | ||
1199 | tcg_gen_op3_i64(INDEX_op_mulsh_i64, rh, arg1, arg2); | ||
1200 | tcg_gen_mov_i64(rl, t); | ||
1201 | tcg_temp_free_i64(t); | ||
1202 | } else if (TCG_TARGET_HAS_mulu2_i64 || TCG_TARGET_HAS_muluh_i64) { | ||
1203 | - TCGv_i64 t0 = tcg_temp_new_i64(); | ||
1204 | - TCGv_i64 t1 = tcg_temp_new_i64(); | ||
1205 | - TCGv_i64 t2 = tcg_temp_new_i64(); | ||
1206 | - TCGv_i64 t3 = tcg_temp_new_i64(); | ||
1207 | + TCGv_i64 t0 = tcg_temp_ebb_new_i64(); | ||
1208 | + TCGv_i64 t1 = tcg_temp_ebb_new_i64(); | ||
1209 | + TCGv_i64 t2 = tcg_temp_ebb_new_i64(); | ||
1210 | + TCGv_i64 t3 = tcg_temp_ebb_new_i64(); | ||
1211 | tcg_gen_mulu2_i64(t0, t1, arg1, arg2); | ||
1212 | /* Adjust for negative inputs. */ | ||
1213 | tcg_gen_sari_i64(t2, arg1, 63); | ||
1214 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_muls2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2) | ||
1215 | tcg_temp_free_i64(t2); | ||
1216 | tcg_temp_free_i64(t3); | ||
1217 | } else { | ||
1218 | - TCGv_i64 t0 = tcg_temp_new_i64(); | ||
1219 | + TCGv_i64 t0 = tcg_temp_ebb_new_i64(); | ||
1220 | tcg_gen_mul_i64(t0, arg1, arg2); | ||
1221 | gen_helper_mulsh_i64(rh, arg1, arg2); | ||
1222 | tcg_gen_mov_i64(rl, t0); | ||
1223 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_muls2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2) | ||
1224 | |||
1225 | void tcg_gen_mulsu2_i64(TCGv_i64 rl, TCGv_i64 rh, TCGv_i64 arg1, TCGv_i64 arg2) | ||
1226 | { | ||
1227 | - TCGv_i64 t0 = tcg_temp_new_i64(); | ||
1228 | - TCGv_i64 t1 = tcg_temp_new_i64(); | ||
1229 | - TCGv_i64 t2 = tcg_temp_new_i64(); | ||
1230 | + TCGv_i64 t0 = tcg_temp_ebb_new_i64(); | ||
1231 | + TCGv_i64 t1 = tcg_temp_ebb_new_i64(); | ||
1232 | + TCGv_i64 t2 = tcg_temp_ebb_new_i64(); | ||
1233 | tcg_gen_mulu2_i64(t0, t1, arg1, arg2); | ||
1234 | /* Adjust for negative input for the signed arg1. */ | ||
1235 | tcg_gen_sari_i64(t2, arg1, 63); | ||
1236 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_umax_i64(TCGv_i64 ret, TCGv_i64 a, TCGv_i64 b) | ||
1237 | |||
1238 | void tcg_gen_abs_i64(TCGv_i64 ret, TCGv_i64 a) | ||
1239 | { | ||
1240 | - TCGv_i64 t = tcg_temp_new_i64(); | ||
1241 | + TCGv_i64 t = tcg_temp_ebb_new_i64(); | ||
1242 | |||
1243 | tcg_gen_sari_i64(t, a, 63); | ||
1244 | tcg_gen_xor_i64(ret, a, t); | ||
1245 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_extrh_i64_i32(TCGv_i32 ret, TCGv_i64 arg) | ||
1246 | tcg_gen_op2(INDEX_op_extrh_i64_i32, | ||
1247 | tcgv_i32_arg(ret), tcgv_i64_arg(arg)); | ||
1248 | } else { | ||
1249 | - TCGv_i64 t = tcg_temp_new_i64(); | ||
1250 | + TCGv_i64 t = tcg_temp_ebb_new_i64(); | ||
1251 | tcg_gen_shri_i64(t, arg, 32); | ||
1252 | tcg_gen_mov_i32(ret, (TCGv_i32)t); | ||
1253 | tcg_temp_free_i64(t); | ||
1254 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_concat_i32_i64(TCGv_i64 dest, TCGv_i32 low, TCGv_i32 high) | ||
1255 | return; | ||
1256 | } | ||
1257 | |||
1258 | - tmp = tcg_temp_new_i64(); | ||
1259 | + tmp = tcg_temp_ebb_new_i64(); | ||
1260 | /* These extensions are only needed for type correctness. | ||
1261 | We may be able to do better given target specific information. */ | ||
1262 | tcg_gen_extu_i32_i64(tmp, high); | ||
1263 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_lookup_and_goto_ptr(void) | ||
1264 | } | ||
1265 | |||
1266 | plugin_gen_disable_mem_helpers(); | ||
1267 | - ptr = tcg_temp_new_ptr(); | ||
1268 | + ptr = tcg_temp_ebb_new_ptr(); | ||
1269 | gen_helper_lookup_tb_ptr(ptr, cpu_env); | ||
1270 | tcg_gen_op1i(INDEX_op_goto_ptr, tcgv_ptr_arg(ptr)); | ||
1271 | tcg_temp_free_ptr(ptr); | ||
1272 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_qemu_st_i32(TCGv_i32 val, TCGv addr, TCGArg idx, MemOp memop) | ||
1273 | oi = make_memop_idx(memop, idx); | ||
1274 | |||
1275 | if (!TCG_TARGET_HAS_MEMORY_BSWAP && (memop & MO_BSWAP)) { | ||
1276 | - swap = tcg_temp_new_i32(); | ||
1277 | + swap = tcg_temp_ebb_new_i32(); | ||
1278 | switch (memop & MO_SIZE) { | ||
1279 | case MO_16: | ||
1280 | tcg_gen_bswap16_i32(swap, val, 0); | ||
1281 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_qemu_st_i64(TCGv_i64 val, TCGv addr, TCGArg idx, MemOp memop) | ||
1282 | oi = make_memop_idx(memop, idx); | ||
1283 | |||
1284 | if (!TCG_TARGET_HAS_MEMORY_BSWAP && (memop & MO_BSWAP)) { | ||
1285 | - swap = tcg_temp_new_i64(); | ||
1286 | + swap = tcg_temp_ebb_new_i64(); | ||
1287 | switch (memop & MO_SIZE) { | ||
1288 | case MO_16: | ||
1289 | tcg_gen_bswap16_i64(swap, val, 0); | ||
1290 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_qemu_st_i128(TCGv_i128 val, TCGv addr, TCGArg idx, MemOp memop) | ||
1291 | |||
1292 | addr_p8 = tcg_temp_new(); | ||
1293 | if ((mop[0] ^ memop) & MO_BSWAP) { | ||
1294 | - TCGv_i64 t = tcg_temp_new_i64(); | ||
1295 | + TCGv_i64 t = tcg_temp_ebb_new_i64(); | ||
1296 | |||
1297 | tcg_gen_bswap64_i64(t, x); | ||
1298 | gen_ldst_i64(INDEX_op_qemu_st_i64, t, addr, mop[0], idx); | ||
1299 | @@ -XXX,XX +XXX,XX @@ static void * const table_cmpxchg[(MO_SIZE | MO_BSWAP) + 1] = { | ||
1300 | void tcg_gen_nonatomic_cmpxchg_i32(TCGv_i32 retv, TCGv addr, TCGv_i32 cmpv, | ||
1301 | TCGv_i32 newv, TCGArg idx, MemOp memop) | ||
1302 | { | ||
1303 | - TCGv_i32 t1 = tcg_temp_new_i32(); | ||
1304 | - TCGv_i32 t2 = tcg_temp_new_i32(); | ||
1305 | + TCGv_i32 t1 = tcg_temp_ebb_new_i32(); | ||
1306 | + TCGv_i32 t2 = tcg_temp_ebb_new_i32(); | ||
1307 | |||
1308 | tcg_gen_ext_i32(t2, cmpv, memop & MO_SIZE); | ||
1309 | |||
1310 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_nonatomic_cmpxchg_i64(TCGv_i64 retv, TCGv addr, TCGv_i64 cmpv, | ||
1311 | return; | ||
1312 | } | ||
1313 | |||
1314 | - t1 = tcg_temp_new_i64(); | ||
1315 | - t2 = tcg_temp_new_i64(); | ||
1316 | + t1 = tcg_temp_ebb_new_i64(); | ||
1317 | + t2 = tcg_temp_ebb_new_i64(); | ||
1318 | |||
1319 | tcg_gen_ext_i64(t2, cmpv, memop & MO_SIZE); | ||
1320 | |||
1321 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_atomic_cmpxchg_i64(TCGv_i64 retv, TCGv addr, TCGv_i64 cmpv, | ||
1322 | tcg_gen_movi_i32(TCGV_HIGH(retv), 0); | ||
1323 | } | ||
1324 | } else { | ||
1325 | - TCGv_i32 c32 = tcg_temp_new_i32(); | ||
1326 | - TCGv_i32 n32 = tcg_temp_new_i32(); | ||
1327 | - TCGv_i32 r32 = tcg_temp_new_i32(); | ||
1328 | + TCGv_i32 c32 = tcg_temp_ebb_new_i32(); | ||
1329 | + TCGv_i32 n32 = tcg_temp_ebb_new_i32(); | ||
1330 | + TCGv_i32 r32 = tcg_temp_ebb_new_i32(); | ||
1331 | |||
1332 | tcg_gen_extrl_i64_i32(c32, cmpv); | ||
1333 | tcg_gen_extrl_i64_i32(n32, newv); | ||
1334 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_nonatomic_cmpxchg_i128(TCGv_i128 retv, TCGv addr, TCGv_i128 cmpv, | ||
1335 | |||
1336 | gen(retv, cpu_env, addr, cmpv, newv, tcg_constant_i32(oi)); | ||
1337 | } else { | ||
1338 | - TCGv_i128 oldv = tcg_temp_new_i128(); | ||
1339 | - TCGv_i128 tmpv = tcg_temp_new_i128(); | ||
1340 | - TCGv_i64 t0 = tcg_temp_new_i64(); | ||
1341 | - TCGv_i64 t1 = tcg_temp_new_i64(); | ||
1342 | + TCGv_i128 oldv = tcg_temp_ebb_new_i128(); | ||
1343 | + TCGv_i128 tmpv = tcg_temp_ebb_new_i128(); | ||
1344 | + TCGv_i64 t0 = tcg_temp_ebb_new_i64(); | ||
1345 | + TCGv_i64 t1 = tcg_temp_ebb_new_i64(); | ||
1346 | TCGv_i64 z = tcg_constant_i64(0); | ||
1347 | |||
1348 | tcg_gen_qemu_ld_i128(oldv, addr, idx, memop); | ||
1349 | @@ -XXX,XX +XXX,XX @@ static void do_nonatomic_op_i32(TCGv_i32 ret, TCGv addr, TCGv_i32 val, | ||
1350 | TCGArg idx, MemOp memop, bool new_val, | ||
1351 | void (*gen)(TCGv_i32, TCGv_i32, TCGv_i32)) | ||
1352 | { | ||
1353 | - TCGv_i32 t1 = tcg_temp_new_i32(); | ||
1354 | - TCGv_i32 t2 = tcg_temp_new_i32(); | ||
1355 | + TCGv_i32 t1 = tcg_temp_ebb_new_i32(); | ||
1356 | + TCGv_i32 t2 = tcg_temp_ebb_new_i32(); | ||
1357 | |||
1358 | memop = tcg_canonicalize_memop(memop, 0, 0); | ||
1359 | |||
1360 | @@ -XXX,XX +XXX,XX @@ static void do_nonatomic_op_i64(TCGv_i64 ret, TCGv addr, TCGv_i64 val, | ||
1361 | TCGArg idx, MemOp memop, bool new_val, | ||
1362 | void (*gen)(TCGv_i64, TCGv_i64, TCGv_i64)) | ||
1363 | { | ||
1364 | - TCGv_i64 t1 = tcg_temp_new_i64(); | ||
1365 | - TCGv_i64 t2 = tcg_temp_new_i64(); | ||
1366 | + TCGv_i64 t1 = tcg_temp_ebb_new_i64(); | ||
1367 | + TCGv_i64 t2 = tcg_temp_ebb_new_i64(); | ||
1368 | |||
1369 | memop = tcg_canonicalize_memop(memop, 1, 0); | ||
1370 | |||
1371 | @@ -XXX,XX +XXX,XX @@ static void do_atomic_op_i64(TCGv_i64 ret, TCGv addr, TCGv_i64 val, | ||
1372 | tcg_gen_movi_i64(ret, 0); | ||
1373 | #endif /* CONFIG_ATOMIC64 */ | ||
1374 | } else { | ||
1375 | - TCGv_i32 v32 = tcg_temp_new_i32(); | ||
1376 | - TCGv_i32 r32 = tcg_temp_new_i32(); | ||
1377 | + TCGv_i32 v32 = tcg_temp_ebb_new_i32(); | ||
1378 | + TCGv_i32 r32 = tcg_temp_ebb_new_i32(); | ||
1379 | |||
1380 | tcg_gen_extrl_i64_i32(v32, val); | ||
1381 | do_atomic_op_i32(r32, addr, v32, idx, memop & ~MO_SIGN, table); | ||
1382 | diff --git a/tcg/tcg.c b/tcg/tcg.c | ||
1383 | index XXXXXXX..XXXXXXX 100644 | ||
1384 | --- a/tcg/tcg.c | ||
1385 | +++ b/tcg/tcg.c | ||
1386 | @@ -XXX,XX +XXX,XX @@ void tcg_gen_callN(void *func, TCGTemp *ret, int nargs, TCGTemp **args) | ||
1387 | case TCG_CALL_ARG_EXTEND_U: | ||
1388 | case TCG_CALL_ARG_EXTEND_S: | ||
1389 | { | ||
1390 | - TCGv_i64 temp = tcg_temp_new_i64(); | ||
1391 | + TCGv_i64 temp = tcg_temp_ebb_new_i64(); | ||
1392 | TCGv_i32 orig = temp_tcgv_i32(ts); | ||
1393 | |||
1394 | if (loc->kind == TCG_CALL_ARG_EXTEND_S) { | ||
92 | -- | 1395 | -- |
93 | 2.25.1 | 1396 | 2.34.1 |
94 | 1397 | ||
95 | 1398 | diff view generated by jsdifflib |
1 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | 1 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
---|---|---|---|
2 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 2 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
4 | --- | 4 | --- |
5 | tcg/optimize.c | 33 +++++++++++++++++++-------------- | 5 | tcg/tcg-op-gvec.c | 3 +-- |
6 | 1 file changed, 19 insertions(+), 14 deletions(-) | 6 | 1 file changed, 1 insertion(+), 2 deletions(-) |
7 | 7 | ||
8 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 8 | diff --git a/tcg/tcg-op-gvec.c b/tcg/tcg-op-gvec.c |
9 | index XXXXXXX..XXXXXXX 100644 | 9 | index XXXXXXX..XXXXXXX 100644 |
10 | --- a/tcg/optimize.c | 10 | --- a/tcg/tcg-op-gvec.c |
11 | +++ b/tcg/optimize.c | 11 | +++ b/tcg/tcg-op-gvec.c |
12 | @@ -XXX,XX +XXX,XX @@ static bool fold_andc(OptContext *ctx, TCGOp *op) | 12 | @@ -XXX,XX +XXX,XX @@ static void do_dup(unsigned vece, uint32_t dofs, uint32_t oprsz, |
13 | return fold_const2(ctx, op); | 13 | * stores through to memset. |
14 | } | 14 | */ |
15 | 15 | if (oprsz == maxsz && vece == MO_8) { | |
16 | +static bool fold_brcond(OptContext *ctx, TCGOp *op) | 16 | - TCGv_ptr t_size = tcg_const_ptr(oprsz); |
17 | +{ | 17 | + TCGv_ptr t_size = tcg_constant_ptr(oprsz); |
18 | + TCGCond cond = op->args[2]; | 18 | TCGv_i32 t_val; |
19 | + int i = do_constant_folding_cond(op->opc, op->args[0], op->args[1], cond); | 19 | |
20 | + | 20 | if (in_32) { |
21 | + if (i == 0) { | 21 | @@ -XXX,XX +XXX,XX @@ static void do_dup(unsigned vece, uint32_t dofs, uint32_t oprsz, |
22 | + tcg_op_remove(ctx->tcg, op); | 22 | if (in_64) { |
23 | + return true; | 23 | tcg_temp_free_i32(t_val); |
24 | + } | 24 | } |
25 | + if (i > 0) { | 25 | - tcg_temp_free_ptr(t_size); |
26 | + op->opc = INDEX_op_br; | 26 | tcg_temp_free_ptr(t_ptr); |
27 | + op->args[0] = op->args[3]; | 27 | return; |
28 | + } | 28 | } |
29 | + return false; | ||
30 | +} | ||
31 | + | ||
32 | static bool fold_brcond2(OptContext *ctx, TCGOp *op) | ||
33 | { | ||
34 | TCGCond cond = op->args[4]; | ||
35 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
36 | } | ||
37 | break; | ||
38 | |||
39 | - CASE_OP_32_64(brcond): | ||
40 | - i = do_constant_folding_cond(opc, op->args[0], | ||
41 | - op->args[1], op->args[2]); | ||
42 | - if (i == 0) { | ||
43 | - tcg_op_remove(s, op); | ||
44 | - continue; | ||
45 | - } else if (i > 0) { | ||
46 | - memset(&ctx.temps_used, 0, sizeof(ctx.temps_used)); | ||
47 | - op->opc = opc = INDEX_op_br; | ||
48 | - op->args[0] = op->args[3]; | ||
49 | - break; | ||
50 | - } | ||
51 | - break; | ||
52 | - | ||
53 | CASE_OP_32_64(movcond): | ||
54 | i = do_constant_folding_cond(opc, op->args[1], | ||
55 | op->args[2], op->args[5]); | ||
56 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
57 | CASE_OP_32_64_VEC(andc): | ||
58 | done = fold_andc(&ctx, op); | ||
59 | break; | ||
60 | + CASE_OP_32_64(brcond): | ||
61 | + done = fold_brcond(&ctx, op); | ||
62 | + break; | ||
63 | case INDEX_op_brcond2_i32: | ||
64 | done = fold_brcond2(&ctx, op); | ||
65 | break; | ||
66 | -- | 29 | -- |
67 | 2.25.1 | 30 | 2.34.1 |
68 | 31 | ||
69 | 32 | diff view generated by jsdifflib |
1 | Reduce some code duplication by folding the NE and EQ cases. | 1 | All of these uses have quite local scope. |
---|---|---|---|
2 | Avoid tcg_const_*, because we haven't added a corresponding | ||
3 | interface for TEMP_EBB. Use explicit tcg_gen_movi_* instead. | ||
2 | 4 | ||
3 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | 5 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
5 | --- | 7 | --- |
6 | tcg/optimize.c | 159 +++++++++++++++++++++++++------------------------ | 8 | accel/tcg/plugin-gen.c | 24 ++++++++++++++---------- |
7 | 1 file changed, 81 insertions(+), 78 deletions(-) | 9 | 1 file changed, 14 insertions(+), 10 deletions(-) |
8 | 10 | ||
9 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 11 | diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c |
10 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
11 | --- a/tcg/optimize.c | 13 | --- a/accel/tcg/plugin-gen.c |
12 | +++ b/tcg/optimize.c | 14 | +++ b/accel/tcg/plugin-gen.c |
13 | @@ -XXX,XX +XXX,XX @@ static bool fold_andc(OptContext *ctx, TCGOp *op) | 15 | @@ -XXX,XX +XXX,XX @@ void HELPER(plugin_vcpu_mem_cb)(unsigned int vcpu_index, |
14 | return fold_const2(ctx, op); | 16 | |
15 | } | 17 | static void do_gen_mem_cb(TCGv vaddr, uint32_t info) |
16 | |||
17 | +static bool fold_brcond2(OptContext *ctx, TCGOp *op) | ||
18 | +{ | ||
19 | + TCGCond cond = op->args[4]; | ||
20 | + int i = do_constant_folding_cond2(&op->args[0], &op->args[2], cond); | ||
21 | + TCGArg label = op->args[5]; | ||
22 | + int inv = 0; | ||
23 | + | ||
24 | + if (i >= 0) { | ||
25 | + goto do_brcond_const; | ||
26 | + } | ||
27 | + | ||
28 | + switch (cond) { | ||
29 | + case TCG_COND_LT: | ||
30 | + case TCG_COND_GE: | ||
31 | + /* | ||
32 | + * Simplify LT/GE comparisons vs zero to a single compare | ||
33 | + * vs the high word of the input. | ||
34 | + */ | ||
35 | + if (arg_is_const(op->args[2]) && arg_info(op->args[2])->val == 0 && | ||
36 | + arg_is_const(op->args[3]) && arg_info(op->args[3])->val == 0) { | ||
37 | + goto do_brcond_high; | ||
38 | + } | ||
39 | + break; | ||
40 | + | ||
41 | + case TCG_COND_NE: | ||
42 | + inv = 1; | ||
43 | + QEMU_FALLTHROUGH; | ||
44 | + case TCG_COND_EQ: | ||
45 | + /* | ||
46 | + * Simplify EQ/NE comparisons where one of the pairs | ||
47 | + * can be simplified. | ||
48 | + */ | ||
49 | + i = do_constant_folding_cond(INDEX_op_brcond_i32, op->args[0], | ||
50 | + op->args[2], cond); | ||
51 | + switch (i ^ inv) { | ||
52 | + case 0: | ||
53 | + goto do_brcond_const; | ||
54 | + case 1: | ||
55 | + goto do_brcond_high; | ||
56 | + } | ||
57 | + | ||
58 | + i = do_constant_folding_cond(INDEX_op_brcond_i32, op->args[1], | ||
59 | + op->args[3], cond); | ||
60 | + switch (i ^ inv) { | ||
61 | + case 0: | ||
62 | + goto do_brcond_const; | ||
63 | + case 1: | ||
64 | + op->opc = INDEX_op_brcond_i32; | ||
65 | + op->args[1] = op->args[2]; | ||
66 | + op->args[2] = cond; | ||
67 | + op->args[3] = label; | ||
68 | + break; | ||
69 | + } | ||
70 | + break; | ||
71 | + | ||
72 | + default: | ||
73 | + break; | ||
74 | + | ||
75 | + do_brcond_high: | ||
76 | + op->opc = INDEX_op_brcond_i32; | ||
77 | + op->args[0] = op->args[1]; | ||
78 | + op->args[1] = op->args[3]; | ||
79 | + op->args[2] = cond; | ||
80 | + op->args[3] = label; | ||
81 | + break; | ||
82 | + | ||
83 | + do_brcond_const: | ||
84 | + if (i == 0) { | ||
85 | + tcg_op_remove(ctx->tcg, op); | ||
86 | + return true; | ||
87 | + } | ||
88 | + op->opc = INDEX_op_br; | ||
89 | + op->args[0] = label; | ||
90 | + break; | ||
91 | + } | ||
92 | + return false; | ||
93 | +} | ||
94 | + | ||
95 | static bool fold_call(OptContext *ctx, TCGOp *op) | ||
96 | { | 18 | { |
97 | TCGContext *s = ctx->tcg; | 19 | - TCGv_i32 cpu_index = tcg_temp_new_i32(); |
98 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | 20 | - TCGv_i32 meminfo = tcg_const_i32(info); |
99 | } | 21 | - TCGv_i64 vaddr64 = tcg_temp_new_i64(); |
100 | break; | 22 | - TCGv_ptr udata = tcg_const_ptr(NULL); |
101 | 23 | + TCGv_i32 cpu_index = tcg_temp_ebb_new_i32(); | |
102 | - case INDEX_op_brcond2_i32: | 24 | + TCGv_i32 meminfo = tcg_temp_ebb_new_i32(); |
103 | - i = do_constant_folding_cond2(&op->args[0], &op->args[2], | 25 | + TCGv_i64 vaddr64 = tcg_temp_ebb_new_i64(); |
104 | - op->args[4]); | 26 | + TCGv_ptr udata = tcg_temp_ebb_new_ptr(); |
105 | - if (i == 0) { | 27 | |
106 | - do_brcond_false: | 28 | + tcg_gen_movi_i32(meminfo, info); |
107 | - tcg_op_remove(s, op); | 29 | + tcg_gen_movi_ptr(udata, 0); |
108 | - continue; | 30 | tcg_gen_ld_i32(cpu_index, cpu_env, |
109 | - } | 31 | -offsetof(ArchCPU, env) + offsetof(CPUState, cpu_index)); |
110 | - if (i > 0) { | 32 | tcg_gen_extu_tl_i64(vaddr64, vaddr); |
111 | - do_brcond_true: | 33 | @@ -XXX,XX +XXX,XX @@ static void do_gen_mem_cb(TCGv vaddr, uint32_t info) |
112 | - op->opc = opc = INDEX_op_br; | 34 | |
113 | - op->args[0] = op->args[5]; | 35 | static void gen_empty_udata_cb(void) |
114 | - break; | 36 | { |
115 | - } | 37 | - TCGv_i32 cpu_index = tcg_temp_new_i32(); |
116 | - if ((op->args[4] == TCG_COND_LT || op->args[4] == TCG_COND_GE) | 38 | - TCGv_ptr udata = tcg_const_ptr(NULL); /* will be overwritten later */ |
117 | - && arg_is_const(op->args[2]) | 39 | + TCGv_i32 cpu_index = tcg_temp_ebb_new_i32(); |
118 | - && arg_info(op->args[2])->val == 0 | 40 | + TCGv_ptr udata = tcg_temp_ebb_new_ptr(); |
119 | - && arg_is_const(op->args[3]) | 41 | |
120 | - && arg_info(op->args[3])->val == 0) { | 42 | + tcg_gen_movi_ptr(udata, 0); |
121 | - /* Simplify LT/GE comparisons vs zero to a single compare | 43 | tcg_gen_ld_i32(cpu_index, cpu_env, |
122 | - vs the high word of the input. */ | 44 | -offsetof(ArchCPU, env) + offsetof(CPUState, cpu_index)); |
123 | - do_brcond_high: | 45 | gen_helper_plugin_vcpu_udata_cb(cpu_index, udata); |
124 | - op->opc = opc = INDEX_op_brcond_i32; | 46 | @@ -XXX,XX +XXX,XX @@ static void gen_empty_udata_cb(void) |
125 | - op->args[0] = op->args[1]; | 47 | */ |
126 | - op->args[1] = op->args[3]; | 48 | static void gen_empty_inline_cb(void) |
127 | - op->args[2] = op->args[4]; | 49 | { |
128 | - op->args[3] = op->args[5]; | 50 | - TCGv_i64 val = tcg_temp_new_i64(); |
129 | - break; | 51 | - TCGv_ptr ptr = tcg_const_ptr(NULL); /* overwritten later */ |
130 | - } | 52 | + TCGv_i64 val = tcg_temp_ebb_new_i64(); |
131 | - if (op->args[4] == TCG_COND_EQ) { | 53 | + TCGv_ptr ptr = tcg_temp_ebb_new_ptr(); |
132 | - /* Simplify EQ comparisons where one of the pairs | 54 | |
133 | - can be simplified. */ | 55 | + tcg_gen_movi_ptr(ptr, 0); |
134 | - i = do_constant_folding_cond(INDEX_op_brcond_i32, | 56 | tcg_gen_ld_i64(val, ptr, 0); |
135 | - op->args[0], op->args[2], | 57 | /* pass an immediate != 0 so that it doesn't get optimized away */ |
136 | - TCG_COND_EQ); | 58 | tcg_gen_addi_i64(val, val, 0xdeadface); |
137 | - if (i == 0) { | 59 | @@ -XXX,XX +XXX,XX @@ static void gen_empty_mem_cb(TCGv addr, uint32_t info) |
138 | - goto do_brcond_false; | 60 | */ |
139 | - } else if (i > 0) { | 61 | static void gen_empty_mem_helper(void) |
140 | - goto do_brcond_high; | 62 | { |
141 | - } | 63 | - TCGv_ptr ptr; |
142 | - i = do_constant_folding_cond(INDEX_op_brcond_i32, | 64 | + TCGv_ptr ptr = tcg_temp_ebb_new_ptr(); |
143 | - op->args[1], op->args[3], | 65 | |
144 | - TCG_COND_EQ); | 66 | - ptr = tcg_const_ptr(NULL); |
145 | - if (i == 0) { | 67 | + tcg_gen_movi_ptr(ptr, 0); |
146 | - goto do_brcond_false; | 68 | tcg_gen_st_ptr(ptr, cpu_env, offsetof(CPUState, plugin_mem_cbs) - |
147 | - } else if (i < 0) { | 69 | offsetof(ArchCPU, env)); |
148 | - break; | 70 | tcg_temp_free_ptr(ptr); |
149 | - } | ||
150 | - do_brcond_low: | ||
151 | - memset(&ctx.temps_used, 0, sizeof(ctx.temps_used)); | ||
152 | - op->opc = INDEX_op_brcond_i32; | ||
153 | - op->args[1] = op->args[2]; | ||
154 | - op->args[2] = op->args[4]; | ||
155 | - op->args[3] = op->args[5]; | ||
156 | - break; | ||
157 | - } | ||
158 | - if (op->args[4] == TCG_COND_NE) { | ||
159 | - /* Simplify NE comparisons where one of the pairs | ||
160 | - can be simplified. */ | ||
161 | - i = do_constant_folding_cond(INDEX_op_brcond_i32, | ||
162 | - op->args[0], op->args[2], | ||
163 | - TCG_COND_NE); | ||
164 | - if (i == 0) { | ||
165 | - goto do_brcond_high; | ||
166 | - } else if (i > 0) { | ||
167 | - goto do_brcond_true; | ||
168 | - } | ||
169 | - i = do_constant_folding_cond(INDEX_op_brcond_i32, | ||
170 | - op->args[1], op->args[3], | ||
171 | - TCG_COND_NE); | ||
172 | - if (i == 0) { | ||
173 | - goto do_brcond_low; | ||
174 | - } else if (i > 0) { | ||
175 | - goto do_brcond_true; | ||
176 | - } | ||
177 | - } | ||
178 | - break; | ||
179 | - | ||
180 | default: | ||
181 | break; | ||
182 | |||
183 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
184 | CASE_OP_32_64_VEC(andc): | ||
185 | done = fold_andc(&ctx, op); | ||
186 | break; | ||
187 | + case INDEX_op_brcond2_i32: | ||
188 | + done = fold_brcond2(&ctx, op); | ||
189 | + break; | ||
190 | CASE_OP_32_64(ctpop): | ||
191 | done = fold_ctpop(&ctx, op); | ||
192 | break; | ||
193 | -- | 71 | -- |
194 | 2.25.1 | 72 | 2.34.1 |
195 | 73 | ||
196 | 74 | diff view generated by jsdifflib |
1 | Provide what will become a larger context for splitting | 1 | Here we are creating a temp whose value needs to be replaced, |
---|---|---|---|
2 | the very large tcg_optimize function. | 2 | but always storing NULL into CPUState.plugin_mem_cbs. |
3 | Use tcg_constant_ptr(0) explicitly. | ||
3 | 4 | ||
4 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 5 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
5 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | ||
6 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
8 | --- | 7 | --- |
9 | tcg/optimize.c | 77 ++++++++++++++++++++++++++------------------------ | 8 | accel/tcg/plugin-gen.c | 8 ++------ |
10 | 1 file changed, 40 insertions(+), 37 deletions(-) | 9 | 1 file changed, 2 insertions(+), 6 deletions(-) |
11 | 10 | ||
12 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 11 | diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c |
13 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/tcg/optimize.c | 13 | --- a/accel/tcg/plugin-gen.c |
15 | +++ b/tcg/optimize.c | 14 | +++ b/accel/tcg/plugin-gen.c |
16 | @@ -XXX,XX +XXX,XX @@ typedef struct TempOptInfo { | 15 | @@ -XXX,XX +XXX,XX @@ static void inject_mem_disable_helper(struct qemu_plugin_insn *plugin_insn, |
17 | uint64_t z_mask; /* mask bit is 0 if and only if value bit is 0 */ | 16 | /* called before finishing a TB with exit_tb, goto_tb or goto_ptr */ |
18 | } TempOptInfo; | 17 | void plugin_gen_disable_mem_helpers(void) |
19 | |||
20 | +typedef struct OptContext { | ||
21 | + TCGTempSet temps_used; | ||
22 | +} OptContext; | ||
23 | + | ||
24 | static inline TempOptInfo *ts_info(TCGTemp *ts) | ||
25 | { | 18 | { |
26 | return ts->state_ptr; | 19 | - TCGv_ptr ptr; |
27 | @@ -XXX,XX +XXX,XX @@ static void reset_temp(TCGArg arg) | 20 | - |
28 | } | 21 | /* |
29 | 22 | * We could emit the clearing unconditionally and be done. However, this can | |
30 | /* Initialize and activate a temporary. */ | 23 | * be wasteful if for instance plugins don't track memory accesses, or if |
31 | -static void init_ts_info(TCGTempSet *temps_used, TCGTemp *ts) | 24 | @@ -XXX,XX +XXX,XX @@ void plugin_gen_disable_mem_helpers(void) |
32 | +static void init_ts_info(OptContext *ctx, TCGTemp *ts) | 25 | if (!tcg_ctx->plugin_tb->mem_helper) { |
33 | { | ||
34 | size_t idx = temp_idx(ts); | ||
35 | TempOptInfo *ti; | ||
36 | |||
37 | - if (test_bit(idx, temps_used->l)) { | ||
38 | + if (test_bit(idx, ctx->temps_used.l)) { | ||
39 | return; | 26 | return; |
40 | } | 27 | } |
41 | - set_bit(idx, temps_used->l); | 28 | - ptr = tcg_const_ptr(NULL); |
42 | + set_bit(idx, ctx->temps_used.l); | 29 | - tcg_gen_st_ptr(ptr, cpu_env, offsetof(CPUState, plugin_mem_cbs) - |
43 | 30 | - offsetof(ArchCPU, env)); | |
44 | ti = ts->state_ptr; | 31 | - tcg_temp_free_ptr(ptr); |
45 | if (ti == NULL) { | 32 | + tcg_gen_st_ptr(tcg_constant_ptr(NULL), cpu_env, |
46 | @@ -XXX,XX +XXX,XX @@ static void init_ts_info(TCGTempSet *temps_used, TCGTemp *ts) | 33 | + offsetof(CPUState, plugin_mem_cbs) - offsetof(ArchCPU, env)); |
47 | } | ||
48 | } | 34 | } |
49 | 35 | ||
50 | -static void init_arg_info(TCGTempSet *temps_used, TCGArg arg) | 36 | static void plugin_gen_tb_udata(const struct qemu_plugin_tb *ptb, |
51 | +static void init_arg_info(OptContext *ctx, TCGArg arg) | ||
52 | { | ||
53 | - init_ts_info(temps_used, arg_temp(arg)); | ||
54 | + init_ts_info(ctx, arg_temp(arg)); | ||
55 | } | ||
56 | |||
57 | static TCGTemp *find_better_copy(TCGContext *s, TCGTemp *ts) | ||
58 | @@ -XXX,XX +XXX,XX @@ static void tcg_opt_gen_mov(TCGContext *s, TCGOp *op, TCGArg dst, TCGArg src) | ||
59 | } | ||
60 | } | ||
61 | |||
62 | -static void tcg_opt_gen_movi(TCGContext *s, TCGTempSet *temps_used, | ||
63 | +static void tcg_opt_gen_movi(TCGContext *s, OptContext *ctx, | ||
64 | TCGOp *op, TCGArg dst, uint64_t val) | ||
65 | { | ||
66 | const TCGOpDef *def = &tcg_op_defs[op->opc]; | ||
67 | @@ -XXX,XX +XXX,XX @@ static void tcg_opt_gen_movi(TCGContext *s, TCGTempSet *temps_used, | ||
68 | |||
69 | /* Convert movi to mov with constant temp. */ | ||
70 | tv = tcg_constant_internal(type, val); | ||
71 | - init_ts_info(temps_used, tv); | ||
72 | + init_ts_info(ctx, tv); | ||
73 | tcg_opt_gen_mov(s, op, dst, temp_arg(tv)); | ||
74 | } | ||
75 | |||
76 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
77 | { | ||
78 | int nb_temps, nb_globals, i; | ||
79 | TCGOp *op, *op_next, *prev_mb = NULL; | ||
80 | - TCGTempSet temps_used; | ||
81 | + OptContext ctx = {}; | ||
82 | |||
83 | /* Array VALS has an element for each temp. | ||
84 | If this temp holds a constant then its value is kept in VALS' element. | ||
85 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
86 | nb_temps = s->nb_temps; | ||
87 | nb_globals = s->nb_globals; | ||
88 | |||
89 | - memset(&temps_used, 0, sizeof(temps_used)); | ||
90 | for (i = 0; i < nb_temps; ++i) { | ||
91 | s->temps[i].state_ptr = NULL; | ||
92 | } | ||
93 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
94 | for (i = 0; i < nb_oargs + nb_iargs; i++) { | ||
95 | TCGTemp *ts = arg_temp(op->args[i]); | ||
96 | if (ts) { | ||
97 | - init_ts_info(&temps_used, ts); | ||
98 | + init_ts_info(&ctx, ts); | ||
99 | } | ||
100 | } | ||
101 | } else { | ||
102 | nb_oargs = def->nb_oargs; | ||
103 | nb_iargs = def->nb_iargs; | ||
104 | for (i = 0; i < nb_oargs + nb_iargs; i++) { | ||
105 | - init_arg_info(&temps_used, op->args[i]); | ||
106 | + init_arg_info(&ctx, op->args[i]); | ||
107 | } | ||
108 | } | ||
109 | |||
110 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
111 | CASE_OP_32_64(rotr): | ||
112 | if (arg_is_const(op->args[1]) | ||
113 | && arg_info(op->args[1])->val == 0) { | ||
114 | - tcg_opt_gen_movi(s, &temps_used, op, op->args[0], 0); | ||
115 | + tcg_opt_gen_movi(s, &ctx, op, op->args[0], 0); | ||
116 | continue; | ||
117 | } | ||
118 | break; | ||
119 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
120 | |||
121 | if (partmask == 0) { | ||
122 | tcg_debug_assert(nb_oargs == 1); | ||
123 | - tcg_opt_gen_movi(s, &temps_used, op, op->args[0], 0); | ||
124 | + tcg_opt_gen_movi(s, &ctx, op, op->args[0], 0); | ||
125 | continue; | ||
126 | } | ||
127 | if (affected == 0) { | ||
128 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
129 | CASE_OP_32_64(mulsh): | ||
130 | if (arg_is_const(op->args[2]) | ||
131 | && arg_info(op->args[2])->val == 0) { | ||
132 | - tcg_opt_gen_movi(s, &temps_used, op, op->args[0], 0); | ||
133 | + tcg_opt_gen_movi(s, &ctx, op, op->args[0], 0); | ||
134 | continue; | ||
135 | } | ||
136 | break; | ||
137 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
138 | CASE_OP_32_64_VEC(sub): | ||
139 | CASE_OP_32_64_VEC(xor): | ||
140 | if (args_are_copies(op->args[1], op->args[2])) { | ||
141 | - tcg_opt_gen_movi(s, &temps_used, op, op->args[0], 0); | ||
142 | + tcg_opt_gen_movi(s, &ctx, op, op->args[0], 0); | ||
143 | continue; | ||
144 | } | ||
145 | break; | ||
146 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
147 | if (arg_is_const(op->args[1])) { | ||
148 | tmp = arg_info(op->args[1])->val; | ||
149 | tmp = dup_const(TCGOP_VECE(op), tmp); | ||
150 | - tcg_opt_gen_movi(s, &temps_used, op, op->args[0], tmp); | ||
151 | + tcg_opt_gen_movi(s, &ctx, op, op->args[0], tmp); | ||
152 | break; | ||
153 | } | ||
154 | goto do_default; | ||
155 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
156 | case INDEX_op_dup2_vec: | ||
157 | assert(TCG_TARGET_REG_BITS == 32); | ||
158 | if (arg_is_const(op->args[1]) && arg_is_const(op->args[2])) { | ||
159 | - tcg_opt_gen_movi(s, &temps_used, op, op->args[0], | ||
160 | + tcg_opt_gen_movi(s, &ctx, op, op->args[0], | ||
161 | deposit64(arg_info(op->args[1])->val, 32, 32, | ||
162 | arg_info(op->args[2])->val)); | ||
163 | break; | ||
164 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
165 | case INDEX_op_extrh_i64_i32: | ||
166 | if (arg_is_const(op->args[1])) { | ||
167 | tmp = do_constant_folding(opc, arg_info(op->args[1])->val, 0); | ||
168 | - tcg_opt_gen_movi(s, &temps_used, op, op->args[0], tmp); | ||
169 | + tcg_opt_gen_movi(s, &ctx, op, op->args[0], tmp); | ||
170 | break; | ||
171 | } | ||
172 | goto do_default; | ||
173 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
174 | if (arg_is_const(op->args[1])) { | ||
175 | tmp = do_constant_folding(opc, arg_info(op->args[1])->val, | ||
176 | op->args[2]); | ||
177 | - tcg_opt_gen_movi(s, &temps_used, op, op->args[0], tmp); | ||
178 | + tcg_opt_gen_movi(s, &ctx, op, op->args[0], tmp); | ||
179 | break; | ||
180 | } | ||
181 | goto do_default; | ||
182 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
183 | if (arg_is_const(op->args[1]) && arg_is_const(op->args[2])) { | ||
184 | tmp = do_constant_folding(opc, arg_info(op->args[1])->val, | ||
185 | arg_info(op->args[2])->val); | ||
186 | - tcg_opt_gen_movi(s, &temps_used, op, op->args[0], tmp); | ||
187 | + tcg_opt_gen_movi(s, &ctx, op, op->args[0], tmp); | ||
188 | break; | ||
189 | } | ||
190 | goto do_default; | ||
191 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
192 | TCGArg v = arg_info(op->args[1])->val; | ||
193 | if (v != 0) { | ||
194 | tmp = do_constant_folding(opc, v, 0); | ||
195 | - tcg_opt_gen_movi(s, &temps_used, op, op->args[0], tmp); | ||
196 | + tcg_opt_gen_movi(s, &ctx, op, op->args[0], tmp); | ||
197 | } else { | ||
198 | tcg_opt_gen_mov(s, op, op->args[0], op->args[2]); | ||
199 | } | ||
200 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
201 | tmp = deposit64(arg_info(op->args[1])->val, | ||
202 | op->args[3], op->args[4], | ||
203 | arg_info(op->args[2])->val); | ||
204 | - tcg_opt_gen_movi(s, &temps_used, op, op->args[0], tmp); | ||
205 | + tcg_opt_gen_movi(s, &ctx, op, op->args[0], tmp); | ||
206 | break; | ||
207 | } | ||
208 | goto do_default; | ||
209 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
210 | if (arg_is_const(op->args[1])) { | ||
211 | tmp = extract64(arg_info(op->args[1])->val, | ||
212 | op->args[2], op->args[3]); | ||
213 | - tcg_opt_gen_movi(s, &temps_used, op, op->args[0], tmp); | ||
214 | + tcg_opt_gen_movi(s, &ctx, op, op->args[0], tmp); | ||
215 | break; | ||
216 | } | ||
217 | goto do_default; | ||
218 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
219 | if (arg_is_const(op->args[1])) { | ||
220 | tmp = sextract64(arg_info(op->args[1])->val, | ||
221 | op->args[2], op->args[3]); | ||
222 | - tcg_opt_gen_movi(s, &temps_used, op, op->args[0], tmp); | ||
223 | + tcg_opt_gen_movi(s, &ctx, op, op->args[0], tmp); | ||
224 | break; | ||
225 | } | ||
226 | goto do_default; | ||
227 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
228 | tmp = (int32_t)(((uint32_t)v1 >> shr) | | ||
229 | ((uint32_t)v2 << (32 - shr))); | ||
230 | } | ||
231 | - tcg_opt_gen_movi(s, &temps_used, op, op->args[0], tmp); | ||
232 | + tcg_opt_gen_movi(s, &ctx, op, op->args[0], tmp); | ||
233 | break; | ||
234 | } | ||
235 | goto do_default; | ||
236 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
237 | tmp = do_constant_folding_cond(opc, op->args[1], | ||
238 | op->args[2], op->args[3]); | ||
239 | if (tmp != 2) { | ||
240 | - tcg_opt_gen_movi(s, &temps_used, op, op->args[0], tmp); | ||
241 | + tcg_opt_gen_movi(s, &ctx, op, op->args[0], tmp); | ||
242 | break; | ||
243 | } | ||
244 | goto do_default; | ||
245 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
246 | op->args[1], op->args[2]); | ||
247 | if (tmp != 2) { | ||
248 | if (tmp) { | ||
249 | - memset(&temps_used, 0, sizeof(temps_used)); | ||
250 | + memset(&ctx.temps_used, 0, sizeof(ctx.temps_used)); | ||
251 | op->opc = INDEX_op_br; | ||
252 | op->args[0] = op->args[3]; | ||
253 | } else { | ||
254 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
255 | |||
256 | rl = op->args[0]; | ||
257 | rh = op->args[1]; | ||
258 | - tcg_opt_gen_movi(s, &temps_used, op, rl, (int32_t)a); | ||
259 | - tcg_opt_gen_movi(s, &temps_used, op2, rh, (int32_t)(a >> 32)); | ||
260 | + tcg_opt_gen_movi(s, &ctx, op, rl, (int32_t)a); | ||
261 | + tcg_opt_gen_movi(s, &ctx, op2, rh, (int32_t)(a >> 32)); | ||
262 | break; | ||
263 | } | ||
264 | goto do_default; | ||
265 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
266 | |||
267 | rl = op->args[0]; | ||
268 | rh = op->args[1]; | ||
269 | - tcg_opt_gen_movi(s, &temps_used, op, rl, (int32_t)r); | ||
270 | - tcg_opt_gen_movi(s, &temps_used, op2, rh, (int32_t)(r >> 32)); | ||
271 | + tcg_opt_gen_movi(s, &ctx, op, rl, (int32_t)r); | ||
272 | + tcg_opt_gen_movi(s, &ctx, op2, rh, (int32_t)(r >> 32)); | ||
273 | break; | ||
274 | } | ||
275 | goto do_default; | ||
276 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
277 | if (tmp != 2) { | ||
278 | if (tmp) { | ||
279 | do_brcond_true: | ||
280 | - memset(&temps_used, 0, sizeof(temps_used)); | ||
281 | + memset(&ctx.temps_used, 0, sizeof(ctx.temps_used)); | ||
282 | op->opc = INDEX_op_br; | ||
283 | op->args[0] = op->args[5]; | ||
284 | } else { | ||
285 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
286 | /* Simplify LT/GE comparisons vs zero to a single compare | ||
287 | vs the high word of the input. */ | ||
288 | do_brcond_high: | ||
289 | - memset(&temps_used, 0, sizeof(temps_used)); | ||
290 | + memset(&ctx.temps_used, 0, sizeof(ctx.temps_used)); | ||
291 | op->opc = INDEX_op_brcond_i32; | ||
292 | op->args[0] = op->args[1]; | ||
293 | op->args[1] = op->args[3]; | ||
294 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
295 | goto do_default; | ||
296 | } | ||
297 | do_brcond_low: | ||
298 | - memset(&temps_used, 0, sizeof(temps_used)); | ||
299 | + memset(&ctx.temps_used, 0, sizeof(ctx.temps_used)); | ||
300 | op->opc = INDEX_op_brcond_i32; | ||
301 | op->args[1] = op->args[2]; | ||
302 | op->args[2] = op->args[4]; | ||
303 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
304 | op->args[5]); | ||
305 | if (tmp != 2) { | ||
306 | do_setcond_const: | ||
307 | - tcg_opt_gen_movi(s, &temps_used, op, op->args[0], tmp); | ||
308 | + tcg_opt_gen_movi(s, &ctx, op, op->args[0], tmp); | ||
309 | } else if ((op->args[5] == TCG_COND_LT | ||
310 | || op->args[5] == TCG_COND_GE) | ||
311 | && arg_is_const(op->args[3]) | ||
312 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
313 | if (!(tcg_call_flags(op) | ||
314 | & (TCG_CALL_NO_READ_GLOBALS | TCG_CALL_NO_WRITE_GLOBALS))) { | ||
315 | for (i = 0; i < nb_globals; i++) { | ||
316 | - if (test_bit(i, temps_used.l)) { | ||
317 | + if (test_bit(i, ctx.temps_used.l)) { | ||
318 | reset_ts(&s->temps[i]); | ||
319 | } | ||
320 | } | ||
321 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
322 | block, otherwise we only trash the output args. "z_mask" is | ||
323 | the non-zero bits mask for the first output arg. */ | ||
324 | if (def->flags & TCG_OPF_BB_END) { | ||
325 | - memset(&temps_used, 0, sizeof(temps_used)); | ||
326 | + memset(&ctx.temps_used, 0, sizeof(ctx.temps_used)); | ||
327 | } else { | ||
328 | do_reset_output: | ||
329 | for (i = 0; i < nb_oargs; i++) { | ||
330 | -- | 37 | -- |
331 | 2.25.1 | 38 | 2.34.1 |
332 | 39 | ||
333 | 40 | diff view generated by jsdifflib |
1 | Split out the conditional conversion from a more complex logical | 1 | Reusing TEMP_TB interferes with detecting whether the |
---|---|---|---|
2 | operation to a simple NOT. Create a couple more helpers to make | 2 | temp can be adjusted to TEMP_EBB. |
3 | this easy for the outer-most logical operations. | ||
4 | 3 | ||
5 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | 4 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> |
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
7 | --- | 6 | --- |
8 | tcg/optimize.c | 158 +++++++++++++++++++++++++++---------------------- | 7 | include/tcg/tcg.h | 2 +- |
9 | 1 file changed, 86 insertions(+), 72 deletions(-) | 8 | tcg/tcg.c | 101 ++++++++++++++++++++++++---------------------- |
9 | 2 files changed, 53 insertions(+), 50 deletions(-) | ||
10 | 10 | ||
11 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 11 | diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h |
12 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/tcg/optimize.c | 13 | --- a/include/tcg/tcg.h |
14 | +++ b/tcg/optimize.c | 14 | +++ b/include/tcg/tcg.h |
15 | @@ -XXX,XX +XXX,XX @@ static bool fold_const2(OptContext *ctx, TCGOp *op) | 15 | @@ -XXX,XX +XXX,XX @@ struct TCGContext { |
16 | return false; | 16 | #endif |
17 | } | 17 | |
18 | 18 | GHashTable *const_table[TCG_TYPE_COUNT]; | |
19 | +/* | 19 | - TCGTempSet free_temps[TCG_TYPE_COUNT * 2]; |
20 | + * Convert @op to NOT, if NOT is supported by the host. | 20 | + TCGTempSet free_temps[TCG_TYPE_COUNT]; |
21 | + * Return true f the conversion is successful, which will still | 21 | TCGTemp temps[TCG_MAX_TEMPS]; /* globals first, temps after */ |
22 | + * indicate that the processing is complete. | 22 | |
23 | + */ | 23 | QTAILQ_HEAD(, TCGOp) ops, free_ops; |
24 | +static bool fold_not(OptContext *ctx, TCGOp *op); | 24 | diff --git a/tcg/tcg.c b/tcg/tcg.c |
25 | +static bool fold_to_not(OptContext *ctx, TCGOp *op, int idx) | 25 | index XXXXXXX..XXXXXXX 100644 |
26 | +{ | 26 | --- a/tcg/tcg.c |
27 | + TCGOpcode not_op; | 27 | +++ b/tcg/tcg.c |
28 | + bool have_not; | 28 | @@ -XXX,XX +XXX,XX @@ TCGTemp *tcg_global_mem_new_internal(TCGType type, TCGv_ptr base, |
29 | + | 29 | TCGTemp *tcg_temp_new_internal(TCGType type, TCGTempKind kind) |
30 | + switch (ctx->type) { | 30 | { |
31 | TCGContext *s = tcg_ctx; | ||
32 | - bool temp_local = kind == TEMP_TB; | ||
33 | TCGTemp *ts; | ||
34 | - int idx, k; | ||
35 | + int n; | ||
36 | |||
37 | - k = type + (temp_local ? TCG_TYPE_COUNT : 0); | ||
38 | - idx = find_first_bit(s->free_temps[k].l, TCG_MAX_TEMPS); | ||
39 | - if (idx < TCG_MAX_TEMPS) { | ||
40 | - /* There is already an available temp with the right type. */ | ||
41 | - clear_bit(idx, s->free_temps[k].l); | ||
42 | + if (kind == TEMP_EBB) { | ||
43 | + int idx = find_first_bit(s->free_temps[type].l, TCG_MAX_TEMPS); | ||
44 | |||
45 | - ts = &s->temps[idx]; | ||
46 | - ts->temp_allocated = 1; | ||
47 | - tcg_debug_assert(ts->base_type == type); | ||
48 | - tcg_debug_assert(ts->kind == kind); | ||
49 | - } else { | ||
50 | - int i, n; | ||
51 | + if (idx < TCG_MAX_TEMPS) { | ||
52 | + /* There is already an available temp with the right type. */ | ||
53 | + clear_bit(idx, s->free_temps[type].l); | ||
54 | |||
55 | - switch (type) { | ||
56 | - case TCG_TYPE_I32: | ||
57 | - case TCG_TYPE_V64: | ||
58 | - case TCG_TYPE_V128: | ||
59 | - case TCG_TYPE_V256: | ||
60 | - n = 1; | ||
61 | - break; | ||
62 | - case TCG_TYPE_I64: | ||
63 | - n = 64 / TCG_TARGET_REG_BITS; | ||
64 | - break; | ||
65 | - case TCG_TYPE_I128: | ||
66 | - n = 128 / TCG_TARGET_REG_BITS; | ||
67 | - break; | ||
68 | - default: | ||
69 | - g_assert_not_reached(); | ||
70 | + ts = &s->temps[idx]; | ||
71 | + ts->temp_allocated = 1; | ||
72 | + tcg_debug_assert(ts->base_type == type); | ||
73 | + tcg_debug_assert(ts->kind == kind); | ||
74 | + goto done; | ||
75 | } | ||
76 | + } else { | ||
77 | + tcg_debug_assert(kind == TEMP_TB); | ||
78 | + } | ||
79 | |||
80 | - ts = tcg_temp_alloc(s); | ||
81 | - ts->base_type = type; | ||
82 | - ts->temp_allocated = 1; | ||
83 | - ts->kind = kind; | ||
84 | + switch (type) { | ||
31 | + case TCG_TYPE_I32: | 85 | + case TCG_TYPE_I32: |
32 | + not_op = INDEX_op_not_i32; | ||
33 | + have_not = TCG_TARGET_HAS_not_i32; | ||
34 | + break; | ||
35 | + case TCG_TYPE_I64: | ||
36 | + not_op = INDEX_op_not_i64; | ||
37 | + have_not = TCG_TARGET_HAS_not_i64; | ||
38 | + break; | ||
39 | + case TCG_TYPE_V64: | 86 | + case TCG_TYPE_V64: |
40 | + case TCG_TYPE_V128: | 87 | + case TCG_TYPE_V128: |
41 | + case TCG_TYPE_V256: | 88 | + case TCG_TYPE_V256: |
42 | + not_op = INDEX_op_not_vec; | 89 | + n = 1; |
43 | + have_not = TCG_TARGET_HAS_not_vec; | 90 | + break; |
91 | + case TCG_TYPE_I64: | ||
92 | + n = 64 / TCG_TARGET_REG_BITS; | ||
93 | + break; | ||
94 | + case TCG_TYPE_I128: | ||
95 | + n = 128 / TCG_TARGET_REG_BITS; | ||
44 | + break; | 96 | + break; |
45 | + default: | 97 | + default: |
46 | + g_assert_not_reached(); | 98 | + g_assert_not_reached(); |
47 | + } | 99 | + } |
48 | + if (have_not) { | 100 | |
49 | + op->opc = not_op; | 101 | - if (n == 1) { |
50 | + op->args[1] = op->args[idx]; | 102 | - ts->type = type; |
51 | + return fold_not(ctx, op); | 103 | - } else { |
104 | - ts->type = TCG_TYPE_REG; | ||
105 | + ts = tcg_temp_alloc(s); | ||
106 | + ts->base_type = type; | ||
107 | + ts->temp_allocated = 1; | ||
108 | + ts->kind = kind; | ||
109 | |||
110 | - for (i = 1; i < n; ++i) { | ||
111 | - TCGTemp *ts2 = tcg_temp_alloc(s); | ||
112 | + if (n == 1) { | ||
113 | + ts->type = type; | ||
114 | + } else { | ||
115 | + ts->type = TCG_TYPE_REG; | ||
116 | |||
117 | - tcg_debug_assert(ts2 == ts + i); | ||
118 | - ts2->base_type = type; | ||
119 | - ts2->type = TCG_TYPE_REG; | ||
120 | - ts2->temp_allocated = 1; | ||
121 | - ts2->temp_subindex = i; | ||
122 | - ts2->kind = kind; | ||
123 | - } | ||
124 | + for (int i = 1; i < n; ++i) { | ||
125 | + TCGTemp *ts2 = tcg_temp_alloc(s); | ||
126 | + | ||
127 | + tcg_debug_assert(ts2 == ts + i); | ||
128 | + ts2->base_type = type; | ||
129 | + ts2->type = TCG_TYPE_REG; | ||
130 | + ts2->temp_allocated = 1; | ||
131 | + ts2->temp_subindex = i; | ||
132 | + ts2->kind = kind; | ||
133 | } | ||
134 | } | ||
135 | |||
136 | + done: | ||
137 | #if defined(CONFIG_DEBUG_TCG) | ||
138 | s->temps_in_use++; | ||
139 | #endif | ||
140 | @@ -XXX,XX +XXX,XX @@ TCGv_vec tcg_temp_new_vec_matching(TCGv_vec match) | ||
141 | void tcg_temp_free_internal(TCGTemp *ts) | ||
142 | { | ||
143 | TCGContext *s = tcg_ctx; | ||
144 | - int k, idx; | ||
145 | |||
146 | switch (ts->kind) { | ||
147 | case TEMP_CONST: | ||
148 | @@ -XXX,XX +XXX,XX @@ void tcg_temp_free_internal(TCGTemp *ts) | ||
149 | s->temps_in_use--; | ||
150 | #endif | ||
151 | |||
152 | - idx = temp_idx(ts); | ||
153 | - k = ts->base_type + (ts->kind == TEMP_EBB ? 0 : TCG_TYPE_COUNT); | ||
154 | - set_bit(idx, s->free_temps[k].l); | ||
155 | + if (ts->kind == TEMP_EBB) { | ||
156 | + int idx = temp_idx(ts); | ||
157 | + set_bit(idx, s->free_temps[ts->base_type].l); | ||
52 | + } | 158 | + } |
53 | + return false; | ||
54 | +} | ||
55 | + | ||
56 | +/* If the binary operation has first argument @i, fold to NOT. */ | ||
57 | +static bool fold_ix_to_not(OptContext *ctx, TCGOp *op, uint64_t i) | ||
58 | +{ | ||
59 | + if (arg_is_const(op->args[1]) && arg_info(op->args[1])->val == i) { | ||
60 | + return fold_to_not(ctx, op, 2); | ||
61 | + } | ||
62 | + return false; | ||
63 | +} | ||
64 | + | ||
65 | /* If the binary operation has second argument @i, fold to @i. */ | ||
66 | static bool fold_xi_to_i(OptContext *ctx, TCGOp *op, uint64_t i) | ||
67 | { | ||
68 | @@ -XXX,XX +XXX,XX @@ static bool fold_xi_to_i(OptContext *ctx, TCGOp *op, uint64_t i) | ||
69 | return false; | ||
70 | } | 159 | } |
71 | 160 | ||
72 | +/* If the binary operation has second argument @i, fold to NOT. */ | 161 | TCGTemp *tcg_constant_internal(TCGType type, int64_t val) |
73 | +static bool fold_xi_to_not(OptContext *ctx, TCGOp *op, uint64_t i) | ||
74 | +{ | ||
75 | + if (arg_is_const(op->args[2]) && arg_info(op->args[2])->val == i) { | ||
76 | + return fold_to_not(ctx, op, 1); | ||
77 | + } | ||
78 | + return false; | ||
79 | +} | ||
80 | + | ||
81 | /* If the binary operation has both arguments equal, fold to @i. */ | ||
82 | static bool fold_xx_to_i(OptContext *ctx, TCGOp *op, uint64_t i) | ||
83 | { | ||
84 | @@ -XXX,XX +XXX,XX @@ static bool fold_and(OptContext *ctx, TCGOp *op) | ||
85 | static bool fold_andc(OptContext *ctx, TCGOp *op) | ||
86 | { | ||
87 | if (fold_const2(ctx, op) || | ||
88 | - fold_xx_to_i(ctx, op, 0)) { | ||
89 | + fold_xx_to_i(ctx, op, 0) || | ||
90 | + fold_ix_to_not(ctx, op, -1)) { | ||
91 | return true; | ||
92 | } | ||
93 | return false; | ||
94 | @@ -XXX,XX +XXX,XX @@ static bool fold_dup2(OptContext *ctx, TCGOp *op) | ||
95 | |||
96 | static bool fold_eqv(OptContext *ctx, TCGOp *op) | ||
97 | { | ||
98 | - return fold_const2(ctx, op); | ||
99 | + if (fold_const2(ctx, op) || | ||
100 | + fold_xi_to_not(ctx, op, 0)) { | ||
101 | + return true; | ||
102 | + } | ||
103 | + return false; | ||
104 | } | ||
105 | |||
106 | static bool fold_extract(OptContext *ctx, TCGOp *op) | ||
107 | @@ -XXX,XX +XXX,XX @@ static bool fold_mulu2_i32(OptContext *ctx, TCGOp *op) | ||
108 | |||
109 | static bool fold_nand(OptContext *ctx, TCGOp *op) | ||
110 | { | ||
111 | - return fold_const2(ctx, op); | ||
112 | + if (fold_const2(ctx, op) || | ||
113 | + fold_xi_to_not(ctx, op, -1)) { | ||
114 | + return true; | ||
115 | + } | ||
116 | + return false; | ||
117 | } | ||
118 | |||
119 | static bool fold_neg(OptContext *ctx, TCGOp *op) | ||
120 | @@ -XXX,XX +XXX,XX @@ static bool fold_neg(OptContext *ctx, TCGOp *op) | ||
121 | |||
122 | static bool fold_nor(OptContext *ctx, TCGOp *op) | ||
123 | { | ||
124 | - return fold_const2(ctx, op); | ||
125 | + if (fold_const2(ctx, op) || | ||
126 | + fold_xi_to_not(ctx, op, 0)) { | ||
127 | + return true; | ||
128 | + } | ||
129 | + return false; | ||
130 | } | ||
131 | |||
132 | static bool fold_not(OptContext *ctx, TCGOp *op) | ||
133 | { | ||
134 | - return fold_const1(ctx, op); | ||
135 | + if (fold_const1(ctx, op)) { | ||
136 | + return true; | ||
137 | + } | ||
138 | + | ||
139 | + /* Because of fold_to_not, we want to always return true, via finish. */ | ||
140 | + finish_folding(ctx, op); | ||
141 | + return true; | ||
142 | } | ||
143 | |||
144 | static bool fold_or(OptContext *ctx, TCGOp *op) | ||
145 | @@ -XXX,XX +XXX,XX @@ static bool fold_or(OptContext *ctx, TCGOp *op) | ||
146 | |||
147 | static bool fold_orc(OptContext *ctx, TCGOp *op) | ||
148 | { | ||
149 | - return fold_const2(ctx, op); | ||
150 | + if (fold_const2(ctx, op) || | ||
151 | + fold_ix_to_not(ctx, op, 0)) { | ||
152 | + return true; | ||
153 | + } | ||
154 | + return false; | ||
155 | } | ||
156 | |||
157 | static bool fold_qemu_ld(OptContext *ctx, TCGOp *op) | ||
158 | @@ -XXX,XX +XXX,XX @@ static bool fold_sub2_i32(OptContext *ctx, TCGOp *op) | ||
159 | static bool fold_xor(OptContext *ctx, TCGOp *op) | ||
160 | { | ||
161 | if (fold_const2(ctx, op) || | ||
162 | - fold_xx_to_i(ctx, op, 0)) { | ||
163 | + fold_xx_to_i(ctx, op, 0) || | ||
164 | + fold_xi_to_not(ctx, op, -1)) { | ||
165 | return true; | ||
166 | } | ||
167 | return false; | ||
168 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
169 | } | ||
170 | } | ||
171 | break; | ||
172 | - CASE_OP_32_64_VEC(xor): | ||
173 | - CASE_OP_32_64(nand): | ||
174 | - if (!arg_is_const(op->args[1]) | ||
175 | - && arg_is_const(op->args[2]) | ||
176 | - && arg_info(op->args[2])->val == -1) { | ||
177 | - i = 1; | ||
178 | - goto try_not; | ||
179 | - } | ||
180 | - break; | ||
181 | - CASE_OP_32_64(nor): | ||
182 | - if (!arg_is_const(op->args[1]) | ||
183 | - && arg_is_const(op->args[2]) | ||
184 | - && arg_info(op->args[2])->val == 0) { | ||
185 | - i = 1; | ||
186 | - goto try_not; | ||
187 | - } | ||
188 | - break; | ||
189 | - CASE_OP_32_64_VEC(andc): | ||
190 | - if (!arg_is_const(op->args[2]) | ||
191 | - && arg_is_const(op->args[1]) | ||
192 | - && arg_info(op->args[1])->val == -1) { | ||
193 | - i = 2; | ||
194 | - goto try_not; | ||
195 | - } | ||
196 | - break; | ||
197 | - CASE_OP_32_64_VEC(orc): | ||
198 | - CASE_OP_32_64(eqv): | ||
199 | - if (!arg_is_const(op->args[2]) | ||
200 | - && arg_is_const(op->args[1]) | ||
201 | - && arg_info(op->args[1])->val == 0) { | ||
202 | - i = 2; | ||
203 | - goto try_not; | ||
204 | - } | ||
205 | - break; | ||
206 | - try_not: | ||
207 | - { | ||
208 | - TCGOpcode not_op; | ||
209 | - bool have_not; | ||
210 | - | ||
211 | - switch (ctx.type) { | ||
212 | - case TCG_TYPE_I32: | ||
213 | - not_op = INDEX_op_not_i32; | ||
214 | - have_not = TCG_TARGET_HAS_not_i32; | ||
215 | - break; | ||
216 | - case TCG_TYPE_I64: | ||
217 | - not_op = INDEX_op_not_i64; | ||
218 | - have_not = TCG_TARGET_HAS_not_i64; | ||
219 | - break; | ||
220 | - case TCG_TYPE_V64: | ||
221 | - case TCG_TYPE_V128: | ||
222 | - case TCG_TYPE_V256: | ||
223 | - not_op = INDEX_op_not_vec; | ||
224 | - have_not = TCG_TARGET_HAS_not_vec; | ||
225 | - break; | ||
226 | - default: | ||
227 | - g_assert_not_reached(); | ||
228 | - } | ||
229 | - if (!have_not) { | ||
230 | - break; | ||
231 | - } | ||
232 | - op->opc = not_op; | ||
233 | - reset_temp(op->args[0]); | ||
234 | - op->args[1] = op->args[i]; | ||
235 | - continue; | ||
236 | - } | ||
237 | default: | ||
238 | break; | ||
239 | } | ||
240 | -- | 162 | -- |
241 | 2.25.1 | 163 | 2.34.1 |
242 | 164 | ||
243 | 165 | diff view generated by jsdifflib |
1 | Rename to fold_addsub2. | 1 | Guest front-ends now get temps that span the lifetime of |
---|---|---|---|
2 | Use Int128 to implement the wider operation. | 2 | the translation block by default, which avoids accidentally |
3 | using the temp across branches and invalidating the data. | ||
3 | 4 | ||
4 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 5 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
5 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | ||
6 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
8 | --- | 7 | --- |
9 | tcg/optimize.c | 65 ++++++++++++++++++++++++++++++++++---------------- | 8 | include/tcg/tcg.h | 8 ++++---- |
10 | 1 file changed, 44 insertions(+), 21 deletions(-) | 9 | 1 file changed, 4 insertions(+), 4 deletions(-) |
11 | 10 | ||
12 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 11 | diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h |
13 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/tcg/optimize.c | 13 | --- a/include/tcg/tcg.h |
15 | +++ b/tcg/optimize.c | 14 | +++ b/include/tcg/tcg.h |
16 | @@ -XXX,XX +XXX,XX @@ | 15 | @@ -XXX,XX +XXX,XX @@ static inline TCGv_i32 tcg_temp_ebb_new_i32(void) |
17 | */ | 16 | |
18 | 17 | static inline TCGv_i32 tcg_temp_new_i32(void) | |
19 | #include "qemu/osdep.h" | 18 | { |
20 | +#include "qemu/int128.h" | 19 | - TCGTemp *t = tcg_temp_new_internal(TCG_TYPE_I32, TEMP_EBB); |
21 | #include "tcg/tcg-op.h" | 20 | + TCGTemp *t = tcg_temp_new_internal(TCG_TYPE_I32, TEMP_TB); |
22 | #include "tcg-internal.h" | 21 | return temp_tcgv_i32(t); |
23 | |||
24 | @@ -XXX,XX +XXX,XX @@ static bool fold_add(OptContext *ctx, TCGOp *op) | ||
25 | return false; | ||
26 | } | 22 | } |
27 | 23 | ||
28 | -static bool fold_addsub2_i32(OptContext *ctx, TCGOp *op, bool add) | 24 | @@ -XXX,XX +XXX,XX @@ static inline TCGv_i64 tcg_temp_ebb_new_i64(void) |
29 | +static bool fold_addsub2(OptContext *ctx, TCGOp *op, bool add) | 25 | |
26 | static inline TCGv_i64 tcg_temp_new_i64(void) | ||
30 | { | 27 | { |
31 | if (arg_is_const(op->args[2]) && arg_is_const(op->args[3]) && | 28 | - TCGTemp *t = tcg_temp_new_internal(TCG_TYPE_I64, TEMP_EBB); |
32 | arg_is_const(op->args[4]) && arg_is_const(op->args[5])) { | 29 | + TCGTemp *t = tcg_temp_new_internal(TCG_TYPE_I64, TEMP_TB); |
33 | - uint32_t al = arg_info(op->args[2])->val; | 30 | return temp_tcgv_i64(t); |
34 | - uint32_t ah = arg_info(op->args[3])->val; | ||
35 | - uint32_t bl = arg_info(op->args[4])->val; | ||
36 | - uint32_t bh = arg_info(op->args[5])->val; | ||
37 | - uint64_t a = ((uint64_t)ah << 32) | al; | ||
38 | - uint64_t b = ((uint64_t)bh << 32) | bl; | ||
39 | + uint64_t al = arg_info(op->args[2])->val; | ||
40 | + uint64_t ah = arg_info(op->args[3])->val; | ||
41 | + uint64_t bl = arg_info(op->args[4])->val; | ||
42 | + uint64_t bh = arg_info(op->args[5])->val; | ||
43 | TCGArg rl, rh; | ||
44 | - TCGOp *op2 = tcg_op_insert_before(ctx->tcg, op, INDEX_op_mov_i32); | ||
45 | + TCGOp *op2; | ||
46 | |||
47 | - if (add) { | ||
48 | - a += b; | ||
49 | + if (ctx->type == TCG_TYPE_I32) { | ||
50 | + uint64_t a = deposit64(al, 32, 32, ah); | ||
51 | + uint64_t b = deposit64(bl, 32, 32, bh); | ||
52 | + | ||
53 | + if (add) { | ||
54 | + a += b; | ||
55 | + } else { | ||
56 | + a -= b; | ||
57 | + } | ||
58 | + | ||
59 | + al = sextract64(a, 0, 32); | ||
60 | + ah = sextract64(a, 32, 32); | ||
61 | } else { | ||
62 | - a -= b; | ||
63 | + Int128 a = int128_make128(al, ah); | ||
64 | + Int128 b = int128_make128(bl, bh); | ||
65 | + | ||
66 | + if (add) { | ||
67 | + a = int128_add(a, b); | ||
68 | + } else { | ||
69 | + a = int128_sub(a, b); | ||
70 | + } | ||
71 | + | ||
72 | + al = int128_getlo(a); | ||
73 | + ah = int128_gethi(a); | ||
74 | } | ||
75 | |||
76 | rl = op->args[0]; | ||
77 | rh = op->args[1]; | ||
78 | - tcg_opt_gen_movi(ctx, op, rl, (int32_t)a); | ||
79 | - tcg_opt_gen_movi(ctx, op2, rh, (int32_t)(a >> 32)); | ||
80 | + | ||
81 | + /* The proper opcode is supplied by tcg_opt_gen_mov. */ | ||
82 | + op2 = tcg_op_insert_before(ctx->tcg, op, 0); | ||
83 | + | ||
84 | + tcg_opt_gen_movi(ctx, op, rl, al); | ||
85 | + tcg_opt_gen_movi(ctx, op2, rh, ah); | ||
86 | return true; | ||
87 | } | ||
88 | return false; | ||
89 | } | 31 | } |
90 | 32 | ||
91 | -static bool fold_add2_i32(OptContext *ctx, TCGOp *op) | 33 | @@ -XXX,XX +XXX,XX @@ static inline TCGv_i128 tcg_temp_ebb_new_i128(void) |
92 | +static bool fold_add2(OptContext *ctx, TCGOp *op) | 34 | |
35 | static inline TCGv_i128 tcg_temp_new_i128(void) | ||
93 | { | 36 | { |
94 | - return fold_addsub2_i32(ctx, op, true); | 37 | - TCGTemp *t = tcg_temp_new_internal(TCG_TYPE_I128, TEMP_EBB); |
95 | + return fold_addsub2(ctx, op, true); | 38 | + TCGTemp *t = tcg_temp_new_internal(TCG_TYPE_I128, TEMP_TB); |
39 | return temp_tcgv_i128(t); | ||
96 | } | 40 | } |
97 | 41 | ||
98 | static bool fold_and(OptContext *ctx, TCGOp *op) | 42 | @@ -XXX,XX +XXX,XX @@ static inline TCGv_ptr tcg_temp_ebb_new_ptr(void) |
99 | @@ -XXX,XX +XXX,XX @@ static bool fold_sub(OptContext *ctx, TCGOp *op) | 43 | |
100 | return false; | 44 | static inline TCGv_ptr tcg_temp_new_ptr(void) |
45 | { | ||
46 | - TCGTemp *t = tcg_temp_new_internal(TCG_TYPE_PTR, TEMP_EBB); | ||
47 | + TCGTemp *t = tcg_temp_new_internal(TCG_TYPE_PTR, TEMP_TB); | ||
48 | return temp_tcgv_ptr(t); | ||
101 | } | 49 | } |
102 | 50 | ||
103 | -static bool fold_sub2_i32(OptContext *ctx, TCGOp *op) | ||
104 | +static bool fold_sub2(OptContext *ctx, TCGOp *op) | ||
105 | { | ||
106 | - return fold_addsub2_i32(ctx, op, false); | ||
107 | + return fold_addsub2(ctx, op, false); | ||
108 | } | ||
109 | |||
110 | static bool fold_tcg_ld(OptContext *ctx, TCGOp *op) | ||
111 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
112 | CASE_OP_32_64_VEC(add): | ||
113 | done = fold_add(&ctx, op); | ||
114 | break; | ||
115 | - case INDEX_op_add2_i32: | ||
116 | - done = fold_add2_i32(&ctx, op); | ||
117 | + CASE_OP_32_64(add2): | ||
118 | + done = fold_add2(&ctx, op); | ||
119 | break; | ||
120 | CASE_OP_32_64_VEC(and): | ||
121 | done = fold_and(&ctx, op); | ||
122 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
123 | CASE_OP_32_64_VEC(sub): | ||
124 | done = fold_sub(&ctx, op); | ||
125 | break; | ||
126 | - case INDEX_op_sub2_i32: | ||
127 | - done = fold_sub2_i32(&ctx, op); | ||
128 | + CASE_OP_32_64(sub2): | ||
129 | + done = fold_sub2(&ctx, op); | ||
130 | break; | ||
131 | CASE_OP_32_64_VEC(xor): | ||
132 | done = fold_xor(&ctx, op); | ||
133 | -- | 51 | -- |
134 | 2.25.1 | 52 | 2.34.1 |
135 | 53 | ||
136 | 54 | diff view generated by jsdifflib |
1 | This puts the separate mb optimization into the same framework | 1 | Since we now get TEMP_TB temporaries by default, we no longer |
---|---|---|---|
2 | as the others. While fold_qemu_{ld,st} are currently identical, | 2 | need to make copies across these loops. These were the only |
3 | that won't last as more code gets moved. | 3 | uses of new_tmp_a64_local(), so remove that as well. |
4 | 4 | ||
5 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | 5 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
6 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
8 | --- | 7 | --- |
9 | tcg/optimize.c | 89 +++++++++++++++++++++++++++++--------------------- | 8 | target/arm/tcg/translate-a64.h | 1 - |
10 | 1 file changed, 51 insertions(+), 38 deletions(-) | 9 | target/arm/tcg/translate-a64.c | 6 ------ |
10 | target/arm/tcg/translate-sve.c | 32 -------------------------------- | ||
11 | 3 files changed, 39 deletions(-) | ||
11 | 12 | ||
12 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 13 | diff --git a/target/arm/tcg/translate-a64.h b/target/arm/tcg/translate-a64.h |
13 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/tcg/optimize.c | 15 | --- a/target/arm/tcg/translate-a64.h |
15 | +++ b/tcg/optimize.c | 16 | +++ b/target/arm/tcg/translate-a64.h |
16 | @@ -XXX,XX +XXX,XX @@ static bool fold_call(OptContext *ctx, TCGOp *op) | 17 | @@ -XXX,XX +XXX,XX @@ |
17 | return true; | 18 | #define TARGET_ARM_TRANSLATE_A64_H |
19 | |||
20 | TCGv_i64 new_tmp_a64(DisasContext *s); | ||
21 | -TCGv_i64 new_tmp_a64_local(DisasContext *s); | ||
22 | TCGv_i64 new_tmp_a64_zero(DisasContext *s); | ||
23 | TCGv_i64 cpu_reg(DisasContext *s, int reg); | ||
24 | TCGv_i64 cpu_reg_sp(DisasContext *s, int reg); | ||
25 | diff --git a/target/arm/tcg/translate-a64.c b/target/arm/tcg/translate-a64.c | ||
26 | index XXXXXXX..XXXXXXX 100644 | ||
27 | --- a/target/arm/tcg/translate-a64.c | ||
28 | +++ b/target/arm/tcg/translate-a64.c | ||
29 | @@ -XXX,XX +XXX,XX @@ TCGv_i64 new_tmp_a64(DisasContext *s) | ||
30 | return s->tmp_a64[s->tmp_a64_count++] = tcg_temp_new_i64(); | ||
18 | } | 31 | } |
19 | 32 | ||
20 | +static bool fold_mb(OptContext *ctx, TCGOp *op) | 33 | -TCGv_i64 new_tmp_a64_local(DisasContext *s) |
21 | +{ | 34 | -{ |
22 | + /* Eliminate duplicate and redundant fence instructions. */ | 35 | - assert(s->tmp_a64_count < TMP_A64_MAX); |
23 | + if (ctx->prev_mb) { | 36 | - return s->tmp_a64[s->tmp_a64_count++] = tcg_temp_local_new_i64(); |
24 | + /* | 37 | -} |
25 | + * Merge two barriers of the same type into one, | 38 | - |
26 | + * or a weaker barrier into a stronger one, | 39 | TCGv_i64 new_tmp_a64_zero(DisasContext *s) |
27 | + * or two weaker barriers into a stronger one. | ||
28 | + * mb X; mb Y => mb X|Y | ||
29 | + * mb; strl => mb; st | ||
30 | + * ldaq; mb => ld; mb | ||
31 | + * ldaq; strl => ld; mb; st | ||
32 | + * Other combinations are also merged into a strong | ||
33 | + * barrier. This is stricter than specified but for | ||
34 | + * the purposes of TCG is better than not optimizing. | ||
35 | + */ | ||
36 | + ctx->prev_mb->args[0] |= op->args[0]; | ||
37 | + tcg_op_remove(ctx->tcg, op); | ||
38 | + } else { | ||
39 | + ctx->prev_mb = op; | ||
40 | + } | ||
41 | + return true; | ||
42 | +} | ||
43 | + | ||
44 | +static bool fold_qemu_ld(OptContext *ctx, TCGOp *op) | ||
45 | +{ | ||
46 | + /* Opcodes that touch guest memory stop the mb optimization. */ | ||
47 | + ctx->prev_mb = NULL; | ||
48 | + return false; | ||
49 | +} | ||
50 | + | ||
51 | +static bool fold_qemu_st(OptContext *ctx, TCGOp *op) | ||
52 | +{ | ||
53 | + /* Opcodes that touch guest memory stop the mb optimization. */ | ||
54 | + ctx->prev_mb = NULL; | ||
55 | + return false; | ||
56 | +} | ||
57 | + | ||
58 | /* Propagate constants and copies, fold constant expressions. */ | ||
59 | void tcg_optimize(TCGContext *s) | ||
60 | { | 40 | { |
61 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | 41 | TCGv_i64 t = new_tmp_a64(s); |
62 | } | 42 | diff --git a/target/arm/tcg/translate-sve.c b/target/arm/tcg/translate-sve.c |
63 | break; | 43 | index XXXXXXX..XXXXXXX 100644 |
64 | 44 | --- a/target/arm/tcg/translate-sve.c | |
65 | + case INDEX_op_mb: | 45 | +++ b/target/arm/tcg/translate-sve.c |
66 | + done = fold_mb(&ctx, op); | 46 | @@ -XXX,XX +XXX,XX @@ void gen_sve_ldr(DisasContext *s, TCGv_ptr base, int vofs, |
67 | + break; | 47 | TCGLabel *loop = gen_new_label(); |
68 | + case INDEX_op_qemu_ld_i32: | 48 | TCGv_ptr tp, i = tcg_const_local_ptr(0); |
69 | + case INDEX_op_qemu_ld_i64: | 49 | |
70 | + done = fold_qemu_ld(&ctx, op); | 50 | - /* Copy the clean address into a local temp, live across the loop. */ |
71 | + break; | 51 | - t0 = clean_addr; |
72 | + case INDEX_op_qemu_st_i32: | 52 | - clean_addr = new_tmp_a64_local(s); |
73 | + case INDEX_op_qemu_st8_i32: | 53 | - tcg_gen_mov_i64(clean_addr, t0); |
74 | + case INDEX_op_qemu_st_i64: | ||
75 | + done = fold_qemu_st(&ctx, op); | ||
76 | + break; | ||
77 | + | ||
78 | default: | ||
79 | break; | ||
80 | } | ||
81 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
82 | if (!done) { | ||
83 | finish_folding(&ctx, op); | ||
84 | } | ||
85 | - | 54 | - |
86 | - /* Eliminate duplicate and redundant fence instructions. */ | 55 | - if (base != cpu_env) { |
87 | - if (ctx.prev_mb) { | 56 | - TCGv_ptr b = tcg_temp_local_new_ptr(); |
88 | - switch (opc) { | 57 | - tcg_gen_mov_ptr(b, base); |
89 | - case INDEX_op_mb: | 58 | - base = b; |
90 | - /* Merge two barriers of the same type into one, | 59 | - } |
91 | - * or a weaker barrier into a stronger one, | ||
92 | - * or two weaker barriers into a stronger one. | ||
93 | - * mb X; mb Y => mb X|Y | ||
94 | - * mb; strl => mb; st | ||
95 | - * ldaq; mb => ld; mb | ||
96 | - * ldaq; strl => ld; mb; st | ||
97 | - * Other combinations are also merged into a strong | ||
98 | - * barrier. This is stricter than specified but for | ||
99 | - * the purposes of TCG is better than not optimizing. | ||
100 | - */ | ||
101 | - ctx.prev_mb->args[0] |= op->args[0]; | ||
102 | - tcg_op_remove(s, op); | ||
103 | - break; | ||
104 | - | 60 | - |
105 | - default: | 61 | gen_set_label(loop); |
106 | - /* Opcodes that end the block stop the optimization. */ | 62 | |
107 | - if ((def->flags & TCG_OPF_BB_END) == 0) { | 63 | t0 = tcg_temp_new_i64(); |
108 | - break; | 64 | @@ -XXX,XX +XXX,XX @@ void gen_sve_ldr(DisasContext *s, TCGv_ptr base, int vofs, |
109 | - } | 65 | |
110 | - /* fallthru */ | 66 | tcg_gen_brcondi_ptr(TCG_COND_LTU, i, len_align, loop); |
111 | - case INDEX_op_qemu_ld_i32: | 67 | tcg_temp_free_ptr(i); |
112 | - case INDEX_op_qemu_ld_i64: | 68 | - |
113 | - case INDEX_op_qemu_st_i32: | 69 | - if (base != cpu_env) { |
114 | - case INDEX_op_qemu_st8_i32: | 70 | - tcg_temp_free_ptr(base); |
115 | - case INDEX_op_qemu_st_i64: | 71 | - assert(len_remain == 0); |
116 | - /* Opcodes that touch guest memory stop the optimization. */ | ||
117 | - ctx.prev_mb = NULL; | ||
118 | - break; | ||
119 | - } | ||
120 | - } else if (opc == INDEX_op_mb) { | ||
121 | - ctx.prev_mb = op; | ||
122 | - } | 72 | - } |
123 | } | 73 | } |
124 | } | 74 | |
75 | /* | ||
76 | @@ -XXX,XX +XXX,XX @@ void gen_sve_str(DisasContext *s, TCGv_ptr base, int vofs, | ||
77 | TCGLabel *loop = gen_new_label(); | ||
78 | TCGv_ptr tp, i = tcg_const_local_ptr(0); | ||
79 | |||
80 | - /* Copy the clean address into a local temp, live across the loop. */ | ||
81 | - t0 = clean_addr; | ||
82 | - clean_addr = new_tmp_a64_local(s); | ||
83 | - tcg_gen_mov_i64(clean_addr, t0); | ||
84 | - | ||
85 | - if (base != cpu_env) { | ||
86 | - TCGv_ptr b = tcg_temp_local_new_ptr(); | ||
87 | - tcg_gen_mov_ptr(b, base); | ||
88 | - base = b; | ||
89 | - } | ||
90 | - | ||
91 | gen_set_label(loop); | ||
92 | |||
93 | t0 = tcg_temp_new_i64(); | ||
94 | @@ -XXX,XX +XXX,XX @@ void gen_sve_str(DisasContext *s, TCGv_ptr base, int vofs, | ||
95 | |||
96 | tcg_gen_brcondi_ptr(TCG_COND_LTU, i, len_align, loop); | ||
97 | tcg_temp_free_ptr(i); | ||
98 | - | ||
99 | - if (base != cpu_env) { | ||
100 | - tcg_temp_free_ptr(base); | ||
101 | - assert(len_remain == 0); | ||
102 | - } | ||
103 | } | ||
104 | |||
105 | /* Predicate register stores can be any multiple of 2. */ | ||
125 | -- | 106 | -- |
126 | 2.25.1 | 107 | 2.34.1 |
127 | |||
128 | diff view generated by jsdifflib |
1 | Pull the "op r, a, i => mov r, a" optimization into a function, | 1 | Since tcg_temp_new_* is now identical, use those. |
---|---|---|---|
2 | and use them in the outer-most logical operations. | ||
3 | 2 | ||
4 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | 3 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
6 | --- | 5 | --- |
7 | tcg/optimize.c | 61 +++++++++++++++++++++----------------------------- | 6 | target/arm/tcg/translate-sve.c | 6 +++--- |
8 | 1 file changed, 26 insertions(+), 35 deletions(-) | 7 | target/arm/tcg/translate.c | 6 +++--- |
8 | 2 files changed, 6 insertions(+), 6 deletions(-) | ||
9 | 9 | ||
10 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 10 | diff --git a/target/arm/tcg/translate-sve.c b/target/arm/tcg/translate-sve.c |
11 | index XXXXXXX..XXXXXXX 100644 | 11 | index XXXXXXX..XXXXXXX 100644 |
12 | --- a/tcg/optimize.c | 12 | --- a/target/arm/tcg/translate-sve.c |
13 | +++ b/tcg/optimize.c | 13 | +++ b/target/arm/tcg/translate-sve.c |
14 | @@ -XXX,XX +XXX,XX @@ static bool fold_xi_to_i(OptContext *ctx, TCGOp *op, uint64_t i) | 14 | @@ -XXX,XX +XXX,XX @@ static bool do_clast_vector(DisasContext *s, arg_rprr_esz *a, bool before) |
15 | return false; | ||
16 | } | ||
17 | |||
18 | +/* If the binary operation has second argument @i, fold to identity. */ | ||
19 | +static bool fold_xi_to_x(OptContext *ctx, TCGOp *op, uint64_t i) | ||
20 | +{ | ||
21 | + if (arg_is_const(op->args[2]) && arg_info(op->args[2])->val == i) { | ||
22 | + return tcg_opt_gen_mov(ctx, op, op->args[0], op->args[1]); | ||
23 | + } | ||
24 | + return false; | ||
25 | +} | ||
26 | + | ||
27 | /* If the binary operation has second argument @i, fold to NOT. */ | ||
28 | static bool fold_xi_to_not(OptContext *ctx, TCGOp *op, uint64_t i) | ||
29 | { | ||
30 | @@ -XXX,XX +XXX,XX @@ static bool fold_xx_to_x(OptContext *ctx, TCGOp *op) | ||
31 | |||
32 | static bool fold_add(OptContext *ctx, TCGOp *op) | ||
33 | { | ||
34 | - return fold_const2(ctx, op); | ||
35 | + if (fold_const2(ctx, op) || | ||
36 | + fold_xi_to_x(ctx, op, 0)) { | ||
37 | + return true; | ||
38 | + } | ||
39 | + return false; | ||
40 | } | ||
41 | |||
42 | static bool fold_addsub2_i32(OptContext *ctx, TCGOp *op, bool add) | ||
43 | @@ -XXX,XX +XXX,XX @@ static bool fold_and(OptContext *ctx, TCGOp *op) | ||
44 | { | ||
45 | if (fold_const2(ctx, op) || | ||
46 | fold_xi_to_i(ctx, op, 0) || | ||
47 | + fold_xi_to_x(ctx, op, -1) || | ||
48 | fold_xx_to_x(ctx, op)) { | ||
49 | return true; | 15 | return true; |
50 | } | 16 | } |
51 | @@ -XXX,XX +XXX,XX @@ static bool fold_andc(OptContext *ctx, TCGOp *op) | 17 | |
52 | { | 18 | - last = tcg_temp_local_new_i32(); |
53 | if (fold_const2(ctx, op) || | 19 | + last = tcg_temp_new_i32(); |
54 | fold_xx_to_i(ctx, op, 0) || | 20 | over = gen_new_label(); |
55 | + fold_xi_to_x(ctx, op, 0) || | 21 | |
56 | fold_ix_to_not(ctx, op, -1)) { | 22 | find_last_active(s, last, esz, a->pg); |
23 | @@ -XXX,XX +XXX,XX @@ void gen_sve_ldr(DisasContext *s, TCGv_ptr base, int vofs, | ||
24 | tcg_temp_free_i64(t0); | ||
25 | } else { | ||
26 | TCGLabel *loop = gen_new_label(); | ||
27 | - TCGv_ptr tp, i = tcg_const_local_ptr(0); | ||
28 | + TCGv_ptr tp, i = tcg_const_ptr(0); | ||
29 | |||
30 | gen_set_label(loop); | ||
31 | |||
32 | @@ -XXX,XX +XXX,XX @@ void gen_sve_str(DisasContext *s, TCGv_ptr base, int vofs, | ||
33 | tcg_temp_free_i64(t0); | ||
34 | } else { | ||
35 | TCGLabel *loop = gen_new_label(); | ||
36 | - TCGv_ptr tp, i = tcg_const_local_ptr(0); | ||
37 | + TCGv_ptr tp, i = tcg_const_ptr(0); | ||
38 | |||
39 | gen_set_label(loop); | ||
40 | |||
41 | diff --git a/target/arm/tcg/translate.c b/target/arm/tcg/translate.c | ||
42 | index XXXXXXX..XXXXXXX 100644 | ||
43 | --- a/target/arm/tcg/translate.c | ||
44 | +++ b/target/arm/tcg/translate.c | ||
45 | @@ -XXX,XX +XXX,XX @@ static bool op_strex(DisasContext *s, arg_STREX *a, MemOp mop, bool rel) | ||
46 | tcg_gen_mb(TCG_MO_ALL | TCG_BAR_STRL); | ||
47 | } | ||
48 | |||
49 | - addr = tcg_temp_local_new_i32(); | ||
50 | + addr = tcg_temp_new_i32(); | ||
51 | load_reg_var(s, addr, a->rn); | ||
52 | tcg_gen_addi_i32(addr, addr, a->imm); | ||
53 | |||
54 | @@ -XXX,XX +XXX,XX @@ static bool op_ldrex(DisasContext *s, arg_LDREX *a, MemOp mop, bool acq) | ||
57 | return true; | 55 | return true; |
58 | } | 56 | } |
59 | @@ -XXX,XX +XXX,XX @@ static bool fold_dup2(OptContext *ctx, TCGOp *op) | 57 | |
60 | static bool fold_eqv(OptContext *ctx, TCGOp *op) | 58 | - addr = tcg_temp_local_new_i32(); |
61 | { | 59 | + addr = tcg_temp_new_i32(); |
62 | if (fold_const2(ctx, op) || | 60 | load_reg_var(s, addr, a->rn); |
63 | + fold_xi_to_x(ctx, op, -1) || | 61 | tcg_gen_addi_i32(addr, addr, a->imm); |
64 | fold_xi_to_not(ctx, op, 0)) { | 62 | |
65 | return true; | 63 | @@ -XXX,XX +XXX,XX @@ static bool trans_LE(DisasContext *s, arg_LE *a) |
66 | } | 64 | * Decrement by 1 << (4 - LTPSIZE). We need to use a TCG local |
67 | @@ -XXX,XX +XXX,XX @@ static bool fold_not(OptContext *ctx, TCGOp *op) | 65 | * so that decr stays live after the brcondi. |
68 | static bool fold_or(OptContext *ctx, TCGOp *op) | 66 | */ |
69 | { | 67 | - TCGv_i32 decr = tcg_temp_local_new_i32(); |
70 | if (fold_const2(ctx, op) || | 68 | + TCGv_i32 decr = tcg_temp_new_i32(); |
71 | + fold_xi_to_x(ctx, op, 0) || | 69 | TCGv_i32 ltpsize = load_cpu_field(v7m.ltpsize); |
72 | fold_xx_to_x(ctx, op)) { | 70 | tcg_gen_sub_i32(decr, tcg_constant_i32(4), ltpsize); |
73 | return true; | 71 | tcg_gen_shl_i32(decr, tcg_constant_i32(1), decr); |
74 | } | ||
75 | @@ -XXX,XX +XXX,XX @@ static bool fold_or(OptContext *ctx, TCGOp *op) | ||
76 | static bool fold_orc(OptContext *ctx, TCGOp *op) | ||
77 | { | ||
78 | if (fold_const2(ctx, op) || | ||
79 | + fold_xi_to_x(ctx, op, -1) || | ||
80 | fold_ix_to_not(ctx, op, 0)) { | ||
81 | return true; | ||
82 | } | ||
83 | @@ -XXX,XX +XXX,XX @@ static bool fold_sextract(OptContext *ctx, TCGOp *op) | ||
84 | |||
85 | static bool fold_shift(OptContext *ctx, TCGOp *op) | ||
86 | { | ||
87 | - return fold_const2(ctx, op); | ||
88 | + if (fold_const2(ctx, op) || | ||
89 | + fold_xi_to_x(ctx, op, 0)) { | ||
90 | + return true; | ||
91 | + } | ||
92 | + return false; | ||
93 | } | ||
94 | |||
95 | static bool fold_sub_to_neg(OptContext *ctx, TCGOp *op) | ||
96 | @@ -XXX,XX +XXX,XX @@ static bool fold_sub(OptContext *ctx, TCGOp *op) | ||
97 | { | ||
98 | if (fold_const2(ctx, op) || | ||
99 | fold_xx_to_i(ctx, op, 0) || | ||
100 | + fold_xi_to_x(ctx, op, 0) || | ||
101 | fold_sub_to_neg(ctx, op)) { | ||
102 | return true; | ||
103 | } | ||
104 | @@ -XXX,XX +XXX,XX @@ static bool fold_xor(OptContext *ctx, TCGOp *op) | ||
105 | { | ||
106 | if (fold_const2(ctx, op) || | ||
107 | fold_xx_to_i(ctx, op, 0) || | ||
108 | + fold_xi_to_x(ctx, op, 0) || | ||
109 | fold_xi_to_not(ctx, op, -1)) { | ||
110 | return true; | ||
111 | } | ||
112 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
113 | break; | ||
114 | } | ||
115 | |||
116 | - /* Simplify expression for "op r, a, const => mov r, a" cases */ | ||
117 | - switch (opc) { | ||
118 | - CASE_OP_32_64_VEC(add): | ||
119 | - CASE_OP_32_64_VEC(sub): | ||
120 | - CASE_OP_32_64_VEC(or): | ||
121 | - CASE_OP_32_64_VEC(xor): | ||
122 | - CASE_OP_32_64_VEC(andc): | ||
123 | - CASE_OP_32_64(shl): | ||
124 | - CASE_OP_32_64(shr): | ||
125 | - CASE_OP_32_64(sar): | ||
126 | - CASE_OP_32_64(rotl): | ||
127 | - CASE_OP_32_64(rotr): | ||
128 | - if (!arg_is_const(op->args[1]) | ||
129 | - && arg_is_const(op->args[2]) | ||
130 | - && arg_info(op->args[2])->val == 0) { | ||
131 | - tcg_opt_gen_mov(&ctx, op, op->args[0], op->args[1]); | ||
132 | - continue; | ||
133 | - } | ||
134 | - break; | ||
135 | - CASE_OP_32_64_VEC(and): | ||
136 | - CASE_OP_32_64_VEC(orc): | ||
137 | - CASE_OP_32_64(eqv): | ||
138 | - if (!arg_is_const(op->args[1]) | ||
139 | - && arg_is_const(op->args[2]) | ||
140 | - && arg_info(op->args[2])->val == -1) { | ||
141 | - tcg_opt_gen_mov(&ctx, op, op->args[0], op->args[1]); | ||
142 | - continue; | ||
143 | - } | ||
144 | - break; | ||
145 | - default: | ||
146 | - break; | ||
147 | - } | ||
148 | - | ||
149 | /* Simplify using known-zero bits. Currently only ops with a single | ||
150 | output argument is supported. */ | ||
151 | z_mask = -1; | ||
152 | -- | 72 | -- |
153 | 2.25.1 | 73 | 2.34.1 |
154 | 74 | ||
155 | 75 | diff view generated by jsdifflib |
1 | Reduce some code duplication by folding the NE and EQ cases. | 1 | Since tcg_temp_new is now identical, use that. |
---|---|---|---|
2 | 2 | ||
3 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 3 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
4 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | ||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
6 | --- | 5 | --- |
7 | tcg/optimize.c | 145 ++++++++++++++++++++++++------------------------- | 6 | target/cris/translate.c | 6 +++--- |
8 | 1 file changed, 72 insertions(+), 73 deletions(-) | 7 | target/cris/translate_v10.c.inc | 10 +++++----- |
8 | 2 files changed, 8 insertions(+), 8 deletions(-) | ||
9 | 9 | ||
10 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 10 | diff --git a/target/cris/translate.c b/target/cris/translate.c |
11 | index XXXXXXX..XXXXXXX 100644 | 11 | index XXXXXXX..XXXXXXX 100644 |
12 | --- a/tcg/optimize.c | 12 | --- a/target/cris/translate.c |
13 | +++ b/tcg/optimize.c | 13 | +++ b/target/cris/translate.c |
14 | @@ -XXX,XX +XXX,XX @@ static bool fold_remainder(OptContext *ctx, TCGOp *op) | 14 | @@ -XXX,XX +XXX,XX @@ static int dec_bound_r(CPUCRISState *env, DisasContext *dc) |
15 | return fold_const2(ctx, op); | 15 | LOG_DIS("bound.%c $r%u, $r%u\n", |
16 | } | 16 | memsize_char(size), dc->op1, dc->op2); |
17 | 17 | cris_cc_mask(dc, CC_MASK_NZ); | |
18 | +static bool fold_setcond2(OptContext *ctx, TCGOp *op) | 18 | - l0 = tcg_temp_local_new(); |
19 | +{ | 19 | + l0 = tcg_temp_new(); |
20 | + TCGCond cond = op->args[5]; | 20 | dec_prep_move_r(dc, dc->op1, dc->op2, size, 0, l0); |
21 | + int i = do_constant_folding_cond2(&op->args[1], &op->args[3], cond); | 21 | cris_alu(dc, CC_OP_BOUND, cpu_R[dc->op2], cpu_R[dc->op2], l0, 4); |
22 | + int inv = 0; | 22 | tcg_temp_free(l0); |
23 | + | 23 | @@ -XXX,XX +XXX,XX @@ static int dec_bound_m(CPUCRISState *env, DisasContext *dc) |
24 | + if (i >= 0) { | 24 | dc->op1, dc->postinc ? "+]" : "]", |
25 | + goto do_setcond_const; | 25 | dc->op2); |
26 | + } | 26 | |
27 | + | 27 | - l[0] = tcg_temp_local_new(); |
28 | + switch (cond) { | 28 | - l[1] = tcg_temp_local_new(); |
29 | + case TCG_COND_LT: | 29 | + l[0] = tcg_temp_new(); |
30 | + case TCG_COND_GE: | 30 | + l[1] = tcg_temp_new(); |
31 | + /* | 31 | insn_len = dec_prep_alu_m(env, dc, 0, memsize, l[0], l[1]); |
32 | + * Simplify LT/GE comparisons vs zero to a single compare | 32 | cris_cc_mask(dc, CC_MASK_NZ); |
33 | + * vs the high word of the input. | 33 | cris_alu(dc, CC_OP_BOUND, cpu_R[dc->op2], l[0], l[1], 4); |
34 | + */ | 34 | diff --git a/target/cris/translate_v10.c.inc b/target/cris/translate_v10.c.inc |
35 | + if (arg_is_const(op->args[3]) && arg_info(op->args[3])->val == 0 && | 35 | index XXXXXXX..XXXXXXX 100644 |
36 | + arg_is_const(op->args[4]) && arg_info(op->args[4])->val == 0) { | 36 | --- a/target/cris/translate_v10.c.inc |
37 | + goto do_setcond_high; | 37 | +++ b/target/cris/translate_v10.c.inc |
38 | + } | 38 | @@ -XXX,XX +XXX,XX @@ static void gen_store_v10_conditional(DisasContext *dc, TCGv addr, TCGv val, |
39 | + break; | 39 | unsigned int size, int mem_index) |
40 | + | ||
41 | + case TCG_COND_NE: | ||
42 | + inv = 1; | ||
43 | + QEMU_FALLTHROUGH; | ||
44 | + case TCG_COND_EQ: | ||
45 | + /* | ||
46 | + * Simplify EQ/NE comparisons where one of the pairs | ||
47 | + * can be simplified. | ||
48 | + */ | ||
49 | + i = do_constant_folding_cond(INDEX_op_setcond_i32, op->args[1], | ||
50 | + op->args[3], cond); | ||
51 | + switch (i ^ inv) { | ||
52 | + case 0: | ||
53 | + goto do_setcond_const; | ||
54 | + case 1: | ||
55 | + goto do_setcond_high; | ||
56 | + } | ||
57 | + | ||
58 | + i = do_constant_folding_cond(INDEX_op_setcond_i32, op->args[2], | ||
59 | + op->args[4], cond); | ||
60 | + switch (i ^ inv) { | ||
61 | + case 0: | ||
62 | + goto do_setcond_const; | ||
63 | + case 1: | ||
64 | + op->args[2] = op->args[3]; | ||
65 | + op->args[3] = cond; | ||
66 | + op->opc = INDEX_op_setcond_i32; | ||
67 | + break; | ||
68 | + } | ||
69 | + break; | ||
70 | + | ||
71 | + default: | ||
72 | + break; | ||
73 | + | ||
74 | + do_setcond_high: | ||
75 | + op->args[1] = op->args[2]; | ||
76 | + op->args[2] = op->args[4]; | ||
77 | + op->args[3] = cond; | ||
78 | + op->opc = INDEX_op_setcond_i32; | ||
79 | + break; | ||
80 | + } | ||
81 | + return false; | ||
82 | + | ||
83 | + do_setcond_const: | ||
84 | + return tcg_opt_gen_movi(ctx, op, op->args[0], i); | ||
85 | +} | ||
86 | + | ||
87 | static bool fold_shift(OptContext *ctx, TCGOp *op) | ||
88 | { | 40 | { |
89 | return fold_const2(ctx, op); | 41 | TCGLabel *l1 = gen_new_label(); |
90 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | 42 | - TCGv taddr = tcg_temp_local_new(); |
91 | } | 43 | - TCGv tval = tcg_temp_local_new(); |
92 | break; | 44 | - TCGv t1 = tcg_temp_local_new(); |
93 | 45 | + TCGv taddr = tcg_temp_new(); | |
94 | - case INDEX_op_setcond2_i32: | 46 | + TCGv tval = tcg_temp_new(); |
95 | - i = do_constant_folding_cond2(&op->args[1], &op->args[3], | 47 | + TCGv t1 = tcg_temp_new(); |
96 | - op->args[5]); | 48 | dc->postinc = 0; |
97 | - if (i >= 0) { | 49 | cris_evaluate_flags(dc); |
98 | - do_setcond_const: | 50 | |
99 | - tcg_opt_gen_movi(&ctx, op, op->args[0], i); | 51 | @@ -XXX,XX +XXX,XX @@ static void dec10_reg_bound(DisasContext *dc, int size) |
100 | - continue; | 52 | { |
101 | - } | 53 | TCGv t; |
102 | - if ((op->args[5] == TCG_COND_LT || op->args[5] == TCG_COND_GE) | 54 | |
103 | - && arg_is_const(op->args[3]) | 55 | - t = tcg_temp_local_new(); |
104 | - && arg_info(op->args[3])->val == 0 | 56 | + t = tcg_temp_new(); |
105 | - && arg_is_const(op->args[4]) | 57 | t_gen_zext(t, cpu_R[dc->src], size); |
106 | - && arg_info(op->args[4])->val == 0) { | 58 | cris_alu(dc, CC_OP_BOUND, cpu_R[dc->dst], cpu_R[dc->dst], t, 4); |
107 | - /* Simplify LT/GE comparisons vs zero to a single compare | 59 | tcg_temp_free(t); |
108 | - vs the high word of the input. */ | 60 | @@ -XXX,XX +XXX,XX @@ static int dec10_ind_bound(CPUCRISState *env, DisasContext *dc, |
109 | - do_setcond_high: | 61 | int rd = dc->dst; |
110 | - reset_temp(op->args[0]); | 62 | TCGv t; |
111 | - arg_info(op->args[0])->z_mask = 1; | 63 | |
112 | - op->opc = INDEX_op_setcond_i32; | 64 | - t = tcg_temp_local_new(); |
113 | - op->args[1] = op->args[2]; | 65 | + t = tcg_temp_new(); |
114 | - op->args[2] = op->args[4]; | 66 | insn_len += dec10_prep_move_m(env, dc, 0, size, t); |
115 | - op->args[3] = op->args[5]; | 67 | cris_alu(dc, CC_OP_BOUND, cpu_R[dc->dst], cpu_R[rd], t, 4); |
116 | - break; | 68 | if (dc->dst == 15) { |
117 | - } | ||
118 | - if (op->args[5] == TCG_COND_EQ) { | ||
119 | - /* Simplify EQ comparisons where one of the pairs | ||
120 | - can be simplified. */ | ||
121 | - i = do_constant_folding_cond(INDEX_op_setcond_i32, | ||
122 | - op->args[1], op->args[3], | ||
123 | - TCG_COND_EQ); | ||
124 | - if (i == 0) { | ||
125 | - goto do_setcond_const; | ||
126 | - } else if (i > 0) { | ||
127 | - goto do_setcond_high; | ||
128 | - } | ||
129 | - i = do_constant_folding_cond(INDEX_op_setcond_i32, | ||
130 | - op->args[2], op->args[4], | ||
131 | - TCG_COND_EQ); | ||
132 | - if (i == 0) { | ||
133 | - goto do_setcond_high; | ||
134 | - } else if (i < 0) { | ||
135 | - break; | ||
136 | - } | ||
137 | - do_setcond_low: | ||
138 | - reset_temp(op->args[0]); | ||
139 | - arg_info(op->args[0])->z_mask = 1; | ||
140 | - op->opc = INDEX_op_setcond_i32; | ||
141 | - op->args[2] = op->args[3]; | ||
142 | - op->args[3] = op->args[5]; | ||
143 | - break; | ||
144 | - } | ||
145 | - if (op->args[5] == TCG_COND_NE) { | ||
146 | - /* Simplify NE comparisons where one of the pairs | ||
147 | - can be simplified. */ | ||
148 | - i = do_constant_folding_cond(INDEX_op_setcond_i32, | ||
149 | - op->args[1], op->args[3], | ||
150 | - TCG_COND_NE); | ||
151 | - if (i == 0) { | ||
152 | - goto do_setcond_high; | ||
153 | - } else if (i > 0) { | ||
154 | - goto do_setcond_const; | ||
155 | - } | ||
156 | - i = do_constant_folding_cond(INDEX_op_setcond_i32, | ||
157 | - op->args[2], op->args[4], | ||
158 | - TCG_COND_NE); | ||
159 | - if (i == 0) { | ||
160 | - goto do_setcond_low; | ||
161 | - } else if (i > 0) { | ||
162 | - goto do_setcond_const; | ||
163 | - } | ||
164 | - } | ||
165 | - break; | ||
166 | - | ||
167 | default: | ||
168 | break; | ||
169 | |||
170 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
171 | CASE_OP_32_64(shr): | ||
172 | done = fold_shift(&ctx, op); | ||
173 | break; | ||
174 | + case INDEX_op_setcond2_i32: | ||
175 | + done = fold_setcond2(&ctx, op); | ||
176 | + break; | ||
177 | CASE_OP_32_64_VEC(sub): | ||
178 | done = fold_sub(&ctx, op); | ||
179 | break; | ||
180 | -- | 69 | -- |
181 | 2.25.1 | 70 | 2.34.1 |
182 | 71 | ||
183 | 72 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | Since tcg_temp_new_* is now identical, use those. | |
2 | |||
3 | Reviewed-by: Taylor Simpson <tsimpson@quicinc.com> | ||
4 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | --- | ||
7 | target/hexagon/idef-parser/README.rst | 4 ++-- | ||
8 | target/hexagon/gen_tcg.h | 4 ++-- | ||
9 | target/hexagon/genptr.c | 16 ++++++++-------- | ||
10 | target/hexagon/idef-parser/parser-helpers.c | 4 ++-- | ||
11 | target/hexagon/translate.c | 2 +- | ||
12 | target/hexagon/README | 8 ++++---- | ||
13 | target/hexagon/gen_tcg_funcs.py | 18 +++++++----------- | ||
14 | 7 files changed, 26 insertions(+), 30 deletions(-) | ||
15 | |||
16 | diff --git a/target/hexagon/idef-parser/README.rst b/target/hexagon/idef-parser/README.rst | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/target/hexagon/idef-parser/README.rst | ||
19 | +++ b/target/hexagon/idef-parser/README.rst | ||
20 | @@ -XXX,XX +XXX,XX @@ generators the previous declarations are mapped to | ||
21 | |||
22 | :: | ||
23 | |||
24 | - int var1; -> TCGv_i32 var1 = tcg_temp_local_new_i32(); | ||
25 | + int var1; -> TCGv_i32 var1 = tcg_temp_new_i32(); | ||
26 | |||
27 | - int var2 = 0; -> TCGv_i32 var1 = tcg_temp_local_new_i32(); | ||
28 | + int var2 = 0; -> TCGv_i32 var1 = tcg_temp_new_i32(); | ||
29 | tcg_gen_movi_i32(j, ((int64_t) 0ULL)); | ||
30 | |||
31 | which are later automatically freed at the end of the function they're declared | ||
32 | diff --git a/target/hexagon/gen_tcg.h b/target/hexagon/gen_tcg.h | ||
33 | index XXXXXXX..XXXXXXX 100644 | ||
34 | --- a/target/hexagon/gen_tcg.h | ||
35 | +++ b/target/hexagon/gen_tcg.h | ||
36 | @@ -XXX,XX +XXX,XX @@ | ||
37 | */ | ||
38 | #define fGEN_TCG_PRED_LOAD(GET_EA, PRED, SIZE, SIGN) \ | ||
39 | do { \ | ||
40 | - TCGv LSB = tcg_temp_local_new(); \ | ||
41 | + TCGv LSB = tcg_temp_new(); \ | ||
42 | TCGLabel *label = gen_new_label(); \ | ||
43 | tcg_gen_movi_tl(EA, 0); \ | ||
44 | PRED; \ | ||
45 | @@ -XXX,XX +XXX,XX @@ | ||
46 | /* Predicated loads into a register pair */ | ||
47 | #define fGEN_TCG_PRED_LOAD_PAIR(GET_EA, PRED) \ | ||
48 | do { \ | ||
49 | - TCGv LSB = tcg_temp_local_new(); \ | ||
50 | + TCGv LSB = tcg_temp_new(); \ | ||
51 | TCGLabel *label = gen_new_label(); \ | ||
52 | tcg_gen_movi_tl(EA, 0); \ | ||
53 | PRED; \ | ||
54 | diff --git a/target/hexagon/genptr.c b/target/hexagon/genptr.c | ||
55 | index XXXXXXX..XXXXXXX 100644 | ||
56 | --- a/target/hexagon/genptr.c | ||
57 | +++ b/target/hexagon/genptr.c | ||
58 | @@ -XXX,XX +XXX,XX @@ static void gen_cond_call(DisasContext *ctx, TCGv pred, | ||
59 | TCGCond cond, int pc_off) | ||
60 | { | ||
61 | TCGv next_PC; | ||
62 | - TCGv lsb = tcg_temp_local_new(); | ||
63 | + TCGv lsb = tcg_temp_new(); | ||
64 | TCGLabel *skip = gen_new_label(); | ||
65 | tcg_gen_andi_tl(lsb, pred, 1); | ||
66 | gen_write_new_pc_pcrel(ctx, pc_off, cond, lsb); | ||
67 | @@ -XXX,XX +XXX,XX @@ static void gen_cond_call(DisasContext *ctx, TCGv pred, | ||
68 | |||
69 | static void gen_endloop0(DisasContext *ctx) | ||
70 | { | ||
71 | - TCGv lpcfg = tcg_temp_local_new(); | ||
72 | + TCGv lpcfg = tcg_temp_new(); | ||
73 | |||
74 | GET_USR_FIELD(USR_LPCFG, lpcfg); | ||
75 | |||
76 | @@ -XXX,XX +XXX,XX @@ static void gen_sar(TCGv dst, TCGv src, TCGv shift_amt) | ||
77 | /* Bidirectional shift right with saturation */ | ||
78 | static void gen_asr_r_r_sat(TCGv RdV, TCGv RsV, TCGv RtV) | ||
79 | { | ||
80 | - TCGv shift_amt = tcg_temp_local_new(); | ||
81 | + TCGv shift_amt = tcg_temp_new(); | ||
82 | TCGLabel *positive = gen_new_label(); | ||
83 | TCGLabel *done = gen_new_label(); | ||
84 | |||
85 | @@ -XXX,XX +XXX,XX @@ static void gen_asr_r_r_sat(TCGv RdV, TCGv RsV, TCGv RtV) | ||
86 | /* Bidirectional shift left with saturation */ | ||
87 | static void gen_asl_r_r_sat(TCGv RdV, TCGv RsV, TCGv RtV) | ||
88 | { | ||
89 | - TCGv shift_amt = tcg_temp_local_new(); | ||
90 | + TCGv shift_amt = tcg_temp_new(); | ||
91 | TCGLabel *positive = gen_new_label(); | ||
92 | TCGLabel *done = gen_new_label(); | ||
93 | |||
94 | @@ -XXX,XX +XXX,XX @@ static void gen_log_vreg_write(DisasContext *ctx, intptr_t srcoff, int num, | ||
95 | intptr_t dstoff; | ||
96 | |||
97 | if (is_predicated) { | ||
98 | - TCGv cancelled = tcg_temp_local_new(); | ||
99 | + TCGv cancelled = tcg_temp_new(); | ||
100 | label_end = gen_new_label(); | ||
101 | |||
102 | /* Don't do anything if the slot was cancelled */ | ||
103 | @@ -XXX,XX +XXX,XX @@ static void gen_log_qreg_write(intptr_t srcoff, int num, int vnew, | ||
104 | intptr_t dstoff; | ||
105 | |||
106 | if (is_predicated) { | ||
107 | - TCGv cancelled = tcg_temp_local_new(); | ||
108 | + TCGv cancelled = tcg_temp_new(); | ||
109 | label_end = gen_new_label(); | ||
110 | |||
111 | /* Don't do anything if the slot was cancelled */ | ||
112 | @@ -XXX,XX +XXX,XX @@ void gen_satu_i64_ovfl(TCGv ovfl, TCGv_i64 dest, TCGv_i64 source, int width) | ||
113 | /* Implements the fADDSAT64 macro in TCG */ | ||
114 | void gen_add_sat_i64(TCGv_i64 ret, TCGv_i64 a, TCGv_i64 b) | ||
115 | { | ||
116 | - TCGv_i64 sum = tcg_temp_local_new_i64(); | ||
117 | + TCGv_i64 sum = tcg_temp_new_i64(); | ||
118 | TCGv_i64 xor = tcg_temp_new_i64(); | ||
119 | TCGv_i64 cond1 = tcg_temp_new_i64(); | ||
120 | - TCGv_i64 cond2 = tcg_temp_local_new_i64(); | ||
121 | + TCGv_i64 cond2 = tcg_temp_new_i64(); | ||
122 | TCGv_i64 cond3 = tcg_temp_new_i64(); | ||
123 | TCGv_i64 mask = tcg_constant_i64(0x8000000000000000ULL); | ||
124 | TCGv_i64 max_pos = tcg_constant_i64(0x7FFFFFFFFFFFFFFFLL); | ||
125 | diff --git a/target/hexagon/idef-parser/parser-helpers.c b/target/hexagon/idef-parser/parser-helpers.c | ||
126 | index XXXXXXX..XXXXXXX 100644 | ||
127 | --- a/target/hexagon/idef-parser/parser-helpers.c | ||
128 | +++ b/target/hexagon/idef-parser/parser-helpers.c | ||
129 | @@ -XXX,XX +XXX,XX @@ HexValue gen_tmp_local(Context *c, | ||
130 | rvalue.is_manual = false; | ||
131 | rvalue.tmp.index = c->inst.tmp_count; | ||
132 | OUT(c, locp, "TCGv_i", &bit_width, " tmp_", &c->inst.tmp_count, | ||
133 | - " = tcg_temp_local_new_i", &bit_width, "();\n"); | ||
134 | + " = tcg_temp_new_i", &bit_width, "();\n"); | ||
135 | c->inst.tmp_count++; | ||
136 | return rvalue; | ||
137 | } | ||
138 | @@ -XXX,XX +XXX,XX @@ void gen_varid_allocate(Context *c, | ||
139 | new_var.signedness = signedness; | ||
140 | |||
141 | EMIT_HEAD(c, "TCGv_%s %s", bit_suffix, varid->var.name->str); | ||
142 | - EMIT_HEAD(c, " = tcg_temp_local_new_%s();\n", bit_suffix); | ||
143 | + EMIT_HEAD(c, " = tcg_temp_new_%s();\n", bit_suffix); | ||
144 | g_array_append_val(c->inst.allocated, new_var); | ||
145 | } | ||
146 | |||
147 | diff --git a/target/hexagon/translate.c b/target/hexagon/translate.c | ||
148 | index XXXXXXX..XXXXXXX 100644 | ||
149 | --- a/target/hexagon/translate.c | ||
150 | +++ b/target/hexagon/translate.c | ||
151 | @@ -XXX,XX +XXX,XX @@ void process_store(DisasContext *ctx, int slot_num) | ||
152 | tcg_temp_free(cancelled); | ||
153 | } | ||
154 | { | ||
155 | - TCGv address = tcg_temp_local_new(); | ||
156 | + TCGv address = tcg_temp_new(); | ||
157 | tcg_gen_mov_tl(address, hex_store_addr[slot_num]); | ||
158 | |||
159 | /* | ||
160 | diff --git a/target/hexagon/README b/target/hexagon/README | ||
161 | index XXXXXXX..XXXXXXX 100644 | ||
162 | --- a/target/hexagon/README | ||
163 | +++ b/target/hexagon/README | ||
164 | @@ -XXX,XX +XXX,XX @@ tcg_funcs_generated.c.inc | ||
165 | Insn *insn, | ||
166 | Packet *pkt) | ||
167 | { | ||
168 | - TCGv RdV = tcg_temp_local_new(); | ||
169 | + TCGv RdV = tcg_temp_new(); | ||
170 | const int RdN = insn->regno[0]; | ||
171 | TCGv RsV = hex_gpr[insn->regno[1]]; | ||
172 | TCGv RtV = hex_gpr[insn->regno[2]]; | ||
173 | @@ -XXX,XX +XXX,XX @@ istruction. | ||
174 | const int VdN = insn->regno[0]; | ||
175 | const intptr_t VdV_off = | ||
176 | ctx_future_vreg_off(ctx, VdN, 1, true); | ||
177 | - TCGv_ptr VdV = tcg_temp_local_new_ptr(); | ||
178 | + TCGv_ptr VdV = tcg_temp_new_ptr(); | ||
179 | tcg_gen_addi_ptr(VdV, cpu_env, VdV_off); | ||
180 | const int VuN = insn->regno[1]; | ||
181 | const intptr_t VuV_off = | ||
182 | vreg_src_off(ctx, VuN); | ||
183 | - TCGv_ptr VuV = tcg_temp_local_new_ptr(); | ||
184 | + TCGv_ptr VuV = tcg_temp_new_ptr(); | ||
185 | const int VvN = insn->regno[2]; | ||
186 | const intptr_t VvV_off = | ||
187 | vreg_src_off(ctx, VvN); | ||
188 | - TCGv_ptr VvV = tcg_temp_local_new_ptr(); | ||
189 | + TCGv_ptr VvV = tcg_temp_new_ptr(); | ||
190 | tcg_gen_addi_ptr(VuV, cpu_env, VuV_off); | ||
191 | tcg_gen_addi_ptr(VvV, cpu_env, VvV_off); | ||
192 | TCGv slot = tcg_constant_tl(insn->slot); | ||
193 | diff --git a/target/hexagon/gen_tcg_funcs.py b/target/hexagon/gen_tcg_funcs.py | ||
194 | index XXXXXXX..XXXXXXX 100755 | ||
195 | --- a/target/hexagon/gen_tcg_funcs.py | ||
196 | +++ b/target/hexagon/gen_tcg_funcs.py | ||
197 | @@ -XXX,XX +XXX,XX @@ | ||
198 | ## Helpers for gen_tcg_func | ||
199 | ## | ||
200 | def gen_decl_ea_tcg(f, tag): | ||
201 | - if ('A_CONDEXEC' in hex_common.attribdict[tag] or | ||
202 | - 'A_LOAD' in hex_common.attribdict[tag]): | ||
203 | - f.write(" TCGv EA = tcg_temp_local_new();\n") | ||
204 | - else: | ||
205 | - f.write(" TCGv EA = tcg_temp_new();\n") | ||
206 | + f.write(" TCGv EA = tcg_temp_new();\n") | ||
207 | |||
208 | def gen_free_ea_tcg(f): | ||
209 | f.write(" tcg_temp_free(EA);\n") | ||
210 | |||
211 | def genptr_decl_pair_writable(f, tag, regtype, regid, regno): | ||
212 | regN="%s%sN" % (regtype,regid) | ||
213 | - f.write(" TCGv_i64 %s%sV = tcg_temp_local_new_i64();\n" % \ | ||
214 | + f.write(" TCGv_i64 %s%sV = tcg_temp_new_i64();\n" % \ | ||
215 | (regtype, regid)) | ||
216 | if (regtype == "C"): | ||
217 | f.write(" const int %s = insn->regno[%d] + HEX_REG_SA0;\n" % \ | ||
218 | @@ -XXX,XX +XXX,XX @@ def genptr_decl_pair_writable(f, tag, regtype, regid, regno): | ||
219 | |||
220 | def genptr_decl_writable(f, tag, regtype, regid, regno): | ||
221 | regN="%s%sN" % (regtype,regid) | ||
222 | - f.write(" TCGv %s%sV = tcg_temp_local_new();\n" % \ | ||
223 | + f.write(" TCGv %s%sV = tcg_temp_new();\n" % \ | ||
224 | (regtype, regid)) | ||
225 | if (regtype == "C"): | ||
226 | f.write(" const int %s = insn->regno[%d] + HEX_REG_SA0;\n" % \ | ||
227 | @@ -XXX,XX +XXX,XX @@ def genptr_decl(f, tag, regtype, regid, regno): | ||
228 | regN="%s%sN" % (regtype,regid) | ||
229 | if (regtype == "R"): | ||
230 | if (regid in {"ss", "tt"}): | ||
231 | - f.write(" TCGv_i64 %s%sV = tcg_temp_local_new_i64();\n" % \ | ||
232 | + f.write(" TCGv_i64 %s%sV = tcg_temp_new_i64();\n" % \ | ||
233 | (regtype, regid)) | ||
234 | f.write(" const int %s = insn->regno[%d];\n" % \ | ||
235 | (regN, regno)) | ||
236 | @@ -XXX,XX +XXX,XX @@ def genptr_decl(f, tag, regtype, regid, regno): | ||
237 | print("Bad register parse: ", regtype, regid) | ||
238 | elif (regtype == "C"): | ||
239 | if (regid == "ss"): | ||
240 | - f.write(" TCGv_i64 %s%sV = tcg_temp_local_new_i64();\n" % \ | ||
241 | + f.write(" TCGv_i64 %s%sV = tcg_temp_new_i64();\n" % \ | ||
242 | (regtype, regid)) | ||
243 | f.write(" const int %s = insn->regno[%d] + HEX_REG_SA0;\n" % \ | ||
244 | (regN, regno)) | ||
245 | elif (regid == "dd"): | ||
246 | genptr_decl_pair_writable(f, tag, regtype, regid, regno) | ||
247 | elif (regid == "s"): | ||
248 | - f.write(" TCGv %s%sV = tcg_temp_local_new();\n" % \ | ||
249 | + f.write(" TCGv %s%sV = tcg_temp_new();\n" % \ | ||
250 | (regtype, regid)) | ||
251 | f.write(" const int %s%sN = insn->regno[%d] + HEX_REG_SA0;\n" % \ | ||
252 | (regtype, regid, regno)) | ||
253 | @@ -XXX,XX +XXX,XX @@ def genptr_dst_write_opn(f,regtype, regid, tag): | ||
254 | ## We produce: | ||
255 | ## static void generate_A2_add(DisasContext *ctx) | ||
256 | ## { | ||
257 | -## TCGv RdV = tcg_temp_local_new(); | ||
258 | +## TCGv RdV = tcg_temp_new(); | ||
259 | ## const int RdN = insn->regno[0]; | ||
260 | ## TCGv RsV = hex_gpr[insn->regno[1]]; | ||
261 | ## TCGv RtV = hex_gpr[insn->regno[2]]; | ||
262 | -- | ||
263 | 2.34.1 | ||
264 | |||
265 | diff view generated by jsdifflib |
1 | From: Luis Pires <luis.pires@eldorado.org.br> | 1 | This is now equivalent to gen_tmp. |
---|---|---|---|
2 | 2 | ||
3 | Move udiv_qrnnd() from include/fpu/softfloat-macros.h to host-utils, | 3 | Reviewed-by: Taylor Simpson <tsimpson@quicinc.com> |
4 | so it can be reused by divu128(). | 4 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
5 | |||
6 | Signed-off-by: Luis Pires <luis.pires@eldorado.org.br> | ||
7 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Message-Id: <20211025191154.350831-3-luis.pires@eldorado.org.br> | ||
9 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
10 | --- | 6 | --- |
11 | include/fpu/softfloat-macros.h | 82 ---------------------------------- | 7 | target/hexagon/idef-parser/parser-helpers.c | 24 ++------------------- |
12 | include/qemu/host-utils.h | 81 +++++++++++++++++++++++++++++++++ | 8 | 1 file changed, 2 insertions(+), 22 deletions(-) |
13 | 2 files changed, 81 insertions(+), 82 deletions(-) | ||
14 | 9 | ||
15 | diff --git a/include/fpu/softfloat-macros.h b/include/fpu/softfloat-macros.h | 10 | diff --git a/target/hexagon/idef-parser/parser-helpers.c b/target/hexagon/idef-parser/parser-helpers.c |
16 | index XXXXXXX..XXXXXXX 100644 | 11 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/include/fpu/softfloat-macros.h | 12 | --- a/target/hexagon/idef-parser/parser-helpers.c |
18 | +++ b/include/fpu/softfloat-macros.h | 13 | +++ b/target/hexagon/idef-parser/parser-helpers.c |
19 | @@ -XXX,XX +XXX,XX @@ | 14 | @@ -XXX,XX +XXX,XX @@ HexValue gen_tmp(Context *c, |
20 | * so some portions are provided under: | 15 | return rvalue; |
21 | * the SoftFloat-2a license | ||
22 | * the BSD license | ||
23 | - * GPL-v2-or-later | ||
24 | * | ||
25 | * Any future contributions to this file after December 1st 2014 will be | ||
26 | * taken to be licensed under the Softfloat-2a license unless specifically | ||
27 | @@ -XXX,XX +XXX,XX @@ this code that are retained. | ||
28 | * THE POSSIBILITY OF SUCH DAMAGE. | ||
29 | */ | ||
30 | |||
31 | -/* Portions of this work are licensed under the terms of the GNU GPL, | ||
32 | - * version 2 or later. See the COPYING file in the top-level directory. | ||
33 | - */ | ||
34 | - | ||
35 | #ifndef FPU_SOFTFLOAT_MACROS_H | ||
36 | #define FPU_SOFTFLOAT_MACROS_H | ||
37 | |||
38 | @@ -XXX,XX +XXX,XX @@ static inline uint64_t estimateDiv128To64(uint64_t a0, uint64_t a1, uint64_t b) | ||
39 | |||
40 | } | 16 | } |
41 | 17 | ||
42 | -/* From the GNU Multi Precision Library - longlong.h __udiv_qrnnd | 18 | -HexValue gen_tmp_local(Context *c, |
43 | - * (https://gmplib.org/repo/gmp/file/tip/longlong.h) | 19 | - YYLTYPE *locp, |
44 | - * | 20 | - unsigned bit_width, |
45 | - * Licensed under the GPLv2/LGPLv3 | 21 | - HexSignedness signedness) |
46 | - */ | ||
47 | -static inline uint64_t udiv_qrnnd(uint64_t *r, uint64_t n1, | ||
48 | - uint64_t n0, uint64_t d) | ||
49 | -{ | 22 | -{ |
50 | -#if defined(__x86_64__) | 23 | - HexValue rvalue; |
51 | - uint64_t q; | 24 | - assert(bit_width == 32 || bit_width == 64); |
52 | - asm("divq %4" : "=a"(q), "=d"(*r) : "0"(n0), "1"(n1), "rm"(d)); | 25 | - memset(&rvalue, 0, sizeof(HexValue)); |
53 | - return q; | 26 | - rvalue.type = TEMP; |
54 | -#elif defined(__s390x__) && !defined(__clang__) | 27 | - rvalue.bit_width = bit_width; |
55 | - /* Need to use a TImode type to get an even register pair for DLGR. */ | 28 | - rvalue.signedness = signedness; |
56 | - unsigned __int128 n = (unsigned __int128)n1 << 64 | n0; | 29 | - rvalue.is_dotnew = false; |
57 | - asm("dlgr %0, %1" : "+r"(n) : "r"(d)); | 30 | - rvalue.is_manual = false; |
58 | - *r = n >> 64; | 31 | - rvalue.tmp.index = c->inst.tmp_count; |
59 | - return n; | 32 | - OUT(c, locp, "TCGv_i", &bit_width, " tmp_", &c->inst.tmp_count, |
60 | -#elif defined(_ARCH_PPC64) && defined(_ARCH_PWR7) | 33 | - " = tcg_temp_new_i", &bit_width, "();\n"); |
61 | - /* From Power ISA 2.06, programming note for divdeu. */ | 34 | - c->inst.tmp_count++; |
62 | - uint64_t q1, q2, Q, r1, r2, R; | 35 | - return rvalue; |
63 | - asm("divdeu %0,%2,%4; divdu %1,%3,%4" | ||
64 | - : "=&r"(q1), "=r"(q2) | ||
65 | - : "r"(n1), "r"(n0), "r"(d)); | ||
66 | - r1 = -(q1 * d); /* low part of (n1<<64) - (q1 * d) */ | ||
67 | - r2 = n0 - (q2 * d); | ||
68 | - Q = q1 + q2; | ||
69 | - R = r1 + r2; | ||
70 | - if (R >= d || R < r2) { /* overflow implies R > d */ | ||
71 | - Q += 1; | ||
72 | - R -= d; | ||
73 | - } | ||
74 | - *r = R; | ||
75 | - return Q; | ||
76 | -#else | ||
77 | - uint64_t d0, d1, q0, q1, r1, r0, m; | ||
78 | - | ||
79 | - d0 = (uint32_t)d; | ||
80 | - d1 = d >> 32; | ||
81 | - | ||
82 | - r1 = n1 % d1; | ||
83 | - q1 = n1 / d1; | ||
84 | - m = q1 * d0; | ||
85 | - r1 = (r1 << 32) | (n0 >> 32); | ||
86 | - if (r1 < m) { | ||
87 | - q1 -= 1; | ||
88 | - r1 += d; | ||
89 | - if (r1 >= d) { | ||
90 | - if (r1 < m) { | ||
91 | - q1 -= 1; | ||
92 | - r1 += d; | ||
93 | - } | ||
94 | - } | ||
95 | - } | ||
96 | - r1 -= m; | ||
97 | - | ||
98 | - r0 = r1 % d1; | ||
99 | - q0 = r1 / d1; | ||
100 | - m = q0 * d0; | ||
101 | - r0 = (r0 << 32) | (uint32_t)n0; | ||
102 | - if (r0 < m) { | ||
103 | - q0 -= 1; | ||
104 | - r0 += d; | ||
105 | - if (r0 >= d) { | ||
106 | - if (r0 < m) { | ||
107 | - q0 -= 1; | ||
108 | - r0 += d; | ||
109 | - } | ||
110 | - } | ||
111 | - } | ||
112 | - r0 -= m; | ||
113 | - | ||
114 | - *r = r0; | ||
115 | - return (q1 << 32) | q0; | ||
116 | -#endif | ||
117 | -} | 36 | -} |
118 | - | 37 | - |
119 | /*---------------------------------------------------------------------------- | 38 | HexValue gen_tmp_value(Context *c, |
120 | | Returns an approximation to the square root of the 32-bit significand given | 39 | YYLTYPE *locp, |
121 | | by `a'. Considered as an integer, `a' must be at least 2^31. If bit 0 of | 40 | const char *value, |
122 | diff --git a/include/qemu/host-utils.h b/include/qemu/host-utils.h | 41 | @@ -XXX,XX +XXX,XX @@ HexValue gen_rvalue_sat(Context *c, YYLTYPE *locp, HexSat *sat, |
123 | index XXXXXXX..XXXXXXX 100644 | 42 | assert_signedness(c, locp, sat->signedness); |
124 | --- a/include/qemu/host-utils.h | 43 | |
125 | +++ b/include/qemu/host-utils.h | 44 | unsigned_str = (sat->signedness == UNSIGNED) ? "u" : ""; |
126 | @@ -XXX,XX +XXX,XX @@ | 45 | - res = gen_tmp_local(c, locp, value->bit_width, sat->signedness); |
127 | * THE SOFTWARE. | 46 | - ovfl = gen_tmp_local(c, locp, 32, sat->signedness); |
128 | */ | 47 | + res = gen_tmp(c, locp, value->bit_width, sat->signedness); |
129 | 48 | + ovfl = gen_tmp(c, locp, 32, sat->signedness); | |
130 | +/* Portions of this work are licensed under the terms of the GNU GPL, | 49 | OUT(c, locp, "gen_sat", unsigned_str, "_", bit_suffix, "_ovfl("); |
131 | + * version 2 or later. See the COPYING file in the top-level directory. | 50 | OUT(c, locp, &ovfl, ", ", &res, ", ", value, ", ", &width->imm.value, |
132 | + */ | 51 | ");\n"); |
133 | + | ||
134 | #ifndef HOST_UTILS_H | ||
135 | #define HOST_UTILS_H | ||
136 | |||
137 | @@ -XXX,XX +XXX,XX @@ void urshift(uint64_t *plow, uint64_t *phigh, int32_t shift); | ||
138 | */ | ||
139 | void ulshift(uint64_t *plow, uint64_t *phigh, int32_t shift, bool *overflow); | ||
140 | |||
141 | +/* From the GNU Multi Precision Library - longlong.h __udiv_qrnnd | ||
142 | + * (https://gmplib.org/repo/gmp/file/tip/longlong.h) | ||
143 | + * | ||
144 | + * Licensed under the GPLv2/LGPLv3 | ||
145 | + */ | ||
146 | +static inline uint64_t udiv_qrnnd(uint64_t *r, uint64_t n1, | ||
147 | + uint64_t n0, uint64_t d) | ||
148 | +{ | ||
149 | +#if defined(__x86_64__) | ||
150 | + uint64_t q; | ||
151 | + asm("divq %4" : "=a"(q), "=d"(*r) : "0"(n0), "1"(n1), "rm"(d)); | ||
152 | + return q; | ||
153 | +#elif defined(__s390x__) && !defined(__clang__) | ||
154 | + /* Need to use a TImode type to get an even register pair for DLGR. */ | ||
155 | + unsigned __int128 n = (unsigned __int128)n1 << 64 | n0; | ||
156 | + asm("dlgr %0, %1" : "+r"(n) : "r"(d)); | ||
157 | + *r = n >> 64; | ||
158 | + return n; | ||
159 | +#elif defined(_ARCH_PPC64) && defined(_ARCH_PWR7) | ||
160 | + /* From Power ISA 2.06, programming note for divdeu. */ | ||
161 | + uint64_t q1, q2, Q, r1, r2, R; | ||
162 | + asm("divdeu %0,%2,%4; divdu %1,%3,%4" | ||
163 | + : "=&r"(q1), "=r"(q2) | ||
164 | + : "r"(n1), "r"(n0), "r"(d)); | ||
165 | + r1 = -(q1 * d); /* low part of (n1<<64) - (q1 * d) */ | ||
166 | + r2 = n0 - (q2 * d); | ||
167 | + Q = q1 + q2; | ||
168 | + R = r1 + r2; | ||
169 | + if (R >= d || R < r2) { /* overflow implies R > d */ | ||
170 | + Q += 1; | ||
171 | + R -= d; | ||
172 | + } | ||
173 | + *r = R; | ||
174 | + return Q; | ||
175 | +#else | ||
176 | + uint64_t d0, d1, q0, q1, r1, r0, m; | ||
177 | + | ||
178 | + d0 = (uint32_t)d; | ||
179 | + d1 = d >> 32; | ||
180 | + | ||
181 | + r1 = n1 % d1; | ||
182 | + q1 = n1 / d1; | ||
183 | + m = q1 * d0; | ||
184 | + r1 = (r1 << 32) | (n0 >> 32); | ||
185 | + if (r1 < m) { | ||
186 | + q1 -= 1; | ||
187 | + r1 += d; | ||
188 | + if (r1 >= d) { | ||
189 | + if (r1 < m) { | ||
190 | + q1 -= 1; | ||
191 | + r1 += d; | ||
192 | + } | ||
193 | + } | ||
194 | + } | ||
195 | + r1 -= m; | ||
196 | + | ||
197 | + r0 = r1 % d1; | ||
198 | + q0 = r1 / d1; | ||
199 | + m = q0 * d0; | ||
200 | + r0 = (r0 << 32) | (uint32_t)n0; | ||
201 | + if (r0 < m) { | ||
202 | + q0 -= 1; | ||
203 | + r0 += d; | ||
204 | + if (r0 >= d) { | ||
205 | + if (r0 < m) { | ||
206 | + q0 -= 1; | ||
207 | + r0 += d; | ||
208 | + } | ||
209 | + } | ||
210 | + } | ||
211 | + r0 -= m; | ||
212 | + | ||
213 | + *r = r0; | ||
214 | + return (q1 << 32) | q0; | ||
215 | +#endif | ||
216 | +} | ||
217 | + | ||
218 | #endif | ||
219 | -- | 52 | -- |
220 | 2.25.1 | 53 | 2.34.1 |
221 | 54 | ||
222 | 55 | diff view generated by jsdifflib |
1 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 1 | This wasn't actually used at all, just some unused |
---|---|---|---|
2 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | 2 | macro re-definitions. |
3 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 3 | |
4 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
5 | --- | 6 | --- |
6 | tcg/optimize.c | 9 ++++++--- | 7 | target/hppa/translate.c | 3 --- |
7 | 1 file changed, 6 insertions(+), 3 deletions(-) | 8 | 1 file changed, 3 deletions(-) |
8 | 9 | ||
9 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 10 | diff --git a/target/hppa/translate.c b/target/hppa/translate.c |
10 | index XXXXXXX..XXXXXXX 100644 | 11 | index XXXXXXX..XXXXXXX 100644 |
11 | --- a/tcg/optimize.c | 12 | --- a/target/hppa/translate.c |
12 | +++ b/tcg/optimize.c | 13 | +++ b/target/hppa/translate.c |
13 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | 14 | @@ -XXX,XX +XXX,XX @@ |
14 | uint64_t z_mask, partmask, affected, tmp; | 15 | #undef TCGv |
15 | TCGOpcode opc = op->opc; | 16 | #undef tcg_temp_new |
16 | const TCGOpDef *def; | 17 | #undef tcg_global_mem_new |
17 | + bool done = false; | 18 | -#undef tcg_temp_local_new |
18 | 19 | #undef tcg_temp_free | |
19 | /* Calls are special. */ | 20 | |
20 | if (opc == INDEX_op_call) { | 21 | #if TARGET_LONG_BITS == 64 |
21 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | 22 | @@ -XXX,XX +XXX,XX @@ |
22 | allocator where needed and possible. Also detect copies. */ | 23 | |
23 | switch (opc) { | 24 | #define tcg_temp_new tcg_temp_new_i64 |
24 | CASE_OP_32_64_VEC(mov): | 25 | #define tcg_global_mem_new tcg_global_mem_new_i64 |
25 | - tcg_opt_gen_mov(&ctx, op, op->args[0], op->args[1]); | 26 | -#define tcg_temp_local_new tcg_temp_local_new_i64 |
26 | - continue; | 27 | #define tcg_temp_free tcg_temp_free_i64 |
27 | + done = tcg_opt_gen_mov(&ctx, op, op->args[0], op->args[1]); | 28 | |
28 | + break; | 29 | #define tcg_gen_movi_reg tcg_gen_movi_i64 |
29 | 30 | @@ -XXX,XX +XXX,XX @@ | |
30 | case INDEX_op_dup_vec: | 31 | #define TCGv_reg TCGv_i32 |
31 | if (arg_is_const(op->args[1])) { | 32 | #define tcg_temp_new tcg_temp_new_i32 |
32 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | 33 | #define tcg_global_mem_new tcg_global_mem_new_i32 |
33 | break; | 34 | -#define tcg_temp_local_new tcg_temp_local_new_i32 |
34 | } | 35 | #define tcg_temp_free tcg_temp_free_i32 |
35 | 36 | ||
36 | - finish_folding(&ctx, op); | 37 | #define tcg_gen_movi_reg tcg_gen_movi_i32 |
37 | + if (!done) { | ||
38 | + finish_folding(&ctx, op); | ||
39 | + } | ||
40 | |||
41 | /* Eliminate duplicate and redundant fence instructions. */ | ||
42 | if (ctx.prev_mb) { | ||
43 | -- | 38 | -- |
44 | 2.25.1 | 39 | 2.34.1 |
45 | 40 | ||
46 | 41 | diff view generated by jsdifflib |
1 | Continue splitting tcg_optimize. | 1 | Since tcg_temp_new is now identical, use that. |
---|---|---|---|
2 | In some cases we can avoid a copy from A0 or T0. | ||
2 | 3 | ||
3 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 4 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
4 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | ||
5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
7 | --- | 6 | --- |
8 | tcg/optimize.c | 22 ++++++++++++++-------- | 7 | target/i386/tcg/translate.c | 27 +++++++++------------------ |
9 | 1 file changed, 14 insertions(+), 8 deletions(-) | 8 | 1 file changed, 9 insertions(+), 18 deletions(-) |
10 | 9 | ||
11 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 10 | diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c |
12 | index XXXXXXX..XXXXXXX 100644 | 11 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/tcg/optimize.c | 12 | --- a/target/i386/tcg/translate.c |
14 | +++ b/tcg/optimize.c | 13 | +++ b/target/i386/tcg/translate.c |
15 | @@ -XXX,XX +XXX,XX @@ static void init_arguments(OptContext *ctx, TCGOp *op, int nb_args) | 14 | @@ -XXX,XX +XXX,XX @@ static bool disas_insn(DisasContext *s, CPUState *cpu) |
16 | } | 15 | if (mod == 3) { |
16 | goto illegal_op; | ||
17 | } | ||
18 | - a0 = tcg_temp_local_new(); | ||
19 | - t0 = tcg_temp_local_new(); | ||
20 | + a0 = s->A0; | ||
21 | + t0 = s->T0; | ||
22 | label1 = gen_new_label(); | ||
23 | |||
24 | - tcg_gen_mov_tl(a0, s->A0); | ||
25 | - tcg_gen_mov_tl(t0, s->T0); | ||
26 | - | ||
27 | gen_set_label(label1); | ||
28 | t1 = tcg_temp_new(); | ||
29 | t2 = tcg_temp_new(); | ||
30 | @@ -XXX,XX +XXX,XX @@ static bool disas_insn(DisasContext *s, CPUState *cpu) | ||
31 | tcg_gen_brcond_tl(TCG_COND_NE, t0, t2, label1); | ||
32 | |||
33 | tcg_temp_free(t2); | ||
34 | - tcg_temp_free(a0); | ||
35 | tcg_gen_neg_tl(s->T0, t0); | ||
36 | - tcg_temp_free(t0); | ||
37 | } else { | ||
38 | tcg_gen_neg_tl(s->T0, s->T0); | ||
39 | if (mod != 3) { | ||
40 | @@ -XXX,XX +XXX,XX @@ static bool disas_insn(DisasContext *s, CPUState *cpu) | ||
41 | #endif | ||
42 | { | ||
43 | TCGLabel *label1; | ||
44 | - TCGv t0, t1, t2, a0; | ||
45 | + TCGv t0, t1, t2; | ||
46 | |||
47 | if (!PE(s) || VM86(s)) | ||
48 | goto illegal_op; | ||
49 | - t0 = tcg_temp_local_new(); | ||
50 | - t1 = tcg_temp_local_new(); | ||
51 | - t2 = tcg_temp_local_new(); | ||
52 | + t0 = tcg_temp_new(); | ||
53 | + t1 = tcg_temp_new(); | ||
54 | + t2 = tcg_temp_new(); | ||
55 | ot = MO_16; | ||
56 | modrm = x86_ldub_code(env, s); | ||
57 | reg = (modrm >> 3) & 7; | ||
58 | @@ -XXX,XX +XXX,XX @@ static bool disas_insn(DisasContext *s, CPUState *cpu) | ||
59 | if (mod != 3) { | ||
60 | gen_lea_modrm(env, s, modrm); | ||
61 | gen_op_ld_v(s, ot, t0, s->A0); | ||
62 | - a0 = tcg_temp_local_new(); | ||
63 | - tcg_gen_mov_tl(a0, s->A0); | ||
64 | } else { | ||
65 | gen_op_mov_v_reg(s, ot, t0, rm); | ||
66 | - a0 = NULL; | ||
67 | } | ||
68 | gen_op_mov_v_reg(s, ot, t1, reg); | ||
69 | tcg_gen_andi_tl(s->tmp0, t0, 3); | ||
70 | @@ -XXX,XX +XXX,XX @@ static bool disas_insn(DisasContext *s, CPUState *cpu) | ||
71 | tcg_gen_movi_tl(t2, CC_Z); | ||
72 | gen_set_label(label1); | ||
73 | if (mod != 3) { | ||
74 | - gen_op_st_v(s, ot, t0, a0); | ||
75 | - tcg_temp_free(a0); | ||
76 | + gen_op_st_v(s, ot, t0, s->A0); | ||
77 | } else { | ||
78 | gen_op_mov_reg_v(s, ot, rm, t0); | ||
79 | } | ||
80 | @@ -XXX,XX +XXX,XX @@ static bool disas_insn(DisasContext *s, CPUState *cpu) | ||
81 | modrm = x86_ldub_code(env, s); | ||
82 | reg = ((modrm >> 3) & 7) | REX_R(s); | ||
83 | gen_ldst_modrm(env, s, modrm, MO_16, OR_TMP0, 0); | ||
84 | - t0 = tcg_temp_local_new(); | ||
85 | + t0 = tcg_temp_new(); | ||
86 | gen_update_cc_op(s); | ||
87 | if (b == 0x102) { | ||
88 | gen_helper_lar(t0, cpu_env, s->T0); | ||
89 | @@ -XXX,XX +XXX,XX @@ static void i386_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cpu) | ||
90 | dc->tmp2_i32 = tcg_temp_new_i32(); | ||
91 | dc->tmp3_i32 = tcg_temp_new_i32(); | ||
92 | dc->tmp4 = tcg_temp_new(); | ||
93 | - dc->cc_srcT = tcg_temp_local_new(); | ||
94 | + dc->cc_srcT = tcg_temp_new(); | ||
17 | } | 95 | } |
18 | 96 | ||
19 | +static void copy_propagate(OptContext *ctx, TCGOp *op, | 97 | static void i386_tr_tb_start(DisasContextBase *db, CPUState *cpu) |
20 | + int nb_oargs, int nb_iargs) | ||
21 | +{ | ||
22 | + TCGContext *s = ctx->tcg; | ||
23 | + | ||
24 | + for (int i = nb_oargs; i < nb_oargs + nb_iargs; i++) { | ||
25 | + TCGTemp *ts = arg_temp(op->args[i]); | ||
26 | + if (ts && ts_is_copy(ts)) { | ||
27 | + op->args[i] = temp_arg(find_better_copy(s, ts)); | ||
28 | + } | ||
29 | + } | ||
30 | +} | ||
31 | + | ||
32 | /* Propagate constants and copies, fold constant expressions. */ | ||
33 | void tcg_optimize(TCGContext *s) | ||
34 | { | ||
35 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
36 | nb_iargs = def->nb_iargs; | ||
37 | } | ||
38 | init_arguments(&ctx, op, nb_oargs + nb_iargs); | ||
39 | - | ||
40 | - /* Do copy propagation */ | ||
41 | - for (i = nb_oargs; i < nb_oargs + nb_iargs; i++) { | ||
42 | - TCGTemp *ts = arg_temp(op->args[i]); | ||
43 | - if (ts && ts_is_copy(ts)) { | ||
44 | - op->args[i] = temp_arg(find_better_copy(s, ts)); | ||
45 | - } | ||
46 | - } | ||
47 | + copy_propagate(&ctx, op, nb_oargs, nb_iargs); | ||
48 | |||
49 | /* For commutative operations make constant second argument */ | ||
50 | switch (opc) { | ||
51 | -- | 98 | -- |
52 | 2.25.1 | 99 | 2.34.1 |
53 | 100 | ||
54 | 101 | diff view generated by jsdifflib |
1 | Adjust the interface to take the OptContext parameter instead | 1 | Since tcg_temp_new is now identical, use that. |
---|---|---|---|
2 | of TCGContext or both. | ||
3 | 2 | ||
4 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 3 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
5 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | ||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
7 | --- | 5 | --- |
8 | tcg/optimize.c | 67 +++++++++++++++++++++++++------------------------- | 6 | target/mips/tcg/translate.c | 57 ++++++------------------ |
9 | 1 file changed, 34 insertions(+), 33 deletions(-) | 7 | target/mips/tcg/nanomips_translate.c.inc | 4 +- |
8 | 2 files changed, 16 insertions(+), 45 deletions(-) | ||
10 | 9 | ||
11 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 10 | diff --git a/target/mips/tcg/translate.c b/target/mips/tcg/translate.c |
12 | index XXXXXXX..XXXXXXX 100644 | 11 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/tcg/optimize.c | 12 | --- a/target/mips/tcg/translate.c |
14 | +++ b/tcg/optimize.c | 13 | +++ b/target/mips/tcg/translate.c |
15 | @@ -XXX,XX +XXX,XX @@ typedef struct TempOptInfo { | 14 | @@ -XXX,XX +XXX,XX @@ static void gen_arith_imm(DisasContext *ctx, uint32_t opc, |
16 | } TempOptInfo; | 15 | switch (opc) { |
17 | 16 | case OPC_ADDI: | |
18 | typedef struct OptContext { | 17 | { |
19 | + TCGContext *tcg; | 18 | - TCGv t0 = tcg_temp_local_new(); |
20 | TCGTempSet temps_used; | 19 | + TCGv t0 = tcg_temp_new(); |
21 | } OptContext; | 20 | TCGv t1 = tcg_temp_new(); |
22 | 21 | TCGv t2 = tcg_temp_new(); | |
23 | @@ -XXX,XX +XXX,XX @@ static bool args_are_copies(TCGArg arg1, TCGArg arg2) | 22 | TCGLabel *l1 = gen_new_label(); |
24 | return ts_are_copies(arg_temp(arg1), arg_temp(arg2)); | 23 | @@ -XXX,XX +XXX,XX @@ static void gen_arith_imm(DisasContext *ctx, uint32_t opc, |
25 | } | 24 | #if defined(TARGET_MIPS64) |
26 | 25 | case OPC_DADDI: | |
27 | -static void tcg_opt_gen_mov(TCGContext *s, TCGOp *op, TCGArg dst, TCGArg src) | 26 | { |
28 | +static void tcg_opt_gen_mov(OptContext *ctx, TCGOp *op, TCGArg dst, TCGArg src) | 27 | - TCGv t0 = tcg_temp_local_new(); |
29 | { | 28 | + TCGv t0 = tcg_temp_new(); |
30 | TCGTemp *dst_ts = arg_temp(dst); | 29 | TCGv t1 = tcg_temp_new(); |
31 | TCGTemp *src_ts = arg_temp(src); | 30 | TCGv t2 = tcg_temp_new(); |
32 | @@ -XXX,XX +XXX,XX @@ static void tcg_opt_gen_mov(TCGContext *s, TCGOp *op, TCGArg dst, TCGArg src) | 31 | TCGLabel *l1 = gen_new_label(); |
33 | TCGOpcode new_op; | 32 | @@ -XXX,XX +XXX,XX @@ static void gen_arith(DisasContext *ctx, uint32_t opc, |
34 | 33 | switch (opc) { | |
35 | if (ts_are_copies(dst_ts, src_ts)) { | 34 | case OPC_ADD: |
36 | - tcg_op_remove(s, op); | 35 | { |
37 | + tcg_op_remove(ctx->tcg, op); | 36 | - TCGv t0 = tcg_temp_local_new(); |
37 | + TCGv t0 = tcg_temp_new(); | ||
38 | TCGv t1 = tcg_temp_new(); | ||
39 | TCGv t2 = tcg_temp_new(); | ||
40 | TCGLabel *l1 = gen_new_label(); | ||
41 | @@ -XXX,XX +XXX,XX @@ static void gen_arith(DisasContext *ctx, uint32_t opc, | ||
42 | break; | ||
43 | case OPC_SUB: | ||
44 | { | ||
45 | - TCGv t0 = tcg_temp_local_new(); | ||
46 | + TCGv t0 = tcg_temp_new(); | ||
47 | TCGv t1 = tcg_temp_new(); | ||
48 | TCGv t2 = tcg_temp_new(); | ||
49 | TCGLabel *l1 = gen_new_label(); | ||
50 | @@ -XXX,XX +XXX,XX @@ static void gen_arith(DisasContext *ctx, uint32_t opc, | ||
51 | #if defined(TARGET_MIPS64) | ||
52 | case OPC_DADD: | ||
53 | { | ||
54 | - TCGv t0 = tcg_temp_local_new(); | ||
55 | + TCGv t0 = tcg_temp_new(); | ||
56 | TCGv t1 = tcg_temp_new(); | ||
57 | TCGv t2 = tcg_temp_new(); | ||
58 | TCGLabel *l1 = gen_new_label(); | ||
59 | @@ -XXX,XX +XXX,XX @@ static void gen_arith(DisasContext *ctx, uint32_t opc, | ||
60 | break; | ||
61 | case OPC_DSUB: | ||
62 | { | ||
63 | - TCGv t0 = tcg_temp_local_new(); | ||
64 | + TCGv t0 = tcg_temp_new(); | ||
65 | TCGv t1 = tcg_temp_new(); | ||
66 | TCGv t2 = tcg_temp_new(); | ||
67 | TCGLabel *l1 = gen_new_label(); | ||
68 | @@ -XXX,XX +XXX,XX @@ static void gen_loongson_integer(DisasContext *ctx, uint32_t opc, | ||
38 | return; | 69 | return; |
39 | } | 70 | } |
40 | 71 | ||
41 | @@ -XXX,XX +XXX,XX @@ static void tcg_opt_gen_mov(TCGContext *s, TCGOp *op, TCGArg dst, TCGArg src) | 72 | - switch (opc) { |
42 | } | 73 | - case OPC_MULT_G_2E: |
43 | } | 74 | - case OPC_MULT_G_2F: |
44 | 75 | - case OPC_MULTU_G_2E: | |
45 | -static void tcg_opt_gen_movi(TCGContext *s, OptContext *ctx, | 76 | - case OPC_MULTU_G_2F: |
46 | - TCGOp *op, TCGArg dst, uint64_t val) | 77 | -#if defined(TARGET_MIPS64) |
47 | +static void tcg_opt_gen_movi(OptContext *ctx, TCGOp *op, | 78 | - case OPC_DMULT_G_2E: |
48 | + TCGArg dst, uint64_t val) | 79 | - case OPC_DMULT_G_2F: |
80 | - case OPC_DMULTU_G_2E: | ||
81 | - case OPC_DMULTU_G_2F: | ||
82 | -#endif | ||
83 | - t0 = tcg_temp_new(); | ||
84 | - t1 = tcg_temp_new(); | ||
85 | - break; | ||
86 | - default: | ||
87 | - t0 = tcg_temp_local_new(); | ||
88 | - t1 = tcg_temp_local_new(); | ||
89 | - break; | ||
90 | - } | ||
91 | - | ||
92 | + t0 = tcg_temp_new(); | ||
93 | + t1 = tcg_temp_new(); | ||
94 | gen_load_gpr(t0, rs); | ||
95 | gen_load_gpr(t1, rt); | ||
96 | |||
97 | @@ -XXX,XX +XXX,XX @@ static void gen_loongson_multimedia(DisasContext *ctx, int rd, int rs, int rt) | ||
98 | TCGCond cond; | ||
99 | |||
100 | opc = MASK_LMMI(ctx->opcode); | ||
101 | - switch (opc) { | ||
102 | - case OPC_ADD_CP2: | ||
103 | - case OPC_SUB_CP2: | ||
104 | - case OPC_DADD_CP2: | ||
105 | - case OPC_DSUB_CP2: | ||
106 | - t0 = tcg_temp_local_new_i64(); | ||
107 | - t1 = tcg_temp_local_new_i64(); | ||
108 | - break; | ||
109 | - default: | ||
110 | - t0 = tcg_temp_new_i64(); | ||
111 | - t1 = tcg_temp_new_i64(); | ||
112 | - break; | ||
113 | - } | ||
114 | - | ||
115 | check_cp1_enabled(ctx); | ||
116 | + | ||
117 | + t0 = tcg_temp_new_i64(); | ||
118 | + t1 = tcg_temp_new_i64(); | ||
119 | gen_load_fpr64(ctx, t0, rs); | ||
120 | gen_load_fpr64(ctx, t1, rt); | ||
121 | |||
122 | @@ -XXX,XX +XXX,XX @@ static void gen_mftr(CPUMIPSState *env, DisasContext *ctx, int rt, int rd, | ||
123 | int u, int sel, int h) | ||
49 | { | 124 | { |
50 | const TCGOpDef *def = &tcg_op_defs[op->opc]; | 125 | int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC); |
51 | TCGType type; | 126 | - TCGv t0 = tcg_temp_local_new(); |
52 | @@ -XXX,XX +XXX,XX @@ static void tcg_opt_gen_movi(TCGContext *s, OptContext *ctx, | 127 | + TCGv t0 = tcg_temp_new(); |
53 | /* Convert movi to mov with constant temp. */ | 128 | |
54 | tv = tcg_constant_internal(type, val); | 129 | if ((env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) == 0 && |
55 | init_ts_info(ctx, tv); | 130 | ((env->tcs[other_tc].CP0_TCBind & (0xf << CP0TCBd_CurVPE)) != |
56 | - tcg_opt_gen_mov(s, op, dst, temp_arg(tv)); | 131 | @@ -XXX,XX +XXX,XX @@ static void gen_mttr(CPUMIPSState *env, DisasContext *ctx, int rd, int rt, |
57 | + tcg_opt_gen_mov(ctx, op, dst, temp_arg(tv)); | 132 | int u, int sel, int h) |
58 | } | ||
59 | |||
60 | static uint64_t do_constant_folding_2(TCGOpcode op, uint64_t x, uint64_t y) | ||
61 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
62 | { | 133 | { |
63 | int nb_temps, nb_globals, i; | 134 | int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC); |
64 | TCGOp *op, *op_next, *prev_mb = NULL; | 135 | - TCGv t0 = tcg_temp_local_new(); |
65 | - OptContext ctx = {}; | 136 | + TCGv t0 = tcg_temp_new(); |
66 | + OptContext ctx = { .tcg = s }; | 137 | |
67 | 138 | gen_load_gpr(t0, rt); | |
68 | /* Array VALS has an element for each temp. | 139 | if ((env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) == 0 && |
69 | If this temp holds a constant then its value is kept in VALS' element. | 140 | @@ -XXX,XX +XXX,XX @@ static void gen_flt3_arith(DisasContext *ctx, uint32_t opc, |
70 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | 141 | case OPC_ALNV_PS: |
71 | CASE_OP_32_64(rotr): | 142 | check_ps(ctx); |
72 | if (arg_is_const(op->args[1]) | 143 | { |
73 | && arg_info(op->args[1])->val == 0) { | 144 | - TCGv t0 = tcg_temp_local_new(); |
74 | - tcg_opt_gen_movi(s, &ctx, op, op->args[0], 0); | 145 | + TCGv t0 = tcg_temp_new(); |
75 | + tcg_opt_gen_movi(&ctx, op, op->args[0], 0); | 146 | TCGv_i32 fp = tcg_temp_new_i32(); |
76 | continue; | 147 | TCGv_i32 fph = tcg_temp_new_i32(); |
77 | } | 148 | TCGLabel *l1 = gen_new_label(); |
78 | break; | 149 | diff --git a/target/mips/tcg/nanomips_translate.c.inc b/target/mips/tcg/nanomips_translate.c.inc |
79 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | 150 | index XXXXXXX..XXXXXXX 100644 |
80 | if (!arg_is_const(op->args[1]) | 151 | --- a/target/mips/tcg/nanomips_translate.c.inc |
81 | && arg_is_const(op->args[2]) | 152 | +++ b/target/mips/tcg/nanomips_translate.c.inc |
82 | && arg_info(op->args[2])->val == 0) { | 153 | @@ -XXX,XX +XXX,XX @@ static void gen_llwp(DisasContext *ctx, uint32_t base, int16_t offset, |
83 | - tcg_opt_gen_mov(s, op, op->args[0], op->args[1]); | 154 | static void gen_scwp(DisasContext *ctx, uint32_t base, int16_t offset, |
84 | + tcg_opt_gen_mov(&ctx, op, op->args[0], op->args[1]); | 155 | uint32_t reg1, uint32_t reg2, bool eva) |
85 | continue; | 156 | { |
86 | } | 157 | - TCGv taddr = tcg_temp_local_new(); |
87 | break; | 158 | - TCGv lladdr = tcg_temp_local_new(); |
88 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | 159 | + TCGv taddr = tcg_temp_new(); |
89 | if (!arg_is_const(op->args[1]) | 160 | + TCGv lladdr = tcg_temp_new(); |
90 | && arg_is_const(op->args[2]) | 161 | TCGv_i64 tval = tcg_temp_new_i64(); |
91 | && arg_info(op->args[2])->val == -1) { | 162 | TCGv_i64 llval = tcg_temp_new_i64(); |
92 | - tcg_opt_gen_mov(s, op, op->args[0], op->args[1]); | 163 | TCGv_i64 val = tcg_temp_new_i64(); |
93 | + tcg_opt_gen_mov(&ctx, op, op->args[0], op->args[1]); | ||
94 | continue; | ||
95 | } | ||
96 | break; | ||
97 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
98 | |||
99 | if (partmask == 0) { | ||
100 | tcg_debug_assert(nb_oargs == 1); | ||
101 | - tcg_opt_gen_movi(s, &ctx, op, op->args[0], 0); | ||
102 | + tcg_opt_gen_movi(&ctx, op, op->args[0], 0); | ||
103 | continue; | ||
104 | } | ||
105 | if (affected == 0) { | ||
106 | tcg_debug_assert(nb_oargs == 1); | ||
107 | - tcg_opt_gen_mov(s, op, op->args[0], op->args[1]); | ||
108 | + tcg_opt_gen_mov(&ctx, op, op->args[0], op->args[1]); | ||
109 | continue; | ||
110 | } | ||
111 | |||
112 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
113 | CASE_OP_32_64(mulsh): | ||
114 | if (arg_is_const(op->args[2]) | ||
115 | && arg_info(op->args[2])->val == 0) { | ||
116 | - tcg_opt_gen_movi(s, &ctx, op, op->args[0], 0); | ||
117 | + tcg_opt_gen_movi(&ctx, op, op->args[0], 0); | ||
118 | continue; | ||
119 | } | ||
120 | break; | ||
121 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
122 | CASE_OP_32_64_VEC(or): | ||
123 | CASE_OP_32_64_VEC(and): | ||
124 | if (args_are_copies(op->args[1], op->args[2])) { | ||
125 | - tcg_opt_gen_mov(s, op, op->args[0], op->args[1]); | ||
126 | + tcg_opt_gen_mov(&ctx, op, op->args[0], op->args[1]); | ||
127 | continue; | ||
128 | } | ||
129 | break; | ||
130 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
131 | CASE_OP_32_64_VEC(sub): | ||
132 | CASE_OP_32_64_VEC(xor): | ||
133 | if (args_are_copies(op->args[1], op->args[2])) { | ||
134 | - tcg_opt_gen_movi(s, &ctx, op, op->args[0], 0); | ||
135 | + tcg_opt_gen_movi(&ctx, op, op->args[0], 0); | ||
136 | continue; | ||
137 | } | ||
138 | break; | ||
139 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
140 | allocator where needed and possible. Also detect copies. */ | ||
141 | switch (opc) { | ||
142 | CASE_OP_32_64_VEC(mov): | ||
143 | - tcg_opt_gen_mov(s, op, op->args[0], op->args[1]); | ||
144 | + tcg_opt_gen_mov(&ctx, op, op->args[0], op->args[1]); | ||
145 | continue; | ||
146 | |||
147 | case INDEX_op_dup_vec: | ||
148 | if (arg_is_const(op->args[1])) { | ||
149 | tmp = arg_info(op->args[1])->val; | ||
150 | tmp = dup_const(TCGOP_VECE(op), tmp); | ||
151 | - tcg_opt_gen_movi(s, &ctx, op, op->args[0], tmp); | ||
152 | + tcg_opt_gen_movi(&ctx, op, op->args[0], tmp); | ||
153 | continue; | ||
154 | } | ||
155 | break; | ||
156 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
157 | case INDEX_op_dup2_vec: | ||
158 | assert(TCG_TARGET_REG_BITS == 32); | ||
159 | if (arg_is_const(op->args[1]) && arg_is_const(op->args[2])) { | ||
160 | - tcg_opt_gen_movi(s, &ctx, op, op->args[0], | ||
161 | + tcg_opt_gen_movi(&ctx, op, op->args[0], | ||
162 | deposit64(arg_info(op->args[1])->val, 32, 32, | ||
163 | arg_info(op->args[2])->val)); | ||
164 | continue; | ||
165 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
166 | case INDEX_op_extrh_i64_i32: | ||
167 | if (arg_is_const(op->args[1])) { | ||
168 | tmp = do_constant_folding(opc, arg_info(op->args[1])->val, 0); | ||
169 | - tcg_opt_gen_movi(s, &ctx, op, op->args[0], tmp); | ||
170 | + tcg_opt_gen_movi(&ctx, op, op->args[0], tmp); | ||
171 | continue; | ||
172 | } | ||
173 | break; | ||
174 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
175 | if (arg_is_const(op->args[1])) { | ||
176 | tmp = do_constant_folding(opc, arg_info(op->args[1])->val, | ||
177 | op->args[2]); | ||
178 | - tcg_opt_gen_movi(s, &ctx, op, op->args[0], tmp); | ||
179 | + tcg_opt_gen_movi(&ctx, op, op->args[0], tmp); | ||
180 | continue; | ||
181 | } | ||
182 | break; | ||
183 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
184 | if (arg_is_const(op->args[1]) && arg_is_const(op->args[2])) { | ||
185 | tmp = do_constant_folding(opc, arg_info(op->args[1])->val, | ||
186 | arg_info(op->args[2])->val); | ||
187 | - tcg_opt_gen_movi(s, &ctx, op, op->args[0], tmp); | ||
188 | + tcg_opt_gen_movi(&ctx, op, op->args[0], tmp); | ||
189 | continue; | ||
190 | } | ||
191 | break; | ||
192 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
193 | TCGArg v = arg_info(op->args[1])->val; | ||
194 | if (v != 0) { | ||
195 | tmp = do_constant_folding(opc, v, 0); | ||
196 | - tcg_opt_gen_movi(s, &ctx, op, op->args[0], tmp); | ||
197 | + tcg_opt_gen_movi(&ctx, op, op->args[0], tmp); | ||
198 | } else { | ||
199 | - tcg_opt_gen_mov(s, op, op->args[0], op->args[2]); | ||
200 | + tcg_opt_gen_mov(&ctx, op, op->args[0], op->args[2]); | ||
201 | } | ||
202 | continue; | ||
203 | } | ||
204 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
205 | tmp = deposit64(arg_info(op->args[1])->val, | ||
206 | op->args[3], op->args[4], | ||
207 | arg_info(op->args[2])->val); | ||
208 | - tcg_opt_gen_movi(s, &ctx, op, op->args[0], tmp); | ||
209 | + tcg_opt_gen_movi(&ctx, op, op->args[0], tmp); | ||
210 | continue; | ||
211 | } | ||
212 | break; | ||
213 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
214 | if (arg_is_const(op->args[1])) { | ||
215 | tmp = extract64(arg_info(op->args[1])->val, | ||
216 | op->args[2], op->args[3]); | ||
217 | - tcg_opt_gen_movi(s, &ctx, op, op->args[0], tmp); | ||
218 | + tcg_opt_gen_movi(&ctx, op, op->args[0], tmp); | ||
219 | continue; | ||
220 | } | ||
221 | break; | ||
222 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
223 | if (arg_is_const(op->args[1])) { | ||
224 | tmp = sextract64(arg_info(op->args[1])->val, | ||
225 | op->args[2], op->args[3]); | ||
226 | - tcg_opt_gen_movi(s, &ctx, op, op->args[0], tmp); | ||
227 | + tcg_opt_gen_movi(&ctx, op, op->args[0], tmp); | ||
228 | continue; | ||
229 | } | ||
230 | break; | ||
231 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
232 | tmp = (int32_t)(((uint32_t)v1 >> shr) | | ||
233 | ((uint32_t)v2 << (32 - shr))); | ||
234 | } | ||
235 | - tcg_opt_gen_movi(s, &ctx, op, op->args[0], tmp); | ||
236 | + tcg_opt_gen_movi(&ctx, op, op->args[0], tmp); | ||
237 | continue; | ||
238 | } | ||
239 | break; | ||
240 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
241 | tmp = do_constant_folding_cond(opc, op->args[1], | ||
242 | op->args[2], op->args[3]); | ||
243 | if (tmp != 2) { | ||
244 | - tcg_opt_gen_movi(s, &ctx, op, op->args[0], tmp); | ||
245 | + tcg_opt_gen_movi(&ctx, op, op->args[0], tmp); | ||
246 | continue; | ||
247 | } | ||
248 | break; | ||
249 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
250 | tmp = do_constant_folding_cond(opc, op->args[1], | ||
251 | op->args[2], op->args[5]); | ||
252 | if (tmp != 2) { | ||
253 | - tcg_opt_gen_mov(s, op, op->args[0], op->args[4-tmp]); | ||
254 | + tcg_opt_gen_mov(&ctx, op, op->args[0], op->args[4-tmp]); | ||
255 | continue; | ||
256 | } | ||
257 | if (arg_is_const(op->args[3]) && arg_is_const(op->args[4])) { | ||
258 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
259 | |||
260 | rl = op->args[0]; | ||
261 | rh = op->args[1]; | ||
262 | - tcg_opt_gen_movi(s, &ctx, op, rl, (int32_t)a); | ||
263 | - tcg_opt_gen_movi(s, &ctx, op2, rh, (int32_t)(a >> 32)); | ||
264 | + tcg_opt_gen_movi(&ctx, op, rl, (int32_t)a); | ||
265 | + tcg_opt_gen_movi(&ctx, op2, rh, (int32_t)(a >> 32)); | ||
266 | continue; | ||
267 | } | ||
268 | break; | ||
269 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
270 | |||
271 | rl = op->args[0]; | ||
272 | rh = op->args[1]; | ||
273 | - tcg_opt_gen_movi(s, &ctx, op, rl, (int32_t)r); | ||
274 | - tcg_opt_gen_movi(s, &ctx, op2, rh, (int32_t)(r >> 32)); | ||
275 | + tcg_opt_gen_movi(&ctx, op, rl, (int32_t)r); | ||
276 | + tcg_opt_gen_movi(&ctx, op2, rh, (int32_t)(r >> 32)); | ||
277 | continue; | ||
278 | } | ||
279 | break; | ||
280 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
281 | op->args[5]); | ||
282 | if (tmp != 2) { | ||
283 | do_setcond_const: | ||
284 | - tcg_opt_gen_movi(s, &ctx, op, op->args[0], tmp); | ||
285 | + tcg_opt_gen_movi(&ctx, op, op->args[0], tmp); | ||
286 | continue; | ||
287 | } | ||
288 | if ((op->args[5] == TCG_COND_LT || op->args[5] == TCG_COND_GE) | ||
289 | -- | 164 | -- |
290 | 2.25.1 | 165 | 2.34.1 |
291 | 166 | ||
292 | 167 | diff view generated by jsdifflib |
1 | From: Luis Pires <luis.pires@eldorado.org.br> | 1 | Since tcg_temp_new is now identical, use that. |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: Luis Pires <luis.pires@eldorado.org.br> | 3 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
4 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
5 | Message-Id: <20211025191154.350831-5-luis.pires@eldorado.org.br> | ||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
7 | --- | 5 | --- |
8 | tests/unit/test-div128.c | 197 +++++++++++++++++++++++++++++++++++++++ | 6 | target/ppc/translate.c | 6 +++--- |
9 | tests/unit/meson.build | 1 + | 7 | target/ppc/translate/spe-impl.c.inc | 8 ++++---- |
10 | 2 files changed, 198 insertions(+) | 8 | target/ppc/translate/vmx-impl.c.inc | 4 ++-- |
11 | create mode 100644 tests/unit/test-div128.c | 9 | 3 files changed, 9 insertions(+), 9 deletions(-) |
12 | 10 | ||
13 | diff --git a/tests/unit/test-div128.c b/tests/unit/test-div128.c | 11 | diff --git a/target/ppc/translate.c b/target/ppc/translate.c |
14 | new file mode 100644 | ||
15 | index XXXXXXX..XXXXXXX | ||
16 | --- /dev/null | ||
17 | +++ b/tests/unit/test-div128.c | ||
18 | @@ -XXX,XX +XXX,XX @@ | ||
19 | +/* | ||
20 | + * Test 128-bit division functions | ||
21 | + * | ||
22 | + * Copyright (c) 2021 Instituto de Pesquisas Eldorado (eldorado.org.br) | ||
23 | + * | ||
24 | + * This library is free software; you can redistribute it and/or | ||
25 | + * modify it under the terms of the GNU Lesser General Public | ||
26 | + * License as published by the Free Software Foundation; either | ||
27 | + * version 2.1 of the License, or (at your option) any later version. | ||
28 | + * | ||
29 | + * This library is distributed in the hope that it will be useful, | ||
30 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
31 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
32 | + * Lesser General Public License for more details. | ||
33 | + * | ||
34 | + * You should have received a copy of the GNU Lesser General Public | ||
35 | + * License along with this library; if not, see <http://www.gnu.org/licenses/>. | ||
36 | + */ | ||
37 | + | ||
38 | +#include "qemu/osdep.h" | ||
39 | +#include "qemu/host-utils.h" | ||
40 | + | ||
41 | +typedef struct { | ||
42 | + uint64_t high; | ||
43 | + uint64_t low; | ||
44 | + uint64_t rhigh; | ||
45 | + uint64_t rlow; | ||
46 | + uint64_t divisor; | ||
47 | + uint64_t remainder; | ||
48 | +} test_data_unsigned; | ||
49 | + | ||
50 | +typedef struct { | ||
51 | + int64_t high; | ||
52 | + uint64_t low; | ||
53 | + int64_t rhigh; | ||
54 | + uint64_t rlow; | ||
55 | + int64_t divisor; | ||
56 | + int64_t remainder; | ||
57 | +} test_data_signed; | ||
58 | + | ||
59 | +static const test_data_unsigned test_table_unsigned[] = { | ||
60 | + /* Dividend fits in 64 bits */ | ||
61 | + { 0x0000000000000000ULL, 0x0000000000000000ULL, | ||
62 | + 0x0000000000000000ULL, 0x0000000000000000ULL, | ||
63 | + 0x0000000000000001ULL, 0x0000000000000000ULL}, | ||
64 | + { 0x0000000000000000ULL, 0x0000000000000001ULL, | ||
65 | + 0x0000000000000000ULL, 0x0000000000000001ULL, | ||
66 | + 0x0000000000000001ULL, 0x0000000000000000ULL}, | ||
67 | + { 0x0000000000000000ULL, 0x0000000000000003ULL, | ||
68 | + 0x0000000000000000ULL, 0x0000000000000001ULL, | ||
69 | + 0x0000000000000002ULL, 0x0000000000000001ULL}, | ||
70 | + { 0x0000000000000000ULL, 0x8000000000000000ULL, | ||
71 | + 0x0000000000000000ULL, 0x8000000000000000ULL, | ||
72 | + 0x0000000000000001ULL, 0x0000000000000000ULL}, | ||
73 | + { 0x0000000000000000ULL, 0xa000000000000000ULL, | ||
74 | + 0x0000000000000000ULL, 0x0000000000000002ULL, | ||
75 | + 0x4000000000000000ULL, 0x2000000000000000ULL}, | ||
76 | + { 0x0000000000000000ULL, 0x8000000000000000ULL, | ||
77 | + 0x0000000000000000ULL, 0x0000000000000001ULL, | ||
78 | + 0x8000000000000000ULL, 0x0000000000000000ULL}, | ||
79 | + | ||
80 | + /* Dividend > 64 bits, with MSB 0 */ | ||
81 | + { 0x123456789abcdefeULL, 0xefedcba987654321ULL, | ||
82 | + 0x123456789abcdefeULL, 0xefedcba987654321ULL, | ||
83 | + 0x0000000000000001ULL, 0x0000000000000000ULL}, | ||
84 | + { 0x123456789abcdefeULL, 0xefedcba987654321ULL, | ||
85 | + 0x0000000000000001ULL, 0x000000000000000dULL, | ||
86 | + 0x123456789abcdefeULL, 0x03456789abcdf03bULL}, | ||
87 | + { 0x123456789abcdefeULL, 0xefedcba987654321ULL, | ||
88 | + 0x0123456789abcdefULL, 0xeefedcba98765432ULL, | ||
89 | + 0x0000000000000010ULL, 0x0000000000000001ULL}, | ||
90 | + | ||
91 | + /* Dividend > 64 bits, with MSB 1 */ | ||
92 | + { 0xfeeddccbbaa99887ULL, 0x766554433221100fULL, | ||
93 | + 0xfeeddccbbaa99887ULL, 0x766554433221100fULL, | ||
94 | + 0x0000000000000001ULL, 0x0000000000000000ULL}, | ||
95 | + { 0xfeeddccbbaa99887ULL, 0x766554433221100fULL, | ||
96 | + 0x0000000000000001ULL, 0x0000000000000000ULL, | ||
97 | + 0xfeeddccbbaa99887ULL, 0x766554433221100fULL}, | ||
98 | + { 0xfeeddccbbaa99887ULL, 0x766554433221100fULL, | ||
99 | + 0x0feeddccbbaa9988ULL, 0x7766554433221100ULL, | ||
100 | + 0x0000000000000010ULL, 0x000000000000000fULL}, | ||
101 | + { 0xfeeddccbbaa99887ULL, 0x766554433221100fULL, | ||
102 | + 0x000000000000000eULL, 0x00f0f0f0f0f0f35aULL, | ||
103 | + 0x123456789abcdefeULL, 0x0f8922bc55ef90c3ULL}, | ||
104 | + | ||
105 | + /** | ||
106 | + * Divisor == 64 bits, with MSB 1 | ||
107 | + * and high 64 bits of dividend >= divisor | ||
108 | + * (for testing normalization) | ||
109 | + */ | ||
110 | + { 0xfeeddccbbaa99887ULL, 0x766554433221100fULL, | ||
111 | + 0x0000000000000001ULL, 0x0000000000000000ULL, | ||
112 | + 0xfeeddccbbaa99887ULL, 0x766554433221100fULL}, | ||
113 | + { 0xfeeddccbbaa99887ULL, 0x766554433221100fULL, | ||
114 | + 0x0000000000000001ULL, 0xfddbb9977553310aULL, | ||
115 | + 0x8000000000000001ULL, 0x78899aabbccddf05ULL}, | ||
116 | + | ||
117 | + /* Dividend > 64 bits, divisor almost as big */ | ||
118 | + { 0x0000000000000001ULL, 0x23456789abcdef01ULL, | ||
119 | + 0x0000000000000000ULL, 0x000000000000000fULL, | ||
120 | + 0x123456789abcdefeULL, 0x123456789abcde1fULL}, | ||
121 | +}; | ||
122 | + | ||
123 | +static const test_data_signed test_table_signed[] = { | ||
124 | + /* Positive dividend, positive/negative divisors */ | ||
125 | + { 0x0000000000000000LL, 0x0000000000bc614eULL, | ||
126 | + 0x0000000000000000LL, 0x0000000000bc614eULL, | ||
127 | + 0x0000000000000001LL, 0x0000000000000000LL}, | ||
128 | + { 0x0000000000000000LL, 0x0000000000bc614eULL, | ||
129 | + 0xffffffffffffffffLL, 0xffffffffff439eb2ULL, | ||
130 | + 0xffffffffffffffffLL, 0x0000000000000000LL}, | ||
131 | + { 0x0000000000000000LL, 0x0000000000bc614eULL, | ||
132 | + 0x0000000000000000LL, 0x00000000005e30a7ULL, | ||
133 | + 0x0000000000000002LL, 0x0000000000000000LL}, | ||
134 | + { 0x0000000000000000LL, 0x0000000000bc614eULL, | ||
135 | + 0xffffffffffffffffLL, 0xffffffffffa1cf59ULL, | ||
136 | + 0xfffffffffffffffeLL, 0x0000000000000000LL}, | ||
137 | + { 0x0000000000000000LL, 0x0000000000bc614eULL, | ||
138 | + 0x0000000000000000LL, 0x0000000000178c29ULL, | ||
139 | + 0x0000000000000008LL, 0x0000000000000006LL}, | ||
140 | + { 0x0000000000000000LL, 0x0000000000bc614eULL, | ||
141 | + 0xffffffffffffffffLL, 0xffffffffffe873d7ULL, | ||
142 | + 0xfffffffffffffff8LL, 0x0000000000000006LL}, | ||
143 | + { 0x0000000000000000LL, 0x0000000000bc614eULL, | ||
144 | + 0x0000000000000000LL, 0x000000000000550dULL, | ||
145 | + 0x0000000000000237LL, 0x0000000000000183LL}, | ||
146 | + { 0x0000000000000000LL, 0x0000000000bc614eULL, | ||
147 | + 0xffffffffffffffffLL, 0xffffffffffffaaf3ULL, | ||
148 | + 0xfffffffffffffdc9LL, 0x0000000000000183LL}, | ||
149 | + | ||
150 | + /* Negative dividend, positive/negative divisors */ | ||
151 | + { 0xffffffffffffffffLL, 0xffffffffff439eb2ULL, | ||
152 | + 0xffffffffffffffffLL, 0xffffffffff439eb2ULL, | ||
153 | + 0x0000000000000001LL, 0x0000000000000000LL}, | ||
154 | + { 0xffffffffffffffffLL, 0xffffffffff439eb2ULL, | ||
155 | + 0x0000000000000000LL, 0x0000000000bc614eULL, | ||
156 | + 0xffffffffffffffffLL, 0x0000000000000000LL}, | ||
157 | + { 0xffffffffffffffffLL, 0xffffffffff439eb2ULL, | ||
158 | + 0xffffffffffffffffLL, 0xffffffffffa1cf59ULL, | ||
159 | + 0x0000000000000002LL, 0x0000000000000000LL}, | ||
160 | + { 0xffffffffffffffffLL, 0xffffffffff439eb2ULL, | ||
161 | + 0x0000000000000000LL, 0x00000000005e30a7ULL, | ||
162 | + 0xfffffffffffffffeLL, 0x0000000000000000LL}, | ||
163 | + { 0xffffffffffffffffLL, 0xffffffffff439eb2ULL, | ||
164 | + 0xffffffffffffffffLL, 0xffffffffffe873d7ULL, | ||
165 | + 0x0000000000000008LL, 0xfffffffffffffffaLL}, | ||
166 | + { 0xffffffffffffffffLL, 0xffffffffff439eb2ULL, | ||
167 | + 0x0000000000000000LL, 0x0000000000178c29ULL, | ||
168 | + 0xfffffffffffffff8LL, 0xfffffffffffffffaLL}, | ||
169 | + { 0xffffffffffffffffLL, 0xffffffffff439eb2ULL, | ||
170 | + 0xffffffffffffffffLL, 0xffffffffffffaaf3ULL, | ||
171 | + 0x0000000000000237LL, 0xfffffffffffffe7dLL}, | ||
172 | + { 0xffffffffffffffffLL, 0xffffffffff439eb2ULL, | ||
173 | + 0x0000000000000000LL, 0x000000000000550dULL, | ||
174 | + 0xfffffffffffffdc9LL, 0xfffffffffffffe7dLL}, | ||
175 | +}; | ||
176 | + | ||
177 | +static void test_divu128(void) | ||
178 | +{ | ||
179 | + int i; | ||
180 | + uint64_t rem; | ||
181 | + test_data_unsigned tmp; | ||
182 | + | ||
183 | + for (i = 0; i < ARRAY_SIZE(test_table_unsigned); ++i) { | ||
184 | + tmp = test_table_unsigned[i]; | ||
185 | + | ||
186 | + rem = divu128(&tmp.low, &tmp.high, tmp.divisor); | ||
187 | + g_assert_cmpuint(tmp.low, ==, tmp.rlow); | ||
188 | + g_assert_cmpuint(tmp.high, ==, tmp.rhigh); | ||
189 | + g_assert_cmpuint(rem, ==, tmp.remainder); | ||
190 | + } | ||
191 | +} | ||
192 | + | ||
193 | +static void test_divs128(void) | ||
194 | +{ | ||
195 | + int i; | ||
196 | + int64_t rem; | ||
197 | + test_data_signed tmp; | ||
198 | + | ||
199 | + for (i = 0; i < ARRAY_SIZE(test_table_signed); ++i) { | ||
200 | + tmp = test_table_signed[i]; | ||
201 | + | ||
202 | + rem = divs128(&tmp.low, &tmp.high, tmp.divisor); | ||
203 | + g_assert_cmpuint(tmp.low, ==, tmp.rlow); | ||
204 | + g_assert_cmpuint(tmp.high, ==, tmp.rhigh); | ||
205 | + g_assert_cmpuint(rem, ==, tmp.remainder); | ||
206 | + } | ||
207 | +} | ||
208 | + | ||
209 | +int main(int argc, char **argv) | ||
210 | +{ | ||
211 | + g_test_init(&argc, &argv, NULL); | ||
212 | + g_test_add_func("/host-utils/test_divu128", test_divu128); | ||
213 | + g_test_add_func("/host-utils/test_divs128", test_divs128); | ||
214 | + return g_test_run(); | ||
215 | +} | ||
216 | diff --git a/tests/unit/meson.build b/tests/unit/meson.build | ||
217 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
218 | --- a/tests/unit/meson.build | 13 | --- a/target/ppc/translate.c |
219 | +++ b/tests/unit/meson.build | 14 | +++ b/target/ppc/translate.c |
220 | @@ -XXX,XX +XXX,XX @@ tests = { | 15 | @@ -XXX,XX +XXX,XX @@ static void gen_bcond(DisasContext *ctx, int type) |
221 | # all code tested by test-x86-cpuid is inside topology.h | 16 | TCGv target; |
222 | 'test-x86-cpuid': [], | 17 | |
223 | 'test-cutils': [], | 18 | if (type == BCOND_LR || type == BCOND_CTR || type == BCOND_TAR) { |
224 | + 'test-div128': [], | 19 | - target = tcg_temp_local_new(); |
225 | 'test-shift128': [], | 20 | + target = tcg_temp_new(); |
226 | 'test-mul64': [], | 21 | if (type == BCOND_CTR) { |
227 | # all code tested by test-int128 is inside int128.h | 22 | tcg_gen_mov_tl(target, cpu_ctr); |
23 | } else if (type == BCOND_TAR) { | ||
24 | @@ -XXX,XX +XXX,XX @@ static inline void gen_405_mulladd_insn(DisasContext *ctx, int opc2, int opc3, | ||
25 | { | ||
26 | TCGv t0, t1; | ||
27 | |||
28 | - t0 = tcg_temp_local_new(); | ||
29 | - t1 = tcg_temp_local_new(); | ||
30 | + t0 = tcg_temp_new(); | ||
31 | + t1 = tcg_temp_new(); | ||
32 | |||
33 | switch (opc3 & 0x0D) { | ||
34 | case 0x05: | ||
35 | diff --git a/target/ppc/translate/spe-impl.c.inc b/target/ppc/translate/spe-impl.c.inc | ||
36 | index XXXXXXX..XXXXXXX 100644 | ||
37 | --- a/target/ppc/translate/spe-impl.c.inc | ||
38 | +++ b/target/ppc/translate/spe-impl.c.inc | ||
39 | @@ -XXX,XX +XXX,XX @@ static inline void gen_op_evsrwu(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) | ||
40 | { | ||
41 | TCGLabel *l1 = gen_new_label(); | ||
42 | TCGLabel *l2 = gen_new_label(); | ||
43 | - TCGv_i32 t0 = tcg_temp_local_new_i32(); | ||
44 | + TCGv_i32 t0 = tcg_temp_new_i32(); | ||
45 | |||
46 | /* No error here: 6 bits are used */ | ||
47 | tcg_gen_andi_i32(t0, arg2, 0x3F); | ||
48 | @@ -XXX,XX +XXX,XX @@ static inline void gen_op_evsrws(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) | ||
49 | { | ||
50 | TCGLabel *l1 = gen_new_label(); | ||
51 | TCGLabel *l2 = gen_new_label(); | ||
52 | - TCGv_i32 t0 = tcg_temp_local_new_i32(); | ||
53 | + TCGv_i32 t0 = tcg_temp_new_i32(); | ||
54 | |||
55 | /* No error here: 6 bits are used */ | ||
56 | tcg_gen_andi_i32(t0, arg2, 0x3F); | ||
57 | @@ -XXX,XX +XXX,XX @@ static inline void gen_op_evslw(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) | ||
58 | { | ||
59 | TCGLabel *l1 = gen_new_label(); | ||
60 | TCGLabel *l2 = gen_new_label(); | ||
61 | - TCGv_i32 t0 = tcg_temp_local_new_i32(); | ||
62 | + TCGv_i32 t0 = tcg_temp_new_i32(); | ||
63 | |||
64 | /* No error here: 6 bits are used */ | ||
65 | tcg_gen_andi_i32(t0, arg2, 0x3F); | ||
66 | @@ -XXX,XX +XXX,XX @@ static inline void gen_evsel(DisasContext *ctx) | ||
67 | TCGLabel *l2 = gen_new_label(); | ||
68 | TCGLabel *l3 = gen_new_label(); | ||
69 | TCGLabel *l4 = gen_new_label(); | ||
70 | - TCGv_i32 t0 = tcg_temp_local_new_i32(); | ||
71 | + TCGv_i32 t0 = tcg_temp_new_i32(); | ||
72 | |||
73 | tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 3); | ||
74 | tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1); | ||
75 | diff --git a/target/ppc/translate/vmx-impl.c.inc b/target/ppc/translate/vmx-impl.c.inc | ||
76 | index XXXXXXX..XXXXXXX 100644 | ||
77 | --- a/target/ppc/translate/vmx-impl.c.inc | ||
78 | +++ b/target/ppc/translate/vmx-impl.c.inc | ||
79 | @@ -XXX,XX +XXX,XX @@ static bool do_vcmpq(DisasContext *ctx, arg_VX_bf *a, bool sign) | ||
80 | REQUIRE_INSNS_FLAGS2(ctx, ISA310); | ||
81 | REQUIRE_VECTOR(ctx); | ||
82 | |||
83 | - vra = tcg_temp_local_new_i64(); | ||
84 | - vrb = tcg_temp_local_new_i64(); | ||
85 | + vra = tcg_temp_new_i64(); | ||
86 | + vrb = tcg_temp_new_i64(); | ||
87 | gt = gen_new_label(); | ||
88 | lt = gen_new_label(); | ||
89 | done = gen_new_label(); | ||
228 | -- | 90 | -- |
229 | 2.25.1 | 91 | 2.34.1 |
230 | 92 | ||
231 | 93 | diff view generated by jsdifflib |
1 | Split out a whole bunch of placeholder functions, which are | 1 | Since tcg_temp_new_* is now identical, use those. |
---|---|---|---|
2 | currently identical. That won't last as more code gets moved. | ||
3 | 2 | ||
4 | Use CASE_32_64_VEC for some logical operators that previously | 3 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
5 | missed the addition of vectors. | ||
6 | |||
7 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | ||
8 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | ||
9 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
10 | --- | 5 | --- |
11 | tcg/optimize.c | 271 +++++++++++++++++++++++++++++++++++++++---------- | 6 | target/xtensa/translate.c | 16 ++++++++-------- |
12 | 1 file changed, 219 insertions(+), 52 deletions(-) | 7 | 1 file changed, 8 insertions(+), 8 deletions(-) |
13 | 8 | ||
14 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 9 | diff --git a/target/xtensa/translate.c b/target/xtensa/translate.c |
15 | index XXXXXXX..XXXXXXX 100644 | 10 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/tcg/optimize.c | 11 | --- a/target/xtensa/translate.c |
17 | +++ b/tcg/optimize.c | 12 | +++ b/target/xtensa/translate.c |
18 | @@ -XXX,XX +XXX,XX @@ static void finish_folding(OptContext *ctx, TCGOp *op) | 13 | @@ -XXX,XX +XXX,XX @@ static void gen_right_shift_sar(DisasContext *dc, TCGv_i32 sa) |
14 | static void gen_left_shift_sar(DisasContext *dc, TCGv_i32 sa) | ||
15 | { | ||
16 | if (!dc->sar_m32_allocated) { | ||
17 | - dc->sar_m32 = tcg_temp_local_new_i32(); | ||
18 | + dc->sar_m32 = tcg_temp_new_i32(); | ||
19 | dc->sar_m32_allocated = true; | ||
20 | } | ||
21 | tcg_gen_andi_i32(dc->sar_m32, sa, 0x1f); | ||
22 | @@ -XXX,XX +XXX,XX @@ static void disas_xtensa_insn(CPUXtensaState *env, DisasContext *dc) | ||
23 | if (i == 0 || arg_copy[i].resource != resource) { | ||
24 | resource = arg_copy[i].resource; | ||
25 | if (arg_copy[i].arg->num_bits <= 32) { | ||
26 | - temp = tcg_temp_local_new_i32(); | ||
27 | + temp = tcg_temp_new_i32(); | ||
28 | tcg_gen_mov_i32(temp, arg_copy[i].arg->in); | ||
29 | } else if (arg_copy[i].arg->num_bits <= 64) { | ||
30 | - temp = tcg_temp_local_new_i64(); | ||
31 | + temp = tcg_temp_new_i64(); | ||
32 | tcg_gen_mov_i64(temp, arg_copy[i].arg->in); | ||
33 | } else { | ||
34 | g_assert_not_reached(); | ||
35 | @@ -XXX,XX +XXX,XX @@ static void xtensa_tr_tb_start(DisasContextBase *dcbase, CPUState *cpu) | ||
36 | DisasContext *dc = container_of(dcbase, DisasContext, base); | ||
37 | |||
38 | if (dc->icount) { | ||
39 | - dc->next_icount = tcg_temp_local_new_i32(); | ||
40 | + dc->next_icount = tcg_temp_new_i32(); | ||
19 | } | 41 | } |
20 | } | 42 | } |
21 | 43 | ||
22 | +/* | 44 | @@ -XXX,XX +XXX,XX @@ static void gen_check_atomctl(DisasContext *dc, TCGv_i32 addr) |
23 | + * The fold_* functions return true when processing is complete, | 45 | static void translate_s32c1i(DisasContext *dc, const OpcodeArg arg[], |
24 | + * usually by folding the operation to a constant or to a copy, | 46 | const uint32_t par[]) |
25 | + * and calling tcg_opt_gen_{mov,movi}. They may do other things, | ||
26 | + * like collect information about the value produced, for use in | ||
27 | + * optimizing a subsequent operation. | ||
28 | + * | ||
29 | + * These first fold_* functions are all helpers, used by other | ||
30 | + * folders for more specific operations. | ||
31 | + */ | ||
32 | + | ||
33 | +static bool fold_const1(OptContext *ctx, TCGOp *op) | ||
34 | +{ | ||
35 | + if (arg_is_const(op->args[1])) { | ||
36 | + uint64_t t; | ||
37 | + | ||
38 | + t = arg_info(op->args[1])->val; | ||
39 | + t = do_constant_folding(op->opc, t, 0); | ||
40 | + return tcg_opt_gen_movi(ctx, op, op->args[0], t); | ||
41 | + } | ||
42 | + return false; | ||
43 | +} | ||
44 | + | ||
45 | +static bool fold_const2(OptContext *ctx, TCGOp *op) | ||
46 | +{ | ||
47 | + if (arg_is_const(op->args[1]) && arg_is_const(op->args[2])) { | ||
48 | + uint64_t t1 = arg_info(op->args[1])->val; | ||
49 | + uint64_t t2 = arg_info(op->args[2])->val; | ||
50 | + | ||
51 | + t1 = do_constant_folding(op->opc, t1, t2); | ||
52 | + return tcg_opt_gen_movi(ctx, op, op->args[0], t1); | ||
53 | + } | ||
54 | + return false; | ||
55 | +} | ||
56 | + | ||
57 | +/* | ||
58 | + * These outermost fold_<op> functions are sorted alphabetically. | ||
59 | + */ | ||
60 | + | ||
61 | +static bool fold_add(OptContext *ctx, TCGOp *op) | ||
62 | +{ | ||
63 | + return fold_const2(ctx, op); | ||
64 | +} | ||
65 | + | ||
66 | +static bool fold_and(OptContext *ctx, TCGOp *op) | ||
67 | +{ | ||
68 | + return fold_const2(ctx, op); | ||
69 | +} | ||
70 | + | ||
71 | +static bool fold_andc(OptContext *ctx, TCGOp *op) | ||
72 | +{ | ||
73 | + return fold_const2(ctx, op); | ||
74 | +} | ||
75 | + | ||
76 | static bool fold_call(OptContext *ctx, TCGOp *op) | ||
77 | { | 47 | { |
78 | TCGContext *s = ctx->tcg; | 48 | - TCGv_i32 tmp = tcg_temp_local_new_i32(); |
79 | @@ -XXX,XX +XXX,XX @@ static bool fold_call(OptContext *ctx, TCGOp *op) | 49 | - TCGv_i32 addr = tcg_temp_local_new_i32(); |
80 | return true; | 50 | + TCGv_i32 tmp = tcg_temp_new_i32(); |
81 | } | 51 | + TCGv_i32 addr = tcg_temp_new_i32(); |
82 | 52 | MemOp mop; | |
83 | +static bool fold_ctpop(OptContext *ctx, TCGOp *op) | 53 | |
84 | +{ | 54 | tcg_gen_mov_i32(tmp, arg[0].in); |
85 | + return fold_const1(ctx, op); | 55 | @@ -XXX,XX +XXX,XX @@ static void translate_s32ex(DisasContext *dc, const OpcodeArg arg[], |
86 | +} | 56 | const uint32_t par[]) |
87 | + | ||
88 | +static bool fold_divide(OptContext *ctx, TCGOp *op) | ||
89 | +{ | ||
90 | + return fold_const2(ctx, op); | ||
91 | +} | ||
92 | + | ||
93 | +static bool fold_eqv(OptContext *ctx, TCGOp *op) | ||
94 | +{ | ||
95 | + return fold_const2(ctx, op); | ||
96 | +} | ||
97 | + | ||
98 | +static bool fold_exts(OptContext *ctx, TCGOp *op) | ||
99 | +{ | ||
100 | + return fold_const1(ctx, op); | ||
101 | +} | ||
102 | + | ||
103 | +static bool fold_extu(OptContext *ctx, TCGOp *op) | ||
104 | +{ | ||
105 | + return fold_const1(ctx, op); | ||
106 | +} | ||
107 | + | ||
108 | static bool fold_mb(OptContext *ctx, TCGOp *op) | ||
109 | { | 57 | { |
110 | /* Eliminate duplicate and redundant fence instructions. */ | 58 | TCGv_i32 prev = tcg_temp_new_i32(); |
111 | @@ -XXX,XX +XXX,XX @@ static bool fold_mb(OptContext *ctx, TCGOp *op) | 59 | - TCGv_i32 addr = tcg_temp_local_new_i32(); |
112 | return true; | 60 | - TCGv_i32 res = tcg_temp_local_new_i32(); |
113 | } | 61 | + TCGv_i32 addr = tcg_temp_new_i32(); |
114 | 62 | + TCGv_i32 res = tcg_temp_new_i32(); | |
115 | +static bool fold_mul(OptContext *ctx, TCGOp *op) | 63 | TCGLabel *label = gen_new_label(); |
116 | +{ | 64 | MemOp mop; |
117 | + return fold_const2(ctx, op); | ||
118 | +} | ||
119 | + | ||
120 | +static bool fold_mul_highpart(OptContext *ctx, TCGOp *op) | ||
121 | +{ | ||
122 | + return fold_const2(ctx, op); | ||
123 | +} | ||
124 | + | ||
125 | +static bool fold_nand(OptContext *ctx, TCGOp *op) | ||
126 | +{ | ||
127 | + return fold_const2(ctx, op); | ||
128 | +} | ||
129 | + | ||
130 | +static bool fold_neg(OptContext *ctx, TCGOp *op) | ||
131 | +{ | ||
132 | + return fold_const1(ctx, op); | ||
133 | +} | ||
134 | + | ||
135 | +static bool fold_nor(OptContext *ctx, TCGOp *op) | ||
136 | +{ | ||
137 | + return fold_const2(ctx, op); | ||
138 | +} | ||
139 | + | ||
140 | +static bool fold_not(OptContext *ctx, TCGOp *op) | ||
141 | +{ | ||
142 | + return fold_const1(ctx, op); | ||
143 | +} | ||
144 | + | ||
145 | +static bool fold_or(OptContext *ctx, TCGOp *op) | ||
146 | +{ | ||
147 | + return fold_const2(ctx, op); | ||
148 | +} | ||
149 | + | ||
150 | +static bool fold_orc(OptContext *ctx, TCGOp *op) | ||
151 | +{ | ||
152 | + return fold_const2(ctx, op); | ||
153 | +} | ||
154 | + | ||
155 | static bool fold_qemu_ld(OptContext *ctx, TCGOp *op) | ||
156 | { | ||
157 | /* Opcodes that touch guest memory stop the mb optimization. */ | ||
158 | @@ -XXX,XX +XXX,XX @@ static bool fold_qemu_st(OptContext *ctx, TCGOp *op) | ||
159 | return false; | ||
160 | } | ||
161 | |||
162 | +static bool fold_remainder(OptContext *ctx, TCGOp *op) | ||
163 | +{ | ||
164 | + return fold_const2(ctx, op); | ||
165 | +} | ||
166 | + | ||
167 | +static bool fold_shift(OptContext *ctx, TCGOp *op) | ||
168 | +{ | ||
169 | + return fold_const2(ctx, op); | ||
170 | +} | ||
171 | + | ||
172 | +static bool fold_sub(OptContext *ctx, TCGOp *op) | ||
173 | +{ | ||
174 | + return fold_const2(ctx, op); | ||
175 | +} | ||
176 | + | ||
177 | +static bool fold_xor(OptContext *ctx, TCGOp *op) | ||
178 | +{ | ||
179 | + return fold_const2(ctx, op); | ||
180 | +} | ||
181 | + | ||
182 | /* Propagate constants and copies, fold constant expressions. */ | ||
183 | void tcg_optimize(TCGContext *s) | ||
184 | { | ||
185 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
186 | } | ||
187 | break; | ||
188 | |||
189 | - CASE_OP_32_64(not): | ||
190 | - CASE_OP_32_64(neg): | ||
191 | - CASE_OP_32_64(ext8s): | ||
192 | - CASE_OP_32_64(ext8u): | ||
193 | - CASE_OP_32_64(ext16s): | ||
194 | - CASE_OP_32_64(ext16u): | ||
195 | - CASE_OP_32_64(ctpop): | ||
196 | - case INDEX_op_ext32s_i64: | ||
197 | - case INDEX_op_ext32u_i64: | ||
198 | - case INDEX_op_ext_i32_i64: | ||
199 | - case INDEX_op_extu_i32_i64: | ||
200 | - case INDEX_op_extrl_i64_i32: | ||
201 | - case INDEX_op_extrh_i64_i32: | ||
202 | - if (arg_is_const(op->args[1])) { | ||
203 | - tmp = do_constant_folding(opc, arg_info(op->args[1])->val, 0); | ||
204 | - tcg_opt_gen_movi(&ctx, op, op->args[0], tmp); | ||
205 | - continue; | ||
206 | - } | ||
207 | - break; | ||
208 | - | ||
209 | CASE_OP_32_64(bswap16): | ||
210 | CASE_OP_32_64(bswap32): | ||
211 | case INDEX_op_bswap64_i64: | ||
212 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
213 | } | ||
214 | break; | ||
215 | |||
216 | - CASE_OP_32_64(add): | ||
217 | - CASE_OP_32_64(sub): | ||
218 | - CASE_OP_32_64(mul): | ||
219 | - CASE_OP_32_64(or): | ||
220 | - CASE_OP_32_64(and): | ||
221 | - CASE_OP_32_64(xor): | ||
222 | - CASE_OP_32_64(shl): | ||
223 | - CASE_OP_32_64(shr): | ||
224 | - CASE_OP_32_64(sar): | ||
225 | - CASE_OP_32_64(rotl): | ||
226 | - CASE_OP_32_64(rotr): | ||
227 | - CASE_OP_32_64(andc): | ||
228 | - CASE_OP_32_64(orc): | ||
229 | - CASE_OP_32_64(eqv): | ||
230 | - CASE_OP_32_64(nand): | ||
231 | - CASE_OP_32_64(nor): | ||
232 | - CASE_OP_32_64(muluh): | ||
233 | - CASE_OP_32_64(mulsh): | ||
234 | - CASE_OP_32_64(div): | ||
235 | - CASE_OP_32_64(divu): | ||
236 | - CASE_OP_32_64(rem): | ||
237 | - CASE_OP_32_64(remu): | ||
238 | - if (arg_is_const(op->args[1]) && arg_is_const(op->args[2])) { | ||
239 | - tmp = do_constant_folding(opc, arg_info(op->args[1])->val, | ||
240 | - arg_info(op->args[2])->val); | ||
241 | - tcg_opt_gen_movi(&ctx, op, op->args[0], tmp); | ||
242 | - continue; | ||
243 | - } | ||
244 | - break; | ||
245 | - | ||
246 | CASE_OP_32_64(clz): | ||
247 | CASE_OP_32_64(ctz): | ||
248 | if (arg_is_const(op->args[1])) { | ||
249 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
250 | } | ||
251 | break; | ||
252 | |||
253 | + default: | ||
254 | + break; | ||
255 | + | ||
256 | + /* ---------------------------------------------------------- */ | ||
257 | + /* Sorted alphabetically by opcode as much as possible. */ | ||
258 | + | ||
259 | + CASE_OP_32_64_VEC(add): | ||
260 | + done = fold_add(&ctx, op); | ||
261 | + break; | ||
262 | + CASE_OP_32_64_VEC(and): | ||
263 | + done = fold_and(&ctx, op); | ||
264 | + break; | ||
265 | + CASE_OP_32_64_VEC(andc): | ||
266 | + done = fold_andc(&ctx, op); | ||
267 | + break; | ||
268 | + CASE_OP_32_64(ctpop): | ||
269 | + done = fold_ctpop(&ctx, op); | ||
270 | + break; | ||
271 | + CASE_OP_32_64(div): | ||
272 | + CASE_OP_32_64(divu): | ||
273 | + done = fold_divide(&ctx, op); | ||
274 | + break; | ||
275 | + CASE_OP_32_64(eqv): | ||
276 | + done = fold_eqv(&ctx, op); | ||
277 | + break; | ||
278 | + CASE_OP_32_64(ext8s): | ||
279 | + CASE_OP_32_64(ext16s): | ||
280 | + case INDEX_op_ext32s_i64: | ||
281 | + case INDEX_op_ext_i32_i64: | ||
282 | + done = fold_exts(&ctx, op); | ||
283 | + break; | ||
284 | + CASE_OP_32_64(ext8u): | ||
285 | + CASE_OP_32_64(ext16u): | ||
286 | + case INDEX_op_ext32u_i64: | ||
287 | + case INDEX_op_extu_i32_i64: | ||
288 | + case INDEX_op_extrl_i64_i32: | ||
289 | + case INDEX_op_extrh_i64_i32: | ||
290 | + done = fold_extu(&ctx, op); | ||
291 | + break; | ||
292 | case INDEX_op_mb: | ||
293 | done = fold_mb(&ctx, op); | ||
294 | break; | ||
295 | + CASE_OP_32_64(mul): | ||
296 | + done = fold_mul(&ctx, op); | ||
297 | + break; | ||
298 | + CASE_OP_32_64(mulsh): | ||
299 | + CASE_OP_32_64(muluh): | ||
300 | + done = fold_mul_highpart(&ctx, op); | ||
301 | + break; | ||
302 | + CASE_OP_32_64(nand): | ||
303 | + done = fold_nand(&ctx, op); | ||
304 | + break; | ||
305 | + CASE_OP_32_64(neg): | ||
306 | + done = fold_neg(&ctx, op); | ||
307 | + break; | ||
308 | + CASE_OP_32_64(nor): | ||
309 | + done = fold_nor(&ctx, op); | ||
310 | + break; | ||
311 | + CASE_OP_32_64_VEC(not): | ||
312 | + done = fold_not(&ctx, op); | ||
313 | + break; | ||
314 | + CASE_OP_32_64_VEC(or): | ||
315 | + done = fold_or(&ctx, op); | ||
316 | + break; | ||
317 | + CASE_OP_32_64_VEC(orc): | ||
318 | + done = fold_orc(&ctx, op); | ||
319 | + break; | ||
320 | case INDEX_op_qemu_ld_i32: | ||
321 | case INDEX_op_qemu_ld_i64: | ||
322 | done = fold_qemu_ld(&ctx, op); | ||
323 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
324 | case INDEX_op_qemu_st_i64: | ||
325 | done = fold_qemu_st(&ctx, op); | ||
326 | break; | ||
327 | - | ||
328 | - default: | ||
329 | + CASE_OP_32_64(rem): | ||
330 | + CASE_OP_32_64(remu): | ||
331 | + done = fold_remainder(&ctx, op); | ||
332 | + break; | ||
333 | + CASE_OP_32_64(rotl): | ||
334 | + CASE_OP_32_64(rotr): | ||
335 | + CASE_OP_32_64(sar): | ||
336 | + CASE_OP_32_64(shl): | ||
337 | + CASE_OP_32_64(shr): | ||
338 | + done = fold_shift(&ctx, op); | ||
339 | + break; | ||
340 | + CASE_OP_32_64_VEC(sub): | ||
341 | + done = fold_sub(&ctx, op); | ||
342 | + break; | ||
343 | + CASE_OP_32_64_VEC(xor): | ||
344 | + done = fold_xor(&ctx, op); | ||
345 | break; | ||
346 | } | ||
347 | 65 | ||
348 | -- | 66 | -- |
349 | 2.25.1 | 67 | 2.34.1 |
350 | 68 | ||
351 | 69 | diff view generated by jsdifflib |
1 | Break the final cleanup clause out of the main switch | 1 | Since tcg_temp_new_i32 is now identical, use that. |
---|---|---|---|
2 | statement. When fully folding an opcode to mov/movi, | ||
3 | use "continue" to process the next opcode, else break | ||
4 | to fall into the final cleanup. | ||
5 | 2 | ||
6 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 3 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
7 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | ||
8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
9 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
10 | --- | 5 | --- |
11 | tcg/optimize.c | 190 ++++++++++++++++++++++++------------------------- | 6 | include/exec/gen-icount.h | 8 +------- |
12 | 1 file changed, 94 insertions(+), 96 deletions(-) | 7 | 1 file changed, 1 insertion(+), 7 deletions(-) |
13 | 8 | ||
14 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 9 | diff --git a/include/exec/gen-icount.h b/include/exec/gen-icount.h |
15 | index XXXXXXX..XXXXXXX 100644 | 10 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/tcg/optimize.c | 11 | --- a/include/exec/gen-icount.h |
17 | +++ b/tcg/optimize.c | 12 | +++ b/include/exec/gen-icount.h |
18 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | 13 | @@ -XXX,XX +XXX,XX @@ static inline void gen_io_start(void) |
19 | switch (opc) { | 14 | |
20 | CASE_OP_32_64_VEC(mov): | 15 | static inline void gen_tb_start(const TranslationBlock *tb) |
21 | tcg_opt_gen_mov(s, op, op->args[0], op->args[1]); | 16 | { |
22 | - break; | 17 | - TCGv_i32 count; |
23 | + continue; | 18 | - |
24 | 19 | - if (tb_cflags(tb) & CF_USE_ICOUNT) { | |
25 | case INDEX_op_dup_vec: | 20 | - count = tcg_temp_local_new_i32(); |
26 | if (arg_is_const(op->args[1])) { | 21 | - } else { |
27 | tmp = arg_info(op->args[1])->val; | 22 | - count = tcg_temp_new_i32(); |
28 | tmp = dup_const(TCGOP_VECE(op), tmp); | 23 | - } |
29 | tcg_opt_gen_movi(s, &ctx, op, op->args[0], tmp); | 24 | + TCGv_i32 count = tcg_temp_new_i32(); |
30 | - break; | 25 | |
31 | + continue; | 26 | tcg_gen_ld_i32(count, cpu_env, |
32 | } | 27 | offsetof(ArchCPU, neg.icount_decr.u32) - |
33 | - goto do_default; | ||
34 | + break; | ||
35 | |||
36 | case INDEX_op_dup2_vec: | ||
37 | assert(TCG_TARGET_REG_BITS == 32); | ||
38 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
39 | tcg_opt_gen_movi(s, &ctx, op, op->args[0], | ||
40 | deposit64(arg_info(op->args[1])->val, 32, 32, | ||
41 | arg_info(op->args[2])->val)); | ||
42 | - break; | ||
43 | + continue; | ||
44 | } else if (args_are_copies(op->args[1], op->args[2])) { | ||
45 | op->opc = INDEX_op_dup_vec; | ||
46 | TCGOP_VECE(op) = MO_32; | ||
47 | nb_iargs = 1; | ||
48 | } | ||
49 | - goto do_default; | ||
50 | + break; | ||
51 | |||
52 | CASE_OP_32_64(not): | ||
53 | CASE_OP_32_64(neg): | ||
54 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
55 | if (arg_is_const(op->args[1])) { | ||
56 | tmp = do_constant_folding(opc, arg_info(op->args[1])->val, 0); | ||
57 | tcg_opt_gen_movi(s, &ctx, op, op->args[0], tmp); | ||
58 | - break; | ||
59 | + continue; | ||
60 | } | ||
61 | - goto do_default; | ||
62 | + break; | ||
63 | |||
64 | CASE_OP_32_64(bswap16): | ||
65 | CASE_OP_32_64(bswap32): | ||
66 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
67 | tmp = do_constant_folding(opc, arg_info(op->args[1])->val, | ||
68 | op->args[2]); | ||
69 | tcg_opt_gen_movi(s, &ctx, op, op->args[0], tmp); | ||
70 | - break; | ||
71 | + continue; | ||
72 | } | ||
73 | - goto do_default; | ||
74 | + break; | ||
75 | |||
76 | CASE_OP_32_64(add): | ||
77 | CASE_OP_32_64(sub): | ||
78 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
79 | tmp = do_constant_folding(opc, arg_info(op->args[1])->val, | ||
80 | arg_info(op->args[2])->val); | ||
81 | tcg_opt_gen_movi(s, &ctx, op, op->args[0], tmp); | ||
82 | - break; | ||
83 | + continue; | ||
84 | } | ||
85 | - goto do_default; | ||
86 | + break; | ||
87 | |||
88 | CASE_OP_32_64(clz): | ||
89 | CASE_OP_32_64(ctz): | ||
90 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
91 | } else { | ||
92 | tcg_opt_gen_mov(s, op, op->args[0], op->args[2]); | ||
93 | } | ||
94 | - break; | ||
95 | + continue; | ||
96 | } | ||
97 | - goto do_default; | ||
98 | + break; | ||
99 | |||
100 | CASE_OP_32_64(deposit): | ||
101 | if (arg_is_const(op->args[1]) && arg_is_const(op->args[2])) { | ||
102 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
103 | op->args[3], op->args[4], | ||
104 | arg_info(op->args[2])->val); | ||
105 | tcg_opt_gen_movi(s, &ctx, op, op->args[0], tmp); | ||
106 | - break; | ||
107 | + continue; | ||
108 | } | ||
109 | - goto do_default; | ||
110 | + break; | ||
111 | |||
112 | CASE_OP_32_64(extract): | ||
113 | if (arg_is_const(op->args[1])) { | ||
114 | tmp = extract64(arg_info(op->args[1])->val, | ||
115 | op->args[2], op->args[3]); | ||
116 | tcg_opt_gen_movi(s, &ctx, op, op->args[0], tmp); | ||
117 | - break; | ||
118 | + continue; | ||
119 | } | ||
120 | - goto do_default; | ||
121 | + break; | ||
122 | |||
123 | CASE_OP_32_64(sextract): | ||
124 | if (arg_is_const(op->args[1])) { | ||
125 | tmp = sextract64(arg_info(op->args[1])->val, | ||
126 | op->args[2], op->args[3]); | ||
127 | tcg_opt_gen_movi(s, &ctx, op, op->args[0], tmp); | ||
128 | - break; | ||
129 | + continue; | ||
130 | } | ||
131 | - goto do_default; | ||
132 | + break; | ||
133 | |||
134 | CASE_OP_32_64(extract2): | ||
135 | if (arg_is_const(op->args[1]) && arg_is_const(op->args[2])) { | ||
136 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
137 | ((uint32_t)v2 << (32 - shr))); | ||
138 | } | ||
139 | tcg_opt_gen_movi(s, &ctx, op, op->args[0], tmp); | ||
140 | - break; | ||
141 | + continue; | ||
142 | } | ||
143 | - goto do_default; | ||
144 | + break; | ||
145 | |||
146 | CASE_OP_32_64(setcond): | ||
147 | tmp = do_constant_folding_cond(opc, op->args[1], | ||
148 | op->args[2], op->args[3]); | ||
149 | if (tmp != 2) { | ||
150 | tcg_opt_gen_movi(s, &ctx, op, op->args[0], tmp); | ||
151 | - break; | ||
152 | + continue; | ||
153 | } | ||
154 | - goto do_default; | ||
155 | + break; | ||
156 | |||
157 | CASE_OP_32_64(brcond): | ||
158 | tmp = do_constant_folding_cond(opc, op->args[0], | ||
159 | op->args[1], op->args[2]); | ||
160 | - if (tmp != 2) { | ||
161 | - if (tmp) { | ||
162 | - memset(&ctx.temps_used, 0, sizeof(ctx.temps_used)); | ||
163 | - op->opc = INDEX_op_br; | ||
164 | - op->args[0] = op->args[3]; | ||
165 | - } else { | ||
166 | - tcg_op_remove(s, op); | ||
167 | - } | ||
168 | + switch (tmp) { | ||
169 | + case 0: | ||
170 | + tcg_op_remove(s, op); | ||
171 | + continue; | ||
172 | + case 1: | ||
173 | + memset(&ctx.temps_used, 0, sizeof(ctx.temps_used)); | ||
174 | + op->opc = opc = INDEX_op_br; | ||
175 | + op->args[0] = op->args[3]; | ||
176 | break; | ||
177 | } | ||
178 | - goto do_default; | ||
179 | + break; | ||
180 | |||
181 | CASE_OP_32_64(movcond): | ||
182 | tmp = do_constant_folding_cond(opc, op->args[1], | ||
183 | op->args[2], op->args[5]); | ||
184 | if (tmp != 2) { | ||
185 | tcg_opt_gen_mov(s, op, op->args[0], op->args[4-tmp]); | ||
186 | - break; | ||
187 | + continue; | ||
188 | } | ||
189 | if (arg_is_const(op->args[3]) && arg_is_const(op->args[4])) { | ||
190 | uint64_t tv = arg_info(op->args[3])->val; | ||
191 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
192 | if (fv == 1 && tv == 0) { | ||
193 | cond = tcg_invert_cond(cond); | ||
194 | } else if (!(tv == 1 && fv == 0)) { | ||
195 | - goto do_default; | ||
196 | + break; | ||
197 | } | ||
198 | op->args[3] = cond; | ||
199 | op->opc = opc = (opc == INDEX_op_movcond_i32 | ||
200 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
201 | : INDEX_op_setcond_i64); | ||
202 | nb_iargs = 2; | ||
203 | } | ||
204 | - goto do_default; | ||
205 | + break; | ||
206 | |||
207 | case INDEX_op_add2_i32: | ||
208 | case INDEX_op_sub2_i32: | ||
209 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
210 | rh = op->args[1]; | ||
211 | tcg_opt_gen_movi(s, &ctx, op, rl, (int32_t)a); | ||
212 | tcg_opt_gen_movi(s, &ctx, op2, rh, (int32_t)(a >> 32)); | ||
213 | - break; | ||
214 | + continue; | ||
215 | } | ||
216 | - goto do_default; | ||
217 | + break; | ||
218 | |||
219 | case INDEX_op_mulu2_i32: | ||
220 | if (arg_is_const(op->args[2]) && arg_is_const(op->args[3])) { | ||
221 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
222 | rh = op->args[1]; | ||
223 | tcg_opt_gen_movi(s, &ctx, op, rl, (int32_t)r); | ||
224 | tcg_opt_gen_movi(s, &ctx, op2, rh, (int32_t)(r >> 32)); | ||
225 | - break; | ||
226 | + continue; | ||
227 | } | ||
228 | - goto do_default; | ||
229 | + break; | ||
230 | |||
231 | case INDEX_op_brcond2_i32: | ||
232 | tmp = do_constant_folding_cond2(&op->args[0], &op->args[2], | ||
233 | op->args[4]); | ||
234 | - if (tmp != 2) { | ||
235 | - if (tmp) { | ||
236 | - do_brcond_true: | ||
237 | - memset(&ctx.temps_used, 0, sizeof(ctx.temps_used)); | ||
238 | - op->opc = INDEX_op_br; | ||
239 | - op->args[0] = op->args[5]; | ||
240 | - } else { | ||
241 | + if (tmp == 0) { | ||
242 | do_brcond_false: | ||
243 | - tcg_op_remove(s, op); | ||
244 | - } | ||
245 | - } else if ((op->args[4] == TCG_COND_LT | ||
246 | - || op->args[4] == TCG_COND_GE) | ||
247 | - && arg_is_const(op->args[2]) | ||
248 | - && arg_info(op->args[2])->val == 0 | ||
249 | - && arg_is_const(op->args[3]) | ||
250 | - && arg_info(op->args[3])->val == 0) { | ||
251 | + tcg_op_remove(s, op); | ||
252 | + continue; | ||
253 | + } | ||
254 | + if (tmp == 1) { | ||
255 | + do_brcond_true: | ||
256 | + op->opc = opc = INDEX_op_br; | ||
257 | + op->args[0] = op->args[5]; | ||
258 | + break; | ||
259 | + } | ||
260 | + if ((op->args[4] == TCG_COND_LT || op->args[4] == TCG_COND_GE) | ||
261 | + && arg_is_const(op->args[2]) | ||
262 | + && arg_info(op->args[2])->val == 0 | ||
263 | + && arg_is_const(op->args[3]) | ||
264 | + && arg_info(op->args[3])->val == 0) { | ||
265 | /* Simplify LT/GE comparisons vs zero to a single compare | ||
266 | vs the high word of the input. */ | ||
267 | do_brcond_high: | ||
268 | - memset(&ctx.temps_used, 0, sizeof(ctx.temps_used)); | ||
269 | - op->opc = INDEX_op_brcond_i32; | ||
270 | + op->opc = opc = INDEX_op_brcond_i32; | ||
271 | op->args[0] = op->args[1]; | ||
272 | op->args[1] = op->args[3]; | ||
273 | op->args[2] = op->args[4]; | ||
274 | op->args[3] = op->args[5]; | ||
275 | - } else if (op->args[4] == TCG_COND_EQ) { | ||
276 | + break; | ||
277 | + } | ||
278 | + if (op->args[4] == TCG_COND_EQ) { | ||
279 | /* Simplify EQ comparisons where one of the pairs | ||
280 | can be simplified. */ | ||
281 | tmp = do_constant_folding_cond(INDEX_op_brcond_i32, | ||
282 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
283 | if (tmp == 0) { | ||
284 | goto do_brcond_false; | ||
285 | } else if (tmp != 1) { | ||
286 | - goto do_default; | ||
287 | + break; | ||
288 | } | ||
289 | do_brcond_low: | ||
290 | memset(&ctx.temps_used, 0, sizeof(ctx.temps_used)); | ||
291 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
292 | op->args[1] = op->args[2]; | ||
293 | op->args[2] = op->args[4]; | ||
294 | op->args[3] = op->args[5]; | ||
295 | - } else if (op->args[4] == TCG_COND_NE) { | ||
296 | + break; | ||
297 | + } | ||
298 | + if (op->args[4] == TCG_COND_NE) { | ||
299 | /* Simplify NE comparisons where one of the pairs | ||
300 | can be simplified. */ | ||
301 | tmp = do_constant_folding_cond(INDEX_op_brcond_i32, | ||
302 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
303 | } else if (tmp == 1) { | ||
304 | goto do_brcond_true; | ||
305 | } | ||
306 | - goto do_default; | ||
307 | - } else { | ||
308 | - goto do_default; | ||
309 | } | ||
310 | break; | ||
311 | |||
312 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
313 | if (tmp != 2) { | ||
314 | do_setcond_const: | ||
315 | tcg_opt_gen_movi(s, &ctx, op, op->args[0], tmp); | ||
316 | - } else if ((op->args[5] == TCG_COND_LT | ||
317 | - || op->args[5] == TCG_COND_GE) | ||
318 | - && arg_is_const(op->args[3]) | ||
319 | - && arg_info(op->args[3])->val == 0 | ||
320 | - && arg_is_const(op->args[4]) | ||
321 | - && arg_info(op->args[4])->val == 0) { | ||
322 | + continue; | ||
323 | + } | ||
324 | + if ((op->args[5] == TCG_COND_LT || op->args[5] == TCG_COND_GE) | ||
325 | + && arg_is_const(op->args[3]) | ||
326 | + && arg_info(op->args[3])->val == 0 | ||
327 | + && arg_is_const(op->args[4]) | ||
328 | + && arg_info(op->args[4])->val == 0) { | ||
329 | /* Simplify LT/GE comparisons vs zero to a single compare | ||
330 | vs the high word of the input. */ | ||
331 | do_setcond_high: | ||
332 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
333 | op->args[1] = op->args[2]; | ||
334 | op->args[2] = op->args[4]; | ||
335 | op->args[3] = op->args[5]; | ||
336 | - } else if (op->args[5] == TCG_COND_EQ) { | ||
337 | + break; | ||
338 | + } | ||
339 | + if (op->args[5] == TCG_COND_EQ) { | ||
340 | /* Simplify EQ comparisons where one of the pairs | ||
341 | can be simplified. */ | ||
342 | tmp = do_constant_folding_cond(INDEX_op_setcond_i32, | ||
343 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
344 | if (tmp == 0) { | ||
345 | goto do_setcond_high; | ||
346 | } else if (tmp != 1) { | ||
347 | - goto do_default; | ||
348 | + break; | ||
349 | } | ||
350 | do_setcond_low: | ||
351 | reset_temp(op->args[0]); | ||
352 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
353 | op->opc = INDEX_op_setcond_i32; | ||
354 | op->args[2] = op->args[3]; | ||
355 | op->args[3] = op->args[5]; | ||
356 | - } else if (op->args[5] == TCG_COND_NE) { | ||
357 | + break; | ||
358 | + } | ||
359 | + if (op->args[5] == TCG_COND_NE) { | ||
360 | /* Simplify NE comparisons where one of the pairs | ||
361 | can be simplified. */ | ||
362 | tmp = do_constant_folding_cond(INDEX_op_setcond_i32, | ||
363 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
364 | } else if (tmp == 1) { | ||
365 | goto do_setcond_const; | ||
366 | } | ||
367 | - goto do_default; | ||
368 | - } else { | ||
369 | - goto do_default; | ||
370 | } | ||
371 | break; | ||
372 | |||
373 | - case INDEX_op_call: | ||
374 | - if (!(tcg_call_flags(op) | ||
375 | + default: | ||
376 | + break; | ||
377 | + } | ||
378 | + | ||
379 | + /* Some of the folding above can change opc. */ | ||
380 | + opc = op->opc; | ||
381 | + def = &tcg_op_defs[opc]; | ||
382 | + if (def->flags & TCG_OPF_BB_END) { | ||
383 | + memset(&ctx.temps_used, 0, sizeof(ctx.temps_used)); | ||
384 | + } else { | ||
385 | + if (opc == INDEX_op_call && | ||
386 | + !(tcg_call_flags(op) | ||
387 | & (TCG_CALL_NO_READ_GLOBALS | TCG_CALL_NO_WRITE_GLOBALS))) { | ||
388 | for (i = 0; i < nb_globals; i++) { | ||
389 | if (test_bit(i, ctx.temps_used.l)) { | ||
390 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
391 | } | ||
392 | } | ||
393 | } | ||
394 | - goto do_reset_output; | ||
395 | |||
396 | - default: | ||
397 | - do_default: | ||
398 | - /* Default case: we know nothing about operation (or were unable | ||
399 | - to compute the operation result) so no propagation is done. | ||
400 | - We trash everything if the operation is the end of a basic | ||
401 | - block, otherwise we only trash the output args. "z_mask" is | ||
402 | - the non-zero bits mask for the first output arg. */ | ||
403 | - if (def->flags & TCG_OPF_BB_END) { | ||
404 | - memset(&ctx.temps_used, 0, sizeof(ctx.temps_used)); | ||
405 | - } else { | ||
406 | - do_reset_output: | ||
407 | - for (i = 0; i < nb_oargs; i++) { | ||
408 | - reset_temp(op->args[i]); | ||
409 | - /* Save the corresponding known-zero bits mask for the | ||
410 | - first output argument (only one supported so far). */ | ||
411 | - if (i == 0) { | ||
412 | - arg_info(op->args[i])->z_mask = z_mask; | ||
413 | - } | ||
414 | + for (i = 0; i < nb_oargs; i++) { | ||
415 | + reset_temp(op->args[i]); | ||
416 | + /* Save the corresponding known-zero bits mask for the | ||
417 | + first output argument (only one supported so far). */ | ||
418 | + if (i == 0) { | ||
419 | + arg_info(op->args[i])->z_mask = z_mask; | ||
420 | } | ||
421 | } | ||
422 | - break; | ||
423 | } | ||
424 | |||
425 | /* Eliminate duplicate and redundant fence instructions. */ | ||
426 | -- | 28 | -- |
427 | 2.25.1 | 29 | 2.34.1 |
428 | 30 | ||
429 | 31 | diff view generated by jsdifflib |
1 | Move all of the known-zero optimizations into the per-opcode | 1 | These symbols are now unused. |
---|---|---|---|
2 | functions. Use fold_masks when there is a possibility of the | ||
3 | result being determined, and simply set ctx->z_mask otherwise. | ||
4 | 2 | ||
5 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 3 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
6 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | ||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
8 | --- | 5 | --- |
9 | tcg/optimize.c | 545 ++++++++++++++++++++++++++----------------------- | 6 | include/tcg/tcg-op.h | 2 -- |
10 | 1 file changed, 294 insertions(+), 251 deletions(-) | 7 | include/tcg/tcg.h | 28 ---------------------------- |
8 | tcg/tcg.c | 16 ---------------- | ||
9 | 3 files changed, 46 deletions(-) | ||
11 | 10 | ||
12 | diff --git a/tcg/optimize.c b/tcg/optimize.c | 11 | diff --git a/include/tcg/tcg-op.h b/include/tcg/tcg-op.h |
13 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/tcg/optimize.c | 13 | --- a/include/tcg/tcg-op.h |
15 | +++ b/tcg/optimize.c | 14 | +++ b/include/tcg/tcg-op.h |
16 | @@ -XXX,XX +XXX,XX @@ typedef struct OptContext { | 15 | @@ -XXX,XX +XXX,XX @@ static inline void tcg_gen_plugin_cb_end(void) |
17 | TCGTempSet temps_used; | 16 | #if TARGET_LONG_BITS == 32 |
18 | 17 | #define tcg_temp_new() tcg_temp_new_i32() | |
19 | /* In flight values from optimization. */ | 18 | #define tcg_global_mem_new tcg_global_mem_new_i32 |
20 | - uint64_t z_mask; | 19 | -#define tcg_temp_local_new() tcg_temp_local_new_i32() |
21 | + uint64_t a_mask; /* mask bit is 0 iff value identical to first input */ | 20 | #define tcg_temp_free tcg_temp_free_i32 |
22 | + uint64_t z_mask; /* mask bit is 0 iff value bit is 0 */ | 21 | #define tcg_gen_qemu_ld_tl tcg_gen_qemu_ld_i32 |
23 | TCGType type; | 22 | #define tcg_gen_qemu_st_tl tcg_gen_qemu_st_i32 |
24 | } OptContext; | 23 | #else |
25 | 24 | #define tcg_temp_new() tcg_temp_new_i64() | |
26 | @@ -XXX,XX +XXX,XX @@ static bool fold_const2(OptContext *ctx, TCGOp *op) | 25 | #define tcg_global_mem_new tcg_global_mem_new_i64 |
27 | return false; | 26 | -#define tcg_temp_local_new() tcg_temp_local_new_i64() |
27 | #define tcg_temp_free tcg_temp_free_i64 | ||
28 | #define tcg_gen_qemu_ld_tl tcg_gen_qemu_ld_i64 | ||
29 | #define tcg_gen_qemu_st_tl tcg_gen_qemu_st_i64 | ||
30 | diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h | ||
31 | index XXXXXXX..XXXXXXX 100644 | ||
32 | --- a/include/tcg/tcg.h | ||
33 | +++ b/include/tcg/tcg.h | ||
34 | @@ -XXX,XX +XXX,XX @@ static inline TCGv_i32 tcg_temp_new_i32(void) | ||
35 | return temp_tcgv_i32(t); | ||
28 | } | 36 | } |
29 | 37 | ||
30 | +static bool fold_masks(OptContext *ctx, TCGOp *op) | 38 | -static inline TCGv_i32 tcg_temp_local_new_i32(void) |
31 | +{ | 39 | -{ |
32 | + uint64_t a_mask = ctx->a_mask; | 40 | - TCGTemp *t = tcg_temp_new_internal(TCG_TYPE_I32, TEMP_TB); |
33 | + uint64_t z_mask = ctx->z_mask; | 41 | - return temp_tcgv_i32(t); |
34 | + | 42 | -} |
35 | + /* | 43 | - |
36 | + * 32-bit ops generate 32-bit results. For the result is zero test | 44 | static inline TCGv_i64 tcg_global_mem_new_i64(TCGv_ptr reg, intptr_t offset, |
37 | + * below, we can ignore high bits, but for further optimizations we | 45 | const char *name) |
38 | + * need to record that the high bits contain garbage. | ||
39 | + */ | ||
40 | + if (ctx->type == TCG_TYPE_I32) { | ||
41 | + ctx->z_mask |= MAKE_64BIT_MASK(32, 32); | ||
42 | + a_mask &= MAKE_64BIT_MASK(0, 32); | ||
43 | + z_mask &= MAKE_64BIT_MASK(0, 32); | ||
44 | + } | ||
45 | + | ||
46 | + if (z_mask == 0) { | ||
47 | + return tcg_opt_gen_movi(ctx, op, op->args[0], 0); | ||
48 | + } | ||
49 | + if (a_mask == 0) { | ||
50 | + return tcg_opt_gen_mov(ctx, op, op->args[0], op->args[1]); | ||
51 | + } | ||
52 | + return false; | ||
53 | +} | ||
54 | + | ||
55 | /* | ||
56 | * Convert @op to NOT, if NOT is supported by the host. | ||
57 | * Return true f the conversion is successful, which will still | ||
58 | @@ -XXX,XX +XXX,XX @@ static bool fold_add2_i32(OptContext *ctx, TCGOp *op) | ||
59 | |||
60 | static bool fold_and(OptContext *ctx, TCGOp *op) | ||
61 | { | 46 | { |
62 | + uint64_t z1, z2; | 47 | @@ -XXX,XX +XXX,XX @@ static inline TCGv_i64 tcg_temp_new_i64(void) |
63 | + | 48 | return temp_tcgv_i64(t); |
64 | if (fold_const2(ctx, op) || | ||
65 | fold_xi_to_i(ctx, op, 0) || | ||
66 | fold_xi_to_x(ctx, op, -1) || | ||
67 | fold_xx_to_x(ctx, op)) { | ||
68 | return true; | ||
69 | } | ||
70 | - return false; | ||
71 | + | ||
72 | + z1 = arg_info(op->args[1])->z_mask; | ||
73 | + z2 = arg_info(op->args[2])->z_mask; | ||
74 | + ctx->z_mask = z1 & z2; | ||
75 | + | ||
76 | + /* | ||
77 | + * Known-zeros does not imply known-ones. Therefore unless | ||
78 | + * arg2 is constant, we can't infer affected bits from it. | ||
79 | + */ | ||
80 | + if (arg_is_const(op->args[2])) { | ||
81 | + ctx->a_mask = z1 & ~z2; | ||
82 | + } | ||
83 | + | ||
84 | + return fold_masks(ctx, op); | ||
85 | } | 49 | } |
86 | 50 | ||
87 | static bool fold_andc(OptContext *ctx, TCGOp *op) | 51 | -static inline TCGv_i64 tcg_temp_local_new_i64(void) |
52 | -{ | ||
53 | - TCGTemp *t = tcg_temp_new_internal(TCG_TYPE_I64, TEMP_TB); | ||
54 | - return temp_tcgv_i64(t); | ||
55 | -} | ||
56 | - | ||
57 | /* Used only by tcg infrastructure: tcg-op.c or plugin-gen.c */ | ||
58 | static inline TCGv_i128 tcg_temp_ebb_new_i128(void) | ||
88 | { | 59 | { |
89 | + uint64_t z1; | 60 | @@ -XXX,XX +XXX,XX @@ static inline TCGv_i128 tcg_temp_new_i128(void) |
90 | + | 61 | return temp_tcgv_i128(t); |
91 | if (fold_const2(ctx, op) || | ||
92 | fold_xx_to_i(ctx, op, 0) || | ||
93 | fold_xi_to_x(ctx, op, 0) || | ||
94 | fold_ix_to_not(ctx, op, -1)) { | ||
95 | return true; | ||
96 | } | ||
97 | - return false; | ||
98 | + | ||
99 | + z1 = arg_info(op->args[1])->z_mask; | ||
100 | + | ||
101 | + /* | ||
102 | + * Known-zeros does not imply known-ones. Therefore unless | ||
103 | + * arg2 is constant, we can't infer anything from it. | ||
104 | + */ | ||
105 | + if (arg_is_const(op->args[2])) { | ||
106 | + uint64_t z2 = ~arg_info(op->args[2])->z_mask; | ||
107 | + ctx->a_mask = z1 & ~z2; | ||
108 | + z1 &= z2; | ||
109 | + } | ||
110 | + ctx->z_mask = z1; | ||
111 | + | ||
112 | + return fold_masks(ctx, op); | ||
113 | } | 62 | } |
114 | 63 | ||
115 | static bool fold_brcond(OptContext *ctx, TCGOp *op) | 64 | -static inline TCGv_i128 tcg_temp_local_new_i128(void) |
116 | @@ -XXX,XX +XXX,XX @@ static bool fold_brcond2(OptContext *ctx, TCGOp *op) | 65 | -{ |
117 | 66 | - TCGTemp *t = tcg_temp_new_internal(TCG_TYPE_I128, TEMP_TB); | |
118 | static bool fold_bswap(OptContext *ctx, TCGOp *op) | 67 | - return temp_tcgv_i128(t); |
68 | -} | ||
69 | - | ||
70 | static inline TCGv_ptr tcg_global_mem_new_ptr(TCGv_ptr reg, intptr_t offset, | ||
71 | const char *name) | ||
119 | { | 72 | { |
120 | + uint64_t z_mask, sign; | 73 | @@ -XXX,XX +XXX,XX @@ static inline TCGv_ptr tcg_temp_new_ptr(void) |
121 | + | 74 | return temp_tcgv_ptr(t); |
122 | if (arg_is_const(op->args[1])) { | ||
123 | uint64_t t = arg_info(op->args[1])->val; | ||
124 | |||
125 | t = do_constant_folding(op->opc, ctx->type, t, op->args[2]); | ||
126 | return tcg_opt_gen_movi(ctx, op, op->args[0], t); | ||
127 | } | ||
128 | - return false; | ||
129 | + | ||
130 | + z_mask = arg_info(op->args[1])->z_mask; | ||
131 | + switch (op->opc) { | ||
132 | + case INDEX_op_bswap16_i32: | ||
133 | + case INDEX_op_bswap16_i64: | ||
134 | + z_mask = bswap16(z_mask); | ||
135 | + sign = INT16_MIN; | ||
136 | + break; | ||
137 | + case INDEX_op_bswap32_i32: | ||
138 | + case INDEX_op_bswap32_i64: | ||
139 | + z_mask = bswap32(z_mask); | ||
140 | + sign = INT32_MIN; | ||
141 | + break; | ||
142 | + case INDEX_op_bswap64_i64: | ||
143 | + z_mask = bswap64(z_mask); | ||
144 | + sign = INT64_MIN; | ||
145 | + break; | ||
146 | + default: | ||
147 | + g_assert_not_reached(); | ||
148 | + } | ||
149 | + | ||
150 | + switch (op->args[2] & (TCG_BSWAP_OZ | TCG_BSWAP_OS)) { | ||
151 | + case TCG_BSWAP_OZ: | ||
152 | + break; | ||
153 | + case TCG_BSWAP_OS: | ||
154 | + /* If the sign bit may be 1, force all the bits above to 1. */ | ||
155 | + if (z_mask & sign) { | ||
156 | + z_mask |= sign; | ||
157 | + } | ||
158 | + break; | ||
159 | + default: | ||
160 | + /* The high bits are undefined: force all bits above the sign to 1. */ | ||
161 | + z_mask |= sign << 1; | ||
162 | + break; | ||
163 | + } | ||
164 | + ctx->z_mask = z_mask; | ||
165 | + | ||
166 | + return fold_masks(ctx, op); | ||
167 | } | 75 | } |
168 | 76 | ||
169 | static bool fold_call(OptContext *ctx, TCGOp *op) | 77 | -static inline TCGv_ptr tcg_temp_local_new_ptr(void) |
170 | @@ -XXX,XX +XXX,XX @@ static bool fold_call(OptContext *ctx, TCGOp *op) | 78 | -{ |
171 | 79 | - TCGTemp *t = tcg_temp_new_internal(TCG_TYPE_PTR, TEMP_TB); | |
172 | static bool fold_count_zeros(OptContext *ctx, TCGOp *op) | 80 | - return temp_tcgv_ptr(t); |
81 | -} | ||
82 | - | ||
83 | #if defined(CONFIG_DEBUG_TCG) | ||
84 | /* If you call tcg_clear_temp_count() at the start of a section of | ||
85 | * code which is not supposed to leak any TCG temporaries, then | ||
86 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s); | ||
87 | /* Allocate a new temporary and initialize it with a constant. */ | ||
88 | TCGv_i32 tcg_const_i32(int32_t val); | ||
89 | TCGv_i64 tcg_const_i64(int64_t val); | ||
90 | -TCGv_i32 tcg_const_local_i32(int32_t val); | ||
91 | -TCGv_i64 tcg_const_local_i64(int64_t val); | ||
92 | TCGv_vec tcg_const_zeros_vec(TCGType); | ||
93 | TCGv_vec tcg_const_ones_vec(TCGType); | ||
94 | TCGv_vec tcg_const_zeros_vec_matching(TCGv_vec); | ||
95 | @@ -XXX,XX +XXX,XX @@ TCGv_vec tcg_constant_vec_matching(TCGv_vec match, unsigned vece, int64_t val); | ||
96 | |||
97 | #if UINTPTR_MAX == UINT32_MAX | ||
98 | # define tcg_const_ptr(x) ((TCGv_ptr)tcg_const_i32((intptr_t)(x))) | ||
99 | -# define tcg_const_local_ptr(x) ((TCGv_ptr)tcg_const_local_i32((intptr_t)(x))) | ||
100 | # define tcg_constant_ptr(x) ((TCGv_ptr)tcg_constant_i32((intptr_t)(x))) | ||
101 | #else | ||
102 | # define tcg_const_ptr(x) ((TCGv_ptr)tcg_const_i64((intptr_t)(x))) | ||
103 | -# define tcg_const_local_ptr(x) ((TCGv_ptr)tcg_const_local_i64((intptr_t)(x))) | ||
104 | # define tcg_constant_ptr(x) ((TCGv_ptr)tcg_constant_i64((intptr_t)(x))) | ||
105 | #endif | ||
106 | |||
107 | diff --git a/tcg/tcg.c b/tcg/tcg.c | ||
108 | index XXXXXXX..XXXXXXX 100644 | ||
109 | --- a/tcg/tcg.c | ||
110 | +++ b/tcg/tcg.c | ||
111 | @@ -XXX,XX +XXX,XX @@ TCGv_i64 tcg_const_i64(int64_t val) | ||
112 | return t0; | ||
113 | } | ||
114 | |||
115 | -TCGv_i32 tcg_const_local_i32(int32_t val) | ||
116 | -{ | ||
117 | - TCGv_i32 t0; | ||
118 | - t0 = tcg_temp_local_new_i32(); | ||
119 | - tcg_gen_movi_i32(t0, val); | ||
120 | - return t0; | ||
121 | -} | ||
122 | - | ||
123 | -TCGv_i64 tcg_const_local_i64(int64_t val) | ||
124 | -{ | ||
125 | - TCGv_i64 t0; | ||
126 | - t0 = tcg_temp_local_new_i64(); | ||
127 | - tcg_gen_movi_i64(t0, val); | ||
128 | - return t0; | ||
129 | -} | ||
130 | - | ||
131 | #if defined(CONFIG_DEBUG_TCG) | ||
132 | void tcg_clear_temp_count(void) | ||
173 | { | 133 | { |
174 | + uint64_t z_mask; | ||
175 | + | ||
176 | if (arg_is_const(op->args[1])) { | ||
177 | uint64_t t = arg_info(op->args[1])->val; | ||
178 | |||
179 | @@ -XXX,XX +XXX,XX @@ static bool fold_count_zeros(OptContext *ctx, TCGOp *op) | ||
180 | } | ||
181 | return tcg_opt_gen_mov(ctx, op, op->args[0], op->args[2]); | ||
182 | } | ||
183 | + | ||
184 | + switch (ctx->type) { | ||
185 | + case TCG_TYPE_I32: | ||
186 | + z_mask = 31; | ||
187 | + break; | ||
188 | + case TCG_TYPE_I64: | ||
189 | + z_mask = 63; | ||
190 | + break; | ||
191 | + default: | ||
192 | + g_assert_not_reached(); | ||
193 | + } | ||
194 | + ctx->z_mask = arg_info(op->args[2])->z_mask | z_mask; | ||
195 | + | ||
196 | return false; | ||
197 | } | ||
198 | |||
199 | static bool fold_ctpop(OptContext *ctx, TCGOp *op) | ||
200 | { | ||
201 | - return fold_const1(ctx, op); | ||
202 | + if (fold_const1(ctx, op)) { | ||
203 | + return true; | ||
204 | + } | ||
205 | + | ||
206 | + switch (ctx->type) { | ||
207 | + case TCG_TYPE_I32: | ||
208 | + ctx->z_mask = 32 | 31; | ||
209 | + break; | ||
210 | + case TCG_TYPE_I64: | ||
211 | + ctx->z_mask = 64 | 63; | ||
212 | + break; | ||
213 | + default: | ||
214 | + g_assert_not_reached(); | ||
215 | + } | ||
216 | + return false; | ||
217 | } | ||
218 | |||
219 | static bool fold_deposit(OptContext *ctx, TCGOp *op) | ||
220 | @@ -XXX,XX +XXX,XX @@ static bool fold_deposit(OptContext *ctx, TCGOp *op) | ||
221 | t1 = deposit64(t1, op->args[3], op->args[4], t2); | ||
222 | return tcg_opt_gen_movi(ctx, op, op->args[0], t1); | ||
223 | } | ||
224 | + | ||
225 | + ctx->z_mask = deposit64(arg_info(op->args[1])->z_mask, | ||
226 | + op->args[3], op->args[4], | ||
227 | + arg_info(op->args[2])->z_mask); | ||
228 | return false; | ||
229 | } | ||
230 | |||
231 | @@ -XXX,XX +XXX,XX @@ static bool fold_eqv(OptContext *ctx, TCGOp *op) | ||
232 | |||
233 | static bool fold_extract(OptContext *ctx, TCGOp *op) | ||
234 | { | ||
235 | + uint64_t z_mask_old, z_mask; | ||
236 | + | ||
237 | if (arg_is_const(op->args[1])) { | ||
238 | uint64_t t; | ||
239 | |||
240 | @@ -XXX,XX +XXX,XX @@ static bool fold_extract(OptContext *ctx, TCGOp *op) | ||
241 | t = extract64(t, op->args[2], op->args[3]); | ||
242 | return tcg_opt_gen_movi(ctx, op, op->args[0], t); | ||
243 | } | ||
244 | - return false; | ||
245 | + | ||
246 | + z_mask_old = arg_info(op->args[1])->z_mask; | ||
247 | + z_mask = extract64(z_mask_old, op->args[2], op->args[3]); | ||
248 | + if (op->args[2] == 0) { | ||
249 | + ctx->a_mask = z_mask_old ^ z_mask; | ||
250 | + } | ||
251 | + ctx->z_mask = z_mask; | ||
252 | + | ||
253 | + return fold_masks(ctx, op); | ||
254 | } | ||
255 | |||
256 | static bool fold_extract2(OptContext *ctx, TCGOp *op) | ||
257 | @@ -XXX,XX +XXX,XX @@ static bool fold_extract2(OptContext *ctx, TCGOp *op) | ||
258 | |||
259 | static bool fold_exts(OptContext *ctx, TCGOp *op) | ||
260 | { | ||
261 | - return fold_const1(ctx, op); | ||
262 | + uint64_t z_mask_old, z_mask, sign; | ||
263 | + bool type_change = false; | ||
264 | + | ||
265 | + if (fold_const1(ctx, op)) { | ||
266 | + return true; | ||
267 | + } | ||
268 | + | ||
269 | + z_mask_old = z_mask = arg_info(op->args[1])->z_mask; | ||
270 | + | ||
271 | + switch (op->opc) { | ||
272 | + CASE_OP_32_64(ext8s): | ||
273 | + sign = INT8_MIN; | ||
274 | + z_mask = (uint8_t)z_mask; | ||
275 | + break; | ||
276 | + CASE_OP_32_64(ext16s): | ||
277 | + sign = INT16_MIN; | ||
278 | + z_mask = (uint16_t)z_mask; | ||
279 | + break; | ||
280 | + case INDEX_op_ext_i32_i64: | ||
281 | + type_change = true; | ||
282 | + QEMU_FALLTHROUGH; | ||
283 | + case INDEX_op_ext32s_i64: | ||
284 | + sign = INT32_MIN; | ||
285 | + z_mask = (uint32_t)z_mask; | ||
286 | + break; | ||
287 | + default: | ||
288 | + g_assert_not_reached(); | ||
289 | + } | ||
290 | + | ||
291 | + if (z_mask & sign) { | ||
292 | + z_mask |= sign; | ||
293 | + } else if (!type_change) { | ||
294 | + ctx->a_mask = z_mask_old ^ z_mask; | ||
295 | + } | ||
296 | + ctx->z_mask = z_mask; | ||
297 | + | ||
298 | + return fold_masks(ctx, op); | ||
299 | } | ||
300 | |||
301 | static bool fold_extu(OptContext *ctx, TCGOp *op) | ||
302 | { | ||
303 | - return fold_const1(ctx, op); | ||
304 | + uint64_t z_mask_old, z_mask; | ||
305 | + bool type_change = false; | ||
306 | + | ||
307 | + if (fold_const1(ctx, op)) { | ||
308 | + return true; | ||
309 | + } | ||
310 | + | ||
311 | + z_mask_old = z_mask = arg_info(op->args[1])->z_mask; | ||
312 | + | ||
313 | + switch (op->opc) { | ||
314 | + CASE_OP_32_64(ext8u): | ||
315 | + z_mask = (uint8_t)z_mask; | ||
316 | + break; | ||
317 | + CASE_OP_32_64(ext16u): | ||
318 | + z_mask = (uint16_t)z_mask; | ||
319 | + break; | ||
320 | + case INDEX_op_extrl_i64_i32: | ||
321 | + case INDEX_op_extu_i32_i64: | ||
322 | + type_change = true; | ||
323 | + QEMU_FALLTHROUGH; | ||
324 | + case INDEX_op_ext32u_i64: | ||
325 | + z_mask = (uint32_t)z_mask; | ||
326 | + break; | ||
327 | + case INDEX_op_extrh_i64_i32: | ||
328 | + type_change = true; | ||
329 | + z_mask >>= 32; | ||
330 | + break; | ||
331 | + default: | ||
332 | + g_assert_not_reached(); | ||
333 | + } | ||
334 | + | ||
335 | + ctx->z_mask = z_mask; | ||
336 | + if (!type_change) { | ||
337 | + ctx->a_mask = z_mask_old ^ z_mask; | ||
338 | + } | ||
339 | + return fold_masks(ctx, op); | ||
340 | } | ||
341 | |||
342 | static bool fold_mb(OptContext *ctx, TCGOp *op) | ||
343 | @@ -XXX,XX +XXX,XX @@ static bool fold_movcond(OptContext *ctx, TCGOp *op) | ||
344 | return tcg_opt_gen_mov(ctx, op, op->args[0], op->args[4 - i]); | ||
345 | } | ||
346 | |||
347 | + ctx->z_mask = arg_info(op->args[3])->z_mask | ||
348 | + | arg_info(op->args[4])->z_mask; | ||
349 | + | ||
350 | if (arg_is_const(op->args[3]) && arg_is_const(op->args[4])) { | ||
351 | uint64_t tv = arg_info(op->args[3])->val; | ||
352 | uint64_t fv = arg_info(op->args[4])->val; | ||
353 | @@ -XXX,XX +XXX,XX @@ static bool fold_nand(OptContext *ctx, TCGOp *op) | ||
354 | |||
355 | static bool fold_neg(OptContext *ctx, TCGOp *op) | ||
356 | { | ||
357 | + uint64_t z_mask; | ||
358 | + | ||
359 | if (fold_const1(ctx, op)) { | ||
360 | return true; | ||
361 | } | ||
362 | + | ||
363 | + /* Set to 1 all bits to the left of the rightmost. */ | ||
364 | + z_mask = arg_info(op->args[1])->z_mask; | ||
365 | + ctx->z_mask = -(z_mask & -z_mask); | ||
366 | + | ||
367 | /* | ||
368 | * Because of fold_sub_to_neg, we want to always return true, | ||
369 | * via finish_folding. | ||
370 | @@ -XXX,XX +XXX,XX @@ static bool fold_or(OptContext *ctx, TCGOp *op) | ||
371 | fold_xx_to_x(ctx, op)) { | ||
372 | return true; | ||
373 | } | ||
374 | - return false; | ||
375 | + | ||
376 | + ctx->z_mask = arg_info(op->args[1])->z_mask | ||
377 | + | arg_info(op->args[2])->z_mask; | ||
378 | + return fold_masks(ctx, op); | ||
379 | } | ||
380 | |||
381 | static bool fold_orc(OptContext *ctx, TCGOp *op) | ||
382 | @@ -XXX,XX +XXX,XX @@ static bool fold_orc(OptContext *ctx, TCGOp *op) | ||
383 | |||
384 | static bool fold_qemu_ld(OptContext *ctx, TCGOp *op) | ||
385 | { | ||
386 | + const TCGOpDef *def = &tcg_op_defs[op->opc]; | ||
387 | + MemOpIdx oi = op->args[def->nb_oargs + def->nb_iargs]; | ||
388 | + MemOp mop = get_memop(oi); | ||
389 | + int width = 8 * memop_size(mop); | ||
390 | + | ||
391 | + if (!(mop & MO_SIGN) && width < 64) { | ||
392 | + ctx->z_mask = MAKE_64BIT_MASK(0, width); | ||
393 | + } | ||
394 | + | ||
395 | /* Opcodes that touch guest memory stop the mb optimization. */ | ||
396 | ctx->prev_mb = NULL; | ||
397 | return false; | ||
398 | @@ -XXX,XX +XXX,XX @@ static bool fold_setcond(OptContext *ctx, TCGOp *op) | ||
399 | if (i >= 0) { | ||
400 | return tcg_opt_gen_movi(ctx, op, op->args[0], i); | ||
401 | } | ||
402 | + | ||
403 | + ctx->z_mask = 1; | ||
404 | return false; | ||
405 | } | ||
406 | |||
407 | @@ -XXX,XX +XXX,XX @@ static bool fold_setcond2(OptContext *ctx, TCGOp *op) | ||
408 | op->opc = INDEX_op_setcond_i32; | ||
409 | break; | ||
410 | } | ||
411 | + | ||
412 | + ctx->z_mask = 1; | ||
413 | return false; | ||
414 | |||
415 | do_setcond_const: | ||
416 | @@ -XXX,XX +XXX,XX @@ static bool fold_setcond2(OptContext *ctx, TCGOp *op) | ||
417 | |||
418 | static bool fold_sextract(OptContext *ctx, TCGOp *op) | ||
419 | { | ||
420 | + int64_t z_mask_old, z_mask; | ||
421 | + | ||
422 | if (arg_is_const(op->args[1])) { | ||
423 | uint64_t t; | ||
424 | |||
425 | @@ -XXX,XX +XXX,XX @@ static bool fold_sextract(OptContext *ctx, TCGOp *op) | ||
426 | t = sextract64(t, op->args[2], op->args[3]); | ||
427 | return tcg_opt_gen_movi(ctx, op, op->args[0], t); | ||
428 | } | ||
429 | - return false; | ||
430 | + | ||
431 | + z_mask_old = arg_info(op->args[1])->z_mask; | ||
432 | + z_mask = sextract64(z_mask_old, op->args[2], op->args[3]); | ||
433 | + if (op->args[2] == 0 && z_mask >= 0) { | ||
434 | + ctx->a_mask = z_mask_old ^ z_mask; | ||
435 | + } | ||
436 | + ctx->z_mask = z_mask; | ||
437 | + | ||
438 | + return fold_masks(ctx, op); | ||
439 | } | ||
440 | |||
441 | static bool fold_shift(OptContext *ctx, TCGOp *op) | ||
442 | @@ -XXX,XX +XXX,XX @@ static bool fold_shift(OptContext *ctx, TCGOp *op) | ||
443 | fold_xi_to_x(ctx, op, 0)) { | ||
444 | return true; | ||
445 | } | ||
446 | + | ||
447 | + if (arg_is_const(op->args[2])) { | ||
448 | + ctx->z_mask = do_constant_folding(op->opc, ctx->type, | ||
449 | + arg_info(op->args[1])->z_mask, | ||
450 | + arg_info(op->args[2])->val); | ||
451 | + return fold_masks(ctx, op); | ||
452 | + } | ||
453 | return false; | ||
454 | } | ||
455 | |||
456 | @@ -XXX,XX +XXX,XX @@ static bool fold_sub2_i32(OptContext *ctx, TCGOp *op) | ||
457 | return fold_addsub2_i32(ctx, op, false); | ||
458 | } | ||
459 | |||
460 | +static bool fold_tcg_ld(OptContext *ctx, TCGOp *op) | ||
461 | +{ | ||
462 | + /* We can't do any folding with a load, but we can record bits. */ | ||
463 | + switch (op->opc) { | ||
464 | + CASE_OP_32_64(ld8u): | ||
465 | + ctx->z_mask = MAKE_64BIT_MASK(0, 8); | ||
466 | + break; | ||
467 | + CASE_OP_32_64(ld16u): | ||
468 | + ctx->z_mask = MAKE_64BIT_MASK(0, 16); | ||
469 | + break; | ||
470 | + case INDEX_op_ld32u_i64: | ||
471 | + ctx->z_mask = MAKE_64BIT_MASK(0, 32); | ||
472 | + break; | ||
473 | + default: | ||
474 | + g_assert_not_reached(); | ||
475 | + } | ||
476 | + return false; | ||
477 | +} | ||
478 | + | ||
479 | static bool fold_xor(OptContext *ctx, TCGOp *op) | ||
480 | { | ||
481 | if (fold_const2(ctx, op) || | ||
482 | @@ -XXX,XX +XXX,XX @@ static bool fold_xor(OptContext *ctx, TCGOp *op) | ||
483 | fold_xi_to_not(ctx, op, -1)) { | ||
484 | return true; | ||
485 | } | ||
486 | - return false; | ||
487 | + | ||
488 | + ctx->z_mask = arg_info(op->args[1])->z_mask | ||
489 | + | arg_info(op->args[2])->z_mask; | ||
490 | + return fold_masks(ctx, op); | ||
491 | } | ||
492 | |||
493 | /* Propagate constants and copies, fold constant expressions. */ | ||
494 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
495 | } | ||
496 | |||
497 | QTAILQ_FOREACH_SAFE(op, &s->ops, link, op_next) { | ||
498 | - uint64_t z_mask, partmask, affected, tmp; | ||
499 | TCGOpcode opc = op->opc; | ||
500 | const TCGOpDef *def; | ||
501 | bool done = false; | ||
502 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
503 | break; | ||
504 | } | ||
505 | |||
506 | - /* Simplify using known-zero bits. Currently only ops with a single | ||
507 | - output argument is supported. */ | ||
508 | - z_mask = -1; | ||
509 | - affected = -1; | ||
510 | - switch (opc) { | ||
511 | - CASE_OP_32_64(ext8s): | ||
512 | - if ((arg_info(op->args[1])->z_mask & 0x80) != 0) { | ||
513 | - break; | ||
514 | - } | ||
515 | - QEMU_FALLTHROUGH; | ||
516 | - CASE_OP_32_64(ext8u): | ||
517 | - z_mask = 0xff; | ||
518 | - goto and_const; | ||
519 | - CASE_OP_32_64(ext16s): | ||
520 | - if ((arg_info(op->args[1])->z_mask & 0x8000) != 0) { | ||
521 | - break; | ||
522 | - } | ||
523 | - QEMU_FALLTHROUGH; | ||
524 | - CASE_OP_32_64(ext16u): | ||
525 | - z_mask = 0xffff; | ||
526 | - goto and_const; | ||
527 | - case INDEX_op_ext32s_i64: | ||
528 | - if ((arg_info(op->args[1])->z_mask & 0x80000000) != 0) { | ||
529 | - break; | ||
530 | - } | ||
531 | - QEMU_FALLTHROUGH; | ||
532 | - case INDEX_op_ext32u_i64: | ||
533 | - z_mask = 0xffffffffU; | ||
534 | - goto and_const; | ||
535 | - | ||
536 | - CASE_OP_32_64(and): | ||
537 | - z_mask = arg_info(op->args[2])->z_mask; | ||
538 | - if (arg_is_const(op->args[2])) { | ||
539 | - and_const: | ||
540 | - affected = arg_info(op->args[1])->z_mask & ~z_mask; | ||
541 | - } | ||
542 | - z_mask = arg_info(op->args[1])->z_mask & z_mask; | ||
543 | - break; | ||
544 | - | ||
545 | - case INDEX_op_ext_i32_i64: | ||
546 | - if ((arg_info(op->args[1])->z_mask & 0x80000000) != 0) { | ||
547 | - break; | ||
548 | - } | ||
549 | - QEMU_FALLTHROUGH; | ||
550 | - case INDEX_op_extu_i32_i64: | ||
551 | - /* We do not compute affected as it is a size changing op. */ | ||
552 | - z_mask = (uint32_t)arg_info(op->args[1])->z_mask; | ||
553 | - break; | ||
554 | - | ||
555 | - CASE_OP_32_64(andc): | ||
556 | - /* Known-zeros does not imply known-ones. Therefore unless | ||
557 | - op->args[2] is constant, we can't infer anything from it. */ | ||
558 | - if (arg_is_const(op->args[2])) { | ||
559 | - z_mask = ~arg_info(op->args[2])->z_mask; | ||
560 | - goto and_const; | ||
561 | - } | ||
562 | - /* But we certainly know nothing outside args[1] may be set. */ | ||
563 | - z_mask = arg_info(op->args[1])->z_mask; | ||
564 | - break; | ||
565 | - | ||
566 | - case INDEX_op_sar_i32: | ||
567 | - if (arg_is_const(op->args[2])) { | ||
568 | - tmp = arg_info(op->args[2])->val & 31; | ||
569 | - z_mask = (int32_t)arg_info(op->args[1])->z_mask >> tmp; | ||
570 | - } | ||
571 | - break; | ||
572 | - case INDEX_op_sar_i64: | ||
573 | - if (arg_is_const(op->args[2])) { | ||
574 | - tmp = arg_info(op->args[2])->val & 63; | ||
575 | - z_mask = (int64_t)arg_info(op->args[1])->z_mask >> tmp; | ||
576 | - } | ||
577 | - break; | ||
578 | - | ||
579 | - case INDEX_op_shr_i32: | ||
580 | - if (arg_is_const(op->args[2])) { | ||
581 | - tmp = arg_info(op->args[2])->val & 31; | ||
582 | - z_mask = (uint32_t)arg_info(op->args[1])->z_mask >> tmp; | ||
583 | - } | ||
584 | - break; | ||
585 | - case INDEX_op_shr_i64: | ||
586 | - if (arg_is_const(op->args[2])) { | ||
587 | - tmp = arg_info(op->args[2])->val & 63; | ||
588 | - z_mask = (uint64_t)arg_info(op->args[1])->z_mask >> tmp; | ||
589 | - } | ||
590 | - break; | ||
591 | - | ||
592 | - case INDEX_op_extrl_i64_i32: | ||
593 | - z_mask = (uint32_t)arg_info(op->args[1])->z_mask; | ||
594 | - break; | ||
595 | - case INDEX_op_extrh_i64_i32: | ||
596 | - z_mask = (uint64_t)arg_info(op->args[1])->z_mask >> 32; | ||
597 | - break; | ||
598 | - | ||
599 | - CASE_OP_32_64(shl): | ||
600 | - if (arg_is_const(op->args[2])) { | ||
601 | - tmp = arg_info(op->args[2])->val & (TCG_TARGET_REG_BITS - 1); | ||
602 | - z_mask = arg_info(op->args[1])->z_mask << tmp; | ||
603 | - } | ||
604 | - break; | ||
605 | - | ||
606 | - CASE_OP_32_64(neg): | ||
607 | - /* Set to 1 all bits to the left of the rightmost. */ | ||
608 | - z_mask = -(arg_info(op->args[1])->z_mask | ||
609 | - & -arg_info(op->args[1])->z_mask); | ||
610 | - break; | ||
611 | - | ||
612 | - CASE_OP_32_64(deposit): | ||
613 | - z_mask = deposit64(arg_info(op->args[1])->z_mask, | ||
614 | - op->args[3], op->args[4], | ||
615 | - arg_info(op->args[2])->z_mask); | ||
616 | - break; | ||
617 | - | ||
618 | - CASE_OP_32_64(extract): | ||
619 | - z_mask = extract64(arg_info(op->args[1])->z_mask, | ||
620 | - op->args[2], op->args[3]); | ||
621 | - if (op->args[2] == 0) { | ||
622 | - affected = arg_info(op->args[1])->z_mask & ~z_mask; | ||
623 | - } | ||
624 | - break; | ||
625 | - CASE_OP_32_64(sextract): | ||
626 | - z_mask = sextract64(arg_info(op->args[1])->z_mask, | ||
627 | - op->args[2], op->args[3]); | ||
628 | - if (op->args[2] == 0 && (tcg_target_long)z_mask >= 0) { | ||
629 | - affected = arg_info(op->args[1])->z_mask & ~z_mask; | ||
630 | - } | ||
631 | - break; | ||
632 | - | ||
633 | - CASE_OP_32_64(or): | ||
634 | - CASE_OP_32_64(xor): | ||
635 | - z_mask = arg_info(op->args[1])->z_mask | ||
636 | - | arg_info(op->args[2])->z_mask; | ||
637 | - break; | ||
638 | - | ||
639 | - case INDEX_op_clz_i32: | ||
640 | - case INDEX_op_ctz_i32: | ||
641 | - z_mask = arg_info(op->args[2])->z_mask | 31; | ||
642 | - break; | ||
643 | - | ||
644 | - case INDEX_op_clz_i64: | ||
645 | - case INDEX_op_ctz_i64: | ||
646 | - z_mask = arg_info(op->args[2])->z_mask | 63; | ||
647 | - break; | ||
648 | - | ||
649 | - case INDEX_op_ctpop_i32: | ||
650 | - z_mask = 32 | 31; | ||
651 | - break; | ||
652 | - case INDEX_op_ctpop_i64: | ||
653 | - z_mask = 64 | 63; | ||
654 | - break; | ||
655 | - | ||
656 | - CASE_OP_32_64(setcond): | ||
657 | - case INDEX_op_setcond2_i32: | ||
658 | - z_mask = 1; | ||
659 | - break; | ||
660 | - | ||
661 | - CASE_OP_32_64(movcond): | ||
662 | - z_mask = arg_info(op->args[3])->z_mask | ||
663 | - | arg_info(op->args[4])->z_mask; | ||
664 | - break; | ||
665 | - | ||
666 | - CASE_OP_32_64(ld8u): | ||
667 | - z_mask = 0xff; | ||
668 | - break; | ||
669 | - CASE_OP_32_64(ld16u): | ||
670 | - z_mask = 0xffff; | ||
671 | - break; | ||
672 | - case INDEX_op_ld32u_i64: | ||
673 | - z_mask = 0xffffffffu; | ||
674 | - break; | ||
675 | - | ||
676 | - CASE_OP_32_64(qemu_ld): | ||
677 | - { | ||
678 | - MemOpIdx oi = op->args[def->nb_oargs + def->nb_iargs]; | ||
679 | - MemOp mop = get_memop(oi); | ||
680 | - if (!(mop & MO_SIGN)) { | ||
681 | - z_mask = (2ULL << ((8 << (mop & MO_SIZE)) - 1)) - 1; | ||
682 | - } | ||
683 | - } | ||
684 | - break; | ||
685 | - | ||
686 | - CASE_OP_32_64(bswap16): | ||
687 | - z_mask = arg_info(op->args[1])->z_mask; | ||
688 | - if (z_mask <= 0xffff) { | ||
689 | - op->args[2] |= TCG_BSWAP_IZ; | ||
690 | - } | ||
691 | - z_mask = bswap16(z_mask); | ||
692 | - switch (op->args[2] & (TCG_BSWAP_OZ | TCG_BSWAP_OS)) { | ||
693 | - case TCG_BSWAP_OZ: | ||
694 | - break; | ||
695 | - case TCG_BSWAP_OS: | ||
696 | - z_mask = (int16_t)z_mask; | ||
697 | - break; | ||
698 | - default: /* undefined high bits */ | ||
699 | - z_mask |= MAKE_64BIT_MASK(16, 48); | ||
700 | - break; | ||
701 | - } | ||
702 | - break; | ||
703 | - | ||
704 | - case INDEX_op_bswap32_i64: | ||
705 | - z_mask = arg_info(op->args[1])->z_mask; | ||
706 | - if (z_mask <= 0xffffffffu) { | ||
707 | - op->args[2] |= TCG_BSWAP_IZ; | ||
708 | - } | ||
709 | - z_mask = bswap32(z_mask); | ||
710 | - switch (op->args[2] & (TCG_BSWAP_OZ | TCG_BSWAP_OS)) { | ||
711 | - case TCG_BSWAP_OZ: | ||
712 | - break; | ||
713 | - case TCG_BSWAP_OS: | ||
714 | - z_mask = (int32_t)z_mask; | ||
715 | - break; | ||
716 | - default: /* undefined high bits */ | ||
717 | - z_mask |= MAKE_64BIT_MASK(32, 32); | ||
718 | - break; | ||
719 | - } | ||
720 | - break; | ||
721 | - | ||
722 | - default: | ||
723 | - break; | ||
724 | - } | ||
725 | - | ||
726 | - /* 32-bit ops generate 32-bit results. For the result is zero test | ||
727 | - below, we can ignore high bits, but for further optimizations we | ||
728 | - need to record that the high bits contain garbage. */ | ||
729 | - partmask = z_mask; | ||
730 | - if (ctx.type == TCG_TYPE_I32) { | ||
731 | - z_mask |= ~(tcg_target_ulong)0xffffffffu; | ||
732 | - partmask &= 0xffffffffu; | ||
733 | - affected &= 0xffffffffu; | ||
734 | - } | ||
735 | - ctx.z_mask = z_mask; | ||
736 | - | ||
737 | - if (partmask == 0) { | ||
738 | - tcg_opt_gen_movi(&ctx, op, op->args[0], 0); | ||
739 | - continue; | ||
740 | - } | ||
741 | - if (affected == 0) { | ||
742 | - tcg_opt_gen_mov(&ctx, op, op->args[0], op->args[1]); | ||
743 | - continue; | ||
744 | - } | ||
745 | + /* Assume all bits affected, and no bits known zero. */ | ||
746 | + ctx.a_mask = -1; | ||
747 | + ctx.z_mask = -1; | ||
748 | |||
749 | /* | ||
750 | * Process each opcode. | ||
751 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
752 | case INDEX_op_extrh_i64_i32: | ||
753 | done = fold_extu(&ctx, op); | ||
754 | break; | ||
755 | + CASE_OP_32_64(ld8u): | ||
756 | + CASE_OP_32_64(ld16u): | ||
757 | + case INDEX_op_ld32u_i64: | ||
758 | + done = fold_tcg_ld(&ctx, op); | ||
759 | + break; | ||
760 | case INDEX_op_mb: | ||
761 | done = fold_mb(&ctx, op); | ||
762 | break; | ||
763 | -- | 134 | -- |
764 | 2.25.1 | 135 | 2.34.1 |
765 | 136 | ||
766 | 137 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Rewrite the sections which talked about 'local temporaries'. | ||
2 | Remove some assumptions which no longer hold. | ||
1 | 3 | ||
4 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | --- | ||
7 | docs/devel/tcg-ops.rst | 230 +++++++++++++++++++++++------------------ | ||
8 | 1 file changed, 129 insertions(+), 101 deletions(-) | ||
9 | |||
10 | diff --git a/docs/devel/tcg-ops.rst b/docs/devel/tcg-ops.rst | ||
11 | index XXXXXXX..XXXXXXX 100644 | ||
12 | --- a/docs/devel/tcg-ops.rst | ||
13 | +++ b/docs/devel/tcg-ops.rst | ||
14 | @@ -XXX,XX +XXX,XX @@ TCG Intermediate Representation | ||
15 | Introduction | ||
16 | ============ | ||
17 | |||
18 | -TCG (Tiny Code Generator) began as a generic backend for a C | ||
19 | -compiler. It was simplified to be used in QEMU. It also has its roots | ||
20 | -in the QOP code generator written by Paul Brook. | ||
21 | +TCG (Tiny Code Generator) began as a generic backend for a C compiler. | ||
22 | +It was simplified to be used in QEMU. It also has its roots in the | ||
23 | +QOP code generator written by Paul Brook. | ||
24 | |||
25 | Definitions | ||
26 | =========== | ||
27 | |||
28 | -TCG receives RISC-like *TCG ops* and performs some optimizations on them, | ||
29 | -including liveness analysis and trivial constant expression | ||
30 | -evaluation. TCG ops are then implemented in the host CPU back end, | ||
31 | -also known as the TCG target. | ||
32 | - | ||
33 | -The TCG *target* is the architecture for which we generate the | ||
34 | -code. It is of course not the same as the "target" of QEMU which is | ||
35 | -the emulated architecture. As TCG started as a generic C backend used | ||
36 | -for cross compiling, it is assumed that the TCG target is different | ||
37 | -from the host, although it is never the case for QEMU. | ||
38 | +The TCG *target* is the architecture for which we generate the code. | ||
39 | +It is of course not the same as the "target" of QEMU which is the | ||
40 | +emulated architecture. As TCG started as a generic C backend used | ||
41 | +for cross compiling, the assumption was that TCG target might be | ||
42 | +different from the host, although this is never the case for QEMU. | ||
43 | |||
44 | In this document, we use *guest* to specify what architecture we are | ||
45 | emulating; *target* always means the TCG target, the machine on which | ||
46 | we are running QEMU. | ||
47 | |||
48 | -A TCG *function* corresponds to a QEMU Translated Block (TB). | ||
49 | - | ||
50 | -A TCG *temporary* is a variable only live in a basic block. Temporaries are allocated explicitly in each function. | ||
51 | - | ||
52 | -A TCG *local temporary* is a variable only live in a function. Local temporaries are allocated explicitly in each function. | ||
53 | - | ||
54 | -A TCG *global* is a variable which is live in all the functions | ||
55 | -(equivalent of a C global variable). They are defined before the | ||
56 | -functions defined. A TCG global can be a memory location (e.g. a QEMU | ||
57 | -CPU register), a fixed host register (e.g. the QEMU CPU state pointer) | ||
58 | -or a memory location which is stored in a register outside QEMU TBs | ||
59 | -(not implemented yet). | ||
60 | - | ||
61 | -A TCG *basic block* corresponds to a list of instructions terminated | ||
62 | -by a branch instruction. | ||
63 | - | ||
64 | An operation with *undefined behavior* may result in a crash. | ||
65 | |||
66 | An operation with *unspecified behavior* shall not crash. However, | ||
67 | the result may be one of several possibilities so may be considered | ||
68 | an *undefined result*. | ||
69 | |||
70 | -Intermediate representation | ||
71 | -=========================== | ||
72 | +Basic Blocks | ||
73 | +============ | ||
74 | |||
75 | -Introduction | ||
76 | ------------- | ||
77 | +A TCG *basic block* is a single entry, multiple exit region which | ||
78 | +corresponds to a list of instructions terminated by a label, or | ||
79 | +any branch instruction. | ||
80 | |||
81 | -TCG instructions operate on variables which are temporaries, local | ||
82 | -temporaries or globals. TCG instructions and variables are strongly | ||
83 | -typed. Two types are supported: 32 bit integers and 64 bit | ||
84 | -integers. Pointers are defined as an alias to 32 bit or 64 bit | ||
85 | -integers depending on the TCG target word size. | ||
86 | +A TCG *extended basic block* is a single entry, multiple exit region | ||
87 | +which corresponds to a list of instructions terminated by a label or | ||
88 | +an unconditional branch. Specifically, an extended basic block is | ||
89 | +a sequence of basic blocks connected by the fall-through paths of | ||
90 | +zero or more conditional branch instructions. | ||
91 | |||
92 | -Each instruction has a fixed number of output variable operands, input | ||
93 | -variable operands and always constant operands. | ||
94 | +Operations | ||
95 | +========== | ||
96 | |||
97 | -The notable exception is the call instruction which has a variable | ||
98 | -number of outputs and inputs. | ||
99 | +TCG instructions or *ops* operate on TCG *variables*, both of which | ||
100 | +are strongly typed. Each instruction has a fixed number of output | ||
101 | +variable operands, input variable operands and constant operands. | ||
102 | +Vector instructions have a field specifying the element size within | ||
103 | +the vector. The notable exception is the call instruction which has | ||
104 | +a variable number of outputs and inputs. | ||
105 | |||
106 | In the textual form, output operands usually come first, followed by | ||
107 | input operands, followed by constant operands. The output type is | ||
108 | @@ -XXX,XX +XXX,XX @@ included in the instruction name. Constants are prefixed with a '$'. | ||
109 | |||
110 | add_i32 t0, t1, t2 /* (t0 <- t1 + t2) */ | ||
111 | |||
112 | +Variables | ||
113 | +========= | ||
114 | |||
115 | -Assumptions | ||
116 | ------------ | ||
117 | +* ``TEMP_FIXED`` | ||
118 | |||
119 | -Basic blocks | ||
120 | -^^^^^^^^^^^^ | ||
121 | + There is one TCG *fixed global* variable, ``cpu_env``, which is | ||
122 | + live in all translation blocks, and holds a pointer to ``CPUArchState``. | ||
123 | + This variable is held in a host cpu register at all times in all | ||
124 | + translation blocks. | ||
125 | |||
126 | -* Basic blocks end after branches (e.g. brcond_i32 instruction), | ||
127 | - goto_tb and exit_tb instructions. | ||
128 | +* ``TEMP_GLOBAL`` | ||
129 | |||
130 | -* Basic blocks start after the end of a previous basic block, or at a | ||
131 | - set_label instruction. | ||
132 | + A TCG *global* is a variable which is live in all translation blocks, | ||
133 | + and corresponds to memory location that is within ``CPUArchState``. | ||
134 | + These may be specified as an offset from ``cpu_env``, in which case | ||
135 | + they are called *direct globals*, or may be specified as an offset | ||
136 | + from a direct global, in which case they are called *indirect globals*. | ||
137 | + Even indirect globals should still reference memory within | ||
138 | + ``CPUArchState``. All TCG globals are defined during | ||
139 | + ``TCGCPUOps.initialize``, before any translation blocks are generated. | ||
140 | |||
141 | -After the end of a basic block, the content of temporaries is | ||
142 | -destroyed, but local temporaries and globals are preserved. | ||
143 | +* ``TEMP_CONST`` | ||
144 | |||
145 | -Floating point types | ||
146 | -^^^^^^^^^^^^^^^^^^^^ | ||
147 | + A TCG *constant* is a variable which is live throughout the entire | ||
148 | + translation block, and contains a constant value. These variables | ||
149 | + are allocated on demand during translation and are hashed so that | ||
150 | + there is exactly one variable holding a given value. | ||
151 | |||
152 | -* Floating point types are not supported yet | ||
153 | +* ``TEMP_TB`` | ||
154 | |||
155 | -Pointers | ||
156 | -^^^^^^^^ | ||
157 | + A TCG *translation block temporary* is a variable which is live | ||
158 | + throughout the entire translation block, but dies on any exit. | ||
159 | + These temporaries are allocated explicitly during translation. | ||
160 | |||
161 | -* Depending on the TCG target, pointer size is 32 bit or 64 | ||
162 | - bit. The type ``TCG_TYPE_PTR`` is an alias to ``TCG_TYPE_I32`` or | ||
163 | - ``TCG_TYPE_I64``. | ||
164 | +* ``TEMP_EBB`` | ||
165 | + | ||
166 | + A TCG *extended basic block temporary* is a variable which is live | ||
167 | + throughout an extended basic block, but dies on any exit. | ||
168 | + These temporaries are allocated explicitly during translation. | ||
169 | + | ||
170 | +Types | ||
171 | +===== | ||
172 | + | ||
173 | +* ``TCG_TYPE_I32`` | ||
174 | + | ||
175 | + A 32-bit integer. | ||
176 | + | ||
177 | +* ``TCG_TYPE_I64`` | ||
178 | + | ||
179 | + A 64-bit integer. For 32-bit hosts, such variables are split into a pair | ||
180 | + of variables with ``type=TCG_TYPE_I32`` and ``base_type=TCG_TYPE_I64``. | ||
181 | + The ``temp_subindex`` for each indicates where it falls within the | ||
182 | + host-endian representation. | ||
183 | + | ||
184 | +* ``TCG_TYPE_PTR`` | ||
185 | + | ||
186 | + An alias for ``TCG_TYPE_I32`` or ``TCG_TYPE_I64``, depending on the size | ||
187 | + of a pointer for the host. | ||
188 | + | ||
189 | +* ``TCG_TYPE_REG`` | ||
190 | + | ||
191 | + An alias for ``TCG_TYPE_I32`` or ``TCG_TYPE_I64``, depending on the size | ||
192 | + of the integer registers for the host. This may be larger | ||
193 | + than ``TCG_TYPE_PTR`` depending on the host ABI. | ||
194 | + | ||
195 | +* ``TCG_TYPE_I128`` | ||
196 | + | ||
197 | + A 128-bit integer. For all hosts, such variables are split into a number | ||
198 | + of variables with ``type=TCG_TYPE_REG`` and ``base_type=TCG_TYPE_I128``. | ||
199 | + The ``temp_subindex`` for each indicates where it falls within the | ||
200 | + host-endian representation. | ||
201 | + | ||
202 | +* ``TCG_TYPE_V64`` | ||
203 | + | ||
204 | + A 64-bit vector. This type is valid only if the TCG target | ||
205 | + sets ``TCG_TARGET_HAS_v64``. | ||
206 | + | ||
207 | +* ``TCG_TYPE_V128`` | ||
208 | + | ||
209 | + A 128-bit vector. This type is valid only if the TCG target | ||
210 | + sets ``TCG_TARGET_HAS_v128``. | ||
211 | + | ||
212 | +* ``TCG_TYPE_V256`` | ||
213 | + | ||
214 | + A 256-bit vector. This type is valid only if the TCG target | ||
215 | + sets ``TCG_TARGET_HAS_v256``. | ||
216 | |||
217 | Helpers | ||
218 | -^^^^^^^ | ||
219 | +======= | ||
220 | |||
221 | -* Using the tcg_gen_helper_x_y it is possible to call any function | ||
222 | - taking i32, i64 or pointer types. By default, before calling a helper, | ||
223 | - all globals are stored at their canonical location and it is assumed | ||
224 | - that the function can modify them. By default, the helper is allowed to | ||
225 | - modify the CPU state or raise an exception. | ||
226 | +Helpers are registered in a guest-specific ``helper.h``, | ||
227 | +which is processed to generate ``tcg_gen_helper_*`` functions. | ||
228 | +With these functions it is possible to call a function taking | ||
229 | +i32, i64, i128 or pointer types. | ||
230 | |||
231 | - This can be overridden using the following function modifiers: | ||
232 | +By default, before calling a helper, all globals are stored at their | ||
233 | +canonical location. By default, the helper is allowed to modify the | ||
234 | +CPU state (including the state represented by tcg globals) | ||
235 | +or may raise an exception. This default can be overridden using the | ||
236 | +following function modifiers: | ||
237 | |||
238 | - - ``TCG_CALL_NO_READ_GLOBALS`` means that the helper does not read globals, | ||
239 | - either directly or via an exception. They will not be saved to their | ||
240 | - canonical locations before calling the helper. | ||
241 | +* ``TCG_CALL_NO_WRITE_GLOBALS`` | ||
242 | |||
243 | - - ``TCG_CALL_NO_WRITE_GLOBALS`` means that the helper does not modify any globals. | ||
244 | - They will only be saved to their canonical location before calling helpers, | ||
245 | - but they won't be reloaded afterwards. | ||
246 | + The helper does not modify any globals, but may read them. | ||
247 | + Globals will be saved to their canonical location before calling helpers, | ||
248 | + but need not be reloaded afterwards. | ||
249 | |||
250 | - - ``TCG_CALL_NO_SIDE_EFFECTS`` means that the call to the function is removed if | ||
251 | - the return value is not used. | ||
252 | +* ``TCG_CALL_NO_READ_GLOBALS`` | ||
253 | |||
254 | - Note that ``TCG_CALL_NO_READ_GLOBALS`` implies ``TCG_CALL_NO_WRITE_GLOBALS``. | ||
255 | + The helper does not read globals, either directly or via an exception. | ||
256 | + They will not be saved to their canonical locations before calling | ||
257 | + the helper. This implies ``TCG_CALL_NO_WRITE_GLOBALS``. | ||
258 | |||
259 | - On some TCG targets (e.g. x86), several calling conventions are | ||
260 | - supported. | ||
261 | +* ``TCG_CALL_NO_SIDE_EFFECTS`` | ||
262 | |||
263 | -Branches | ||
264 | -^^^^^^^^ | ||
265 | - | ||
266 | -* Use the instruction 'br' to jump to a label. | ||
267 | + The call to the helper function may be removed if the return value is | ||
268 | + not used. This means that it may not modify any CPU state nor may it | ||
269 | + raise an exception. | ||
270 | |||
271 | Code Optimizations | ||
272 | ------------------- | ||
273 | +================== | ||
274 | |||
275 | When generating instructions, you can count on at least the following | ||
276 | optimizations: | ||
277 | @@ -XXX,XX +XXX,XX @@ Recommended coding rules for best performance | ||
278 | often modified, e.g. the integer registers and the condition | ||
279 | codes. TCG will be able to use host registers to store them. | ||
280 | |||
281 | -- Avoid globals stored in fixed registers. They must be used only to | ||
282 | - store the pointer to the CPU state and possibly to store a pointer | ||
283 | - to a register window. | ||
284 | - | ||
285 | -- Use temporaries. Use local temporaries only when really needed, | ||
286 | - e.g. when you need to use a value after a jump. Local temporaries | ||
287 | - introduce a performance hit in the current TCG implementation: their | ||
288 | - content is saved to memory at end of each basic block. | ||
289 | - | ||
290 | -- Free temporaries and local temporaries when they are no longer used | ||
291 | - (tcg_temp_free). Since tcg_const_x() also creates a temporary, you | ||
292 | - should free it after it is used. Freeing temporaries does not yield | ||
293 | - a better generated code, but it reduces the memory usage of TCG and | ||
294 | - the speed of the translation. | ||
295 | +- Free temporaries when they are no longer used (``tcg_temp_free``). | ||
296 | + Since ``tcg_const_x`` also creates a temporary, you should free it | ||
297 | + after it is used. | ||
298 | |||
299 | - Don't hesitate to use helpers for complicated or seldom used guest | ||
300 | instructions. There is little performance advantage in using TCG to | ||
301 | @@ -XXX,XX +XXX,XX @@ Recommended coding rules for best performance | ||
302 | the instruction is mostly doing loads and stores, and in those cases | ||
303 | inline TCG may still be faster for longer sequences. | ||
304 | |||
305 | -- The hard limit on the number of TCG instructions you can generate | ||
306 | - per guest instruction is set by ``MAX_OP_PER_INSTR`` in ``exec-all.h`` -- | ||
307 | - you cannot exceed this without risking a buffer overrun. | ||
308 | - | ||
309 | - Use the 'discard' instruction if you know that TCG won't be able to | ||
310 | prove that a given global is "dead" at a given program point. The | ||
311 | x86 guest uses it to improve the condition codes optimisation. | ||
312 | -- | ||
313 | 2.34.1 | diff view generated by jsdifflib |