1 | The following changes since commit d0dddab40e472ba62b5f43f11cc7dba085dabe71: | 1 | The following changes since commit c52d69e7dbaaed0ffdef8125e79218672c30161d: |
---|---|---|---|
2 | 2 | ||
3 | Merge remote-tracking branch 'remotes/mst/tags/for_upstream' into staging (2021-02-05 15:27:02 +0000) | 3 | Merge remote-tracking branch 'remotes/cschoenebeck/tags/pull-9p-20211027' into staging (2021-10-27 11:45:18 -0700) |
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-20210205 | 7 | https://gitlab.com/rth7680/qemu.git tags/pull-tcg-20211027 |
8 | 8 | ||
9 | for you to fetch changes up to fb6916dd6ca8bb4b42d44baba9c67ecaf2279577: | 9 | for you to fetch changes up to 820c025f0dcacf2f3c12735b1f162893fbfa7bc6: |
10 | 10 | ||
11 | accel: introduce AccelCPUClass extending CPUClass (2021-02-05 10:24:15 -1000) | 11 | tcg/optimize: Propagate sign info for shifting (2021-10-27 17:11:23 -0700) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | TCGCPUOps cleanups (claudio) | 14 | Improvements to qemu/int128 |
15 | tcg/s390 compare fix (phil) | 15 | Fixes for 128/64 division. |
16 | tcg/aarch64 rotli_vec fix | 16 | Cleanup tcg/optimize.c |
17 | tcg/tci cleanups and fixes | 17 | Optimize redundant sign extensions |
18 | 18 | ||
19 | ---------------------------------------------------------------- | 19 | ---------------------------------------------------------------- |
20 | Claudio Fontana (13): | 20 | Frédéric Pétrot (1): |
21 | target/riscv: remove CONFIG_TCG, as it is always TCG | 21 | qemu/int128: Add int128_{not,xor} |
22 | accel/tcg: split TCG-only code from cpu_exec_realizefn | ||
23 | target/arm: do not use cc->do_interrupt for KVM directly | ||
24 | cpu: move cc->do_interrupt to tcg_ops | ||
25 | cpu: move cc->transaction_failed to tcg_ops | ||
26 | cpu: move do_unaligned_access to tcg_ops | ||
27 | physmem: make watchpoint checking code TCG-only | ||
28 | cpu: move adjust_watchpoint_address to tcg_ops | ||
29 | cpu: move debug_check_watchpoint to tcg_ops | ||
30 | cpu: tcg_ops: move to tcg-cpu-ops.h, keep a pointer in CPUClass | ||
31 | accel: extend AccelState and AccelClass to user-mode | ||
32 | accel: replace struct CpusAccel with AccelOpsClass | ||
33 | accel: introduce AccelCPUClass extending CPUClass | ||
34 | 22 | ||
35 | Eduardo Habkost (5): | 23 | Luis Pires (4): |
36 | cpu: Introduce TCGCpuOperations struct | 24 | host-utils: move checks out of divu128/divs128 |
37 | cpu: Move synchronize_from_tb() to tcg_ops | 25 | host-utils: move udiv_qrnnd() to host-utils |
38 | cpu: Move cpu_exec_* to tcg_ops | 26 | host-utils: add 128-bit quotient support to divu128/divs128 |
39 | cpu: Move tlb_fill to tcg_ops | 27 | host-utils: add unit tests for divu128/divs128 |
40 | cpu: Move debug_excp_handler to tcg_ops | ||
41 | 28 | ||
42 | Philippe Mathieu-Daudé (2): | 29 | Richard Henderson (51): |
43 | tcg/s390: Fix compare instruction from extended-immediate facility | 30 | tcg/optimize: Rename "mask" to "z_mask" |
44 | exec/cpu-defs: Remove TCG backends dependency | 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 | ||
45 | 81 | ||
46 | Richard Henderson (24): | 82 | include/fpu/softfloat-macros.h | 82 -- |
47 | tcg/aarch64: Do not convert TCGArg to temps that are not temps | 83 | include/hw/clock.h | 5 +- |
48 | configure: Fix --enable-tcg-interpreter | 84 | include/qemu/host-utils.h | 121 +- |
49 | tcg/tci: Make tci_tb_ptr thread-local | 85 | include/qemu/int128.h | 20 + |
50 | tcg/tci: Inline tci_write_reg32s into the only caller | 86 | target/ppc/int_helper.c | 23 +- |
51 | tcg/tci: Inline tci_write_reg8 into its callers | 87 | tcg/optimize.c | 2644 ++++++++++++++++++++++++---------------- |
52 | tcg/tci: Inline tci_write_reg16 into the only caller | 88 | tests/unit/test-div128.c | 197 +++ |
53 | tcg/tci: Inline tci_write_reg32 into all callers | 89 | util/host-utils.c | 147 ++- |
54 | tcg/tci: Inline tci_write_reg64 into 64-bit callers | 90 | tests/unit/meson.build | 1 + |
55 | tcg/tci: Merge INDEX_op_ld8u_{i32,i64} | 91 | 9 files changed, 2053 insertions(+), 1187 deletions(-) |
56 | tcg/tci: Merge INDEX_op_ld8s_{i32,i64} | 92 | create mode 100644 tests/unit/test-div128.c |
57 | tcg/tci: Merge INDEX_op_ld16u_{i32,i64} | ||
58 | tcg/tci: Merge INDEX_op_ld16s_{i32,i64} | ||
59 | tcg/tci: Merge INDEX_op_{ld_i32,ld32u_i64} | ||
60 | tcg/tci: Merge INDEX_op_st8_{i32,i64} | ||
61 | tcg/tci: Merge INDEX_op_st16_{i32,i64} | ||
62 | tcg/tci: Move stack bounds check to compile-time | ||
63 | tcg/tci: Merge INDEX_op_{st_i32,st32_i64} | ||
64 | tcg/tci: Use g_assert_not_reached | ||
65 | tcg/tci: Remove dead code for TCG_TARGET_HAS_div2_* | ||
66 | tcg/tci: Implement 64-bit division | ||
67 | tcg/tci: Remove TODO as unused | ||
68 | tcg/tci: Restrict TCG_TARGET_NB_REGS to 16 | ||
69 | tcg/tci: Fix TCG_REG_R4 misusage | ||
70 | tcg/tci: Remove TCG_CONST | ||
71 | 93 | ||
72 | Stefan Weil (2): | ||
73 | tcg/tci: Implement INDEX_op_ld16s_i32 | ||
74 | tcg/tci: Implement INDEX_op_ld8s_i64 | ||
75 | |||
76 | configure | 5 +- | ||
77 | accel/accel-softmmu.h | 15 + | ||
78 | accel/kvm/kvm-cpus.h | 2 - | ||
79 | .../{tcg-cpus-icount.h => tcg-accel-ops-icount.h} | 2 + | ||
80 | accel/tcg/tcg-accel-ops-mttcg.h | 19 + | ||
81 | accel/tcg/{tcg-cpus-rr.h => tcg-accel-ops-rr.h} | 0 | ||
82 | accel/tcg/{tcg-cpus.h => tcg-accel-ops.h} | 6 +- | ||
83 | include/exec/cpu-all.h | 11 +- | ||
84 | include/exec/cpu-defs.h | 3 - | ||
85 | include/exec/exec-all.h | 2 +- | ||
86 | include/hw/boards.h | 2 +- | ||
87 | include/hw/core/accel-cpu.h | 38 ++ | ||
88 | include/hw/core/cpu.h | 86 +--- | ||
89 | include/hw/core/tcg-cpu-ops.h | 97 +++++ | ||
90 | include/{sysemu => qemu}/accel.h | 16 +- | ||
91 | include/sysemu/accel-ops.h | 45 ++ | ||
92 | include/sysemu/cpus.h | 26 +- | ||
93 | include/sysemu/hvf.h | 2 +- | ||
94 | include/sysemu/kvm.h | 2 +- | ||
95 | include/sysemu/kvm_int.h | 2 +- | ||
96 | target/arm/internals.h | 6 + | ||
97 | target/i386/hax/{hax-cpus.h => hax-accel-ops.h} | 2 - | ||
98 | target/i386/hax/hax-windows.h | 2 +- | ||
99 | target/i386/hvf/{hvf-cpus.h => hvf-accel-ops.h} | 2 - | ||
100 | target/i386/hvf/hvf-i386.h | 2 +- | ||
101 | target/i386/whpx/{whpx-cpus.h => whpx-accel-ops.h} | 2 - | ||
102 | tcg/tci/tcg-target-con-set.h | 6 +- | ||
103 | tcg/tci/tcg-target.h | 37 +- | ||
104 | accel/accel-common.c | 105 +++++ | ||
105 | accel/{accel.c => accel-softmmu.c} | 61 ++- | ||
106 | accel/accel-user.c | 24 ++ | ||
107 | accel/kvm/{kvm-cpus.c => kvm-accel-ops.c} | 28 +- | ||
108 | accel/kvm/kvm-all.c | 2 - | ||
109 | accel/qtest/qtest.c | 25 +- | ||
110 | accel/tcg/cpu-exec.c | 53 ++- | ||
111 | accel/tcg/cputlb.c | 34 +- | ||
112 | .../{tcg-cpus-icount.c => tcg-accel-ops-icount.c} | 21 +- | ||
113 | .../{tcg-cpus-mttcg.c => tcg-accel-ops-mttcg.c} | 14 +- | ||
114 | accel/tcg/{tcg-cpus-rr.c => tcg-accel-ops-rr.c} | 13 +- | ||
115 | accel/tcg/{tcg-cpus.c => tcg-accel-ops.c} | 47 +- | ||
116 | accel/tcg/tcg-all.c | 19 +- | ||
117 | accel/tcg/user-exec.c | 8 +- | ||
118 | accel/xen/xen-all.c | 26 +- | ||
119 | bsd-user/main.c | 11 +- | ||
120 | cpu.c | 66 +-- | ||
121 | hw/core/cpu.c | 21 +- | ||
122 | hw/mips/jazz.c | 12 +- | ||
123 | linux-user/main.c | 7 +- | ||
124 | softmmu/cpus.c | 12 +- | ||
125 | softmmu/memory.c | 2 +- | ||
126 | softmmu/physmem.c | 149 ++++--- | ||
127 | softmmu/qtest.c | 2 +- | ||
128 | softmmu/vl.c | 9 +- | ||
129 | target/alpha/cpu.c | 21 +- | ||
130 | target/arm/cpu.c | 45 +- | ||
131 | target/arm/cpu64.c | 4 +- | ||
132 | target/arm/cpu_tcg.c | 32 +- | ||
133 | target/arm/helper.c | 4 + | ||
134 | target/arm/kvm64.c | 6 +- | ||
135 | target/avr/cpu.c | 19 +- | ||
136 | target/avr/helper.c | 5 +- | ||
137 | target/cris/cpu.c | 43 +- | ||
138 | target/cris/helper.c | 5 +- | ||
139 | target/hppa/cpu.c | 24 +- | ||
140 | target/i386/hax/{hax-cpus.c => hax-accel-ops.c} | 33 +- | ||
141 | target/i386/hax/hax-all.c | 7 +- | ||
142 | target/i386/hax/hax-mem.c | 2 +- | ||
143 | target/i386/hax/hax-posix.c | 2 +- | ||
144 | target/i386/hax/hax-windows.c | 2 +- | ||
145 | target/i386/hvf/{hvf-cpus.c => hvf-accel-ops.c} | 29 +- | ||
146 | target/i386/hvf/hvf.c | 5 +- | ||
147 | target/i386/hvf/x86_task.c | 2 +- | ||
148 | target/i386/hvf/x86hvf.c | 2 +- | ||
149 | target/i386/tcg/tcg-cpu.c | 26 +- | ||
150 | target/i386/whpx/{whpx-cpus.c => whpx-accel-ops.c} | 33 +- | ||
151 | target/i386/whpx/whpx-all.c | 9 +- | ||
152 | target/lm32/cpu.c | 19 +- | ||
153 | target/m68k/cpu.c | 19 +- | ||
154 | target/microblaze/cpu.c | 25 +- | ||
155 | target/mips/cpu.c | 35 +- | ||
156 | target/moxie/cpu.c | 15 +- | ||
157 | target/nios2/cpu.c | 18 +- | ||
158 | target/openrisc/cpu.c | 17 +- | ||
159 | target/riscv/cpu.c | 26 +- | ||
160 | target/riscv/cpu_helper.c | 2 +- | ||
161 | target/rx/cpu.c | 20 +- | ||
162 | target/s390x/cpu.c | 33 +- | ||
163 | target/s390x/excp_helper.c | 2 +- | ||
164 | target/sh4/cpu.c | 21 +- | ||
165 | target/sparc/cpu.c | 25 +- | ||
166 | target/tilegx/cpu.c | 17 +- | ||
167 | target/tricore/cpu.c | 12 +- | ||
168 | target/unicore32/cpu.c | 17 +- | ||
169 | target/xtensa/cpu.c | 23 +- | ||
170 | target/xtensa/helper.c | 4 +- | ||
171 | tcg/tcg-common.c | 4 - | ||
172 | tcg/tci.c | 479 ++++++++------------- | ||
173 | target/ppc/translate_init.c.inc | 39 +- | ||
174 | tcg/aarch64/tcg-target.c.inc | 7 +- | ||
175 | tcg/s390/tcg-target.c.inc | 2 +- | ||
176 | tcg/tci/tcg-target.c.inc | 149 ++----- | ||
177 | MAINTAINERS | 7 +- | ||
178 | accel/kvm/meson.build | 2 +- | ||
179 | accel/meson.build | 4 +- | ||
180 | accel/tcg/meson.build | 10 +- | ||
181 | target/i386/hax/meson.build | 2 +- | ||
182 | target/i386/hvf/meson.build | 2 +- | ||
183 | target/i386/whpx/meson.build | 2 +- | ||
184 | 108 files changed, 1565 insertions(+), 1065 deletions(-) | ||
185 | create mode 100644 accel/accel-softmmu.h | ||
186 | rename accel/tcg/{tcg-cpus-icount.h => tcg-accel-ops-icount.h} (88%) | ||
187 | create mode 100644 accel/tcg/tcg-accel-ops-mttcg.h | ||
188 | rename accel/tcg/{tcg-cpus-rr.h => tcg-accel-ops-rr.h} (100%) | ||
189 | rename accel/tcg/{tcg-cpus.h => tcg-accel-ops.h} (72%) | ||
190 | create mode 100644 include/hw/core/accel-cpu.h | ||
191 | create mode 100644 include/hw/core/tcg-cpu-ops.h | ||
192 | rename include/{sysemu => qemu}/accel.h (94%) | ||
193 | create mode 100644 include/sysemu/accel-ops.h | ||
194 | rename target/i386/hax/{hax-cpus.h => hax-accel-ops.h} (95%) | ||
195 | rename target/i386/hvf/{hvf-cpus.h => hvf-accel-ops.h} (94%) | ||
196 | rename target/i386/whpx/{whpx-cpus.h => whpx-accel-ops.h} (96%) | ||
197 | create mode 100644 accel/accel-common.c | ||
198 | rename accel/{accel.c => accel-softmmu.c} (64%) | ||
199 | create mode 100644 accel/accel-user.c | ||
200 | rename accel/kvm/{kvm-cpus.c => kvm-accel-ops.c} (72%) | ||
201 | rename accel/tcg/{tcg-cpus-icount.c => tcg-accel-ops-icount.c} (89%) | ||
202 | rename accel/tcg/{tcg-cpus-mttcg.c => tcg-accel-ops-mttcg.c} (92%) | ||
203 | rename accel/tcg/{tcg-cpus-rr.c => tcg-accel-ops-rr.c} (97%) | ||
204 | rename accel/tcg/{tcg-cpus.c => tcg-accel-ops.c} (63%) | ||
205 | rename target/i386/hax/{hax-cpus.c => hax-accel-ops.c} (69%) | ||
206 | rename target/i386/hvf/{hvf-cpus.c => hvf-accel-ops.c} (84%) | ||
207 | rename target/i386/whpx/{whpx-cpus.c => whpx-accel-ops.c} (71%) | ||
208 | diff view generated by jsdifflib |
1 | From: Claudio Fontana <cfontana@suse.de> | 1 | From: Frédéric Pétrot <frederic.petrot@univ-grenoble-alpes.fr> |
---|---|---|---|
2 | 2 | ||
3 | This will allow us to centralize the registration of | 3 | Addition of not and xor on 128-bit integers. |
4 | the cpus.c module accelerator operations (in accel/accel-softmmu.c), | ||
5 | and trigger it automatically using object hierarchy lookup from the | ||
6 | new accel_init_interfaces() initialization step, depending just on | ||
7 | which accelerators are available in the code. | ||
8 | 4 | ||
9 | Rename all tcg-cpus.c, kvm-cpus.c, etc to tcg-accel-ops.c, | 5 | Signed-off-by: Frédéric Pétrot <frederic.petrot@univ-grenoble-alpes.fr> |
10 | kvm-accel-ops.c, etc, matching the object type names. | 6 | Co-authored-by: Fabien Portas <fabien.portas@grenoble-inp.org> |
11 | 7 | Message-Id: <20211025122818.168890-3-frederic.petrot@univ-grenoble-alpes.fr> | |
12 | Signed-off-by: Claudio Fontana <cfontana@suse.de> | 8 | [rth: Split out logical operations.] |
13 | Message-Id: <20210204163931.7358-18-cfontana@suse.de> | 9 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
14 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 10 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
15 | --- | 11 | --- |
16 | accel/accel-softmmu.h | 15 ++++++ | 12 | include/qemu/int128.h | 20 ++++++++++++++++++++ |
17 | accel/kvm/kvm-cpus.h | 2 - | 13 | 1 file changed, 20 insertions(+) |
18 | ...g-cpus-icount.h => tcg-accel-ops-icount.h} | 2 + | ||
19 | accel/tcg/tcg-accel-ops-mttcg.h | 19 ++++++++ | ||
20 | .../tcg/{tcg-cpus-rr.h => tcg-accel-ops-rr.h} | 0 | ||
21 | accel/tcg/{tcg-cpus.h => tcg-accel-ops.h} | 6 +-- | ||
22 | include/qemu/accel.h | 2 + | ||
23 | include/sysemu/accel-ops.h | 45 ++++++++++++++++++ | ||
24 | include/sysemu/cpus.h | 26 ++-------- | ||
25 | .../i386/hax/{hax-cpus.h => hax-accel-ops.h} | 2 - | ||
26 | target/i386/hax/hax-windows.h | 2 +- | ||
27 | .../i386/hvf/{hvf-cpus.h => hvf-accel-ops.h} | 2 - | ||
28 | .../whpx/{whpx-cpus.h => whpx-accel-ops.h} | 2 - | ||
29 | accel/accel-common.c | 11 +++++ | ||
30 | accel/accel-softmmu.c | 44 +++++++++++++++-- | ||
31 | accel/kvm/{kvm-cpus.c => kvm-accel-ops.c} | 28 ++++++++--- | ||
32 | accel/kvm/kvm-all.c | 2 - | ||
33 | accel/qtest/qtest.c | 23 ++++++--- | ||
34 | ...g-cpus-icount.c => tcg-accel-ops-icount.c} | 21 +++------ | ||
35 | ...tcg-cpus-mttcg.c => tcg-accel-ops-mttcg.c} | 14 ++---- | ||
36 | .../tcg/{tcg-cpus-rr.c => tcg-accel-ops-rr.c} | 13 ++--- | ||
37 | accel/tcg/{tcg-cpus.c => tcg-accel-ops.c} | 47 ++++++++++++++++++- | ||
38 | accel/tcg/tcg-all.c | 12 ----- | ||
39 | accel/xen/xen-all.c | 24 ++++++---- | ||
40 | bsd-user/main.c | 3 +- | ||
41 | linux-user/main.c | 1 + | ||
42 | softmmu/cpus.c | 12 ++--- | ||
43 | softmmu/vl.c | 7 ++- | ||
44 | .../i386/hax/{hax-cpus.c => hax-accel-ops.c} | 33 +++++++++---- | ||
45 | target/i386/hax/hax-all.c | 5 +- | ||
46 | target/i386/hax/hax-mem.c | 2 +- | ||
47 | target/i386/hax/hax-posix.c | 2 +- | ||
48 | target/i386/hax/hax-windows.c | 2 +- | ||
49 | .../i386/hvf/{hvf-cpus.c => hvf-accel-ops.c} | 29 +++++++++--- | ||
50 | target/i386/hvf/hvf.c | 3 +- | ||
51 | target/i386/hvf/x86hvf.c | 2 +- | ||
52 | .../whpx/{whpx-cpus.c => whpx-accel-ops.c} | 33 +++++++++---- | ||
53 | target/i386/whpx/whpx-all.c | 7 +-- | ||
54 | MAINTAINERS | 3 +- | ||
55 | accel/kvm/meson.build | 2 +- | ||
56 | accel/tcg/meson.build | 8 ++-- | ||
57 | target/i386/hax/meson.build | 2 +- | ||
58 | target/i386/hvf/meson.build | 2 +- | ||
59 | target/i386/whpx/meson.build | 2 +- | ||
60 | 44 files changed, 361 insertions(+), 163 deletions(-) | ||
61 | create mode 100644 accel/accel-softmmu.h | ||
62 | rename accel/tcg/{tcg-cpus-icount.h => tcg-accel-ops-icount.h} (88%) | ||
63 | create mode 100644 accel/tcg/tcg-accel-ops-mttcg.h | ||
64 | rename accel/tcg/{tcg-cpus-rr.h => tcg-accel-ops-rr.h} (100%) | ||
65 | rename accel/tcg/{tcg-cpus.h => tcg-accel-ops.h} (72%) | ||
66 | create mode 100644 include/sysemu/accel-ops.h | ||
67 | rename target/i386/hax/{hax-cpus.h => hax-accel-ops.h} (95%) | ||
68 | rename target/i386/hvf/{hvf-cpus.h => hvf-accel-ops.h} (94%) | ||
69 | rename target/i386/whpx/{whpx-cpus.h => whpx-accel-ops.h} (96%) | ||
70 | rename accel/kvm/{kvm-cpus.c => kvm-accel-ops.c} (72%) | ||
71 | rename accel/tcg/{tcg-cpus-icount.c => tcg-accel-ops-icount.c} (89%) | ||
72 | rename accel/tcg/{tcg-cpus-mttcg.c => tcg-accel-ops-mttcg.c} (92%) | ||
73 | rename accel/tcg/{tcg-cpus-rr.c => tcg-accel-ops-rr.c} (97%) | ||
74 | rename accel/tcg/{tcg-cpus.c => tcg-accel-ops.c} (63%) | ||
75 | rename target/i386/hax/{hax-cpus.c => hax-accel-ops.c} (69%) | ||
76 | rename target/i386/hvf/{hvf-cpus.c => hvf-accel-ops.c} (84%) | ||
77 | rename target/i386/whpx/{whpx-cpus.c => whpx-accel-ops.c} (71%) | ||
78 | 14 | ||
79 | diff --git a/accel/accel-softmmu.h b/accel/accel-softmmu.h | 15 | diff --git a/include/qemu/int128.h b/include/qemu/int128.h |
80 | new file mode 100644 | ||
81 | index XXXXXXX..XXXXXXX | ||
82 | --- /dev/null | ||
83 | +++ b/accel/accel-softmmu.h | ||
84 | @@ -XXX,XX +XXX,XX @@ | ||
85 | +/* | ||
86 | + * QEMU System Emulation accel internal functions | ||
87 | + * | ||
88 | + * Copyright 2021 SUSE LLC | ||
89 | + * | ||
90 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
91 | + * See the COPYING file in the top-level directory. | ||
92 | + */ | ||
93 | + | ||
94 | +#ifndef ACCEL_SOFTMMU_H | ||
95 | +#define ACCEL_SOFTMMU_H | ||
96 | + | ||
97 | +void accel_init_ops_interfaces(AccelClass *ac); | ||
98 | + | ||
99 | +#endif /* ACCEL_SOFTMMU_H */ | ||
100 | diff --git a/accel/kvm/kvm-cpus.h b/accel/kvm/kvm-cpus.h | ||
101 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
102 | --- a/accel/kvm/kvm-cpus.h | 17 | --- a/include/qemu/int128.h |
103 | +++ b/accel/kvm/kvm-cpus.h | 18 | +++ b/include/qemu/int128.h |
104 | @@ -XXX,XX +XXX,XX @@ | 19 | @@ -XXX,XX +XXX,XX @@ static inline Int128 int128_exts64(int64_t a) |
105 | 20 | return a; | |
106 | #include "sysemu/cpus.h" | ||
107 | |||
108 | -extern const CpusAccel kvm_cpus; | ||
109 | - | ||
110 | int kvm_init_vcpu(CPUState *cpu, Error **errp); | ||
111 | int kvm_cpu_exec(CPUState *cpu); | ||
112 | void kvm_destroy_vcpu(CPUState *cpu); | ||
113 | diff --git a/accel/tcg/tcg-cpus-icount.h b/accel/tcg/tcg-accel-ops-icount.h | ||
114 | similarity index 88% | ||
115 | rename from accel/tcg/tcg-cpus-icount.h | ||
116 | rename to accel/tcg/tcg-accel-ops-icount.h | ||
117 | index XXXXXXX..XXXXXXX 100644 | ||
118 | --- a/accel/tcg/tcg-cpus-icount.h | ||
119 | +++ b/accel/tcg/tcg-accel-ops-icount.h | ||
120 | @@ -XXX,XX +XXX,XX @@ void icount_handle_deadline(void); | ||
121 | void icount_prepare_for_run(CPUState *cpu); | ||
122 | void icount_process_data(CPUState *cpu); | ||
123 | |||
124 | +void icount_handle_interrupt(CPUState *cpu, int mask); | ||
125 | + | ||
126 | #endif /* TCG_CPUS_ICOUNT_H */ | ||
127 | diff --git a/accel/tcg/tcg-accel-ops-mttcg.h b/accel/tcg/tcg-accel-ops-mttcg.h | ||
128 | new file mode 100644 | ||
129 | index XXXXXXX..XXXXXXX | ||
130 | --- /dev/null | ||
131 | +++ b/accel/tcg/tcg-accel-ops-mttcg.h | ||
132 | @@ -XXX,XX +XXX,XX @@ | ||
133 | +/* | ||
134 | + * QEMU TCG Multi Threaded vCPUs implementation | ||
135 | + * | ||
136 | + * Copyright 2021 SUSE LLC | ||
137 | + * | ||
138 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
139 | + * See the COPYING file in the top-level directory. | ||
140 | + */ | ||
141 | + | ||
142 | +#ifndef TCG_CPUS_MTTCG_H | ||
143 | +#define TCG_CPUS_MTTCG_H | ||
144 | + | ||
145 | +/* kick MTTCG vCPU thread */ | ||
146 | +void mttcg_kick_vcpu_thread(CPUState *cpu); | ||
147 | + | ||
148 | +/* start an mttcg vCPU thread */ | ||
149 | +void mttcg_start_vcpu_thread(CPUState *cpu); | ||
150 | + | ||
151 | +#endif /* TCG_CPUS_MTTCG_H */ | ||
152 | diff --git a/accel/tcg/tcg-cpus-rr.h b/accel/tcg/tcg-accel-ops-rr.h | ||
153 | similarity index 100% | ||
154 | rename from accel/tcg/tcg-cpus-rr.h | ||
155 | rename to accel/tcg/tcg-accel-ops-rr.h | ||
156 | diff --git a/accel/tcg/tcg-cpus.h b/accel/tcg/tcg-accel-ops.h | ||
157 | similarity index 72% | ||
158 | rename from accel/tcg/tcg-cpus.h | ||
159 | rename to accel/tcg/tcg-accel-ops.h | ||
160 | index XXXXXXX..XXXXXXX 100644 | ||
161 | --- a/accel/tcg/tcg-cpus.h | ||
162 | +++ b/accel/tcg/tcg-accel-ops.h | ||
163 | @@ -XXX,XX +XXX,XX @@ | ||
164 | |||
165 | #include "sysemu/cpus.h" | ||
166 | |||
167 | -extern const CpusAccel tcg_cpus_mttcg; | ||
168 | -extern const CpusAccel tcg_cpus_icount; | ||
169 | -extern const CpusAccel tcg_cpus_rr; | ||
170 | - | ||
171 | void tcg_cpus_destroy(CPUState *cpu); | ||
172 | int tcg_cpus_exec(CPUState *cpu); | ||
173 | -void tcg_cpus_handle_interrupt(CPUState *cpu, int mask); | ||
174 | +void tcg_handle_interrupt(CPUState *cpu, int mask); | ||
175 | |||
176 | #endif /* TCG_CPUS_H */ | ||
177 | diff --git a/include/qemu/accel.h b/include/qemu/accel.h | ||
178 | index XXXXXXX..XXXXXXX 100644 | ||
179 | --- a/include/qemu/accel.h | ||
180 | +++ b/include/qemu/accel.h | ||
181 | @@ -XXX,XX +XXX,XX @@ typedef struct AccelClass { | ||
182 | AccelClass *accel_find(const char *opt_name); | ||
183 | AccelState *current_accel(void); | ||
184 | |||
185 | +void accel_init_interfaces(AccelClass *ac); | ||
186 | + | ||
187 | #ifndef CONFIG_USER_ONLY | ||
188 | int accel_init_machine(AccelState *accel, MachineState *ms); | ||
189 | |||
190 | diff --git a/include/sysemu/accel-ops.h b/include/sysemu/accel-ops.h | ||
191 | new file mode 100644 | ||
192 | index XXXXXXX..XXXXXXX | ||
193 | --- /dev/null | ||
194 | +++ b/include/sysemu/accel-ops.h | ||
195 | @@ -XXX,XX +XXX,XX @@ | ||
196 | +/* | ||
197 | + * Accelerator OPS, used for cpus.c module | ||
198 | + * | ||
199 | + * Copyright 2021 SUSE LLC | ||
200 | + * | ||
201 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
202 | + * See the COPYING file in the top-level directory. | ||
203 | + */ | ||
204 | + | ||
205 | +#ifndef ACCEL_OPS_H | ||
206 | +#define ACCEL_OPS_H | ||
207 | + | ||
208 | +#include "qom/object.h" | ||
209 | + | ||
210 | +#define ACCEL_OPS_SUFFIX "-ops" | ||
211 | +#define TYPE_ACCEL_OPS "accel" ACCEL_OPS_SUFFIX | ||
212 | +#define ACCEL_OPS_NAME(name) (name "-" TYPE_ACCEL_OPS) | ||
213 | + | ||
214 | +typedef struct AccelOpsClass AccelOpsClass; | ||
215 | +DECLARE_CLASS_CHECKERS(AccelOpsClass, ACCEL_OPS, TYPE_ACCEL_OPS) | ||
216 | + | ||
217 | +/* cpus.c operations interface */ | ||
218 | +struct AccelOpsClass { | ||
219 | + /*< private >*/ | ||
220 | + ObjectClass parent_class; | ||
221 | + /*< public >*/ | ||
222 | + | ||
223 | + /* initialization function called when accel is chosen */ | ||
224 | + void (*ops_init)(AccelOpsClass *ops); | ||
225 | + | ||
226 | + void (*create_vcpu_thread)(CPUState *cpu); /* MANDATORY NON-NULL */ | ||
227 | + void (*kick_vcpu_thread)(CPUState *cpu); | ||
228 | + | ||
229 | + void (*synchronize_post_reset)(CPUState *cpu); | ||
230 | + void (*synchronize_post_init)(CPUState *cpu); | ||
231 | + void (*synchronize_state)(CPUState *cpu); | ||
232 | + void (*synchronize_pre_loadvm)(CPUState *cpu); | ||
233 | + | ||
234 | + void (*handle_interrupt)(CPUState *cpu, int mask); | ||
235 | + | ||
236 | + int64_t (*get_virtual_clock)(void); | ||
237 | + int64_t (*get_elapsed_ticks)(void); | ||
238 | +}; | ||
239 | + | ||
240 | +#endif /* ACCEL_OPS_H */ | ||
241 | diff --git a/include/sysemu/cpus.h b/include/sysemu/cpus.h | ||
242 | index XXXXXXX..XXXXXXX 100644 | ||
243 | --- a/include/sysemu/cpus.h | ||
244 | +++ b/include/sysemu/cpus.h | ||
245 | @@ -XXX,XX +XXX,XX @@ | ||
246 | #define QEMU_CPUS_H | ||
247 | |||
248 | #include "qemu/timer.h" | ||
249 | +#include "sysemu/accel-ops.h" | ||
250 | |||
251 | -/* cpus.c */ | ||
252 | +/* register accel-specific operations */ | ||
253 | +void cpus_register_accel(const AccelOpsClass *i); | ||
254 | |||
255 | -/* CPU execution threads */ | ||
256 | +/* accel/dummy-cpus.c */ | ||
257 | |||
258 | -typedef struct CpusAccel { | ||
259 | - void (*create_vcpu_thread)(CPUState *cpu); /* MANDATORY */ | ||
260 | - void (*kick_vcpu_thread)(CPUState *cpu); | ||
261 | - | ||
262 | - void (*synchronize_post_reset)(CPUState *cpu); | ||
263 | - void (*synchronize_post_init)(CPUState *cpu); | ||
264 | - void (*synchronize_state)(CPUState *cpu); | ||
265 | - void (*synchronize_pre_loadvm)(CPUState *cpu); | ||
266 | - | ||
267 | - void (*handle_interrupt)(CPUState *cpu, int mask); | ||
268 | - | ||
269 | - int64_t (*get_virtual_clock)(void); | ||
270 | - int64_t (*get_elapsed_ticks)(void); | ||
271 | -} CpusAccel; | ||
272 | - | ||
273 | -/* register accel-specific cpus interface implementation */ | ||
274 | -void cpus_register_accel(const CpusAccel *i); | ||
275 | - | ||
276 | -/* Create a dummy vcpu for CpusAccel->create_vcpu_thread */ | ||
277 | +/* Create a dummy vcpu for AccelOpsClass->create_vcpu_thread */ | ||
278 | void dummy_start_vcpu_thread(CPUState *); | ||
279 | |||
280 | /* interface available for cpus accelerator threads */ | ||
281 | diff --git a/target/i386/hax/hax-cpus.h b/target/i386/hax/hax-accel-ops.h | ||
282 | similarity index 95% | ||
283 | rename from target/i386/hax/hax-cpus.h | ||
284 | rename to target/i386/hax/hax-accel-ops.h | ||
285 | index XXXXXXX..XXXXXXX 100644 | ||
286 | --- a/target/i386/hax/hax-cpus.h | ||
287 | +++ b/target/i386/hax/hax-accel-ops.h | ||
288 | @@ -XXX,XX +XXX,XX @@ | ||
289 | |||
290 | #include "sysemu/cpus.h" | ||
291 | |||
292 | -extern const CpusAccel hax_cpus; | ||
293 | - | ||
294 | #include "hax-interface.h" | ||
295 | #include "hax-i386.h" | ||
296 | |||
297 | diff --git a/target/i386/hax/hax-windows.h b/target/i386/hax/hax-windows.h | ||
298 | index XXXXXXX..XXXXXXX 100644 | ||
299 | --- a/target/i386/hax/hax-windows.h | ||
300 | +++ b/target/i386/hax/hax-windows.h | ||
301 | @@ -XXX,XX +XXX,XX @@ | ||
302 | #include <winioctl.h> | ||
303 | #include <windef.h> | ||
304 | |||
305 | -#include "hax-cpus.h" | ||
306 | +#include "hax-accel-ops.h" | ||
307 | |||
308 | #define HAX_INVALID_FD INVALID_HANDLE_VALUE | ||
309 | |||
310 | diff --git a/target/i386/hvf/hvf-cpus.h b/target/i386/hvf/hvf-accel-ops.h | ||
311 | similarity index 94% | ||
312 | rename from target/i386/hvf/hvf-cpus.h | ||
313 | rename to target/i386/hvf/hvf-accel-ops.h | ||
314 | index XXXXXXX..XXXXXXX 100644 | ||
315 | --- a/target/i386/hvf/hvf-cpus.h | ||
316 | +++ b/target/i386/hvf/hvf-accel-ops.h | ||
317 | @@ -XXX,XX +XXX,XX @@ | ||
318 | |||
319 | #include "sysemu/cpus.h" | ||
320 | |||
321 | -extern const CpusAccel hvf_cpus; | ||
322 | - | ||
323 | int hvf_init_vcpu(CPUState *); | ||
324 | int hvf_vcpu_exec(CPUState *); | ||
325 | void hvf_cpu_synchronize_state(CPUState *); | ||
326 | diff --git a/target/i386/whpx/whpx-cpus.h b/target/i386/whpx/whpx-accel-ops.h | ||
327 | similarity index 96% | ||
328 | rename from target/i386/whpx/whpx-cpus.h | ||
329 | rename to target/i386/whpx/whpx-accel-ops.h | ||
330 | index XXXXXXX..XXXXXXX 100644 | ||
331 | --- a/target/i386/whpx/whpx-cpus.h | ||
332 | +++ b/target/i386/whpx/whpx-accel-ops.h | ||
333 | @@ -XXX,XX +XXX,XX @@ | ||
334 | |||
335 | #include "sysemu/cpus.h" | ||
336 | |||
337 | -extern const CpusAccel whpx_cpus; | ||
338 | - | ||
339 | int whpx_init_vcpu(CPUState *cpu); | ||
340 | int whpx_vcpu_exec(CPUState *cpu); | ||
341 | void whpx_destroy_vcpu(CPUState *cpu); | ||
342 | diff --git a/accel/accel-common.c b/accel/accel-common.c | ||
343 | index XXXXXXX..XXXXXXX 100644 | ||
344 | --- a/accel/accel-common.c | ||
345 | +++ b/accel/accel-common.c | ||
346 | @@ -XXX,XX +XXX,XX @@ | ||
347 | #include "qemu/osdep.h" | ||
348 | #include "qemu/accel.h" | ||
349 | |||
350 | +#ifndef CONFIG_USER_ONLY | ||
351 | +#include "accel-softmmu.h" | ||
352 | +#endif /* !CONFIG_USER_ONLY */ | ||
353 | + | ||
354 | static const TypeInfo accel_type = { | ||
355 | .name = TYPE_ACCEL, | ||
356 | .parent = TYPE_OBJECT, | ||
357 | @@ -XXX,XX +XXX,XX @@ AccelClass *accel_find(const char *opt_name) | ||
358 | return ac; | ||
359 | } | 21 | } |
360 | 22 | ||
361 | +void accel_init_interfaces(AccelClass *ac) | 23 | +static inline Int128 int128_not(Int128 a) |
362 | +{ | 24 | +{ |
363 | +#ifndef CONFIG_USER_ONLY | 25 | + return ~a; |
364 | + accel_init_ops_interfaces(ac); | ||
365 | +#endif /* !CONFIG_USER_ONLY */ | ||
366 | +} | 26 | +} |
367 | + | 27 | + |
368 | static void register_accel_types(void) | 28 | static inline Int128 int128_and(Int128 a, Int128 b) |
369 | { | 29 | { |
370 | type_register_static(&accel_type); | 30 | return a & b; |
371 | diff --git a/accel/accel-softmmu.c b/accel/accel-softmmu.c | 31 | @@ -XXX,XX +XXX,XX @@ static inline Int128 int128_or(Int128 a, Int128 b) |
372 | index XXXXXXX..XXXXXXX 100644 | 32 | return a | b; |
373 | --- a/accel/accel-softmmu.c | ||
374 | +++ b/accel/accel-softmmu.c | ||
375 | @@ -XXX,XX +XXX,XX @@ | ||
376 | #include "qemu/osdep.h" | ||
377 | #include "qemu/accel.h" | ||
378 | #include "hw/boards.h" | ||
379 | -#include "sysemu/arch_init.h" | ||
380 | -#include "sysemu/sysemu.h" | ||
381 | -#include "qom/object.h" | ||
382 | +#include "sysemu/cpus.h" | ||
383 | + | ||
384 | +#include "accel-softmmu.h" | ||
385 | |||
386 | int accel_init_machine(AccelState *accel, MachineState *ms) | ||
387 | { | ||
388 | @@ -XXX,XX +XXX,XX @@ void accel_setup_post(MachineState *ms) | ||
389 | acc->setup_post(ms, accel); | ||
390 | } | ||
391 | } | 33 | } |
392 | + | 34 | |
393 | +/* initialize the arch-independent accel operation interfaces */ | 35 | +static inline Int128 int128_xor(Int128 a, Int128 b) |
394 | +void accel_init_ops_interfaces(AccelClass *ac) | ||
395 | +{ | 36 | +{ |
396 | + const char *ac_name; | 37 | + return a ^ b; |
397 | + char *ops_name; | ||
398 | + AccelOpsClass *ops; | ||
399 | + | ||
400 | + ac_name = object_class_get_name(OBJECT_CLASS(ac)); | ||
401 | + g_assert(ac_name != NULL); | ||
402 | + | ||
403 | + ops_name = g_strdup_printf("%s" ACCEL_OPS_SUFFIX, ac_name); | ||
404 | + ops = ACCEL_OPS_CLASS(object_class_by_name(ops_name)); | ||
405 | + g_free(ops_name); | ||
406 | + | ||
407 | + /* | ||
408 | + * all accelerators need to define ops, providing at least a mandatory | ||
409 | + * non-NULL create_vcpu_thread operation. | ||
410 | + */ | ||
411 | + g_assert(ops != NULL); | ||
412 | + if (ops->ops_init) { | ||
413 | + ops->ops_init(ops); | ||
414 | + } | ||
415 | + cpus_register_accel(ops); | ||
416 | +} | 38 | +} |
417 | + | 39 | + |
418 | +static const TypeInfo accel_ops_type_info = { | 40 | static inline Int128 int128_rshift(Int128 a, int n) |
419 | + .name = TYPE_ACCEL_OPS, | 41 | { |
420 | + .parent = TYPE_OBJECT, | 42 | return a >> n; |
421 | + .abstract = true, | 43 | @@ -XXX,XX +XXX,XX @@ static inline Int128 int128_exts64(int64_t a) |
422 | + .class_size = sizeof(AccelOpsClass), | 44 | return int128_make128(a, (a < 0) ? -1 : 0); |
423 | +}; | 45 | } |
424 | + | 46 | |
425 | +static void accel_softmmu_register_types(void) | 47 | +static inline Int128 int128_not(Int128 a) |
426 | +{ | 48 | +{ |
427 | + type_register_static(&accel_ops_type_info); | 49 | + return int128_make128(~a.lo, ~a.hi); |
428 | +} | ||
429 | +type_init(accel_softmmu_register_types); | ||
430 | diff --git a/accel/kvm/kvm-cpus.c b/accel/kvm/kvm-accel-ops.c | ||
431 | similarity index 72% | ||
432 | rename from accel/kvm/kvm-cpus.c | ||
433 | rename to accel/kvm/kvm-accel-ops.c | ||
434 | index XXXXXXX..XXXXXXX 100644 | ||
435 | --- a/accel/kvm/kvm-cpus.c | ||
436 | +++ b/accel/kvm/kvm-accel-ops.c | ||
437 | @@ -XXX,XX +XXX,XX @@ static void kvm_start_vcpu_thread(CPUState *cpu) | ||
438 | cpu, QEMU_THREAD_JOINABLE); | ||
439 | } | ||
440 | |||
441 | -const CpusAccel kvm_cpus = { | ||
442 | - .create_vcpu_thread = kvm_start_vcpu_thread, | ||
443 | +static void kvm_accel_ops_class_init(ObjectClass *oc, void *data) | ||
444 | +{ | ||
445 | + AccelOpsClass *ops = ACCEL_OPS_CLASS(oc); | ||
446 | |||
447 | - .synchronize_post_reset = kvm_cpu_synchronize_post_reset, | ||
448 | - .synchronize_post_init = kvm_cpu_synchronize_post_init, | ||
449 | - .synchronize_state = kvm_cpu_synchronize_state, | ||
450 | - .synchronize_pre_loadvm = kvm_cpu_synchronize_pre_loadvm, | ||
451 | + ops->create_vcpu_thread = kvm_start_vcpu_thread; | ||
452 | + ops->synchronize_post_reset = kvm_cpu_synchronize_post_reset; | ||
453 | + ops->synchronize_post_init = kvm_cpu_synchronize_post_init; | ||
454 | + ops->synchronize_state = kvm_cpu_synchronize_state; | ||
455 | + ops->synchronize_pre_loadvm = kvm_cpu_synchronize_pre_loadvm; | ||
456 | +} | 50 | +} |
457 | + | 51 | + |
458 | +static const TypeInfo kvm_accel_ops_type = { | 52 | static inline Int128 int128_and(Int128 a, Int128 b) |
459 | + .name = ACCEL_OPS_NAME("kvm"), | 53 | { |
460 | + | 54 | return int128_make128(a.lo & b.lo, a.hi & b.hi); |
461 | + .parent = TYPE_ACCEL_OPS, | 55 | @@ -XXX,XX +XXX,XX @@ static inline Int128 int128_or(Int128 a, Int128 b) |
462 | + .class_init = kvm_accel_ops_class_init, | 56 | return int128_make128(a.lo | b.lo, a.hi | b.hi); |
463 | + .abstract = true, | 57 | } |
464 | }; | 58 | |
465 | + | 59 | +static inline Int128 int128_xor(Int128 a, Int128 b) |
466 | +static void kvm_accel_ops_register_types(void) | ||
467 | +{ | 60 | +{ |
468 | + type_register_static(&kvm_accel_ops_type); | 61 | + return int128_make128(a.lo ^ b.lo, a.hi ^ b.hi); |
469 | +} | ||
470 | +type_init(kvm_accel_ops_register_types); | ||
471 | diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c | ||
472 | index XXXXXXX..XXXXXXX 100644 | ||
473 | --- a/accel/kvm/kvm-all.c | ||
474 | +++ b/accel/kvm/kvm-all.c | ||
475 | @@ -XXX,XX +XXX,XX @@ static int kvm_init(MachineState *ms) | ||
476 | ret = ram_block_discard_disable(true); | ||
477 | assert(!ret); | ||
478 | } | ||
479 | - | ||
480 | - cpus_register_accel(&kvm_cpus); | ||
481 | return 0; | ||
482 | |||
483 | err: | ||
484 | diff --git a/accel/qtest/qtest.c b/accel/qtest/qtest.c | ||
485 | index XXXXXXX..XXXXXXX 100644 | ||
486 | --- a/accel/qtest/qtest.c | ||
487 | +++ b/accel/qtest/qtest.c | ||
488 | @@ -XXX,XX +XXX,XX @@ | ||
489 | #include "qemu/main-loop.h" | ||
490 | #include "hw/core/cpu.h" | ||
491 | |||
492 | -const CpusAccel qtest_cpus = { | ||
493 | - .create_vcpu_thread = dummy_start_vcpu_thread, | ||
494 | - .get_virtual_clock = qtest_get_virtual_clock, | ||
495 | -}; | ||
496 | - | ||
497 | static int qtest_init_accel(MachineState *ms) | ||
498 | { | ||
499 | - cpus_register_accel(&qtest_cpus); | ||
500 | return 0; | ||
501 | } | ||
502 | |||
503 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo qtest_accel_type = { | ||
504 | .class_init = qtest_accel_class_init, | ||
505 | }; | ||
506 | |||
507 | +static void qtest_accel_ops_class_init(ObjectClass *oc, void *data) | ||
508 | +{ | ||
509 | + AccelOpsClass *ops = ACCEL_OPS_CLASS(oc); | ||
510 | + | ||
511 | + ops->create_vcpu_thread = dummy_start_vcpu_thread; | ||
512 | + ops->get_virtual_clock = qtest_get_virtual_clock; | ||
513 | +}; | ||
514 | + | ||
515 | +static const TypeInfo qtest_accel_ops_type = { | ||
516 | + .name = ACCEL_OPS_NAME("qtest"), | ||
517 | + | ||
518 | + .parent = TYPE_ACCEL_OPS, | ||
519 | + .class_init = qtest_accel_ops_class_init, | ||
520 | + .abstract = true, | ||
521 | +}; | ||
522 | + | ||
523 | static void qtest_type_init(void) | ||
524 | { | ||
525 | type_register_static(&qtest_accel_type); | ||
526 | + type_register_static(&qtest_accel_ops_type); | ||
527 | } | ||
528 | |||
529 | type_init(qtest_type_init); | ||
530 | diff --git a/accel/tcg/tcg-cpus-icount.c b/accel/tcg/tcg-accel-ops-icount.c | ||
531 | similarity index 89% | ||
532 | rename from accel/tcg/tcg-cpus-icount.c | ||
533 | rename to accel/tcg/tcg-accel-ops-icount.c | ||
534 | index XXXXXXX..XXXXXXX 100644 | ||
535 | --- a/accel/tcg/tcg-cpus-icount.c | ||
536 | +++ b/accel/tcg/tcg-accel-ops-icount.c | ||
537 | @@ -XXX,XX +XXX,XX @@ | ||
538 | #include "exec/exec-all.h" | ||
539 | #include "hw/boards.h" | ||
540 | |||
541 | -#include "tcg-cpus.h" | ||
542 | -#include "tcg-cpus-icount.h" | ||
543 | -#include "tcg-cpus-rr.h" | ||
544 | +#include "tcg-accel-ops.h" | ||
545 | +#include "tcg-accel-ops-icount.h" | ||
546 | +#include "tcg-accel-ops-rr.h" | ||
547 | |||
548 | static int64_t icount_get_limit(void) | ||
549 | { | ||
550 | @@ -XXX,XX +XXX,XX @@ void icount_prepare_for_run(CPUState *cpu) | ||
551 | /* | ||
552 | * These should always be cleared by icount_process_data after | ||
553 | * each vCPU execution. However u16.high can be raised | ||
554 | - * asynchronously by cpu_exit/cpu_interrupt/tcg_cpus_handle_interrupt | ||
555 | + * asynchronously by cpu_exit/cpu_interrupt/tcg_handle_interrupt | ||
556 | */ | ||
557 | g_assert(cpu_neg(cpu)->icount_decr.u16.low == 0); | ||
558 | g_assert(cpu->icount_extra == 0); | ||
559 | @@ -XXX,XX +XXX,XX @@ void icount_process_data(CPUState *cpu) | ||
560 | replay_mutex_unlock(); | ||
561 | } | ||
562 | |||
563 | -static void icount_handle_interrupt(CPUState *cpu, int mask) | ||
564 | +void icount_handle_interrupt(CPUState *cpu, int mask) | ||
565 | { | ||
566 | int old_mask = cpu->interrupt_request; | ||
567 | |||
568 | - tcg_cpus_handle_interrupt(cpu, mask); | ||
569 | + tcg_handle_interrupt(cpu, mask); | ||
570 | if (qemu_cpu_is_self(cpu) && | ||
571 | !cpu->can_do_io | ||
572 | && (mask & ~old_mask) != 0) { | ||
573 | cpu_abort(cpu, "Raised interrupt while not in I/O function"); | ||
574 | } | ||
575 | } | ||
576 | - | ||
577 | -const CpusAccel tcg_cpus_icount = { | ||
578 | - .create_vcpu_thread = rr_start_vcpu_thread, | ||
579 | - .kick_vcpu_thread = rr_kick_vcpu_thread, | ||
580 | - | ||
581 | - .handle_interrupt = icount_handle_interrupt, | ||
582 | - .get_virtual_clock = icount_get, | ||
583 | - .get_elapsed_ticks = icount_get, | ||
584 | -}; | ||
585 | diff --git a/accel/tcg/tcg-cpus-mttcg.c b/accel/tcg/tcg-accel-ops-mttcg.c | ||
586 | similarity index 92% | ||
587 | rename from accel/tcg/tcg-cpus-mttcg.c | ||
588 | rename to accel/tcg/tcg-accel-ops-mttcg.c | ||
589 | index XXXXXXX..XXXXXXX 100644 | ||
590 | --- a/accel/tcg/tcg-cpus-mttcg.c | ||
591 | +++ b/accel/tcg/tcg-accel-ops-mttcg.c | ||
592 | @@ -XXX,XX +XXX,XX @@ | ||
593 | #include "exec/exec-all.h" | ||
594 | #include "hw/boards.h" | ||
595 | |||
596 | -#include "tcg-cpus.h" | ||
597 | +#include "tcg-accel-ops.h" | ||
598 | +#include "tcg-accel-ops-mttcg.h" | ||
599 | |||
600 | /* | ||
601 | * In the multi-threaded case each vCPU has its own thread. The TLS | ||
602 | @@ -XXX,XX +XXX,XX @@ static void *mttcg_cpu_thread_fn(void *arg) | ||
603 | return NULL; | ||
604 | } | ||
605 | |||
606 | -static void mttcg_kick_vcpu_thread(CPUState *cpu) | ||
607 | +void mttcg_kick_vcpu_thread(CPUState *cpu) | ||
608 | { | ||
609 | cpu_exit(cpu); | ||
610 | } | ||
611 | |||
612 | -static void mttcg_start_vcpu_thread(CPUState *cpu) | ||
613 | +void mttcg_start_vcpu_thread(CPUState *cpu) | ||
614 | { | ||
615 | char thread_name[VCPU_THREAD_NAME_SIZE]; | ||
616 | |||
617 | @@ -XXX,XX +XXX,XX @@ static void mttcg_start_vcpu_thread(CPUState *cpu) | ||
618 | cpu->hThread = qemu_thread_get_handle(cpu->thread); | ||
619 | #endif | ||
620 | } | ||
621 | - | ||
622 | -const CpusAccel tcg_cpus_mttcg = { | ||
623 | - .create_vcpu_thread = mttcg_start_vcpu_thread, | ||
624 | - .kick_vcpu_thread = mttcg_kick_vcpu_thread, | ||
625 | - | ||
626 | - .handle_interrupt = tcg_cpus_handle_interrupt, | ||
627 | -}; | ||
628 | diff --git a/accel/tcg/tcg-cpus-rr.c b/accel/tcg/tcg-accel-ops-rr.c | ||
629 | similarity index 97% | ||
630 | rename from accel/tcg/tcg-cpus-rr.c | ||
631 | rename to accel/tcg/tcg-accel-ops-rr.c | ||
632 | index XXXXXXX..XXXXXXX 100644 | ||
633 | --- a/accel/tcg/tcg-cpus-rr.c | ||
634 | +++ b/accel/tcg/tcg-accel-ops-rr.c | ||
635 | @@ -XXX,XX +XXX,XX @@ | ||
636 | #include "exec/exec-all.h" | ||
637 | #include "hw/boards.h" | ||
638 | |||
639 | -#include "tcg-cpus.h" | ||
640 | -#include "tcg-cpus-rr.h" | ||
641 | -#include "tcg-cpus-icount.h" | ||
642 | +#include "tcg-accel-ops.h" | ||
643 | +#include "tcg-accel-ops-rr.h" | ||
644 | +#include "tcg-accel-ops-icount.h" | ||
645 | |||
646 | /* Kick all RR vCPUs */ | ||
647 | void rr_kick_vcpu_thread(CPUState *unused) | ||
648 | @@ -XXX,XX +XXX,XX @@ void rr_start_vcpu_thread(CPUState *cpu) | ||
649 | cpu->created = true; | ||
650 | } | ||
651 | } | ||
652 | - | ||
653 | -const CpusAccel tcg_cpus_rr = { | ||
654 | - .create_vcpu_thread = rr_start_vcpu_thread, | ||
655 | - .kick_vcpu_thread = rr_kick_vcpu_thread, | ||
656 | - | ||
657 | - .handle_interrupt = tcg_cpus_handle_interrupt, | ||
658 | -}; | ||
659 | diff --git a/accel/tcg/tcg-cpus.c b/accel/tcg/tcg-accel-ops.c | ||
660 | similarity index 63% | ||
661 | rename from accel/tcg/tcg-cpus.c | ||
662 | rename to accel/tcg/tcg-accel-ops.c | ||
663 | index XXXXXXX..XXXXXXX 100644 | ||
664 | --- a/accel/tcg/tcg-cpus.c | ||
665 | +++ b/accel/tcg/tcg-accel-ops.c | ||
666 | @@ -XXX,XX +XXX,XX @@ | ||
667 | #include "exec/exec-all.h" | ||
668 | #include "hw/boards.h" | ||
669 | |||
670 | -#include "tcg-cpus.h" | ||
671 | +#include "tcg-accel-ops.h" | ||
672 | +#include "tcg-accel-ops-mttcg.h" | ||
673 | +#include "tcg-accel-ops-rr.h" | ||
674 | +#include "tcg-accel-ops-icount.h" | ||
675 | |||
676 | /* common functionality among all TCG variants */ | ||
677 | |||
678 | @@ -XXX,XX +XXX,XX @@ int tcg_cpus_exec(CPUState *cpu) | ||
679 | } | ||
680 | |||
681 | /* mask must never be zero, except for A20 change call */ | ||
682 | -void tcg_cpus_handle_interrupt(CPUState *cpu, int mask) | ||
683 | +void tcg_handle_interrupt(CPUState *cpu, int mask) | ||
684 | { | ||
685 | g_assert(qemu_mutex_iothread_locked()); | ||
686 | |||
687 | @@ -XXX,XX +XXX,XX @@ void tcg_cpus_handle_interrupt(CPUState *cpu, int mask) | ||
688 | qatomic_set(&cpu_neg(cpu)->icount_decr.u16.high, -1); | ||
689 | } | ||
690 | } | ||
691 | + | ||
692 | +static void tcg_accel_ops_init(AccelOpsClass *ops) | ||
693 | +{ | ||
694 | + if (qemu_tcg_mttcg_enabled()) { | ||
695 | + ops->create_vcpu_thread = mttcg_start_vcpu_thread; | ||
696 | + ops->kick_vcpu_thread = mttcg_kick_vcpu_thread; | ||
697 | + ops->handle_interrupt = tcg_handle_interrupt; | ||
698 | + } else if (icount_enabled()) { | ||
699 | + ops->create_vcpu_thread = rr_start_vcpu_thread; | ||
700 | + ops->kick_vcpu_thread = rr_kick_vcpu_thread; | ||
701 | + ops->handle_interrupt = icount_handle_interrupt; | ||
702 | + ops->get_virtual_clock = icount_get; | ||
703 | + ops->get_elapsed_ticks = icount_get; | ||
704 | + } else { | ||
705 | + ops->create_vcpu_thread = rr_start_vcpu_thread; | ||
706 | + ops->kick_vcpu_thread = rr_kick_vcpu_thread; | ||
707 | + ops->handle_interrupt = tcg_handle_interrupt; | ||
708 | + } | ||
709 | +} | 62 | +} |
710 | + | 63 | + |
711 | +static void tcg_accel_ops_class_init(ObjectClass *oc, void *data) | 64 | static inline Int128 int128_rshift(Int128 a, int n) |
712 | +{ | ||
713 | + AccelOpsClass *ops = ACCEL_OPS_CLASS(oc); | ||
714 | + | ||
715 | + ops->ops_init = tcg_accel_ops_init; | ||
716 | +} | ||
717 | + | ||
718 | +static const TypeInfo tcg_accel_ops_type = { | ||
719 | + .name = ACCEL_OPS_NAME("tcg"), | ||
720 | + | ||
721 | + .parent = TYPE_ACCEL_OPS, | ||
722 | + .class_init = tcg_accel_ops_class_init, | ||
723 | + .abstract = true, | ||
724 | +}; | ||
725 | + | ||
726 | +static void tcg_accel_ops_register_types(void) | ||
727 | +{ | ||
728 | + type_register_static(&tcg_accel_ops_type); | ||
729 | +} | ||
730 | +type_init(tcg_accel_ops_register_types); | ||
731 | diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c | ||
732 | index XXXXXXX..XXXXXXX 100644 | ||
733 | --- a/accel/tcg/tcg-all.c | ||
734 | +++ b/accel/tcg/tcg-all.c | ||
735 | @@ -XXX,XX +XXX,XX @@ | ||
736 | #include "qemu/accel.h" | ||
737 | #include "qapi/qapi-builtin-visit.h" | ||
738 | |||
739 | -#ifndef CONFIG_USER_ONLY | ||
740 | -#include "tcg-cpus.h" | ||
741 | -#endif /* CONFIG_USER_ONLY */ | ||
742 | - | ||
743 | struct TCGState { | ||
744 | AccelState parent_obj; | ||
745 | |||
746 | @@ -XXX,XX +XXX,XX @@ static int tcg_init(MachineState *ms) | ||
747 | */ | ||
748 | #ifndef CONFIG_USER_ONLY | ||
749 | tcg_region_init(); | ||
750 | - | ||
751 | - if (mttcg_enabled) { | ||
752 | - cpus_register_accel(&tcg_cpus_mttcg); | ||
753 | - } else if (icount_enabled()) { | ||
754 | - cpus_register_accel(&tcg_cpus_icount); | ||
755 | - } else { | ||
756 | - cpus_register_accel(&tcg_cpus_rr); | ||
757 | - } | ||
758 | #endif /* !CONFIG_USER_ONLY */ | ||
759 | |||
760 | return 0; | ||
761 | diff --git a/accel/xen/xen-all.c b/accel/xen/xen-all.c | ||
762 | index XXXXXXX..XXXXXXX 100644 | ||
763 | --- a/accel/xen/xen-all.c | ||
764 | +++ b/accel/xen/xen-all.c | ||
765 | @@ -XXX,XX +XXX,XX @@ static void xen_setup_post(MachineState *ms, AccelState *accel) | ||
766 | } | ||
767 | } | ||
768 | |||
769 | -const CpusAccel xen_cpus = { | ||
770 | - .create_vcpu_thread = dummy_start_vcpu_thread, | ||
771 | -}; | ||
772 | - | ||
773 | static int xen_init(MachineState *ms) | ||
774 | { | 65 | { |
775 | MachineClass *mc = MACHINE_GET_CLASS(ms); | 66 | int64_t h; |
776 | @@ -XXX,XX +XXX,XX @@ static int xen_init(MachineState *ms) | ||
777 | * opt out of system RAM being allocated by generic code | ||
778 | */ | ||
779 | mc->default_ram_id = NULL; | ||
780 | - | ||
781 | - cpus_register_accel(&xen_cpus); | ||
782 | - | ||
783 | return 0; | ||
784 | } | ||
785 | |||
786 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo xen_accel_type = { | ||
787 | .class_init = xen_accel_class_init, | ||
788 | }; | ||
789 | |||
790 | +static void xen_accel_ops_class_init(ObjectClass *oc, void *data) | ||
791 | +{ | ||
792 | + AccelOpsClass *ops = ACCEL_OPS_CLASS(oc); | ||
793 | + | ||
794 | + ops->create_vcpu_thread = dummy_start_vcpu_thread; | ||
795 | +} | ||
796 | + | ||
797 | +static const TypeInfo xen_accel_ops_type = { | ||
798 | + .name = ACCEL_OPS_NAME("xen"), | ||
799 | + | ||
800 | + .parent = TYPE_ACCEL_OPS, | ||
801 | + .class_init = xen_accel_ops_class_init, | ||
802 | + .abstract = true, | ||
803 | +}; | ||
804 | + | ||
805 | static void xen_type_init(void) | ||
806 | { | ||
807 | type_register_static(&xen_accel_type); | ||
808 | + type_register_static(&xen_accel_ops_type); | ||
809 | } | ||
810 | - | ||
811 | type_init(xen_type_init); | ||
812 | diff --git a/bsd-user/main.c b/bsd-user/main.c | ||
813 | index XXXXXXX..XXXXXXX 100644 | ||
814 | --- a/bsd-user/main.c | ||
815 | +++ b/bsd-user/main.c | ||
816 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv) | ||
817 | #endif | ||
818 | } | ||
819 | |||
820 | + cpu_type = parse_cpu_option(cpu_model); | ||
821 | /* init tcg before creating CPUs and to get qemu_host_page_size */ | ||
822 | { | ||
823 | AccelClass *ac = ACCEL_GET_CLASS(current_accel()); | ||
824 | |||
825 | ac->init_machine(NULL); | ||
826 | + accel_init_interfaces(ac); | ||
827 | } | ||
828 | - cpu_type = parse_cpu_option(cpu_model); | ||
829 | cpu = cpu_create(cpu_type); | ||
830 | env = cpu->env_ptr; | ||
831 | #if defined(TARGET_SPARC) || defined(TARGET_PPC) | ||
832 | diff --git a/linux-user/main.c b/linux-user/main.c | ||
833 | index XXXXXXX..XXXXXXX 100644 | ||
834 | --- a/linux-user/main.c | ||
835 | +++ b/linux-user/main.c | ||
836 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv, char **envp) | ||
837 | AccelClass *ac = ACCEL_GET_CLASS(current_accel()); | ||
838 | |||
839 | ac->init_machine(NULL); | ||
840 | + accel_init_interfaces(ac); | ||
841 | } | ||
842 | cpu = cpu_create(cpu_type); | ||
843 | env = cpu->env_ptr; | ||
844 | diff --git a/softmmu/cpus.c b/softmmu/cpus.c | ||
845 | index XXXXXXX..XXXXXXX 100644 | ||
846 | --- a/softmmu/cpus.c | ||
847 | +++ b/softmmu/cpus.c | ||
848 | @@ -XXX,XX +XXX,XX @@ void hw_error(const char *fmt, ...) | ||
849 | /* | ||
850 | * The chosen accelerator is supposed to register this. | ||
851 | */ | ||
852 | -static const CpusAccel *cpus_accel; | ||
853 | +static const AccelOpsClass *cpus_accel; | ||
854 | |||
855 | void cpu_synchronize_all_states(void) | ||
856 | { | ||
857 | @@ -XXX,XX +XXX,XX @@ void cpu_remove_sync(CPUState *cpu) | ||
858 | qemu_mutex_lock_iothread(); | ||
859 | } | ||
860 | |||
861 | -void cpus_register_accel(const CpusAccel *ca) | ||
862 | +void cpus_register_accel(const AccelOpsClass *ops) | ||
863 | { | ||
864 | - assert(ca != NULL); | ||
865 | - assert(ca->create_vcpu_thread != NULL); /* mandatory */ | ||
866 | - cpus_accel = ca; | ||
867 | + assert(ops != NULL); | ||
868 | + assert(ops->create_vcpu_thread != NULL); /* mandatory */ | ||
869 | + cpus_accel = ops; | ||
870 | } | ||
871 | |||
872 | void qemu_init_vcpu(CPUState *cpu) | ||
873 | @@ -XXX,XX +XXX,XX @@ void qemu_init_vcpu(CPUState *cpu) | ||
874 | cpu_address_space_init(cpu, 0, "cpu-memory", cpu->memory); | ||
875 | } | ||
876 | |||
877 | - /* accelerators all implement the CpusAccel interface */ | ||
878 | + /* accelerators all implement the AccelOpsClass */ | ||
879 | g_assert(cpus_accel != NULL && cpus_accel->create_vcpu_thread != NULL); | ||
880 | cpus_accel->create_vcpu_thread(cpu); | ||
881 | |||
882 | diff --git a/softmmu/vl.c b/softmmu/vl.c | ||
883 | index XXXXXXX..XXXXXXX 100644 | ||
884 | --- a/softmmu/vl.c | ||
885 | +++ b/softmmu/vl.c | ||
886 | @@ -XXX,XX +XXX,XX @@ static bool object_create_early(const char *type, QemuOpts *opts) | ||
887 | return false; | ||
888 | } | ||
889 | |||
890 | - /* Allocation of large amounts of memory may delay | ||
891 | + /* | ||
892 | + * Allocation of large amounts of memory may delay | ||
893 | * chardev initialization for too long, and trigger timeouts | ||
894 | * on software that waits for a monitor socket to be created | ||
895 | * (e.g. libvirt). | ||
896 | @@ -XXX,XX +XXX,XX @@ void qemu_init(int argc, char **argv, char **envp) | ||
897 | * | ||
898 | * Machine compat properties: object_set_machine_compat_props(). | ||
899 | * Accelerator compat props: object_set_accelerator_compat_props(), | ||
900 | - * called from configure_accelerator(). | ||
901 | + * called from do_configure_accelerator(). | ||
902 | */ | ||
903 | |||
904 | machine_class = MACHINE_GET_CLASS(current_machine); | ||
905 | @@ -XXX,XX +XXX,XX @@ void qemu_init(int argc, char **argv, char **envp) | ||
906 | if (cpu_option) { | ||
907 | current_machine->cpu_type = parse_cpu_option(cpu_option); | ||
908 | } | ||
909 | + /* NB: for machine none cpu_type could STILL be NULL here! */ | ||
910 | + accel_init_interfaces(ACCEL_GET_CLASS(current_machine->accelerator)); | ||
911 | |||
912 | qemu_resolve_machine_memdev(); | ||
913 | parse_numa_opts(current_machine); | ||
914 | diff --git a/target/i386/hax/hax-cpus.c b/target/i386/hax/hax-accel-ops.c | ||
915 | similarity index 69% | ||
916 | rename from target/i386/hax/hax-cpus.c | ||
917 | rename to target/i386/hax/hax-accel-ops.c | ||
918 | index XXXXXXX..XXXXXXX 100644 | ||
919 | --- a/target/i386/hax/hax-cpus.c | ||
920 | +++ b/target/i386/hax/hax-accel-ops.c | ||
921 | @@ -XXX,XX +XXX,XX @@ | ||
922 | #include "sysemu/cpus.h" | ||
923 | #include "qemu/guest-random.h" | ||
924 | |||
925 | -#include "hax-cpus.h" | ||
926 | +#include "hax-accel-ops.h" | ||
927 | |||
928 | static void *hax_cpu_thread_fn(void *arg) | ||
929 | { | ||
930 | @@ -XXX,XX +XXX,XX @@ static void hax_start_vcpu_thread(CPUState *cpu) | ||
931 | #endif | ||
932 | } | ||
933 | |||
934 | -const CpusAccel hax_cpus = { | ||
935 | - .create_vcpu_thread = hax_start_vcpu_thread, | ||
936 | - .kick_vcpu_thread = hax_kick_vcpu_thread, | ||
937 | +static void hax_accel_ops_class_init(ObjectClass *oc, void *data) | ||
938 | +{ | ||
939 | + AccelOpsClass *ops = ACCEL_OPS_CLASS(oc); | ||
940 | |||
941 | - .synchronize_post_reset = hax_cpu_synchronize_post_reset, | ||
942 | - .synchronize_post_init = hax_cpu_synchronize_post_init, | ||
943 | - .synchronize_state = hax_cpu_synchronize_state, | ||
944 | - .synchronize_pre_loadvm = hax_cpu_synchronize_pre_loadvm, | ||
945 | + ops->create_vcpu_thread = hax_start_vcpu_thread; | ||
946 | + ops->kick_vcpu_thread = hax_kick_vcpu_thread; | ||
947 | + | ||
948 | + ops->synchronize_post_reset = hax_cpu_synchronize_post_reset; | ||
949 | + ops->synchronize_post_init = hax_cpu_synchronize_post_init; | ||
950 | + ops->synchronize_state = hax_cpu_synchronize_state; | ||
951 | + ops->synchronize_pre_loadvm = hax_cpu_synchronize_pre_loadvm; | ||
952 | +} | ||
953 | + | ||
954 | +static const TypeInfo hax_accel_ops_type = { | ||
955 | + .name = ACCEL_OPS_NAME("hax"), | ||
956 | + | ||
957 | + .parent = TYPE_ACCEL_OPS, | ||
958 | + .class_init = hax_accel_ops_class_init, | ||
959 | + .abstract = true, | ||
960 | }; | ||
961 | + | ||
962 | +static void hax_accel_ops_register_types(void) | ||
963 | +{ | ||
964 | + type_register_static(&hax_accel_ops_type); | ||
965 | +} | ||
966 | +type_init(hax_accel_ops_register_types); | ||
967 | diff --git a/target/i386/hax/hax-all.c b/target/i386/hax/hax-all.c | ||
968 | index XXXXXXX..XXXXXXX 100644 | ||
969 | --- a/target/i386/hax/hax-all.c | ||
970 | +++ b/target/i386/hax/hax-all.c | ||
971 | @@ -XXX,XX +XXX,XX @@ | ||
972 | #include "sysemu/runstate.h" | ||
973 | #include "hw/boards.h" | ||
974 | |||
975 | -#include "hax-cpus.h" | ||
976 | +#include "hax-accel-ops.h" | ||
977 | |||
978 | #define DEBUG_HAX 0 | ||
979 | |||
980 | @@ -XXX,XX +XXX,XX @@ static int hax_accel_init(MachineState *ms) | ||
981 | !ret ? "working" : "not working", | ||
982 | !ret ? "fast virt" : "emulation"); | ||
983 | } | ||
984 | - if (ret == 0) { | ||
985 | - cpus_register_accel(&hax_cpus); | ||
986 | - } | ||
987 | return ret; | ||
988 | } | ||
989 | |||
990 | diff --git a/target/i386/hax/hax-mem.c b/target/i386/hax/hax-mem.c | ||
991 | index XXXXXXX..XXXXXXX 100644 | ||
992 | --- a/target/i386/hax/hax-mem.c | ||
993 | +++ b/target/i386/hax/hax-mem.c | ||
994 | @@ -XXX,XX +XXX,XX @@ | ||
995 | #include "exec/address-spaces.h" | ||
996 | #include "qemu/error-report.h" | ||
997 | |||
998 | -#include "hax-cpus.h" | ||
999 | +#include "hax-accel-ops.h" | ||
1000 | #include "qemu/queue.h" | ||
1001 | |||
1002 | #define DEBUG_HAX_MEM 0 | ||
1003 | diff --git a/target/i386/hax/hax-posix.c b/target/i386/hax/hax-posix.c | ||
1004 | index XXXXXXX..XXXXXXX 100644 | ||
1005 | --- a/target/i386/hax/hax-posix.c | ||
1006 | +++ b/target/i386/hax/hax-posix.c | ||
1007 | @@ -XXX,XX +XXX,XX @@ | ||
1008 | #include <sys/ioctl.h> | ||
1009 | |||
1010 | #include "sysemu/cpus.h" | ||
1011 | -#include "hax-cpus.h" | ||
1012 | +#include "hax-accel-ops.h" | ||
1013 | |||
1014 | hax_fd hax_mod_open(void) | ||
1015 | { | ||
1016 | diff --git a/target/i386/hax/hax-windows.c b/target/i386/hax/hax-windows.c | ||
1017 | index XXXXXXX..XXXXXXX 100644 | ||
1018 | --- a/target/i386/hax/hax-windows.c | ||
1019 | +++ b/target/i386/hax/hax-windows.c | ||
1020 | @@ -XXX,XX +XXX,XX @@ | ||
1021 | |||
1022 | #include "qemu/osdep.h" | ||
1023 | #include "cpu.h" | ||
1024 | -#include "hax-cpus.h" | ||
1025 | +#include "hax-accel-ops.h" | ||
1026 | |||
1027 | /* | ||
1028 | * return 0 when success, -1 when driver not loaded, | ||
1029 | diff --git a/target/i386/hvf/hvf-cpus.c b/target/i386/hvf/hvf-accel-ops.c | ||
1030 | similarity index 84% | ||
1031 | rename from target/i386/hvf/hvf-cpus.c | ||
1032 | rename to target/i386/hvf/hvf-accel-ops.c | ||
1033 | index XXXXXXX..XXXXXXX 100644 | ||
1034 | --- a/target/i386/hvf/hvf-cpus.c | ||
1035 | +++ b/target/i386/hvf/hvf-accel-ops.c | ||
1036 | @@ -XXX,XX +XXX,XX @@ | ||
1037 | #include "target/i386/cpu.h" | ||
1038 | #include "qemu/guest-random.h" | ||
1039 | |||
1040 | -#include "hvf-cpus.h" | ||
1041 | +#include "hvf-accel-ops.h" | ||
1042 | |||
1043 | /* | ||
1044 | * The HVF-specific vCPU thread function. This one should only run when the host | ||
1045 | @@ -XXX,XX +XXX,XX @@ static void hvf_start_vcpu_thread(CPUState *cpu) | ||
1046 | cpu, QEMU_THREAD_JOINABLE); | ||
1047 | } | ||
1048 | |||
1049 | -const CpusAccel hvf_cpus = { | ||
1050 | - .create_vcpu_thread = hvf_start_vcpu_thread, | ||
1051 | +static void hvf_accel_ops_class_init(ObjectClass *oc, void *data) | ||
1052 | +{ | ||
1053 | + AccelOpsClass *ops = ACCEL_OPS_CLASS(oc); | ||
1054 | |||
1055 | - .synchronize_post_reset = hvf_cpu_synchronize_post_reset, | ||
1056 | - .synchronize_post_init = hvf_cpu_synchronize_post_init, | ||
1057 | - .synchronize_state = hvf_cpu_synchronize_state, | ||
1058 | - .synchronize_pre_loadvm = hvf_cpu_synchronize_pre_loadvm, | ||
1059 | + ops->create_vcpu_thread = hvf_start_vcpu_thread; | ||
1060 | + | ||
1061 | + ops->synchronize_post_reset = hvf_cpu_synchronize_post_reset; | ||
1062 | + ops->synchronize_post_init = hvf_cpu_synchronize_post_init; | ||
1063 | + ops->synchronize_state = hvf_cpu_synchronize_state; | ||
1064 | + ops->synchronize_pre_loadvm = hvf_cpu_synchronize_pre_loadvm; | ||
1065 | }; | ||
1066 | +static const TypeInfo hvf_accel_ops_type = { | ||
1067 | + .name = ACCEL_OPS_NAME("hvf"), | ||
1068 | + | ||
1069 | + .parent = TYPE_ACCEL_OPS, | ||
1070 | + .class_init = hvf_accel_ops_class_init, | ||
1071 | + .abstract = true, | ||
1072 | +}; | ||
1073 | +static void hvf_accel_ops_register_types(void) | ||
1074 | +{ | ||
1075 | + type_register_static(&hvf_accel_ops_type); | ||
1076 | +} | ||
1077 | +type_init(hvf_accel_ops_register_types); | ||
1078 | diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c | ||
1079 | index XXXXXXX..XXXXXXX 100644 | ||
1080 | --- a/target/i386/hvf/hvf.c | ||
1081 | +++ b/target/i386/hvf/hvf.c | ||
1082 | @@ -XXX,XX +XXX,XX @@ | ||
1083 | #include "qemu/accel.h" | ||
1084 | #include "target/i386/cpu.h" | ||
1085 | |||
1086 | -#include "hvf-cpus.h" | ||
1087 | +#include "hvf-accel-ops.h" | ||
1088 | |||
1089 | HVFState *hvf_state; | ||
1090 | |||
1091 | @@ -XXX,XX +XXX,XX @@ static int hvf_accel_init(MachineState *ms) | ||
1092 | |||
1093 | hvf_state = s; | ||
1094 | memory_listener_register(&hvf_memory_listener, &address_space_memory); | ||
1095 | - cpus_register_accel(&hvf_cpus); | ||
1096 | return 0; | ||
1097 | } | ||
1098 | |||
1099 | diff --git a/target/i386/hvf/x86hvf.c b/target/i386/hvf/x86hvf.c | ||
1100 | index XXXXXXX..XXXXXXX 100644 | ||
1101 | --- a/target/i386/hvf/x86hvf.c | ||
1102 | +++ b/target/i386/hvf/x86hvf.c | ||
1103 | @@ -XXX,XX +XXX,XX @@ | ||
1104 | #include <Hypervisor/hv.h> | ||
1105 | #include <Hypervisor/hv_vmx.h> | ||
1106 | |||
1107 | -#include "hvf-cpus.h" | ||
1108 | +#include "hvf-accel-ops.h" | ||
1109 | |||
1110 | void hvf_set_segment(struct CPUState *cpu, struct vmx_segment *vmx_seg, | ||
1111 | SegmentCache *qseg, bool is_tr) | ||
1112 | diff --git a/target/i386/whpx/whpx-cpus.c b/target/i386/whpx/whpx-accel-ops.c | ||
1113 | similarity index 71% | ||
1114 | rename from target/i386/whpx/whpx-cpus.c | ||
1115 | rename to target/i386/whpx/whpx-accel-ops.c | ||
1116 | index XXXXXXX..XXXXXXX 100644 | ||
1117 | --- a/target/i386/whpx/whpx-cpus.c | ||
1118 | +++ b/target/i386/whpx/whpx-accel-ops.c | ||
1119 | @@ -XXX,XX +XXX,XX @@ | ||
1120 | |||
1121 | #include "sysemu/whpx.h" | ||
1122 | #include "whpx-internal.h" | ||
1123 | -#include "whpx-cpus.h" | ||
1124 | +#include "whpx-accel-ops.h" | ||
1125 | |||
1126 | static void *whpx_cpu_thread_fn(void *arg) | ||
1127 | { | ||
1128 | @@ -XXX,XX +XXX,XX @@ static void whpx_kick_vcpu_thread(CPUState *cpu) | ||
1129 | } | ||
1130 | } | ||
1131 | |||
1132 | -const CpusAccel whpx_cpus = { | ||
1133 | - .create_vcpu_thread = whpx_start_vcpu_thread, | ||
1134 | - .kick_vcpu_thread = whpx_kick_vcpu_thread, | ||
1135 | +static void whpx_accel_ops_class_init(ObjectClass *oc, void *data) | ||
1136 | +{ | ||
1137 | + AccelOpsClass *ops = ACCEL_OPS_CLASS(oc); | ||
1138 | |||
1139 | - .synchronize_post_reset = whpx_cpu_synchronize_post_reset, | ||
1140 | - .synchronize_post_init = whpx_cpu_synchronize_post_init, | ||
1141 | - .synchronize_state = whpx_cpu_synchronize_state, | ||
1142 | - .synchronize_pre_loadvm = whpx_cpu_synchronize_pre_loadvm, | ||
1143 | + ops->create_vcpu_thread = whpx_start_vcpu_thread; | ||
1144 | + ops->kick_vcpu_thread = whpx_kick_vcpu_thread; | ||
1145 | + | ||
1146 | + ops->synchronize_post_reset = whpx_cpu_synchronize_post_reset; | ||
1147 | + ops->synchronize_post_init = whpx_cpu_synchronize_post_init; | ||
1148 | + ops->synchronize_state = whpx_cpu_synchronize_state; | ||
1149 | + ops->synchronize_pre_loadvm = whpx_cpu_synchronize_pre_loadvm; | ||
1150 | +} | ||
1151 | + | ||
1152 | +static const TypeInfo whpx_accel_ops_type = { | ||
1153 | + .name = ACCEL_OPS_NAME("whpx"), | ||
1154 | + | ||
1155 | + .parent = TYPE_ACCEL_OPS, | ||
1156 | + .class_init = whpx_accel_ops_class_init, | ||
1157 | + .abstract = true, | ||
1158 | }; | ||
1159 | + | ||
1160 | +static void whpx_accel_ops_register_types(void) | ||
1161 | +{ | ||
1162 | + type_register_static(&whpx_accel_ops_type); | ||
1163 | +} | ||
1164 | +type_init(whpx_accel_ops_register_types); | ||
1165 | diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c | ||
1166 | index XXXXXXX..XXXXXXX 100644 | ||
1167 | --- a/target/i386/whpx/whpx-all.c | ||
1168 | +++ b/target/i386/whpx/whpx-all.c | ||
1169 | @@ -XXX,XX +XXX,XX @@ | ||
1170 | #include "migration/blocker.h" | ||
1171 | #include <winerror.h> | ||
1172 | |||
1173 | -#include "whpx-cpus.h" | ||
1174 | #include "whpx-internal.h" | ||
1175 | +#include "whpx-accel-ops.h" | ||
1176 | + | ||
1177 | +#include <WinHvPlatform.h> | ||
1178 | +#include <WinHvEmulation.h> | ||
1179 | |||
1180 | #define HYPERV_APIC_BUS_FREQUENCY (200000000ULL) | ||
1181 | |||
1182 | @@ -XXX,XX +XXX,XX @@ static int whpx_accel_init(MachineState *ms) | ||
1183 | |||
1184 | whpx_memory_init(); | ||
1185 | |||
1186 | - cpus_register_accel(&whpx_cpus); | ||
1187 | - | ||
1188 | printf("Windows Hypervisor Platform accelerator is operational\n"); | ||
1189 | return 0; | ||
1190 | |||
1191 | diff --git a/MAINTAINERS b/MAINTAINERS | ||
1192 | index XXXXXXX..XXXXXXX 100644 | ||
1193 | --- a/MAINTAINERS | ||
1194 | +++ b/MAINTAINERS | ||
1195 | @@ -XXX,XX +XXX,XX @@ M: Richard Henderson <richard.henderson@linaro.org> | ||
1196 | R: Paolo Bonzini <pbonzini@redhat.com> | ||
1197 | S: Maintained | ||
1198 | F: include/qemu/accel.h | ||
1199 | -F: accel/accel.c | ||
1200 | +F: include/sysemu/accel-ops.h | ||
1201 | +F: accel/accel-*.c | ||
1202 | F: accel/Makefile.objs | ||
1203 | F: accel/stubs/Makefile.objs | ||
1204 | |||
1205 | diff --git a/accel/kvm/meson.build b/accel/kvm/meson.build | ||
1206 | index XXXXXXX..XXXXXXX 100644 | ||
1207 | --- a/accel/kvm/meson.build | ||
1208 | +++ b/accel/kvm/meson.build | ||
1209 | @@ -XXX,XX +XXX,XX @@ | ||
1210 | kvm_ss = ss.source_set() | ||
1211 | kvm_ss.add(files( | ||
1212 | 'kvm-all.c', | ||
1213 | - 'kvm-cpus.c', | ||
1214 | + 'kvm-accel-ops.c', | ||
1215 | )) | ||
1216 | kvm_ss.add(when: 'CONFIG_SEV', if_false: files('sev-stub.c')) | ||
1217 | |||
1218 | diff --git a/accel/tcg/meson.build b/accel/tcg/meson.build | ||
1219 | index XXXXXXX..XXXXXXX 100644 | ||
1220 | --- a/accel/tcg/meson.build | ||
1221 | +++ b/accel/tcg/meson.build | ||
1222 | @@ -XXX,XX +XXX,XX @@ specific_ss.add_all(when: 'CONFIG_TCG', if_true: tcg_ss) | ||
1223 | |||
1224 | specific_ss.add(when: ['CONFIG_SOFTMMU', 'CONFIG_TCG'], if_true: files( | ||
1225 | 'cputlb.c', | ||
1226 | - 'tcg-cpus.c', | ||
1227 | - 'tcg-cpus-mttcg.c', | ||
1228 | - 'tcg-cpus-icount.c', | ||
1229 | - 'tcg-cpus-rr.c' | ||
1230 | + 'tcg-accel-ops.c', | ||
1231 | + 'tcg-accel-ops-mttcg.c', | ||
1232 | + 'tcg-accel-ops-icount.c', | ||
1233 | + 'tcg-accel-ops-rr.c' | ||
1234 | )) | ||
1235 | diff --git a/target/i386/hax/meson.build b/target/i386/hax/meson.build | ||
1236 | index XXXXXXX..XXXXXXX 100644 | ||
1237 | --- a/target/i386/hax/meson.build | ||
1238 | +++ b/target/i386/hax/meson.build | ||
1239 | @@ -XXX,XX +XXX,XX @@ | ||
1240 | i386_softmmu_ss.add(when: 'CONFIG_HAX', if_true: files( | ||
1241 | 'hax-all.c', | ||
1242 | 'hax-mem.c', | ||
1243 | - 'hax-cpus.c', | ||
1244 | + 'hax-accel-ops.c', | ||
1245 | )) | ||
1246 | i386_softmmu_ss.add(when: ['CONFIG_HAX', 'CONFIG_POSIX'], if_true: files('hax-posix.c')) | ||
1247 | i386_softmmu_ss.add(when: ['CONFIG_HAX', 'CONFIG_WIN32'], if_true: files('hax-windows.c')) | ||
1248 | diff --git a/target/i386/hvf/meson.build b/target/i386/hvf/meson.build | ||
1249 | index XXXXXXX..XXXXXXX 100644 | ||
1250 | --- a/target/i386/hvf/meson.build | ||
1251 | +++ b/target/i386/hvf/meson.build | ||
1252 | @@ -XXX,XX +XXX,XX @@ | ||
1253 | i386_softmmu_ss.add(when: [hvf, 'CONFIG_HVF'], if_true: files( | ||
1254 | 'hvf.c', | ||
1255 | - 'hvf-cpus.c', | ||
1256 | + 'hvf-accel-ops.c', | ||
1257 | 'x86.c', | ||
1258 | 'x86_cpuid.c', | ||
1259 | 'x86_decode.c', | ||
1260 | diff --git a/target/i386/whpx/meson.build b/target/i386/whpx/meson.build | ||
1261 | index XXXXXXX..XXXXXXX 100644 | ||
1262 | --- a/target/i386/whpx/meson.build | ||
1263 | +++ b/target/i386/whpx/meson.build | ||
1264 | @@ -XXX,XX +XXX,XX @@ | ||
1265 | i386_softmmu_ss.add(when: 'CONFIG_WHPX', if_true: files( | ||
1266 | 'whpx-all.c', | ||
1267 | 'whpx-apic.c', | ||
1268 | - 'whpx-cpus.c', | ||
1269 | + 'whpx-accel-ops.c', | ||
1270 | )) | ||
1271 | -- | 67 | -- |
1272 | 2.25.1 | 68 | 2.25.1 |
1273 | 69 | ||
1274 | 70 | diff view generated by jsdifflib |
1 | Tested-by: Alex Bennée <alex.bennee@linaro.org> | 1 | From: Luis Pires <luis.pires@eldorado.org.br> |
---|---|---|---|
2 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 2 | |
3 | In preparation for changing the divu128/divs128 implementations | ||
4 | to allow for quotients larger than 64 bits, move the div-by-zero | ||
5 | and overflow checks to the callers. | ||
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> | ||
3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 10 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
4 | --- | 11 | --- |
5 | tcg/tci.c | 20 +++++++++++++------- | 12 | include/hw/clock.h | 5 +++-- |
6 | 1 file changed, 13 insertions(+), 7 deletions(-) | 13 | include/qemu/host-utils.h | 34 ++++++++++++--------------------- |
7 | 14 | target/ppc/int_helper.c | 14 +++++++++----- | |
8 | diff --git a/tcg/tci.c b/tcg/tci.c | 15 | util/host-utils.c | 40 ++++++++++++++++++--------------------- |
9 | index XXXXXXX..XXXXXXX 100644 | 16 | 4 files changed, 42 insertions(+), 51 deletions(-) |
10 | --- a/tcg/tci.c | 17 | |
11 | +++ b/tcg/tci.c | 18 | diff --git a/include/hw/clock.h b/include/hw/clock.h |
12 | @@ -XXX,XX +XXX,XX @@ static bool tci_compare64(uint64_t u0, uint64_t u1, TCGCond condition) | 19 | index XXXXXXX..XXXXXXX 100644 |
13 | # define qemu_st_beq(X) stq_be_p(g2h(taddr), X) | 20 | --- a/include/hw/clock.h |
21 | +++ b/include/hw/clock.h | ||
22 | @@ -XXX,XX +XXX,XX @@ static inline uint64_t clock_ns_to_ticks(const Clock *clk, uint64_t ns) | ||
23 | return 0; | ||
24 | } | ||
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 { | ||
158 | |||
159 | for (i = 0; i < 64; i++) { | ||
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 | } | ||
166 | } | ||
167 | |||
168 | -int divs128(int64_t *plow, int64_t *phigh, int64_t divisor) | ||
169 | +/* | ||
170 | + * Signed 128-by-64 division. Returns quotient via plow and | ||
171 | + * remainder via phigh. | ||
172 | + * The result must fit in 64 bits (plow) - otherwise, the result | ||
173 | + * is undefined. | ||
174 | + * This function will cause a division by zero if passed a zero divisor. | ||
175 | + */ | ||
176 | +void divs128(int64_t *plow, int64_t *phigh, int64_t divisor) | ||
177 | { | ||
178 | int sgn_dvdnd = *phigh < 0; | ||
179 | int sgn_divsr = divisor < 0; | ||
180 | - int overflow = 0; | ||
181 | |||
182 | if (sgn_dvdnd) { | ||
183 | *plow = ~(*plow); | ||
184 | @@ -XXX,XX +XXX,XX @@ int divs128(int64_t *plow, int64_t *phigh, int64_t divisor) | ||
185 | divisor = 0 - divisor; | ||
186 | } | ||
187 | |||
188 | - overflow = divu128((uint64_t *)plow, (uint64_t *)phigh, (uint64_t)divisor); | ||
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 | } | ||
14 | #endif | 203 | #endif |
15 | 204 | ||
16 | +#if TCG_TARGET_REG_BITS == 64 | ||
17 | +# define CASE_32_64(x) \ | ||
18 | + case glue(glue(INDEX_op_, x), _i64): \ | ||
19 | + case glue(glue(INDEX_op_, x), _i32): | ||
20 | +# define CASE_64(x) \ | ||
21 | + case glue(glue(INDEX_op_, x), _i64): | ||
22 | +#else | ||
23 | +# define CASE_32_64(x) \ | ||
24 | + case glue(glue(INDEX_op_, x), _i32): | ||
25 | +# define CASE_64(x) | ||
26 | +#endif | ||
27 | + | ||
28 | /* Interpret pseudo code in tb. */ | ||
29 | /* | ||
30 | * Disable CFI checks. | ||
31 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | ||
32 | |||
33 | /* Load/store operations (32 bit). */ | ||
34 | |||
35 | - case INDEX_op_ld8u_i32: | ||
36 | + CASE_32_64(ld8u) | ||
37 | t0 = *tb_ptr++; | ||
38 | t1 = tci_read_r(regs, &tb_ptr); | ||
39 | t2 = tci_read_s32(&tb_ptr); | ||
40 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | ||
41 | |||
42 | /* Load/store operations (64 bit). */ | ||
43 | |||
44 | - case INDEX_op_ld8u_i64: | ||
45 | - t0 = *tb_ptr++; | ||
46 | - t1 = tci_read_r(regs, &tb_ptr); | ||
47 | - t2 = tci_read_s32(&tb_ptr); | ||
48 | - tci_write_reg(regs, t0, *(uint8_t *)(t1 + t2)); | ||
49 | - break; | ||
50 | case INDEX_op_ld8s_i64: | ||
51 | t0 = *tb_ptr++; | ||
52 | t1 = tci_read_r(regs, &tb_ptr); | ||
53 | -- | 205 | -- |
54 | 2.25.1 | 206 | 2.25.1 |
55 | 207 | ||
56 | 208 | diff view generated by jsdifflib |
1 | Tested-by: Alex Bennée <alex.bennee@linaro.org> | 1 | From: Luis Pires <luis.pires@eldorado.org.br> |
---|---|---|---|
2 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 2 | |
3 | Move udiv_qrnnd() from include/fpu/softfloat-macros.h to host-utils, | ||
4 | so it can be reused by divu128(). | ||
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> | ||
3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 9 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
4 | --- | 10 | --- |
5 | tcg/tci.c | 8 -------- | 11 | include/fpu/softfloat-macros.h | 82 ---------------------------------- |
6 | 1 file changed, 8 deletions(-) | 12 | include/qemu/host-utils.h | 81 +++++++++++++++++++++++++++++++++ |
7 | 13 | 2 files changed, 81 insertions(+), 82 deletions(-) | |
8 | diff --git a/tcg/tci.c b/tcg/tci.c | 14 | |
15 | diff --git a/include/fpu/softfloat-macros.h b/include/fpu/softfloat-macros.h | ||
9 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
10 | --- a/tcg/tci.c | 17 | --- a/include/fpu/softfloat-macros.h |
11 | +++ b/tcg/tci.c | 18 | +++ b/include/fpu/softfloat-macros.h |
12 | @@ -XXX,XX +XXX,XX @@ | 19 | @@ -XXX,XX +XXX,XX @@ |
13 | #include "tcg/tcg-op.h" | 20 | * so some portions are provided under: |
14 | #include "qemu/compiler.h" | 21 | * the SoftFloat-2a license |
15 | 22 | * the BSD license | |
16 | -/* Marker for missing code. */ | 23 | - * GPL-v2-or-later |
17 | -#define TODO() \ | 24 | * |
18 | - do { \ | 25 | * Any future contributions to this file after December 1st 2014 will be |
19 | - fprintf(stderr, "TODO %s:%u: %s()\n", \ | 26 | * taken to be licensed under the Softfloat-2a license unless specifically |
20 | - __FILE__, __LINE__, __func__); \ | 27 | @@ -XXX,XX +XXX,XX @@ this code that are retained. |
21 | - tcg_abort(); \ | 28 | * THE POSSIBILITY OF SUCH DAMAGE. |
22 | - } while (0) | 29 | */ |
23 | - | 30 | |
24 | #if MAX_OPC_PARAM_IARGS != 6 | 31 | -/* Portions of this work are licensed under the terms of the GNU GPL, |
25 | # error Fix needed, number of supported input arguments changed! | 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 | } | ||
41 | |||
42 | -/* From the GNU Multi Precision Library - longlong.h __udiv_qrnnd | ||
43 | - * (https://gmplib.org/repo/gmp/file/tip/longlong.h) | ||
44 | - * | ||
45 | - * Licensed under the GPLv2/LGPLv3 | ||
46 | - */ | ||
47 | -static inline uint64_t udiv_qrnnd(uint64_t *r, uint64_t n1, | ||
48 | - uint64_t n0, uint64_t d) | ||
49 | -{ | ||
50 | -#if defined(__x86_64__) | ||
51 | - uint64_t q; | ||
52 | - asm("divq %4" : "=a"(q), "=d"(*r) : "0"(n0), "1"(n1), "rm"(d)); | ||
53 | - return q; | ||
54 | -#elif defined(__s390x__) && !defined(__clang__) | ||
55 | - /* Need to use a TImode type to get an even register pair for DLGR. */ | ||
56 | - unsigned __int128 n = (unsigned __int128)n1 << 64 | n0; | ||
57 | - asm("dlgr %0, %1" : "+r"(n) : "r"(d)); | ||
58 | - *r = n >> 64; | ||
59 | - return n; | ||
60 | -#elif defined(_ARCH_PPC64) && defined(_ARCH_PWR7) | ||
61 | - /* From Power ISA 2.06, programming note for divdeu. */ | ||
62 | - uint64_t q1, q2, Q, r1, r2, R; | ||
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 | -} | ||
118 | - | ||
119 | /*---------------------------------------------------------------------------- | ||
120 | | Returns an approximation to the square root of the 32-bit significand given | ||
121 | | by `a'. Considered as an integer, `a' must be at least 2^31. If bit 0 of | ||
122 | diff --git a/include/qemu/host-utils.h b/include/qemu/host-utils.h | ||
123 | index XXXXXXX..XXXXXXX 100644 | ||
124 | --- a/include/qemu/host-utils.h | ||
125 | +++ b/include/qemu/host-utils.h | ||
126 | @@ -XXX,XX +XXX,XX @@ | ||
127 | * THE SOFTWARE. | ||
128 | */ | ||
129 | |||
130 | +/* Portions of this work are licensed under the terms of the GNU GPL, | ||
131 | + * version 2 or later. See the COPYING file in the top-level directory. | ||
132 | + */ | ||
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 | + | ||
26 | #endif | 218 | #endif |
27 | -- | 219 | -- |
28 | 2.25.1 | 220 | 2.25.1 |
29 | 221 | ||
30 | 222 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | 1 | From: Luis Pires <luis.pires@eldorado.org.br> |
---|---|---|---|
2 | 2 | ||
3 | "exec/cpu-defs.h" contains generic CPU definitions for the | 3 | These will be used to implement new decimal floating point |
4 | TCG frontends (mostly related to TLB). TCG backends definitions | 4 | instructions from Power ISA 3.1. |
5 | aren't relevant here. | 5 | |
6 | 6 | The remainder is now returned directly by divu128/divs128, | |
7 | See tcg/README description: | 7 | freeing up phigh to receive the high 64 bits of the quotient. |
8 | 8 | ||
9 | 4) Backend | 9 | Signed-off-by: Luis Pires <luis.pires@eldorado.org.br> |
10 | 10 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | |
11 | tcg-target.h contains the target specific definitions. tcg-target.c.inc | 11 | Message-Id: <20211025191154.350831-4-luis.pires@eldorado.org.br> |
12 | contains the target specific code; it is #included by tcg/tcg.c, rather | ||
13 | than being a standalone C file. | ||
14 | |||
15 | So far only "tcg/tcg.h" requires these headers. | ||
16 | |||
17 | Remove the "target-tcg.h" header dependency on TCG frontends, so we | ||
18 | don't have to rebuild all frontends when hacking a single backend. | ||
19 | |||
20 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
21 | Message-Id: <20210204191423.1754158-1-f4bug@amsat.org> | ||
22 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 12 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
23 | --- | 13 | --- |
24 | include/exec/cpu-defs.h | 3 --- | 14 | include/hw/clock.h | 6 +- |
25 | 1 file changed, 3 deletions(-) | 15 | include/qemu/host-utils.h | 20 ++++-- |
26 | 16 | target/ppc/int_helper.c | 9 +-- | |
27 | diff --git a/include/exec/cpu-defs.h b/include/exec/cpu-defs.h | 17 | util/host-utils.c | 133 +++++++++++++++++++++++++------------- |
28 | index XXXXXXX..XXXXXXX 100644 | 18 | 4 files changed, 108 insertions(+), 60 deletions(-) |
29 | --- a/include/exec/cpu-defs.h | 19 | |
30 | +++ b/include/exec/cpu-defs.h | 20 | diff --git a/include/hw/clock.h b/include/hw/clock.h |
31 | @@ -XXX,XX +XXX,XX @@ | 21 | index XXXXXXX..XXXXXXX 100644 |
32 | 22 | --- a/include/hw/clock.h | |
33 | #include "qemu/host-utils.h" | 23 | +++ b/include/hw/clock.h |
34 | #include "qemu/thread.h" | 24 | @@ -XXX,XX +XXX,XX @@ static inline uint64_t clock_ns_to_ticks(const Clock *clk, uint64_t ns) |
35 | -#ifdef CONFIG_TCG | 25 | if (clk->period == 0) { |
36 | -#include "tcg-target.h" | 26 | return 0; |
37 | -#endif | 27 | } |
38 | #ifndef CONFIG_USER_ONLY | 28 | - /* |
39 | #include "exec/hwaddr.h" | 29 | - * BUG: when CONFIG_INT128 is not defined, the current implementation of |
30 | - * divu128 does not return a valid truncated quotient, so the result will | ||
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 | - | ||
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 | } | ||
40 | #endif | 281 | #endif |
41 | -- | 282 | -- |
42 | 2.25.1 | 283 | 2.25.1 |
43 | 284 | ||
44 | 285 | diff view generated by jsdifflib |
1 | From: Claudio Fontana <cfontana@suse.de> | 1 | From: Luis Pires <luis.pires@eldorado.org.br> |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: Claudio Fontana <cfontana@suse.de> | 3 | Signed-off-by: Luis Pires <luis.pires@eldorado.org.br> |
4 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 4 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
5 | 5 | Message-Id: <20211025191154.350831-5-luis.pires@eldorado.org.br> | |
6 | [claudio: rebased on Richard's splitwx work] | ||
7 | |||
8 | Signed-off-by: Claudio Fontana <cfontana@suse.de> | ||
9 | Message-Id: <20210204163931.7358-17-cfontana@suse.de> | ||
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/boards.h | 2 +- | 8 | tests/unit/test-div128.c | 197 +++++++++++++++++++++++++++++++++++++++ |
13 | include/{sysemu => qemu}/accel.h | 14 +++++---- | 9 | tests/unit/meson.build | 1 + |
14 | include/sysemu/hvf.h | 2 +- | 10 | 2 files changed, 198 insertions(+) |
15 | include/sysemu/kvm.h | 2 +- | 11 | create mode 100644 tests/unit/test-div128.c |
16 | include/sysemu/kvm_int.h | 2 +- | 12 | |
17 | target/i386/hvf/hvf-i386.h | 2 +- | 13 | diff --git a/tests/unit/test-div128.c b/tests/unit/test-div128.c |
18 | accel/accel-common.c | 50 ++++++++++++++++++++++++++++++ | ||
19 | accel/{accel.c => accel-softmmu.c} | 27 ++-------------- | ||
20 | accel/accel-user.c | 24 ++++++++++++++ | ||
21 | accel/qtest/qtest.c | 2 +- | ||
22 | accel/tcg/tcg-all.c | 15 +++++++-- | ||
23 | accel/xen/xen-all.c | 2 +- | ||
24 | bsd-user/main.c | 6 +++- | ||
25 | linux-user/main.c | 6 +++- | ||
26 | softmmu/memory.c | 2 +- | ||
27 | softmmu/qtest.c | 2 +- | ||
28 | softmmu/vl.c | 2 +- | ||
29 | target/i386/hax/hax-all.c | 2 +- | ||
30 | target/i386/hvf/hvf.c | 2 +- | ||
31 | target/i386/hvf/x86_task.c | 2 +- | ||
32 | target/i386/whpx/whpx-all.c | 2 +- | ||
33 | MAINTAINERS | 2 +- | ||
34 | accel/meson.build | 4 ++- | ||
35 | accel/tcg/meson.build | 2 +- | ||
36 | 24 files changed, 125 insertions(+), 53 deletions(-) | ||
37 | rename include/{sysemu => qemu}/accel.h (95%) | ||
38 | create mode 100644 accel/accel-common.c | ||
39 | rename accel/{accel.c => accel-softmmu.c} (75%) | ||
40 | create mode 100644 accel/accel-user.c | ||
41 | |||
42 | diff --git a/include/hw/boards.h b/include/hw/boards.h | ||
43 | index XXXXXXX..XXXXXXX 100644 | ||
44 | --- a/include/hw/boards.h | ||
45 | +++ b/include/hw/boards.h | ||
46 | @@ -XXX,XX +XXX,XX @@ | ||
47 | #include "exec/memory.h" | ||
48 | #include "sysemu/hostmem.h" | ||
49 | #include "sysemu/blockdev.h" | ||
50 | -#include "sysemu/accel.h" | ||
51 | +#include "qemu/accel.h" | ||
52 | #include "qapi/qapi-types-machine.h" | ||
53 | #include "qemu/module.h" | ||
54 | #include "qom/object.h" | ||
55 | diff --git a/include/sysemu/accel.h b/include/qemu/accel.h | ||
56 | similarity index 95% | ||
57 | rename from include/sysemu/accel.h | ||
58 | rename to include/qemu/accel.h | ||
59 | index XXXXXXX..XXXXXXX 100644 | ||
60 | --- a/include/sysemu/accel.h | ||
61 | +++ b/include/qemu/accel.h | ||
62 | @@ -XXX,XX +XXX,XX @@ | ||
63 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
64 | * THE SOFTWARE. | ||
65 | */ | ||
66 | -#ifndef HW_ACCEL_H | ||
67 | -#define HW_ACCEL_H | ||
68 | +#ifndef QEMU_ACCEL_H | ||
69 | +#define QEMU_ACCEL_H | ||
70 | |||
71 | #include "qom/object.h" | ||
72 | #include "exec/hwaddr.h" | ||
73 | @@ -XXX,XX +XXX,XX @@ typedef struct AccelClass { | ||
74 | /*< public >*/ | ||
75 | |||
76 | const char *name; | ||
77 | -#ifndef CONFIG_USER_ONLY | ||
78 | int (*init_machine)(MachineState *ms); | ||
79 | +#ifndef CONFIG_USER_ONLY | ||
80 | void (*setup_post)(MachineState *ms, AccelState *accel); | ||
81 | bool (*has_memory)(MachineState *ms, AddressSpace *as, | ||
82 | hwaddr start_addr, hwaddr size); | ||
83 | @@ -XXX,XX +XXX,XX @@ typedef struct AccelClass { | ||
84 | OBJECT_GET_CLASS(AccelClass, (obj), TYPE_ACCEL) | ||
85 | |||
86 | AccelClass *accel_find(const char *opt_name); | ||
87 | +AccelState *current_accel(void); | ||
88 | + | ||
89 | +#ifndef CONFIG_USER_ONLY | ||
90 | int accel_init_machine(AccelState *accel, MachineState *ms); | ||
91 | |||
92 | /* Called just before os_setup_post (ie just before drop OS privs) */ | ||
93 | void accel_setup_post(MachineState *ms); | ||
94 | +#endif /* !CONFIG_USER_ONLY */ | ||
95 | |||
96 | -AccelState *current_accel(void); | ||
97 | - | ||
98 | -#endif | ||
99 | +#endif /* QEMU_ACCEL_H */ | ||
100 | diff --git a/include/sysemu/hvf.h b/include/sysemu/hvf.h | ||
101 | index XXXXXXX..XXXXXXX 100644 | ||
102 | --- a/include/sysemu/hvf.h | ||
103 | +++ b/include/sysemu/hvf.h | ||
104 | @@ -XXX,XX +XXX,XX @@ | ||
105 | #ifndef HVF_H | ||
106 | #define HVF_H | ||
107 | |||
108 | -#include "sysemu/accel.h" | ||
109 | +#include "qemu/accel.h" | ||
110 | #include "qom/object.h" | ||
111 | |||
112 | #ifdef CONFIG_HVF | ||
113 | diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h | ||
114 | index XXXXXXX..XXXXXXX 100644 | ||
115 | --- a/include/sysemu/kvm.h | ||
116 | +++ b/include/sysemu/kvm.h | ||
117 | @@ -XXX,XX +XXX,XX @@ | ||
118 | #include "qemu/queue.h" | ||
119 | #include "hw/core/cpu.h" | ||
120 | #include "exec/memattrs.h" | ||
121 | -#include "sysemu/accel.h" | ||
122 | +#include "qemu/accel.h" | ||
123 | #include "qom/object.h" | ||
124 | |||
125 | #ifdef NEED_CPU_H | ||
126 | diff --git a/include/sysemu/kvm_int.h b/include/sysemu/kvm_int.h | ||
127 | index XXXXXXX..XXXXXXX 100644 | ||
128 | --- a/include/sysemu/kvm_int.h | ||
129 | +++ b/include/sysemu/kvm_int.h | ||
130 | @@ -XXX,XX +XXX,XX @@ | ||
131 | #define QEMU_KVM_INT_H | ||
132 | |||
133 | #include "exec/memory.h" | ||
134 | -#include "sysemu/accel.h" | ||
135 | +#include "qemu/accel.h" | ||
136 | #include "sysemu/kvm.h" | ||
137 | |||
138 | typedef struct KVMSlot | ||
139 | diff --git a/target/i386/hvf/hvf-i386.h b/target/i386/hvf/hvf-i386.h | ||
140 | index XXXXXXX..XXXXXXX 100644 | ||
141 | --- a/target/i386/hvf/hvf-i386.h | ||
142 | +++ b/target/i386/hvf/hvf-i386.h | ||
143 | @@ -XXX,XX +XXX,XX @@ | ||
144 | #ifndef HVF_I386_H | ||
145 | #define HVF_I386_H | ||
146 | |||
147 | -#include "sysemu/accel.h" | ||
148 | +#include "qemu/accel.h" | ||
149 | #include "sysemu/hvf.h" | ||
150 | #include "cpu.h" | ||
151 | #include "x86.h" | ||
152 | diff --git a/accel/accel-common.c b/accel/accel-common.c | ||
153 | new file mode 100644 | 14 | new file mode 100644 |
154 | index XXXXXXX..XXXXXXX | 15 | index XXXXXXX..XXXXXXX |
155 | --- /dev/null | 16 | --- /dev/null |
156 | +++ b/accel/accel-common.c | 17 | +++ b/tests/unit/test-div128.c |
157 | @@ -XXX,XX +XXX,XX @@ | 18 | @@ -XXX,XX +XXX,XX @@ |
158 | +/* | 19 | +/* |
159 | + * QEMU accel class, components common to system emulation and user mode | 20 | + * Test 128-bit division functions |
160 | + * | 21 | + * |
161 | + * Copyright (c) 2003-2008 Fabrice Bellard | 22 | + * Copyright (c) 2021 Instituto de Pesquisas Eldorado (eldorado.org.br) |
162 | + * Copyright (c) 2014 Red Hat Inc. | 23 | + * |
163 | + * | 24 | + * This library is free software; you can redistribute it and/or |
164 | + * Permission is hereby granted, free of charge, to any person obtaining a copy | 25 | + * modify it under the terms of the GNU Lesser General Public |
165 | + * of this software and associated documentation files (the "Software"), to deal | 26 | + * License as published by the Free Software Foundation; either |
166 | + * in the Software without restriction, including without limitation the rights | 27 | + * version 2.1 of the License, or (at your option) any later version. |
167 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | 28 | + * |
168 | + * copies of the Software, and to permit persons to whom the Software is | 29 | + * This library is distributed in the hope that it will be useful, |
169 | + * furnished to do so, subject to the following conditions: | 30 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
170 | + * | 31 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
171 | + * The above copyright notice and this permission notice shall be included in | 32 | + * Lesser General Public License for more details. |
172 | + * all copies or substantial portions of the Software. | 33 | + * |
173 | + * | 34 | + * You should have received a copy of the GNU Lesser General Public |
174 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 35 | + * License along with this library; if not, see <http://www.gnu.org/licenses/>. |
175 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
176 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
177 | + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
178 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
179 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
180 | + * THE SOFTWARE. | ||
181 | + */ | 36 | + */ |
182 | + | 37 | + |
183 | +#include "qemu/osdep.h" | 38 | +#include "qemu/osdep.h" |
184 | +#include "qemu/accel.h" | 39 | +#include "qemu/host-utils.h" |
185 | + | 40 | + |
186 | +static const TypeInfo accel_type = { | 41 | +typedef struct { |
187 | + .name = TYPE_ACCEL, | 42 | + uint64_t high; |
188 | + .parent = TYPE_OBJECT, | 43 | + uint64_t low; |
189 | + .class_size = sizeof(AccelClass), | 44 | + uint64_t rhigh; |
190 | + .instance_size = sizeof(AccelState), | 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}, | ||
191 | +}; | 121 | +}; |
192 | + | 122 | + |
193 | +/* Lookup AccelClass from opt_name. Returns NULL if not found */ | 123 | +static const test_data_signed test_table_signed[] = { |
194 | +AccelClass *accel_find(const char *opt_name) | 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) | ||
195 | +{ | 178 | +{ |
196 | + char *class_name = g_strdup_printf(ACCEL_CLASS_NAME("%s"), opt_name); | 179 | + int i; |
197 | + AccelClass *ac = ACCEL_CLASS(object_class_by_name(class_name)); | 180 | + uint64_t rem; |
198 | + g_free(class_name); | 181 | + test_data_unsigned tmp; |
199 | + return ac; | 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 | + } | ||
200 | +} | 191 | +} |
201 | + | 192 | + |
202 | +static void register_accel_types(void) | 193 | +static void test_divs128(void) |
203 | +{ | 194 | +{ |
204 | + type_register_static(&accel_type); | 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 | + } | ||
205 | +} | 207 | +} |
206 | + | 208 | + |
207 | +type_init(register_accel_types); | 209 | +int main(int argc, char **argv) |
208 | diff --git a/accel/accel.c b/accel/accel-softmmu.c | 210 | +{ |
209 | similarity index 75% | 211 | + g_test_init(&argc, &argv, NULL); |
210 | rename from accel/accel.c | 212 | + g_test_add_func("/host-utils/test_divu128", test_divu128); |
211 | rename to accel/accel-softmmu.c | 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 | ||
212 | index XXXXXXX..XXXXXXX 100644 | 217 | index XXXXXXX..XXXXXXX 100644 |
213 | --- a/accel/accel.c | 218 | --- a/tests/unit/meson.build |
214 | +++ b/accel/accel-softmmu.c | 219 | +++ b/tests/unit/meson.build |
215 | @@ -XXX,XX +XXX,XX @@ | 220 | @@ -XXX,XX +XXX,XX @@ tests = { |
216 | /* | 221 | # all code tested by test-x86-cpuid is inside topology.h |
217 | - * QEMU System Emulator, accelerator interfaces | 222 | 'test-x86-cpuid': [], |
218 | + * QEMU accel class, system emulation components | 223 | 'test-cutils': [], |
219 | * | 224 | + 'test-div128': [], |
220 | * Copyright (c) 2003-2008 Fabrice Bellard | 225 | 'test-shift128': [], |
221 | * Copyright (c) 2014 Red Hat Inc. | 226 | 'test-mul64': [], |
222 | @@ -XXX,XX +XXX,XX @@ | 227 | # all code tested by test-int128 is inside int128.h |
223 | */ | ||
224 | |||
225 | #include "qemu/osdep.h" | ||
226 | -#include "sysemu/accel.h" | ||
227 | +#include "qemu/accel.h" | ||
228 | #include "hw/boards.h" | ||
229 | #include "sysemu/arch_init.h" | ||
230 | #include "sysemu/sysemu.h" | ||
231 | #include "qom/object.h" | ||
232 | |||
233 | -static const TypeInfo accel_type = { | ||
234 | - .name = TYPE_ACCEL, | ||
235 | - .parent = TYPE_OBJECT, | ||
236 | - .class_size = sizeof(AccelClass), | ||
237 | - .instance_size = sizeof(AccelState), | ||
238 | -}; | ||
239 | - | ||
240 | -/* Lookup AccelClass from opt_name. Returns NULL if not found */ | ||
241 | -AccelClass *accel_find(const char *opt_name) | ||
242 | -{ | ||
243 | - char *class_name = g_strdup_printf(ACCEL_CLASS_NAME("%s"), opt_name); | ||
244 | - AccelClass *ac = ACCEL_CLASS(object_class_by_name(class_name)); | ||
245 | - g_free(class_name); | ||
246 | - return ac; | ||
247 | -} | ||
248 | - | ||
249 | int accel_init_machine(AccelState *accel, MachineState *ms) | ||
250 | { | ||
251 | AccelClass *acc = ACCEL_GET_CLASS(accel); | ||
252 | @@ -XXX,XX +XXX,XX @@ void accel_setup_post(MachineState *ms) | ||
253 | acc->setup_post(ms, accel); | ||
254 | } | ||
255 | } | ||
256 | - | ||
257 | -static void register_accel_types(void) | ||
258 | -{ | ||
259 | - type_register_static(&accel_type); | ||
260 | -} | ||
261 | - | ||
262 | -type_init(register_accel_types); | ||
263 | diff --git a/accel/accel-user.c b/accel/accel-user.c | ||
264 | new file mode 100644 | ||
265 | index XXXXXXX..XXXXXXX | ||
266 | --- /dev/null | ||
267 | +++ b/accel/accel-user.c | ||
268 | @@ -XXX,XX +XXX,XX @@ | ||
269 | +/* | ||
270 | + * QEMU accel class, user-mode components | ||
271 | + * | ||
272 | + * Copyright 2021 SUSE LLC | ||
273 | + * | ||
274 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
275 | + * See the COPYING file in the top-level directory. | ||
276 | + */ | ||
277 | + | ||
278 | +#include "qemu/osdep.h" | ||
279 | +#include "qemu/accel.h" | ||
280 | + | ||
281 | +AccelState *current_accel(void) | ||
282 | +{ | ||
283 | + static AccelState *accel; | ||
284 | + | ||
285 | + if (!accel) { | ||
286 | + AccelClass *ac = accel_find("tcg"); | ||
287 | + | ||
288 | + g_assert(ac != NULL); | ||
289 | + accel = ACCEL(object_new_with_class(OBJECT_CLASS(ac))); | ||
290 | + } | ||
291 | + return accel; | ||
292 | +} | ||
293 | diff --git a/accel/qtest/qtest.c b/accel/qtest/qtest.c | ||
294 | index XXXXXXX..XXXXXXX 100644 | ||
295 | --- a/accel/qtest/qtest.c | ||
296 | +++ b/accel/qtest/qtest.c | ||
297 | @@ -XXX,XX +XXX,XX @@ | ||
298 | #include "qemu/module.h" | ||
299 | #include "qemu/option.h" | ||
300 | #include "qemu/config-file.h" | ||
301 | -#include "sysemu/accel.h" | ||
302 | +#include "qemu/accel.h" | ||
303 | #include "sysemu/qtest.h" | ||
304 | #include "sysemu/cpus.h" | ||
305 | #include "sysemu/cpu-timers.h" | ||
306 | diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c | ||
307 | index XXXXXXX..XXXXXXX 100644 | ||
308 | --- a/accel/tcg/tcg-all.c | ||
309 | +++ b/accel/tcg/tcg-all.c | ||
310 | @@ -XXX,XX +XXX,XX @@ | ||
311 | #include "tcg/tcg.h" | ||
312 | #include "qapi/error.h" | ||
313 | #include "qemu/error-report.h" | ||
314 | -#include "hw/boards.h" | ||
315 | +#include "qemu/accel.h" | ||
316 | #include "qapi/qapi-builtin-visit.h" | ||
317 | + | ||
318 | +#ifndef CONFIG_USER_ONLY | ||
319 | #include "tcg-cpus.h" | ||
320 | +#endif /* CONFIG_USER_ONLY */ | ||
321 | |||
322 | struct TCGState { | ||
323 | AccelState parent_obj; | ||
324 | @@ -XXX,XX +XXX,XX @@ static void tcg_accel_instance_init(Object *obj) | ||
325 | s->mttcg_enabled = default_mttcg_enabled(); | ||
326 | |||
327 | /* If debugging enabled, default "auto on", otherwise off. */ | ||
328 | -#ifdef CONFIG_DEBUG_TCG | ||
329 | +#if defined(CONFIG_DEBUG_TCG) && !defined(CONFIG_USER_ONLY) | ||
330 | s->splitwx_enabled = -1; | ||
331 | #else | ||
332 | s->splitwx_enabled = 0; | ||
333 | @@ -XXX,XX +XXX,XX @@ static int tcg_init(MachineState *ms) | ||
334 | mttcg_enabled = s->mttcg_enabled; | ||
335 | |||
336 | /* | ||
337 | - * Initialize TCG regions | ||
338 | + * Initialize TCG regions only for softmmu. | ||
339 | + * | ||
340 | + * This needs to be done later for user mode, because the prologue | ||
341 | + * generation needs to be delayed so that GUEST_BASE is already set. | ||
342 | */ | ||
343 | +#ifndef CONFIG_USER_ONLY | ||
344 | tcg_region_init(); | ||
345 | |||
346 | if (mttcg_enabled) { | ||
347 | @@ -XXX,XX +XXX,XX @@ static int tcg_init(MachineState *ms) | ||
348 | } else { | ||
349 | cpus_register_accel(&tcg_cpus_rr); | ||
350 | } | ||
351 | +#endif /* !CONFIG_USER_ONLY */ | ||
352 | + | ||
353 | return 0; | ||
354 | } | ||
355 | |||
356 | diff --git a/accel/xen/xen-all.c b/accel/xen/xen-all.c | ||
357 | index XXXXXXX..XXXXXXX 100644 | ||
358 | --- a/accel/xen/xen-all.c | ||
359 | +++ b/accel/xen/xen-all.c | ||
360 | @@ -XXX,XX +XXX,XX @@ | ||
361 | #include "hw/xen/xen-legacy-backend.h" | ||
362 | #include "hw/xen/xen_pt.h" | ||
363 | #include "chardev/char.h" | ||
364 | -#include "sysemu/accel.h" | ||
365 | +#include "qemu/accel.h" | ||
366 | #include "sysemu/cpus.h" | ||
367 | #include "sysemu/xen.h" | ||
368 | #include "sysemu/runstate.h" | ||
369 | diff --git a/bsd-user/main.c b/bsd-user/main.c | ||
370 | index XXXXXXX..XXXXXXX 100644 | ||
371 | --- a/bsd-user/main.c | ||
372 | +++ b/bsd-user/main.c | ||
373 | @@ -XXX,XX +XXX,XX @@ | ||
374 | #include "qemu/osdep.h" | ||
375 | #include "qemu-common.h" | ||
376 | #include "qemu/units.h" | ||
377 | +#include "qemu/accel.h" | ||
378 | #include "sysemu/tcg.h" | ||
379 | #include "qemu-version.h" | ||
380 | #include <machine/trap.h> | ||
381 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv) | ||
382 | } | ||
383 | |||
384 | /* init tcg before creating CPUs and to get qemu_host_page_size */ | ||
385 | - tcg_exec_init(0, false); | ||
386 | + { | ||
387 | + AccelClass *ac = ACCEL_GET_CLASS(current_accel()); | ||
388 | |||
389 | + ac->init_machine(NULL); | ||
390 | + } | ||
391 | cpu_type = parse_cpu_option(cpu_model); | ||
392 | cpu = cpu_create(cpu_type); | ||
393 | env = cpu->env_ptr; | ||
394 | diff --git a/linux-user/main.c b/linux-user/main.c | ||
395 | index XXXXXXX..XXXXXXX 100644 | ||
396 | --- a/linux-user/main.c | ||
397 | +++ b/linux-user/main.c | ||
398 | @@ -XXX,XX +XXX,XX @@ | ||
399 | #include "qemu/osdep.h" | ||
400 | #include "qemu-common.h" | ||
401 | #include "qemu/units.h" | ||
402 | +#include "qemu/accel.h" | ||
403 | #include "sysemu/tcg.h" | ||
404 | #include "qemu-version.h" | ||
405 | #include <sys/syscall.h> | ||
406 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv, char **envp) | ||
407 | cpu_type = parse_cpu_option(cpu_model); | ||
408 | |||
409 | /* init tcg before creating CPUs and to get qemu_host_page_size */ | ||
410 | - tcg_exec_init(0, false); | ||
411 | + { | ||
412 | + AccelClass *ac = ACCEL_GET_CLASS(current_accel()); | ||
413 | |||
414 | + ac->init_machine(NULL); | ||
415 | + } | ||
416 | cpu = cpu_create(cpu_type); | ||
417 | env = cpu->env_ptr; | ||
418 | cpu_reset(cpu); | ||
419 | diff --git a/softmmu/memory.c b/softmmu/memory.c | ||
420 | index XXXXXXX..XXXXXXX 100644 | ||
421 | --- a/softmmu/memory.c | ||
422 | +++ b/softmmu/memory.c | ||
423 | @@ -XXX,XX +XXX,XX @@ | ||
424 | #include "sysemu/kvm.h" | ||
425 | #include "sysemu/runstate.h" | ||
426 | #include "sysemu/tcg.h" | ||
427 | -#include "sysemu/accel.h" | ||
428 | +#include "qemu/accel.h" | ||
429 | #include "hw/boards.h" | ||
430 | #include "migration/vmstate.h" | ||
431 | |||
432 | diff --git a/softmmu/qtest.c b/softmmu/qtest.c | ||
433 | index XXXXXXX..XXXXXXX 100644 | ||
434 | --- a/softmmu/qtest.c | ||
435 | +++ b/softmmu/qtest.c | ||
436 | @@ -XXX,XX +XXX,XX @@ | ||
437 | #include "exec/ioport.h" | ||
438 | #include "exec/memory.h" | ||
439 | #include "hw/irq.h" | ||
440 | -#include "sysemu/accel.h" | ||
441 | +#include "qemu/accel.h" | ||
442 | #include "sysemu/cpu-timers.h" | ||
443 | #include "qemu/config-file.h" | ||
444 | #include "qemu/option.h" | ||
445 | diff --git a/softmmu/vl.c b/softmmu/vl.c | ||
446 | index XXXXXXX..XXXXXXX 100644 | ||
447 | --- a/softmmu/vl.c | ||
448 | +++ b/softmmu/vl.c | ||
449 | @@ -XXX,XX +XXX,XX @@ | ||
450 | |||
451 | #include "qemu/error-report.h" | ||
452 | #include "qemu/sockets.h" | ||
453 | -#include "sysemu/accel.h" | ||
454 | +#include "qemu/accel.h" | ||
455 | #include "hw/usb.h" | ||
456 | #include "hw/isa/isa.h" | ||
457 | #include "hw/scsi/scsi.h" | ||
458 | diff --git a/target/i386/hax/hax-all.c b/target/i386/hax/hax-all.c | ||
459 | index XXXXXXX..XXXXXXX 100644 | ||
460 | --- a/target/i386/hax/hax-all.c | ||
461 | +++ b/target/i386/hax/hax-all.c | ||
462 | @@ -XXX,XX +XXX,XX @@ | ||
463 | #include "exec/address-spaces.h" | ||
464 | |||
465 | #include "qemu-common.h" | ||
466 | -#include "sysemu/accel.h" | ||
467 | +#include "qemu/accel.h" | ||
468 | #include "sysemu/reset.h" | ||
469 | #include "sysemu/runstate.h" | ||
470 | #include "hw/boards.h" | ||
471 | diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c | ||
472 | index XXXXXXX..XXXXXXX 100644 | ||
473 | --- a/target/i386/hvf/hvf.c | ||
474 | +++ b/target/i386/hvf/hvf.c | ||
475 | @@ -XXX,XX +XXX,XX @@ | ||
476 | #include "exec/address-spaces.h" | ||
477 | #include "hw/i386/apic_internal.h" | ||
478 | #include "qemu/main-loop.h" | ||
479 | -#include "sysemu/accel.h" | ||
480 | +#include "qemu/accel.h" | ||
481 | #include "target/i386/cpu.h" | ||
482 | |||
483 | #include "hvf-cpus.h" | ||
484 | diff --git a/target/i386/hvf/x86_task.c b/target/i386/hvf/x86_task.c | ||
485 | index XXXXXXX..XXXXXXX 100644 | ||
486 | --- a/target/i386/hvf/x86_task.c | ||
487 | +++ b/target/i386/hvf/x86_task.c | ||
488 | @@ -XXX,XX +XXX,XX @@ | ||
489 | |||
490 | #include "hw/i386/apic_internal.h" | ||
491 | #include "qemu/main-loop.h" | ||
492 | -#include "sysemu/accel.h" | ||
493 | +#include "qemu/accel.h" | ||
494 | #include "target/i386/cpu.h" | ||
495 | |||
496 | // TODO: taskswitch handling | ||
497 | diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c | ||
498 | index XXXXXXX..XXXXXXX 100644 | ||
499 | --- a/target/i386/whpx/whpx-all.c | ||
500 | +++ b/target/i386/whpx/whpx-all.c | ||
501 | @@ -XXX,XX +XXX,XX @@ | ||
502 | #include "exec/address-spaces.h" | ||
503 | #include "exec/ioport.h" | ||
504 | #include "qemu-common.h" | ||
505 | -#include "sysemu/accel.h" | ||
506 | +#include "qemu/accel.h" | ||
507 | #include "sysemu/whpx.h" | ||
508 | #include "sysemu/cpus.h" | ||
509 | #include "sysemu/runstate.h" | ||
510 | diff --git a/MAINTAINERS b/MAINTAINERS | ||
511 | index XXXXXXX..XXXXXXX 100644 | ||
512 | --- a/MAINTAINERS | ||
513 | +++ b/MAINTAINERS | ||
514 | @@ -XXX,XX +XXX,XX @@ Overall | ||
515 | M: Richard Henderson <richard.henderson@linaro.org> | ||
516 | R: Paolo Bonzini <pbonzini@redhat.com> | ||
517 | S: Maintained | ||
518 | -F: include/sysemu/accel.h | ||
519 | +F: include/qemu/accel.h | ||
520 | F: accel/accel.c | ||
521 | F: accel/Makefile.objs | ||
522 | F: accel/stubs/Makefile.objs | ||
523 | diff --git a/accel/meson.build b/accel/meson.build | ||
524 | index XXXXXXX..XXXXXXX 100644 | ||
525 | --- a/accel/meson.build | ||
526 | +++ b/accel/meson.build | ||
527 | @@ -XXX,XX +XXX,XX @@ | ||
528 | -softmmu_ss.add(files('accel.c')) | ||
529 | +specific_ss.add(files('accel-common.c')) | ||
530 | +softmmu_ss.add(files('accel-softmmu.c')) | ||
531 | +user_ss.add(files('accel-user.c')) | ||
532 | |||
533 | subdir('qtest') | ||
534 | subdir('kvm') | ||
535 | diff --git a/accel/tcg/meson.build b/accel/tcg/meson.build | ||
536 | index XXXXXXX..XXXXXXX 100644 | ||
537 | --- a/accel/tcg/meson.build | ||
538 | +++ b/accel/tcg/meson.build | ||
539 | @@ -XXX,XX +XXX,XX @@ | ||
540 | tcg_ss = ss.source_set() | ||
541 | tcg_ss.add(files( | ||
542 | + 'tcg-all.c', | ||
543 | 'cpu-exec-common.c', | ||
544 | 'cpu-exec.c', | ||
545 | 'tcg-runtime-gvec.c', | ||
546 | @@ -XXX,XX +XXX,XX @@ tcg_ss.add(when: 'CONFIG_PLUGIN', if_true: [files('plugin-gen.c'), libdl]) | ||
547 | specific_ss.add_all(when: 'CONFIG_TCG', if_true: tcg_ss) | ||
548 | |||
549 | specific_ss.add(when: ['CONFIG_SOFTMMU', 'CONFIG_TCG'], if_true: files( | ||
550 | - 'tcg-all.c', | ||
551 | 'cputlb.c', | ||
552 | 'tcg-cpus.c', | ||
553 | 'tcg-cpus-mttcg.c', | ||
554 | -- | 228 | -- |
555 | 2.25.1 | 229 | 2.25.1 |
556 | 230 | ||
557 | 231 | diff view generated by jsdifflib |
1 | Note that we had two functions of the same name: a 32-bit version | 1 | Prepare for tracking different masks by renaming this one. |
---|---|---|---|
2 | which took two register numbers and a 64-bit version which was a | ||
3 | no-op wrapper for tcg_write_reg. After this, we are left with | ||
4 | only the 32-bit version. | ||
5 | 2 | ||
6 | Tested-by: Alex Bennée <alex.bennee@linaro.org> | ||
7 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 3 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> |
4 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | ||
5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
9 | --- | 7 | --- |
10 | tcg/tci.c | 60 +++++++++++++++++++++++++------------------------------ | 8 | tcg/optimize.c | 142 +++++++++++++++++++++++++------------------------ |
11 | 1 file changed, 27 insertions(+), 33 deletions(-) | 9 | 1 file changed, 72 insertions(+), 70 deletions(-) |
12 | 10 | ||
13 | diff --git a/tcg/tci.c b/tcg/tci.c | 11 | diff --git a/tcg/optimize.c b/tcg/optimize.c |
14 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/tcg/tci.c | 13 | --- a/tcg/optimize.c |
16 | +++ b/tcg/tci.c | 14 | +++ b/tcg/optimize.c |
17 | @@ -XXX,XX +XXX,XX @@ static void tci_write_reg64(tcg_target_ulong *regs, uint32_t high_index, | 15 | @@ -XXX,XX +XXX,XX @@ typedef struct TempOptInfo { |
18 | tci_write_reg(regs, low_index, value); | 16 | TCGTemp *prev_copy; |
19 | tci_write_reg(regs, high_index, value >> 32); | 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; | ||
20 | } | 30 | } |
21 | -#elif TCG_TARGET_REG_BITS == 64 | 31 | |
22 | -static void | 32 | static void reset_temp(TCGArg arg) |
23 | -tci_write_reg64(tcg_target_ulong *regs, TCGReg index, uint64_t value) | 33 | @@ -XXX,XX +XXX,XX @@ static void init_ts_info(TCGTempSet *temps_used, TCGTemp *ts) |
24 | -{ | 34 | if (ts->kind == TEMP_CONST) { |
25 | - tci_write_reg(regs, index, value); | 35 | ti->is_const = true; |
26 | -} | 36 | ti->val = ts->val; |
27 | #endif | 37 | - ti->mask = ts->val; |
28 | 38 | + ti->z_mask = ts->val; | |
29 | #if TCG_TARGET_REG_BITS == 32 | 39 | if (TCG_TARGET_REG_BITS > 32 && ts->type == TCG_TYPE_I32) { |
30 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 40 | /* High bits of a 32-bit quantity are garbage. */ |
31 | t1 = tci_read_r64(regs, &tb_ptr); | 41 | - ti->mask |= ~0xffffffffull; |
32 | t2 = tci_read_ri64(regs, &tb_ptr); | 42 | + ti->z_mask |= ~0xffffffffull; |
33 | condition = *tb_ptr++; | 43 | } |
34 | - tci_write_reg64(regs, t0, tci_compare64(t1, t2, condition)); | 44 | } else { |
35 | + tci_write_reg(regs, t0, tci_compare64(t1, t2, condition)); | 45 | ti->is_const = false; |
36 | break; | 46 | - ti->mask = -1; |
37 | #endif | 47 | + ti->z_mask = -1; |
38 | case INDEX_op_mov_i32: | 48 | } |
39 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 49 | } |
40 | case INDEX_op_mov_i64: | 50 | |
41 | t0 = *tb_ptr++; | 51 | @@ -XXX,XX +XXX,XX @@ static void tcg_opt_gen_mov(TCGContext *s, TCGOp *op, TCGArg dst, TCGArg src) |
42 | t1 = tci_read_r64(regs, &tb_ptr); | 52 | const TCGOpDef *def; |
43 | - tci_write_reg64(regs, t0, t1); | 53 | TempOptInfo *di; |
44 | + tci_write_reg(regs, t0, t1); | 54 | TempOptInfo *si; |
45 | break; | 55 | - uint64_t mask; |
46 | case INDEX_op_tci_movi_i64: | 56 | + uint64_t z_mask; |
47 | t0 = *tb_ptr++; | 57 | TCGOpcode new_op; |
48 | t1 = tci_read_i64(&tb_ptr); | 58 | |
49 | - tci_write_reg64(regs, t0, t1); | 59 | if (ts_are_copies(dst_ts, src_ts)) { |
50 | + tci_write_reg(regs, t0, t1); | 60 | @@ -XXX,XX +XXX,XX @@ static void tcg_opt_gen_mov(TCGContext *s, TCGOp *op, TCGArg dst, TCGArg src) |
51 | break; | 61 | op->args[0] = dst; |
52 | 62 | op->args[1] = src; | |
53 | /* Load/store operations (64 bit). */ | 63 | |
54 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 64 | - mask = si->mask; |
55 | t0 = *tb_ptr++; | 65 | + z_mask = si->z_mask; |
56 | t1 = tci_read_r(regs, &tb_ptr); | 66 | if (TCG_TARGET_REG_BITS > 32 && new_op == INDEX_op_mov_i32) { |
57 | t2 = tci_read_s32(&tb_ptr); | 67 | /* High bits of the destination are now garbage. */ |
58 | - tci_write_reg64(regs, t0, *(uint64_t *)(t1 + t2)); | 68 | - mask |= ~0xffffffffull; |
59 | + tci_write_reg(regs, t0, *(uint64_t *)(t1 + t2)); | 69 | + z_mask |= ~0xffffffffull; |
60 | break; | 70 | } |
61 | case INDEX_op_st8_i64: | 71 | - di->mask = mask; |
62 | t0 = tci_read_r8(regs, &tb_ptr); | 72 | + di->z_mask = z_mask; |
63 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 73 | |
64 | t0 = *tb_ptr++; | 74 | if (src_ts->type == dst_ts->type) { |
65 | t1 = tci_read_ri64(regs, &tb_ptr); | 75 | TempOptInfo *ni = ts_info(si->next_copy); |
66 | t2 = tci_read_ri64(regs, &tb_ptr); | 76 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) |
67 | - tci_write_reg64(regs, t0, t1 + t2); | 77 | } |
68 | + tci_write_reg(regs, t0, t1 + t2); | 78 | |
69 | break; | 79 | QTAILQ_FOREACH_SAFE(op, &s->ops, link, op_next) { |
70 | case INDEX_op_sub_i64: | 80 | - uint64_t mask, partmask, affected, tmp; |
71 | t0 = *tb_ptr++; | 81 | + uint64_t z_mask, partmask, affected, tmp; |
72 | t1 = tci_read_ri64(regs, &tb_ptr); | 82 | int nb_oargs, nb_iargs; |
73 | t2 = tci_read_ri64(regs, &tb_ptr); | 83 | TCGOpcode opc = op->opc; |
74 | - tci_write_reg64(regs, t0, t1 - t2); | 84 | const TCGOpDef *def = &tcg_op_defs[opc]; |
75 | + tci_write_reg(regs, t0, t1 - t2); | 85 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) |
76 | break; | 86 | |
77 | case INDEX_op_mul_i64: | 87 | /* Simplify using known-zero bits. Currently only ops with a single |
78 | t0 = *tb_ptr++; | 88 | output argument is supported. */ |
79 | t1 = tci_read_ri64(regs, &tb_ptr); | 89 | - mask = -1; |
80 | t2 = tci_read_ri64(regs, &tb_ptr); | 90 | + z_mask = -1; |
81 | - tci_write_reg64(regs, t0, t1 * t2); | 91 | affected = -1; |
82 | + tci_write_reg(regs, t0, t1 * t2); | 92 | switch (opc) { |
83 | break; | 93 | CASE_OP_32_64(ext8s): |
84 | #if TCG_TARGET_HAS_div_i64 | 94 | - if ((arg_info(op->args[1])->mask & 0x80) != 0) { |
85 | case INDEX_op_div_i64: | 95 | + if ((arg_info(op->args[1])->z_mask & 0x80) != 0) { |
86 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 96 | break; |
87 | t0 = *tb_ptr++; | 97 | } |
88 | t1 = tci_read_ri64(regs, &tb_ptr); | 98 | QEMU_FALLTHROUGH; |
89 | t2 = tci_read_ri64(regs, &tb_ptr); | 99 | CASE_OP_32_64(ext8u): |
90 | - tci_write_reg64(regs, t0, t1 & t2); | 100 | - mask = 0xff; |
91 | + tci_write_reg(regs, t0, t1 & t2); | 101 | + z_mask = 0xff; |
92 | break; | 102 | goto and_const; |
93 | case INDEX_op_or_i64: | 103 | CASE_OP_32_64(ext16s): |
94 | t0 = *tb_ptr++; | 104 | - if ((arg_info(op->args[1])->mask & 0x8000) != 0) { |
95 | t1 = tci_read_ri64(regs, &tb_ptr); | 105 | + if ((arg_info(op->args[1])->z_mask & 0x8000) != 0) { |
96 | t2 = tci_read_ri64(regs, &tb_ptr); | 106 | break; |
97 | - tci_write_reg64(regs, t0, t1 | t2); | 107 | } |
98 | + tci_write_reg(regs, t0, t1 | t2); | 108 | QEMU_FALLTHROUGH; |
99 | break; | 109 | CASE_OP_32_64(ext16u): |
100 | case INDEX_op_xor_i64: | 110 | - mask = 0xffff; |
101 | t0 = *tb_ptr++; | 111 | + z_mask = 0xffff; |
102 | t1 = tci_read_ri64(regs, &tb_ptr); | 112 | goto and_const; |
103 | t2 = tci_read_ri64(regs, &tb_ptr); | 113 | case INDEX_op_ext32s_i64: |
104 | - tci_write_reg64(regs, t0, t1 ^ t2); | 114 | - if ((arg_info(op->args[1])->mask & 0x80000000) != 0) { |
105 | + tci_write_reg(regs, t0, t1 ^ t2); | 115 | + if ((arg_info(op->args[1])->z_mask & 0x80000000) != 0) { |
106 | break; | 116 | break; |
107 | 117 | } | |
108 | /* Shift/rotate operations (64 bit). */ | 118 | QEMU_FALLTHROUGH; |
109 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 119 | case INDEX_op_ext32u_i64: |
110 | t0 = *tb_ptr++; | 120 | - mask = 0xffffffffU; |
111 | t1 = tci_read_ri64(regs, &tb_ptr); | 121 | + z_mask = 0xffffffffU; |
112 | t2 = tci_read_ri64(regs, &tb_ptr); | 122 | goto and_const; |
113 | - tci_write_reg64(regs, t0, t1 << (t2 & 63)); | 123 | |
114 | + tci_write_reg(regs, t0, t1 << (t2 & 63)); | 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 | } | ||
115 | break; | 182 | break; |
116 | case INDEX_op_shr_i64: | 183 | case INDEX_op_shr_i64: |
117 | t0 = *tb_ptr++; | 184 | if (arg_is_const(op->args[2])) { |
118 | t1 = tci_read_ri64(regs, &tb_ptr); | 185 | tmp = arg_info(op->args[2])->val & 63; |
119 | t2 = tci_read_ri64(regs, &tb_ptr); | 186 | - mask = (uint64_t)arg_info(op->args[1])->mask >> tmp; |
120 | - tci_write_reg64(regs, t0, t1 >> (t2 & 63)); | 187 | + z_mask = (uint64_t)arg_info(op->args[1])->z_mask >> tmp; |
121 | + tci_write_reg(regs, t0, t1 >> (t2 & 63)); | 188 | } |
122 | break; | 189 | break; |
123 | case INDEX_op_sar_i64: | 190 | |
124 | t0 = *tb_ptr++; | 191 | case INDEX_op_extrl_i64_i32: |
125 | t1 = tci_read_ri64(regs, &tb_ptr); | 192 | - mask = (uint32_t)arg_info(op->args[1])->mask; |
126 | t2 = tci_read_ri64(regs, &tb_ptr); | 193 | + z_mask = (uint32_t)arg_info(op->args[1])->z_mask; |
127 | - tci_write_reg64(regs, t0, ((int64_t)t1 >> (t2 & 63))); | 194 | break; |
128 | + tci_write_reg(regs, t0, ((int64_t)t1 >> (t2 & 63))); | 195 | case INDEX_op_extrh_i64_i32: |
129 | break; | 196 | - mask = (uint64_t)arg_info(op->args[1])->mask >> 32; |
130 | #if TCG_TARGET_HAS_rot_i64 | 197 | + z_mask = (uint64_t)arg_info(op->args[1])->z_mask >> 32; |
131 | case INDEX_op_rotl_i64: | 198 | break; |
132 | t0 = *tb_ptr++; | 199 | |
133 | t1 = tci_read_ri64(regs, &tb_ptr); | 200 | CASE_OP_32_64(shl): |
134 | t2 = tci_read_ri64(regs, &tb_ptr); | 201 | if (arg_is_const(op->args[2])) { |
135 | - tci_write_reg64(regs, t0, rol64(t1, t2 & 63)); | 202 | tmp = arg_info(op->args[2])->val & (TCG_TARGET_REG_BITS - 1); |
136 | + tci_write_reg(regs, t0, rol64(t1, t2 & 63)); | 203 | - mask = arg_info(op->args[1])->mask << tmp; |
137 | break; | 204 | + z_mask = arg_info(op->args[1])->z_mask << tmp; |
138 | case INDEX_op_rotr_i64: | 205 | } |
139 | t0 = *tb_ptr++; | 206 | break; |
140 | t1 = tci_read_ri64(regs, &tb_ptr); | 207 | |
141 | t2 = tci_read_ri64(regs, &tb_ptr); | 208 | CASE_OP_32_64(neg): |
142 | - tci_write_reg64(regs, t0, ror64(t1, t2 & 63)); | 209 | /* Set to 1 all bits to the left of the rightmost. */ |
143 | + tci_write_reg(regs, t0, ror64(t1, t2 & 63)); | 210 | - mask = -(arg_info(op->args[1])->mask |
144 | break; | 211 | - & -arg_info(op->args[1])->mask); |
145 | #endif | 212 | + z_mask = -(arg_info(op->args[1])->z_mask |
146 | #if TCG_TARGET_HAS_deposit_i64 | 213 | + & -arg_info(op->args[1])->z_mask); |
147 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 214 | break; |
148 | tmp16 = *tb_ptr++; | 215 | |
149 | tmp8 = *tb_ptr++; | 216 | CASE_OP_32_64(deposit): |
150 | tmp64 = (((1ULL << tmp8) - 1) << tmp16); | 217 | - mask = deposit64(arg_info(op->args[1])->mask, |
151 | - tci_write_reg64(regs, t0, (t1 & ~tmp64) | ((t2 << tmp16) & tmp64)); | 218 | - op->args[3], op->args[4], |
152 | + tci_write_reg(regs, t0, (t1 & ~tmp64) | ((t2 << tmp16) & tmp64)); | 219 | - arg_info(op->args[2])->mask); |
153 | break; | 220 | + z_mask = deposit64(arg_info(op->args[1])->z_mask, |
154 | #endif | 221 | + op->args[3], op->args[4], |
155 | case INDEX_op_brcond_i64: | 222 | + arg_info(op->args[2])->z_mask); |
156 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 223 | break; |
157 | case INDEX_op_ext8u_i64: | 224 | |
158 | t0 = *tb_ptr++; | 225 | CASE_OP_32_64(extract): |
159 | t1 = tci_read_r8(regs, &tb_ptr); | 226 | - mask = extract64(arg_info(op->args[1])->mask, |
160 | - tci_write_reg64(regs, t0, t1); | 227 | - op->args[2], op->args[3]); |
161 | + tci_write_reg(regs, t0, t1); | 228 | + z_mask = extract64(arg_info(op->args[1])->z_mask, |
162 | break; | 229 | + op->args[2], op->args[3]); |
163 | #endif | 230 | if (op->args[2] == 0) { |
164 | #if TCG_TARGET_HAS_ext8s_i64 | 231 | - affected = arg_info(op->args[1])->mask & ~mask; |
165 | case INDEX_op_ext8s_i64: | 232 | + affected = arg_info(op->args[1])->z_mask & ~z_mask; |
166 | t0 = *tb_ptr++; | 233 | } |
167 | t1 = tci_read_r8s(regs, &tb_ptr); | 234 | break; |
168 | - tci_write_reg64(regs, t0, t1); | 235 | CASE_OP_32_64(sextract): |
169 | + tci_write_reg(regs, t0, t1); | 236 | - mask = sextract64(arg_info(op->args[1])->mask, |
170 | break; | 237 | - op->args[2], op->args[3]); |
171 | #endif | 238 | - if (op->args[2] == 0 && (tcg_target_long)mask >= 0) { |
172 | #if TCG_TARGET_HAS_ext16s_i64 | 239 | - affected = arg_info(op->args[1])->mask & ~mask; |
173 | case INDEX_op_ext16s_i64: | 240 | + z_mask = sextract64(arg_info(op->args[1])->z_mask, |
174 | t0 = *tb_ptr++; | 241 | + op->args[2], op->args[3]); |
175 | t1 = tci_read_r16s(regs, &tb_ptr); | 242 | + if (op->args[2] == 0 && (tcg_target_long)z_mask >= 0) { |
176 | - tci_write_reg64(regs, t0, t1); | 243 | + affected = arg_info(op->args[1])->z_mask & ~z_mask; |
177 | + tci_write_reg(regs, t0, t1); | 244 | } |
178 | break; | 245 | break; |
179 | #endif | 246 | |
180 | #if TCG_TARGET_HAS_ext16u_i64 | 247 | CASE_OP_32_64(or): |
181 | case INDEX_op_ext16u_i64: | 248 | CASE_OP_32_64(xor): |
182 | t0 = *tb_ptr++; | 249 | - mask = arg_info(op->args[1])->mask | arg_info(op->args[2])->mask; |
183 | t1 = tci_read_r16(regs, &tb_ptr); | 250 | + z_mask = arg_info(op->args[1])->z_mask |
184 | - tci_write_reg64(regs, t0, t1); | 251 | + | arg_info(op->args[2])->z_mask; |
185 | + tci_write_reg(regs, t0, t1); | 252 | break; |
186 | break; | 253 | |
187 | #endif | 254 | case INDEX_op_clz_i32: |
188 | #if TCG_TARGET_HAS_ext32s_i64 | 255 | case INDEX_op_ctz_i32: |
189 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 256 | - mask = arg_info(op->args[2])->mask | 31; |
190 | case INDEX_op_ext_i32_i64: | 257 | + z_mask = arg_info(op->args[2])->z_mask | 31; |
191 | t0 = *tb_ptr++; | 258 | break; |
192 | t1 = tci_read_r32s(regs, &tb_ptr); | 259 | |
193 | - tci_write_reg64(regs, t0, t1); | 260 | case INDEX_op_clz_i64: |
194 | + tci_write_reg(regs, t0, t1); | 261 | case INDEX_op_ctz_i64: |
195 | break; | 262 | - mask = arg_info(op->args[2])->mask | 63; |
196 | #if TCG_TARGET_HAS_ext32u_i64 | 263 | + z_mask = arg_info(op->args[2])->z_mask | 63; |
197 | case INDEX_op_ext32u_i64: | 264 | break; |
198 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 265 | |
199 | case INDEX_op_extu_i32_i64: | 266 | case INDEX_op_ctpop_i32: |
200 | t0 = *tb_ptr++; | 267 | - mask = 32 | 31; |
201 | t1 = tci_read_r32(regs, &tb_ptr); | 268 | + z_mask = 32 | 31; |
202 | - tci_write_reg64(regs, t0, t1); | 269 | break; |
203 | + tci_write_reg(regs, t0, t1); | 270 | case INDEX_op_ctpop_i64: |
204 | break; | 271 | - mask = 64 | 63; |
205 | #if TCG_TARGET_HAS_bswap16_i64 | 272 | + z_mask = 64 | 63; |
206 | case INDEX_op_bswap16_i64: | 273 | break; |
207 | t0 = *tb_ptr++; | 274 | |
208 | t1 = tci_read_r16(regs, &tb_ptr); | 275 | CASE_OP_32_64(setcond): |
209 | - tci_write_reg64(regs, t0, bswap16(t1)); | 276 | case INDEX_op_setcond2_i32: |
210 | + tci_write_reg(regs, t0, bswap16(t1)); | 277 | - mask = 1; |
211 | break; | 278 | + z_mask = 1; |
212 | #endif | 279 | break; |
213 | #if TCG_TARGET_HAS_bswap32_i64 | 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 | |||
214 | case INDEX_op_bswap32_i64: | 334 | case INDEX_op_bswap32_i64: |
215 | t0 = *tb_ptr++; | 335 | - mask = arg_info(op->args[1])->mask; |
216 | t1 = tci_read_r32(regs, &tb_ptr); | 336 | - if (mask <= 0xffffffffu) { |
217 | - tci_write_reg64(regs, t0, bswap32(t1)); | 337 | + z_mask = arg_info(op->args[1])->z_mask; |
218 | + tci_write_reg(regs, t0, bswap32(t1)); | 338 | + if (z_mask <= 0xffffffffu) { |
219 | break; | 339 | op->args[2] |= TCG_BSWAP_IZ; |
220 | #endif | 340 | } |
221 | #if TCG_TARGET_HAS_bswap64_i64 | 341 | - mask = bswap32(mask); |
222 | case INDEX_op_bswap64_i64: | 342 | + z_mask = bswap32(z_mask); |
223 | t0 = *tb_ptr++; | 343 | switch (op->args[2] & (TCG_BSWAP_OZ | TCG_BSWAP_OS)) { |
224 | t1 = tci_read_r64(regs, &tb_ptr); | 344 | case TCG_BSWAP_OZ: |
225 | - tci_write_reg64(regs, t0, bswap64(t1)); | 345 | break; |
226 | + tci_write_reg(regs, t0, bswap64(t1)); | 346 | case TCG_BSWAP_OS: |
227 | break; | 347 | - mask = (int32_t)mask; |
228 | #endif | 348 | + z_mask = (int32_t)z_mask; |
229 | #if TCG_TARGET_HAS_not_i64 | 349 | break; |
230 | case INDEX_op_not_i64: | 350 | default: /* undefined high bits */ |
231 | t0 = *tb_ptr++; | 351 | - mask |= MAKE_64BIT_MASK(32, 32); |
232 | t1 = tci_read_r64(regs, &tb_ptr); | 352 | + z_mask |= MAKE_64BIT_MASK(32, 32); |
233 | - tci_write_reg64(regs, t0, ~t1); | 353 | break; |
234 | + tci_write_reg(regs, t0, ~t1); | 354 | } |
235 | break; | 355 | break; |
236 | #endif | 356 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) |
237 | #if TCG_TARGET_HAS_neg_i64 | 357 | /* 32-bit ops generate 32-bit results. For the result is zero test |
238 | case INDEX_op_neg_i64: | 358 | below, we can ignore high bits, but for further optimizations we |
239 | t0 = *tb_ptr++; | 359 | need to record that the high bits contain garbage. */ |
240 | t1 = tci_read_r64(regs, &tb_ptr); | 360 | - partmask = mask; |
241 | - tci_write_reg64(regs, t0, -t1); | 361 | + partmask = z_mask; |
242 | + tci_write_reg(regs, t0, -t1); | 362 | if (!(def->flags & TCG_OPF_64BIT)) { |
243 | break; | 363 | - mask |= ~(tcg_target_ulong)0xffffffffu; |
244 | #endif | 364 | + z_mask |= ~(tcg_target_ulong)0xffffffffu; |
245 | #endif /* TCG_TARGET_REG_BITS == 64 */ | 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 | } | ||
246 | -- | 404 | -- |
247 | 2.25.1 | 405 | 2.25.1 |
248 | 406 | ||
249 | 407 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Provide what will become a larger context for splitting | ||
2 | the very large tcg_optimize function. | ||
1 | 3 | ||
4 | Reviewed-by: Alex Bennée <alex.bennee@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> | ||
8 | --- | ||
9 | tcg/optimize.c | 77 ++++++++++++++++++++++++++------------------------ | ||
10 | 1 file changed, 40 insertions(+), 37 deletions(-) | ||
11 | |||
12 | diff --git a/tcg/optimize.c b/tcg/optimize.c | ||
13 | index XXXXXXX..XXXXXXX 100644 | ||
14 | --- a/tcg/optimize.c | ||
15 | +++ b/tcg/optimize.c | ||
16 | @@ -XXX,XX +XXX,XX @@ typedef struct TempOptInfo { | ||
17 | uint64_t z_mask; /* mask bit is 0 if and only if value bit is 0 */ | ||
18 | } TempOptInfo; | ||
19 | |||
20 | +typedef struct OptContext { | ||
21 | + TCGTempSet temps_used; | ||
22 | +} OptContext; | ||
23 | + | ||
24 | static inline TempOptInfo *ts_info(TCGTemp *ts) | ||
25 | { | ||
26 | return ts->state_ptr; | ||
27 | @@ -XXX,XX +XXX,XX @@ static void reset_temp(TCGArg arg) | ||
28 | } | ||
29 | |||
30 | /* Initialize and activate a temporary. */ | ||
31 | -static void init_ts_info(TCGTempSet *temps_used, TCGTemp *ts) | ||
32 | +static void init_ts_info(OptContext *ctx, TCGTemp *ts) | ||
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; | ||
40 | } | ||
41 | - set_bit(idx, temps_used->l); | ||
42 | + set_bit(idx, ctx->temps_used.l); | ||
43 | |||
44 | ti = ts->state_ptr; | ||
45 | if (ti == NULL) { | ||
46 | @@ -XXX,XX +XXX,XX @@ static void init_ts_info(TCGTempSet *temps_used, TCGTemp *ts) | ||
47 | } | ||
48 | } | ||
49 | |||
50 | -static void init_arg_info(TCGTempSet *temps_used, TCGArg arg) | ||
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 | -- | ||
331 | 2.25.1 | ||
332 | |||
333 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Break the final cleanup clause out of the main switch | ||
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. | ||
1 | 5 | ||
6 | Reviewed-by: Alex Bennée <alex.bennee@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> | ||
10 | --- | ||
11 | tcg/optimize.c | 190 ++++++++++++++++++++++++------------------------- | ||
12 | 1 file changed, 94 insertions(+), 96 deletions(-) | ||
13 | |||
14 | diff --git a/tcg/optimize.c b/tcg/optimize.c | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/tcg/optimize.c | ||
17 | +++ b/tcg/optimize.c | ||
18 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
19 | switch (opc) { | ||
20 | CASE_OP_32_64_VEC(mov): | ||
21 | tcg_opt_gen_mov(s, op, op->args[0], op->args[1]); | ||
22 | - break; | ||
23 | + continue; | ||
24 | |||
25 | case INDEX_op_dup_vec: | ||
26 | if (arg_is_const(op->args[1])) { | ||
27 | tmp = arg_info(op->args[1])->val; | ||
28 | tmp = dup_const(TCGOP_VECE(op), tmp); | ||
29 | tcg_opt_gen_movi(s, &ctx, op, op->args[0], tmp); | ||
30 | - break; | ||
31 | + continue; | ||
32 | } | ||
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 | -- | ||
427 | 2.25.1 | ||
428 | |||
429 | diff view generated by jsdifflib |
1 | From: Eduardo Habkost <ehabkost@redhat.com> | 1 | Adjust the interface to take the OptContext parameter instead |
---|---|---|---|
2 | 2 | of TCGContext or both. | |
3 | Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> | 3 | |
4 | Signed-off-by: Claudio Fontana <cfontana@suse.de> | ||
5 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 4 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> |
6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 5 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> |
7 | Message-Id: <20210204163931.7358-8-cfontana@suse.de> | ||
8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
9 | --- | 7 | --- |
10 | include/hw/core/cpu.h | 4 ++-- | 8 | tcg/optimize.c | 67 +++++++++++++++++++++++++------------------------- |
11 | accel/tcg/cpu-exec.c | 4 ++-- | 9 | 1 file changed, 34 insertions(+), 33 deletions(-) |
12 | target/arm/cpu.c | 2 +- | 10 | |
13 | target/i386/tcg/tcg-cpu.c | 2 +- | 11 | diff --git a/tcg/optimize.c b/tcg/optimize.c |
14 | target/lm32/cpu.c | 2 +- | ||
15 | target/s390x/cpu.c | 2 +- | ||
16 | target/xtensa/cpu.c | 2 +- | ||
17 | 7 files changed, 9 insertions(+), 9 deletions(-) | ||
18 | |||
19 | diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h | ||
20 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/include/hw/core/cpu.h | 13 | --- a/tcg/optimize.c |
22 | +++ b/include/hw/core/cpu.h | 14 | +++ b/tcg/optimize.c |
23 | @@ -XXX,XX +XXX,XX @@ typedef struct TcgCpuOperations { | 15 | @@ -XXX,XX +XXX,XX @@ typedef struct TempOptInfo { |
24 | bool (*tlb_fill)(CPUState *cpu, vaddr address, int size, | 16 | } TempOptInfo; |
25 | MMUAccessType access_type, int mmu_idx, | 17 | |
26 | bool probe, uintptr_t retaddr); | 18 | typedef struct OptContext { |
27 | + /** @debug_excp_handler: Callback for handling debug exceptions */ | 19 | + TCGContext *tcg; |
28 | + void (*debug_excp_handler)(CPUState *cpu); | 20 | TCGTempSet temps_used; |
29 | 21 | } OptContext; | |
30 | } TcgCpuOperations; | 22 | |
31 | 23 | @@ -XXX,XX +XXX,XX @@ static bool args_are_copies(TCGArg arg1, TCGArg arg2) | |
32 | @@ -XXX,XX +XXX,XX @@ typedef struct TcgCpuOperations { | 24 | return ts_are_copies(arg_temp(arg1), arg_temp(arg2)); |
33 | * @gdb_write_register: Callback for letting GDB write a register. | 25 | } |
34 | * @debug_check_watchpoint: Callback: return true if the architectural | 26 | |
35 | * watchpoint whose address has matched should really fire. | 27 | -static void tcg_opt_gen_mov(TCGContext *s, TCGOp *op, TCGArg dst, TCGArg src) |
36 | - * @debug_excp_handler: Callback for handling debug exceptions. | 28 | +static void tcg_opt_gen_mov(OptContext *ctx, TCGOp *op, TCGArg dst, TCGArg src) |
37 | * @write_elf64_note: Callback for writing a CPU-specific ELF note to a | 29 | { |
38 | * 64-bit VM coredump. | 30 | TCGTemp *dst_ts = arg_temp(dst); |
39 | * @write_elf32_qemunote: Callback for writing a CPU- and QEMU-specific ELF | 31 | TCGTemp *src_ts = arg_temp(src); |
40 | @@ -XXX,XX +XXX,XX @@ struct CPUClass { | 32 | @@ -XXX,XX +XXX,XX @@ static void tcg_opt_gen_mov(TCGContext *s, TCGOp *op, TCGArg dst, TCGArg src) |
41 | int (*gdb_read_register)(CPUState *cpu, GByteArray *buf, int reg); | 33 | TCGOpcode new_op; |
42 | int (*gdb_write_register)(CPUState *cpu, uint8_t *buf, int reg); | 34 | |
43 | bool (*debug_check_watchpoint)(CPUState *cpu, CPUWatchpoint *wp); | 35 | if (ts_are_copies(dst_ts, src_ts)) { |
44 | - void (*debug_excp_handler)(CPUState *cpu); | 36 | - tcg_op_remove(s, op); |
45 | 37 | + tcg_op_remove(ctx->tcg, op); | |
46 | int (*write_elf64_note)(WriteCoreDumpFunction f, CPUState *cpu, | 38 | return; |
47 | int cpuid, void *opaque); | ||
48 | diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c | ||
49 | index XXXXXXX..XXXXXXX 100644 | ||
50 | --- a/accel/tcg/cpu-exec.c | ||
51 | +++ b/accel/tcg/cpu-exec.c | ||
52 | @@ -XXX,XX +XXX,XX @@ static inline void cpu_handle_debug_exception(CPUState *cpu) | ||
53 | } | ||
54 | } | 39 | } |
55 | 40 | ||
56 | - if (cc->debug_excp_handler) { | 41 | @@ -XXX,XX +XXX,XX @@ static void tcg_opt_gen_mov(TCGContext *s, TCGOp *op, TCGArg dst, TCGArg src) |
57 | - cc->debug_excp_handler(cpu); | ||
58 | + if (cc->tcg_ops.debug_excp_handler) { | ||
59 | + cc->tcg_ops.debug_excp_handler(cpu); | ||
60 | } | 42 | } |
61 | } | 43 | } |
62 | 44 | ||
63 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | 45 | -static void tcg_opt_gen_movi(TCGContext *s, OptContext *ctx, |
64 | index XXXXXXX..XXXXXXX 100644 | 46 | - TCGOp *op, TCGArg dst, uint64_t val) |
65 | --- a/target/arm/cpu.c | 47 | +static void tcg_opt_gen_movi(OptContext *ctx, TCGOp *op, |
66 | +++ b/target/arm/cpu.c | 48 | + TCGArg dst, uint64_t val) |
67 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_class_init(ObjectClass *oc, void *data) | 49 | { |
68 | cc->tcg_ops.cpu_exec_interrupt = arm_cpu_exec_interrupt; | 50 | const TCGOpDef *def = &tcg_op_defs[op->opc]; |
69 | cc->tcg_ops.synchronize_from_tb = arm_cpu_synchronize_from_tb; | 51 | TCGType type; |
70 | cc->tcg_ops.tlb_fill = arm_cpu_tlb_fill; | 52 | @@ -XXX,XX +XXX,XX @@ static void tcg_opt_gen_movi(TCGContext *s, OptContext *ctx, |
71 | - cc->debug_excp_handler = arm_debug_excp_handler; | 53 | /* Convert movi to mov with constant temp. */ |
72 | + cc->tcg_ops.debug_excp_handler = arm_debug_excp_handler; | 54 | tv = tcg_constant_internal(type, val); |
73 | cc->debug_check_watchpoint = arm_debug_check_watchpoint; | 55 | init_ts_info(ctx, tv); |
74 | cc->do_unaligned_access = arm_cpu_do_unaligned_access; | 56 | - tcg_opt_gen_mov(s, op, dst, temp_arg(tv)); |
75 | #if !defined(CONFIG_USER_ONLY) | 57 | + tcg_opt_gen_mov(ctx, op, dst, temp_arg(tv)); |
76 | diff --git a/target/i386/tcg/tcg-cpu.c b/target/i386/tcg/tcg-cpu.c | ||
77 | index XXXXXXX..XXXXXXX 100644 | ||
78 | --- a/target/i386/tcg/tcg-cpu.c | ||
79 | +++ b/target/i386/tcg/tcg-cpu.c | ||
80 | @@ -XXX,XX +XXX,XX @@ void tcg_cpu_common_class_init(CPUClass *cc) | ||
81 | cc->tcg_ops.initialize = tcg_x86_init; | ||
82 | cc->tcg_ops.tlb_fill = x86_cpu_tlb_fill; | ||
83 | #ifndef CONFIG_USER_ONLY | ||
84 | - cc->debug_excp_handler = breakpoint_handler; | ||
85 | + cc->tcg_ops.debug_excp_handler = breakpoint_handler; | ||
86 | #endif | ||
87 | } | 58 | } |
88 | diff --git a/target/lm32/cpu.c b/target/lm32/cpu.c | 59 | |
89 | index XXXXXXX..XXXXXXX 100644 | 60 | static uint64_t do_constant_folding_2(TCGOpcode op, uint64_t x, uint64_t y) |
90 | --- a/target/lm32/cpu.c | 61 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) |
91 | +++ b/target/lm32/cpu.c | 62 | { |
92 | @@ -XXX,XX +XXX,XX @@ static void lm32_cpu_class_init(ObjectClass *oc, void *data) | 63 | int nb_temps, nb_globals, i; |
93 | #endif | 64 | TCGOp *op, *op_next, *prev_mb = NULL; |
94 | cc->gdb_num_core_regs = 32 + 7; | 65 | - OptContext ctx = {}; |
95 | cc->gdb_stop_before_watchpoint = true; | 66 | + OptContext ctx = { .tcg = s }; |
96 | - cc->debug_excp_handler = lm32_debug_excp_handler; | 67 | |
97 | + cc->tcg_ops.debug_excp_handler = lm32_debug_excp_handler; | 68 | /* Array VALS has an element for each temp. |
98 | cc->disas_set_info = lm32_cpu_disas_set_info; | 69 | If this temp holds a constant then its value is kept in VALS' element. |
99 | cc->tcg_ops.initialize = lm32_translate_init; | 70 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) |
100 | } | 71 | CASE_OP_32_64(rotr): |
101 | diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c | 72 | if (arg_is_const(op->args[1]) |
102 | index XXXXXXX..XXXXXXX 100644 | 73 | && arg_info(op->args[1])->val == 0) { |
103 | --- a/target/s390x/cpu.c | 74 | - tcg_opt_gen_movi(s, &ctx, op, op->args[0], 0); |
104 | +++ b/target/s390x/cpu.c | 75 | + tcg_opt_gen_movi(&ctx, op, op->args[0], 0); |
105 | @@ -XXX,XX +XXX,XX @@ static void s390_cpu_class_init(ObjectClass *oc, void *data) | 76 | continue; |
106 | cc->write_elf64_note = s390_cpu_write_elf64_note; | 77 | } |
107 | #ifdef CONFIG_TCG | 78 | break; |
108 | cc->tcg_ops.cpu_exec_interrupt = s390_cpu_exec_interrupt; | 79 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) |
109 | - cc->debug_excp_handler = s390x_cpu_debug_excp_handler; | 80 | if (!arg_is_const(op->args[1]) |
110 | + cc->tcg_ops.debug_excp_handler = s390x_cpu_debug_excp_handler; | 81 | && arg_is_const(op->args[2]) |
111 | cc->do_unaligned_access = s390x_cpu_do_unaligned_access; | 82 | && arg_info(op->args[2])->val == 0) { |
112 | #endif | 83 | - tcg_opt_gen_mov(s, op, op->args[0], op->args[1]); |
113 | #endif | 84 | + tcg_opt_gen_mov(&ctx, op, op->args[0], op->args[1]); |
114 | diff --git a/target/xtensa/cpu.c b/target/xtensa/cpu.c | 85 | continue; |
115 | index XXXXXXX..XXXXXXX 100644 | 86 | } |
116 | --- a/target/xtensa/cpu.c | 87 | break; |
117 | +++ b/target/xtensa/cpu.c | 88 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) |
118 | @@ -XXX,XX +XXX,XX @@ static void xtensa_cpu_class_init(ObjectClass *oc, void *data) | 89 | if (!arg_is_const(op->args[1]) |
119 | cc->get_phys_page_debug = xtensa_cpu_get_phys_page_debug; | 90 | && arg_is_const(op->args[2]) |
120 | cc->do_transaction_failed = xtensa_cpu_do_transaction_failed; | 91 | && arg_info(op->args[2])->val == -1) { |
121 | #endif | 92 | - tcg_opt_gen_mov(s, op, op->args[0], op->args[1]); |
122 | - cc->debug_excp_handler = xtensa_breakpoint_handler; | 93 | + tcg_opt_gen_mov(&ctx, op, op->args[0], op->args[1]); |
123 | + cc->tcg_ops.debug_excp_handler = xtensa_breakpoint_handler; | 94 | continue; |
124 | cc->disas_set_info = xtensa_cpu_disas_set_info; | 95 | } |
125 | cc->tcg_ops.initialize = xtensa_translate_init; | 96 | break; |
126 | dc->vmsd = &vmstate_xtensa_cpu; | 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) | ||
127 | -- | 289 | -- |
128 | 2.25.1 | 290 | 2.25.1 |
129 | 291 | ||
130 | 292 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | This will expose the variable to subroutines that | ||
2 | will be broken out of tcg_optimize. | ||
1 | 3 | ||
4 | Reviewed-by: Alex Bennée <alex.bennee@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> | ||
8 | --- | ||
9 | tcg/optimize.c | 11 ++++++----- | ||
10 | 1 file changed, 6 insertions(+), 5 deletions(-) | ||
11 | |||
12 | diff --git a/tcg/optimize.c b/tcg/optimize.c | ||
13 | index XXXXXXX..XXXXXXX 100644 | ||
14 | --- a/tcg/optimize.c | ||
15 | +++ b/tcg/optimize.c | ||
16 | @@ -XXX,XX +XXX,XX @@ typedef struct TempOptInfo { | ||
17 | |||
18 | typedef struct OptContext { | ||
19 | TCGContext *tcg; | ||
20 | + TCGOp *prev_mb; | ||
21 | TCGTempSet temps_used; | ||
22 | } OptContext; | ||
23 | |||
24 | @@ -XXX,XX +XXX,XX @@ static bool swap_commutative2(TCGArg *p1, TCGArg *p2) | ||
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 | } | ||
63 | } | ||
64 | } | ||
65 | -- | ||
66 | 2.25.1 | ||
67 | |||
68 | diff view generated by jsdifflib |
1 | For a 64-bit TCI, the upper bits of a 32-bit operation are | 1 | There was no real reason for calls to have separate code here. |
---|---|---|---|
2 | undefined (much like a native ppc64 32-bit operation). It | 2 | Unify init for calls vs non-calls using the call path, which |
3 | simplifies everything if we don't force-extend the result. | 3 | handles TCG_CALL_DUMMY_ARG. |
4 | 4 | ||
5 | Tested-by: Alex Bennée <alex.bennee@linaro.org> | ||
6 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 5 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> |
6 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | ||
7 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
8 | --- | 9 | --- |
9 | tcg/tci.c | 66 +++++++++++++++++++++++++------------------------------ | 10 | tcg/optimize.c | 25 +++++++++++-------------- |
10 | 1 file changed, 30 insertions(+), 36 deletions(-) | 11 | 1 file changed, 11 insertions(+), 14 deletions(-) |
11 | 12 | ||
12 | diff --git a/tcg/tci.c b/tcg/tci.c | 13 | diff --git a/tcg/optimize.c b/tcg/optimize.c |
13 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/tcg/tci.c | 15 | --- a/tcg/optimize.c |
15 | +++ b/tcg/tci.c | 16 | +++ b/tcg/optimize.c |
16 | @@ -XXX,XX +XXX,XX @@ tci_write_reg(tcg_target_ulong *regs, TCGReg index, tcg_target_ulong value) | 17 | @@ -XXX,XX +XXX,XX @@ static void init_ts_info(OptContext *ctx, TCGTemp *ts) |
17 | regs[index] = value; | 18 | } |
18 | } | 19 | } |
19 | 20 | ||
20 | -static void | 21 | -static void init_arg_info(OptContext *ctx, TCGArg arg) |
21 | -tci_write_reg32(tcg_target_ulong *regs, TCGReg index, uint32_t value) | ||
22 | -{ | 22 | -{ |
23 | - tci_write_reg(regs, index, value); | 23 | - init_ts_info(ctx, arg_temp(arg)); |
24 | -} | 24 | -} |
25 | - | 25 | - |
26 | #if TCG_TARGET_REG_BITS == 32 | 26 | static TCGTemp *find_better_copy(TCGContext *s, TCGTemp *ts) |
27 | static void tci_write_reg64(tcg_target_ulong *regs, uint32_t high_index, | 27 | { |
28 | uint32_t low_index, uint64_t value) | 28 | TCGTemp *i, *g, *l; |
29 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 29 | @@ -XXX,XX +XXX,XX @@ static bool swap_commutative2(TCGArg *p1, TCGArg *p2) |
30 | t1 = tci_read_r32(regs, &tb_ptr); | 30 | return false; |
31 | t2 = tci_read_ri32(regs, &tb_ptr); | 31 | } |
32 | condition = *tb_ptr++; | 32 | |
33 | - tci_write_reg32(regs, t0, tci_compare32(t1, t2, condition)); | 33 | +static void init_arguments(OptContext *ctx, TCGOp *op, int nb_args) |
34 | + tci_write_reg(regs, t0, tci_compare32(t1, t2, condition)); | 34 | +{ |
35 | break; | 35 | + for (int i = 0; i < nb_args; i++) { |
36 | #if TCG_TARGET_REG_BITS == 32 | 36 | + TCGTemp *ts = arg_temp(op->args[i]); |
37 | case INDEX_op_setcond2_i32: | 37 | + if (ts) { |
38 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 38 | + init_ts_info(ctx, ts); |
39 | tmp64 = tci_read_r64(regs, &tb_ptr); | 39 | + } |
40 | v64 = tci_read_ri64(regs, &tb_ptr); | 40 | + } |
41 | condition = *tb_ptr++; | 41 | +} |
42 | - tci_write_reg32(regs, t0, tci_compare64(tmp64, v64, condition)); | 42 | + |
43 | + tci_write_reg(regs, t0, tci_compare64(tmp64, v64, condition)); | 43 | /* Propagate constants and copies, fold constant expressions. */ |
44 | break; | 44 | void tcg_optimize(TCGContext *s) |
45 | #elif TCG_TARGET_REG_BITS == 64 | 45 | { |
46 | case INDEX_op_setcond_i64: | 46 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) |
47 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 47 | if (opc == INDEX_op_call) { |
48 | case INDEX_op_mov_i32: | 48 | nb_oargs = TCGOP_CALLO(op); |
49 | t0 = *tb_ptr++; | 49 | nb_iargs = TCGOP_CALLI(op); |
50 | t1 = tci_read_r32(regs, &tb_ptr); | 50 | - for (i = 0; i < nb_oargs + nb_iargs; i++) { |
51 | - tci_write_reg32(regs, t0, t1); | 51 | - TCGTemp *ts = arg_temp(op->args[i]); |
52 | + tci_write_reg(regs, t0, t1); | 52 | - if (ts) { |
53 | break; | 53 | - init_ts_info(&ctx, ts); |
54 | case INDEX_op_tci_movi_i32: | 54 | - } |
55 | t0 = *tb_ptr++; | 55 | - } |
56 | t1 = tci_read_i32(&tb_ptr); | 56 | } else { |
57 | - tci_write_reg32(regs, t0, t1); | 57 | nb_oargs = def->nb_oargs; |
58 | + tci_write_reg(regs, t0, t1); | 58 | nb_iargs = def->nb_iargs; |
59 | break; | 59 | - for (i = 0; i < nb_oargs + nb_iargs; i++) { |
60 | 60 | - init_arg_info(&ctx, op->args[i]); | |
61 | /* Load/store operations (32 bit). */ | 61 | - } |
62 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 62 | } |
63 | t0 = *tb_ptr++; | 63 | + init_arguments(&ctx, op, nb_oargs + nb_iargs); |
64 | t1 = tci_read_r(regs, &tb_ptr); | 64 | |
65 | t2 = tci_read_s32(&tb_ptr); | 65 | /* Do copy propagation */ |
66 | - tci_write_reg32(regs, t0, *(uint32_t *)(t1 + t2)); | 66 | for (i = nb_oargs; i < nb_oargs + nb_iargs; i++) { |
67 | + tci_write_reg(regs, t0, *(uint32_t *)(t1 + t2)); | ||
68 | break; | ||
69 | case INDEX_op_st8_i32: | ||
70 | t0 = tci_read_r8(regs, &tb_ptr); | ||
71 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | ||
72 | t0 = *tb_ptr++; | ||
73 | t1 = tci_read_ri32(regs, &tb_ptr); | ||
74 | t2 = tci_read_ri32(regs, &tb_ptr); | ||
75 | - tci_write_reg32(regs, t0, t1 + t2); | ||
76 | + tci_write_reg(regs, t0, t1 + t2); | ||
77 | break; | ||
78 | case INDEX_op_sub_i32: | ||
79 | t0 = *tb_ptr++; | ||
80 | t1 = tci_read_ri32(regs, &tb_ptr); | ||
81 | t2 = tci_read_ri32(regs, &tb_ptr); | ||
82 | - tci_write_reg32(regs, t0, t1 - t2); | ||
83 | + tci_write_reg(regs, t0, t1 - t2); | ||
84 | break; | ||
85 | case INDEX_op_mul_i32: | ||
86 | t0 = *tb_ptr++; | ||
87 | t1 = tci_read_ri32(regs, &tb_ptr); | ||
88 | t2 = tci_read_ri32(regs, &tb_ptr); | ||
89 | - tci_write_reg32(regs, t0, t1 * t2); | ||
90 | + tci_write_reg(regs, t0, t1 * t2); | ||
91 | break; | ||
92 | #if TCG_TARGET_HAS_div_i32 | ||
93 | case INDEX_op_div_i32: | ||
94 | t0 = *tb_ptr++; | ||
95 | t1 = tci_read_ri32(regs, &tb_ptr); | ||
96 | t2 = tci_read_ri32(regs, &tb_ptr); | ||
97 | - tci_write_reg32(regs, t0, (int32_t)t1 / (int32_t)t2); | ||
98 | + tci_write_reg(regs, t0, (int32_t)t1 / (int32_t)t2); | ||
99 | break; | ||
100 | case INDEX_op_divu_i32: | ||
101 | t0 = *tb_ptr++; | ||
102 | t1 = tci_read_ri32(regs, &tb_ptr); | ||
103 | t2 = tci_read_ri32(regs, &tb_ptr); | ||
104 | - tci_write_reg32(regs, t0, t1 / t2); | ||
105 | + tci_write_reg(regs, t0, t1 / t2); | ||
106 | break; | ||
107 | case INDEX_op_rem_i32: | ||
108 | t0 = *tb_ptr++; | ||
109 | t1 = tci_read_ri32(regs, &tb_ptr); | ||
110 | t2 = tci_read_ri32(regs, &tb_ptr); | ||
111 | - tci_write_reg32(regs, t0, (int32_t)t1 % (int32_t)t2); | ||
112 | + tci_write_reg(regs, t0, (int32_t)t1 % (int32_t)t2); | ||
113 | break; | ||
114 | case INDEX_op_remu_i32: | ||
115 | t0 = *tb_ptr++; | ||
116 | t1 = tci_read_ri32(regs, &tb_ptr); | ||
117 | t2 = tci_read_ri32(regs, &tb_ptr); | ||
118 | - tci_write_reg32(regs, t0, t1 % t2); | ||
119 | + tci_write_reg(regs, t0, t1 % t2); | ||
120 | break; | ||
121 | #elif TCG_TARGET_HAS_div2_i32 | ||
122 | case INDEX_op_div2_i32: | ||
123 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | ||
124 | t0 = *tb_ptr++; | ||
125 | t1 = tci_read_ri32(regs, &tb_ptr); | ||
126 | t2 = tci_read_ri32(regs, &tb_ptr); | ||
127 | - tci_write_reg32(regs, t0, t1 & t2); | ||
128 | + tci_write_reg(regs, t0, t1 & t2); | ||
129 | break; | ||
130 | case INDEX_op_or_i32: | ||
131 | t0 = *tb_ptr++; | ||
132 | t1 = tci_read_ri32(regs, &tb_ptr); | ||
133 | t2 = tci_read_ri32(regs, &tb_ptr); | ||
134 | - tci_write_reg32(regs, t0, t1 | t2); | ||
135 | + tci_write_reg(regs, t0, t1 | t2); | ||
136 | break; | ||
137 | case INDEX_op_xor_i32: | ||
138 | t0 = *tb_ptr++; | ||
139 | t1 = tci_read_ri32(regs, &tb_ptr); | ||
140 | t2 = tci_read_ri32(regs, &tb_ptr); | ||
141 | - tci_write_reg32(regs, t0, t1 ^ t2); | ||
142 | + tci_write_reg(regs, t0, t1 ^ t2); | ||
143 | break; | ||
144 | |||
145 | /* Shift/rotate operations (32 bit). */ | ||
146 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | ||
147 | t0 = *tb_ptr++; | ||
148 | t1 = tci_read_ri32(regs, &tb_ptr); | ||
149 | t2 = tci_read_ri32(regs, &tb_ptr); | ||
150 | - tci_write_reg32(regs, t0, t1 << (t2 & 31)); | ||
151 | + tci_write_reg(regs, t0, t1 << (t2 & 31)); | ||
152 | break; | ||
153 | case INDEX_op_shr_i32: | ||
154 | t0 = *tb_ptr++; | ||
155 | t1 = tci_read_ri32(regs, &tb_ptr); | ||
156 | t2 = tci_read_ri32(regs, &tb_ptr); | ||
157 | - tci_write_reg32(regs, t0, t1 >> (t2 & 31)); | ||
158 | + tci_write_reg(regs, t0, t1 >> (t2 & 31)); | ||
159 | break; | ||
160 | case INDEX_op_sar_i32: | ||
161 | t0 = *tb_ptr++; | ||
162 | t1 = tci_read_ri32(regs, &tb_ptr); | ||
163 | t2 = tci_read_ri32(regs, &tb_ptr); | ||
164 | - tci_write_reg32(regs, t0, ((int32_t)t1 >> (t2 & 31))); | ||
165 | + tci_write_reg(regs, t0, ((int32_t)t1 >> (t2 & 31))); | ||
166 | break; | ||
167 | #if TCG_TARGET_HAS_rot_i32 | ||
168 | case INDEX_op_rotl_i32: | ||
169 | t0 = *tb_ptr++; | ||
170 | t1 = tci_read_ri32(regs, &tb_ptr); | ||
171 | t2 = tci_read_ri32(regs, &tb_ptr); | ||
172 | - tci_write_reg32(regs, t0, rol32(t1, t2 & 31)); | ||
173 | + tci_write_reg(regs, t0, rol32(t1, t2 & 31)); | ||
174 | break; | ||
175 | case INDEX_op_rotr_i32: | ||
176 | t0 = *tb_ptr++; | ||
177 | t1 = tci_read_ri32(regs, &tb_ptr); | ||
178 | t2 = tci_read_ri32(regs, &tb_ptr); | ||
179 | - tci_write_reg32(regs, t0, ror32(t1, t2 & 31)); | ||
180 | + tci_write_reg(regs, t0, ror32(t1, t2 & 31)); | ||
181 | break; | ||
182 | #endif | ||
183 | #if TCG_TARGET_HAS_deposit_i32 | ||
184 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | ||
185 | tmp16 = *tb_ptr++; | ||
186 | tmp8 = *tb_ptr++; | ||
187 | tmp32 = (((1 << tmp8) - 1) << tmp16); | ||
188 | - tci_write_reg32(regs, t0, (t1 & ~tmp32) | ((t2 << tmp16) & tmp32)); | ||
189 | + tci_write_reg(regs, t0, (t1 & ~tmp32) | ((t2 << tmp16) & tmp32)); | ||
190 | break; | ||
191 | #endif | ||
192 | case INDEX_op_brcond_i32: | ||
193 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | ||
194 | case INDEX_op_ext8s_i32: | ||
195 | t0 = *tb_ptr++; | ||
196 | t1 = tci_read_r8s(regs, &tb_ptr); | ||
197 | - tci_write_reg32(regs, t0, t1); | ||
198 | + tci_write_reg(regs, t0, t1); | ||
199 | break; | ||
200 | #endif | ||
201 | #if TCG_TARGET_HAS_ext16s_i32 | ||
202 | case INDEX_op_ext16s_i32: | ||
203 | t0 = *tb_ptr++; | ||
204 | t1 = tci_read_r16s(regs, &tb_ptr); | ||
205 | - tci_write_reg32(regs, t0, t1); | ||
206 | + tci_write_reg(regs, t0, t1); | ||
207 | break; | ||
208 | #endif | ||
209 | #if TCG_TARGET_HAS_ext8u_i32 | ||
210 | case INDEX_op_ext8u_i32: | ||
211 | t0 = *tb_ptr++; | ||
212 | t1 = tci_read_r8(regs, &tb_ptr); | ||
213 | - tci_write_reg32(regs, t0, t1); | ||
214 | + tci_write_reg(regs, t0, t1); | ||
215 | break; | ||
216 | #endif | ||
217 | #if TCG_TARGET_HAS_ext16u_i32 | ||
218 | case INDEX_op_ext16u_i32: | ||
219 | t0 = *tb_ptr++; | ||
220 | t1 = tci_read_r16(regs, &tb_ptr); | ||
221 | - tci_write_reg32(regs, t0, t1); | ||
222 | + tci_write_reg(regs, t0, t1); | ||
223 | break; | ||
224 | #endif | ||
225 | #if TCG_TARGET_HAS_bswap16_i32 | ||
226 | case INDEX_op_bswap16_i32: | ||
227 | t0 = *tb_ptr++; | ||
228 | t1 = tci_read_r16(regs, &tb_ptr); | ||
229 | - tci_write_reg32(regs, t0, bswap16(t1)); | ||
230 | + tci_write_reg(regs, t0, bswap16(t1)); | ||
231 | break; | ||
232 | #endif | ||
233 | #if TCG_TARGET_HAS_bswap32_i32 | ||
234 | case INDEX_op_bswap32_i32: | ||
235 | t0 = *tb_ptr++; | ||
236 | t1 = tci_read_r32(regs, &tb_ptr); | ||
237 | - tci_write_reg32(regs, t0, bswap32(t1)); | ||
238 | + tci_write_reg(regs, t0, bswap32(t1)); | ||
239 | break; | ||
240 | #endif | ||
241 | #if TCG_TARGET_HAS_not_i32 | ||
242 | case INDEX_op_not_i32: | ||
243 | t0 = *tb_ptr++; | ||
244 | t1 = tci_read_r32(regs, &tb_ptr); | ||
245 | - tci_write_reg32(regs, t0, ~t1); | ||
246 | + tci_write_reg(regs, t0, ~t1); | ||
247 | break; | ||
248 | #endif | ||
249 | #if TCG_TARGET_HAS_neg_i32 | ||
250 | case INDEX_op_neg_i32: | ||
251 | t0 = *tb_ptr++; | ||
252 | t1 = tci_read_r32(regs, &tb_ptr); | ||
253 | - tci_write_reg32(regs, t0, -t1); | ||
254 | + tci_write_reg(regs, t0, -t1); | ||
255 | break; | ||
256 | #endif | ||
257 | #if TCG_TARGET_REG_BITS == 64 | ||
258 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | ||
259 | t0 = *tb_ptr++; | ||
260 | t1 = tci_read_r(regs, &tb_ptr); | ||
261 | t2 = tci_read_s32(&tb_ptr); | ||
262 | - tci_write_reg32(regs, t0, *(uint32_t *)(t1 + t2)); | ||
263 | + tci_write_reg(regs, t0, *(uint32_t *)(t1 + t2)); | ||
264 | break; | ||
265 | case INDEX_op_ld32s_i64: | ||
266 | t0 = *tb_ptr++; | ||
267 | -- | 67 | -- |
268 | 2.25.1 | 68 | 2.25.1 |
269 | 69 | ||
270 | 70 | diff view generated by jsdifflib |
1 | The existing check was incomplete: | 1 | Continue splitting tcg_optimize. |
---|---|---|---|
2 | (1) Only applied to two of the 7 stores, and not to the loads at all. | ||
3 | (2) Only checked the upper, but not the lower bound of the stack. | ||
4 | 2 | ||
5 | Doing this at compile time means that we don't need to do it | ||
6 | at runtime as well. | ||
7 | |||
8 | Tested-by: Alex Bennée <alex.bennee@linaro.org> | ||
9 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 3 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> |
4 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | ||
5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
10 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
11 | --- | 7 | --- |
12 | tcg/tci.c | 2 -- | 8 | tcg/optimize.c | 22 ++++++++++++++-------- |
13 | tcg/tci/tcg-target.c.inc | 13 +++++++++++++ | 9 | 1 file changed, 14 insertions(+), 8 deletions(-) |
14 | 2 files changed, 13 insertions(+), 2 deletions(-) | ||
15 | 10 | ||
16 | diff --git a/tcg/tci.c b/tcg/tci.c | 11 | diff --git a/tcg/optimize.c b/tcg/optimize.c |
17 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/tcg/tci.c | 13 | --- a/tcg/optimize.c |
19 | +++ b/tcg/tci.c | 14 | +++ b/tcg/optimize.c |
20 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 15 | @@ -XXX,XX +XXX,XX @@ static void init_arguments(OptContext *ctx, TCGOp *op, int nb_args) |
21 | t0 = tci_read_r32(regs, &tb_ptr); | ||
22 | t1 = tci_read_r(regs, &tb_ptr); | ||
23 | t2 = tci_read_s32(&tb_ptr); | ||
24 | - tci_assert(t1 != sp_value || (int32_t)t2 < 0); | ||
25 | *(uint32_t *)(t1 + t2) = t0; | ||
26 | break; | ||
27 | |||
28 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | ||
29 | t0 = tci_read_r64(regs, &tb_ptr); | ||
30 | t1 = tci_read_r(regs, &tb_ptr); | ||
31 | t2 = tci_read_s32(&tb_ptr); | ||
32 | - tci_assert(t1 != sp_value || (int32_t)t2 < 0); | ||
33 | *(uint64_t *)(t1 + t2) = t0; | ||
34 | break; | ||
35 | |||
36 | diff --git a/tcg/tci/tcg-target.c.inc b/tcg/tci/tcg-target.c.inc | ||
37 | index XXXXXXX..XXXXXXX 100644 | ||
38 | --- a/tcg/tci/tcg-target.c.inc | ||
39 | +++ b/tcg/tci/tcg-target.c.inc | ||
40 | @@ -XXX,XX +XXX,XX @@ static void tci_out_label(TCGContext *s, TCGLabel *label) | ||
41 | } | 16 | } |
42 | } | 17 | } |
43 | 18 | ||
44 | +static void stack_bounds_check(TCGReg base, target_long offset) | 19 | +static void copy_propagate(OptContext *ctx, TCGOp *op, |
20 | + int nb_oargs, int nb_iargs) | ||
45 | +{ | 21 | +{ |
46 | + if (base == TCG_REG_CALL_STACK) { | 22 | + TCGContext *s = ctx->tcg; |
47 | + tcg_debug_assert(offset < 0); | 23 | + |
48 | + tcg_debug_assert(offset >= -(CPU_TEMP_BUF_NLONGS * sizeof(long))); | 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 | + } | ||
49 | + } | 29 | + } |
50 | +} | 30 | +} |
51 | + | 31 | + |
52 | static void tcg_out_ld(TCGContext *s, TCGType type, TCGReg ret, TCGReg arg1, | 32 | /* Propagate constants and copies, fold constant expressions. */ |
53 | intptr_t arg2) | 33 | void tcg_optimize(TCGContext *s) |
54 | { | 34 | { |
55 | uint8_t *old_code_ptr = s->code_ptr; | 35 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) |
56 | + | 36 | nb_iargs = def->nb_iargs; |
57 | + stack_bounds_check(arg1, arg2); | 37 | } |
58 | if (type == TCG_TYPE_I32) { | 38 | init_arguments(&ctx, op, nb_oargs + nb_iargs); |
59 | tcg_out_op_t(s, INDEX_op_ld_i32); | 39 | - |
60 | tcg_out_r(s, ret); | 40 | - /* Do copy propagation */ |
61 | @@ -XXX,XX +XXX,XX @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg *args, | 41 | - for (i = nb_oargs; i < nb_oargs + nb_iargs; i++) { |
62 | case INDEX_op_st16_i64: | 42 | - TCGTemp *ts = arg_temp(op->args[i]); |
63 | case INDEX_op_st32_i64: | 43 | - if (ts && ts_is_copy(ts)) { |
64 | case INDEX_op_st_i64: | 44 | - op->args[i] = temp_arg(find_better_copy(s, ts)); |
65 | + stack_bounds_check(args[1], args[2]); | 45 | - } |
66 | tcg_out_r(s, args[0]); | 46 | - } |
67 | tcg_out_r(s, args[1]); | 47 | + copy_propagate(&ctx, op, nb_oargs, nb_iargs); |
68 | tcg_debug_assert(args[2] == (int32_t)args[2]); | 48 | |
69 | @@ -XXX,XX +XXX,XX @@ static void tcg_out_st(TCGContext *s, TCGType type, TCGReg arg, TCGReg arg1, | 49 | /* For commutative operations make constant second argument */ |
70 | intptr_t arg2) | 50 | switch (opc) { |
71 | { | ||
72 | uint8_t *old_code_ptr = s->code_ptr; | ||
73 | + | ||
74 | + stack_bounds_check(arg1, arg2); | ||
75 | if (type == TCG_TYPE_I32) { | ||
76 | tcg_out_op_t(s, INDEX_op_st_i32); | ||
77 | tcg_out_r(s, arg); | ||
78 | -- | 51 | -- |
79 | 2.25.1 | 52 | 2.25.1 |
80 | 53 | ||
81 | 54 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Calls are special in that they have a variable number | ||
2 | of arguments, and need to be able to clobber globals. | ||
1 | 3 | ||
4 | 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> | ||
7 | --- | ||
8 | tcg/optimize.c | 63 ++++++++++++++++++++++++++++++++------------------ | ||
9 | 1 file changed, 41 insertions(+), 22 deletions(-) | ||
10 | |||
11 | diff --git a/tcg/optimize.c b/tcg/optimize.c | ||
12 | index XXXXXXX..XXXXXXX 100644 | ||
13 | --- a/tcg/optimize.c | ||
14 | +++ b/tcg/optimize.c | ||
15 | @@ -XXX,XX +XXX,XX @@ static void copy_propagate(OptContext *ctx, TCGOp *op, | ||
16 | } | ||
17 | } | ||
18 | |||
19 | +static bool fold_call(OptContext *ctx, TCGOp *op) | ||
20 | +{ | ||
21 | + TCGContext *s = ctx->tcg; | ||
22 | + int nb_oargs = TCGOP_CALLO(op); | ||
23 | + int nb_iargs = TCGOP_CALLI(op); | ||
24 | + int flags, i; | ||
25 | + | ||
26 | + init_arguments(ctx, op, nb_oargs + nb_iargs); | ||
27 | + copy_propagate(ctx, op, nb_oargs, nb_iargs); | ||
28 | + | ||
29 | + /* If the function reads or writes globals, reset temp data. */ | ||
30 | + flags = tcg_call_flags(op); | ||
31 | + if (!(flags & (TCG_CALL_NO_READ_GLOBALS | TCG_CALL_NO_WRITE_GLOBALS))) { | ||
32 | + int nb_globals = s->nb_globals; | ||
33 | + | ||
34 | + for (i = 0; i < nb_globals; i++) { | ||
35 | + if (test_bit(i, ctx->temps_used.l)) { | ||
36 | + reset_ts(&ctx->tcg->temps[i]); | ||
37 | + } | ||
38 | + } | ||
39 | + } | ||
40 | + | ||
41 | + /* Reset temp data for outputs. */ | ||
42 | + for (i = 0; i < nb_oargs; i++) { | ||
43 | + reset_temp(op->args[i]); | ||
44 | + } | ||
45 | + | ||
46 | + /* Stop optimizing MB across calls. */ | ||
47 | + ctx->prev_mb = NULL; | ||
48 | + return true; | ||
49 | +} | ||
50 | + | ||
51 | /* Propagate constants and copies, fold constant expressions. */ | ||
52 | void tcg_optimize(TCGContext *s) | ||
53 | { | ||
54 | - int nb_temps, nb_globals, i; | ||
55 | + int nb_temps, i; | ||
56 | TCGOp *op, *op_next; | ||
57 | OptContext ctx = { .tcg = s }; | ||
58 | |||
59 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
60 | available through the doubly linked circular list. */ | ||
61 | |||
62 | nb_temps = s->nb_temps; | ||
63 | - nb_globals = s->nb_globals; | ||
64 | - | ||
65 | for (i = 0; i < nb_temps; ++i) { | ||
66 | s->temps[i].state_ptr = NULL; | ||
67 | } | ||
68 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
69 | uint64_t z_mask, partmask, affected, tmp; | ||
70 | int nb_oargs, nb_iargs; | ||
71 | TCGOpcode opc = op->opc; | ||
72 | - const TCGOpDef *def = &tcg_op_defs[opc]; | ||
73 | + const TCGOpDef *def; | ||
74 | |||
75 | - /* Count the arguments, and initialize the temps that are | ||
76 | - going to be used */ | ||
77 | + /* Calls are special. */ | ||
78 | if (opc == INDEX_op_call) { | ||
79 | - nb_oargs = TCGOP_CALLO(op); | ||
80 | - nb_iargs = TCGOP_CALLI(op); | ||
81 | - } else { | ||
82 | - nb_oargs = def->nb_oargs; | ||
83 | - nb_iargs = def->nb_iargs; | ||
84 | + fold_call(&ctx, op); | ||
85 | + continue; | ||
86 | } | ||
87 | + | ||
88 | + def = &tcg_op_defs[opc]; | ||
89 | + nb_oargs = def->nb_oargs; | ||
90 | + nb_iargs = def->nb_iargs; | ||
91 | init_arguments(&ctx, op, nb_oargs + nb_iargs); | ||
92 | copy_propagate(&ctx, op, nb_oargs, nb_iargs); | ||
93 | |||
94 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
95 | if (def->flags & TCG_OPF_BB_END) { | ||
96 | memset(&ctx.temps_used, 0, sizeof(ctx.temps_used)); | ||
97 | } else { | ||
98 | - if (opc == INDEX_op_call && | ||
99 | - !(tcg_call_flags(op) | ||
100 | - & (TCG_CALL_NO_READ_GLOBALS | TCG_CALL_NO_WRITE_GLOBALS))) { | ||
101 | - for (i = 0; i < nb_globals; i++) { | ||
102 | - if (test_bit(i, ctx.temps_used.l)) { | ||
103 | - reset_ts(&s->temps[i]); | ||
104 | - } | ||
105 | - } | ||
106 | - } | ||
107 | - | ||
108 | for (i = 0; i < nb_oargs; i++) { | ||
109 | reset_temp(op->args[i]); | ||
110 | /* Save the corresponding known-zero bits mask for the | ||
111 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
112 | case INDEX_op_qemu_st_i32: | ||
113 | case INDEX_op_qemu_st8_i32: | ||
114 | case INDEX_op_qemu_st_i64: | ||
115 | - case INDEX_op_call: | ||
116 | /* Opcodes that touch guest memory stop the optimization. */ | ||
117 | ctx.prev_mb = NULL; | ||
118 | break; | ||
119 | -- | ||
120 | 2.25.1 | ||
121 | |||
122 | diff view generated by jsdifflib |
1 | Three TODO instances are never happen cases. | 1 | Rather than try to keep these up-to-date across folding, |
---|---|---|---|
2 | Other uses of tcg_abort are also indicating unreachable cases. | 2 | re-read nb_oargs at the end, after re-reading the opcode. |
3 | 3 | ||
4 | Tested-by: Alex Bennée <alex.bennee@linaro.org> | 4 | A couple of asserts need dropping, but that will take care |
5 | Reviewed-by: Stefan Weil <sw@weilnetz.de> | 5 | of itself as we split the function further. |
6 | |||
6 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 7 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> |
8 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | ||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 9 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
8 | --- | 10 | --- |
9 | tcg/tci.c | 15 +++++++-------- | 11 | tcg/optimize.c | 14 ++++---------- |
10 | 1 file changed, 7 insertions(+), 8 deletions(-) | 12 | 1 file changed, 4 insertions(+), 10 deletions(-) |
11 | 13 | ||
12 | diff --git a/tcg/tci.c b/tcg/tci.c | 14 | diff --git a/tcg/optimize.c b/tcg/optimize.c |
13 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/tcg/tci.c | 16 | --- a/tcg/optimize.c |
15 | +++ b/tcg/tci.c | 17 | +++ b/tcg/optimize.c |
16 | @@ -XXX,XX +XXX,XX @@ static bool tci_compare32(uint32_t u0, uint32_t u1, TCGCond condition) | 18 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) |
17 | result = (u0 > u1); | 19 | |
18 | break; | 20 | QTAILQ_FOREACH_SAFE(op, &s->ops, link, op_next) { |
19 | default: | 21 | uint64_t z_mask, partmask, affected, tmp; |
20 | - TODO(); | 22 | - int nb_oargs, nb_iargs; |
21 | + g_assert_not_reached(); | 23 | TCGOpcode opc = op->opc; |
22 | } | 24 | const TCGOpDef *def; |
23 | return result; | 25 | |
24 | } | 26 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) |
25 | @@ -XXX,XX +XXX,XX @@ static bool tci_compare64(uint64_t u0, uint64_t u1, TCGCond condition) | 27 | } |
26 | result = (u0 > u1); | 28 | |
27 | break; | 29 | def = &tcg_op_defs[opc]; |
28 | default: | 30 | - nb_oargs = def->nb_oargs; |
29 | - TODO(); | 31 | - nb_iargs = def->nb_iargs; |
30 | + g_assert_not_reached(); | 32 | - init_arguments(&ctx, op, nb_oargs + nb_iargs); |
31 | } | 33 | - copy_propagate(&ctx, op, nb_oargs, nb_iargs); |
32 | return result; | 34 | + init_arguments(&ctx, op, def->nb_oargs + def->nb_iargs); |
33 | } | 35 | + copy_propagate(&ctx, op, def->nb_oargs, def->nb_iargs); |
34 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 36 | |
35 | tmp32 = qemu_ld_beul; | 37 | /* For commutative operations make constant second argument */ |
36 | break; | 38 | switch (opc) { |
37 | default: | 39 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) |
38 | - tcg_abort(); | 40 | |
39 | + g_assert_not_reached(); | 41 | CASE_OP_32_64(qemu_ld): |
40 | } | 42 | { |
41 | tci_write_reg(regs, t0, tmp32); | 43 | - MemOpIdx oi = op->args[nb_oargs + nb_iargs]; |
42 | break; | 44 | + MemOpIdx oi = op->args[def->nb_oargs + def->nb_iargs]; |
43 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 45 | MemOp mop = get_memop(oi); |
44 | tmp64 = qemu_ld_beq; | 46 | if (!(mop & MO_SIGN)) { |
45 | break; | 47 | z_mask = (2ULL << ((8 << (mop & MO_SIZE)) - 1)) - 1; |
46 | default: | 48 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) |
47 | - tcg_abort(); | 49 | } |
48 | + g_assert_not_reached(); | 50 | |
49 | } | 51 | if (partmask == 0) { |
50 | tci_write_reg(regs, t0, tmp64); | 52 | - tcg_debug_assert(nb_oargs == 1); |
51 | if (TCG_TARGET_REG_BITS == 32) { | 53 | tcg_opt_gen_movi(&ctx, op, op->args[0], 0); |
52 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 54 | continue; |
53 | qemu_st_bel(t0); | 55 | } |
54 | break; | 56 | if (affected == 0) { |
55 | default: | 57 | - tcg_debug_assert(nb_oargs == 1); |
56 | - tcg_abort(); | 58 | tcg_opt_gen_mov(&ctx, op, op->args[0], op->args[1]); |
57 | + g_assert_not_reached(); | 59 | continue; |
60 | } | ||
61 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
62 | } else if (args_are_copies(op->args[1], op->args[2])) { | ||
63 | op->opc = INDEX_op_dup_vec; | ||
64 | TCGOP_VECE(op) = MO_32; | ||
65 | - nb_iargs = 1; | ||
58 | } | 66 | } |
59 | break; | 67 | break; |
60 | case INDEX_op_qemu_st_i64: | 68 | |
61 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 69 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) |
62 | qemu_st_beq(tmp64); | 70 | op->opc = opc = (opc == INDEX_op_movcond_i32 |
63 | break; | 71 | ? INDEX_op_setcond_i32 |
64 | default: | 72 | : INDEX_op_setcond_i64); |
65 | - tcg_abort(); | 73 | - nb_iargs = 2; |
66 | + g_assert_not_reached(); | ||
67 | } | 74 | } |
68 | break; | 75 | break; |
69 | case INDEX_op_mb: | 76 | |
70 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 77 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) |
71 | smp_mb(); | 78 | if (def->flags & TCG_OPF_BB_END) { |
72 | break; | 79 | memset(&ctx.temps_used, 0, sizeof(ctx.temps_used)); |
73 | default: | 80 | } else { |
74 | - TODO(); | 81 | + int nb_oargs = def->nb_oargs; |
75 | - break; | 82 | for (i = 0; i < nb_oargs; i++) { |
76 | + g_assert_not_reached(); | 83 | reset_temp(op->args[i]); |
77 | } | 84 | /* Save the corresponding known-zero bits mask for the |
78 | tci_assert(tb_ptr == old_code_ptr + op_size); | ||
79 | } | ||
80 | -- | 85 | -- |
81 | 2.25.1 | 86 | 2.25.1 |
82 | 87 | ||
83 | 88 | diff view generated by jsdifflib |
1 | From: Claudio Fontana <cfontana@suse.de> | 1 | Return -1 instead of 2 for failure, so that we can |
---|---|---|---|
2 | 2 | use comparisons against 0 for all cases. | |
3 | Signed-off-by: Claudio Fontana <cfontana@suse.de> | 3 | |
4 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 4 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> |
5 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | 5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | |||
8 | [claudio: wrap target code around CONFIG_TCG and !CONFIG_USER_ONLY] | ||
9 | |||
10 | avoiding its use in headers used by common_ss code (should be poisoned). | ||
11 | |||
12 | Note: need to be careful with the use of CONFIG_USER_ONLY, | ||
13 | Message-Id: <20210204163931.7358-11-cfontana@suse.de> | ||
14 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
15 | --- | 7 | --- |
16 | include/hw/core/cpu.h | 28 +++++++++++++--------------- | 8 | tcg/optimize.c | 145 +++++++++++++++++++++++++------------------------ |
17 | hw/mips/jazz.c | 9 +++++++-- | 9 | 1 file changed, 74 insertions(+), 71 deletions(-) |
18 | target/alpha/cpu.c | 2 +- | 10 | |
19 | target/arm/cpu.c | 4 ++-- | 11 | diff --git a/tcg/optimize.c b/tcg/optimize.c |
20 | target/m68k/cpu.c | 2 +- | ||
21 | target/microblaze/cpu.c | 2 +- | ||
22 | target/mips/cpu.c | 4 +++- | ||
23 | target/riscv/cpu.c | 2 +- | ||
24 | target/riscv/cpu_helper.c | 2 +- | ||
25 | target/sparc/cpu.c | 2 +- | ||
26 | target/xtensa/cpu.c | 2 +- | ||
27 | target/xtensa/helper.c | 4 ++-- | ||
28 | 12 files changed, 34 insertions(+), 29 deletions(-) | ||
29 | |||
30 | diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h | ||
31 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
32 | --- a/include/hw/core/cpu.h | 13 | --- a/tcg/optimize.c |
33 | +++ b/include/hw/core/cpu.h | 14 | +++ b/tcg/optimize.c |
34 | @@ -XXX,XX +XXX,XX @@ typedef struct TcgCpuOperations { | 15 | @@ -XXX,XX +XXX,XX @@ static bool do_constant_folding_cond_eq(TCGCond c) |
35 | /** @debug_excp_handler: Callback for handling debug exceptions */ | ||
36 | void (*debug_excp_handler)(CPUState *cpu); | ||
37 | |||
38 | + /** | ||
39 | + * @do_transaction_failed: Callback for handling failed memory transactions | ||
40 | + * (ie bus faults or external aborts; not MMU faults) | ||
41 | + */ | ||
42 | + void (*do_transaction_failed)(CPUState *cpu, hwaddr physaddr, vaddr addr, | ||
43 | + unsigned size, MMUAccessType access_type, | ||
44 | + int mmu_idx, MemTxAttrs attrs, | ||
45 | + MemTxResult response, uintptr_t retaddr); | ||
46 | } TcgCpuOperations; | ||
47 | |||
48 | /** | ||
49 | @@ -XXX,XX +XXX,XX @@ typedef struct TcgCpuOperations { | ||
50 | * @has_work: Callback for checking if there is work to do. | ||
51 | * @do_unaligned_access: Callback for unaligned access handling, if | ||
52 | * the target defines #TARGET_ALIGNED_ONLY. | ||
53 | - * @do_transaction_failed: Callback for handling failed memory transactions | ||
54 | - * (ie bus faults or external aborts; not MMU faults) | ||
55 | * @virtio_is_big_endian: Callback to return %true if a CPU which supports | ||
56 | * runtime configurable endianness is currently big-endian. Non-configurable | ||
57 | * CPUs can use the default implementation of this method. This method should | ||
58 | @@ -XXX,XX +XXX,XX @@ struct CPUClass { | ||
59 | void (*do_unaligned_access)(CPUState *cpu, vaddr addr, | ||
60 | MMUAccessType access_type, | ||
61 | int mmu_idx, uintptr_t retaddr); | ||
62 | - void (*do_transaction_failed)(CPUState *cpu, hwaddr physaddr, vaddr addr, | ||
63 | - unsigned size, MMUAccessType access_type, | ||
64 | - int mmu_idx, MemTxAttrs attrs, | ||
65 | - MemTxResult response, uintptr_t retaddr); | ||
66 | bool (*virtio_is_big_endian)(CPUState *cpu); | ||
67 | int (*memory_rw_debug)(CPUState *cpu, vaddr addr, | ||
68 | uint8_t *buf, int len, bool is_write); | ||
69 | @@ -XXX,XX +XXX,XX @@ CPUState *cpu_by_arch_id(int64_t id); | ||
70 | |||
71 | void cpu_interrupt(CPUState *cpu, int mask); | ||
72 | |||
73 | -#ifdef NEED_CPU_H | ||
74 | - | ||
75 | -#ifdef CONFIG_SOFTMMU | ||
76 | static inline void cpu_unaligned_access(CPUState *cpu, vaddr addr, | ||
77 | MMUAccessType access_type, | ||
78 | int mmu_idx, uintptr_t retaddr) | ||
79 | @@ -XXX,XX +XXX,XX @@ static inline void cpu_transaction_failed(CPUState *cpu, hwaddr physaddr, | ||
80 | { | ||
81 | CPUClass *cc = CPU_GET_CLASS(cpu); | ||
82 | |||
83 | - if (!cpu->ignore_memory_transaction_failures && cc->do_transaction_failed) { | ||
84 | - cc->do_transaction_failed(cpu, physaddr, addr, size, access_type, | ||
85 | - mmu_idx, attrs, response, retaddr); | ||
86 | + if (!cpu->ignore_memory_transaction_failures && | ||
87 | + cc->tcg_ops.do_transaction_failed) { | ||
88 | + cc->tcg_ops.do_transaction_failed(cpu, physaddr, addr, size, | ||
89 | + access_type, mmu_idx, attrs, | ||
90 | + response, retaddr); | ||
91 | } | 16 | } |
92 | } | 17 | } |
93 | -#endif | 18 | |
94 | - | 19 | -/* Return 2 if the condition can't be simplified, and the result |
95 | -#endif /* NEED_CPU_H */ | 20 | - of the condition (0 or 1) if it can */ |
96 | 21 | -static TCGArg do_constant_folding_cond(TCGOpcode op, TCGArg x, | |
97 | /** | 22 | - TCGArg y, TCGCond c) |
98 | * cpu_set_pc: | 23 | +/* |
99 | diff --git a/hw/mips/jazz.c b/hw/mips/jazz.c | 24 | + * Return -1 if the condition can't be simplified, |
100 | index XXXXXXX..XXXXXXX 100644 | 25 | + * and the result of the condition (0 or 1) if it can. |
101 | --- a/hw/mips/jazz.c | 26 | + */ |
102 | +++ b/hw/mips/jazz.c | 27 | +static int do_constant_folding_cond(TCGOpcode op, TCGArg x, |
103 | @@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps dma_dummy_ops = { | 28 | + TCGArg y, TCGCond c) |
104 | #define MAGNUM_BIOS_SIZE_MAX 0x7e000 | 29 | { |
105 | #define MAGNUM_BIOS_SIZE \ | 30 | uint64_t xv = arg_info(x)->val; |
106 | (BIOS_SIZE < MAGNUM_BIOS_SIZE_MAX ? BIOS_SIZE : MAGNUM_BIOS_SIZE_MAX) | 31 | uint64_t yv = arg_info(y)->val; |
107 | + | 32 | @@ -XXX,XX +XXX,XX @@ static TCGArg do_constant_folding_cond(TCGOpcode op, TCGArg x, |
108 | +#if defined(CONFIG_TCG) && !defined(CONFIG_USER_ONLY) | 33 | case TCG_COND_GEU: |
109 | static void (*real_do_transaction_failed)(CPUState *cpu, hwaddr physaddr, | 34 | return 1; |
110 | vaddr addr, unsigned size, | 35 | default: |
111 | MMUAccessType access_type, | 36 | - return 2; |
112 | @@ -XXX,XX +XXX,XX @@ static void mips_jazz_do_transaction_failed(CPUState *cs, hwaddr physaddr, | 37 | + return -1; |
113 | (*real_do_transaction_failed)(cs, physaddr, addr, size, access_type, | 38 | } |
114 | mmu_idx, attrs, response, retaddr); | 39 | } |
40 | - return 2; | ||
41 | + return -1; | ||
115 | } | 42 | } |
116 | +#endif /* CONFIG_TCG && !CONFIG_USER_ONLY */ | 43 | |
117 | 44 | -/* Return 2 if the condition can't be simplified, and the result | |
118 | static void mips_jazz_init(MachineState *machine, | 45 | - of the condition (0 or 1) if it can */ |
119 | enum jazz_model_e jazz_model) | 46 | -static TCGArg do_constant_folding_cond2(TCGArg *p1, TCGArg *p2, TCGCond c) |
120 | @@ -XXX,XX +XXX,XX @@ static void mips_jazz_init(MachineState *machine, | 47 | +/* |
121 | * memory region that catches all memory accesses, as we do on Malta. | 48 | + * Return -1 if the condition can't be simplified, |
122 | */ | 49 | + * and the result of the condition (0 or 1) if it can. |
123 | cc = CPU_GET_CLASS(cpu); | 50 | + */ |
124 | - real_do_transaction_failed = cc->do_transaction_failed; | 51 | +static int do_constant_folding_cond2(TCGArg *p1, TCGArg *p2, TCGCond c) |
125 | - cc->do_transaction_failed = mips_jazz_do_transaction_failed; | 52 | { |
126 | +#if defined(CONFIG_TCG) && !defined(CONFIG_USER_ONLY) | 53 | TCGArg al = p1[0], ah = p1[1]; |
127 | + real_do_transaction_failed = cc->tcg_ops.do_transaction_failed; | 54 | TCGArg bl = p2[0], bh = p2[1]; |
128 | + cc->tcg_ops.do_transaction_failed = mips_jazz_do_transaction_failed; | 55 | @@ -XXX,XX +XXX,XX @@ static TCGArg do_constant_folding_cond2(TCGArg *p1, TCGArg *p2, TCGCond c) |
129 | +#endif /* CONFIG_TCG && !CONFIG_USER_ONLY */ | 56 | if (args_are_copies(al, bl) && args_are_copies(ah, bh)) { |
130 | 57 | return do_constant_folding_cond_eq(c); | |
131 | /* allocate RAM */ | 58 | } |
132 | memory_region_add_subregion(address_space, 0, machine->ram); | 59 | - return 2; |
133 | diff --git a/target/alpha/cpu.c b/target/alpha/cpu.c | 60 | + return -1; |
134 | index XXXXXXX..XXXXXXX 100644 | ||
135 | --- a/target/alpha/cpu.c | ||
136 | +++ b/target/alpha/cpu.c | ||
137 | @@ -XXX,XX +XXX,XX @@ static void alpha_cpu_class_init(ObjectClass *oc, void *data) | ||
138 | cc->gdb_write_register = alpha_cpu_gdb_write_register; | ||
139 | cc->tcg_ops.tlb_fill = alpha_cpu_tlb_fill; | ||
140 | #ifndef CONFIG_USER_ONLY | ||
141 | - cc->do_transaction_failed = alpha_cpu_do_transaction_failed; | ||
142 | + cc->tcg_ops.do_transaction_failed = alpha_cpu_do_transaction_failed; | ||
143 | cc->do_unaligned_access = alpha_cpu_do_unaligned_access; | ||
144 | cc->get_phys_page_debug = alpha_cpu_get_phys_page_debug; | ||
145 | dc->vmsd = &vmstate_alpha_cpu; | ||
146 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | ||
147 | index XXXXXXX..XXXXXXX 100644 | ||
148 | --- a/target/arm/cpu.c | ||
149 | +++ b/target/arm/cpu.c | ||
150 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_class_init(ObjectClass *oc, void *data) | ||
151 | cc->debug_check_watchpoint = arm_debug_check_watchpoint; | ||
152 | cc->do_unaligned_access = arm_cpu_do_unaligned_access; | ||
153 | #if !defined(CONFIG_USER_ONLY) | ||
154 | - cc->do_transaction_failed = arm_cpu_do_transaction_failed; | ||
155 | + cc->tcg_ops.do_transaction_failed = arm_cpu_do_transaction_failed; | ||
156 | cc->adjust_watchpoint_address = arm_adjust_watchpoint_address; | ||
157 | cc->tcg_ops.do_interrupt = arm_cpu_do_interrupt; | ||
158 | #endif /* CONFIG_TCG && !CONFIG_USER_ONLY */ | ||
159 | -#endif | ||
160 | +#endif /* CONFIG_TCG */ | ||
161 | } | 61 | } |
162 | 62 | ||
163 | #ifdef CONFIG_KVM | 63 | static bool swap_commutative(TCGArg dest, TCGArg *p1, TCGArg *p2) |
164 | diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c | 64 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) |
165 | index XXXXXXX..XXXXXXX 100644 | 65 | break; |
166 | --- a/target/m68k/cpu.c | 66 | |
167 | +++ b/target/m68k/cpu.c | 67 | CASE_OP_32_64(setcond): |
168 | @@ -XXX,XX +XXX,XX @@ static void m68k_cpu_class_init(ObjectClass *c, void *data) | 68 | - tmp = do_constant_folding_cond(opc, op->args[1], |
169 | cc->gdb_write_register = m68k_cpu_gdb_write_register; | 69 | - op->args[2], op->args[3]); |
170 | cc->tcg_ops.tlb_fill = m68k_cpu_tlb_fill; | 70 | - if (tmp != 2) { |
171 | #if defined(CONFIG_SOFTMMU) | 71 | - tcg_opt_gen_movi(&ctx, op, op->args[0], tmp); |
172 | - cc->do_transaction_failed = m68k_cpu_transaction_failed; | 72 | + i = do_constant_folding_cond(opc, op->args[1], |
173 | + cc->tcg_ops.do_transaction_failed = m68k_cpu_transaction_failed; | 73 | + op->args[2], op->args[3]); |
174 | cc->get_phys_page_debug = m68k_cpu_get_phys_page_debug; | 74 | + if (i >= 0) { |
175 | dc->vmsd = &vmstate_m68k_cpu; | 75 | + tcg_opt_gen_movi(&ctx, op, op->args[0], i); |
176 | #endif | 76 | continue; |
177 | diff --git a/target/microblaze/cpu.c b/target/microblaze/cpu.c | 77 | } |
178 | index XXXXXXX..XXXXXXX 100644 | 78 | break; |
179 | --- a/target/microblaze/cpu.c | 79 | |
180 | +++ b/target/microblaze/cpu.c | 80 | CASE_OP_32_64(brcond): |
181 | @@ -XXX,XX +XXX,XX @@ static void mb_cpu_class_init(ObjectClass *oc, void *data) | 81 | - tmp = do_constant_folding_cond(opc, op->args[0], |
182 | cc->gdb_write_register = mb_cpu_gdb_write_register; | 82 | - op->args[1], op->args[2]); |
183 | cc->tcg_ops.tlb_fill = mb_cpu_tlb_fill; | 83 | - switch (tmp) { |
184 | #ifndef CONFIG_USER_ONLY | 84 | - case 0: |
185 | - cc->do_transaction_failed = mb_cpu_transaction_failed; | 85 | + i = do_constant_folding_cond(opc, op->args[0], |
186 | + cc->tcg_ops.do_transaction_failed = mb_cpu_transaction_failed; | 86 | + op->args[1], op->args[2]); |
187 | cc->get_phys_page_attrs_debug = mb_cpu_get_phys_page_attrs_debug; | 87 | + if (i == 0) { |
188 | dc->vmsd = &vmstate_mb_cpu; | 88 | tcg_op_remove(s, op); |
189 | #endif | 89 | continue; |
190 | diff --git a/target/mips/cpu.c b/target/mips/cpu.c | 90 | - case 1: |
191 | index XXXXXXX..XXXXXXX 100644 | 91 | + } else if (i > 0) { |
192 | --- a/target/mips/cpu.c | 92 | memset(&ctx.temps_used, 0, sizeof(ctx.temps_used)); |
193 | +++ b/target/mips/cpu.c | 93 | op->opc = opc = INDEX_op_br; |
194 | @@ -XXX,XX +XXX,XX @@ static void mips_cpu_class_init(ObjectClass *c, void *data) | 94 | op->args[0] = op->args[3]; |
195 | cc->gdb_read_register = mips_cpu_gdb_read_register; | 95 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) |
196 | cc->gdb_write_register = mips_cpu_gdb_write_register; | 96 | break; |
197 | #ifndef CONFIG_USER_ONLY | 97 | |
198 | - cc->do_transaction_failed = mips_cpu_do_transaction_failed; | 98 | CASE_OP_32_64(movcond): |
199 | cc->do_unaligned_access = mips_cpu_do_unaligned_access; | 99 | - tmp = do_constant_folding_cond(opc, op->args[1], |
200 | cc->get_phys_page_debug = mips_cpu_get_phys_page_debug; | 100 | - op->args[2], op->args[5]); |
201 | cc->vmsd = &vmstate_mips_cpu; | 101 | - if (tmp != 2) { |
202 | @@ -XXX,XX +XXX,XX @@ static void mips_cpu_class_init(ObjectClass *c, void *data) | 102 | - tcg_opt_gen_mov(&ctx, op, op->args[0], op->args[4-tmp]); |
203 | cc->tcg_ops.cpu_exec_interrupt = mips_cpu_exec_interrupt; | 103 | + i = do_constant_folding_cond(opc, op->args[1], |
204 | cc->tcg_ops.synchronize_from_tb = mips_cpu_synchronize_from_tb; | 104 | + op->args[2], op->args[5]); |
205 | cc->tcg_ops.tlb_fill = mips_cpu_tlb_fill; | 105 | + if (i >= 0) { |
206 | +#ifndef CONFIG_USER_ONLY | 106 | + tcg_opt_gen_mov(&ctx, op, op->args[0], op->args[4 - i]); |
207 | + cc->tcg_ops.do_transaction_failed = mips_cpu_do_transaction_failed; | 107 | continue; |
208 | +#endif /* CONFIG_USER_ONLY */ | 108 | } |
209 | #endif /* CONFIG_TCG */ | 109 | if (arg_is_const(op->args[3]) && arg_is_const(op->args[4])) { |
210 | 110 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | |
211 | cc->gdb_num_core_regs = 73; | 111 | break; |
212 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 112 | |
213 | index XXXXXXX..XXXXXXX 100644 | 113 | case INDEX_op_brcond2_i32: |
214 | --- a/target/riscv/cpu.c | 114 | - tmp = do_constant_folding_cond2(&op->args[0], &op->args[2], |
215 | +++ b/target/riscv/cpu.c | 115 | - op->args[4]); |
216 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_class_init(ObjectClass *c, void *data) | 116 | - if (tmp == 0) { |
217 | cc->gdb_stop_before_watchpoint = true; | 117 | + i = do_constant_folding_cond2(&op->args[0], &op->args[2], |
218 | cc->disas_set_info = riscv_cpu_disas_set_info; | 118 | + op->args[4]); |
219 | #ifndef CONFIG_USER_ONLY | 119 | + if (i == 0) { |
220 | - cc->do_transaction_failed = riscv_cpu_do_transaction_failed; | 120 | do_brcond_false: |
221 | + cc->tcg_ops.do_transaction_failed = riscv_cpu_do_transaction_failed; | 121 | tcg_op_remove(s, op); |
222 | cc->do_unaligned_access = riscv_cpu_do_unaligned_access; | 122 | continue; |
223 | cc->get_phys_page_debug = riscv_cpu_get_phys_page_debug; | 123 | } |
224 | /* For now, mark unmigratable: */ | 124 | - if (tmp == 1) { |
225 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c | 125 | + if (i > 0) { |
226 | index XXXXXXX..XXXXXXX 100644 | 126 | do_brcond_true: |
227 | --- a/target/riscv/cpu_helper.c | 127 | op->opc = opc = INDEX_op_br; |
228 | +++ b/target/riscv/cpu_helper.c | 128 | op->args[0] = op->args[5]; |
229 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_unaligned_access(CPUState *cs, vaddr addr, | 129 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) |
230 | env->badaddr = addr; | 130 | if (op->args[4] == TCG_COND_EQ) { |
231 | riscv_raise_exception(env, cs->exception_index, retaddr); | 131 | /* Simplify EQ comparisons where one of the pairs |
232 | } | 132 | can be simplified. */ |
233 | -#endif | 133 | - tmp = do_constant_folding_cond(INDEX_op_brcond_i32, |
234 | +#endif /* !CONFIG_USER_ONLY */ | 134 | - op->args[0], op->args[2], |
235 | 135 | - TCG_COND_EQ); | |
236 | bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, | 136 | - if (tmp == 0) { |
237 | MMUAccessType access_type, int mmu_idx, | 137 | + i = do_constant_folding_cond(INDEX_op_brcond_i32, |
238 | diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c | 138 | + op->args[0], op->args[2], |
239 | index XXXXXXX..XXXXXXX 100644 | 139 | + TCG_COND_EQ); |
240 | --- a/target/sparc/cpu.c | 140 | + if (i == 0) { |
241 | +++ b/target/sparc/cpu.c | 141 | goto do_brcond_false; |
242 | @@ -XXX,XX +XXX,XX @@ static void sparc_cpu_class_init(ObjectClass *oc, void *data) | 142 | - } else if (tmp == 1) { |
243 | cc->gdb_write_register = sparc_cpu_gdb_write_register; | 143 | + } else if (i > 0) { |
244 | cc->tcg_ops.tlb_fill = sparc_cpu_tlb_fill; | 144 | goto do_brcond_high; |
245 | #ifndef CONFIG_USER_ONLY | 145 | } |
246 | - cc->do_transaction_failed = sparc_cpu_do_transaction_failed; | 146 | - tmp = do_constant_folding_cond(INDEX_op_brcond_i32, |
247 | + cc->tcg_ops.do_transaction_failed = sparc_cpu_do_transaction_failed; | 147 | - op->args[1], op->args[3], |
248 | cc->do_unaligned_access = sparc_cpu_do_unaligned_access; | 148 | - TCG_COND_EQ); |
249 | cc->get_phys_page_debug = sparc_cpu_get_phys_page_debug; | 149 | - if (tmp == 0) { |
250 | cc->vmsd = &vmstate_sparc_cpu; | 150 | + i = do_constant_folding_cond(INDEX_op_brcond_i32, |
251 | diff --git a/target/xtensa/cpu.c b/target/xtensa/cpu.c | 151 | + op->args[1], op->args[3], |
252 | index XXXXXXX..XXXXXXX 100644 | 152 | + TCG_COND_EQ); |
253 | --- a/target/xtensa/cpu.c | 153 | + if (i == 0) { |
254 | +++ b/target/xtensa/cpu.c | 154 | goto do_brcond_false; |
255 | @@ -XXX,XX +XXX,XX @@ static void xtensa_cpu_class_init(ObjectClass *oc, void *data) | 155 | - } else if (tmp != 1) { |
256 | #ifndef CONFIG_USER_ONLY | 156 | + } else if (i < 0) { |
257 | cc->do_unaligned_access = xtensa_cpu_do_unaligned_access; | 157 | break; |
258 | cc->get_phys_page_debug = xtensa_cpu_get_phys_page_debug; | 158 | } |
259 | - cc->do_transaction_failed = xtensa_cpu_do_transaction_failed; | 159 | do_brcond_low: |
260 | + cc->tcg_ops.do_transaction_failed = xtensa_cpu_do_transaction_failed; | 160 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) |
261 | #endif | 161 | if (op->args[4] == TCG_COND_NE) { |
262 | cc->tcg_ops.debug_excp_handler = xtensa_breakpoint_handler; | 162 | /* Simplify NE comparisons where one of the pairs |
263 | cc->disas_set_info = xtensa_cpu_disas_set_info; | 163 | can be simplified. */ |
264 | diff --git a/target/xtensa/helper.c b/target/xtensa/helper.c | 164 | - tmp = do_constant_folding_cond(INDEX_op_brcond_i32, |
265 | index XXXXXXX..XXXXXXX 100644 | 165 | - op->args[0], op->args[2], |
266 | --- a/target/xtensa/helper.c | 166 | - TCG_COND_NE); |
267 | +++ b/target/xtensa/helper.c | 167 | - if (tmp == 0) { |
268 | @@ -XXX,XX +XXX,XX @@ bool xtensa_cpu_tlb_fill(CPUState *cs, vaddr address, int size, | 168 | + i = do_constant_folding_cond(INDEX_op_brcond_i32, |
269 | cpu_loop_exit_restore(cs, retaddr); | 169 | + op->args[0], op->args[2], |
270 | } | 170 | + TCG_COND_NE); |
271 | 171 | + if (i == 0) { | |
272 | -#else | 172 | goto do_brcond_high; |
273 | +#else /* !CONFIG_USER_ONLY */ | 173 | - } else if (tmp == 1) { |
274 | 174 | + } else if (i > 0) { | |
275 | void xtensa_cpu_do_unaligned_access(CPUState *cs, | 175 | goto do_brcond_true; |
276 | vaddr addr, MMUAccessType access_type, | 176 | } |
277 | @@ -XXX,XX +XXX,XX @@ void xtensa_runstall(CPUXtensaState *env, bool runstall) | 177 | - tmp = do_constant_folding_cond(INDEX_op_brcond_i32, |
278 | qemu_cpu_kick(cpu); | 178 | - op->args[1], op->args[3], |
279 | } | 179 | - TCG_COND_NE); |
280 | } | 180 | - if (tmp == 0) { |
281 | -#endif | 181 | + i = do_constant_folding_cond(INDEX_op_brcond_i32, |
282 | +#endif /* !CONFIG_USER_ONLY */ | 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 | } | ||
283 | -- | 268 | -- |
284 | 2.25.1 | 269 | 2.25.1 |
285 | 270 | ||
286 | 271 | diff view generated by jsdifflib |
1 | Restrict all operands to registers. All constants will be forced | 1 | This will allow callers to tail call to these functions |
---|---|---|---|
2 | into registers by the middle-end. Removing the difference in how | 2 | and return true indicating processing complete. |
3 | immediate integers were encoded will allow more code to be shared | ||
4 | between 32-bit and 64-bit operations. | ||
5 | 3 | ||
6 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 4 | Reviewed-by: Alex Bennée <alex.bennee@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/tci/tcg-target-con-set.h | 6 +- | 9 | tcg/optimize.c | 9 +++++---- |
10 | tcg/tci/tcg-target.h | 3 - | 10 | 1 file changed, 5 insertions(+), 4 deletions(-) |
11 | tcg/tci.c | 189 +++++++++++++---------------------- | ||
12 | tcg/tci/tcg-target.c.inc | 85 ++++------------ | ||
13 | 4 files changed, 89 insertions(+), 194 deletions(-) | ||
14 | 11 | ||
15 | diff --git a/tcg/tci/tcg-target-con-set.h b/tcg/tci/tcg-target-con-set.h | 12 | diff --git a/tcg/optimize.c b/tcg/optimize.c |
16 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/tcg/tci/tcg-target-con-set.h | 14 | --- a/tcg/optimize.c |
18 | +++ b/tcg/tci/tcg-target-con-set.h | 15 | +++ b/tcg/optimize.c |
19 | @@ -XXX,XX +XXX,XX @@ | 16 | @@ -XXX,XX +XXX,XX @@ static bool args_are_copies(TCGArg arg1, TCGArg arg2) |
20 | * tcg-target-con-str.h; the constraint combination is inclusive or. | 17 | return ts_are_copies(arg_temp(arg1), arg_temp(arg2)); |
21 | */ | ||
22 | C_O0_I2(r, r) | ||
23 | -C_O0_I2(r, ri) | ||
24 | C_O0_I3(r, r, r) | ||
25 | -C_O0_I4(r, r, ri, ri) | ||
26 | C_O0_I4(r, r, r, r) | ||
27 | C_O1_I1(r, r) | ||
28 | C_O1_I2(r, 0, r) | ||
29 | -C_O1_I2(r, ri, ri) | ||
30 | C_O1_I2(r, r, r) | ||
31 | -C_O1_I2(r, r, ri) | ||
32 | -C_O1_I4(r, r, r, ri, ri) | ||
33 | +C_O1_I4(r, r, r, r, r) | ||
34 | C_O2_I1(r, r, r) | ||
35 | C_O2_I2(r, r, r, r) | ||
36 | C_O2_I4(r, r, r, r, r, r) | ||
37 | diff --git a/tcg/tci/tcg-target.h b/tcg/tci/tcg-target.h | ||
38 | index XXXXXXX..XXXXXXX 100644 | ||
39 | --- a/tcg/tci/tcg-target.h | ||
40 | +++ b/tcg/tci/tcg-target.h | ||
41 | @@ -XXX,XX +XXX,XX @@ typedef enum { | ||
42 | |||
43 | TCG_AREG0 = TCG_REG_R14, | ||
44 | TCG_REG_CALL_STACK = TCG_REG_R15, | ||
45 | - | ||
46 | - /* Special value UINT8_MAX is used by TCI to encode constant values. */ | ||
47 | - TCG_CONST = UINT8_MAX | ||
48 | } TCGReg; | ||
49 | |||
50 | /* Used for function call generation. */ | ||
51 | diff --git a/tcg/tci.c b/tcg/tci.c | ||
52 | index XXXXXXX..XXXXXXX 100644 | ||
53 | --- a/tcg/tci.c | ||
54 | +++ b/tcg/tci.c | ||
55 | @@ -XXX,XX +XXX,XX @@ tci_read_ulong(const tcg_target_ulong *regs, const uint8_t **tb_ptr) | ||
56 | return taddr; | ||
57 | } | 18 | } |
58 | 19 | ||
59 | -/* Read indexed register or constant (native size) from bytecode. */ | 20 | -static void tcg_opt_gen_mov(OptContext *ctx, TCGOp *op, TCGArg dst, TCGArg src) |
60 | -static tcg_target_ulong | 21 | +static bool tcg_opt_gen_mov(OptContext *ctx, TCGOp *op, TCGArg dst, TCGArg src) |
61 | -tci_read_ri(const tcg_target_ulong *regs, const uint8_t **tb_ptr) | ||
62 | -{ | ||
63 | - tcg_target_ulong value; | ||
64 | - TCGReg r = **tb_ptr; | ||
65 | - *tb_ptr += 1; | ||
66 | - if (r == TCG_CONST) { | ||
67 | - value = tci_read_i(tb_ptr); | ||
68 | - } else { | ||
69 | - value = tci_read_reg(regs, r); | ||
70 | - } | ||
71 | - return value; | ||
72 | -} | ||
73 | - | ||
74 | -/* Read indexed register or constant (32 bit) from bytecode. */ | ||
75 | -static uint32_t tci_read_ri32(const tcg_target_ulong *regs, | ||
76 | - const uint8_t **tb_ptr) | ||
77 | -{ | ||
78 | - uint32_t value; | ||
79 | - TCGReg r = **tb_ptr; | ||
80 | - *tb_ptr += 1; | ||
81 | - if (r == TCG_CONST) { | ||
82 | - value = tci_read_i32(tb_ptr); | ||
83 | - } else { | ||
84 | - value = tci_read_reg32(regs, r); | ||
85 | - } | ||
86 | - return value; | ||
87 | -} | ||
88 | - | ||
89 | -#if TCG_TARGET_REG_BITS == 32 | ||
90 | -/* Read two indexed registers or constants (2 * 32 bit) from bytecode. */ | ||
91 | -static uint64_t tci_read_ri64(const tcg_target_ulong *regs, | ||
92 | - const uint8_t **tb_ptr) | ||
93 | -{ | ||
94 | - uint32_t low = tci_read_ri32(regs, tb_ptr); | ||
95 | - return tci_uint64(tci_read_ri32(regs, tb_ptr), low); | ||
96 | -} | ||
97 | -#elif TCG_TARGET_REG_BITS == 64 | ||
98 | -/* Read indexed register or constant (64 bit) from bytecode. */ | ||
99 | -static uint64_t tci_read_ri64(const tcg_target_ulong *regs, | ||
100 | - const uint8_t **tb_ptr) | ||
101 | -{ | ||
102 | - uint64_t value; | ||
103 | - TCGReg r = **tb_ptr; | ||
104 | - *tb_ptr += 1; | ||
105 | - if (r == TCG_CONST) { | ||
106 | - value = tci_read_i64(tb_ptr); | ||
107 | - } else { | ||
108 | - value = tci_read_reg64(regs, r); | ||
109 | - } | ||
110 | - return value; | ||
111 | -} | ||
112 | -#endif | ||
113 | - | ||
114 | static tcg_target_ulong tci_read_label(const uint8_t **tb_ptr) | ||
115 | { | 22 | { |
116 | tcg_target_ulong label = tci_read_i(tb_ptr); | 23 | TCGTemp *dst_ts = arg_temp(dst); |
117 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 24 | TCGTemp *src_ts = arg_temp(src); |
118 | 25 | @@ -XXX,XX +XXX,XX @@ static void tcg_opt_gen_mov(OptContext *ctx, TCGOp *op, TCGArg dst, TCGArg src) | |
119 | switch (opc) { | 26 | |
120 | case INDEX_op_call: | 27 | if (ts_are_copies(dst_ts, src_ts)) { |
121 | - t0 = tci_read_ri(regs, &tb_ptr); | 28 | tcg_op_remove(ctx->tcg, op); |
122 | + t0 = tci_read_i(&tb_ptr); | 29 | - return; |
123 | tci_tb_ptr = (uintptr_t)tb_ptr; | 30 | + return true; |
124 | #if TCG_TARGET_REG_BITS == 32 | 31 | } |
125 | tmp64 = ((helper_function)t0)(tci_read_reg(regs, TCG_REG_R0), | 32 | |
126 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 33 | reset_ts(dst_ts); |
127 | case INDEX_op_setcond_i32: | 34 | @@ -XXX,XX +XXX,XX @@ static void tcg_opt_gen_mov(OptContext *ctx, TCGOp *op, TCGArg dst, TCGArg src) |
128 | t0 = *tb_ptr++; | 35 | di->is_const = si->is_const; |
129 | t1 = tci_read_r32(regs, &tb_ptr); | 36 | di->val = si->val; |
130 | - t2 = tci_read_ri32(regs, &tb_ptr); | 37 | } |
131 | + t2 = tci_read_r32(regs, &tb_ptr); | 38 | + return true; |
132 | condition = *tb_ptr++; | ||
133 | tci_write_reg(regs, t0, tci_compare32(t1, t2, condition)); | ||
134 | break; | ||
135 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | ||
136 | case INDEX_op_setcond2_i32: | ||
137 | t0 = *tb_ptr++; | ||
138 | tmp64 = tci_read_r64(regs, &tb_ptr); | ||
139 | - v64 = tci_read_ri64(regs, &tb_ptr); | ||
140 | + v64 = tci_read_r64(regs, &tb_ptr); | ||
141 | condition = *tb_ptr++; | ||
142 | tci_write_reg(regs, t0, tci_compare64(tmp64, v64, condition)); | ||
143 | break; | ||
144 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | ||
145 | case INDEX_op_setcond_i64: | ||
146 | t0 = *tb_ptr++; | ||
147 | t1 = tci_read_r64(regs, &tb_ptr); | ||
148 | - t2 = tci_read_ri64(regs, &tb_ptr); | ||
149 | + t2 = tci_read_r64(regs, &tb_ptr); | ||
150 | condition = *tb_ptr++; | ||
151 | tci_write_reg(regs, t0, tci_compare64(t1, t2, condition)); | ||
152 | break; | ||
153 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | ||
154 | |||
155 | case INDEX_op_add_i32: | ||
156 | t0 = *tb_ptr++; | ||
157 | - t1 = tci_read_ri32(regs, &tb_ptr); | ||
158 | - t2 = tci_read_ri32(regs, &tb_ptr); | ||
159 | + t1 = tci_read_r32(regs, &tb_ptr); | ||
160 | + t2 = tci_read_r32(regs, &tb_ptr); | ||
161 | tci_write_reg(regs, t0, t1 + t2); | ||
162 | break; | ||
163 | case INDEX_op_sub_i32: | ||
164 | t0 = *tb_ptr++; | ||
165 | - t1 = tci_read_ri32(regs, &tb_ptr); | ||
166 | - t2 = tci_read_ri32(regs, &tb_ptr); | ||
167 | + t1 = tci_read_r32(regs, &tb_ptr); | ||
168 | + t2 = tci_read_r32(regs, &tb_ptr); | ||
169 | tci_write_reg(regs, t0, t1 - t2); | ||
170 | break; | ||
171 | case INDEX_op_mul_i32: | ||
172 | t0 = *tb_ptr++; | ||
173 | - t1 = tci_read_ri32(regs, &tb_ptr); | ||
174 | - t2 = tci_read_ri32(regs, &tb_ptr); | ||
175 | + t1 = tci_read_r32(regs, &tb_ptr); | ||
176 | + t2 = tci_read_r32(regs, &tb_ptr); | ||
177 | tci_write_reg(regs, t0, t1 * t2); | ||
178 | break; | ||
179 | case INDEX_op_div_i32: | ||
180 | t0 = *tb_ptr++; | ||
181 | - t1 = tci_read_ri32(regs, &tb_ptr); | ||
182 | - t2 = tci_read_ri32(regs, &tb_ptr); | ||
183 | + t1 = tci_read_r32(regs, &tb_ptr); | ||
184 | + t2 = tci_read_r32(regs, &tb_ptr); | ||
185 | tci_write_reg(regs, t0, (int32_t)t1 / (int32_t)t2); | ||
186 | break; | ||
187 | case INDEX_op_divu_i32: | ||
188 | t0 = *tb_ptr++; | ||
189 | - t1 = tci_read_ri32(regs, &tb_ptr); | ||
190 | - t2 = tci_read_ri32(regs, &tb_ptr); | ||
191 | + t1 = tci_read_r32(regs, &tb_ptr); | ||
192 | + t2 = tci_read_r32(regs, &tb_ptr); | ||
193 | tci_write_reg(regs, t0, t1 / t2); | ||
194 | break; | ||
195 | case INDEX_op_rem_i32: | ||
196 | t0 = *tb_ptr++; | ||
197 | - t1 = tci_read_ri32(regs, &tb_ptr); | ||
198 | - t2 = tci_read_ri32(regs, &tb_ptr); | ||
199 | + t1 = tci_read_r32(regs, &tb_ptr); | ||
200 | + t2 = tci_read_r32(regs, &tb_ptr); | ||
201 | tci_write_reg(regs, t0, (int32_t)t1 % (int32_t)t2); | ||
202 | break; | ||
203 | case INDEX_op_remu_i32: | ||
204 | t0 = *tb_ptr++; | ||
205 | - t1 = tci_read_ri32(regs, &tb_ptr); | ||
206 | - t2 = tci_read_ri32(regs, &tb_ptr); | ||
207 | + t1 = tci_read_r32(regs, &tb_ptr); | ||
208 | + t2 = tci_read_r32(regs, &tb_ptr); | ||
209 | tci_write_reg(regs, t0, t1 % t2); | ||
210 | break; | ||
211 | case INDEX_op_and_i32: | ||
212 | t0 = *tb_ptr++; | ||
213 | - t1 = tci_read_ri32(regs, &tb_ptr); | ||
214 | - t2 = tci_read_ri32(regs, &tb_ptr); | ||
215 | + t1 = tci_read_r32(regs, &tb_ptr); | ||
216 | + t2 = tci_read_r32(regs, &tb_ptr); | ||
217 | tci_write_reg(regs, t0, t1 & t2); | ||
218 | break; | ||
219 | case INDEX_op_or_i32: | ||
220 | t0 = *tb_ptr++; | ||
221 | - t1 = tci_read_ri32(regs, &tb_ptr); | ||
222 | - t2 = tci_read_ri32(regs, &tb_ptr); | ||
223 | + t1 = tci_read_r32(regs, &tb_ptr); | ||
224 | + t2 = tci_read_r32(regs, &tb_ptr); | ||
225 | tci_write_reg(regs, t0, t1 | t2); | ||
226 | break; | ||
227 | case INDEX_op_xor_i32: | ||
228 | t0 = *tb_ptr++; | ||
229 | - t1 = tci_read_ri32(regs, &tb_ptr); | ||
230 | - t2 = tci_read_ri32(regs, &tb_ptr); | ||
231 | + t1 = tci_read_r32(regs, &tb_ptr); | ||
232 | + t2 = tci_read_r32(regs, &tb_ptr); | ||
233 | tci_write_reg(regs, t0, t1 ^ t2); | ||
234 | break; | ||
235 | |||
236 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | ||
237 | |||
238 | case INDEX_op_shl_i32: | ||
239 | t0 = *tb_ptr++; | ||
240 | - t1 = tci_read_ri32(regs, &tb_ptr); | ||
241 | - t2 = tci_read_ri32(regs, &tb_ptr); | ||
242 | + t1 = tci_read_r32(regs, &tb_ptr); | ||
243 | + t2 = tci_read_r32(regs, &tb_ptr); | ||
244 | tci_write_reg(regs, t0, t1 << (t2 & 31)); | ||
245 | break; | ||
246 | case INDEX_op_shr_i32: | ||
247 | t0 = *tb_ptr++; | ||
248 | - t1 = tci_read_ri32(regs, &tb_ptr); | ||
249 | - t2 = tci_read_ri32(regs, &tb_ptr); | ||
250 | + t1 = tci_read_r32(regs, &tb_ptr); | ||
251 | + t2 = tci_read_r32(regs, &tb_ptr); | ||
252 | tci_write_reg(regs, t0, t1 >> (t2 & 31)); | ||
253 | break; | ||
254 | case INDEX_op_sar_i32: | ||
255 | t0 = *tb_ptr++; | ||
256 | - t1 = tci_read_ri32(regs, &tb_ptr); | ||
257 | - t2 = tci_read_ri32(regs, &tb_ptr); | ||
258 | + t1 = tci_read_r32(regs, &tb_ptr); | ||
259 | + t2 = tci_read_r32(regs, &tb_ptr); | ||
260 | tci_write_reg(regs, t0, ((int32_t)t1 >> (t2 & 31))); | ||
261 | break; | ||
262 | #if TCG_TARGET_HAS_rot_i32 | ||
263 | case INDEX_op_rotl_i32: | ||
264 | t0 = *tb_ptr++; | ||
265 | - t1 = tci_read_ri32(regs, &tb_ptr); | ||
266 | - t2 = tci_read_ri32(regs, &tb_ptr); | ||
267 | + t1 = tci_read_r32(regs, &tb_ptr); | ||
268 | + t2 = tci_read_r32(regs, &tb_ptr); | ||
269 | tci_write_reg(regs, t0, rol32(t1, t2 & 31)); | ||
270 | break; | ||
271 | case INDEX_op_rotr_i32: | ||
272 | t0 = *tb_ptr++; | ||
273 | - t1 = tci_read_ri32(regs, &tb_ptr); | ||
274 | - t2 = tci_read_ri32(regs, &tb_ptr); | ||
275 | + t1 = tci_read_r32(regs, &tb_ptr); | ||
276 | + t2 = tci_read_r32(regs, &tb_ptr); | ||
277 | tci_write_reg(regs, t0, ror32(t1, t2 & 31)); | ||
278 | break; | ||
279 | #endif | ||
280 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | ||
281 | #endif | ||
282 | case INDEX_op_brcond_i32: | ||
283 | t0 = tci_read_r32(regs, &tb_ptr); | ||
284 | - t1 = tci_read_ri32(regs, &tb_ptr); | ||
285 | + t1 = tci_read_r32(regs, &tb_ptr); | ||
286 | condition = *tb_ptr++; | ||
287 | label = tci_read_label(&tb_ptr); | ||
288 | if (tci_compare32(t0, t1, condition)) { | ||
289 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | ||
290 | break; | ||
291 | case INDEX_op_brcond2_i32: | ||
292 | tmp64 = tci_read_r64(regs, &tb_ptr); | ||
293 | - v64 = tci_read_ri64(regs, &tb_ptr); | ||
294 | + v64 = tci_read_r64(regs, &tb_ptr); | ||
295 | condition = *tb_ptr++; | ||
296 | label = tci_read_label(&tb_ptr); | ||
297 | if (tci_compare64(tmp64, v64, condition)) { | ||
298 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | ||
299 | |||
300 | case INDEX_op_add_i64: | ||
301 | t0 = *tb_ptr++; | ||
302 | - t1 = tci_read_ri64(regs, &tb_ptr); | ||
303 | - t2 = tci_read_ri64(regs, &tb_ptr); | ||
304 | + t1 = tci_read_r64(regs, &tb_ptr); | ||
305 | + t2 = tci_read_r64(regs, &tb_ptr); | ||
306 | tci_write_reg(regs, t0, t1 + t2); | ||
307 | break; | ||
308 | case INDEX_op_sub_i64: | ||
309 | t0 = *tb_ptr++; | ||
310 | - t1 = tci_read_ri64(regs, &tb_ptr); | ||
311 | - t2 = tci_read_ri64(regs, &tb_ptr); | ||
312 | + t1 = tci_read_r64(regs, &tb_ptr); | ||
313 | + t2 = tci_read_r64(regs, &tb_ptr); | ||
314 | tci_write_reg(regs, t0, t1 - t2); | ||
315 | break; | ||
316 | case INDEX_op_mul_i64: | ||
317 | t0 = *tb_ptr++; | ||
318 | - t1 = tci_read_ri64(regs, &tb_ptr); | ||
319 | - t2 = tci_read_ri64(regs, &tb_ptr); | ||
320 | + t1 = tci_read_r64(regs, &tb_ptr); | ||
321 | + t2 = tci_read_r64(regs, &tb_ptr); | ||
322 | tci_write_reg(regs, t0, t1 * t2); | ||
323 | break; | ||
324 | case INDEX_op_div_i64: | ||
325 | t0 = *tb_ptr++; | ||
326 | - t1 = tci_read_ri64(regs, &tb_ptr); | ||
327 | - t2 = tci_read_ri64(regs, &tb_ptr); | ||
328 | + t1 = tci_read_r64(regs, &tb_ptr); | ||
329 | + t2 = tci_read_r64(regs, &tb_ptr); | ||
330 | tci_write_reg(regs, t0, (int64_t)t1 / (int64_t)t2); | ||
331 | break; | ||
332 | case INDEX_op_divu_i64: | ||
333 | t0 = *tb_ptr++; | ||
334 | - t1 = tci_read_ri64(regs, &tb_ptr); | ||
335 | - t2 = tci_read_ri64(regs, &tb_ptr); | ||
336 | + t1 = tci_read_r64(regs, &tb_ptr); | ||
337 | + t2 = tci_read_r64(regs, &tb_ptr); | ||
338 | tci_write_reg(regs, t0, (uint64_t)t1 / (uint64_t)t2); | ||
339 | break; | ||
340 | case INDEX_op_rem_i64: | ||
341 | t0 = *tb_ptr++; | ||
342 | - t1 = tci_read_ri64(regs, &tb_ptr); | ||
343 | - t2 = tci_read_ri64(regs, &tb_ptr); | ||
344 | + t1 = tci_read_r64(regs, &tb_ptr); | ||
345 | + t2 = tci_read_r64(regs, &tb_ptr); | ||
346 | tci_write_reg(regs, t0, (int64_t)t1 % (int64_t)t2); | ||
347 | break; | ||
348 | case INDEX_op_remu_i64: | ||
349 | t0 = *tb_ptr++; | ||
350 | - t1 = tci_read_ri64(regs, &tb_ptr); | ||
351 | - t2 = tci_read_ri64(regs, &tb_ptr); | ||
352 | + t1 = tci_read_r64(regs, &tb_ptr); | ||
353 | + t2 = tci_read_r64(regs, &tb_ptr); | ||
354 | tci_write_reg(regs, t0, (uint64_t)t1 % (uint64_t)t2); | ||
355 | break; | ||
356 | case INDEX_op_and_i64: | ||
357 | t0 = *tb_ptr++; | ||
358 | - t1 = tci_read_ri64(regs, &tb_ptr); | ||
359 | - t2 = tci_read_ri64(regs, &tb_ptr); | ||
360 | + t1 = tci_read_r64(regs, &tb_ptr); | ||
361 | + t2 = tci_read_r64(regs, &tb_ptr); | ||
362 | tci_write_reg(regs, t0, t1 & t2); | ||
363 | break; | ||
364 | case INDEX_op_or_i64: | ||
365 | t0 = *tb_ptr++; | ||
366 | - t1 = tci_read_ri64(regs, &tb_ptr); | ||
367 | - t2 = tci_read_ri64(regs, &tb_ptr); | ||
368 | + t1 = tci_read_r64(regs, &tb_ptr); | ||
369 | + t2 = tci_read_r64(regs, &tb_ptr); | ||
370 | tci_write_reg(regs, t0, t1 | t2); | ||
371 | break; | ||
372 | case INDEX_op_xor_i64: | ||
373 | t0 = *tb_ptr++; | ||
374 | - t1 = tci_read_ri64(regs, &tb_ptr); | ||
375 | - t2 = tci_read_ri64(regs, &tb_ptr); | ||
376 | + t1 = tci_read_r64(regs, &tb_ptr); | ||
377 | + t2 = tci_read_r64(regs, &tb_ptr); | ||
378 | tci_write_reg(regs, t0, t1 ^ t2); | ||
379 | break; | ||
380 | |||
381 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | ||
382 | |||
383 | case INDEX_op_shl_i64: | ||
384 | t0 = *tb_ptr++; | ||
385 | - t1 = tci_read_ri64(regs, &tb_ptr); | ||
386 | - t2 = tci_read_ri64(regs, &tb_ptr); | ||
387 | + t1 = tci_read_r64(regs, &tb_ptr); | ||
388 | + t2 = tci_read_r64(regs, &tb_ptr); | ||
389 | tci_write_reg(regs, t0, t1 << (t2 & 63)); | ||
390 | break; | ||
391 | case INDEX_op_shr_i64: | ||
392 | t0 = *tb_ptr++; | ||
393 | - t1 = tci_read_ri64(regs, &tb_ptr); | ||
394 | - t2 = tci_read_ri64(regs, &tb_ptr); | ||
395 | + t1 = tci_read_r64(regs, &tb_ptr); | ||
396 | + t2 = tci_read_r64(regs, &tb_ptr); | ||
397 | tci_write_reg(regs, t0, t1 >> (t2 & 63)); | ||
398 | break; | ||
399 | case INDEX_op_sar_i64: | ||
400 | t0 = *tb_ptr++; | ||
401 | - t1 = tci_read_ri64(regs, &tb_ptr); | ||
402 | - t2 = tci_read_ri64(regs, &tb_ptr); | ||
403 | + t1 = tci_read_r64(regs, &tb_ptr); | ||
404 | + t2 = tci_read_r64(regs, &tb_ptr); | ||
405 | tci_write_reg(regs, t0, ((int64_t)t1 >> (t2 & 63))); | ||
406 | break; | ||
407 | #if TCG_TARGET_HAS_rot_i64 | ||
408 | case INDEX_op_rotl_i64: | ||
409 | t0 = *tb_ptr++; | ||
410 | - t1 = tci_read_ri64(regs, &tb_ptr); | ||
411 | - t2 = tci_read_ri64(regs, &tb_ptr); | ||
412 | + t1 = tci_read_r64(regs, &tb_ptr); | ||
413 | + t2 = tci_read_r64(regs, &tb_ptr); | ||
414 | tci_write_reg(regs, t0, rol64(t1, t2 & 63)); | ||
415 | break; | ||
416 | case INDEX_op_rotr_i64: | ||
417 | t0 = *tb_ptr++; | ||
418 | - t1 = tci_read_ri64(regs, &tb_ptr); | ||
419 | - t2 = tci_read_ri64(regs, &tb_ptr); | ||
420 | + t1 = tci_read_r64(regs, &tb_ptr); | ||
421 | + t2 = tci_read_r64(regs, &tb_ptr); | ||
422 | tci_write_reg(regs, t0, ror64(t1, t2 & 63)); | ||
423 | break; | ||
424 | #endif | ||
425 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | ||
426 | #endif | ||
427 | case INDEX_op_brcond_i64: | ||
428 | t0 = tci_read_r64(regs, &tb_ptr); | ||
429 | - t1 = tci_read_ri64(regs, &tb_ptr); | ||
430 | + t1 = tci_read_r64(regs, &tb_ptr); | ||
431 | condition = *tb_ptr++; | ||
432 | label = tci_read_label(&tb_ptr); | ||
433 | if (tci_compare64(t0, t1, condition)) { | ||
434 | diff --git a/tcg/tci/tcg-target.c.inc b/tcg/tci/tcg-target.c.inc | ||
435 | index XXXXXXX..XXXXXXX 100644 | ||
436 | --- a/tcg/tci/tcg-target.c.inc | ||
437 | +++ b/tcg/tci/tcg-target.c.inc | ||
438 | @@ -XXX,XX +XXX,XX @@ static TCGConstraintSetIndex tcg_target_op_def(TCGOpcode op) | ||
439 | case INDEX_op_rem_i64: | ||
440 | case INDEX_op_remu_i32: | ||
441 | case INDEX_op_remu_i64: | ||
442 | - return C_O1_I2(r, r, r); | ||
443 | - | ||
444 | case INDEX_op_add_i32: | ||
445 | case INDEX_op_add_i64: | ||
446 | case INDEX_op_sub_i32: | ||
447 | @@ -XXX,XX +XXX,XX @@ static TCGConstraintSetIndex tcg_target_op_def(TCGOpcode op) | ||
448 | case INDEX_op_rotl_i64: | ||
449 | case INDEX_op_rotr_i32: | ||
450 | case INDEX_op_rotr_i64: | ||
451 | - /* TODO: Does R, RI, RI result in faster code than R, R, RI? */ | ||
452 | - return C_O1_I2(r, ri, ri); | ||
453 | + case INDEX_op_setcond_i32: | ||
454 | + case INDEX_op_setcond_i64: | ||
455 | + return C_O1_I2(r, r, r); | ||
456 | |||
457 | case INDEX_op_deposit_i32: | ||
458 | case INDEX_op_deposit_i64: | ||
459 | @@ -XXX,XX +XXX,XX @@ static TCGConstraintSetIndex tcg_target_op_def(TCGOpcode op) | ||
460 | |||
461 | case INDEX_op_brcond_i32: | ||
462 | case INDEX_op_brcond_i64: | ||
463 | - return C_O0_I2(r, ri); | ||
464 | - | ||
465 | - case INDEX_op_setcond_i32: | ||
466 | - case INDEX_op_setcond_i64: | ||
467 | - return C_O1_I2(r, r, ri); | ||
468 | + return C_O0_I2(r, r); | ||
469 | |||
470 | #if TCG_TARGET_REG_BITS == 32 | ||
471 | /* TODO: Support R, R, R, R, RI, RI? Will it be faster? */ | ||
472 | @@ -XXX,XX +XXX,XX @@ static TCGConstraintSetIndex tcg_target_op_def(TCGOpcode op) | ||
473 | case INDEX_op_sub2_i32: | ||
474 | return C_O2_I4(r, r, r, r, r, r); | ||
475 | case INDEX_op_brcond2_i32: | ||
476 | - return C_O0_I4(r, r, ri, ri); | ||
477 | + return C_O0_I4(r, r, r, r); | ||
478 | case INDEX_op_mulu2_i32: | ||
479 | return C_O2_I2(r, r, r, r); | ||
480 | case INDEX_op_setcond2_i32: | ||
481 | - return C_O1_I4(r, r, r, ri, ri); | ||
482 | + return C_O1_I4(r, r, r, r, r); | ||
483 | #endif | ||
484 | |||
485 | case INDEX_op_qemu_ld_i32: | ||
486 | @@ -XXX,XX +XXX,XX @@ static void tcg_out_r(TCGContext *s, TCGArg t0) | ||
487 | tcg_out8(s, t0); | ||
488 | } | 39 | } |
489 | 40 | ||
490 | -/* Write register or constant (native size). */ | 41 | -static void tcg_opt_gen_movi(OptContext *ctx, TCGOp *op, |
491 | -static void tcg_out_ri(TCGContext *s, int const_arg, TCGArg arg) | 42 | +static bool tcg_opt_gen_movi(OptContext *ctx, TCGOp *op, |
492 | -{ | 43 | TCGArg dst, uint64_t val) |
493 | - if (const_arg) { | ||
494 | - tcg_debug_assert(const_arg == 1); | ||
495 | - tcg_out8(s, TCG_CONST); | ||
496 | - tcg_out_i(s, arg); | ||
497 | - } else { | ||
498 | - tcg_out_r(s, arg); | ||
499 | - } | ||
500 | -} | ||
501 | - | ||
502 | -/* Write register or constant (32 bit). */ | ||
503 | -static void tcg_out_ri32(TCGContext *s, int const_arg, TCGArg arg) | ||
504 | -{ | ||
505 | - if (const_arg) { | ||
506 | - tcg_debug_assert(const_arg == 1); | ||
507 | - tcg_out8(s, TCG_CONST); | ||
508 | - tcg_out32(s, arg); | ||
509 | - } else { | ||
510 | - tcg_out_r(s, arg); | ||
511 | - } | ||
512 | -} | ||
513 | - | ||
514 | -#if TCG_TARGET_REG_BITS == 64 | ||
515 | -/* Write register or constant (64 bit). */ | ||
516 | -static void tcg_out_ri64(TCGContext *s, int const_arg, TCGArg arg) | ||
517 | -{ | ||
518 | - if (const_arg) { | ||
519 | - tcg_debug_assert(const_arg == 1); | ||
520 | - tcg_out8(s, TCG_CONST); | ||
521 | - tcg_out64(s, arg); | ||
522 | - } else { | ||
523 | - tcg_out_r(s, arg); | ||
524 | - } | ||
525 | -} | ||
526 | -#endif | ||
527 | - | ||
528 | /* Write label. */ | ||
529 | static void tci_out_label(TCGContext *s, TCGLabel *label) | ||
530 | { | 44 | { |
531 | @@ -XXX,XX +XXX,XX @@ static inline void tcg_out_call(TCGContext *s, const tcg_insn_unit *arg) | 45 | const TCGOpDef *def = &tcg_op_defs[op->opc]; |
532 | { | 46 | @@ -XXX,XX +XXX,XX @@ static void tcg_opt_gen_movi(OptContext *ctx, TCGOp *op, |
533 | uint8_t *old_code_ptr = s->code_ptr; | 47 | /* Convert movi to mov with constant temp. */ |
534 | tcg_out_op_t(s, INDEX_op_call); | 48 | tv = tcg_constant_internal(type, val); |
535 | - tcg_out_ri(s, 1, (uintptr_t)arg); | 49 | init_ts_info(ctx, tv); |
536 | + tcg_out_i(s, (uintptr_t)arg); | 50 | - tcg_opt_gen_mov(ctx, op, dst, temp_arg(tv)); |
537 | old_code_ptr[1] = s->code_ptr - old_code_ptr; | 51 | + return tcg_opt_gen_mov(ctx, op, dst, temp_arg(tv)); |
538 | } | 52 | } |
539 | 53 | ||
540 | @@ -XXX,XX +XXX,XX @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg *args, | 54 | static uint64_t do_constant_folding_2(TCGOpcode op, uint64_t x, uint64_t y) |
541 | case INDEX_op_setcond_i32: | ||
542 | tcg_out_r(s, args[0]); | ||
543 | tcg_out_r(s, args[1]); | ||
544 | - tcg_out_ri32(s, const_args[2], args[2]); | ||
545 | + tcg_out_r(s, args[2]); | ||
546 | tcg_out8(s, args[3]); /* condition */ | ||
547 | break; | ||
548 | #if TCG_TARGET_REG_BITS == 32 | ||
549 | @@ -XXX,XX +XXX,XX @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg *args, | ||
550 | tcg_out_r(s, args[0]); | ||
551 | tcg_out_r(s, args[1]); | ||
552 | tcg_out_r(s, args[2]); | ||
553 | - tcg_out_ri32(s, const_args[3], args[3]); | ||
554 | - tcg_out_ri32(s, const_args[4], args[4]); | ||
555 | + tcg_out_r(s, args[3]); | ||
556 | + tcg_out_r(s, args[4]); | ||
557 | tcg_out8(s, args[5]); /* condition */ | ||
558 | break; | ||
559 | #elif TCG_TARGET_REG_BITS == 64 | ||
560 | case INDEX_op_setcond_i64: | ||
561 | tcg_out_r(s, args[0]); | ||
562 | tcg_out_r(s, args[1]); | ||
563 | - tcg_out_ri64(s, const_args[2], args[2]); | ||
564 | + tcg_out_r(s, args[2]); | ||
565 | tcg_out8(s, args[3]); /* condition */ | ||
566 | break; | ||
567 | #endif | ||
568 | @@ -XXX,XX +XXX,XX @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg *args, | ||
569 | case INDEX_op_rotl_i32: /* Optional (TCG_TARGET_HAS_rot_i32). */ | ||
570 | case INDEX_op_rotr_i32: /* Optional (TCG_TARGET_HAS_rot_i32). */ | ||
571 | tcg_out_r(s, args[0]); | ||
572 | - tcg_out_ri32(s, const_args[1], args[1]); | ||
573 | - tcg_out_ri32(s, const_args[2], args[2]); | ||
574 | + tcg_out_r(s, args[1]); | ||
575 | + tcg_out_r(s, args[2]); | ||
576 | break; | ||
577 | case INDEX_op_deposit_i32: /* Optional (TCG_TARGET_HAS_deposit_i32). */ | ||
578 | tcg_out_r(s, args[0]); | ||
579 | @@ -XXX,XX +XXX,XX @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg *args, | ||
580 | case INDEX_op_rem_i64: /* Optional (TCG_TARGET_HAS_div_i64). */ | ||
581 | case INDEX_op_remu_i64: /* Optional (TCG_TARGET_HAS_div_i64). */ | ||
582 | tcg_out_r(s, args[0]); | ||
583 | - tcg_out_ri64(s, const_args[1], args[1]); | ||
584 | - tcg_out_ri64(s, const_args[2], args[2]); | ||
585 | + tcg_out_r(s, args[1]); | ||
586 | + tcg_out_r(s, args[2]); | ||
587 | break; | ||
588 | case INDEX_op_deposit_i64: /* Optional (TCG_TARGET_HAS_deposit_i64). */ | ||
589 | tcg_out_r(s, args[0]); | ||
590 | @@ -XXX,XX +XXX,XX @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg *args, | ||
591 | break; | ||
592 | case INDEX_op_brcond_i64: | ||
593 | tcg_out_r(s, args[0]); | ||
594 | - tcg_out_ri64(s, const_args[1], args[1]); | ||
595 | + tcg_out_r(s, args[1]); | ||
596 | tcg_out8(s, args[2]); /* condition */ | ||
597 | tci_out_label(s, arg_label(args[3])); | ||
598 | break; | ||
599 | @@ -XXX,XX +XXX,XX @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg *args, | ||
600 | case INDEX_op_rem_i32: /* Optional (TCG_TARGET_HAS_div_i32). */ | ||
601 | case INDEX_op_remu_i32: /* Optional (TCG_TARGET_HAS_div_i32). */ | ||
602 | tcg_out_r(s, args[0]); | ||
603 | - tcg_out_ri32(s, const_args[1], args[1]); | ||
604 | - tcg_out_ri32(s, const_args[2], args[2]); | ||
605 | + tcg_out_r(s, args[1]); | ||
606 | + tcg_out_r(s, args[2]); | ||
607 | break; | ||
608 | #if TCG_TARGET_REG_BITS == 32 | ||
609 | case INDEX_op_add2_i32: | ||
610 | @@ -XXX,XX +XXX,XX @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg *args, | ||
611 | case INDEX_op_brcond2_i32: | ||
612 | tcg_out_r(s, args[0]); | ||
613 | tcg_out_r(s, args[1]); | ||
614 | - tcg_out_ri32(s, const_args[2], args[2]); | ||
615 | - tcg_out_ri32(s, const_args[3], args[3]); | ||
616 | + tcg_out_r(s, args[2]); | ||
617 | + tcg_out_r(s, args[3]); | ||
618 | tcg_out8(s, args[4]); /* condition */ | ||
619 | tci_out_label(s, arg_label(args[5])); | ||
620 | break; | ||
621 | @@ -XXX,XX +XXX,XX @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg *args, | ||
622 | #endif | ||
623 | case INDEX_op_brcond_i32: | ||
624 | tcg_out_r(s, args[0]); | ||
625 | - tcg_out_ri32(s, const_args[1], args[1]); | ||
626 | + tcg_out_r(s, args[1]); | ||
627 | tcg_out8(s, args[2]); /* condition */ | ||
628 | tci_out_label(s, arg_label(args[3])); | ||
629 | break; | ||
630 | -- | 55 | -- |
631 | 2.25.1 | 56 | 2.25.1 |
632 | 57 | ||
633 | 58 | diff view generated by jsdifflib |
1 | From: Claudio Fontana <cfontana@suse.de> | 1 | Copy z_mask into OptContext, for writeback to the |
---|---|---|---|
2 | first output within the new function. | ||
2 | 3 | ||
3 | cpu_check_watchpoint, watchpoint_address_matches are TCG-only. | ||
4 | |||
5 | Signed-off-by: Claudio Fontana <cfontana@suse.de> | ||
6 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 4 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> |
7 | Message-Id: <20210204163931.7358-13-cfontana@suse.de> | 5 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> |
8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
9 | --- | 7 | --- |
10 | softmmu/physmem.c | 141 +++++++++++++++++++++++----------------------- | 8 | tcg/optimize.c | 49 +++++++++++++++++++++++++++++++++---------------- |
11 | 1 file changed, 72 insertions(+), 69 deletions(-) | 9 | 1 file changed, 33 insertions(+), 16 deletions(-) |
12 | 10 | ||
13 | diff --git a/softmmu/physmem.c b/softmmu/physmem.c | 11 | diff --git a/tcg/optimize.c b/tcg/optimize.c |
14 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/softmmu/physmem.c | 13 | --- a/tcg/optimize.c |
16 | +++ b/softmmu/physmem.c | 14 | +++ b/tcg/optimize.c |
17 | @@ -XXX,XX +XXX,XX @@ void cpu_watchpoint_remove_all(CPUState *cpu, int mask) | 15 | @@ -XXX,XX +XXX,XX @@ typedef struct OptContext { |
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, | ||
18 | } | 26 | } |
19 | } | 27 | } |
20 | 28 | ||
21 | +#ifdef CONFIG_TCG | 29 | +static void finish_folding(OptContext *ctx, TCGOp *op) |
22 | /* Return true if this watchpoint address matches the specified | ||
23 | * access (ie the address range covered by the watchpoint overlaps | ||
24 | * partially or completely with the address range covered by the | ||
25 | @@ -XXX,XX +XXX,XX @@ int cpu_watchpoint_address_matches(CPUState *cpu, vaddr addr, vaddr len) | ||
26 | return ret; | ||
27 | } | ||
28 | |||
29 | +/* Generate a debug exception if a watchpoint has been hit. */ | ||
30 | +void cpu_check_watchpoint(CPUState *cpu, vaddr addr, vaddr len, | ||
31 | + MemTxAttrs attrs, int flags, uintptr_t ra) | ||
32 | +{ | 30 | +{ |
33 | + CPUClass *cc = CPU_GET_CLASS(cpu); | 31 | + const TCGOpDef *def = &tcg_op_defs[op->opc]; |
34 | + CPUWatchpoint *wp; | 32 | + int i, nb_oargs; |
35 | + | 33 | + |
36 | + assert(tcg_enabled()); | 34 | + /* |
37 | + if (cpu->watchpoint_hit) { | 35 | + * For an opcode that ends a BB, reset all temp data. |
38 | + /* | 36 | + * We do no cross-BB optimization. |
39 | + * We re-entered the check after replacing the TB. | 37 | + */ |
40 | + * Now raise the debug interrupt so that it will | 38 | + if (def->flags & TCG_OPF_BB_END) { |
41 | + * trigger after the current instruction. | 39 | + memset(&ctx->temps_used, 0, sizeof(ctx->temps_used)); |
42 | + */ | 40 | + ctx->prev_mb = NULL; |
43 | + qemu_mutex_lock_iothread(); | ||
44 | + cpu_interrupt(cpu, CPU_INTERRUPT_DEBUG); | ||
45 | + qemu_mutex_unlock_iothread(); | ||
46 | + return; | 41 | + return; |
47 | + } | 42 | + } |
48 | + | 43 | + |
49 | + addr = cc->adjust_watchpoint_address(cpu, addr, len); | 44 | + nb_oargs = def->nb_oargs; |
50 | + QTAILQ_FOREACH(wp, &cpu->watchpoints, entry) { | 45 | + for (i = 0; i < nb_oargs; i++) { |
51 | + if (watchpoint_address_matches(wp, addr, len) | 46 | + reset_temp(op->args[i]); |
52 | + && (wp->flags & flags)) { | 47 | + /* |
53 | + if (replay_running_debug()) { | 48 | + * Save the corresponding known-zero bits mask for the |
54 | + /* | 49 | + * first output argument (only one supported so far). |
55 | + * Don't process the watchpoints when we are | 50 | + */ |
56 | + * in a reverse debugging operation. | 51 | + if (i == 0) { |
57 | + */ | 52 | + arg_info(op->args[i])->z_mask = ctx->z_mask; |
58 | + replay_breakpoint(); | ||
59 | + return; | ||
60 | + } | ||
61 | + if (flags == BP_MEM_READ) { | ||
62 | + wp->flags |= BP_WATCHPOINT_HIT_READ; | ||
63 | + } else { | ||
64 | + wp->flags |= BP_WATCHPOINT_HIT_WRITE; | ||
65 | + } | ||
66 | + wp->hitaddr = MAX(addr, wp->vaddr); | ||
67 | + wp->hitattrs = attrs; | ||
68 | + if (!cpu->watchpoint_hit) { | ||
69 | + if (wp->flags & BP_CPU && | ||
70 | + !cc->debug_check_watchpoint(cpu, wp)) { | ||
71 | + wp->flags &= ~BP_WATCHPOINT_HIT; | ||
72 | + continue; | ||
73 | + } | ||
74 | + cpu->watchpoint_hit = wp; | ||
75 | + | ||
76 | + mmap_lock(); | ||
77 | + tb_check_watchpoint(cpu, ra); | ||
78 | + if (wp->flags & BP_STOP_BEFORE_ACCESS) { | ||
79 | + cpu->exception_index = EXCP_DEBUG; | ||
80 | + mmap_unlock(); | ||
81 | + cpu_loop_exit_restore(cpu, ra); | ||
82 | + } else { | ||
83 | + /* Force execution of one insn next time. */ | ||
84 | + cpu->cflags_next_tb = 1 | curr_cflags(); | ||
85 | + mmap_unlock(); | ||
86 | + if (ra) { | ||
87 | + cpu_restore_state(cpu, ra, true); | ||
88 | + } | ||
89 | + cpu_loop_exit_noexc(cpu); | ||
90 | + } | ||
91 | + } | ||
92 | + } else { | ||
93 | + wp->flags &= ~BP_WATCHPOINT_HIT; | ||
94 | + } | 53 | + } |
95 | + } | 54 | + } |
96 | +} | 55 | +} |
97 | + | 56 | + |
98 | +#endif /* CONFIG_TCG */ | 57 | static bool fold_call(OptContext *ctx, TCGOp *op) |
99 | + | ||
100 | /* Called from RCU critical section */ | ||
101 | static RAMBlock *qemu_get_ram_block(ram_addr_t addr) | ||
102 | { | 58 | { |
103 | @@ -XXX,XX +XXX,XX @@ ram_addr_t qemu_ram_addr_from_host(void *ptr) | 59 | TCGContext *s = ctx->tcg; |
104 | return block->offset + offset; | 60 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) |
105 | } | 61 | partmask &= 0xffffffffu; |
106 | 62 | affected &= 0xffffffffu; | |
107 | -/* Generate a debug exception if a watchpoint has been hit. */ | 63 | } |
108 | -void cpu_check_watchpoint(CPUState *cpu, vaddr addr, vaddr len, | 64 | + ctx.z_mask = z_mask; |
109 | - MemTxAttrs attrs, int flags, uintptr_t ra) | 65 | |
110 | -{ | 66 | if (partmask == 0) { |
111 | - CPUClass *cc = CPU_GET_CLASS(cpu); | 67 | tcg_opt_gen_movi(&ctx, op, op->args[0], 0); |
112 | - CPUWatchpoint *wp; | 68 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) |
113 | - | 69 | break; |
114 | - assert(tcg_enabled()); | 70 | } |
115 | - if (cpu->watchpoint_hit) { | 71 | |
116 | - /* | 72 | - /* Some of the folding above can change opc. */ |
117 | - * We re-entered the check after replacing the TB. | 73 | - opc = op->opc; |
118 | - * Now raise the debug interrupt so that it will | 74 | - def = &tcg_op_defs[opc]; |
119 | - * trigger after the current instruction. | 75 | - if (def->flags & TCG_OPF_BB_END) { |
120 | - */ | 76 | - memset(&ctx.temps_used, 0, sizeof(ctx.temps_used)); |
121 | - qemu_mutex_lock_iothread(); | 77 | - } else { |
122 | - cpu_interrupt(cpu, CPU_INTERRUPT_DEBUG); | 78 | - int nb_oargs = def->nb_oargs; |
123 | - qemu_mutex_unlock_iothread(); | 79 | - for (i = 0; i < nb_oargs; i++) { |
124 | - return; | 80 | - reset_temp(op->args[i]); |
125 | - } | 81 | - /* Save the corresponding known-zero bits mask for the |
126 | - | 82 | - first output argument (only one supported so far). */ |
127 | - addr = cc->adjust_watchpoint_address(cpu, addr, len); | 83 | - if (i == 0) { |
128 | - QTAILQ_FOREACH(wp, &cpu->watchpoints, entry) { | 84 | - arg_info(op->args[i])->z_mask = z_mask; |
129 | - if (watchpoint_address_matches(wp, addr, len) | ||
130 | - && (wp->flags & flags)) { | ||
131 | - if (replay_running_debug()) { | ||
132 | - /* | ||
133 | - * Don't process the watchpoints when we are | ||
134 | - * in a reverse debugging operation. | ||
135 | - */ | ||
136 | - replay_breakpoint(); | ||
137 | - return; | ||
138 | - } | ||
139 | - if (flags == BP_MEM_READ) { | ||
140 | - wp->flags |= BP_WATCHPOINT_HIT_READ; | ||
141 | - } else { | ||
142 | - wp->flags |= BP_WATCHPOINT_HIT_WRITE; | ||
143 | - } | ||
144 | - wp->hitaddr = MAX(addr, wp->vaddr); | ||
145 | - wp->hitattrs = attrs; | ||
146 | - if (!cpu->watchpoint_hit) { | ||
147 | - if (wp->flags & BP_CPU && | ||
148 | - !cc->debug_check_watchpoint(cpu, wp)) { | ||
149 | - wp->flags &= ~BP_WATCHPOINT_HIT; | ||
150 | - continue; | ||
151 | - } | ||
152 | - cpu->watchpoint_hit = wp; | ||
153 | - | ||
154 | - mmap_lock(); | ||
155 | - tb_check_watchpoint(cpu, ra); | ||
156 | - if (wp->flags & BP_STOP_BEFORE_ACCESS) { | ||
157 | - cpu->exception_index = EXCP_DEBUG; | ||
158 | - mmap_unlock(); | ||
159 | - cpu_loop_exit_restore(cpu, ra); | ||
160 | - } else { | ||
161 | - /* Force execution of one insn next time. */ | ||
162 | - cpu->cflags_next_tb = 1 | curr_cflags(); | ||
163 | - mmap_unlock(); | ||
164 | - if (ra) { | ||
165 | - cpu_restore_state(cpu, ra, true); | ||
166 | - } | ||
167 | - cpu_loop_exit_noexc(cpu); | ||
168 | - } | 85 | - } |
169 | - } | 86 | - } |
170 | - } else { | ||
171 | - wp->flags &= ~BP_WATCHPOINT_HIT; | ||
172 | - } | 87 | - } |
173 | - } | 88 | + finish_folding(&ctx, op); |
174 | -} | 89 | |
175 | - | 90 | /* Eliminate duplicate and redundant fence instructions. */ |
176 | static MemTxResult flatview_read(FlatView *fv, hwaddr addr, | 91 | if (ctx.prev_mb) { |
177 | MemTxAttrs attrs, void *buf, hwaddr len); | ||
178 | static MemTxResult flatview_write(FlatView *fv, hwaddr addr, MemTxAttrs attrs, | ||
179 | -- | 92 | -- |
180 | 2.25.1 | 93 | 2.25.1 |
181 | 94 | ||
182 | 95 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | ||
2 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | ||
3 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
5 | --- | ||
6 | tcg/optimize.c | 9 ++++++--- | ||
7 | 1 file changed, 6 insertions(+), 3 deletions(-) | ||
1 | 8 | ||
9 | diff --git a/tcg/optimize.c b/tcg/optimize.c | ||
10 | index XXXXXXX..XXXXXXX 100644 | ||
11 | --- a/tcg/optimize.c | ||
12 | +++ b/tcg/optimize.c | ||
13 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
14 | uint64_t z_mask, partmask, affected, tmp; | ||
15 | TCGOpcode opc = op->opc; | ||
16 | const TCGOpDef *def; | ||
17 | + bool done = false; | ||
18 | |||
19 | /* Calls are special. */ | ||
20 | if (opc == INDEX_op_call) { | ||
21 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
22 | allocator where needed and possible. Also detect copies. */ | ||
23 | switch (opc) { | ||
24 | CASE_OP_32_64_VEC(mov): | ||
25 | - tcg_opt_gen_mov(&ctx, op, op->args[0], op->args[1]); | ||
26 | - continue; | ||
27 | + done = tcg_opt_gen_mov(&ctx, op, op->args[0], op->args[1]); | ||
28 | + break; | ||
29 | |||
30 | case INDEX_op_dup_vec: | ||
31 | if (arg_is_const(op->args[1])) { | ||
32 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
33 | break; | ||
34 | } | ||
35 | |||
36 | - finish_folding(&ctx, op); | ||
37 | + if (!done) { | ||
38 | + finish_folding(&ctx, op); | ||
39 | + } | ||
40 | |||
41 | /* Eliminate duplicate and redundant fence instructions. */ | ||
42 | if (ctx.prev_mb) { | ||
43 | -- | ||
44 | 2.25.1 | ||
45 | |||
46 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | This puts the separate mb optimization into the same framework | ||
2 | as the others. While fold_qemu_{ld,st} are currently identical, | ||
3 | that won't last as more code gets moved. | ||
1 | 4 | ||
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> | ||
8 | --- | ||
9 | tcg/optimize.c | 89 +++++++++++++++++++++++++++++--------------------- | ||
10 | 1 file changed, 51 insertions(+), 38 deletions(-) | ||
11 | |||
12 | diff --git a/tcg/optimize.c b/tcg/optimize.c | ||
13 | index XXXXXXX..XXXXXXX 100644 | ||
14 | --- a/tcg/optimize.c | ||
15 | +++ b/tcg/optimize.c | ||
16 | @@ -XXX,XX +XXX,XX @@ static bool fold_call(OptContext *ctx, TCGOp *op) | ||
17 | return true; | ||
18 | } | ||
19 | |||
20 | +static bool fold_mb(OptContext *ctx, TCGOp *op) | ||
21 | +{ | ||
22 | + /* Eliminate duplicate and redundant fence instructions. */ | ||
23 | + if (ctx->prev_mb) { | ||
24 | + /* | ||
25 | + * Merge two barriers of the same type into one, | ||
26 | + * or a weaker barrier into a stronger one, | ||
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 | { | ||
61 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
62 | } | ||
63 | break; | ||
64 | |||
65 | + case INDEX_op_mb: | ||
66 | + done = fold_mb(&ctx, op); | ||
67 | + break; | ||
68 | + case INDEX_op_qemu_ld_i32: | ||
69 | + case INDEX_op_qemu_ld_i64: | ||
70 | + done = fold_qemu_ld(&ctx, op); | ||
71 | + break; | ||
72 | + case INDEX_op_qemu_st_i32: | ||
73 | + case INDEX_op_qemu_st8_i32: | ||
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 | - | ||
86 | - /* Eliminate duplicate and redundant fence instructions. */ | ||
87 | - if (ctx.prev_mb) { | ||
88 | - switch (opc) { | ||
89 | - case INDEX_op_mb: | ||
90 | - /* Merge two barriers of the same type into one, | ||
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 | - | ||
105 | - default: | ||
106 | - /* Opcodes that end the block stop the optimization. */ | ||
107 | - if ((def->flags & TCG_OPF_BB_END) == 0) { | ||
108 | - break; | ||
109 | - } | ||
110 | - /* fallthru */ | ||
111 | - case INDEX_op_qemu_ld_i32: | ||
112 | - case INDEX_op_qemu_ld_i64: | ||
113 | - case INDEX_op_qemu_st_i32: | ||
114 | - case INDEX_op_qemu_st8_i32: | ||
115 | - case INDEX_op_qemu_st_i64: | ||
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 | - } | ||
123 | } | ||
124 | } | ||
125 | -- | ||
126 | 2.25.1 | ||
127 | |||
128 | diff view generated by jsdifflib |
1 | From: Claudio Fontana <cfontana@suse.de> | 1 | Split out a whole bunch of placeholder functions, which are |
---|---|---|---|
2 | 2 | currently identical. That won't last as more code gets moved. | |
3 | we cannot in principle make the TCG Operations field definitions | 3 | |
4 | conditional on CONFIG_TCG in code that is included by both common_ss | 4 | Use CASE_32_64_VEC for some logical operators that previously |
5 | and specific_ss modules. | 5 | missed the addition of vectors. |
6 | 6 | ||
7 | Therefore, what we can do safely to restrict the TCG fields to TCG-only | 7 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> |
8 | builds, is to move all tcg cpu operations into a separate header file, | 8 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> |
9 | which is only included by TCG, target-specific code. | ||
10 | |||
11 | This leaves just a NULL pointer in the cpu.h for the non-TCG builds. | ||
12 | |||
13 | This also tidies up the code in all targets a bit, having all TCG cpu | ||
14 | operations neatly contained by a dedicated data struct. | ||
15 | |||
16 | Signed-off-by: Claudio Fontana <cfontana@suse.de> | ||
17 | Message-Id: <20210204163931.7358-16-cfontana@suse.de> | ||
18 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 9 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
19 | --- | 10 | --- |
20 | include/hw/core/cpu.h | 103 ++------------------------------ | 11 | tcg/optimize.c | 271 +++++++++++++++++++++++++++++++++++++++---------- |
21 | include/hw/core/tcg-cpu-ops.h | 97 ++++++++++++++++++++++++++++++ | 12 | 1 file changed, 219 insertions(+), 52 deletions(-) |
22 | target/arm/internals.h | 6 ++ | 13 | |
23 | accel/tcg/cpu-exec.c | 27 +++++---- | 14 | diff --git a/tcg/optimize.c b/tcg/optimize.c |
24 | accel/tcg/cputlb.c | 35 +++++++++-- | ||
25 | accel/tcg/user-exec.c | 9 +-- | ||
26 | hw/mips/jazz.c | 7 ++- | ||
27 | softmmu/physmem.c | 13 ++-- | ||
28 | target/alpha/cpu.c | 21 +++++-- | ||
29 | target/arm/cpu.c | 41 ++++++++----- | ||
30 | target/arm/cpu64.c | 7 +-- | ||
31 | target/arm/cpu_tcg.c | 28 +++++++-- | ||
32 | target/avr/cpu.c | 19 ++++-- | ||
33 | target/avr/helper.c | 5 +- | ||
34 | target/cris/cpu.c | 43 ++++++++----- | ||
35 | target/cris/helper.c | 5 +- | ||
36 | target/hppa/cpu.c | 22 ++++--- | ||
37 | target/i386/tcg/tcg-cpu.c | 26 ++++---- | ||
38 | target/lm32/cpu.c | 19 ++++-- | ||
39 | target/m68k/cpu.c | 19 ++++-- | ||
40 | target/microblaze/cpu.c | 25 +++++--- | ||
41 | target/mips/cpu.c | 36 +++++++---- | ||
42 | target/moxie/cpu.c | 15 ++++- | ||
43 | target/nios2/cpu.c | 18 ++++-- | ||
44 | target/openrisc/cpu.c | 17 ++++-- | ||
45 | target/riscv/cpu.c | 23 ++++--- | ||
46 | target/rx/cpu.c | 20 +++++-- | ||
47 | target/s390x/cpu.c | 33 ++++++---- | ||
48 | target/sh4/cpu.c | 21 +++++-- | ||
49 | target/sparc/cpu.c | 25 +++++--- | ||
50 | target/tilegx/cpu.c | 17 ++++-- | ||
51 | target/tricore/cpu.c | 12 +++- | ||
52 | target/unicore32/cpu.c | 17 ++++-- | ||
53 | target/xtensa/cpu.c | 23 ++++--- | ||
54 | target/ppc/translate_init.c.inc | 33 ++++++---- | ||
55 | MAINTAINERS | 1 + | ||
56 | 36 files changed, 582 insertions(+), 306 deletions(-) | ||
57 | create mode 100644 include/hw/core/tcg-cpu-ops.h | ||
58 | |||
59 | diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h | ||
60 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
61 | --- a/include/hw/core/cpu.h | 16 | --- a/tcg/optimize.c |
62 | +++ b/include/hw/core/cpu.h | 17 | +++ b/tcg/optimize.c |
63 | @@ -XXX,XX +XXX,XX @@ typedef struct CPUWatchpoint CPUWatchpoint; | 18 | @@ -XXX,XX +XXX,XX @@ static void finish_folding(OptContext *ctx, TCGOp *op) |
64 | |||
65 | struct TranslationBlock; | ||
66 | |||
67 | -/** | ||
68 | - * struct TcgCpuOperations: TCG operations specific to a CPU class | ||
69 | - */ | ||
70 | -typedef struct TcgCpuOperations { | ||
71 | - /** | ||
72 | - * @initialize: Initalize TCG state | ||
73 | - * | ||
74 | - * Called when the first CPU is realized. | ||
75 | - */ | ||
76 | - void (*initialize)(void); | ||
77 | - /** | ||
78 | - * @synchronize_from_tb: Synchronize state from a TCG #TranslationBlock | ||
79 | - * | ||
80 | - * This is called when we abandon execution of a TB before starting it, | ||
81 | - * and must set all parts of the CPU state which the previous TB in the | ||
82 | - * chain may not have updated. | ||
83 | - * By default, when this is NULL, a call is made to @set_pc(tb->pc). | ||
84 | - * | ||
85 | - * If more state needs to be restored, the target must implement a | ||
86 | - * function to restore all the state, and register it here. | ||
87 | - */ | ||
88 | - void (*synchronize_from_tb)(CPUState *cpu, | ||
89 | - const struct TranslationBlock *tb); | ||
90 | - /** @cpu_exec_enter: Callback for cpu_exec preparation */ | ||
91 | - void (*cpu_exec_enter)(CPUState *cpu); | ||
92 | - /** @cpu_exec_exit: Callback for cpu_exec cleanup */ | ||
93 | - void (*cpu_exec_exit)(CPUState *cpu); | ||
94 | - /** @cpu_exec_interrupt: Callback for processing interrupts in cpu_exec */ | ||
95 | - bool (*cpu_exec_interrupt)(CPUState *cpu, int interrupt_request); | ||
96 | - /** @do_interrupt: Callback for interrupt handling. */ | ||
97 | - void (*do_interrupt)(CPUState *cpu); | ||
98 | - /** | ||
99 | - * @tlb_fill: Handle a softmmu tlb miss or user-only address fault | ||
100 | - * | ||
101 | - * For system mode, if the access is valid, call tlb_set_page | ||
102 | - * and return true; if the access is invalid, and probe is | ||
103 | - * true, return false; otherwise raise an exception and do | ||
104 | - * not return. For user-only mode, always raise an exception | ||
105 | - * and do not return. | ||
106 | - */ | ||
107 | - bool (*tlb_fill)(CPUState *cpu, vaddr address, int size, | ||
108 | - MMUAccessType access_type, int mmu_idx, | ||
109 | - bool probe, uintptr_t retaddr); | ||
110 | - /** @debug_excp_handler: Callback for handling debug exceptions */ | ||
111 | - void (*debug_excp_handler)(CPUState *cpu); | ||
112 | - | ||
113 | - /** | ||
114 | - * @do_transaction_failed: Callback for handling failed memory transactions | ||
115 | - * (ie bus faults or external aborts; not MMU faults) | ||
116 | - */ | ||
117 | - void (*do_transaction_failed)(CPUState *cpu, hwaddr physaddr, vaddr addr, | ||
118 | - unsigned size, MMUAccessType access_type, | ||
119 | - int mmu_idx, MemTxAttrs attrs, | ||
120 | - MemTxResult response, uintptr_t retaddr); | ||
121 | - /** | ||
122 | - * @do_unaligned_access: Callback for unaligned access handling | ||
123 | - */ | ||
124 | - void (*do_unaligned_access)(CPUState *cpu, vaddr addr, | ||
125 | - MMUAccessType access_type, | ||
126 | - int mmu_idx, uintptr_t retaddr); | ||
127 | - /** | ||
128 | - * @adjust_watchpoint_address: hack for cpu_check_watchpoint used by ARM | ||
129 | - */ | ||
130 | - vaddr (*adjust_watchpoint_address)(CPUState *cpu, vaddr addr, int len); | ||
131 | - | ||
132 | - /** | ||
133 | - * @debug_check_watchpoint: return true if the architectural | ||
134 | - * watchpoint whose address has matched should really fire, used by ARM | ||
135 | - */ | ||
136 | - bool (*debug_check_watchpoint)(CPUState *cpu, CPUWatchpoint *wp); | ||
137 | - | ||
138 | -} TcgCpuOperations; | ||
139 | +/* see tcg-cpu-ops.h */ | ||
140 | +struct TCGCPUOps; | ||
141 | |||
142 | /** | ||
143 | * CPUClass: | ||
144 | @@ -XXX,XX +XXX,XX @@ struct CPUClass { | ||
145 | int gdb_num_core_regs; | ||
146 | bool gdb_stop_before_watchpoint; | ||
147 | |||
148 | - TcgCpuOperations tcg_ops; | ||
149 | + /* when TCG is not available, this pointer is NULL */ | ||
150 | + struct TCGCPUOps *tcg_ops; | ||
151 | }; | ||
152 | |||
153 | /* | ||
154 | @@ -XXX,XX +XXX,XX @@ CPUState *cpu_by_arch_id(int64_t id); | ||
155 | |||
156 | void cpu_interrupt(CPUState *cpu, int mask); | ||
157 | |||
158 | -static inline void cpu_unaligned_access(CPUState *cpu, vaddr addr, | ||
159 | - MMUAccessType access_type, | ||
160 | - int mmu_idx, uintptr_t retaddr) | ||
161 | -{ | ||
162 | - CPUClass *cc = CPU_GET_CLASS(cpu); | ||
163 | - | ||
164 | - cc->tcg_ops.do_unaligned_access(cpu, addr, access_type, mmu_idx, retaddr); | ||
165 | -} | ||
166 | - | ||
167 | -static inline void cpu_transaction_failed(CPUState *cpu, hwaddr physaddr, | ||
168 | - vaddr addr, unsigned size, | ||
169 | - MMUAccessType access_type, | ||
170 | - int mmu_idx, MemTxAttrs attrs, | ||
171 | - MemTxResult response, | ||
172 | - uintptr_t retaddr) | ||
173 | -{ | ||
174 | - CPUClass *cc = CPU_GET_CLASS(cpu); | ||
175 | - | ||
176 | - if (!cpu->ignore_memory_transaction_failures && | ||
177 | - cc->tcg_ops.do_transaction_failed) { | ||
178 | - cc->tcg_ops.do_transaction_failed(cpu, physaddr, addr, size, | ||
179 | - access_type, mmu_idx, attrs, | ||
180 | - response, retaddr); | ||
181 | - } | ||
182 | -} | ||
183 | - | ||
184 | /** | ||
185 | * cpu_set_pc: | ||
186 | * @cpu: The CPU to set the program counter for. | ||
187 | diff --git a/include/hw/core/tcg-cpu-ops.h b/include/hw/core/tcg-cpu-ops.h | ||
188 | new file mode 100644 | ||
189 | index XXXXXXX..XXXXXXX | ||
190 | --- /dev/null | ||
191 | +++ b/include/hw/core/tcg-cpu-ops.h | ||
192 | @@ -XXX,XX +XXX,XX @@ | ||
193 | +/* | ||
194 | + * TCG CPU-specific operations | ||
195 | + * | ||
196 | + * Copyright 2021 SUSE LLC | ||
197 | + * | ||
198 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
199 | + * See the COPYING file in the top-level directory. | ||
200 | + */ | ||
201 | + | ||
202 | +#ifndef TCG_CPU_OPS_H | ||
203 | +#define TCG_CPU_OPS_H | ||
204 | + | ||
205 | +#include "hw/core/cpu.h" | ||
206 | + | ||
207 | +struct TCGCPUOps { | ||
208 | + /** | ||
209 | + * @initialize: Initalize TCG state | ||
210 | + * | ||
211 | + * Called when the first CPU is realized. | ||
212 | + */ | ||
213 | + void (*initialize)(void); | ||
214 | + /** | ||
215 | + * @synchronize_from_tb: Synchronize state from a TCG #TranslationBlock | ||
216 | + * | ||
217 | + * This is called when we abandon execution of a TB before starting it, | ||
218 | + * and must set all parts of the CPU state which the previous TB in the | ||
219 | + * chain may not have updated. | ||
220 | + * By default, when this is NULL, a call is made to @set_pc(tb->pc). | ||
221 | + * | ||
222 | + * If more state needs to be restored, the target must implement a | ||
223 | + * function to restore all the state, and register it here. | ||
224 | + */ | ||
225 | + void (*synchronize_from_tb)(CPUState *cpu, | ||
226 | + const struct TranslationBlock *tb); | ||
227 | + /** @cpu_exec_enter: Callback for cpu_exec preparation */ | ||
228 | + void (*cpu_exec_enter)(CPUState *cpu); | ||
229 | + /** @cpu_exec_exit: Callback for cpu_exec cleanup */ | ||
230 | + void (*cpu_exec_exit)(CPUState *cpu); | ||
231 | + /** @cpu_exec_interrupt: Callback for processing interrupts in cpu_exec */ | ||
232 | + bool (*cpu_exec_interrupt)(CPUState *cpu, int interrupt_request); | ||
233 | + /** | ||
234 | + * @do_interrupt: Callback for interrupt handling. | ||
235 | + * | ||
236 | + * note that this is in general SOFTMMU only, but it actually isn't | ||
237 | + * because of an x86 hack (accel/tcg/cpu-exec.c), so we cannot put it | ||
238 | + * in the SOFTMMU section in general. | ||
239 | + */ | ||
240 | + void (*do_interrupt)(CPUState *cpu); | ||
241 | + /** | ||
242 | + * @tlb_fill: Handle a softmmu tlb miss or user-only address fault | ||
243 | + * | ||
244 | + * For system mode, if the access is valid, call tlb_set_page | ||
245 | + * and return true; if the access is invalid, and probe is | ||
246 | + * true, return false; otherwise raise an exception and do | ||
247 | + * not return. For user-only mode, always raise an exception | ||
248 | + * and do not return. | ||
249 | + */ | ||
250 | + bool (*tlb_fill)(CPUState *cpu, vaddr address, int size, | ||
251 | + MMUAccessType access_type, int mmu_idx, | ||
252 | + bool probe, uintptr_t retaddr); | ||
253 | + /** @debug_excp_handler: Callback for handling debug exceptions */ | ||
254 | + void (*debug_excp_handler)(CPUState *cpu); | ||
255 | + | ||
256 | +#ifdef NEED_CPU_H | ||
257 | +#ifdef CONFIG_SOFTMMU | ||
258 | + /** | ||
259 | + * @do_transaction_failed: Callback for handling failed memory transactions | ||
260 | + * (ie bus faults or external aborts; not MMU faults) | ||
261 | + */ | ||
262 | + void (*do_transaction_failed)(CPUState *cpu, hwaddr physaddr, vaddr addr, | ||
263 | + unsigned size, MMUAccessType access_type, | ||
264 | + int mmu_idx, MemTxAttrs attrs, | ||
265 | + MemTxResult response, uintptr_t retaddr); | ||
266 | + /** | ||
267 | + * @do_unaligned_access: Callback for unaligned access handling | ||
268 | + */ | ||
269 | + void (*do_unaligned_access)(CPUState *cpu, vaddr addr, | ||
270 | + MMUAccessType access_type, | ||
271 | + int mmu_idx, uintptr_t retaddr); | ||
272 | + | ||
273 | + /** | ||
274 | + * @adjust_watchpoint_address: hack for cpu_check_watchpoint used by ARM | ||
275 | + */ | ||
276 | + vaddr (*adjust_watchpoint_address)(CPUState *cpu, vaddr addr, int len); | ||
277 | + | ||
278 | + /** | ||
279 | + * @debug_check_watchpoint: return true if the architectural | ||
280 | + * watchpoint whose address has matched should really fire, used by ARM | ||
281 | + */ | ||
282 | + bool (*debug_check_watchpoint)(CPUState *cpu, CPUWatchpoint *wp); | ||
283 | + | ||
284 | +#endif /* CONFIG_SOFTMMU */ | ||
285 | +#endif /* NEED_CPU_H */ | ||
286 | + | ||
287 | +}; | ||
288 | + | ||
289 | +#endif /* TCG_CPU_OPS_H */ | ||
290 | diff --git a/target/arm/internals.h b/target/arm/internals.h | ||
291 | index XXXXXXX..XXXXXXX 100644 | ||
292 | --- a/target/arm/internals.h | ||
293 | +++ b/target/arm/internals.h | ||
294 | @@ -XXX,XX +XXX,XX @@ static inline int r14_bank_number(int mode) | ||
295 | void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu); | ||
296 | void arm_translate_init(void); | ||
297 | |||
298 | +#ifdef CONFIG_TCG | ||
299 | +void arm_cpu_synchronize_from_tb(CPUState *cs, | ||
300 | + const struct TranslationBlock *tb); | ||
301 | +#endif /* CONFIG_TCG */ | ||
302 | + | ||
303 | + | ||
304 | enum arm_fprounding { | ||
305 | FPROUNDING_TIEEVEN, | ||
306 | FPROUNDING_POSINF, | ||
307 | diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c | ||
308 | index XXXXXXX..XXXXXXX 100644 | ||
309 | --- a/accel/tcg/cpu-exec.c | ||
310 | +++ b/accel/tcg/cpu-exec.c | ||
311 | @@ -XXX,XX +XXX,XX @@ | ||
312 | #include "qemu-common.h" | ||
313 | #include "qemu/qemu-print.h" | ||
314 | #include "cpu.h" | ||
315 | +#include "hw/core/tcg-cpu-ops.h" | ||
316 | #include "trace.h" | ||
317 | #include "disas/disas.h" | ||
318 | #include "exec/exec-all.h" | ||
319 | @@ -XXX,XX +XXX,XX @@ cpu_tb_exec(CPUState *cpu, TranslationBlock *itb, int *tb_exit) | ||
320 | TARGET_FMT_lx "] %s\n", | ||
321 | last_tb->tc.ptr, last_tb->pc, | ||
322 | lookup_symbol(last_tb->pc)); | ||
323 | - if (cc->tcg_ops.synchronize_from_tb) { | ||
324 | - cc->tcg_ops.synchronize_from_tb(cpu, last_tb); | ||
325 | + if (cc->tcg_ops->synchronize_from_tb) { | ||
326 | + cc->tcg_ops->synchronize_from_tb(cpu, last_tb); | ||
327 | } else { | ||
328 | assert(cc->set_pc); | ||
329 | cc->set_pc(cpu, last_tb->pc); | ||
330 | @@ -XXX,XX +XXX,XX @@ static void cpu_exec_enter(CPUState *cpu) | ||
331 | { | ||
332 | CPUClass *cc = CPU_GET_CLASS(cpu); | ||
333 | |||
334 | - if (cc->tcg_ops.cpu_exec_enter) { | ||
335 | - cc->tcg_ops.cpu_exec_enter(cpu); | ||
336 | + if (cc->tcg_ops->cpu_exec_enter) { | ||
337 | + cc->tcg_ops->cpu_exec_enter(cpu); | ||
338 | } | 19 | } |
339 | } | 20 | } |
340 | 21 | ||
341 | @@ -XXX,XX +XXX,XX @@ static void cpu_exec_exit(CPUState *cpu) | 22 | +/* |
23 | + * The fold_* functions return true when processing is complete, | ||
24 | + * usually by folding the operation to a constant or to a copy, | ||
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) | ||
342 | { | 77 | { |
343 | CPUClass *cc = CPU_GET_CLASS(cpu); | 78 | TCGContext *s = ctx->tcg; |
344 | 79 | @@ -XXX,XX +XXX,XX @@ static bool fold_call(OptContext *ctx, TCGOp *op) | |
345 | - if (cc->tcg_ops.cpu_exec_exit) { | ||
346 | - cc->tcg_ops.cpu_exec_exit(cpu); | ||
347 | + if (cc->tcg_ops->cpu_exec_exit) { | ||
348 | + cc->tcg_ops->cpu_exec_exit(cpu); | ||
349 | } | ||
350 | } | ||
351 | |||
352 | @@ -XXX,XX +XXX,XX @@ static inline void cpu_handle_debug_exception(CPUState *cpu) | ||
353 | } | ||
354 | } | ||
355 | |||
356 | - if (cc->tcg_ops.debug_excp_handler) { | ||
357 | - cc->tcg_ops.debug_excp_handler(cpu); | ||
358 | + if (cc->tcg_ops->debug_excp_handler) { | ||
359 | + cc->tcg_ops->debug_excp_handler(cpu); | ||
360 | } | ||
361 | } | ||
362 | |||
363 | @@ -XXX,XX +XXX,XX @@ static inline bool cpu_handle_exception(CPUState *cpu, int *ret) | ||
364 | loop */ | ||
365 | #if defined(TARGET_I386) | ||
366 | CPUClass *cc = CPU_GET_CLASS(cpu); | ||
367 | - cc->tcg_ops.do_interrupt(cpu); | ||
368 | + cc->tcg_ops->do_interrupt(cpu); | ||
369 | #endif | ||
370 | *ret = cpu->exception_index; | ||
371 | cpu->exception_index = -1; | ||
372 | @@ -XXX,XX +XXX,XX @@ static inline bool cpu_handle_exception(CPUState *cpu, int *ret) | ||
373 | if (replay_exception()) { | ||
374 | CPUClass *cc = CPU_GET_CLASS(cpu); | ||
375 | qemu_mutex_lock_iothread(); | ||
376 | - cc->tcg_ops.do_interrupt(cpu); | ||
377 | + cc->tcg_ops->do_interrupt(cpu); | ||
378 | qemu_mutex_unlock_iothread(); | ||
379 | cpu->exception_index = -1; | ||
380 | |||
381 | @@ -XXX,XX +XXX,XX @@ static inline bool cpu_handle_interrupt(CPUState *cpu, | ||
382 | True when it is, and we should restart on a new TB, | ||
383 | and via longjmp via cpu_loop_exit. */ | ||
384 | else { | ||
385 | - if (cc->tcg_ops.cpu_exec_interrupt && | ||
386 | - cc->tcg_ops.cpu_exec_interrupt(cpu, interrupt_request)) { | ||
387 | + if (cc->tcg_ops->cpu_exec_interrupt && | ||
388 | + cc->tcg_ops->cpu_exec_interrupt(cpu, interrupt_request)) { | ||
389 | if (need_replay_interrupt(interrupt_request)) { | ||
390 | replay_interrupt(); | ||
391 | } | ||
392 | @@ -XXX,XX +XXX,XX @@ void tcg_exec_realizefn(CPUState *cpu, Error **errp) | ||
393 | CPUClass *cc = CPU_GET_CLASS(cpu); | ||
394 | |||
395 | if (!tcg_target_initialized) { | ||
396 | - cc->tcg_ops.initialize(); | ||
397 | + cc->tcg_ops->initialize(); | ||
398 | tcg_target_initialized = true; | ||
399 | } | ||
400 | tlb_init(cpu); | ||
401 | diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c | ||
402 | index XXXXXXX..XXXXXXX 100644 | ||
403 | --- a/accel/tcg/cputlb.c | ||
404 | +++ b/accel/tcg/cputlb.c | ||
405 | @@ -XXX,XX +XXX,XX @@ | ||
406 | #include "qemu/osdep.h" | ||
407 | #include "qemu/main-loop.h" | ||
408 | #include "cpu.h" | ||
409 | +#include "hw/core/tcg-cpu-ops.h" | ||
410 | #include "exec/exec-all.h" | ||
411 | #include "exec/memory.h" | ||
412 | #include "exec/address-spaces.h" | ||
413 | @@ -XXX,XX +XXX,XX @@ static void tlb_fill(CPUState *cpu, target_ulong addr, int size, | ||
414 | * This is not a probe, so only valid return is success; failure | ||
415 | * should result in exception + longjmp to the cpu loop. | ||
416 | */ | ||
417 | - ok = cc->tcg_ops.tlb_fill(cpu, addr, size, | ||
418 | - access_type, mmu_idx, false, retaddr); | ||
419 | + ok = cc->tcg_ops->tlb_fill(cpu, addr, size, | ||
420 | + access_type, mmu_idx, false, retaddr); | ||
421 | assert(ok); | ||
422 | } | ||
423 | |||
424 | +static inline void cpu_unaligned_access(CPUState *cpu, vaddr addr, | ||
425 | + MMUAccessType access_type, | ||
426 | + int mmu_idx, uintptr_t retaddr) | ||
427 | +{ | ||
428 | + CPUClass *cc = CPU_GET_CLASS(cpu); | ||
429 | + | ||
430 | + cc->tcg_ops->do_unaligned_access(cpu, addr, access_type, mmu_idx, retaddr); | ||
431 | +} | ||
432 | + | ||
433 | +static inline void cpu_transaction_failed(CPUState *cpu, hwaddr physaddr, | ||
434 | + vaddr addr, unsigned size, | ||
435 | + MMUAccessType access_type, | ||
436 | + int mmu_idx, MemTxAttrs attrs, | ||
437 | + MemTxResult response, | ||
438 | + uintptr_t retaddr) | ||
439 | +{ | ||
440 | + CPUClass *cc = CPU_GET_CLASS(cpu); | ||
441 | + | ||
442 | + if (!cpu->ignore_memory_transaction_failures && | ||
443 | + cc->tcg_ops->do_transaction_failed) { | ||
444 | + cc->tcg_ops->do_transaction_failed(cpu, physaddr, addr, size, | ||
445 | + access_type, mmu_idx, attrs, | ||
446 | + response, retaddr); | ||
447 | + } | ||
448 | +} | ||
449 | + | ||
450 | static uint64_t io_readx(CPUArchState *env, CPUIOTLBEntry *iotlbentry, | ||
451 | int mmu_idx, target_ulong addr, uintptr_t retaddr, | ||
452 | MMUAccessType access_type, MemOp op) | ||
453 | @@ -XXX,XX +XXX,XX @@ static int probe_access_internal(CPUArchState *env, target_ulong addr, | ||
454 | CPUState *cs = env_cpu(env); | ||
455 | CPUClass *cc = CPU_GET_CLASS(cs); | ||
456 | |||
457 | - if (!cc->tcg_ops.tlb_fill(cs, addr, fault_size, access_type, | ||
458 | - mmu_idx, nonfault, retaddr)) { | ||
459 | + if (!cc->tcg_ops->tlb_fill(cs, addr, fault_size, access_type, | ||
460 | + mmu_idx, nonfault, retaddr)) { | ||
461 | /* Non-faulting page table read failed. */ | ||
462 | *phost = NULL; | ||
463 | return TLB_INVALID_MASK; | ||
464 | diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c | ||
465 | index XXXXXXX..XXXXXXX 100644 | ||
466 | --- a/accel/tcg/user-exec.c | ||
467 | +++ b/accel/tcg/user-exec.c | ||
468 | @@ -XXX,XX +XXX,XX @@ | ||
469 | */ | ||
470 | #include "qemu/osdep.h" | ||
471 | #include "cpu.h" | ||
472 | +#include "hw/core/tcg-cpu-ops.h" | ||
473 | #include "disas/disas.h" | ||
474 | #include "exec/exec-all.h" | ||
475 | #include "tcg/tcg.h" | ||
476 | @@ -XXX,XX +XXX,XX @@ static inline int handle_cpu_signal(uintptr_t pc, siginfo_t *info, | ||
477 | clear_helper_retaddr(); | ||
478 | |||
479 | cc = CPU_GET_CLASS(cpu); | ||
480 | - cc->tcg_ops.tlb_fill(cpu, address, 0, access_type, | ||
481 | - MMU_USER_IDX, false, pc); | ||
482 | + cc->tcg_ops->tlb_fill(cpu, address, 0, access_type, | ||
483 | + MMU_USER_IDX, false, pc); | ||
484 | g_assert_not_reached(); | ||
485 | } | ||
486 | |||
487 | @@ -XXX,XX +XXX,XX @@ static int probe_access_internal(CPUArchState *env, target_ulong addr, | ||
488 | } else { | ||
489 | CPUState *cpu = env_cpu(env); | ||
490 | CPUClass *cc = CPU_GET_CLASS(cpu); | ||
491 | - cc->tcg_ops.tlb_fill(cpu, addr, fault_size, access_type, | ||
492 | - MMU_USER_IDX, false, ra); | ||
493 | + cc->tcg_ops->tlb_fill(cpu, addr, fault_size, access_type, | ||
494 | + MMU_USER_IDX, false, ra); | ||
495 | g_assert_not_reached(); | ||
496 | } | ||
497 | } | ||
498 | diff --git a/hw/mips/jazz.c b/hw/mips/jazz.c | ||
499 | index XXXXXXX..XXXXXXX 100644 | ||
500 | --- a/hw/mips/jazz.c | ||
501 | +++ b/hw/mips/jazz.c | ||
502 | @@ -XXX,XX +XXX,XX @@ | ||
503 | #include "qapi/error.h" | ||
504 | #include "qemu/error-report.h" | ||
505 | #include "qemu/help_option.h" | ||
506 | +#ifdef CONFIG_TCG | ||
507 | +#include "hw/core/tcg-cpu-ops.h" | ||
508 | +#endif /* CONFIG_TCG */ | ||
509 | |||
510 | enum jazz_model_e { | ||
511 | JAZZ_MAGNUM, | ||
512 | @@ -XXX,XX +XXX,XX @@ static void mips_jazz_init(MachineState *machine, | ||
513 | */ | ||
514 | cc = CPU_GET_CLASS(cpu); | ||
515 | #if defined(CONFIG_TCG) && !defined(CONFIG_USER_ONLY) | ||
516 | - real_do_transaction_failed = cc->tcg_ops.do_transaction_failed; | ||
517 | - cc->tcg_ops.do_transaction_failed = mips_jazz_do_transaction_failed; | ||
518 | + real_do_transaction_failed = cc->tcg_ops->do_transaction_failed; | ||
519 | + cc->tcg_ops->do_transaction_failed = mips_jazz_do_transaction_failed; | ||
520 | #endif /* CONFIG_TCG && !CONFIG_USER_ONLY */ | ||
521 | |||
522 | /* allocate RAM */ | ||
523 | diff --git a/softmmu/physmem.c b/softmmu/physmem.c | ||
524 | index XXXXXXX..XXXXXXX 100644 | ||
525 | --- a/softmmu/physmem.c | ||
526 | +++ b/softmmu/physmem.c | ||
527 | @@ -XXX,XX +XXX,XX @@ | ||
528 | #include "qemu/cutils.h" | ||
529 | #include "qemu/cacheflush.h" | ||
530 | #include "cpu.h" | ||
531 | + | ||
532 | +#ifdef CONFIG_TCG | ||
533 | +#include "hw/core/tcg-cpu-ops.h" | ||
534 | +#endif /* CONFIG_TCG */ | ||
535 | + | ||
536 | #include "exec/exec-all.h" | ||
537 | #include "exec/target_page.h" | ||
538 | #include "hw/qdev-core.h" | ||
539 | @@ -XXX,XX +XXX,XX @@ void cpu_check_watchpoint(CPUState *cpu, vaddr addr, vaddr len, | ||
540 | return; | ||
541 | } | ||
542 | |||
543 | - if (cc->tcg_ops.adjust_watchpoint_address) { | ||
544 | + if (cc->tcg_ops->adjust_watchpoint_address) { | ||
545 | /* this is currently used only by ARM BE32 */ | ||
546 | - addr = cc->tcg_ops.adjust_watchpoint_address(cpu, addr, len); | ||
547 | + addr = cc->tcg_ops->adjust_watchpoint_address(cpu, addr, len); | ||
548 | } | ||
549 | QTAILQ_FOREACH(wp, &cpu->watchpoints, entry) { | ||
550 | if (watchpoint_address_matches(wp, addr, len) | ||
551 | @@ -XXX,XX +XXX,XX @@ void cpu_check_watchpoint(CPUState *cpu, vaddr addr, vaddr len, | ||
552 | wp->hitaddr = MAX(addr, wp->vaddr); | ||
553 | wp->hitattrs = attrs; | ||
554 | if (!cpu->watchpoint_hit) { | ||
555 | - if (wp->flags & BP_CPU && cc->tcg_ops.debug_check_watchpoint && | ||
556 | - !cc->tcg_ops.debug_check_watchpoint(cpu, wp)) { | ||
557 | + if (wp->flags & BP_CPU && cc->tcg_ops->debug_check_watchpoint && | ||
558 | + !cc->tcg_ops->debug_check_watchpoint(cpu, wp)) { | ||
559 | wp->flags &= ~BP_WATCHPOINT_HIT; | ||
560 | continue; | ||
561 | } | ||
562 | diff --git a/target/alpha/cpu.c b/target/alpha/cpu.c | ||
563 | index XXXXXXX..XXXXXXX 100644 | ||
564 | --- a/target/alpha/cpu.c | ||
565 | +++ b/target/alpha/cpu.c | ||
566 | @@ -XXX,XX +XXX,XX @@ static void alpha_cpu_initfn(Object *obj) | ||
567 | #endif | ||
568 | } | ||
569 | |||
570 | +#include "hw/core/tcg-cpu-ops.h" | ||
571 | + | ||
572 | +static struct TCGCPUOps alpha_tcg_ops = { | ||
573 | + .initialize = alpha_translate_init, | ||
574 | + .cpu_exec_interrupt = alpha_cpu_exec_interrupt, | ||
575 | + .tlb_fill = alpha_cpu_tlb_fill, | ||
576 | + | ||
577 | +#ifndef CONFIG_USER_ONLY | ||
578 | + .do_interrupt = alpha_cpu_do_interrupt, | ||
579 | + .do_transaction_failed = alpha_cpu_do_transaction_failed, | ||
580 | + .do_unaligned_access = alpha_cpu_do_unaligned_access, | ||
581 | +#endif /* !CONFIG_USER_ONLY */ | ||
582 | +}; | ||
583 | + | ||
584 | static void alpha_cpu_class_init(ObjectClass *oc, void *data) | ||
585 | { | ||
586 | DeviceClass *dc = DEVICE_CLASS(oc); | ||
587 | @@ -XXX,XX +XXX,XX @@ static void alpha_cpu_class_init(ObjectClass *oc, void *data) | ||
588 | |||
589 | cc->class_by_name = alpha_cpu_class_by_name; | ||
590 | cc->has_work = alpha_cpu_has_work; | ||
591 | - cc->tcg_ops.do_interrupt = alpha_cpu_do_interrupt; | ||
592 | - cc->tcg_ops.cpu_exec_interrupt = alpha_cpu_exec_interrupt; | ||
593 | cc->dump_state = alpha_cpu_dump_state; | ||
594 | cc->set_pc = alpha_cpu_set_pc; | ||
595 | cc->gdb_read_register = alpha_cpu_gdb_read_register; | ||
596 | cc->gdb_write_register = alpha_cpu_gdb_write_register; | ||
597 | - cc->tcg_ops.tlb_fill = alpha_cpu_tlb_fill; | ||
598 | #ifndef CONFIG_USER_ONLY | ||
599 | - cc->tcg_ops.do_transaction_failed = alpha_cpu_do_transaction_failed; | ||
600 | - cc->tcg_ops.do_unaligned_access = alpha_cpu_do_unaligned_access; | ||
601 | cc->get_phys_page_debug = alpha_cpu_get_phys_page_debug; | ||
602 | dc->vmsd = &vmstate_alpha_cpu; | ||
603 | #endif | ||
604 | cc->disas_set_info = alpha_cpu_disas_set_info; | ||
605 | - cc->tcg_ops.initialize = alpha_translate_init; | ||
606 | |||
607 | + cc->tcg_ops = &alpha_tcg_ops; | ||
608 | cc->gdb_num_core_regs = 67; | ||
609 | } | ||
610 | |||
611 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | ||
612 | index XXXXXXX..XXXXXXX 100644 | ||
613 | --- a/target/arm/cpu.c | ||
614 | +++ b/target/arm/cpu.c | ||
615 | @@ -XXX,XX +XXX,XX @@ | ||
616 | #include "qapi/error.h" | ||
617 | #include "qapi/visitor.h" | ||
618 | #include "cpu.h" | ||
619 | +#ifdef CONFIG_TCG | ||
620 | +#include "hw/core/tcg-cpu-ops.h" | ||
621 | +#endif /* CONFIG_TCG */ | ||
622 | #include "internals.h" | ||
623 | #include "exec/exec-all.h" | ||
624 | #include "hw/qdev-properties.h" | ||
625 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_set_pc(CPUState *cs, vaddr value) | ||
626 | } | ||
627 | |||
628 | #ifdef CONFIG_TCG | ||
629 | -static void arm_cpu_synchronize_from_tb(CPUState *cs, | ||
630 | - const TranslationBlock *tb) | ||
631 | +void arm_cpu_synchronize_from_tb(CPUState *cs, | ||
632 | + const TranslationBlock *tb) | ||
633 | { | ||
634 | ARMCPU *cpu = ARM_CPU(cs); | ||
635 | CPUARMState *env = &cpu->env; | ||
636 | @@ -XXX,XX +XXX,XX @@ bool arm_cpu_exec_interrupt(CPUState *cs, int interrupt_request) | ||
637 | found: | ||
638 | cs->exception_index = excp_idx; | ||
639 | env->exception.target_el = target_el; | ||
640 | - cc->tcg_ops.do_interrupt(cs); | ||
641 | + cc->tcg_ops->do_interrupt(cs); | ||
642 | return true; | 80 | return true; |
643 | } | 81 | } |
644 | 82 | ||
645 | @@ -XXX,XX +XXX,XX @@ static gchar *arm_gdb_arch_name(CPUState *cs) | 83 | +static bool fold_ctpop(OptContext *ctx, TCGOp *op) |
646 | return g_strdup("arm"); | 84 | +{ |
85 | + return fold_const1(ctx, op); | ||
86 | +} | ||
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 | { | ||
110 | /* Eliminate duplicate and redundant fence instructions. */ | ||
111 | @@ -XXX,XX +XXX,XX @@ static bool fold_mb(OptContext *ctx, TCGOp *op) | ||
112 | return true; | ||
647 | } | 113 | } |
648 | 114 | ||
649 | +#ifdef CONFIG_TCG | 115 | +static bool fold_mul(OptContext *ctx, TCGOp *op) |
650 | +static struct TCGCPUOps arm_tcg_ops = { | 116 | +{ |
651 | + .initialize = arm_translate_init, | 117 | + return fold_const2(ctx, op); |
652 | + .synchronize_from_tb = arm_cpu_synchronize_from_tb, | 118 | +} |
653 | + .cpu_exec_interrupt = arm_cpu_exec_interrupt, | 119 | + |
654 | + .tlb_fill = arm_cpu_tlb_fill, | 120 | +static bool fold_mul_highpart(OptContext *ctx, TCGOp *op) |
655 | + .debug_excp_handler = arm_debug_excp_handler, | 121 | +{ |
656 | + | 122 | + return fold_const2(ctx, op); |
657 | +#if !defined(CONFIG_USER_ONLY) | 123 | +} |
658 | + .do_interrupt = arm_cpu_do_interrupt, | 124 | + |
659 | + .do_transaction_failed = arm_cpu_do_transaction_failed, | 125 | +static bool fold_nand(OptContext *ctx, TCGOp *op) |
660 | + .do_unaligned_access = arm_cpu_do_unaligned_access, | 126 | +{ |
661 | + .adjust_watchpoint_address = arm_adjust_watchpoint_address, | 127 | + return fold_const2(ctx, op); |
662 | + .debug_check_watchpoint = arm_debug_check_watchpoint, | 128 | +} |
663 | +#endif /* !CONFIG_USER_ONLY */ | 129 | + |
664 | +}; | 130 | +static bool fold_neg(OptContext *ctx, TCGOp *op) |
665 | +#endif /* CONFIG_TCG */ | 131 | +{ |
666 | + | 132 | + return fold_const1(ctx, op); |
667 | static void arm_cpu_class_init(ObjectClass *oc, void *data) | 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) | ||
668 | { | 156 | { |
669 | ARMCPUClass *acc = ARM_CPU_CLASS(oc); | 157 | /* Opcodes that touch guest memory stop the mb optimization. */ |
670 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_class_init(ObjectClass *oc, void *data) | 158 | @@ -XXX,XX +XXX,XX @@ static bool fold_qemu_st(OptContext *ctx, TCGOp *op) |
671 | cc->gdb_get_dynamic_xml = arm_gdb_get_dynamic_xml; | ||
672 | cc->gdb_stop_before_watchpoint = true; | ||
673 | cc->disas_set_info = arm_disas_set_info; | ||
674 | + | ||
675 | #ifdef CONFIG_TCG | ||
676 | - cc->tcg_ops.initialize = arm_translate_init; | ||
677 | - cc->tcg_ops.cpu_exec_interrupt = arm_cpu_exec_interrupt; | ||
678 | - cc->tcg_ops.synchronize_from_tb = arm_cpu_synchronize_from_tb; | ||
679 | - cc->tcg_ops.tlb_fill = arm_cpu_tlb_fill; | ||
680 | - cc->tcg_ops.debug_excp_handler = arm_debug_excp_handler; | ||
681 | -#if !defined(CONFIG_USER_ONLY) | ||
682 | - cc->tcg_ops.do_interrupt = arm_cpu_do_interrupt; | ||
683 | - cc->tcg_ops.do_transaction_failed = arm_cpu_do_transaction_failed; | ||
684 | - cc->tcg_ops.do_unaligned_access = arm_cpu_do_unaligned_access; | ||
685 | - cc->tcg_ops.adjust_watchpoint_address = arm_adjust_watchpoint_address; | ||
686 | - cc->tcg_ops.debug_check_watchpoint = arm_debug_check_watchpoint; | ||
687 | -#endif /* CONFIG_TCG && !CONFIG_USER_ONLY */ | ||
688 | + cc->tcg_ops = &arm_tcg_ops; | ||
689 | #endif /* CONFIG_TCG */ | ||
690 | } | ||
691 | |||
692 | diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c | ||
693 | index XXXXXXX..XXXXXXX 100644 | ||
694 | --- a/target/arm/cpu64.c | ||
695 | +++ b/target/arm/cpu64.c | ||
696 | @@ -XXX,XX +XXX,XX @@ | ||
697 | #include "qemu/osdep.h" | ||
698 | #include "qapi/error.h" | ||
699 | #include "cpu.h" | ||
700 | +#ifdef CONFIG_TCG | ||
701 | +#include "hw/core/tcg-cpu-ops.h" | ||
702 | +#endif /* CONFIG_TCG */ | ||
703 | #include "qemu/module.h" | ||
704 | #if !defined(CONFIG_USER_ONLY) | ||
705 | #include "hw/loader.h" | ||
706 | @@ -XXX,XX +XXX,XX @@ static void aarch64_cpu_class_init(ObjectClass *oc, void *data) | ||
707 | { | ||
708 | CPUClass *cc = CPU_CLASS(oc); | ||
709 | |||
710 | -#ifdef CONFIG_TCG | ||
711 | - cc->tcg_ops.cpu_exec_interrupt = arm_cpu_exec_interrupt; | ||
712 | -#endif /* CONFIG_TCG */ | ||
713 | - | ||
714 | cc->gdb_read_register = aarch64_cpu_gdb_read_register; | ||
715 | cc->gdb_write_register = aarch64_cpu_gdb_write_register; | ||
716 | cc->gdb_num_core_regs = 34; | ||
717 | diff --git a/target/arm/cpu_tcg.c b/target/arm/cpu_tcg.c | ||
718 | index XXXXXXX..XXXXXXX 100644 | ||
719 | --- a/target/arm/cpu_tcg.c | ||
720 | +++ b/target/arm/cpu_tcg.c | ||
721 | @@ -XXX,XX +XXX,XX @@ | ||
722 | |||
723 | #include "qemu/osdep.h" | ||
724 | #include "cpu.h" | ||
725 | +#ifdef CONFIG_TCG | ||
726 | +#include "hw/core/tcg-cpu-ops.h" | ||
727 | +#endif /* CONFIG_TCG */ | ||
728 | #include "internals.h" | ||
729 | |||
730 | /* CPU models. These are not needed for the AArch64 linux-user build. */ | ||
731 | @@ -XXX,XX +XXX,XX @@ static bool arm_v7m_cpu_exec_interrupt(CPUState *cs, int interrupt_request) | ||
732 | if (interrupt_request & CPU_INTERRUPT_HARD | ||
733 | && (armv7m_nvic_can_take_pending_exception(env->nvic))) { | ||
734 | cs->exception_index = EXCP_IRQ; | ||
735 | - cc->tcg_ops.do_interrupt(cs); | ||
736 | + cc->tcg_ops->do_interrupt(cs); | ||
737 | ret = true; | ||
738 | } | ||
739 | return ret; | ||
740 | @@ -XXX,XX +XXX,XX @@ static void pxa270c5_initfn(Object *obj) | ||
741 | cpu->reset_sctlr = 0x00000078; | ||
742 | } | ||
743 | |||
744 | +#ifdef CONFIG_TCG | ||
745 | +static struct TCGCPUOps arm_v7m_tcg_ops = { | ||
746 | + .initialize = arm_translate_init, | ||
747 | + .synchronize_from_tb = arm_cpu_synchronize_from_tb, | ||
748 | + .cpu_exec_interrupt = arm_v7m_cpu_exec_interrupt, | ||
749 | + .tlb_fill = arm_cpu_tlb_fill, | ||
750 | + .debug_excp_handler = arm_debug_excp_handler, | ||
751 | + | ||
752 | +#if !defined(CONFIG_USER_ONLY) | ||
753 | + .do_interrupt = arm_v7m_cpu_do_interrupt, | ||
754 | + .do_transaction_failed = arm_cpu_do_transaction_failed, | ||
755 | + .do_unaligned_access = arm_cpu_do_unaligned_access, | ||
756 | + .adjust_watchpoint_address = arm_adjust_watchpoint_address, | ||
757 | + .debug_check_watchpoint = arm_debug_check_watchpoint, | ||
758 | +#endif /* !CONFIG_USER_ONLY */ | ||
759 | +}; | ||
760 | +#endif /* CONFIG_TCG */ | ||
761 | + | ||
762 | static void arm_v7m_class_init(ObjectClass *oc, void *data) | ||
763 | { | ||
764 | ARMCPUClass *acc = ARM_CPU_CLASS(oc); | ||
765 | @@ -XXX,XX +XXX,XX @@ static void arm_v7m_class_init(ObjectClass *oc, void *data) | ||
766 | |||
767 | acc->info = data; | ||
768 | #ifdef CONFIG_TCG | ||
769 | - cc->tcg_ops.cpu_exec_interrupt = arm_v7m_cpu_exec_interrupt; | ||
770 | -#ifndef CONFIG_USER_ONLY | ||
771 | - cc->tcg_ops.do_interrupt = arm_v7m_cpu_do_interrupt; | ||
772 | -#endif | ||
773 | + cc->tcg_ops = &arm_v7m_tcg_ops; | ||
774 | #endif /* CONFIG_TCG */ | ||
775 | |||
776 | cc->gdb_core_xml_file = "arm-m-profile.xml"; | ||
777 | diff --git a/target/avr/cpu.c b/target/avr/cpu.c | ||
778 | index XXXXXXX..XXXXXXX 100644 | ||
779 | --- a/target/avr/cpu.c | ||
780 | +++ b/target/avr/cpu.c | ||
781 | @@ -XXX,XX +XXX,XX @@ static void avr_cpu_dump_state(CPUState *cs, FILE *f, int flags) | ||
782 | qemu_fprintf(f, "\n"); | ||
783 | } | ||
784 | |||
785 | +#include "hw/core/tcg-cpu-ops.h" | ||
786 | + | ||
787 | +static struct TCGCPUOps avr_tcg_ops = { | ||
788 | + .initialize = avr_cpu_tcg_init, | ||
789 | + .synchronize_from_tb = avr_cpu_synchronize_from_tb, | ||
790 | + .cpu_exec_interrupt = avr_cpu_exec_interrupt, | ||
791 | + .tlb_fill = avr_cpu_tlb_fill, | ||
792 | + | ||
793 | +#ifndef CONFIG_USER_ONLY | ||
794 | + .do_interrupt = avr_cpu_do_interrupt, | ||
795 | +#endif /* !CONFIG_USER_ONLY */ | ||
796 | +}; | ||
797 | + | ||
798 | static void avr_cpu_class_init(ObjectClass *oc, void *data) | ||
799 | { | ||
800 | DeviceClass *dc = DEVICE_CLASS(oc); | ||
801 | @@ -XXX,XX +XXX,XX @@ static void avr_cpu_class_init(ObjectClass *oc, void *data) | ||
802 | cc->class_by_name = avr_cpu_class_by_name; | ||
803 | |||
804 | cc->has_work = avr_cpu_has_work; | ||
805 | - cc->tcg_ops.do_interrupt = avr_cpu_do_interrupt; | ||
806 | - cc->tcg_ops.cpu_exec_interrupt = avr_cpu_exec_interrupt; | ||
807 | cc->dump_state = avr_cpu_dump_state; | ||
808 | cc->set_pc = avr_cpu_set_pc; | ||
809 | cc->memory_rw_debug = avr_cpu_memory_rw_debug; | ||
810 | cc->get_phys_page_debug = avr_cpu_get_phys_page_debug; | ||
811 | - cc->tcg_ops.tlb_fill = avr_cpu_tlb_fill; | ||
812 | cc->vmsd = &vms_avr_cpu; | ||
813 | cc->disas_set_info = avr_cpu_disas_set_info; | ||
814 | - cc->tcg_ops.initialize = avr_cpu_tcg_init; | ||
815 | - cc->tcg_ops.synchronize_from_tb = avr_cpu_synchronize_from_tb; | ||
816 | cc->gdb_read_register = avr_cpu_gdb_read_register; | ||
817 | cc->gdb_write_register = avr_cpu_gdb_write_register; | ||
818 | cc->gdb_num_core_regs = 35; | ||
819 | cc->gdb_core_xml_file = "avr-cpu.xml"; | ||
820 | + cc->tcg_ops = &avr_tcg_ops; | ||
821 | } | ||
822 | |||
823 | /* | ||
824 | diff --git a/target/avr/helper.c b/target/avr/helper.c | ||
825 | index XXXXXXX..XXXXXXX 100644 | ||
826 | --- a/target/avr/helper.c | ||
827 | +++ b/target/avr/helper.c | ||
828 | @@ -XXX,XX +XXX,XX @@ | ||
829 | |||
830 | #include "qemu/osdep.h" | ||
831 | #include "cpu.h" | ||
832 | +#include "hw/core/tcg-cpu-ops.h" | ||
833 | #include "exec/exec-all.h" | ||
834 | #include "exec/address-spaces.h" | ||
835 | #include "exec/helper-proto.h" | ||
836 | @@ -XXX,XX +XXX,XX @@ bool avr_cpu_exec_interrupt(CPUState *cs, int interrupt_request) | ||
837 | if (interrupt_request & CPU_INTERRUPT_RESET) { | ||
838 | if (cpu_interrupts_enabled(env)) { | ||
839 | cs->exception_index = EXCP_RESET; | ||
840 | - cc->tcg_ops.do_interrupt(cs); | ||
841 | + cc->tcg_ops->do_interrupt(cs); | ||
842 | |||
843 | cs->interrupt_request &= ~CPU_INTERRUPT_RESET; | ||
844 | |||
845 | @@ -XXX,XX +XXX,XX @@ bool avr_cpu_exec_interrupt(CPUState *cs, int interrupt_request) | ||
846 | if (cpu_interrupts_enabled(env) && env->intsrc != 0) { | ||
847 | int index = ctz32(env->intsrc); | ||
848 | cs->exception_index = EXCP_INT(index); | ||
849 | - cc->tcg_ops.do_interrupt(cs); | ||
850 | + cc->tcg_ops->do_interrupt(cs); | ||
851 | |||
852 | env->intsrc &= env->intsrc - 1; /* clear the interrupt */ | ||
853 | cs->interrupt_request &= ~CPU_INTERRUPT_HARD; | ||
854 | diff --git a/target/cris/cpu.c b/target/cris/cpu.c | ||
855 | index XXXXXXX..XXXXXXX 100644 | ||
856 | --- a/target/cris/cpu.c | ||
857 | +++ b/target/cris/cpu.c | ||
858 | @@ -XXX,XX +XXX,XX @@ static void cris_cpu_initfn(Object *obj) | ||
859 | #endif | ||
860 | } | ||
861 | |||
862 | +#include "hw/core/tcg-cpu-ops.h" | ||
863 | + | ||
864 | +static struct TCGCPUOps crisv10_tcg_ops = { | ||
865 | + .initialize = cris_initialize_crisv10_tcg, | ||
866 | + .cpu_exec_interrupt = cris_cpu_exec_interrupt, | ||
867 | + .tlb_fill = cris_cpu_tlb_fill, | ||
868 | + | ||
869 | +#ifndef CONFIG_USER_ONLY | ||
870 | + .do_interrupt = crisv10_cpu_do_interrupt, | ||
871 | +#endif /* !CONFIG_USER_ONLY */ | ||
872 | +}; | ||
873 | + | ||
874 | +static struct TCGCPUOps crisv32_tcg_ops = { | ||
875 | + .initialize = cris_initialize_tcg, | ||
876 | + .cpu_exec_interrupt = cris_cpu_exec_interrupt, | ||
877 | + .tlb_fill = cris_cpu_tlb_fill, | ||
878 | + | ||
879 | +#ifndef CONFIG_USER_ONLY | ||
880 | + .do_interrupt = cris_cpu_do_interrupt, | ||
881 | +#endif /* !CONFIG_USER_ONLY */ | ||
882 | +}; | ||
883 | + | ||
884 | static void crisv8_cpu_class_init(ObjectClass *oc, void *data) | ||
885 | { | ||
886 | CPUClass *cc = CPU_CLASS(oc); | ||
887 | CRISCPUClass *ccc = CRIS_CPU_CLASS(oc); | ||
888 | |||
889 | ccc->vr = 8; | ||
890 | - cc->tcg_ops.do_interrupt = crisv10_cpu_do_interrupt; | ||
891 | cc->gdb_read_register = crisv10_cpu_gdb_read_register; | ||
892 | - cc->tcg_ops.initialize = cris_initialize_crisv10_tcg; | ||
893 | + cc->tcg_ops = &crisv10_tcg_ops; | ||
894 | } | ||
895 | |||
896 | static void crisv9_cpu_class_init(ObjectClass *oc, void *data) | ||
897 | @@ -XXX,XX +XXX,XX @@ static void crisv9_cpu_class_init(ObjectClass *oc, void *data) | ||
898 | CRISCPUClass *ccc = CRIS_CPU_CLASS(oc); | ||
899 | |||
900 | ccc->vr = 9; | ||
901 | - cc->tcg_ops.do_interrupt = crisv10_cpu_do_interrupt; | ||
902 | cc->gdb_read_register = crisv10_cpu_gdb_read_register; | ||
903 | - cc->tcg_ops.initialize = cris_initialize_crisv10_tcg; | ||
904 | + cc->tcg_ops = &crisv10_tcg_ops; | ||
905 | } | ||
906 | |||
907 | static void crisv10_cpu_class_init(ObjectClass *oc, void *data) | ||
908 | @@ -XXX,XX +XXX,XX @@ static void crisv10_cpu_class_init(ObjectClass *oc, void *data) | ||
909 | CRISCPUClass *ccc = CRIS_CPU_CLASS(oc); | ||
910 | |||
911 | ccc->vr = 10; | ||
912 | - cc->tcg_ops.do_interrupt = crisv10_cpu_do_interrupt; | ||
913 | cc->gdb_read_register = crisv10_cpu_gdb_read_register; | ||
914 | - cc->tcg_ops.initialize = cris_initialize_crisv10_tcg; | ||
915 | + cc->tcg_ops = &crisv10_tcg_ops; | ||
916 | } | ||
917 | |||
918 | static void crisv11_cpu_class_init(ObjectClass *oc, void *data) | ||
919 | @@ -XXX,XX +XXX,XX @@ static void crisv11_cpu_class_init(ObjectClass *oc, void *data) | ||
920 | CRISCPUClass *ccc = CRIS_CPU_CLASS(oc); | ||
921 | |||
922 | ccc->vr = 11; | ||
923 | - cc->tcg_ops.do_interrupt = crisv10_cpu_do_interrupt; | ||
924 | cc->gdb_read_register = crisv10_cpu_gdb_read_register; | ||
925 | - cc->tcg_ops.initialize = cris_initialize_crisv10_tcg; | ||
926 | + cc->tcg_ops = &crisv10_tcg_ops; | ||
927 | } | ||
928 | |||
929 | static void crisv17_cpu_class_init(ObjectClass *oc, void *data) | ||
930 | @@ -XXX,XX +XXX,XX @@ static void crisv17_cpu_class_init(ObjectClass *oc, void *data) | ||
931 | CRISCPUClass *ccc = CRIS_CPU_CLASS(oc); | ||
932 | |||
933 | ccc->vr = 17; | ||
934 | - cc->tcg_ops.do_interrupt = crisv10_cpu_do_interrupt; | ||
935 | cc->gdb_read_register = crisv10_cpu_gdb_read_register; | ||
936 | - cc->tcg_ops.initialize = cris_initialize_crisv10_tcg; | ||
937 | + cc->tcg_ops = &crisv10_tcg_ops; | ||
938 | } | ||
939 | |||
940 | static void crisv32_cpu_class_init(ObjectClass *oc, void *data) | ||
941 | { | ||
942 | + CPUClass *cc = CPU_CLASS(oc); | ||
943 | CRISCPUClass *ccc = CRIS_CPU_CLASS(oc); | ||
944 | |||
945 | ccc->vr = 32; | ||
946 | + cc->tcg_ops = &crisv32_tcg_ops; | ||
947 | } | ||
948 | |||
949 | static void cris_cpu_class_init(ObjectClass *oc, void *data) | ||
950 | @@ -XXX,XX +XXX,XX @@ static void cris_cpu_class_init(ObjectClass *oc, void *data) | ||
951 | |||
952 | cc->class_by_name = cris_cpu_class_by_name; | ||
953 | cc->has_work = cris_cpu_has_work; | ||
954 | - cc->tcg_ops.do_interrupt = cris_cpu_do_interrupt; | ||
955 | - cc->tcg_ops.cpu_exec_interrupt = cris_cpu_exec_interrupt; | ||
956 | cc->dump_state = cris_cpu_dump_state; | ||
957 | cc->set_pc = cris_cpu_set_pc; | ||
958 | cc->gdb_read_register = cris_cpu_gdb_read_register; | ||
959 | cc->gdb_write_register = cris_cpu_gdb_write_register; | ||
960 | - cc->tcg_ops.tlb_fill = cris_cpu_tlb_fill; | ||
961 | #ifndef CONFIG_USER_ONLY | ||
962 | cc->get_phys_page_debug = cris_cpu_get_phys_page_debug; | ||
963 | dc->vmsd = &vmstate_cris_cpu; | ||
964 | @@ -XXX,XX +XXX,XX @@ static void cris_cpu_class_init(ObjectClass *oc, void *data) | ||
965 | cc->gdb_stop_before_watchpoint = true; | ||
966 | |||
967 | cc->disas_set_info = cris_disas_set_info; | ||
968 | - cc->tcg_ops.initialize = cris_initialize_tcg; | ||
969 | } | ||
970 | |||
971 | #define DEFINE_CRIS_CPU_TYPE(cpu_model, initfn) \ | ||
972 | diff --git a/target/cris/helper.c b/target/cris/helper.c | ||
973 | index XXXXXXX..XXXXXXX 100644 | ||
974 | --- a/target/cris/helper.c | ||
975 | +++ b/target/cris/helper.c | ||
976 | @@ -XXX,XX +XXX,XX @@ | ||
977 | |||
978 | #include "qemu/osdep.h" | ||
979 | #include "cpu.h" | ||
980 | +#include "hw/core/tcg-cpu-ops.h" | ||
981 | #include "mmu.h" | ||
982 | #include "qemu/host-utils.h" | ||
983 | #include "exec/exec-all.h" | ||
984 | @@ -XXX,XX +XXX,XX @@ bool cris_cpu_exec_interrupt(CPUState *cs, int interrupt_request) | ||
985 | && (env->pregs[PR_CCS] & I_FLAG) | ||
986 | && !env->locked_irq) { | ||
987 | cs->exception_index = EXCP_IRQ; | ||
988 | - cc->tcg_ops.do_interrupt(cs); | ||
989 | + cc->tcg_ops->do_interrupt(cs); | ||
990 | ret = true; | ||
991 | } | ||
992 | if (interrupt_request & CPU_INTERRUPT_NMI) { | ||
993 | @@ -XXX,XX +XXX,XX @@ bool cris_cpu_exec_interrupt(CPUState *cs, int interrupt_request) | ||
994 | } | ||
995 | if ((env->pregs[PR_CCS] & m_flag_archval)) { | ||
996 | cs->exception_index = EXCP_NMI; | ||
997 | - cc->tcg_ops.do_interrupt(cs); | ||
998 | + cc->tcg_ops->do_interrupt(cs); | ||
999 | ret = true; | ||
1000 | } | ||
1001 | } | ||
1002 | diff --git a/target/hppa/cpu.c b/target/hppa/cpu.c | ||
1003 | index XXXXXXX..XXXXXXX 100644 | ||
1004 | --- a/target/hppa/cpu.c | ||
1005 | +++ b/target/hppa/cpu.c | ||
1006 | @@ -XXX,XX +XXX,XX @@ static ObjectClass *hppa_cpu_class_by_name(const char *cpu_model) | ||
1007 | return object_class_by_name(TYPE_HPPA_CPU); | ||
1008 | } | ||
1009 | |||
1010 | +#include "hw/core/tcg-cpu-ops.h" | ||
1011 | + | ||
1012 | +static struct TCGCPUOps hppa_tcg_ops = { | ||
1013 | + .initialize = hppa_translate_init, | ||
1014 | + .synchronize_from_tb = hppa_cpu_synchronize_from_tb, | ||
1015 | + .cpu_exec_interrupt = hppa_cpu_exec_interrupt, | ||
1016 | + .tlb_fill = hppa_cpu_tlb_fill, | ||
1017 | + | ||
1018 | +#ifndef CONFIG_USER_ONLY | ||
1019 | + .do_interrupt = hppa_cpu_do_interrupt, | ||
1020 | + .do_unaligned_access = hppa_cpu_do_unaligned_access, | ||
1021 | +#endif /* !CONFIG_USER_ONLY */ | ||
1022 | +}; | ||
1023 | + | ||
1024 | static void hppa_cpu_class_init(ObjectClass *oc, void *data) | ||
1025 | { | ||
1026 | DeviceClass *dc = DEVICE_CLASS(oc); | ||
1027 | @@ -XXX,XX +XXX,XX @@ static void hppa_cpu_class_init(ObjectClass *oc, void *data) | ||
1028 | |||
1029 | cc->class_by_name = hppa_cpu_class_by_name; | ||
1030 | cc->has_work = hppa_cpu_has_work; | ||
1031 | - cc->tcg_ops.do_interrupt = hppa_cpu_do_interrupt; | ||
1032 | - cc->tcg_ops.cpu_exec_interrupt = hppa_cpu_exec_interrupt; | ||
1033 | cc->dump_state = hppa_cpu_dump_state; | ||
1034 | cc->set_pc = hppa_cpu_set_pc; | ||
1035 | - cc->tcg_ops.synchronize_from_tb = hppa_cpu_synchronize_from_tb; | ||
1036 | cc->gdb_read_register = hppa_cpu_gdb_read_register; | ||
1037 | cc->gdb_write_register = hppa_cpu_gdb_write_register; | ||
1038 | - cc->tcg_ops.tlb_fill = hppa_cpu_tlb_fill; | ||
1039 | #ifndef CONFIG_USER_ONLY | ||
1040 | cc->get_phys_page_debug = hppa_cpu_get_phys_page_debug; | ||
1041 | - cc->tcg_ops.do_unaligned_access = hppa_cpu_do_unaligned_access; | ||
1042 | dc->vmsd = &vmstate_hppa_cpu; | ||
1043 | #endif | ||
1044 | cc->disas_set_info = hppa_cpu_disas_set_info; | ||
1045 | - cc->tcg_ops.initialize = hppa_translate_init; | ||
1046 | - | ||
1047 | cc->gdb_num_core_regs = 128; | ||
1048 | + cc->tcg_ops = &hppa_tcg_ops; | ||
1049 | } | ||
1050 | |||
1051 | static const TypeInfo hppa_cpu_type_info = { | ||
1052 | diff --git a/target/i386/tcg/tcg-cpu.c b/target/i386/tcg/tcg-cpu.c | ||
1053 | index XXXXXXX..XXXXXXX 100644 | ||
1054 | --- a/target/i386/tcg/tcg-cpu.c | ||
1055 | +++ b/target/i386/tcg/tcg-cpu.c | ||
1056 | @@ -XXX,XX +XXX,XX @@ static void x86_cpu_synchronize_from_tb(CPUState *cs, | ||
1057 | cpu->env.eip = tb->pc - tb->cs_base; | ||
1058 | } | ||
1059 | |||
1060 | +#include "hw/core/tcg-cpu-ops.h" | ||
1061 | + | ||
1062 | +static struct TCGCPUOps x86_tcg_ops = { | ||
1063 | + .initialize = tcg_x86_init, | ||
1064 | + .synchronize_from_tb = x86_cpu_synchronize_from_tb, | ||
1065 | + .cpu_exec_enter = x86_cpu_exec_enter, | ||
1066 | + .cpu_exec_exit = x86_cpu_exec_exit, | ||
1067 | + .cpu_exec_interrupt = x86_cpu_exec_interrupt, | ||
1068 | + .do_interrupt = x86_cpu_do_interrupt, | ||
1069 | + .tlb_fill = x86_cpu_tlb_fill, | ||
1070 | +#ifndef CONFIG_USER_ONLY | ||
1071 | + .debug_excp_handler = breakpoint_handler, | ||
1072 | +#endif /* !CONFIG_USER_ONLY */ | ||
1073 | +}; | ||
1074 | + | ||
1075 | void tcg_cpu_common_class_init(CPUClass *cc) | ||
1076 | { | ||
1077 | - cc->tcg_ops.do_interrupt = x86_cpu_do_interrupt; | ||
1078 | - cc->tcg_ops.cpu_exec_interrupt = x86_cpu_exec_interrupt; | ||
1079 | - cc->tcg_ops.synchronize_from_tb = x86_cpu_synchronize_from_tb; | ||
1080 | - cc->tcg_ops.cpu_exec_enter = x86_cpu_exec_enter; | ||
1081 | - cc->tcg_ops.cpu_exec_exit = x86_cpu_exec_exit; | ||
1082 | - cc->tcg_ops.initialize = tcg_x86_init; | ||
1083 | - cc->tcg_ops.tlb_fill = x86_cpu_tlb_fill; | ||
1084 | -#ifndef CONFIG_USER_ONLY | ||
1085 | - cc->tcg_ops.debug_excp_handler = breakpoint_handler; | ||
1086 | -#endif | ||
1087 | + cc->tcg_ops = &x86_tcg_ops; | ||
1088 | } | ||
1089 | diff --git a/target/lm32/cpu.c b/target/lm32/cpu.c | ||
1090 | index XXXXXXX..XXXXXXX 100644 | ||
1091 | --- a/target/lm32/cpu.c | ||
1092 | +++ b/target/lm32/cpu.c | ||
1093 | @@ -XXX,XX +XXX,XX @@ static ObjectClass *lm32_cpu_class_by_name(const char *cpu_model) | ||
1094 | return oc; | ||
1095 | } | ||
1096 | |||
1097 | +#include "hw/core/tcg-cpu-ops.h" | ||
1098 | + | ||
1099 | +static struct TCGCPUOps lm32_tcg_ops = { | ||
1100 | + .initialize = lm32_translate_init, | ||
1101 | + .cpu_exec_interrupt = lm32_cpu_exec_interrupt, | ||
1102 | + .tlb_fill = lm32_cpu_tlb_fill, | ||
1103 | + .debug_excp_handler = lm32_debug_excp_handler, | ||
1104 | + | ||
1105 | +#ifndef CONFIG_USER_ONLY | ||
1106 | + .do_interrupt = lm32_cpu_do_interrupt, | ||
1107 | +#endif /* !CONFIG_USER_ONLY */ | ||
1108 | +}; | ||
1109 | + | ||
1110 | static void lm32_cpu_class_init(ObjectClass *oc, void *data) | ||
1111 | { | ||
1112 | LM32CPUClass *lcc = LM32_CPU_CLASS(oc); | ||
1113 | @@ -XXX,XX +XXX,XX @@ static void lm32_cpu_class_init(ObjectClass *oc, void *data) | ||
1114 | |||
1115 | cc->class_by_name = lm32_cpu_class_by_name; | ||
1116 | cc->has_work = lm32_cpu_has_work; | ||
1117 | - cc->tcg_ops.do_interrupt = lm32_cpu_do_interrupt; | ||
1118 | - cc->tcg_ops.cpu_exec_interrupt = lm32_cpu_exec_interrupt; | ||
1119 | cc->dump_state = lm32_cpu_dump_state; | ||
1120 | cc->set_pc = lm32_cpu_set_pc; | ||
1121 | cc->gdb_read_register = lm32_cpu_gdb_read_register; | ||
1122 | cc->gdb_write_register = lm32_cpu_gdb_write_register; | ||
1123 | - cc->tcg_ops.tlb_fill = lm32_cpu_tlb_fill; | ||
1124 | #ifndef CONFIG_USER_ONLY | ||
1125 | cc->get_phys_page_debug = lm32_cpu_get_phys_page_debug; | ||
1126 | cc->vmsd = &vmstate_lm32_cpu; | ||
1127 | #endif | ||
1128 | cc->gdb_num_core_regs = 32 + 7; | ||
1129 | cc->gdb_stop_before_watchpoint = true; | ||
1130 | - cc->tcg_ops.debug_excp_handler = lm32_debug_excp_handler; | ||
1131 | cc->disas_set_info = lm32_cpu_disas_set_info; | ||
1132 | - cc->tcg_ops.initialize = lm32_translate_init; | ||
1133 | + cc->tcg_ops = &lm32_tcg_ops; | ||
1134 | } | ||
1135 | |||
1136 | #define DEFINE_LM32_CPU_TYPE(cpu_model, initfn) \ | ||
1137 | diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c | ||
1138 | index XXXXXXX..XXXXXXX 100644 | ||
1139 | --- a/target/m68k/cpu.c | ||
1140 | +++ b/target/m68k/cpu.c | ||
1141 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_m68k_cpu = { | ||
1142 | }; | ||
1143 | #endif | ||
1144 | |||
1145 | +#include "hw/core/tcg-cpu-ops.h" | ||
1146 | + | ||
1147 | +static struct TCGCPUOps m68k_tcg_ops = { | ||
1148 | + .initialize = m68k_tcg_init, | ||
1149 | + .cpu_exec_interrupt = m68k_cpu_exec_interrupt, | ||
1150 | + .tlb_fill = m68k_cpu_tlb_fill, | ||
1151 | + | ||
1152 | +#ifndef CONFIG_USER_ONLY | ||
1153 | + .do_interrupt = m68k_cpu_do_interrupt, | ||
1154 | + .do_transaction_failed = m68k_cpu_transaction_failed, | ||
1155 | +#endif /* !CONFIG_USER_ONLY */ | ||
1156 | +}; | ||
1157 | + | ||
1158 | static void m68k_cpu_class_init(ObjectClass *c, void *data) | ||
1159 | { | ||
1160 | M68kCPUClass *mcc = M68K_CPU_CLASS(c); | ||
1161 | @@ -XXX,XX +XXX,XX @@ static void m68k_cpu_class_init(ObjectClass *c, void *data) | ||
1162 | |||
1163 | cc->class_by_name = m68k_cpu_class_by_name; | ||
1164 | cc->has_work = m68k_cpu_has_work; | ||
1165 | - cc->tcg_ops.do_interrupt = m68k_cpu_do_interrupt; | ||
1166 | - cc->tcg_ops.cpu_exec_interrupt = m68k_cpu_exec_interrupt; | ||
1167 | cc->dump_state = m68k_cpu_dump_state; | ||
1168 | cc->set_pc = m68k_cpu_set_pc; | ||
1169 | cc->gdb_read_register = m68k_cpu_gdb_read_register; | ||
1170 | cc->gdb_write_register = m68k_cpu_gdb_write_register; | ||
1171 | - cc->tcg_ops.tlb_fill = m68k_cpu_tlb_fill; | ||
1172 | #if defined(CONFIG_SOFTMMU) | ||
1173 | - cc->tcg_ops.do_transaction_failed = m68k_cpu_transaction_failed; | ||
1174 | cc->get_phys_page_debug = m68k_cpu_get_phys_page_debug; | ||
1175 | dc->vmsd = &vmstate_m68k_cpu; | ||
1176 | #endif | ||
1177 | cc->disas_set_info = m68k_cpu_disas_set_info; | ||
1178 | - cc->tcg_ops.initialize = m68k_tcg_init; | ||
1179 | |||
1180 | cc->gdb_num_core_regs = 18; | ||
1181 | + cc->tcg_ops = &m68k_tcg_ops; | ||
1182 | } | ||
1183 | |||
1184 | static void m68k_cpu_class_init_cf_core(ObjectClass *c, void *data) | ||
1185 | diff --git a/target/microblaze/cpu.c b/target/microblaze/cpu.c | ||
1186 | index XXXXXXX..XXXXXXX 100644 | ||
1187 | --- a/target/microblaze/cpu.c | ||
1188 | +++ b/target/microblaze/cpu.c | ||
1189 | @@ -XXX,XX +XXX,XX @@ static ObjectClass *mb_cpu_class_by_name(const char *cpu_model) | ||
1190 | return object_class_by_name(TYPE_MICROBLAZE_CPU); | ||
1191 | } | ||
1192 | |||
1193 | +#include "hw/core/tcg-cpu-ops.h" | ||
1194 | + | ||
1195 | +static struct TCGCPUOps mb_tcg_ops = { | ||
1196 | + .initialize = mb_tcg_init, | ||
1197 | + .synchronize_from_tb = mb_cpu_synchronize_from_tb, | ||
1198 | + .cpu_exec_interrupt = mb_cpu_exec_interrupt, | ||
1199 | + .tlb_fill = mb_cpu_tlb_fill, | ||
1200 | + | ||
1201 | +#ifndef CONFIG_USER_ONLY | ||
1202 | + .do_interrupt = mb_cpu_do_interrupt, | ||
1203 | + .do_transaction_failed = mb_cpu_transaction_failed, | ||
1204 | + .do_unaligned_access = mb_cpu_do_unaligned_access, | ||
1205 | +#endif /* !CONFIG_USER_ONLY */ | ||
1206 | +}; | ||
1207 | + | ||
1208 | static void mb_cpu_class_init(ObjectClass *oc, void *data) | ||
1209 | { | ||
1210 | DeviceClass *dc = DEVICE_CLASS(oc); | ||
1211 | @@ -XXX,XX +XXX,XX @@ static void mb_cpu_class_init(ObjectClass *oc, void *data) | ||
1212 | |||
1213 | cc->class_by_name = mb_cpu_class_by_name; | ||
1214 | cc->has_work = mb_cpu_has_work; | ||
1215 | - cc->tcg_ops.do_interrupt = mb_cpu_do_interrupt; | ||
1216 | - cc->tcg_ops.cpu_exec_interrupt = mb_cpu_exec_interrupt; | ||
1217 | + | ||
1218 | cc->dump_state = mb_cpu_dump_state; | ||
1219 | cc->set_pc = mb_cpu_set_pc; | ||
1220 | - cc->tcg_ops.synchronize_from_tb = mb_cpu_synchronize_from_tb; | ||
1221 | cc->gdb_read_register = mb_cpu_gdb_read_register; | ||
1222 | cc->gdb_write_register = mb_cpu_gdb_write_register; | ||
1223 | - cc->tcg_ops.tlb_fill = mb_cpu_tlb_fill; | ||
1224 | + | ||
1225 | #ifndef CONFIG_USER_ONLY | ||
1226 | - cc->tcg_ops.do_transaction_failed = mb_cpu_transaction_failed; | ||
1227 | - cc->tcg_ops.do_unaligned_access = mb_cpu_do_unaligned_access; | ||
1228 | cc->get_phys_page_attrs_debug = mb_cpu_get_phys_page_attrs_debug; | ||
1229 | dc->vmsd = &vmstate_mb_cpu; | ||
1230 | #endif | ||
1231 | @@ -XXX,XX +XXX,XX @@ static void mb_cpu_class_init(ObjectClass *oc, void *data) | ||
1232 | cc->gdb_num_core_regs = 32 + 27; | ||
1233 | |||
1234 | cc->disas_set_info = mb_disas_set_info; | ||
1235 | - cc->tcg_ops.initialize = mb_tcg_init; | ||
1236 | + cc->tcg_ops = &mb_tcg_ops; | ||
1237 | } | ||
1238 | |||
1239 | static const TypeInfo mb_cpu_type_info = { | ||
1240 | diff --git a/target/mips/cpu.c b/target/mips/cpu.c | ||
1241 | index XXXXXXX..XXXXXXX 100644 | ||
1242 | --- a/target/mips/cpu.c | ||
1243 | +++ b/target/mips/cpu.c | ||
1244 | @@ -XXX,XX +XXX,XX @@ static Property mips_cpu_properties[] = { | ||
1245 | DEFINE_PROP_END_OF_LIST() | ||
1246 | }; | ||
1247 | |||
1248 | +#ifdef CONFIG_TCG | ||
1249 | +#include "hw/core/tcg-cpu-ops.h" | ||
1250 | +/* | ||
1251 | + * NB: cannot be const, as some elements are changed for specific | ||
1252 | + * mips hardware (see hw/mips/jazz.c). | ||
1253 | + */ | ||
1254 | +static struct TCGCPUOps mips_tcg_ops = { | ||
1255 | + .initialize = mips_tcg_init, | ||
1256 | + .synchronize_from_tb = mips_cpu_synchronize_from_tb, | ||
1257 | + .cpu_exec_interrupt = mips_cpu_exec_interrupt, | ||
1258 | + .tlb_fill = mips_cpu_tlb_fill, | ||
1259 | + | ||
1260 | +#if !defined(CONFIG_USER_ONLY) | ||
1261 | + .do_interrupt = mips_cpu_do_interrupt, | ||
1262 | + .do_transaction_failed = mips_cpu_do_transaction_failed, | ||
1263 | + .do_unaligned_access = mips_cpu_do_unaligned_access, | ||
1264 | +#endif /* !CONFIG_USER_ONLY */ | ||
1265 | +}; | ||
1266 | +#endif /* CONFIG_TCG */ | ||
1267 | + | ||
1268 | static void mips_cpu_class_init(ObjectClass *c, void *data) | ||
1269 | { | ||
1270 | MIPSCPUClass *mcc = MIPS_CPU_CLASS(c); | ||
1271 | @@ -XXX,XX +XXX,XX @@ static void mips_cpu_class_init(ObjectClass *c, void *data) | ||
1272 | cc->vmsd = &vmstate_mips_cpu; | ||
1273 | #endif | ||
1274 | cc->disas_set_info = mips_cpu_disas_set_info; | ||
1275 | -#ifdef CONFIG_TCG | ||
1276 | - cc->tcg_ops.initialize = mips_tcg_init; | ||
1277 | - cc->tcg_ops.do_interrupt = mips_cpu_do_interrupt; | ||
1278 | - cc->tcg_ops.cpu_exec_interrupt = mips_cpu_exec_interrupt; | ||
1279 | - cc->tcg_ops.synchronize_from_tb = mips_cpu_synchronize_from_tb; | ||
1280 | - cc->tcg_ops.tlb_fill = mips_cpu_tlb_fill; | ||
1281 | -#ifndef CONFIG_USER_ONLY | ||
1282 | - cc->tcg_ops.do_transaction_failed = mips_cpu_do_transaction_failed; | ||
1283 | - cc->tcg_ops.do_unaligned_access = mips_cpu_do_unaligned_access; | ||
1284 | - | ||
1285 | -#endif /* CONFIG_USER_ONLY */ | ||
1286 | -#endif /* CONFIG_TCG */ | ||
1287 | - | ||
1288 | cc->gdb_num_core_regs = 73; | ||
1289 | cc->gdb_stop_before_watchpoint = true; | ||
1290 | +#ifdef CONFIG_TCG | ||
1291 | + cc->tcg_ops = &mips_tcg_ops; | ||
1292 | +#endif /* CONFIG_TCG */ | ||
1293 | } | ||
1294 | |||
1295 | static const TypeInfo mips_cpu_type_info = { | ||
1296 | diff --git a/target/moxie/cpu.c b/target/moxie/cpu.c | ||
1297 | index XXXXXXX..XXXXXXX 100644 | ||
1298 | --- a/target/moxie/cpu.c | ||
1299 | +++ b/target/moxie/cpu.c | ||
1300 | @@ -XXX,XX +XXX,XX @@ static ObjectClass *moxie_cpu_class_by_name(const char *cpu_model) | ||
1301 | return oc; | ||
1302 | } | ||
1303 | |||
1304 | +#include "hw/core/tcg-cpu-ops.h" | ||
1305 | + | ||
1306 | +static struct TCGCPUOps moxie_tcg_ops = { | ||
1307 | + .initialize = moxie_translate_init, | ||
1308 | + .tlb_fill = moxie_cpu_tlb_fill, | ||
1309 | + | ||
1310 | +#ifndef CONFIG_USER_ONLY | ||
1311 | + .do_interrupt = moxie_cpu_do_interrupt, | ||
1312 | +#endif /* !CONFIG_USER_ONLY */ | ||
1313 | +}; | ||
1314 | + | ||
1315 | static void moxie_cpu_class_init(ObjectClass *oc, void *data) | ||
1316 | { | ||
1317 | DeviceClass *dc = DEVICE_CLASS(oc); | ||
1318 | @@ -XXX,XX +XXX,XX @@ static void moxie_cpu_class_init(ObjectClass *oc, void *data) | ||
1319 | cc->class_by_name = moxie_cpu_class_by_name; | ||
1320 | |||
1321 | cc->has_work = moxie_cpu_has_work; | ||
1322 | - cc->tcg_ops.do_interrupt = moxie_cpu_do_interrupt; | ||
1323 | cc->dump_state = moxie_cpu_dump_state; | ||
1324 | cc->set_pc = moxie_cpu_set_pc; | ||
1325 | - cc->tcg_ops.tlb_fill = moxie_cpu_tlb_fill; | ||
1326 | #ifndef CONFIG_USER_ONLY | ||
1327 | cc->get_phys_page_debug = moxie_cpu_get_phys_page_debug; | ||
1328 | cc->vmsd = &vmstate_moxie_cpu; | ||
1329 | #endif | ||
1330 | cc->disas_set_info = moxie_cpu_disas_set_info; | ||
1331 | - cc->tcg_ops.initialize = moxie_translate_init; | ||
1332 | + cc->tcg_ops = &moxie_tcg_ops; | ||
1333 | } | ||
1334 | |||
1335 | static void moxielite_initfn(Object *obj) | ||
1336 | diff --git a/target/nios2/cpu.c b/target/nios2/cpu.c | ||
1337 | index XXXXXXX..XXXXXXX 100644 | ||
1338 | --- a/target/nios2/cpu.c | ||
1339 | +++ b/target/nios2/cpu.c | ||
1340 | @@ -XXX,XX +XXX,XX @@ static Property nios2_properties[] = { | ||
1341 | DEFINE_PROP_END_OF_LIST(), | ||
1342 | }; | ||
1343 | |||
1344 | +#include "hw/core/tcg-cpu-ops.h" | ||
1345 | + | ||
1346 | +static struct TCGCPUOps nios2_tcg_ops = { | ||
1347 | + .initialize = nios2_tcg_init, | ||
1348 | + .cpu_exec_interrupt = nios2_cpu_exec_interrupt, | ||
1349 | + .tlb_fill = nios2_cpu_tlb_fill, | ||
1350 | + | ||
1351 | +#ifndef CONFIG_USER_ONLY | ||
1352 | + .do_interrupt = nios2_cpu_do_interrupt, | ||
1353 | + .do_unaligned_access = nios2_cpu_do_unaligned_access, | ||
1354 | +#endif /* !CONFIG_USER_ONLY */ | ||
1355 | +}; | ||
1356 | |||
1357 | static void nios2_cpu_class_init(ObjectClass *oc, void *data) | ||
1358 | { | ||
1359 | @@ -XXX,XX +XXX,XX @@ static void nios2_cpu_class_init(ObjectClass *oc, void *data) | ||
1360 | |||
1361 | cc->class_by_name = nios2_cpu_class_by_name; | ||
1362 | cc->has_work = nios2_cpu_has_work; | ||
1363 | - cc->tcg_ops.do_interrupt = nios2_cpu_do_interrupt; | ||
1364 | - cc->tcg_ops.cpu_exec_interrupt = nios2_cpu_exec_interrupt; | ||
1365 | cc->dump_state = nios2_cpu_dump_state; | ||
1366 | cc->set_pc = nios2_cpu_set_pc; | ||
1367 | cc->disas_set_info = nios2_cpu_disas_set_info; | ||
1368 | - cc->tcg_ops.tlb_fill = nios2_cpu_tlb_fill; | ||
1369 | #ifndef CONFIG_USER_ONLY | ||
1370 | - cc->tcg_ops.do_unaligned_access = nios2_cpu_do_unaligned_access; | ||
1371 | cc->get_phys_page_debug = nios2_cpu_get_phys_page_debug; | ||
1372 | #endif | ||
1373 | cc->gdb_read_register = nios2_cpu_gdb_read_register; | ||
1374 | cc->gdb_write_register = nios2_cpu_gdb_write_register; | ||
1375 | cc->gdb_num_core_regs = 49; | ||
1376 | - cc->tcg_ops.initialize = nios2_tcg_init; | ||
1377 | + cc->tcg_ops = &nios2_tcg_ops; | ||
1378 | } | ||
1379 | |||
1380 | static const TypeInfo nios2_cpu_type_info = { | ||
1381 | diff --git a/target/openrisc/cpu.c b/target/openrisc/cpu.c | ||
1382 | index XXXXXXX..XXXXXXX 100644 | ||
1383 | --- a/target/openrisc/cpu.c | ||
1384 | +++ b/target/openrisc/cpu.c | ||
1385 | @@ -XXX,XX +XXX,XX @@ static void openrisc_any_initfn(Object *obj) | ||
1386 | | (IMMUCFGR_NTS & (ctz32(TLB_SIZE) << 2)); | ||
1387 | } | ||
1388 | |||
1389 | +#include "hw/core/tcg-cpu-ops.h" | ||
1390 | + | ||
1391 | +static struct TCGCPUOps openrisc_tcg_ops = { | ||
1392 | + .initialize = openrisc_translate_init, | ||
1393 | + .cpu_exec_interrupt = openrisc_cpu_exec_interrupt, | ||
1394 | + .tlb_fill = openrisc_cpu_tlb_fill, | ||
1395 | + | ||
1396 | +#ifndef CONFIG_USER_ONLY | ||
1397 | + .do_interrupt = openrisc_cpu_do_interrupt, | ||
1398 | +#endif /* !CONFIG_USER_ONLY */ | ||
1399 | +}; | ||
1400 | + | ||
1401 | static void openrisc_cpu_class_init(ObjectClass *oc, void *data) | ||
1402 | { | ||
1403 | OpenRISCCPUClass *occ = OPENRISC_CPU_CLASS(oc); | ||
1404 | @@ -XXX,XX +XXX,XX @@ static void openrisc_cpu_class_init(ObjectClass *oc, void *data) | ||
1405 | |||
1406 | cc->class_by_name = openrisc_cpu_class_by_name; | ||
1407 | cc->has_work = openrisc_cpu_has_work; | ||
1408 | - cc->tcg_ops.do_interrupt = openrisc_cpu_do_interrupt; | ||
1409 | - cc->tcg_ops.cpu_exec_interrupt = openrisc_cpu_exec_interrupt; | ||
1410 | cc->dump_state = openrisc_cpu_dump_state; | ||
1411 | cc->set_pc = openrisc_cpu_set_pc; | ||
1412 | cc->gdb_read_register = openrisc_cpu_gdb_read_register; | ||
1413 | cc->gdb_write_register = openrisc_cpu_gdb_write_register; | ||
1414 | - cc->tcg_ops.tlb_fill = openrisc_cpu_tlb_fill; | ||
1415 | #ifndef CONFIG_USER_ONLY | ||
1416 | cc->get_phys_page_debug = openrisc_cpu_get_phys_page_debug; | ||
1417 | dc->vmsd = &vmstate_openrisc_cpu; | ||
1418 | #endif | ||
1419 | cc->gdb_num_core_regs = 32 + 3; | ||
1420 | - cc->tcg_ops.initialize = openrisc_translate_init; | ||
1421 | cc->disas_set_info = openrisc_disas_set_info; | ||
1422 | + cc->tcg_ops = &openrisc_tcg_ops; | ||
1423 | } | ||
1424 | |||
1425 | /* Sort alphabetically by type name, except for "any". */ | ||
1426 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
1427 | index XXXXXXX..XXXXXXX 100644 | ||
1428 | --- a/target/riscv/cpu.c | ||
1429 | +++ b/target/riscv/cpu.c | ||
1430 | @@ -XXX,XX +XXX,XX @@ static const char *riscv_gdb_get_dynamic_xml(CPUState *cs, const char *xmlname) | ||
1431 | return NULL; | ||
1432 | } | ||
1433 | |||
1434 | +#include "hw/core/tcg-cpu-ops.h" | ||
1435 | + | ||
1436 | +static struct TCGCPUOps riscv_tcg_ops = { | ||
1437 | + .initialize = riscv_translate_init, | ||
1438 | + .synchronize_from_tb = riscv_cpu_synchronize_from_tb, | ||
1439 | + .cpu_exec_interrupt = riscv_cpu_exec_interrupt, | ||
1440 | + .tlb_fill = riscv_cpu_tlb_fill, | ||
1441 | + | ||
1442 | +#ifndef CONFIG_USER_ONLY | ||
1443 | + .do_interrupt = riscv_cpu_do_interrupt, | ||
1444 | + .do_transaction_failed = riscv_cpu_do_transaction_failed, | ||
1445 | + .do_unaligned_access = riscv_cpu_do_unaligned_access, | ||
1446 | +#endif /* !CONFIG_USER_ONLY */ | ||
1447 | +}; | ||
1448 | + | ||
1449 | static void riscv_cpu_class_init(ObjectClass *c, void *data) | ||
1450 | { | ||
1451 | RISCVCPUClass *mcc = RISCV_CPU_CLASS(c); | ||
1452 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_class_init(ObjectClass *c, void *data) | ||
1453 | |||
1454 | cc->class_by_name = riscv_cpu_class_by_name; | ||
1455 | cc->has_work = riscv_cpu_has_work; | ||
1456 | - cc->tcg_ops.do_interrupt = riscv_cpu_do_interrupt; | ||
1457 | - cc->tcg_ops.cpu_exec_interrupt = riscv_cpu_exec_interrupt; | ||
1458 | cc->dump_state = riscv_cpu_dump_state; | ||
1459 | cc->set_pc = riscv_cpu_set_pc; | ||
1460 | - cc->tcg_ops.synchronize_from_tb = riscv_cpu_synchronize_from_tb; | ||
1461 | cc->gdb_read_register = riscv_cpu_gdb_read_register; | ||
1462 | cc->gdb_write_register = riscv_cpu_gdb_write_register; | ||
1463 | cc->gdb_num_core_regs = 33; | ||
1464 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_class_init(ObjectClass *c, void *data) | ||
1465 | cc->gdb_stop_before_watchpoint = true; | ||
1466 | cc->disas_set_info = riscv_cpu_disas_set_info; | ||
1467 | #ifndef CONFIG_USER_ONLY | ||
1468 | - cc->tcg_ops.do_transaction_failed = riscv_cpu_do_transaction_failed; | ||
1469 | - cc->tcg_ops.do_unaligned_access = riscv_cpu_do_unaligned_access; | ||
1470 | cc->get_phys_page_debug = riscv_cpu_get_phys_page_debug; | ||
1471 | /* For now, mark unmigratable: */ | ||
1472 | cc->vmsd = &vmstate_riscv_cpu; | ||
1473 | #endif | ||
1474 | cc->gdb_arch_name = riscv_gdb_arch_name; | ||
1475 | cc->gdb_get_dynamic_xml = riscv_gdb_get_dynamic_xml; | ||
1476 | - cc->tcg_ops.initialize = riscv_translate_init; | ||
1477 | - cc->tcg_ops.tlb_fill = riscv_cpu_tlb_fill; | ||
1478 | + cc->tcg_ops = &riscv_tcg_ops; | ||
1479 | |||
1480 | device_class_set_props(dc, riscv_cpu_properties); | ||
1481 | } | ||
1482 | diff --git a/target/rx/cpu.c b/target/rx/cpu.c | ||
1483 | index XXXXXXX..XXXXXXX 100644 | ||
1484 | --- a/target/rx/cpu.c | ||
1485 | +++ b/target/rx/cpu.c | ||
1486 | @@ -XXX,XX +XXX,XX @@ static void rx_cpu_init(Object *obj) | ||
1487 | qdev_init_gpio_in(DEVICE(cpu), rx_cpu_set_irq, 2); | ||
1488 | } | ||
1489 | |||
1490 | +#include "hw/core/tcg-cpu-ops.h" | ||
1491 | + | ||
1492 | +static struct TCGCPUOps rx_tcg_ops = { | ||
1493 | + .initialize = rx_translate_init, | ||
1494 | + .synchronize_from_tb = rx_cpu_synchronize_from_tb, | ||
1495 | + .cpu_exec_interrupt = rx_cpu_exec_interrupt, | ||
1496 | + .tlb_fill = rx_cpu_tlb_fill, | ||
1497 | + | ||
1498 | +#ifndef CONFIG_USER_ONLY | ||
1499 | + .do_interrupt = rx_cpu_do_interrupt, | ||
1500 | +#endif /* !CONFIG_USER_ONLY */ | ||
1501 | +}; | ||
1502 | + | ||
1503 | static void rx_cpu_class_init(ObjectClass *klass, void *data) | ||
1504 | { | ||
1505 | DeviceClass *dc = DEVICE_CLASS(klass); | ||
1506 | @@ -XXX,XX +XXX,XX @@ static void rx_cpu_class_init(ObjectClass *klass, void *data) | ||
1507 | |||
1508 | cc->class_by_name = rx_cpu_class_by_name; | ||
1509 | cc->has_work = rx_cpu_has_work; | ||
1510 | - cc->tcg_ops.do_interrupt = rx_cpu_do_interrupt; | ||
1511 | - cc->tcg_ops.cpu_exec_interrupt = rx_cpu_exec_interrupt; | ||
1512 | cc->dump_state = rx_cpu_dump_state; | ||
1513 | cc->set_pc = rx_cpu_set_pc; | ||
1514 | - cc->tcg_ops.synchronize_from_tb = rx_cpu_synchronize_from_tb; | ||
1515 | + | ||
1516 | cc->gdb_read_register = rx_cpu_gdb_read_register; | ||
1517 | cc->gdb_write_register = rx_cpu_gdb_write_register; | ||
1518 | cc->get_phys_page_debug = rx_cpu_get_phys_page_debug; | ||
1519 | cc->disas_set_info = rx_cpu_disas_set_info; | ||
1520 | - cc->tcg_ops.initialize = rx_translate_init; | ||
1521 | - cc->tcg_ops.tlb_fill = rx_cpu_tlb_fill; | ||
1522 | |||
1523 | cc->gdb_num_core_regs = 26; | ||
1524 | cc->gdb_core_xml_file = "rx-core.xml"; | ||
1525 | + cc->tcg_ops = &rx_tcg_ops; | ||
1526 | } | ||
1527 | |||
1528 | static const TypeInfo rx_cpu_info = { | ||
1529 | diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c | ||
1530 | index XXXXXXX..XXXXXXX 100644 | ||
1531 | --- a/target/s390x/cpu.c | ||
1532 | +++ b/target/s390x/cpu.c | ||
1533 | @@ -XXX,XX +XXX,XX @@ static void s390_cpu_reset_full(DeviceState *dev) | ||
1534 | return s390_cpu_reset(s, S390_CPU_RESET_CLEAR); | ||
1535 | } | ||
1536 | |||
1537 | +#ifdef CONFIG_TCG | ||
1538 | +#include "hw/core/tcg-cpu-ops.h" | ||
1539 | + | ||
1540 | +static struct TCGCPUOps s390_tcg_ops = { | ||
1541 | + .initialize = s390x_translate_init, | ||
1542 | + .tlb_fill = s390_cpu_tlb_fill, | ||
1543 | + | ||
1544 | +#if !defined(CONFIG_USER_ONLY) | ||
1545 | + .cpu_exec_interrupt = s390_cpu_exec_interrupt, | ||
1546 | + .do_interrupt = s390_cpu_do_interrupt, | ||
1547 | + .debug_excp_handler = s390x_cpu_debug_excp_handler, | ||
1548 | + .do_unaligned_access = s390x_cpu_do_unaligned_access, | ||
1549 | +#endif /* !CONFIG_USER_ONLY */ | ||
1550 | +}; | ||
1551 | +#endif /* CONFIG_TCG */ | ||
1552 | + | ||
1553 | static void s390_cpu_class_init(ObjectClass *oc, void *data) | ||
1554 | { | ||
1555 | S390CPUClass *scc = S390_CPU_CLASS(oc); | ||
1556 | @@ -XXX,XX +XXX,XX @@ static void s390_cpu_class_init(ObjectClass *oc, void *data) | ||
1557 | scc->reset = s390_cpu_reset; | ||
1558 | cc->class_by_name = s390_cpu_class_by_name, | ||
1559 | cc->has_work = s390_cpu_has_work; | ||
1560 | -#ifdef CONFIG_TCG | ||
1561 | - cc->tcg_ops.do_interrupt = s390_cpu_do_interrupt; | ||
1562 | -#endif | ||
1563 | cc->dump_state = s390_cpu_dump_state; | ||
1564 | cc->set_pc = s390_cpu_set_pc; | ||
1565 | cc->gdb_read_register = s390_cpu_gdb_read_register; | ||
1566 | @@ -XXX,XX +XXX,XX @@ static void s390_cpu_class_init(ObjectClass *oc, void *data) | ||
1567 | cc->vmsd = &vmstate_s390_cpu; | ||
1568 | cc->get_crash_info = s390_cpu_get_crash_info; | ||
1569 | cc->write_elf64_note = s390_cpu_write_elf64_note; | ||
1570 | -#ifdef CONFIG_TCG | ||
1571 | - cc->tcg_ops.cpu_exec_interrupt = s390_cpu_exec_interrupt; | ||
1572 | - cc->tcg_ops.debug_excp_handler = s390x_cpu_debug_excp_handler; | ||
1573 | - cc->tcg_ops.do_unaligned_access = s390x_cpu_do_unaligned_access; | ||
1574 | -#endif | ||
1575 | #endif | ||
1576 | cc->disas_set_info = s390_cpu_disas_set_info; | ||
1577 | -#ifdef CONFIG_TCG | ||
1578 | - cc->tcg_ops.initialize = s390x_translate_init; | ||
1579 | - cc->tcg_ops.tlb_fill = s390_cpu_tlb_fill; | ||
1580 | -#endif | ||
1581 | - | ||
1582 | cc->gdb_num_core_regs = S390_NUM_CORE_REGS; | ||
1583 | cc->gdb_core_xml_file = "s390x-core64.xml"; | ||
1584 | cc->gdb_arch_name = s390_gdb_arch_name; | ||
1585 | |||
1586 | s390_cpu_model_class_register_props(oc); | ||
1587 | + | ||
1588 | +#ifdef CONFIG_TCG | ||
1589 | + cc->tcg_ops = &s390_tcg_ops; | ||
1590 | +#endif /* CONFIG_TCG */ | ||
1591 | } | ||
1592 | |||
1593 | static const TypeInfo s390_cpu_type_info = { | ||
1594 | diff --git a/target/sh4/cpu.c b/target/sh4/cpu.c | ||
1595 | index XXXXXXX..XXXXXXX 100644 | ||
1596 | --- a/target/sh4/cpu.c | ||
1597 | +++ b/target/sh4/cpu.c | ||
1598 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_sh_cpu = { | ||
1599 | .unmigratable = 1, | ||
1600 | }; | ||
1601 | |||
1602 | +#include "hw/core/tcg-cpu-ops.h" | ||
1603 | + | ||
1604 | +static struct TCGCPUOps superh_tcg_ops = { | ||
1605 | + .initialize = sh4_translate_init, | ||
1606 | + .synchronize_from_tb = superh_cpu_synchronize_from_tb, | ||
1607 | + .cpu_exec_interrupt = superh_cpu_exec_interrupt, | ||
1608 | + .tlb_fill = superh_cpu_tlb_fill, | ||
1609 | + | ||
1610 | +#ifndef CONFIG_USER_ONLY | ||
1611 | + .do_interrupt = superh_cpu_do_interrupt, | ||
1612 | + .do_unaligned_access = superh_cpu_do_unaligned_access, | ||
1613 | +#endif /* !CONFIG_USER_ONLY */ | ||
1614 | +}; | ||
1615 | + | ||
1616 | static void superh_cpu_class_init(ObjectClass *oc, void *data) | ||
1617 | { | ||
1618 | DeviceClass *dc = DEVICE_CLASS(oc); | ||
1619 | @@ -XXX,XX +XXX,XX @@ static void superh_cpu_class_init(ObjectClass *oc, void *data) | ||
1620 | |||
1621 | cc->class_by_name = superh_cpu_class_by_name; | ||
1622 | cc->has_work = superh_cpu_has_work; | ||
1623 | - cc->tcg_ops.do_interrupt = superh_cpu_do_interrupt; | ||
1624 | - cc->tcg_ops.cpu_exec_interrupt = superh_cpu_exec_interrupt; | ||
1625 | cc->dump_state = superh_cpu_dump_state; | ||
1626 | cc->set_pc = superh_cpu_set_pc; | ||
1627 | - cc->tcg_ops.synchronize_from_tb = superh_cpu_synchronize_from_tb; | ||
1628 | cc->gdb_read_register = superh_cpu_gdb_read_register; | ||
1629 | cc->gdb_write_register = superh_cpu_gdb_write_register; | ||
1630 | - cc->tcg_ops.tlb_fill = superh_cpu_tlb_fill; | ||
1631 | #ifndef CONFIG_USER_ONLY | ||
1632 | - cc->tcg_ops.do_unaligned_access = superh_cpu_do_unaligned_access; | ||
1633 | cc->get_phys_page_debug = superh_cpu_get_phys_page_debug; | ||
1634 | #endif | ||
1635 | cc->disas_set_info = superh_cpu_disas_set_info; | ||
1636 | - cc->tcg_ops.initialize = sh4_translate_init; | ||
1637 | |||
1638 | cc->gdb_num_core_regs = 59; | ||
1639 | |||
1640 | dc->vmsd = &vmstate_sh_cpu; | ||
1641 | + cc->tcg_ops = &superh_tcg_ops; | ||
1642 | } | ||
1643 | |||
1644 | #define DEFINE_SUPERH_CPU_TYPE(type_name, cinit, initfn) \ | ||
1645 | diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c | ||
1646 | index XXXXXXX..XXXXXXX 100644 | ||
1647 | --- a/target/sparc/cpu.c | ||
1648 | +++ b/target/sparc/cpu.c | ||
1649 | @@ -XXX,XX +XXX,XX @@ static Property sparc_cpu_properties[] = { | ||
1650 | DEFINE_PROP_END_OF_LIST() | ||
1651 | }; | ||
1652 | |||
1653 | +#ifdef CONFIG_TCG | ||
1654 | +#include "hw/core/tcg-cpu-ops.h" | ||
1655 | + | ||
1656 | +static struct TCGCPUOps sparc_tcg_ops = { | ||
1657 | + .initialize = sparc_tcg_init, | ||
1658 | + .synchronize_from_tb = sparc_cpu_synchronize_from_tb, | ||
1659 | + .cpu_exec_interrupt = sparc_cpu_exec_interrupt, | ||
1660 | + .tlb_fill = sparc_cpu_tlb_fill, | ||
1661 | + | ||
1662 | +#ifndef CONFIG_USER_ONLY | ||
1663 | + .do_interrupt = sparc_cpu_do_interrupt, | ||
1664 | + .do_transaction_failed = sparc_cpu_do_transaction_failed, | ||
1665 | + .do_unaligned_access = sparc_cpu_do_unaligned_access, | ||
1666 | +#endif /* !CONFIG_USER_ONLY */ | ||
1667 | +}; | ||
1668 | +#endif /* CONFIG_TCG */ | ||
1669 | + | ||
1670 | static void sparc_cpu_class_init(ObjectClass *oc, void *data) | ||
1671 | { | ||
1672 | SPARCCPUClass *scc = SPARC_CPU_CLASS(oc); | ||
1673 | @@ -XXX,XX +XXX,XX @@ static void sparc_cpu_class_init(ObjectClass *oc, void *data) | ||
1674 | cc->class_by_name = sparc_cpu_class_by_name; | ||
1675 | cc->parse_features = sparc_cpu_parse_features; | ||
1676 | cc->has_work = sparc_cpu_has_work; | ||
1677 | - cc->tcg_ops.do_interrupt = sparc_cpu_do_interrupt; | ||
1678 | - cc->tcg_ops.cpu_exec_interrupt = sparc_cpu_exec_interrupt; | ||
1679 | cc->dump_state = sparc_cpu_dump_state; | ||
1680 | #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY) | ||
1681 | cc->memory_rw_debug = sparc_cpu_memory_rw_debug; | ||
1682 | #endif | ||
1683 | cc->set_pc = sparc_cpu_set_pc; | ||
1684 | - cc->tcg_ops.synchronize_from_tb = sparc_cpu_synchronize_from_tb; | ||
1685 | cc->gdb_read_register = sparc_cpu_gdb_read_register; | ||
1686 | cc->gdb_write_register = sparc_cpu_gdb_write_register; | ||
1687 | - cc->tcg_ops.tlb_fill = sparc_cpu_tlb_fill; | ||
1688 | #ifndef CONFIG_USER_ONLY | ||
1689 | - cc->tcg_ops.do_transaction_failed = sparc_cpu_do_transaction_failed; | ||
1690 | - cc->tcg_ops.do_unaligned_access = sparc_cpu_do_unaligned_access; | ||
1691 | cc->get_phys_page_debug = sparc_cpu_get_phys_page_debug; | ||
1692 | cc->vmsd = &vmstate_sparc_cpu; | ||
1693 | #endif | ||
1694 | cc->disas_set_info = cpu_sparc_disas_set_info; | ||
1695 | - cc->tcg_ops.initialize = sparc_tcg_init; | ||
1696 | |||
1697 | #if defined(TARGET_SPARC64) && !defined(TARGET_ABI32) | ||
1698 | cc->gdb_num_core_regs = 86; | ||
1699 | #else | ||
1700 | cc->gdb_num_core_regs = 72; | ||
1701 | #endif | ||
1702 | + cc->tcg_ops = &sparc_tcg_ops; | ||
1703 | } | ||
1704 | |||
1705 | static const TypeInfo sparc_cpu_type_info = { | ||
1706 | diff --git a/target/tilegx/cpu.c b/target/tilegx/cpu.c | ||
1707 | index XXXXXXX..XXXXXXX 100644 | ||
1708 | --- a/target/tilegx/cpu.c | ||
1709 | +++ b/target/tilegx/cpu.c | ||
1710 | @@ -XXX,XX +XXX,XX @@ static bool tilegx_cpu_exec_interrupt(CPUState *cs, int interrupt_request) | ||
1711 | return false; | 159 | return false; |
1712 | } | 160 | } |
1713 | 161 | ||
1714 | +#include "hw/core/tcg-cpu-ops.h" | 162 | +static bool fold_remainder(OptContext *ctx, TCGOp *op) |
1715 | + | 163 | +{ |
1716 | +static struct TCGCPUOps tilegx_tcg_ops = { | 164 | + return fold_const2(ctx, op); |
1717 | + .initialize = tilegx_tcg_init, | 165 | +} |
1718 | + .cpu_exec_interrupt = tilegx_cpu_exec_interrupt, | 166 | + |
1719 | + .tlb_fill = tilegx_cpu_tlb_fill, | 167 | +static bool fold_shift(OptContext *ctx, TCGOp *op) |
1720 | + | 168 | +{ |
1721 | +#ifndef CONFIG_USER_ONLY | 169 | + return fold_const2(ctx, op); |
1722 | + .do_interrupt = tilegx_cpu_do_interrupt, | 170 | +} |
1723 | +#endif /* !CONFIG_USER_ONLY */ | 171 | + |
1724 | +}; | 172 | +static bool fold_sub(OptContext *ctx, TCGOp *op) |
1725 | + | 173 | +{ |
1726 | static void tilegx_cpu_class_init(ObjectClass *oc, void *data) | 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) | ||
1727 | { | 184 | { |
1728 | DeviceClass *dc = DEVICE_CLASS(oc); | 185 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) |
1729 | @@ -XXX,XX +XXX,XX @@ static void tilegx_cpu_class_init(ObjectClass *oc, void *data) | 186 | } |
1730 | 187 | break; | |
1731 | cc->class_by_name = tilegx_cpu_class_by_name; | 188 | |
1732 | cc->has_work = tilegx_cpu_has_work; | 189 | - CASE_OP_32_64(not): |
1733 | - cc->tcg_ops.do_interrupt = tilegx_cpu_do_interrupt; | 190 | - CASE_OP_32_64(neg): |
1734 | - cc->tcg_ops.cpu_exec_interrupt = tilegx_cpu_exec_interrupt; | 191 | - CASE_OP_32_64(ext8s): |
1735 | cc->dump_state = tilegx_cpu_dump_state; | 192 | - CASE_OP_32_64(ext8u): |
1736 | cc->set_pc = tilegx_cpu_set_pc; | 193 | - CASE_OP_32_64(ext16s): |
1737 | - cc->tcg_ops.tlb_fill = tilegx_cpu_tlb_fill; | 194 | - CASE_OP_32_64(ext16u): |
1738 | cc->gdb_num_core_regs = 0; | 195 | - CASE_OP_32_64(ctpop): |
1739 | - cc->tcg_ops.initialize = tilegx_tcg_init; | 196 | - case INDEX_op_ext32s_i64: |
1740 | + cc->tcg_ops = &tilegx_tcg_ops; | 197 | - case INDEX_op_ext32u_i64: |
1741 | } | 198 | - case INDEX_op_ext_i32_i64: |
1742 | 199 | - case INDEX_op_extu_i32_i64: | |
1743 | static const TypeInfo tilegx_cpu_type_info = { | 200 | - case INDEX_op_extrl_i64_i32: |
1744 | diff --git a/target/tricore/cpu.c b/target/tricore/cpu.c | 201 | - case INDEX_op_extrh_i64_i32: |
1745 | index XXXXXXX..XXXXXXX 100644 | 202 | - if (arg_is_const(op->args[1])) { |
1746 | --- a/target/tricore/cpu.c | 203 | - tmp = do_constant_folding(opc, arg_info(op->args[1])->val, 0); |
1747 | +++ b/target/tricore/cpu.c | 204 | - tcg_opt_gen_movi(&ctx, op, op->args[0], tmp); |
1748 | @@ -XXX,XX +XXX,XX @@ static void tc27x_initfn(Object *obj) | 205 | - continue; |
1749 | set_feature(&cpu->env, TRICORE_FEATURE_161); | 206 | - } |
1750 | } | 207 | - break; |
1751 | |||
1752 | +#include "hw/core/tcg-cpu-ops.h" | ||
1753 | + | ||
1754 | +static struct TCGCPUOps tricore_tcg_ops = { | ||
1755 | + .initialize = tricore_tcg_init, | ||
1756 | + .synchronize_from_tb = tricore_cpu_synchronize_from_tb, | ||
1757 | + .tlb_fill = tricore_cpu_tlb_fill, | ||
1758 | +}; | ||
1759 | + | ||
1760 | static void tricore_cpu_class_init(ObjectClass *c, void *data) | ||
1761 | { | ||
1762 | TriCoreCPUClass *mcc = TRICORE_CPU_CLASS(c); | ||
1763 | @@ -XXX,XX +XXX,XX @@ static void tricore_cpu_class_init(ObjectClass *c, void *data) | ||
1764 | |||
1765 | cc->dump_state = tricore_cpu_dump_state; | ||
1766 | cc->set_pc = tricore_cpu_set_pc; | ||
1767 | - cc->tcg_ops.synchronize_from_tb = tricore_cpu_synchronize_from_tb; | ||
1768 | cc->get_phys_page_debug = tricore_cpu_get_phys_page_debug; | ||
1769 | - cc->tcg_ops.initialize = tricore_tcg_init; | ||
1770 | - cc->tcg_ops.tlb_fill = tricore_cpu_tlb_fill; | ||
1771 | + cc->tcg_ops = &tricore_tcg_ops; | ||
1772 | } | ||
1773 | |||
1774 | #define DEFINE_TRICORE_CPU_TYPE(cpu_model, initfn) \ | ||
1775 | diff --git a/target/unicore32/cpu.c b/target/unicore32/cpu.c | ||
1776 | index XXXXXXX..XXXXXXX 100644 | ||
1777 | --- a/target/unicore32/cpu.c | ||
1778 | +++ b/target/unicore32/cpu.c | ||
1779 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_uc32_cpu = { | ||
1780 | .unmigratable = 1, | ||
1781 | }; | ||
1782 | |||
1783 | +#include "hw/core/tcg-cpu-ops.h" | ||
1784 | + | ||
1785 | +static struct TCGCPUOps uc32_tcg_ops = { | ||
1786 | + .initialize = uc32_translate_init, | ||
1787 | + .cpu_exec_interrupt = uc32_cpu_exec_interrupt, | ||
1788 | + .tlb_fill = uc32_cpu_tlb_fill, | ||
1789 | + | ||
1790 | +#ifndef CONFIG_USER_ONLY | ||
1791 | + .do_interrupt = uc32_cpu_do_interrupt, | ||
1792 | +#endif /* !CONFIG_USER_ONLY */ | ||
1793 | +}; | ||
1794 | + | ||
1795 | static void uc32_cpu_class_init(ObjectClass *oc, void *data) | ||
1796 | { | ||
1797 | DeviceClass *dc = DEVICE_CLASS(oc); | ||
1798 | @@ -XXX,XX +XXX,XX @@ static void uc32_cpu_class_init(ObjectClass *oc, void *data) | ||
1799 | |||
1800 | cc->class_by_name = uc32_cpu_class_by_name; | ||
1801 | cc->has_work = uc32_cpu_has_work; | ||
1802 | - cc->tcg_ops.do_interrupt = uc32_cpu_do_interrupt; | ||
1803 | - cc->tcg_ops.cpu_exec_interrupt = uc32_cpu_exec_interrupt; | ||
1804 | cc->dump_state = uc32_cpu_dump_state; | ||
1805 | cc->set_pc = uc32_cpu_set_pc; | ||
1806 | - cc->tcg_ops.tlb_fill = uc32_cpu_tlb_fill; | ||
1807 | cc->get_phys_page_debug = uc32_cpu_get_phys_page_debug; | ||
1808 | - cc->tcg_ops.initialize = uc32_translate_init; | ||
1809 | dc->vmsd = &vmstate_uc32_cpu; | ||
1810 | + cc->tcg_ops = &uc32_tcg_ops; | ||
1811 | } | ||
1812 | |||
1813 | #define DEFINE_UNICORE32_CPU_TYPE(cpu_model, initfn) \ | ||
1814 | diff --git a/target/xtensa/cpu.c b/target/xtensa/cpu.c | ||
1815 | index XXXXXXX..XXXXXXX 100644 | ||
1816 | --- a/target/xtensa/cpu.c | ||
1817 | +++ b/target/xtensa/cpu.c | ||
1818 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_xtensa_cpu = { | ||
1819 | .unmigratable = 1, | ||
1820 | }; | ||
1821 | |||
1822 | +#include "hw/core/tcg-cpu-ops.h" | ||
1823 | + | ||
1824 | +static struct TCGCPUOps xtensa_tcg_ops = { | ||
1825 | + .initialize = xtensa_translate_init, | ||
1826 | + .cpu_exec_interrupt = xtensa_cpu_exec_interrupt, | ||
1827 | + .tlb_fill = xtensa_cpu_tlb_fill, | ||
1828 | + .debug_excp_handler = xtensa_breakpoint_handler, | ||
1829 | + | ||
1830 | +#ifndef CONFIG_USER_ONLY | ||
1831 | + .do_interrupt = xtensa_cpu_do_interrupt, | ||
1832 | + .do_transaction_failed = xtensa_cpu_do_transaction_failed, | ||
1833 | + .do_unaligned_access = xtensa_cpu_do_unaligned_access, | ||
1834 | +#endif /* !CONFIG_USER_ONLY */ | ||
1835 | +}; | ||
1836 | + | ||
1837 | static void xtensa_cpu_class_init(ObjectClass *oc, void *data) | ||
1838 | { | ||
1839 | DeviceClass *dc = DEVICE_CLASS(oc); | ||
1840 | @@ -XXX,XX +XXX,XX @@ static void xtensa_cpu_class_init(ObjectClass *oc, void *data) | ||
1841 | |||
1842 | cc->class_by_name = xtensa_cpu_class_by_name; | ||
1843 | cc->has_work = xtensa_cpu_has_work; | ||
1844 | - cc->tcg_ops.do_interrupt = xtensa_cpu_do_interrupt; | ||
1845 | - cc->tcg_ops.cpu_exec_interrupt = xtensa_cpu_exec_interrupt; | ||
1846 | cc->dump_state = xtensa_cpu_dump_state; | ||
1847 | cc->set_pc = xtensa_cpu_set_pc; | ||
1848 | cc->gdb_read_register = xtensa_cpu_gdb_read_register; | ||
1849 | cc->gdb_write_register = xtensa_cpu_gdb_write_register; | ||
1850 | cc->gdb_stop_before_watchpoint = true; | ||
1851 | - cc->tcg_ops.tlb_fill = xtensa_cpu_tlb_fill; | ||
1852 | #ifndef CONFIG_USER_ONLY | ||
1853 | - cc->tcg_ops.do_unaligned_access = xtensa_cpu_do_unaligned_access; | ||
1854 | cc->get_phys_page_debug = xtensa_cpu_get_phys_page_debug; | ||
1855 | - cc->tcg_ops.do_transaction_failed = xtensa_cpu_do_transaction_failed; | ||
1856 | #endif | ||
1857 | - cc->tcg_ops.debug_excp_handler = xtensa_breakpoint_handler; | ||
1858 | cc->disas_set_info = xtensa_cpu_disas_set_info; | ||
1859 | - cc->tcg_ops.initialize = xtensa_translate_init; | ||
1860 | dc->vmsd = &vmstate_xtensa_cpu; | ||
1861 | + cc->tcg_ops = &xtensa_tcg_ops; | ||
1862 | } | ||
1863 | |||
1864 | static const TypeInfo xtensa_cpu_type_info = { | ||
1865 | diff --git a/target/ppc/translate_init.c.inc b/target/ppc/translate_init.c.inc | ||
1866 | index XXXXXXX..XXXXXXX 100644 | ||
1867 | --- a/target/ppc/translate_init.c.inc | ||
1868 | +++ b/target/ppc/translate_init.c.inc | ||
1869 | @@ -XXX,XX +XXX,XX @@ static Property ppc_cpu_properties[] = { | ||
1870 | DEFINE_PROP_END_OF_LIST(), | ||
1871 | }; | ||
1872 | |||
1873 | +#ifdef CONFIG_TCG | ||
1874 | +#include "hw/core/tcg-cpu-ops.h" | ||
1875 | + | ||
1876 | +static struct TCGCPUOps ppc_tcg_ops = { | ||
1877 | + .initialize = ppc_translate_init, | ||
1878 | + .cpu_exec_interrupt = ppc_cpu_exec_interrupt, | ||
1879 | + .tlb_fill = ppc_cpu_tlb_fill, | ||
1880 | + | ||
1881 | +#ifndef CONFIG_USER_ONLY | ||
1882 | + .do_interrupt = ppc_cpu_do_interrupt, | ||
1883 | + .cpu_exec_enter = ppc_cpu_exec_enter, | ||
1884 | + .cpu_exec_exit = ppc_cpu_exec_exit, | ||
1885 | + .do_unaligned_access = ppc_cpu_do_unaligned_access, | ||
1886 | +#endif /* !CONFIG_USER_ONLY */ | ||
1887 | +}; | ||
1888 | +#endif /* CONFIG_TCG */ | ||
1889 | + | ||
1890 | static void ppc_cpu_class_init(ObjectClass *oc, void *data) | ||
1891 | { | ||
1892 | PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(oc); | ||
1893 | @@ -XXX,XX +XXX,XX @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data) | ||
1894 | #ifndef CONFIG_USER_ONLY | ||
1895 | cc->virtio_is_big_endian = ppc_cpu_is_big_endian; | ||
1896 | #endif | ||
1897 | -#ifdef CONFIG_TCG | ||
1898 | - cc->tcg_ops.initialize = ppc_translate_init; | ||
1899 | - cc->tcg_ops.cpu_exec_interrupt = ppc_cpu_exec_interrupt; | ||
1900 | - cc->tcg_ops.do_interrupt = ppc_cpu_do_interrupt; | ||
1901 | - cc->tcg_ops.tlb_fill = ppc_cpu_tlb_fill; | ||
1902 | -#ifndef CONFIG_USER_ONLY | ||
1903 | - cc->tcg_ops.cpu_exec_enter = ppc_cpu_exec_enter; | ||
1904 | - cc->tcg_ops.cpu_exec_exit = ppc_cpu_exec_exit; | ||
1905 | - cc->tcg_ops.do_unaligned_access = ppc_cpu_do_unaligned_access; | ||
1906 | -#endif /* !CONFIG_USER_ONLY */ | ||
1907 | -#endif /* CONFIG_TCG */ | ||
1908 | - | 208 | - |
1909 | cc->disas_set_info = ppc_disas_set_info; | 209 | CASE_OP_32_64(bswap16): |
1910 | 210 | CASE_OP_32_64(bswap32): | |
1911 | dc->fw_name = "PowerPC,UNKNOWN"; | 211 | case INDEX_op_bswap64_i64: |
1912 | + | 212 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) |
1913 | +#ifdef CONFIG_TCG | 213 | } |
1914 | + cc->tcg_ops = &ppc_tcg_ops; | 214 | break; |
1915 | +#endif /* CONFIG_TCG */ | 215 | |
1916 | } | 216 | - CASE_OP_32_64(add): |
1917 | 217 | - CASE_OP_32_64(sub): | |
1918 | static const TypeInfo ppc_cpu_type_info = { | 218 | - CASE_OP_32_64(mul): |
1919 | diff --git a/MAINTAINERS b/MAINTAINERS | 219 | - CASE_OP_32_64(or): |
1920 | index XXXXXXX..XXXXXXX 100644 | 220 | - CASE_OP_32_64(and): |
1921 | --- a/MAINTAINERS | 221 | - CASE_OP_32_64(xor): |
1922 | +++ b/MAINTAINERS | 222 | - CASE_OP_32_64(shl): |
1923 | @@ -XXX,XX +XXX,XX @@ F: include/exec/helper*.h | 223 | - CASE_OP_32_64(shr): |
1924 | F: include/exec/tb-hash.h | 224 | - CASE_OP_32_64(sar): |
1925 | F: include/sysemu/cpus.h | 225 | - CASE_OP_32_64(rotl): |
1926 | F: include/sysemu/tcg.h | 226 | - CASE_OP_32_64(rotr): |
1927 | +F: include/hw/core/tcg-cpu-ops.h | 227 | - CASE_OP_32_64(andc): |
1928 | 228 | - CASE_OP_32_64(orc): | |
1929 | FPU emulation | 229 | - CASE_OP_32_64(eqv): |
1930 | M: Aurelien Jarno <aurelien@aurel32.net> | 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 | |||
1931 | -- | 348 | -- |
1932 | 2.25.1 | 349 | 2.25.1 |
1933 | 350 | ||
1934 | 351 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Reduce some code duplication by folding the NE and EQ cases. | ||
1 | 2 | ||
3 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | ||
4 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | ||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | --- | ||
7 | tcg/optimize.c | 145 ++++++++++++++++++++++++------------------------- | ||
8 | 1 file changed, 72 insertions(+), 73 deletions(-) | ||
9 | |||
10 | diff --git a/tcg/optimize.c b/tcg/optimize.c | ||
11 | index XXXXXXX..XXXXXXX 100644 | ||
12 | --- a/tcg/optimize.c | ||
13 | +++ b/tcg/optimize.c | ||
14 | @@ -XXX,XX +XXX,XX @@ static bool fold_remainder(OptContext *ctx, TCGOp *op) | ||
15 | return fold_const2(ctx, op); | ||
16 | } | ||
17 | |||
18 | +static bool fold_setcond2(OptContext *ctx, TCGOp *op) | ||
19 | +{ | ||
20 | + TCGCond cond = op->args[5]; | ||
21 | + int i = do_constant_folding_cond2(&op->args[1], &op->args[3], cond); | ||
22 | + int inv = 0; | ||
23 | + | ||
24 | + if (i >= 0) { | ||
25 | + goto do_setcond_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[3]) && arg_info(op->args[3])->val == 0 && | ||
36 | + arg_is_const(op->args[4]) && arg_info(op->args[4])->val == 0) { | ||
37 | + goto do_setcond_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_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 | { | ||
89 | return fold_const2(ctx, op); | ||
90 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
91 | } | ||
92 | break; | ||
93 | |||
94 | - case INDEX_op_setcond2_i32: | ||
95 | - i = do_constant_folding_cond2(&op->args[1], &op->args[3], | ||
96 | - op->args[5]); | ||
97 | - if (i >= 0) { | ||
98 | - do_setcond_const: | ||
99 | - tcg_opt_gen_movi(&ctx, op, op->args[0], i); | ||
100 | - continue; | ||
101 | - } | ||
102 | - if ((op->args[5] == TCG_COND_LT || op->args[5] == TCG_COND_GE) | ||
103 | - && arg_is_const(op->args[3]) | ||
104 | - && arg_info(op->args[3])->val == 0 | ||
105 | - && arg_is_const(op->args[4]) | ||
106 | - && arg_info(op->args[4])->val == 0) { | ||
107 | - /* Simplify LT/GE comparisons vs zero to a single compare | ||
108 | - vs the high word of the input. */ | ||
109 | - do_setcond_high: | ||
110 | - reset_temp(op->args[0]); | ||
111 | - arg_info(op->args[0])->z_mask = 1; | ||
112 | - op->opc = INDEX_op_setcond_i32; | ||
113 | - op->args[1] = op->args[2]; | ||
114 | - op->args[2] = op->args[4]; | ||
115 | - op->args[3] = op->args[5]; | ||
116 | - break; | ||
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 | -- | ||
181 | 2.25.1 | ||
182 | |||
183 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Reduce some code duplication by folding the NE and EQ cases. | ||
1 | 2 | ||
3 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | ||
4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
5 | --- | ||
6 | tcg/optimize.c | 159 +++++++++++++++++++++++++------------------------ | ||
7 | 1 file changed, 81 insertions(+), 78 deletions(-) | ||
8 | |||
9 | diff --git a/tcg/optimize.c b/tcg/optimize.c | ||
10 | index XXXXXXX..XXXXXXX 100644 | ||
11 | --- a/tcg/optimize.c | ||
12 | +++ b/tcg/optimize.c | ||
13 | @@ -XXX,XX +XXX,XX @@ static bool fold_andc(OptContext *ctx, TCGOp *op) | ||
14 | return fold_const2(ctx, op); | ||
15 | } | ||
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 | { | ||
97 | TCGContext *s = ctx->tcg; | ||
98 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
99 | } | ||
100 | break; | ||
101 | |||
102 | - case INDEX_op_brcond2_i32: | ||
103 | - i = do_constant_folding_cond2(&op->args[0], &op->args[2], | ||
104 | - op->args[4]); | ||
105 | - if (i == 0) { | ||
106 | - do_brcond_false: | ||
107 | - tcg_op_remove(s, op); | ||
108 | - continue; | ||
109 | - } | ||
110 | - if (i > 0) { | ||
111 | - do_brcond_true: | ||
112 | - op->opc = opc = INDEX_op_br; | ||
113 | - op->args[0] = op->args[5]; | ||
114 | - break; | ||
115 | - } | ||
116 | - if ((op->args[4] == TCG_COND_LT || op->args[4] == TCG_COND_GE) | ||
117 | - && arg_is_const(op->args[2]) | ||
118 | - && arg_info(op->args[2])->val == 0 | ||
119 | - && arg_is_const(op->args[3]) | ||
120 | - && arg_info(op->args[3])->val == 0) { | ||
121 | - /* Simplify LT/GE comparisons vs zero to a single compare | ||
122 | - vs the high word of the input. */ | ||
123 | - do_brcond_high: | ||
124 | - op->opc = opc = INDEX_op_brcond_i32; | ||
125 | - op->args[0] = op->args[1]; | ||
126 | - op->args[1] = op->args[3]; | ||
127 | - op->args[2] = op->args[4]; | ||
128 | - op->args[3] = op->args[5]; | ||
129 | - break; | ||
130 | - } | ||
131 | - if (op->args[4] == TCG_COND_EQ) { | ||
132 | - /* Simplify EQ comparisons where one of the pairs | ||
133 | - can be simplified. */ | ||
134 | - i = do_constant_folding_cond(INDEX_op_brcond_i32, | ||
135 | - op->args[0], op->args[2], | ||
136 | - TCG_COND_EQ); | ||
137 | - if (i == 0) { | ||
138 | - goto do_brcond_false; | ||
139 | - } else if (i > 0) { | ||
140 | - goto do_brcond_high; | ||
141 | - } | ||
142 | - i = do_constant_folding_cond(INDEX_op_brcond_i32, | ||
143 | - op->args[1], op->args[3], | ||
144 | - TCG_COND_EQ); | ||
145 | - if (i == 0) { | ||
146 | - goto do_brcond_false; | ||
147 | - } else if (i < 0) { | ||
148 | - break; | ||
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 | -- | ||
194 | 2.25.1 | ||
195 | |||
196 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | ||
2 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
4 | --- | ||
5 | tcg/optimize.c | 33 +++++++++++++++++++-------------- | ||
6 | 1 file changed, 19 insertions(+), 14 deletions(-) | ||
1 | 7 | ||
8 | diff --git a/tcg/optimize.c b/tcg/optimize.c | ||
9 | index XXXXXXX..XXXXXXX 100644 | ||
10 | --- a/tcg/optimize.c | ||
11 | +++ b/tcg/optimize.c | ||
12 | @@ -XXX,XX +XXX,XX @@ static bool fold_andc(OptContext *ctx, TCGOp *op) | ||
13 | return fold_const2(ctx, op); | ||
14 | } | ||
15 | |||
16 | +static bool fold_brcond(OptContext *ctx, TCGOp *op) | ||
17 | +{ | ||
18 | + TCGCond cond = op->args[2]; | ||
19 | + int i = do_constant_folding_cond(op->opc, op->args[0], op->args[1], cond); | ||
20 | + | ||
21 | + if (i == 0) { | ||
22 | + tcg_op_remove(ctx->tcg, op); | ||
23 | + return true; | ||
24 | + } | ||
25 | + if (i > 0) { | ||
26 | + op->opc = INDEX_op_br; | ||
27 | + op->args[0] = op->args[3]; | ||
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 | -- | ||
67 | 2.25.1 | ||
68 | |||
69 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | ||
2 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
4 | --- | ||
5 | tcg/optimize.c | 23 ++++++++++++++--------- | ||
6 | 1 file changed, 14 insertions(+), 9 deletions(-) | ||
1 | 7 | ||
8 | diff --git a/tcg/optimize.c b/tcg/optimize.c | ||
9 | index XXXXXXX..XXXXXXX 100644 | ||
10 | --- a/tcg/optimize.c | ||
11 | +++ b/tcg/optimize.c | ||
12 | @@ -XXX,XX +XXX,XX @@ static bool fold_remainder(OptContext *ctx, TCGOp *op) | ||
13 | return fold_const2(ctx, op); | ||
14 | } | ||
15 | |||
16 | +static bool fold_setcond(OptContext *ctx, TCGOp *op) | ||
17 | +{ | ||
18 | + TCGCond cond = op->args[3]; | ||
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 | +} | ||
26 | + | ||
27 | static bool fold_setcond2(OptContext *ctx, TCGOp *op) | ||
28 | { | ||
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 | -- | ||
57 | 2.25.1 | ||
58 | |||
59 | diff view generated by jsdifflib |
1 | Trivially implemented like other arithmetic. | 1 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> |
---|---|---|---|
2 | Tested via check-tcg and the ppc64 target. | 2 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
3 | |||
4 | Tested-by: Alex Bennée <alex.bennee@linaro.org> | ||
5 | Reviewed-by: Alex Bennée <alex.bennee@linaro.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/tci/tcg-target.h | 4 ++-- | 5 | tcg/optimize.c | 37 +++++++++++++++++++++---------------- |
9 | tcg/tci.c | 28 ++++++++++++++++++++++------ | 6 | 1 file changed, 21 insertions(+), 16 deletions(-) |
10 | tcg/tci/tcg-target.c.inc | 10 ++++------ | ||
11 | 3 files changed, 28 insertions(+), 14 deletions(-) | ||
12 | 7 | ||
13 | diff --git a/tcg/tci/tcg-target.h b/tcg/tci/tcg-target.h | 8 | diff --git a/tcg/optimize.c b/tcg/optimize.c |
14 | index XXXXXXX..XXXXXXX 100644 | 9 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/tcg/tci/tcg-target.h | 10 | --- a/tcg/optimize.c |
16 | +++ b/tcg/tci/tcg-target.h | 11 | +++ b/tcg/optimize.c |
17 | @@ -XXX,XX +XXX,XX @@ | 12 | @@ -XXX,XX +XXX,XX @@ static bool fold_mul_highpart(OptContext *ctx, TCGOp *op) |
18 | #define TCG_TARGET_HAS_extract_i64 0 | 13 | return fold_const2(ctx, op); |
19 | #define TCG_TARGET_HAS_sextract_i64 0 | 14 | } |
20 | #define TCG_TARGET_HAS_extract2_i64 0 | 15 | |
21 | -#define TCG_TARGET_HAS_div_i64 0 | 16 | +static bool fold_mulu2_i32(OptContext *ctx, TCGOp *op) |
22 | -#define TCG_TARGET_HAS_rem_i64 0 | 17 | +{ |
23 | +#define TCG_TARGET_HAS_div_i64 1 | 18 | + if (arg_is_const(op->args[2]) && arg_is_const(op->args[3])) { |
24 | +#define TCG_TARGET_HAS_rem_i64 1 | 19 | + uint32_t a = arg_info(op->args[2])->val; |
25 | #define TCG_TARGET_HAS_ext8s_i64 1 | 20 | + uint32_t b = arg_info(op->args[3])->val; |
26 | #define TCG_TARGET_HAS_ext16s_i64 1 | 21 | + uint64_t r = (uint64_t)a * b; |
27 | #define TCG_TARGET_HAS_ext32s_i64 1 | 22 | + TCGArg rl, rh; |
28 | diff --git a/tcg/tci.c b/tcg/tci.c | 23 | + TCGOp *op2 = tcg_op_insert_before(ctx->tcg, op, INDEX_op_mov_i32); |
29 | index XXXXXXX..XXXXXXX 100644 | 24 | + |
30 | --- a/tcg/tci.c | 25 | + rl = op->args[0]; |
31 | +++ b/tcg/tci.c | 26 | + rh = op->args[1]; |
32 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 27 | + tcg_opt_gen_movi(ctx, op, rl, (int32_t)r); |
33 | t2 = tci_read_ri64(regs, &tb_ptr); | 28 | + tcg_opt_gen_movi(ctx, op2, rh, (int32_t)(r >> 32)); |
34 | tci_write_reg(regs, t0, t1 * t2); | 29 | + return true; |
30 | + } | ||
31 | + return false; | ||
32 | +} | ||
33 | + | ||
34 | static bool fold_nand(OptContext *ctx, TCGOp *op) | ||
35 | { | ||
36 | return fold_const2(ctx, op); | ||
37 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
38 | } | ||
35 | break; | 39 | break; |
36 | -#if TCG_TARGET_HAS_div_i64 | 40 | |
37 | case INDEX_op_div_i64: | 41 | - case INDEX_op_mulu2_i32: |
38 | - case INDEX_op_divu_i64: | 42 | - if (arg_is_const(op->args[2]) && arg_is_const(op->args[3])) { |
39 | - case INDEX_op_rem_i64: | 43 | - uint32_t a = arg_info(op->args[2])->val; |
40 | - case INDEX_op_remu_i64: | 44 | - uint32_t b = arg_info(op->args[3])->val; |
41 | - TODO(); | 45 | - uint64_t r = (uint64_t)a * b; |
42 | + t0 = *tb_ptr++; | 46 | - TCGArg rl, rh; |
43 | + t1 = tci_read_ri64(regs, &tb_ptr); | 47 | - TCGOp *op2 = tcg_op_insert_before(s, op, INDEX_op_mov_i32); |
44 | + t2 = tci_read_ri64(regs, &tb_ptr); | 48 | - |
45 | + tci_write_reg(regs, t0, (int64_t)t1 / (int64_t)t2); | 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; | ||
56 | - | ||
57 | default: | ||
58 | break; | ||
59 | |||
60 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
61 | CASE_OP_32_64(muluh): | ||
62 | done = fold_mul_highpart(&ctx, op); | ||
63 | break; | ||
64 | + case INDEX_op_mulu2_i32: | ||
65 | + done = fold_mulu2_i32(&ctx, op); | ||
46 | + break; | 66 | + break; |
47 | + case INDEX_op_divu_i64: | 67 | CASE_OP_32_64(nand): |
48 | + t0 = *tb_ptr++; | 68 | done = fold_nand(&ctx, op); |
49 | + t1 = tci_read_ri64(regs, &tb_ptr); | ||
50 | + t2 = tci_read_ri64(regs, &tb_ptr); | ||
51 | + tci_write_reg(regs, t0, (uint64_t)t1 / (uint64_t)t2); | ||
52 | + break; | ||
53 | + case INDEX_op_rem_i64: | ||
54 | + t0 = *tb_ptr++; | ||
55 | + t1 = tci_read_ri64(regs, &tb_ptr); | ||
56 | + t2 = tci_read_ri64(regs, &tb_ptr); | ||
57 | + tci_write_reg(regs, t0, (int64_t)t1 % (int64_t)t2); | ||
58 | + break; | ||
59 | + case INDEX_op_remu_i64: | ||
60 | + t0 = *tb_ptr++; | ||
61 | + t1 = tci_read_ri64(regs, &tb_ptr); | ||
62 | + t2 = tci_read_ri64(regs, &tb_ptr); | ||
63 | + tci_write_reg(regs, t0, (uint64_t)t1 % (uint64_t)t2); | ||
64 | break; | 69 | break; |
65 | -#endif | ||
66 | case INDEX_op_and_i64: | ||
67 | t0 = *tb_ptr++; | ||
68 | t1 = tci_read_ri64(regs, &tb_ptr); | ||
69 | diff --git a/tcg/tci/tcg-target.c.inc b/tcg/tci/tcg-target.c.inc | ||
70 | index XXXXXXX..XXXXXXX 100644 | ||
71 | --- a/tcg/tci/tcg-target.c.inc | ||
72 | +++ b/tcg/tci/tcg-target.c.inc | ||
73 | @@ -XXX,XX +XXX,XX @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg *args, | ||
74 | case INDEX_op_sar_i64: | ||
75 | case INDEX_op_rotl_i64: /* Optional (TCG_TARGET_HAS_rot_i64). */ | ||
76 | case INDEX_op_rotr_i64: /* Optional (TCG_TARGET_HAS_rot_i64). */ | ||
77 | + case INDEX_op_div_i64: /* Optional (TCG_TARGET_HAS_div_i64). */ | ||
78 | + case INDEX_op_divu_i64: /* Optional (TCG_TARGET_HAS_div_i64). */ | ||
79 | + case INDEX_op_rem_i64: /* Optional (TCG_TARGET_HAS_div_i64). */ | ||
80 | + case INDEX_op_remu_i64: /* Optional (TCG_TARGET_HAS_div_i64). */ | ||
81 | tcg_out_r(s, args[0]); | ||
82 | tcg_out_ri64(s, const_args[1], args[1]); | ||
83 | tcg_out_ri64(s, const_args[2], args[2]); | ||
84 | @@ -XXX,XX +XXX,XX @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg *args, | ||
85 | tcg_debug_assert(args[4] <= UINT8_MAX); | ||
86 | tcg_out8(s, args[4]); | ||
87 | break; | ||
88 | - case INDEX_op_div_i64: /* Optional (TCG_TARGET_HAS_div_i64). */ | ||
89 | - case INDEX_op_divu_i64: /* Optional (TCG_TARGET_HAS_div_i64). */ | ||
90 | - case INDEX_op_rem_i64: /* Optional (TCG_TARGET_HAS_div_i64). */ | ||
91 | - case INDEX_op_remu_i64: /* Optional (TCG_TARGET_HAS_div_i64). */ | ||
92 | - TODO(); | ||
93 | - break; | ||
94 | case INDEX_op_brcond_i64: | ||
95 | tcg_out_r(s, args[0]); | ||
96 | tcg_out_ri64(s, const_args[1], args[1]); | ||
97 | -- | 70 | -- |
98 | 2.25.1 | 71 | 2.25.1 |
99 | 72 | ||
100 | 73 | diff view generated by jsdifflib |
1 | We do not simultaneously support div and div2 -- it's one | 1 | Add two additional helpers, fold_add2_i32 and fold_sub2_i32 |
---|---|---|---|
2 | or the other. TCI is already using div, so remove div2. | 2 | which will not be simple wrappers forever. |
3 | 3 | ||
4 | Tested-by: Alex Bennée <alex.bennee@linaro.org> | 4 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> |
5 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
7 | --- | 7 | --- |
8 | tcg/tci.c | 12 ------------ | 8 | tcg/optimize.c | 70 +++++++++++++++++++++++++++++++------------------- |
9 | tcg/tci/tcg-target.c.inc | 8 -------- | 9 | 1 file changed, 44 insertions(+), 26 deletions(-) |
10 | 2 files changed, 20 deletions(-) | ||
11 | 10 | ||
12 | diff --git a/tcg/tci.c b/tcg/tci.c | 11 | diff --git a/tcg/optimize.c b/tcg/optimize.c |
13 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/tcg/tci.c | 13 | --- a/tcg/optimize.c |
15 | +++ b/tcg/tci.c | 14 | +++ b/tcg/optimize.c |
16 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 15 | @@ -XXX,XX +XXX,XX @@ static bool fold_add(OptContext *ctx, TCGOp *op) |
17 | t2 = tci_read_ri32(regs, &tb_ptr); | 16 | return fold_const2(ctx, op); |
18 | tci_write_reg(regs, t0, t1 * t2); | 17 | } |
18 | |||
19 | +static bool fold_addsub2_i32(OptContext *ctx, TCGOp *op, bool add) | ||
20 | +{ | ||
21 | + if (arg_is_const(op->args[2]) && arg_is_const(op->args[3]) && | ||
22 | + arg_is_const(op->args[4]) && arg_is_const(op->args[5])) { | ||
23 | + uint32_t al = arg_info(op->args[2])->val; | ||
24 | + uint32_t ah = arg_info(op->args[3])->val; | ||
25 | + uint32_t bl = arg_info(op->args[4])->val; | ||
26 | + uint32_t bh = arg_info(op->args[5])->val; | ||
27 | + uint64_t a = ((uint64_t)ah << 32) | al; | ||
28 | + uint64_t b = ((uint64_t)bh << 32) | bl; | ||
29 | + TCGArg rl, rh; | ||
30 | + TCGOp *op2 = tcg_op_insert_before(ctx->tcg, op, INDEX_op_mov_i32); | ||
31 | + | ||
32 | + if (add) { | ||
33 | + a += b; | ||
34 | + } else { | ||
35 | + a -= b; | ||
36 | + } | ||
37 | + | ||
38 | + rl = op->args[0]; | ||
39 | + rh = op->args[1]; | ||
40 | + tcg_opt_gen_movi(ctx, op, rl, (int32_t)a); | ||
41 | + tcg_opt_gen_movi(ctx, op2, rh, (int32_t)(a >> 32)); | ||
42 | + return true; | ||
43 | + } | ||
44 | + return false; | ||
45 | +} | ||
46 | + | ||
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 | } | ||
19 | break; | 69 | break; |
20 | -#if TCG_TARGET_HAS_div_i32 | 70 | |
21 | case INDEX_op_div_i32: | 71 | - case INDEX_op_add2_i32: |
22 | t0 = *tb_ptr++; | 72 | - case INDEX_op_sub2_i32: |
23 | t1 = tci_read_ri32(regs, &tb_ptr); | 73 | - if (arg_is_const(op->args[2]) && arg_is_const(op->args[3]) |
24 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 74 | - && arg_is_const(op->args[4]) && arg_is_const(op->args[5])) { |
25 | t2 = tci_read_ri32(regs, &tb_ptr); | 75 | - uint32_t al = arg_info(op->args[2])->val; |
26 | tci_write_reg(regs, t0, t1 % t2); | 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: | ||
27 | break; | 99 | break; |
28 | -#elif TCG_TARGET_HAS_div2_i32 | 100 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) |
29 | - case INDEX_op_div2_i32: | 101 | CASE_OP_32_64_VEC(add): |
30 | - case INDEX_op_divu2_i32: | 102 | done = fold_add(&ctx, op); |
31 | - TODO(); | ||
32 | - break; | ||
33 | -#endif | ||
34 | case INDEX_op_and_i32: | ||
35 | t0 = *tb_ptr++; | ||
36 | t1 = tci_read_ri32(regs, &tb_ptr); | ||
37 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | ||
38 | case INDEX_op_remu_i64: | ||
39 | TODO(); | ||
40 | break; | 103 | break; |
41 | -#elif TCG_TARGET_HAS_div2_i64 | 104 | + case INDEX_op_add2_i32: |
42 | - case INDEX_op_div2_i64: | 105 | + done = fold_add2_i32(&ctx, op); |
43 | - case INDEX_op_divu2_i64: | 106 | + break; |
44 | - TODO(); | 107 | CASE_OP_32_64_VEC(and): |
45 | - break; | 108 | done = fold_and(&ctx, op); |
46 | #endif | 109 | break; |
47 | case INDEX_op_and_i64: | 110 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) |
48 | t0 = *tb_ptr++; | 111 | CASE_OP_32_64_VEC(sub): |
49 | diff --git a/tcg/tci/tcg-target.c.inc b/tcg/tci/tcg-target.c.inc | 112 | done = fold_sub(&ctx, op); |
50 | index XXXXXXX..XXXXXXX 100644 | 113 | break; |
51 | --- a/tcg/tci/tcg-target.c.inc | 114 | + case INDEX_op_sub2_i32: |
52 | +++ b/tcg/tci/tcg-target.c.inc | 115 | + done = fold_sub2_i32(&ctx, op); |
53 | @@ -XXX,XX +XXX,XX @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg *args, | 116 | + break; |
54 | case INDEX_op_remu_i64: /* Optional (TCG_TARGET_HAS_div_i64). */ | 117 | CASE_OP_32_64_VEC(xor): |
55 | TODO(); | 118 | done = fold_xor(&ctx, op); |
56 | break; | 119 | break; |
57 | - case INDEX_op_div2_i64: /* Optional (TCG_TARGET_HAS_div2_i64). */ | ||
58 | - case INDEX_op_divu2_i64: /* Optional (TCG_TARGET_HAS_div2_i64). */ | ||
59 | - TODO(); | ||
60 | - break; | ||
61 | case INDEX_op_brcond_i64: | ||
62 | tcg_out_r(s, args[0]); | ||
63 | tcg_out_ri64(s, const_args[1], args[1]); | ||
64 | @@ -XXX,XX +XXX,XX @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg *args, | ||
65 | tcg_out_ri32(s, const_args[1], args[1]); | ||
66 | tcg_out_ri32(s, const_args[2], args[2]); | ||
67 | break; | ||
68 | - case INDEX_op_div2_i32: /* Optional (TCG_TARGET_HAS_div2_i32). */ | ||
69 | - case INDEX_op_divu2_i32: /* Optional (TCG_TARGET_HAS_div2_i32). */ | ||
70 | - TODO(); | ||
71 | - break; | ||
72 | #if TCG_TARGET_REG_BITS == 32 | ||
73 | case INDEX_op_add2_i32: | ||
74 | case INDEX_op_sub2_i32: | ||
75 | -- | 120 | -- |
76 | 2.25.1 | 121 | 2.25.1 |
77 | 122 | ||
78 | 123 | diff view generated by jsdifflib |
1 | Tested-by: Alex Bennée <alex.bennee@linaro.org> | 1 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> |
---|---|---|---|
2 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 2 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
4 | --- | 4 | --- |
5 | tcg/tci.c | 7 +------ | 5 | tcg/optimize.c | 56 ++++++++++++++++++++++++++++---------------------- |
6 | 1 file changed, 1 insertion(+), 6 deletions(-) | 6 | 1 file changed, 31 insertions(+), 25 deletions(-) |
7 | 7 | ||
8 | diff --git a/tcg/tci.c b/tcg/tci.c | 8 | diff --git a/tcg/optimize.c b/tcg/optimize.c |
9 | index XXXXXXX..XXXXXXX 100644 | 9 | index XXXXXXX..XXXXXXX 100644 |
10 | --- a/tcg/tci.c | 10 | --- a/tcg/optimize.c |
11 | +++ b/tcg/tci.c | 11 | +++ b/tcg/optimize.c |
12 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 12 | @@ -XXX,XX +XXX,XX @@ static bool fold_mb(OptContext *ctx, TCGOp *op) |
13 | *(uint16_t *)(t1 + t2) = t0; | 13 | return true; |
14 | } | ||
15 | |||
16 | +static bool fold_movcond(OptContext *ctx, TCGOp *op) | ||
17 | +{ | ||
18 | + TCGOpcode opc = op->opc; | ||
19 | + TCGCond cond = op->args[5]; | ||
20 | + int i = do_constant_folding_cond(opc, op->args[1], op->args[2], cond); | ||
21 | + | ||
22 | + if (i >= 0) { | ||
23 | + return tcg_opt_gen_mov(ctx, op, op->args[0], op->args[4 - i]); | ||
24 | + } | ||
25 | + | ||
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 | } | ||
14 | break; | 49 | break; |
15 | case INDEX_op_st_i32: | 50 | |
16 | + CASE_64(st32) | 51 | - CASE_OP_32_64(movcond): |
17 | t0 = tci_read_r32(regs, &tb_ptr); | 52 | - i = do_constant_folding_cond(opc, op->args[1], |
18 | t1 = tci_read_r(regs, &tb_ptr); | 53 | - op->args[2], op->args[5]); |
19 | t2 = tci_read_s32(&tb_ptr); | 54 | - if (i >= 0) { |
20 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 55 | - tcg_opt_gen_mov(&ctx, op, op->args[0], op->args[4 - i]); |
21 | t2 = tci_read_s32(&tb_ptr); | 56 | - continue; |
22 | tci_write_reg(regs, t0, *(uint64_t *)(t1 + t2)); | 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: | ||
23 | break; | 77 | break; |
24 | - case INDEX_op_st32_i64: | 78 | |
25 | - t0 = tci_read_r32(regs, &tb_ptr); | 79 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) |
26 | - t1 = tci_read_r(regs, &tb_ptr); | 80 | case INDEX_op_mb: |
27 | - t2 = tci_read_s32(&tb_ptr); | 81 | done = fold_mb(&ctx, op); |
28 | - *(uint32_t *)(t1 + t2) = t0; | 82 | break; |
29 | - break; | 83 | + CASE_OP_32_64(movcond): |
30 | case INDEX_op_st_i64: | 84 | + done = fold_movcond(&ctx, op); |
31 | t0 = tci_read_r64(regs, &tb_ptr); | 85 | + break; |
32 | t1 = tci_read_r(regs, &tb_ptr); | 86 | CASE_OP_32_64(mul): |
87 | done = fold_mul(&ctx, op); | ||
88 | break; | ||
33 | -- | 89 | -- |
34 | 2.25.1 | 90 | 2.25.1 |
35 | 91 | ||
36 | 92 | diff view generated by jsdifflib |
1 | Tested-by: Alex Bennée <alex.bennee@linaro.org> | 1 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> |
---|---|---|---|
2 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 2 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
4 | --- | 4 | --- |
5 | tcg/tci.c | 8 +------- | 5 | tcg/optimize.c | 39 ++++++++++++++++++++++----------------- |
6 | 1 file changed, 1 insertion(+), 7 deletions(-) | 6 | 1 file changed, 22 insertions(+), 17 deletions(-) |
7 | 7 | ||
8 | diff --git a/tcg/tci.c b/tcg/tci.c | 8 | diff --git a/tcg/optimize.c b/tcg/optimize.c |
9 | index XXXXXXX..XXXXXXX 100644 | 9 | index XXXXXXX..XXXXXXX 100644 |
10 | --- a/tcg/tci.c | 10 | --- a/tcg/optimize.c |
11 | +++ b/tcg/tci.c | 11 | +++ b/tcg/optimize.c |
12 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 12 | @@ -XXX,XX +XXX,XX @@ static bool fold_eqv(OptContext *ctx, TCGOp *op) |
13 | t2 = tci_read_s32(&tb_ptr); | 13 | return fold_const2(ctx, op); |
14 | *(uint8_t *)(t1 + t2) = t0; | 14 | } |
15 | |||
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 | } | ||
15 | break; | 40 | break; |
16 | - case INDEX_op_st16_i32: | 41 | |
17 | + CASE_32_64(st16) | 42 | - CASE_OP_32_64(extract2): |
18 | t0 = tci_read_r16(regs, &tb_ptr); | 43 | - if (arg_is_const(op->args[1]) && arg_is_const(op->args[2])) { |
19 | t1 = tci_read_r(regs, &tb_ptr); | 44 | - uint64_t v1 = arg_info(op->args[1])->val; |
20 | t2 = tci_read_s32(&tb_ptr); | 45 | - uint64_t v2 = arg_info(op->args[2])->val; |
21 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 46 | - int shr = op->args[3]; |
22 | t2 = tci_read_s32(&tb_ptr); | 47 | - |
23 | tci_write_reg(regs, t0, *(uint64_t *)(t1 + t2)); | 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: | ||
24 | break; | 60 | break; |
25 | - case INDEX_op_st16_i64: | 61 | |
26 | - t0 = tci_read_r16(regs, &tb_ptr); | 62 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) |
27 | - t1 = tci_read_r(regs, &tb_ptr); | 63 | CASE_OP_32_64(eqv): |
28 | - t2 = tci_read_s32(&tb_ptr); | 64 | done = fold_eqv(&ctx, op); |
29 | - *(uint16_t *)(t1 + t2) = t0; | 65 | break; |
30 | - break; | 66 | + CASE_OP_32_64(extract2): |
31 | case INDEX_op_st32_i64: | 67 | + done = fold_extract2(&ctx, op); |
32 | t0 = tci_read_r32(regs, &tb_ptr); | 68 | + break; |
33 | t1 = tci_read_r(regs, &tb_ptr); | 69 | CASE_OP_32_64(ext8s): |
70 | CASE_OP_32_64(ext16s): | ||
71 | case INDEX_op_ext32s_i64: | ||
34 | -- | 72 | -- |
35 | 2.25.1 | 73 | 2.25.1 |
36 | 74 | ||
37 | 75 | diff view generated by jsdifflib |
1 | Tested-by: Alex Bennée <alex.bennee@linaro.org> | 1 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> |
---|---|---|---|
2 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 2 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
4 | --- | 4 | --- |
5 | tcg/tci.c | 8 +------- | 5 | tcg/optimize.c | 48 ++++++++++++++++++++++++++++++------------------ |
6 | 1 file changed, 1 insertion(+), 7 deletions(-) | 6 | 1 file changed, 30 insertions(+), 18 deletions(-) |
7 | 7 | ||
8 | diff --git a/tcg/tci.c b/tcg/tci.c | 8 | diff --git a/tcg/optimize.c b/tcg/optimize.c |
9 | index XXXXXXX..XXXXXXX 100644 | 9 | index XXXXXXX..XXXXXXX 100644 |
10 | --- a/tcg/tci.c | 10 | --- a/tcg/optimize.c |
11 | +++ b/tcg/tci.c | 11 | +++ b/tcg/optimize.c |
12 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 12 | @@ -XXX,XX +XXX,XX @@ static bool fold_eqv(OptContext *ctx, TCGOp *op) |
13 | t2 = tci_read_s32(&tb_ptr); | 13 | return fold_const2(ctx, op); |
14 | tci_write_reg(regs, t0, *(uint32_t *)(t1 + t2)); | 14 | } |
15 | |||
16 | +static bool fold_extract(OptContext *ctx, TCGOp *op) | ||
17 | +{ | ||
18 | + if (arg_is_const(op->args[1])) { | ||
19 | + uint64_t t; | ||
20 | + | ||
21 | + t = arg_info(op->args[1])->val; | ||
22 | + t = extract64(t, op->args[2], op->args[3]); | ||
23 | + return tcg_opt_gen_movi(ctx, op, op->args[0], t); | ||
24 | + } | ||
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 | } | ||
15 | break; | 52 | break; |
16 | - case INDEX_op_st8_i32: | 53 | |
17 | + CASE_32_64(st8) | 54 | - CASE_OP_32_64(extract): |
18 | t0 = tci_read_r8(regs, &tb_ptr); | 55 | - if (arg_is_const(op->args[1])) { |
19 | t1 = tci_read_r(regs, &tb_ptr); | 56 | - tmp = extract64(arg_info(op->args[1])->val, |
20 | t2 = tci_read_s32(&tb_ptr); | 57 | - op->args[2], op->args[3]); |
21 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 58 | - tcg_opt_gen_movi(&ctx, op, op->args[0], tmp); |
22 | t2 = tci_read_s32(&tb_ptr); | 59 | - continue; |
23 | tci_write_reg(regs, t0, *(uint64_t *)(t1 + t2)); | 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: | ||
24 | break; | 73 | break; |
25 | - case INDEX_op_st8_i64: | 74 | |
26 | - t0 = tci_read_r8(regs, &tb_ptr); | 75 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) |
27 | - t1 = tci_read_r(regs, &tb_ptr); | 76 | CASE_OP_32_64(eqv): |
28 | - t2 = tci_read_s32(&tb_ptr); | 77 | done = fold_eqv(&ctx, op); |
29 | - *(uint8_t *)(t1 + t2) = t0; | 78 | break; |
30 | - break; | 79 | + CASE_OP_32_64(extract): |
31 | case INDEX_op_st16_i64: | 80 | + done = fold_extract(&ctx, op); |
32 | t0 = tci_read_r16(regs, &tb_ptr); | 81 | + break; |
33 | t1 = tci_read_r(regs, &tb_ptr); | 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; | ||
34 | -- | 95 | -- |
35 | 2.25.1 | 96 | 2.25.1 |
36 | 97 | ||
37 | 98 | diff view generated by jsdifflib |
1 | Tested-by: Alex Bennée <alex.bennee@linaro.org> | 1 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> |
---|---|---|---|
2 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 2 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
4 | --- | 4 | --- |
5 | tcg/tci.c | 7 +------ | 5 | tcg/optimize.c | 25 +++++++++++++++---------- |
6 | 1 file changed, 1 insertion(+), 6 deletions(-) | 6 | 1 file changed, 15 insertions(+), 10 deletions(-) |
7 | 7 | ||
8 | diff --git a/tcg/tci.c b/tcg/tci.c | 8 | diff --git a/tcg/optimize.c b/tcg/optimize.c |
9 | index XXXXXXX..XXXXXXX 100644 | 9 | index XXXXXXX..XXXXXXX 100644 |
10 | --- a/tcg/tci.c | 10 | --- a/tcg/optimize.c |
11 | +++ b/tcg/tci.c | 11 | +++ b/tcg/optimize.c |
12 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 12 | @@ -XXX,XX +XXX,XX @@ static bool fold_ctpop(OptContext *ctx, TCGOp *op) |
13 | tci_write_reg(regs, t0, *(int16_t *)(t1 + t2)); | 13 | return fold_const1(ctx, op); |
14 | } | ||
15 | |||
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 | } | ||
14 | break; | 33 | break; |
15 | case INDEX_op_ld_i32: | 34 | |
16 | + CASE_64(ld32u) | 35 | - CASE_OP_32_64(deposit): |
17 | t0 = *tb_ptr++; | 36 | - if (arg_is_const(op->args[1]) && arg_is_const(op->args[2])) { |
18 | t1 = tci_read_r(regs, &tb_ptr); | 37 | - tmp = deposit64(arg_info(op->args[1])->val, |
19 | t2 = tci_read_s32(&tb_ptr); | 38 | - op->args[3], op->args[4], |
20 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 39 | - arg_info(op->args[2])->val); |
21 | 40 | - tcg_opt_gen_movi(&ctx, op, op->args[0], tmp); | |
22 | /* Load/store operations (64 bit). */ | 41 | - continue; |
23 | 42 | - } | |
24 | - case INDEX_op_ld32u_i64: | ||
25 | - t0 = *tb_ptr++; | ||
26 | - t1 = tci_read_r(regs, &tb_ptr); | ||
27 | - t2 = tci_read_s32(&tb_ptr); | ||
28 | - tci_write_reg(regs, t0, *(uint32_t *)(t1 + t2)); | ||
29 | - break; | 43 | - break; |
30 | case INDEX_op_ld32s_i64: | 44 | - |
31 | t0 = *tb_ptr++; | 45 | default: |
32 | t1 = tci_read_r(regs, &tb_ptr); | 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); | ||
33 | -- | 58 | -- |
34 | 2.25.1 | 59 | 2.25.1 |
35 | 60 | ||
36 | 61 | diff view generated by jsdifflib |
1 | From: Claudio Fontana <cfontana@suse.de> | 1 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> |
---|---|---|---|
2 | 2 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | |
3 | Signed-off-by: Claudio Fontana <cfontana@suse.de> | ||
4 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | ||
5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Message-Id: <20210204163931.7358-10-cfontana@suse.de> | ||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
8 | --- | 4 | --- |
9 | include/hw/core/cpu.h | 4 ++-- | 5 | tcg/optimize.c | 32 ++++++++++++++++++-------------- |
10 | accel/tcg/cpu-exec.c | 4 ++-- | 6 | 1 file changed, 18 insertions(+), 14 deletions(-) |
11 | target/alpha/cpu.c | 2 +- | ||
12 | target/arm/cpu.c | 4 ++-- | ||
13 | target/arm/cpu_tcg.c | 9 ++++----- | ||
14 | target/avr/cpu.c | 2 +- | ||
15 | target/avr/helper.c | 4 ++-- | ||
16 | target/cris/cpu.c | 12 ++++++------ | ||
17 | target/cris/helper.c | 4 ++-- | ||
18 | target/hppa/cpu.c | 2 +- | ||
19 | target/i386/tcg/tcg-cpu.c | 2 +- | ||
20 | target/lm32/cpu.c | 2 +- | ||
21 | target/m68k/cpu.c | 2 +- | ||
22 | target/microblaze/cpu.c | 2 +- | ||
23 | target/mips/cpu.c | 4 ++-- | ||
24 | target/moxie/cpu.c | 2 +- | ||
25 | target/nios2/cpu.c | 2 +- | ||
26 | target/openrisc/cpu.c | 2 +- | ||
27 | target/riscv/cpu.c | 2 +- | ||
28 | target/rx/cpu.c | 2 +- | ||
29 | target/s390x/cpu.c | 2 +- | ||
30 | target/sh4/cpu.c | 2 +- | ||
31 | target/sparc/cpu.c | 2 +- | ||
32 | target/tilegx/cpu.c | 2 +- | ||
33 | target/unicore32/cpu.c | 2 +- | ||
34 | target/xtensa/cpu.c | 2 +- | ||
35 | target/ppc/translate_init.c.inc | 2 +- | ||
36 | 27 files changed, 41 insertions(+), 42 deletions(-) | ||
37 | 7 | ||
38 | diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h | 8 | diff --git a/tcg/optimize.c b/tcg/optimize.c |
39 | index XXXXXXX..XXXXXXX 100644 | 9 | index XXXXXXX..XXXXXXX 100644 |
40 | --- a/include/hw/core/cpu.h | 10 | --- a/tcg/optimize.c |
41 | +++ b/include/hw/core/cpu.h | 11 | +++ b/tcg/optimize.c |
42 | @@ -XXX,XX +XXX,XX @@ typedef struct TcgCpuOperations { | 12 | @@ -XXX,XX +XXX,XX @@ static bool fold_call(OptContext *ctx, TCGOp *op) |
43 | void (*cpu_exec_exit)(CPUState *cpu); | ||
44 | /** @cpu_exec_interrupt: Callback for processing interrupts in cpu_exec */ | ||
45 | bool (*cpu_exec_interrupt)(CPUState *cpu, int interrupt_request); | ||
46 | + /** @do_interrupt: Callback for interrupt handling. */ | ||
47 | + void (*do_interrupt)(CPUState *cpu); | ||
48 | /** | ||
49 | * @tlb_fill: Handle a softmmu tlb miss or user-only address fault | ||
50 | * | ||
51 | @@ -XXX,XX +XXX,XX @@ typedef struct TcgCpuOperations { | ||
52 | * @parse_features: Callback to parse command line arguments. | ||
53 | * @reset_dump_flags: #CPUDumpFlags to use for reset logging. | ||
54 | * @has_work: Callback for checking if there is work to do. | ||
55 | - * @do_interrupt: Callback for interrupt handling. | ||
56 | * @do_unaligned_access: Callback for unaligned access handling, if | ||
57 | * the target defines #TARGET_ALIGNED_ONLY. | ||
58 | * @do_transaction_failed: Callback for handling failed memory transactions | ||
59 | @@ -XXX,XX +XXX,XX @@ struct CPUClass { | ||
60 | |||
61 | int reset_dump_flags; | ||
62 | bool (*has_work)(CPUState *cpu); | ||
63 | - void (*do_interrupt)(CPUState *cpu); | ||
64 | void (*do_unaligned_access)(CPUState *cpu, vaddr addr, | ||
65 | MMUAccessType access_type, | ||
66 | int mmu_idx, uintptr_t retaddr); | ||
67 | diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c | ||
68 | index XXXXXXX..XXXXXXX 100644 | ||
69 | --- a/accel/tcg/cpu-exec.c | ||
70 | +++ b/accel/tcg/cpu-exec.c | ||
71 | @@ -XXX,XX +XXX,XX @@ static inline bool cpu_handle_exception(CPUState *cpu, int *ret) | ||
72 | loop */ | ||
73 | #if defined(TARGET_I386) | ||
74 | CPUClass *cc = CPU_GET_CLASS(cpu); | ||
75 | - cc->do_interrupt(cpu); | ||
76 | + cc->tcg_ops.do_interrupt(cpu); | ||
77 | #endif | ||
78 | *ret = cpu->exception_index; | ||
79 | cpu->exception_index = -1; | ||
80 | @@ -XXX,XX +XXX,XX @@ static inline bool cpu_handle_exception(CPUState *cpu, int *ret) | ||
81 | if (replay_exception()) { | ||
82 | CPUClass *cc = CPU_GET_CLASS(cpu); | ||
83 | qemu_mutex_lock_iothread(); | ||
84 | - cc->do_interrupt(cpu); | ||
85 | + cc->tcg_ops.do_interrupt(cpu); | ||
86 | qemu_mutex_unlock_iothread(); | ||
87 | cpu->exception_index = -1; | ||
88 | |||
89 | diff --git a/target/alpha/cpu.c b/target/alpha/cpu.c | ||
90 | index XXXXXXX..XXXXXXX 100644 | ||
91 | --- a/target/alpha/cpu.c | ||
92 | +++ b/target/alpha/cpu.c | ||
93 | @@ -XXX,XX +XXX,XX @@ static void alpha_cpu_class_init(ObjectClass *oc, void *data) | ||
94 | |||
95 | cc->class_by_name = alpha_cpu_class_by_name; | ||
96 | cc->has_work = alpha_cpu_has_work; | ||
97 | - cc->do_interrupt = alpha_cpu_do_interrupt; | ||
98 | + cc->tcg_ops.do_interrupt = alpha_cpu_do_interrupt; | ||
99 | cc->tcg_ops.cpu_exec_interrupt = alpha_cpu_exec_interrupt; | ||
100 | cc->dump_state = alpha_cpu_dump_state; | ||
101 | cc->set_pc = alpha_cpu_set_pc; | ||
102 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | ||
103 | index XXXXXXX..XXXXXXX 100644 | ||
104 | --- a/target/arm/cpu.c | ||
105 | +++ b/target/arm/cpu.c | ||
106 | @@ -XXX,XX +XXX,XX @@ bool arm_cpu_exec_interrupt(CPUState *cs, int interrupt_request) | ||
107 | found: | ||
108 | cs->exception_index = excp_idx; | ||
109 | env->exception.target_el = target_el; | ||
110 | - cc->do_interrupt(cs); | ||
111 | + cc->tcg_ops.do_interrupt(cs); | ||
112 | return true; | 13 | return true; |
113 | } | 14 | } |
114 | 15 | ||
115 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_class_init(ObjectClass *oc, void *data) | 16 | +static bool fold_count_zeros(OptContext *ctx, TCGOp *op) |
116 | cc->gdb_read_register = arm_cpu_gdb_read_register; | 17 | +{ |
117 | cc->gdb_write_register = arm_cpu_gdb_write_register; | 18 | + if (arg_is_const(op->args[1])) { |
118 | #ifndef CONFIG_USER_ONLY | 19 | + uint64_t t = arg_info(op->args[1])->val; |
119 | - cc->do_interrupt = arm_cpu_do_interrupt; | 20 | + |
120 | cc->get_phys_page_attrs_debug = arm_cpu_get_phys_page_attrs_debug; | 21 | + if (t != 0) { |
121 | cc->asidx_from_attrs = arm_asidx_from_attrs; | 22 | + t = do_constant_folding(op->opc, t, 0); |
122 | cc->vmsd = &vmstate_arm_cpu; | 23 | + return tcg_opt_gen_movi(ctx, op, op->args[0], t); |
123 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_class_init(ObjectClass *oc, void *data) | 24 | + } |
124 | #if !defined(CONFIG_USER_ONLY) | 25 | + return tcg_opt_gen_mov(ctx, op, op->args[0], op->args[2]); |
125 | cc->do_transaction_failed = arm_cpu_do_transaction_failed; | 26 | + } |
126 | cc->adjust_watchpoint_address = arm_adjust_watchpoint_address; | 27 | + return false; |
127 | + cc->tcg_ops.do_interrupt = arm_cpu_do_interrupt; | 28 | +} |
128 | #endif /* CONFIG_TCG && !CONFIG_USER_ONLY */ | 29 | + |
129 | #endif | 30 | static bool fold_ctpop(OptContext *ctx, TCGOp *op) |
130 | } | 31 | { |
131 | diff --git a/target/arm/cpu_tcg.c b/target/arm/cpu_tcg.c | 32 | return fold_const1(ctx, op); |
132 | index XXXXXXX..XXXXXXX 100644 | 33 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) |
133 | --- a/target/arm/cpu_tcg.c | 34 | } |
134 | +++ b/target/arm/cpu_tcg.c | 35 | break; |
135 | @@ -XXX,XX +XXX,XX @@ static bool arm_v7m_cpu_exec_interrupt(CPUState *cs, int interrupt_request) | 36 | |
136 | if (interrupt_request & CPU_INTERRUPT_HARD | 37 | - CASE_OP_32_64(clz): |
137 | && (armv7m_nvic_can_take_pending_exception(env->nvic))) { | 38 | - CASE_OP_32_64(ctz): |
138 | cs->exception_index = EXCP_IRQ; | 39 | - if (arg_is_const(op->args[1])) { |
139 | - cc->do_interrupt(cs); | 40 | - TCGArg v = arg_info(op->args[1])->val; |
140 | + cc->tcg_ops.do_interrupt(cs); | 41 | - if (v != 0) { |
141 | ret = true; | 42 | - tmp = do_constant_folding(opc, v, 0); |
142 | } | 43 | - tcg_opt_gen_movi(&ctx, op, op->args[0], tmp); |
143 | return ret; | 44 | - } else { |
144 | @@ -XXX,XX +XXX,XX @@ static void arm_v7m_class_init(ObjectClass *oc, void *data) | 45 | - tcg_opt_gen_mov(&ctx, op, op->args[0], op->args[2]); |
145 | CPUClass *cc = CPU_CLASS(oc); | 46 | - } |
146 | 47 | - continue; | |
147 | acc->info = data; | 48 | - } |
148 | -#ifndef CONFIG_USER_ONLY | 49 | - break; |
149 | - cc->do_interrupt = arm_v7m_cpu_do_interrupt; | ||
150 | -#endif | ||
151 | - | 50 | - |
152 | #ifdef CONFIG_TCG | 51 | default: |
153 | cc->tcg_ops.cpu_exec_interrupt = arm_v7m_cpu_exec_interrupt; | 52 | break; |
154 | +#ifndef CONFIG_USER_ONLY | 53 | |
155 | + cc->tcg_ops.do_interrupt = arm_v7m_cpu_do_interrupt; | 54 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) |
156 | +#endif | 55 | case INDEX_op_brcond2_i32: |
157 | #endif /* CONFIG_TCG */ | 56 | done = fold_brcond2(&ctx, op); |
158 | 57 | break; | |
159 | cc->gdb_core_xml_file = "arm-m-profile.xml"; | 58 | + CASE_OP_32_64(clz): |
160 | diff --git a/target/avr/cpu.c b/target/avr/cpu.c | 59 | + CASE_OP_32_64(ctz): |
161 | index XXXXXXX..XXXXXXX 100644 | 60 | + done = fold_count_zeros(&ctx, op); |
162 | --- a/target/avr/cpu.c | 61 | + break; |
163 | +++ b/target/avr/cpu.c | 62 | CASE_OP_32_64(ctpop): |
164 | @@ -XXX,XX +XXX,XX @@ static void avr_cpu_class_init(ObjectClass *oc, void *data) | 63 | done = fold_ctpop(&ctx, op); |
165 | cc->class_by_name = avr_cpu_class_by_name; | 64 | break; |
166 | |||
167 | cc->has_work = avr_cpu_has_work; | ||
168 | - cc->do_interrupt = avr_cpu_do_interrupt; | ||
169 | + cc->tcg_ops.do_interrupt = avr_cpu_do_interrupt; | ||
170 | cc->tcg_ops.cpu_exec_interrupt = avr_cpu_exec_interrupt; | ||
171 | cc->dump_state = avr_cpu_dump_state; | ||
172 | cc->set_pc = avr_cpu_set_pc; | ||
173 | diff --git a/target/avr/helper.c b/target/avr/helper.c | ||
174 | index XXXXXXX..XXXXXXX 100644 | ||
175 | --- a/target/avr/helper.c | ||
176 | +++ b/target/avr/helper.c | ||
177 | @@ -XXX,XX +XXX,XX @@ bool avr_cpu_exec_interrupt(CPUState *cs, int interrupt_request) | ||
178 | if (interrupt_request & CPU_INTERRUPT_RESET) { | ||
179 | if (cpu_interrupts_enabled(env)) { | ||
180 | cs->exception_index = EXCP_RESET; | ||
181 | - cc->do_interrupt(cs); | ||
182 | + cc->tcg_ops.do_interrupt(cs); | ||
183 | |||
184 | cs->interrupt_request &= ~CPU_INTERRUPT_RESET; | ||
185 | |||
186 | @@ -XXX,XX +XXX,XX @@ bool avr_cpu_exec_interrupt(CPUState *cs, int interrupt_request) | ||
187 | if (cpu_interrupts_enabled(env) && env->intsrc != 0) { | ||
188 | int index = ctz32(env->intsrc); | ||
189 | cs->exception_index = EXCP_INT(index); | ||
190 | - cc->do_interrupt(cs); | ||
191 | + cc->tcg_ops.do_interrupt(cs); | ||
192 | |||
193 | env->intsrc &= env->intsrc - 1; /* clear the interrupt */ | ||
194 | cs->interrupt_request &= ~CPU_INTERRUPT_HARD; | ||
195 | diff --git a/target/cris/cpu.c b/target/cris/cpu.c | ||
196 | index XXXXXXX..XXXXXXX 100644 | ||
197 | --- a/target/cris/cpu.c | ||
198 | +++ b/target/cris/cpu.c | ||
199 | @@ -XXX,XX +XXX,XX @@ static void crisv8_cpu_class_init(ObjectClass *oc, void *data) | ||
200 | CRISCPUClass *ccc = CRIS_CPU_CLASS(oc); | ||
201 | |||
202 | ccc->vr = 8; | ||
203 | - cc->do_interrupt = crisv10_cpu_do_interrupt; | ||
204 | + cc->tcg_ops.do_interrupt = crisv10_cpu_do_interrupt; | ||
205 | cc->gdb_read_register = crisv10_cpu_gdb_read_register; | ||
206 | cc->tcg_ops.initialize = cris_initialize_crisv10_tcg; | ||
207 | } | ||
208 | @@ -XXX,XX +XXX,XX @@ static void crisv9_cpu_class_init(ObjectClass *oc, void *data) | ||
209 | CRISCPUClass *ccc = CRIS_CPU_CLASS(oc); | ||
210 | |||
211 | ccc->vr = 9; | ||
212 | - cc->do_interrupt = crisv10_cpu_do_interrupt; | ||
213 | + cc->tcg_ops.do_interrupt = crisv10_cpu_do_interrupt; | ||
214 | cc->gdb_read_register = crisv10_cpu_gdb_read_register; | ||
215 | cc->tcg_ops.initialize = cris_initialize_crisv10_tcg; | ||
216 | } | ||
217 | @@ -XXX,XX +XXX,XX @@ static void crisv10_cpu_class_init(ObjectClass *oc, void *data) | ||
218 | CRISCPUClass *ccc = CRIS_CPU_CLASS(oc); | ||
219 | |||
220 | ccc->vr = 10; | ||
221 | - cc->do_interrupt = crisv10_cpu_do_interrupt; | ||
222 | + cc->tcg_ops.do_interrupt = crisv10_cpu_do_interrupt; | ||
223 | cc->gdb_read_register = crisv10_cpu_gdb_read_register; | ||
224 | cc->tcg_ops.initialize = cris_initialize_crisv10_tcg; | ||
225 | } | ||
226 | @@ -XXX,XX +XXX,XX @@ static void crisv11_cpu_class_init(ObjectClass *oc, void *data) | ||
227 | CRISCPUClass *ccc = CRIS_CPU_CLASS(oc); | ||
228 | |||
229 | ccc->vr = 11; | ||
230 | - cc->do_interrupt = crisv10_cpu_do_interrupt; | ||
231 | + cc->tcg_ops.do_interrupt = crisv10_cpu_do_interrupt; | ||
232 | cc->gdb_read_register = crisv10_cpu_gdb_read_register; | ||
233 | cc->tcg_ops.initialize = cris_initialize_crisv10_tcg; | ||
234 | } | ||
235 | @@ -XXX,XX +XXX,XX @@ static void crisv17_cpu_class_init(ObjectClass *oc, void *data) | ||
236 | CRISCPUClass *ccc = CRIS_CPU_CLASS(oc); | ||
237 | |||
238 | ccc->vr = 17; | ||
239 | - cc->do_interrupt = crisv10_cpu_do_interrupt; | ||
240 | + cc->tcg_ops.do_interrupt = crisv10_cpu_do_interrupt; | ||
241 | cc->gdb_read_register = crisv10_cpu_gdb_read_register; | ||
242 | cc->tcg_ops.initialize = cris_initialize_crisv10_tcg; | ||
243 | } | ||
244 | @@ -XXX,XX +XXX,XX @@ static void cris_cpu_class_init(ObjectClass *oc, void *data) | ||
245 | |||
246 | cc->class_by_name = cris_cpu_class_by_name; | ||
247 | cc->has_work = cris_cpu_has_work; | ||
248 | - cc->do_interrupt = cris_cpu_do_interrupt; | ||
249 | + cc->tcg_ops.do_interrupt = cris_cpu_do_interrupt; | ||
250 | cc->tcg_ops.cpu_exec_interrupt = cris_cpu_exec_interrupt; | ||
251 | cc->dump_state = cris_cpu_dump_state; | ||
252 | cc->set_pc = cris_cpu_set_pc; | ||
253 | diff --git a/target/cris/helper.c b/target/cris/helper.c | ||
254 | index XXXXXXX..XXXXXXX 100644 | ||
255 | --- a/target/cris/helper.c | ||
256 | +++ b/target/cris/helper.c | ||
257 | @@ -XXX,XX +XXX,XX @@ bool cris_cpu_exec_interrupt(CPUState *cs, int interrupt_request) | ||
258 | && (env->pregs[PR_CCS] & I_FLAG) | ||
259 | && !env->locked_irq) { | ||
260 | cs->exception_index = EXCP_IRQ; | ||
261 | - cc->do_interrupt(cs); | ||
262 | + cc->tcg_ops.do_interrupt(cs); | ||
263 | ret = true; | ||
264 | } | ||
265 | if (interrupt_request & CPU_INTERRUPT_NMI) { | ||
266 | @@ -XXX,XX +XXX,XX @@ bool cris_cpu_exec_interrupt(CPUState *cs, int interrupt_request) | ||
267 | } | ||
268 | if ((env->pregs[PR_CCS] & m_flag_archval)) { | ||
269 | cs->exception_index = EXCP_NMI; | ||
270 | - cc->do_interrupt(cs); | ||
271 | + cc->tcg_ops.do_interrupt(cs); | ||
272 | ret = true; | ||
273 | } | ||
274 | } | ||
275 | diff --git a/target/hppa/cpu.c b/target/hppa/cpu.c | ||
276 | index XXXXXXX..XXXXXXX 100644 | ||
277 | --- a/target/hppa/cpu.c | ||
278 | +++ b/target/hppa/cpu.c | ||
279 | @@ -XXX,XX +XXX,XX @@ static void hppa_cpu_class_init(ObjectClass *oc, void *data) | ||
280 | |||
281 | cc->class_by_name = hppa_cpu_class_by_name; | ||
282 | cc->has_work = hppa_cpu_has_work; | ||
283 | - cc->do_interrupt = hppa_cpu_do_interrupt; | ||
284 | + cc->tcg_ops.do_interrupt = hppa_cpu_do_interrupt; | ||
285 | cc->tcg_ops.cpu_exec_interrupt = hppa_cpu_exec_interrupt; | ||
286 | cc->dump_state = hppa_cpu_dump_state; | ||
287 | cc->set_pc = hppa_cpu_set_pc; | ||
288 | diff --git a/target/i386/tcg/tcg-cpu.c b/target/i386/tcg/tcg-cpu.c | ||
289 | index XXXXXXX..XXXXXXX 100644 | ||
290 | --- a/target/i386/tcg/tcg-cpu.c | ||
291 | +++ b/target/i386/tcg/tcg-cpu.c | ||
292 | @@ -XXX,XX +XXX,XX @@ static void x86_cpu_synchronize_from_tb(CPUState *cs, | ||
293 | |||
294 | void tcg_cpu_common_class_init(CPUClass *cc) | ||
295 | { | ||
296 | - cc->do_interrupt = x86_cpu_do_interrupt; | ||
297 | + cc->tcg_ops.do_interrupt = x86_cpu_do_interrupt; | ||
298 | cc->tcg_ops.cpu_exec_interrupt = x86_cpu_exec_interrupt; | ||
299 | cc->tcg_ops.synchronize_from_tb = x86_cpu_synchronize_from_tb; | ||
300 | cc->tcg_ops.cpu_exec_enter = x86_cpu_exec_enter; | ||
301 | diff --git a/target/lm32/cpu.c b/target/lm32/cpu.c | ||
302 | index XXXXXXX..XXXXXXX 100644 | ||
303 | --- a/target/lm32/cpu.c | ||
304 | +++ b/target/lm32/cpu.c | ||
305 | @@ -XXX,XX +XXX,XX @@ static void lm32_cpu_class_init(ObjectClass *oc, void *data) | ||
306 | |||
307 | cc->class_by_name = lm32_cpu_class_by_name; | ||
308 | cc->has_work = lm32_cpu_has_work; | ||
309 | - cc->do_interrupt = lm32_cpu_do_interrupt; | ||
310 | + cc->tcg_ops.do_interrupt = lm32_cpu_do_interrupt; | ||
311 | cc->tcg_ops.cpu_exec_interrupt = lm32_cpu_exec_interrupt; | ||
312 | cc->dump_state = lm32_cpu_dump_state; | ||
313 | cc->set_pc = lm32_cpu_set_pc; | ||
314 | diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c | ||
315 | index XXXXXXX..XXXXXXX 100644 | ||
316 | --- a/target/m68k/cpu.c | ||
317 | +++ b/target/m68k/cpu.c | ||
318 | @@ -XXX,XX +XXX,XX @@ static void m68k_cpu_class_init(ObjectClass *c, void *data) | ||
319 | |||
320 | cc->class_by_name = m68k_cpu_class_by_name; | ||
321 | cc->has_work = m68k_cpu_has_work; | ||
322 | - cc->do_interrupt = m68k_cpu_do_interrupt; | ||
323 | + cc->tcg_ops.do_interrupt = m68k_cpu_do_interrupt; | ||
324 | cc->tcg_ops.cpu_exec_interrupt = m68k_cpu_exec_interrupt; | ||
325 | cc->dump_state = m68k_cpu_dump_state; | ||
326 | cc->set_pc = m68k_cpu_set_pc; | ||
327 | diff --git a/target/microblaze/cpu.c b/target/microblaze/cpu.c | ||
328 | index XXXXXXX..XXXXXXX 100644 | ||
329 | --- a/target/microblaze/cpu.c | ||
330 | +++ b/target/microblaze/cpu.c | ||
331 | @@ -XXX,XX +XXX,XX @@ static void mb_cpu_class_init(ObjectClass *oc, void *data) | ||
332 | |||
333 | cc->class_by_name = mb_cpu_class_by_name; | ||
334 | cc->has_work = mb_cpu_has_work; | ||
335 | - cc->do_interrupt = mb_cpu_do_interrupt; | ||
336 | + cc->tcg_ops.do_interrupt = mb_cpu_do_interrupt; | ||
337 | cc->do_unaligned_access = mb_cpu_do_unaligned_access; | ||
338 | cc->tcg_ops.cpu_exec_interrupt = mb_cpu_exec_interrupt; | ||
339 | cc->dump_state = mb_cpu_dump_state; | ||
340 | diff --git a/target/mips/cpu.c b/target/mips/cpu.c | ||
341 | index XXXXXXX..XXXXXXX 100644 | ||
342 | --- a/target/mips/cpu.c | ||
343 | +++ b/target/mips/cpu.c | ||
344 | @@ -XXX,XX +XXX,XX @@ static void mips_cpu_class_init(ObjectClass *c, void *data) | ||
345 | |||
346 | cc->class_by_name = mips_cpu_class_by_name; | ||
347 | cc->has_work = mips_cpu_has_work; | ||
348 | - cc->do_interrupt = mips_cpu_do_interrupt; | ||
349 | cc->dump_state = mips_cpu_dump_state; | ||
350 | cc->set_pc = mips_cpu_set_pc; | ||
351 | cc->gdb_read_register = mips_cpu_gdb_read_register; | ||
352 | @@ -XXX,XX +XXX,XX @@ static void mips_cpu_class_init(ObjectClass *c, void *data) | ||
353 | cc->disas_set_info = mips_cpu_disas_set_info; | ||
354 | #ifdef CONFIG_TCG | ||
355 | cc->tcg_ops.initialize = mips_tcg_init; | ||
356 | + cc->tcg_ops.do_interrupt = mips_cpu_do_interrupt; | ||
357 | cc->tcg_ops.cpu_exec_interrupt = mips_cpu_exec_interrupt; | ||
358 | cc->tcg_ops.synchronize_from_tb = mips_cpu_synchronize_from_tb; | ||
359 | cc->tcg_ops.tlb_fill = mips_cpu_tlb_fill; | ||
360 | -#endif | ||
361 | +#endif /* CONFIG_TCG */ | ||
362 | |||
363 | cc->gdb_num_core_regs = 73; | ||
364 | cc->gdb_stop_before_watchpoint = true; | ||
365 | diff --git a/target/moxie/cpu.c b/target/moxie/cpu.c | ||
366 | index XXXXXXX..XXXXXXX 100644 | ||
367 | --- a/target/moxie/cpu.c | ||
368 | +++ b/target/moxie/cpu.c | ||
369 | @@ -XXX,XX +XXX,XX @@ static void moxie_cpu_class_init(ObjectClass *oc, void *data) | ||
370 | cc->class_by_name = moxie_cpu_class_by_name; | ||
371 | |||
372 | cc->has_work = moxie_cpu_has_work; | ||
373 | - cc->do_interrupt = moxie_cpu_do_interrupt; | ||
374 | + cc->tcg_ops.do_interrupt = moxie_cpu_do_interrupt; | ||
375 | cc->dump_state = moxie_cpu_dump_state; | ||
376 | cc->set_pc = moxie_cpu_set_pc; | ||
377 | cc->tcg_ops.tlb_fill = moxie_cpu_tlb_fill; | ||
378 | diff --git a/target/nios2/cpu.c b/target/nios2/cpu.c | ||
379 | index XXXXXXX..XXXXXXX 100644 | ||
380 | --- a/target/nios2/cpu.c | ||
381 | +++ b/target/nios2/cpu.c | ||
382 | @@ -XXX,XX +XXX,XX @@ static void nios2_cpu_class_init(ObjectClass *oc, void *data) | ||
383 | |||
384 | cc->class_by_name = nios2_cpu_class_by_name; | ||
385 | cc->has_work = nios2_cpu_has_work; | ||
386 | - cc->do_interrupt = nios2_cpu_do_interrupt; | ||
387 | + cc->tcg_ops.do_interrupt = nios2_cpu_do_interrupt; | ||
388 | cc->tcg_ops.cpu_exec_interrupt = nios2_cpu_exec_interrupt; | ||
389 | cc->dump_state = nios2_cpu_dump_state; | ||
390 | cc->set_pc = nios2_cpu_set_pc; | ||
391 | diff --git a/target/openrisc/cpu.c b/target/openrisc/cpu.c | ||
392 | index XXXXXXX..XXXXXXX 100644 | ||
393 | --- a/target/openrisc/cpu.c | ||
394 | +++ b/target/openrisc/cpu.c | ||
395 | @@ -XXX,XX +XXX,XX @@ static void openrisc_cpu_class_init(ObjectClass *oc, void *data) | ||
396 | |||
397 | cc->class_by_name = openrisc_cpu_class_by_name; | ||
398 | cc->has_work = openrisc_cpu_has_work; | ||
399 | - cc->do_interrupt = openrisc_cpu_do_interrupt; | ||
400 | + cc->tcg_ops.do_interrupt = openrisc_cpu_do_interrupt; | ||
401 | cc->tcg_ops.cpu_exec_interrupt = openrisc_cpu_exec_interrupt; | ||
402 | cc->dump_state = openrisc_cpu_dump_state; | ||
403 | cc->set_pc = openrisc_cpu_set_pc; | ||
404 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
405 | index XXXXXXX..XXXXXXX 100644 | ||
406 | --- a/target/riscv/cpu.c | ||
407 | +++ b/target/riscv/cpu.c | ||
408 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_class_init(ObjectClass *c, void *data) | ||
409 | |||
410 | cc->class_by_name = riscv_cpu_class_by_name; | ||
411 | cc->has_work = riscv_cpu_has_work; | ||
412 | - cc->do_interrupt = riscv_cpu_do_interrupt; | ||
413 | + cc->tcg_ops.do_interrupt = riscv_cpu_do_interrupt; | ||
414 | cc->tcg_ops.cpu_exec_interrupt = riscv_cpu_exec_interrupt; | ||
415 | cc->dump_state = riscv_cpu_dump_state; | ||
416 | cc->set_pc = riscv_cpu_set_pc; | ||
417 | diff --git a/target/rx/cpu.c b/target/rx/cpu.c | ||
418 | index XXXXXXX..XXXXXXX 100644 | ||
419 | --- a/target/rx/cpu.c | ||
420 | +++ b/target/rx/cpu.c | ||
421 | @@ -XXX,XX +XXX,XX @@ static void rx_cpu_class_init(ObjectClass *klass, void *data) | ||
422 | |||
423 | cc->class_by_name = rx_cpu_class_by_name; | ||
424 | cc->has_work = rx_cpu_has_work; | ||
425 | - cc->do_interrupt = rx_cpu_do_interrupt; | ||
426 | + cc->tcg_ops.do_interrupt = rx_cpu_do_interrupt; | ||
427 | cc->tcg_ops.cpu_exec_interrupt = rx_cpu_exec_interrupt; | ||
428 | cc->dump_state = rx_cpu_dump_state; | ||
429 | cc->set_pc = rx_cpu_set_pc; | ||
430 | diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c | ||
431 | index XXXXXXX..XXXXXXX 100644 | ||
432 | --- a/target/s390x/cpu.c | ||
433 | +++ b/target/s390x/cpu.c | ||
434 | @@ -XXX,XX +XXX,XX @@ static void s390_cpu_class_init(ObjectClass *oc, void *data) | ||
435 | cc->class_by_name = s390_cpu_class_by_name, | ||
436 | cc->has_work = s390_cpu_has_work; | ||
437 | #ifdef CONFIG_TCG | ||
438 | - cc->do_interrupt = s390_cpu_do_interrupt; | ||
439 | + cc->tcg_ops.do_interrupt = s390_cpu_do_interrupt; | ||
440 | #endif | ||
441 | cc->dump_state = s390_cpu_dump_state; | ||
442 | cc->set_pc = s390_cpu_set_pc; | ||
443 | diff --git a/target/sh4/cpu.c b/target/sh4/cpu.c | ||
444 | index XXXXXXX..XXXXXXX 100644 | ||
445 | --- a/target/sh4/cpu.c | ||
446 | +++ b/target/sh4/cpu.c | ||
447 | @@ -XXX,XX +XXX,XX @@ static void superh_cpu_class_init(ObjectClass *oc, void *data) | ||
448 | |||
449 | cc->class_by_name = superh_cpu_class_by_name; | ||
450 | cc->has_work = superh_cpu_has_work; | ||
451 | - cc->do_interrupt = superh_cpu_do_interrupt; | ||
452 | + cc->tcg_ops.do_interrupt = superh_cpu_do_interrupt; | ||
453 | cc->tcg_ops.cpu_exec_interrupt = superh_cpu_exec_interrupt; | ||
454 | cc->dump_state = superh_cpu_dump_state; | ||
455 | cc->set_pc = superh_cpu_set_pc; | ||
456 | diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c | ||
457 | index XXXXXXX..XXXXXXX 100644 | ||
458 | --- a/target/sparc/cpu.c | ||
459 | +++ b/target/sparc/cpu.c | ||
460 | @@ -XXX,XX +XXX,XX @@ static void sparc_cpu_class_init(ObjectClass *oc, void *data) | ||
461 | cc->class_by_name = sparc_cpu_class_by_name; | ||
462 | cc->parse_features = sparc_cpu_parse_features; | ||
463 | cc->has_work = sparc_cpu_has_work; | ||
464 | - cc->do_interrupt = sparc_cpu_do_interrupt; | ||
465 | + cc->tcg_ops.do_interrupt = sparc_cpu_do_interrupt; | ||
466 | cc->tcg_ops.cpu_exec_interrupt = sparc_cpu_exec_interrupt; | ||
467 | cc->dump_state = sparc_cpu_dump_state; | ||
468 | #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY) | ||
469 | diff --git a/target/tilegx/cpu.c b/target/tilegx/cpu.c | ||
470 | index XXXXXXX..XXXXXXX 100644 | ||
471 | --- a/target/tilegx/cpu.c | ||
472 | +++ b/target/tilegx/cpu.c | ||
473 | @@ -XXX,XX +XXX,XX @@ static void tilegx_cpu_class_init(ObjectClass *oc, void *data) | ||
474 | |||
475 | cc->class_by_name = tilegx_cpu_class_by_name; | ||
476 | cc->has_work = tilegx_cpu_has_work; | ||
477 | - cc->do_interrupt = tilegx_cpu_do_interrupt; | ||
478 | + cc->tcg_ops.do_interrupt = tilegx_cpu_do_interrupt; | ||
479 | cc->tcg_ops.cpu_exec_interrupt = tilegx_cpu_exec_interrupt; | ||
480 | cc->dump_state = tilegx_cpu_dump_state; | ||
481 | cc->set_pc = tilegx_cpu_set_pc; | ||
482 | diff --git a/target/unicore32/cpu.c b/target/unicore32/cpu.c | ||
483 | index XXXXXXX..XXXXXXX 100644 | ||
484 | --- a/target/unicore32/cpu.c | ||
485 | +++ b/target/unicore32/cpu.c | ||
486 | @@ -XXX,XX +XXX,XX @@ static void uc32_cpu_class_init(ObjectClass *oc, void *data) | ||
487 | |||
488 | cc->class_by_name = uc32_cpu_class_by_name; | ||
489 | cc->has_work = uc32_cpu_has_work; | ||
490 | - cc->do_interrupt = uc32_cpu_do_interrupt; | ||
491 | + cc->tcg_ops.do_interrupt = uc32_cpu_do_interrupt; | ||
492 | cc->tcg_ops.cpu_exec_interrupt = uc32_cpu_exec_interrupt; | ||
493 | cc->dump_state = uc32_cpu_dump_state; | ||
494 | cc->set_pc = uc32_cpu_set_pc; | ||
495 | diff --git a/target/xtensa/cpu.c b/target/xtensa/cpu.c | ||
496 | index XXXXXXX..XXXXXXX 100644 | ||
497 | --- a/target/xtensa/cpu.c | ||
498 | +++ b/target/xtensa/cpu.c | ||
499 | @@ -XXX,XX +XXX,XX @@ static void xtensa_cpu_class_init(ObjectClass *oc, void *data) | ||
500 | |||
501 | cc->class_by_name = xtensa_cpu_class_by_name; | ||
502 | cc->has_work = xtensa_cpu_has_work; | ||
503 | - cc->do_interrupt = xtensa_cpu_do_interrupt; | ||
504 | + cc->tcg_ops.do_interrupt = xtensa_cpu_do_interrupt; | ||
505 | cc->tcg_ops.cpu_exec_interrupt = xtensa_cpu_exec_interrupt; | ||
506 | cc->dump_state = xtensa_cpu_dump_state; | ||
507 | cc->set_pc = xtensa_cpu_set_pc; | ||
508 | diff --git a/target/ppc/translate_init.c.inc b/target/ppc/translate_init.c.inc | ||
509 | index XXXXXXX..XXXXXXX 100644 | ||
510 | --- a/target/ppc/translate_init.c.inc | ||
511 | +++ b/target/ppc/translate_init.c.inc | ||
512 | @@ -XXX,XX +XXX,XX @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data) | ||
513 | |||
514 | cc->class_by_name = ppc_cpu_class_by_name; | ||
515 | cc->has_work = ppc_cpu_has_work; | ||
516 | - cc->do_interrupt = ppc_cpu_do_interrupt; | ||
517 | cc->dump_state = ppc_cpu_dump_state; | ||
518 | cc->dump_statistics = ppc_cpu_dump_statistics; | ||
519 | cc->set_pc = ppc_cpu_set_pc; | ||
520 | @@ -XXX,XX +XXX,XX @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data) | ||
521 | #ifdef CONFIG_TCG | ||
522 | cc->tcg_ops.initialize = ppc_translate_init; | ||
523 | cc->tcg_ops.cpu_exec_interrupt = ppc_cpu_exec_interrupt; | ||
524 | + cc->tcg_ops.do_interrupt = ppc_cpu_do_interrupt; | ||
525 | cc->tcg_ops.tlb_fill = ppc_cpu_tlb_fill; | ||
526 | #ifndef CONFIG_USER_ONLY | ||
527 | cc->tcg_ops.cpu_exec_enter = ppc_cpu_exec_enter; | ||
528 | -- | 65 | -- |
529 | 2.25.1 | 66 | 2.25.1 |
530 | 67 | ||
531 | 68 | diff view generated by jsdifflib |
1 | Eliminating a TODO for ld16s_i64. | 1 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> |
---|---|---|---|
2 | 2 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | |
3 | Tested-by: Alex Bennée <alex.bennee@linaro.org> | ||
4 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | ||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
6 | --- | 4 | --- |
7 | tcg/tci.c | 5 +---- | 5 | tcg/optimize.c | 27 ++++++++++++++++----------- |
8 | 1 file changed, 1 insertion(+), 4 deletions(-) | 6 | 1 file changed, 16 insertions(+), 11 deletions(-) |
9 | 7 | ||
10 | diff --git a/tcg/tci.c b/tcg/tci.c | 8 | diff --git a/tcg/optimize.c b/tcg/optimize.c |
11 | index XXXXXXX..XXXXXXX 100644 | 9 | index XXXXXXX..XXXXXXX 100644 |
12 | --- a/tcg/tci.c | 10 | --- a/tcg/optimize.c |
13 | +++ b/tcg/tci.c | 11 | +++ b/tcg/optimize.c |
14 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 12 | @@ -XXX,XX +XXX,XX @@ static bool fold_brcond2(OptContext *ctx, TCGOp *op) |
15 | t2 = tci_read_s32(&tb_ptr); | 13 | return false; |
16 | tci_write_reg(regs, t0, *(uint16_t *)(t1 + t2)); | 14 | } |
15 | |||
16 | +static bool fold_bswap(OptContext *ctx, TCGOp *op) | ||
17 | +{ | ||
18 | + if (arg_is_const(op->args[1])) { | ||
19 | + uint64_t t = arg_info(op->args[1])->val; | ||
20 | + | ||
21 | + t = do_constant_folding(op->opc, t, op->args[2]); | ||
22 | + return tcg_opt_gen_movi(ctx, op, op->args[0], t); | ||
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 | } | ||
17 | break; | 32 | break; |
18 | - case INDEX_op_ld16s_i32: | 33 | |
19 | + CASE_32_64(ld16s) | 34 | - CASE_OP_32_64(bswap16): |
20 | t0 = *tb_ptr++; | 35 | - CASE_OP_32_64(bswap32): |
21 | t1 = tci_read_r(regs, &tb_ptr); | 36 | - case INDEX_op_bswap64_i64: |
22 | t2 = tci_read_s32(&tb_ptr); | 37 | - if (arg_is_const(op->args[1])) { |
23 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 38 | - tmp = do_constant_folding(opc, arg_info(op->args[1])->val, |
24 | 39 | - op->args[2]); | |
25 | /* Load/store operations (64 bit). */ | 40 | - tcg_opt_gen_movi(&ctx, op, op->args[0], tmp); |
26 | 41 | - continue; | |
27 | - case INDEX_op_ld16s_i64: | 42 | - } |
28 | - TODO(); | ||
29 | - break; | 43 | - break; |
30 | case INDEX_op_ld32u_i64: | 44 | - |
31 | t0 = *tb_ptr++; | 45 | default: |
32 | t1 = tci_read_r(regs, &tb_ptr); | 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); | ||
33 | -- | 60 | -- |
34 | 2.25.1 | 61 | 2.25.1 |
35 | 62 | ||
36 | 63 | diff view generated by jsdifflib |
1 | Eliminating a TODO for ld16u_i32. | 1 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> |
---|---|---|---|
2 | 2 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | |
3 | Tested-by: Alex Bennée <alex.bennee@linaro.org> | ||
4 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | ||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
6 | --- | 4 | --- |
7 | tcg/tci.c | 13 +++++-------- | 5 | tcg/optimize.c | 53 +++++++++++++++++++++++++++++--------------------- |
8 | 1 file changed, 5 insertions(+), 8 deletions(-) | 6 | 1 file changed, 31 insertions(+), 22 deletions(-) |
9 | 7 | ||
10 | diff --git a/tcg/tci.c b/tcg/tci.c | 8 | diff --git a/tcg/optimize.c b/tcg/optimize.c |
11 | index XXXXXXX..XXXXXXX 100644 | 9 | index XXXXXXX..XXXXXXX 100644 |
12 | --- a/tcg/tci.c | 10 | --- a/tcg/optimize.c |
13 | +++ b/tcg/tci.c | 11 | +++ b/tcg/optimize.c |
14 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 12 | @@ -XXX,XX +XXX,XX @@ static bool fold_divide(OptContext *ctx, TCGOp *op) |
15 | t2 = tci_read_s32(&tb_ptr); | 13 | return fold_const2(ctx, op); |
16 | tci_write_reg(regs, t0, *(int8_t *)(t1 + t2)); | 14 | } |
15 | |||
16 | +static bool fold_dup(OptContext *ctx, TCGOp *op) | ||
17 | +{ | ||
18 | + if (arg_is_const(op->args[1])) { | ||
19 | + uint64_t t = arg_info(op->args[1])->val; | ||
20 | + t = dup_const(TCGOP_VECE(op), t); | ||
21 | + return tcg_opt_gen_movi(ctx, op, op->args[0], t); | ||
22 | + } | ||
23 | + return false; | ||
24 | +} | ||
25 | + | ||
26 | +static bool fold_dup2(OptContext *ctx, TCGOp *op) | ||
27 | +{ | ||
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 | { | ||
43 | return fold_const2(ctx, op); | ||
44 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
45 | done = tcg_opt_gen_mov(&ctx, op, op->args[0], op->args[1]); | ||
17 | break; | 46 | break; |
18 | - case INDEX_op_ld16u_i32: | 47 | |
19 | - TODO(); | 48 | - case INDEX_op_dup_vec: |
20 | + CASE_32_64(ld16u) | 49 | - if (arg_is_const(op->args[1])) { |
21 | + t0 = *tb_ptr++; | 50 | - tmp = arg_info(op->args[1])->val; |
22 | + t1 = tci_read_r(regs, &tb_ptr); | 51 | - tmp = dup_const(TCGOP_VECE(op), tmp); |
23 | + t2 = tci_read_s32(&tb_ptr); | 52 | - tcg_opt_gen_movi(&ctx, op, op->args[0], tmp); |
24 | + tci_write_reg(regs, t0, *(uint16_t *)(t1 + t2)); | 53 | - continue; |
54 | - } | ||
55 | - break; | ||
56 | - | ||
57 | - case INDEX_op_dup2_vec: | ||
58 | - assert(TCG_TARGET_REG_BITS == 32); | ||
59 | - if (arg_is_const(op->args[1]) && arg_is_const(op->args[2])) { | ||
60 | - tcg_opt_gen_movi(&ctx, op, op->args[0], | ||
61 | - deposit64(arg_info(op->args[1])->val, 32, 32, | ||
62 | - arg_info(op->args[2])->val)); | ||
63 | - continue; | ||
64 | - } else if (args_are_copies(op->args[1], op->args[2])) { | ||
65 | - op->opc = INDEX_op_dup_vec; | ||
66 | - TCGOP_VECE(op) = MO_32; | ||
67 | - } | ||
68 | - break; | ||
69 | - | ||
70 | default: | ||
25 | break; | 71 | break; |
26 | case INDEX_op_ld16s_i32: | 72 | |
27 | t0 = *tb_ptr++; | 73 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) |
28 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 74 | CASE_OP_32_64(divu): |
29 | 75 | done = fold_divide(&ctx, op); | |
30 | /* Load/store operations (64 bit). */ | 76 | break; |
31 | 77 | + case INDEX_op_dup_vec: | |
32 | - case INDEX_op_ld16u_i64: | 78 | + done = fold_dup(&ctx, op); |
33 | - t0 = *tb_ptr++; | 79 | + break; |
34 | - t1 = tci_read_r(regs, &tb_ptr); | 80 | + case INDEX_op_dup2_vec: |
35 | - t2 = tci_read_s32(&tb_ptr); | 81 | + done = fold_dup2(&ctx, op); |
36 | - tci_write_reg(regs, t0, *(uint16_t *)(t1 + t2)); | 82 | + break; |
37 | - break; | 83 | CASE_OP_32_64(eqv): |
38 | case INDEX_op_ld16s_i64: | 84 | done = fold_eqv(&ctx, op); |
39 | TODO(); | ||
40 | break; | 85 | break; |
41 | -- | 86 | -- |
42 | 2.25.1 | 87 | 2.25.1 |
43 | 88 | ||
44 | 89 | diff view generated by jsdifflib |
1 | Eliminating a TODO for ld8s_i32. | 1 | This is the final entry in the main switch that was in a |
---|---|---|---|
2 | different form. After this, we have the option to convert | ||
3 | the switch into a function dispatch table. | ||
2 | 4 | ||
3 | Tested-by: Alex Bennée <alex.bennee@linaro.org> | 5 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> |
4 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 6 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
6 | --- | 8 | --- |
7 | tcg/tci.c | 13 +++++-------- | 9 | tcg/optimize.c | 27 ++++++++++++++------------- |
8 | 1 file changed, 5 insertions(+), 8 deletions(-) | 10 | 1 file changed, 14 insertions(+), 13 deletions(-) |
9 | 11 | ||
10 | diff --git a/tcg/tci.c b/tcg/tci.c | 12 | diff --git a/tcg/optimize.c b/tcg/optimize.c |
11 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
12 | --- a/tcg/tci.c | 14 | --- a/tcg/optimize.c |
13 | +++ b/tcg/tci.c | 15 | +++ b/tcg/optimize.c |
14 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 16 | @@ -XXX,XX +XXX,XX @@ static bool fold_mb(OptContext *ctx, TCGOp *op) |
15 | t2 = tci_read_s32(&tb_ptr); | 17 | return true; |
16 | tci_write_reg(regs, t0, *(uint8_t *)(t1 + t2)); | 18 | } |
19 | |||
20 | +static bool fold_mov(OptContext *ctx, TCGOp *op) | ||
21 | +{ | ||
22 | + return tcg_opt_gen_mov(ctx, op, op->args[0], op->args[1]); | ||
23 | +} | ||
24 | + | ||
25 | static bool fold_movcond(OptContext *ctx, TCGOp *op) | ||
26 | { | ||
27 | TCGOpcode opc = op->opc; | ||
28 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
17 | break; | 29 | break; |
18 | - case INDEX_op_ld8s_i32: | 30 | } |
19 | - TODO(); | 31 | |
20 | + CASE_32_64(ld8s) | 32 | - /* Propagate constants through copy operations and do constant |
21 | + t0 = *tb_ptr++; | 33 | - folding. Constants will be substituted to arguments by register |
22 | + t1 = tci_read_r(regs, &tb_ptr); | 34 | - allocator where needed and possible. Also detect copies. */ |
23 | + t2 = tci_read_s32(&tb_ptr); | 35 | + /* |
24 | + tci_write_reg(regs, t0, *(int8_t *)(t1 + t2)); | 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); | ||
25 | break; | 52 | break; |
26 | case INDEX_op_ld16u_i32: | 53 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) |
27 | TODO(); | 54 | case INDEX_op_mb: |
28 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 55 | done = fold_mb(&ctx, op); |
29 | 56 | break; | |
30 | /* Load/store operations (64 bit). */ | 57 | + CASE_OP_32_64_VEC(mov): |
31 | 58 | + done = fold_mov(&ctx, op); | |
32 | - case INDEX_op_ld8s_i64: | 59 | + break; |
33 | - t0 = *tb_ptr++; | 60 | CASE_OP_32_64(movcond): |
34 | - t1 = tci_read_r(regs, &tb_ptr); | 61 | done = fold_movcond(&ctx, op); |
35 | - t2 = tci_read_s32(&tb_ptr); | 62 | break; |
36 | - tci_write_reg(regs, t0, *(int8_t *)(t1 + t2)); | 63 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) |
37 | - break; | 64 | CASE_OP_32_64_VEC(xor): |
38 | case INDEX_op_ld16u_i64: | 65 | done = fold_xor(&ctx, op); |
39 | t0 = *tb_ptr++; | 66 | break; |
40 | t1 = tci_read_r(regs, &tb_ptr); | 67 | + default: |
68 | + break; | ||
69 | } | ||
70 | |||
71 | if (!done) { | ||
41 | -- | 72 | -- |
42 | 2.25.1 | 73 | 2.25.1 |
43 | 74 | ||
44 | 75 | diff view generated by jsdifflib |
1 | From: Eduardo Habkost <ehabkost@redhat.com> | 1 | Pull the "op r, a, a => movi r, 0" optimization into a function, |
---|---|---|---|
2 | and use it in the outer opcode fold functions. | ||
2 | 3 | ||
3 | The TCG-specific CPU methods will be moved to a separate struct, | 4 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> |
4 | to make it easier to move accel-specific code outside generic CPU | 5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
5 | code in the future. Start by moving tcg_initialize(). | ||
6 | |||
7 | The new CPUClass.tcg_opts field may eventually become a pointer, | ||
8 | but keep it an embedded struct for now, to make code conversion | ||
9 | easier. | ||
10 | |||
11 | Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> | ||
12 | [claudio: move TCGCpuOperations inside include/hw/core/cpu.h] | ||
13 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | ||
14 | Message-Id: <20210204163931.7358-2-cfontana@suse.de> | ||
15 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
16 | --- | 7 | --- |
17 | include/hw/core/cpu.h | 16 +++++++++++++++- | 8 | tcg/optimize.c | 41 ++++++++++++++++++++++++----------------- |
18 | cpu.c | 6 +++++- | 9 | 1 file changed, 24 insertions(+), 17 deletions(-) |
19 | target/alpha/cpu.c | 2 +- | ||
20 | target/arm/cpu.c | 2 +- | ||
21 | target/avr/cpu.c | 2 +- | ||
22 | target/cris/cpu.c | 12 ++++++------ | ||
23 | target/hppa/cpu.c | 2 +- | ||
24 | target/i386/tcg/tcg-cpu.c | 2 +- | ||
25 | target/lm32/cpu.c | 2 +- | ||
26 | target/m68k/cpu.c | 2 +- | ||
27 | target/microblaze/cpu.c | 2 +- | ||
28 | target/mips/cpu.c | 2 +- | ||
29 | target/moxie/cpu.c | 2 +- | ||
30 | target/nios2/cpu.c | 2 +- | ||
31 | target/openrisc/cpu.c | 2 +- | ||
32 | target/riscv/cpu.c | 2 +- | ||
33 | target/rx/cpu.c | 2 +- | ||
34 | target/s390x/cpu.c | 2 +- | ||
35 | target/sh4/cpu.c | 2 +- | ||
36 | target/sparc/cpu.c | 2 +- | ||
37 | target/tilegx/cpu.c | 2 +- | ||
38 | target/tricore/cpu.c | 2 +- | ||
39 | target/unicore32/cpu.c | 2 +- | ||
40 | target/xtensa/cpu.c | 2 +- | ||
41 | target/ppc/translate_init.c.inc | 2 +- | ||
42 | 25 files changed, 48 insertions(+), 30 deletions(-) | ||
43 | 10 | ||
44 | diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h | 11 | diff --git a/tcg/optimize.c b/tcg/optimize.c |
45 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
46 | --- a/include/hw/core/cpu.h | 13 | --- a/tcg/optimize.c |
47 | +++ b/include/hw/core/cpu.h | 14 | +++ b/tcg/optimize.c |
48 | @@ -XXX,XX +XXX,XX @@ typedef struct CPUWatchpoint CPUWatchpoint; | 15 | @@ -XXX,XX +XXX,XX @@ static bool fold_const2(OptContext *ctx, TCGOp *op) |
49 | 16 | return false; | |
50 | struct TranslationBlock; | 17 | } |
51 | 18 | ||
52 | +/** | 19 | +/* If the binary operation has both arguments equal, fold to @i. */ |
53 | + * struct TcgCpuOperations: TCG operations specific to a CPU class | 20 | +static bool fold_xx_to_i(OptContext *ctx, TCGOp *op, uint64_t i) |
54 | + */ | 21 | +{ |
55 | +typedef struct TcgCpuOperations { | 22 | + if (args_are_copies(op->args[1], op->args[2])) { |
56 | + /** | 23 | + return tcg_opt_gen_movi(ctx, op, op->args[0], i); |
57 | + * @initialize: Initalize TCG state | 24 | + } |
58 | + * | 25 | + return false; |
59 | + * Called when the first CPU is realized. | 26 | +} |
60 | + */ | ||
61 | + void (*initialize)(void); | ||
62 | + | 27 | + |
63 | +} TcgCpuOperations; | ||
64 | + | ||
65 | /** | ||
66 | * CPUClass: | ||
67 | * @class_by_name: Callback to map -cpu command line model name to an | ||
68 | @@ -XXX,XX +XXX,XX @@ struct CPUClass { | ||
69 | |||
70 | void (*disas_set_info)(CPUState *cpu, disassemble_info *info); | ||
71 | vaddr (*adjust_watchpoint_address)(CPUState *cpu, vaddr addr, int len); | ||
72 | - void (*tcg_initialize)(void); | ||
73 | |||
74 | const char *deprecation_note; | ||
75 | /* Keep non-pointer data at the end to minimize holes. */ | ||
76 | int gdb_num_core_regs; | ||
77 | bool gdb_stop_before_watchpoint; | ||
78 | + | ||
79 | + TcgCpuOperations tcg_ops; | ||
80 | }; | ||
81 | |||
82 | /* | 28 | /* |
83 | diff --git a/cpu.c b/cpu.c | 29 | * These outermost fold_<op> functions are sorted alphabetically. |
84 | index XXXXXXX..XXXXXXX 100644 | 30 | */ |
85 | --- a/cpu.c | 31 | @@ -XXX,XX +XXX,XX @@ static bool fold_and(OptContext *ctx, TCGOp *op) |
86 | +++ b/cpu.c | 32 | |
87 | @@ -XXX,XX +XXX,XX @@ void cpu_exec_initfn(CPUState *cpu) | 33 | static bool fold_andc(OptContext *ctx, TCGOp *op) |
88 | void cpu_exec_realizefn(CPUState *cpu, Error **errp) | ||
89 | { | 34 | { |
90 | CPUClass *cc = CPU_GET_CLASS(cpu); | 35 | - return fold_const2(ctx, op); |
91 | +#ifdef CONFIG_TCG | 36 | + if (fold_const2(ctx, op) || |
92 | static bool tcg_target_initialized; | 37 | + fold_xx_to_i(ctx, op, 0)) { |
93 | +#endif /* CONFIG_TCG */ | 38 | + return true; |
94 | 39 | + } | |
95 | cpu_list_add(cpu); | 40 | + return false; |
96 | |||
97 | +#ifdef CONFIG_TCG | ||
98 | if (tcg_enabled() && !tcg_target_initialized) { | ||
99 | tcg_target_initialized = true; | ||
100 | - cc->tcg_initialize(); | ||
101 | + cc->tcg_ops.initialize(); | ||
102 | } | ||
103 | +#endif /* CONFIG_TCG */ | ||
104 | tlb_init(cpu); | ||
105 | |||
106 | qemu_plugin_vcpu_init_hook(cpu); | ||
107 | diff --git a/target/alpha/cpu.c b/target/alpha/cpu.c | ||
108 | index XXXXXXX..XXXXXXX 100644 | ||
109 | --- a/target/alpha/cpu.c | ||
110 | +++ b/target/alpha/cpu.c | ||
111 | @@ -XXX,XX +XXX,XX @@ static void alpha_cpu_class_init(ObjectClass *oc, void *data) | ||
112 | dc->vmsd = &vmstate_alpha_cpu; | ||
113 | #endif | ||
114 | cc->disas_set_info = alpha_cpu_disas_set_info; | ||
115 | - cc->tcg_initialize = alpha_translate_init; | ||
116 | + cc->tcg_ops.initialize = alpha_translate_init; | ||
117 | |||
118 | cc->gdb_num_core_regs = 67; | ||
119 | } | 41 | } |
120 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | 42 | |
121 | index XXXXXXX..XXXXXXX 100644 | 43 | static bool fold_brcond(OptContext *ctx, TCGOp *op) |
122 | --- a/target/arm/cpu.c | 44 | @@ -XXX,XX +XXX,XX @@ static bool fold_shift(OptContext *ctx, TCGOp *op) |
123 | +++ b/target/arm/cpu.c | 45 | |
124 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_class_init(ObjectClass *oc, void *data) | 46 | static bool fold_sub(OptContext *ctx, TCGOp *op) |
125 | cc->gdb_stop_before_watchpoint = true; | 47 | { |
126 | cc->disas_set_info = arm_disas_set_info; | 48 | - return fold_const2(ctx, op); |
127 | #ifdef CONFIG_TCG | 49 | + if (fold_const2(ctx, op) || |
128 | - cc->tcg_initialize = arm_translate_init; | 50 | + fold_xx_to_i(ctx, op, 0)) { |
129 | + cc->tcg_ops.initialize = arm_translate_init; | 51 | + return true; |
130 | cc->tlb_fill = arm_cpu_tlb_fill; | 52 | + } |
131 | cc->debug_excp_handler = arm_debug_excp_handler; | 53 | + return false; |
132 | cc->debug_check_watchpoint = arm_debug_check_watchpoint; | ||
133 | diff --git a/target/avr/cpu.c b/target/avr/cpu.c | ||
134 | index XXXXXXX..XXXXXXX 100644 | ||
135 | --- a/target/avr/cpu.c | ||
136 | +++ b/target/avr/cpu.c | ||
137 | @@ -XXX,XX +XXX,XX @@ static void avr_cpu_class_init(ObjectClass *oc, void *data) | ||
138 | cc->tlb_fill = avr_cpu_tlb_fill; | ||
139 | cc->vmsd = &vms_avr_cpu; | ||
140 | cc->disas_set_info = avr_cpu_disas_set_info; | ||
141 | - cc->tcg_initialize = avr_cpu_tcg_init; | ||
142 | + cc->tcg_ops.initialize = avr_cpu_tcg_init; | ||
143 | cc->synchronize_from_tb = avr_cpu_synchronize_from_tb; | ||
144 | cc->gdb_read_register = avr_cpu_gdb_read_register; | ||
145 | cc->gdb_write_register = avr_cpu_gdb_write_register; | ||
146 | diff --git a/target/cris/cpu.c b/target/cris/cpu.c | ||
147 | index XXXXXXX..XXXXXXX 100644 | ||
148 | --- a/target/cris/cpu.c | ||
149 | +++ b/target/cris/cpu.c | ||
150 | @@ -XXX,XX +XXX,XX @@ static void crisv8_cpu_class_init(ObjectClass *oc, void *data) | ||
151 | ccc->vr = 8; | ||
152 | cc->do_interrupt = crisv10_cpu_do_interrupt; | ||
153 | cc->gdb_read_register = crisv10_cpu_gdb_read_register; | ||
154 | - cc->tcg_initialize = cris_initialize_crisv10_tcg; | ||
155 | + cc->tcg_ops.initialize = cris_initialize_crisv10_tcg; | ||
156 | } | 54 | } |
157 | 55 | ||
158 | static void crisv9_cpu_class_init(ObjectClass *oc, void *data) | 56 | static bool fold_sub2_i32(OptContext *ctx, TCGOp *op) |
159 | @@ -XXX,XX +XXX,XX @@ static void crisv9_cpu_class_init(ObjectClass *oc, void *data) | 57 | @@ -XXX,XX +XXX,XX @@ static bool fold_sub2_i32(OptContext *ctx, TCGOp *op) |
160 | ccc->vr = 9; | 58 | |
161 | cc->do_interrupt = crisv10_cpu_do_interrupt; | 59 | static bool fold_xor(OptContext *ctx, TCGOp *op) |
162 | cc->gdb_read_register = crisv10_cpu_gdb_read_register; | 60 | { |
163 | - cc->tcg_initialize = cris_initialize_crisv10_tcg; | 61 | - return fold_const2(ctx, op); |
164 | + cc->tcg_ops.initialize = cris_initialize_crisv10_tcg; | 62 | + if (fold_const2(ctx, op) || |
63 | + fold_xx_to_i(ctx, op, 0)) { | ||
64 | + return true; | ||
65 | + } | ||
66 | + return false; | ||
165 | } | 67 | } |
166 | 68 | ||
167 | static void crisv10_cpu_class_init(ObjectClass *oc, void *data) | 69 | /* Propagate constants and copies, fold constant expressions. */ |
168 | @@ -XXX,XX +XXX,XX @@ static void crisv10_cpu_class_init(ObjectClass *oc, void *data) | 70 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) |
169 | ccc->vr = 10; | 71 | break; |
170 | cc->do_interrupt = crisv10_cpu_do_interrupt; | 72 | } |
171 | cc->gdb_read_register = crisv10_cpu_gdb_read_register; | 73 | |
172 | - cc->tcg_initialize = cris_initialize_crisv10_tcg; | 74 | - /* Simplify expression for "op r, a, a => movi r, 0" cases */ |
173 | + cc->tcg_ops.initialize = cris_initialize_crisv10_tcg; | 75 | - switch (opc) { |
174 | } | 76 | - CASE_OP_32_64_VEC(andc): |
175 | 77 | - CASE_OP_32_64_VEC(sub): | |
176 | static void crisv11_cpu_class_init(ObjectClass *oc, void *data) | 78 | - CASE_OP_32_64_VEC(xor): |
177 | @@ -XXX,XX +XXX,XX @@ static void crisv11_cpu_class_init(ObjectClass *oc, void *data) | 79 | - if (args_are_copies(op->args[1], op->args[2])) { |
178 | ccc->vr = 11; | 80 | - tcg_opt_gen_movi(&ctx, op, op->args[0], 0); |
179 | cc->do_interrupt = crisv10_cpu_do_interrupt; | 81 | - continue; |
180 | cc->gdb_read_register = crisv10_cpu_gdb_read_register; | 82 | - } |
181 | - cc->tcg_initialize = cris_initialize_crisv10_tcg; | 83 | - break; |
182 | + cc->tcg_ops.initialize = cris_initialize_crisv10_tcg; | 84 | - default: |
183 | } | 85 | - break; |
184 | 86 | - } | |
185 | static void crisv17_cpu_class_init(ObjectClass *oc, void *data) | 87 | - |
186 | @@ -XXX,XX +XXX,XX @@ static void crisv17_cpu_class_init(ObjectClass *oc, void *data) | 88 | /* |
187 | ccc->vr = 17; | 89 | * Process each opcode. |
188 | cc->do_interrupt = crisv10_cpu_do_interrupt; | 90 | * Sorted alphabetically by opcode as much as possible. |
189 | cc->gdb_read_register = crisv10_cpu_gdb_read_register; | ||
190 | - cc->tcg_initialize = cris_initialize_crisv10_tcg; | ||
191 | + cc->tcg_ops.initialize = cris_initialize_crisv10_tcg; | ||
192 | } | ||
193 | |||
194 | static void crisv32_cpu_class_init(ObjectClass *oc, void *data) | ||
195 | @@ -XXX,XX +XXX,XX @@ static void cris_cpu_class_init(ObjectClass *oc, void *data) | ||
196 | cc->gdb_stop_before_watchpoint = true; | ||
197 | |||
198 | cc->disas_set_info = cris_disas_set_info; | ||
199 | - cc->tcg_initialize = cris_initialize_tcg; | ||
200 | + cc->tcg_ops.initialize = cris_initialize_tcg; | ||
201 | } | ||
202 | |||
203 | #define DEFINE_CRIS_CPU_TYPE(cpu_model, initfn) \ | ||
204 | diff --git a/target/hppa/cpu.c b/target/hppa/cpu.c | ||
205 | index XXXXXXX..XXXXXXX 100644 | ||
206 | --- a/target/hppa/cpu.c | ||
207 | +++ b/target/hppa/cpu.c | ||
208 | @@ -XXX,XX +XXX,XX @@ static void hppa_cpu_class_init(ObjectClass *oc, void *data) | ||
209 | #endif | ||
210 | cc->do_unaligned_access = hppa_cpu_do_unaligned_access; | ||
211 | cc->disas_set_info = hppa_cpu_disas_set_info; | ||
212 | - cc->tcg_initialize = hppa_translate_init; | ||
213 | + cc->tcg_ops.initialize = hppa_translate_init; | ||
214 | |||
215 | cc->gdb_num_core_regs = 128; | ||
216 | } | ||
217 | diff --git a/target/i386/tcg/tcg-cpu.c b/target/i386/tcg/tcg-cpu.c | ||
218 | index XXXXXXX..XXXXXXX 100644 | ||
219 | --- a/target/i386/tcg/tcg-cpu.c | ||
220 | +++ b/target/i386/tcg/tcg-cpu.c | ||
221 | @@ -XXX,XX +XXX,XX @@ void tcg_cpu_common_class_init(CPUClass *cc) | ||
222 | cc->synchronize_from_tb = x86_cpu_synchronize_from_tb; | ||
223 | cc->cpu_exec_enter = x86_cpu_exec_enter; | ||
224 | cc->cpu_exec_exit = x86_cpu_exec_exit; | ||
225 | - cc->tcg_initialize = tcg_x86_init; | ||
226 | + cc->tcg_ops.initialize = tcg_x86_init; | ||
227 | cc->tlb_fill = x86_cpu_tlb_fill; | ||
228 | #ifndef CONFIG_USER_ONLY | ||
229 | cc->debug_excp_handler = breakpoint_handler; | ||
230 | diff --git a/target/lm32/cpu.c b/target/lm32/cpu.c | ||
231 | index XXXXXXX..XXXXXXX 100644 | ||
232 | --- a/target/lm32/cpu.c | ||
233 | +++ b/target/lm32/cpu.c | ||
234 | @@ -XXX,XX +XXX,XX @@ static void lm32_cpu_class_init(ObjectClass *oc, void *data) | ||
235 | cc->gdb_stop_before_watchpoint = true; | ||
236 | cc->debug_excp_handler = lm32_debug_excp_handler; | ||
237 | cc->disas_set_info = lm32_cpu_disas_set_info; | ||
238 | - cc->tcg_initialize = lm32_translate_init; | ||
239 | + cc->tcg_ops.initialize = lm32_translate_init; | ||
240 | } | ||
241 | |||
242 | #define DEFINE_LM32_CPU_TYPE(cpu_model, initfn) \ | ||
243 | diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c | ||
244 | index XXXXXXX..XXXXXXX 100644 | ||
245 | --- a/target/m68k/cpu.c | ||
246 | +++ b/target/m68k/cpu.c | ||
247 | @@ -XXX,XX +XXX,XX @@ static void m68k_cpu_class_init(ObjectClass *c, void *data) | ||
248 | dc->vmsd = &vmstate_m68k_cpu; | ||
249 | #endif | ||
250 | cc->disas_set_info = m68k_cpu_disas_set_info; | ||
251 | - cc->tcg_initialize = m68k_tcg_init; | ||
252 | + cc->tcg_ops.initialize = m68k_tcg_init; | ||
253 | |||
254 | cc->gdb_num_core_regs = 18; | ||
255 | } | ||
256 | diff --git a/target/microblaze/cpu.c b/target/microblaze/cpu.c | ||
257 | index XXXXXXX..XXXXXXX 100644 | ||
258 | --- a/target/microblaze/cpu.c | ||
259 | +++ b/target/microblaze/cpu.c | ||
260 | @@ -XXX,XX +XXX,XX @@ static void mb_cpu_class_init(ObjectClass *oc, void *data) | ||
261 | cc->gdb_num_core_regs = 32 + 27; | ||
262 | |||
263 | cc->disas_set_info = mb_disas_set_info; | ||
264 | - cc->tcg_initialize = mb_tcg_init; | ||
265 | + cc->tcg_ops.initialize = mb_tcg_init; | ||
266 | } | ||
267 | |||
268 | static const TypeInfo mb_cpu_type_info = { | ||
269 | diff --git a/target/mips/cpu.c b/target/mips/cpu.c | ||
270 | index XXXXXXX..XXXXXXX 100644 | ||
271 | --- a/target/mips/cpu.c | ||
272 | +++ b/target/mips/cpu.c | ||
273 | @@ -XXX,XX +XXX,XX @@ static void mips_cpu_class_init(ObjectClass *c, void *data) | ||
274 | #endif | ||
275 | cc->disas_set_info = mips_cpu_disas_set_info; | ||
276 | #ifdef CONFIG_TCG | ||
277 | - cc->tcg_initialize = mips_tcg_init; | ||
278 | + cc->tcg_ops.initialize = mips_tcg_init; | ||
279 | cc->tlb_fill = mips_cpu_tlb_fill; | ||
280 | #endif | ||
281 | |||
282 | diff --git a/target/moxie/cpu.c b/target/moxie/cpu.c | ||
283 | index XXXXXXX..XXXXXXX 100644 | ||
284 | --- a/target/moxie/cpu.c | ||
285 | +++ b/target/moxie/cpu.c | ||
286 | @@ -XXX,XX +XXX,XX @@ static void moxie_cpu_class_init(ObjectClass *oc, void *data) | ||
287 | cc->vmsd = &vmstate_moxie_cpu; | ||
288 | #endif | ||
289 | cc->disas_set_info = moxie_cpu_disas_set_info; | ||
290 | - cc->tcg_initialize = moxie_translate_init; | ||
291 | + cc->tcg_ops.initialize = moxie_translate_init; | ||
292 | } | ||
293 | |||
294 | static void moxielite_initfn(Object *obj) | ||
295 | diff --git a/target/nios2/cpu.c b/target/nios2/cpu.c | ||
296 | index XXXXXXX..XXXXXXX 100644 | ||
297 | --- a/target/nios2/cpu.c | ||
298 | +++ b/target/nios2/cpu.c | ||
299 | @@ -XXX,XX +XXX,XX @@ static void nios2_cpu_class_init(ObjectClass *oc, void *data) | ||
300 | cc->gdb_read_register = nios2_cpu_gdb_read_register; | ||
301 | cc->gdb_write_register = nios2_cpu_gdb_write_register; | ||
302 | cc->gdb_num_core_regs = 49; | ||
303 | - cc->tcg_initialize = nios2_tcg_init; | ||
304 | + cc->tcg_ops.initialize = nios2_tcg_init; | ||
305 | } | ||
306 | |||
307 | static const TypeInfo nios2_cpu_type_info = { | ||
308 | diff --git a/target/openrisc/cpu.c b/target/openrisc/cpu.c | ||
309 | index XXXXXXX..XXXXXXX 100644 | ||
310 | --- a/target/openrisc/cpu.c | ||
311 | +++ b/target/openrisc/cpu.c | ||
312 | @@ -XXX,XX +XXX,XX @@ static void openrisc_cpu_class_init(ObjectClass *oc, void *data) | ||
313 | dc->vmsd = &vmstate_openrisc_cpu; | ||
314 | #endif | ||
315 | cc->gdb_num_core_regs = 32 + 3; | ||
316 | - cc->tcg_initialize = openrisc_translate_init; | ||
317 | + cc->tcg_ops.initialize = openrisc_translate_init; | ||
318 | cc->disas_set_info = openrisc_disas_set_info; | ||
319 | } | ||
320 | |||
321 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
322 | index XXXXXXX..XXXXXXX 100644 | ||
323 | --- a/target/riscv/cpu.c | ||
324 | +++ b/target/riscv/cpu.c | ||
325 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_class_init(ObjectClass *c, void *data) | ||
326 | cc->gdb_arch_name = riscv_gdb_arch_name; | ||
327 | cc->gdb_get_dynamic_xml = riscv_gdb_get_dynamic_xml; | ||
328 | #ifdef CONFIG_TCG | ||
329 | - cc->tcg_initialize = riscv_translate_init; | ||
330 | + cc->tcg_ops.initialize = riscv_translate_init; | ||
331 | cc->tlb_fill = riscv_cpu_tlb_fill; | ||
332 | #endif | ||
333 | device_class_set_props(dc, riscv_cpu_properties); | ||
334 | diff --git a/target/rx/cpu.c b/target/rx/cpu.c | ||
335 | index XXXXXXX..XXXXXXX 100644 | ||
336 | --- a/target/rx/cpu.c | ||
337 | +++ b/target/rx/cpu.c | ||
338 | @@ -XXX,XX +XXX,XX @@ static void rx_cpu_class_init(ObjectClass *klass, void *data) | ||
339 | cc->gdb_write_register = rx_cpu_gdb_write_register; | ||
340 | cc->get_phys_page_debug = rx_cpu_get_phys_page_debug; | ||
341 | cc->disas_set_info = rx_cpu_disas_set_info; | ||
342 | - cc->tcg_initialize = rx_translate_init; | ||
343 | + cc->tcg_ops.initialize = rx_translate_init; | ||
344 | cc->tlb_fill = rx_cpu_tlb_fill; | ||
345 | |||
346 | cc->gdb_num_core_regs = 26; | ||
347 | diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c | ||
348 | index XXXXXXX..XXXXXXX 100644 | ||
349 | --- a/target/s390x/cpu.c | ||
350 | +++ b/target/s390x/cpu.c | ||
351 | @@ -XXX,XX +XXX,XX @@ static void s390_cpu_class_init(ObjectClass *oc, void *data) | ||
352 | #endif | ||
353 | cc->disas_set_info = s390_cpu_disas_set_info; | ||
354 | #ifdef CONFIG_TCG | ||
355 | - cc->tcg_initialize = s390x_translate_init; | ||
356 | + cc->tcg_ops.initialize = s390x_translate_init; | ||
357 | cc->tlb_fill = s390_cpu_tlb_fill; | ||
358 | #endif | ||
359 | |||
360 | diff --git a/target/sh4/cpu.c b/target/sh4/cpu.c | ||
361 | index XXXXXXX..XXXXXXX 100644 | ||
362 | --- a/target/sh4/cpu.c | ||
363 | +++ b/target/sh4/cpu.c | ||
364 | @@ -XXX,XX +XXX,XX @@ static void superh_cpu_class_init(ObjectClass *oc, void *data) | ||
365 | cc->get_phys_page_debug = superh_cpu_get_phys_page_debug; | ||
366 | #endif | ||
367 | cc->disas_set_info = superh_cpu_disas_set_info; | ||
368 | - cc->tcg_initialize = sh4_translate_init; | ||
369 | + cc->tcg_ops.initialize = sh4_translate_init; | ||
370 | |||
371 | cc->gdb_num_core_regs = 59; | ||
372 | |||
373 | diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c | ||
374 | index XXXXXXX..XXXXXXX 100644 | ||
375 | --- a/target/sparc/cpu.c | ||
376 | +++ b/target/sparc/cpu.c | ||
377 | @@ -XXX,XX +XXX,XX @@ static void sparc_cpu_class_init(ObjectClass *oc, void *data) | ||
378 | cc->vmsd = &vmstate_sparc_cpu; | ||
379 | #endif | ||
380 | cc->disas_set_info = cpu_sparc_disas_set_info; | ||
381 | - cc->tcg_initialize = sparc_tcg_init; | ||
382 | + cc->tcg_ops.initialize = sparc_tcg_init; | ||
383 | |||
384 | #if defined(TARGET_SPARC64) && !defined(TARGET_ABI32) | ||
385 | cc->gdb_num_core_regs = 86; | ||
386 | diff --git a/target/tilegx/cpu.c b/target/tilegx/cpu.c | ||
387 | index XXXXXXX..XXXXXXX 100644 | ||
388 | --- a/target/tilegx/cpu.c | ||
389 | +++ b/target/tilegx/cpu.c | ||
390 | @@ -XXX,XX +XXX,XX @@ static void tilegx_cpu_class_init(ObjectClass *oc, void *data) | ||
391 | cc->set_pc = tilegx_cpu_set_pc; | ||
392 | cc->tlb_fill = tilegx_cpu_tlb_fill; | ||
393 | cc->gdb_num_core_regs = 0; | ||
394 | - cc->tcg_initialize = tilegx_tcg_init; | ||
395 | + cc->tcg_ops.initialize = tilegx_tcg_init; | ||
396 | } | ||
397 | |||
398 | static const TypeInfo tilegx_cpu_type_info = { | ||
399 | diff --git a/target/tricore/cpu.c b/target/tricore/cpu.c | ||
400 | index XXXXXXX..XXXXXXX 100644 | ||
401 | --- a/target/tricore/cpu.c | ||
402 | +++ b/target/tricore/cpu.c | ||
403 | @@ -XXX,XX +XXX,XX @@ static void tricore_cpu_class_init(ObjectClass *c, void *data) | ||
404 | cc->set_pc = tricore_cpu_set_pc; | ||
405 | cc->synchronize_from_tb = tricore_cpu_synchronize_from_tb; | ||
406 | cc->get_phys_page_debug = tricore_cpu_get_phys_page_debug; | ||
407 | - cc->tcg_initialize = tricore_tcg_init; | ||
408 | + cc->tcg_ops.initialize = tricore_tcg_init; | ||
409 | cc->tlb_fill = tricore_cpu_tlb_fill; | ||
410 | } | ||
411 | |||
412 | diff --git a/target/unicore32/cpu.c b/target/unicore32/cpu.c | ||
413 | index XXXXXXX..XXXXXXX 100644 | ||
414 | --- a/target/unicore32/cpu.c | ||
415 | +++ b/target/unicore32/cpu.c | ||
416 | @@ -XXX,XX +XXX,XX @@ static void uc32_cpu_class_init(ObjectClass *oc, void *data) | ||
417 | cc->set_pc = uc32_cpu_set_pc; | ||
418 | cc->tlb_fill = uc32_cpu_tlb_fill; | ||
419 | cc->get_phys_page_debug = uc32_cpu_get_phys_page_debug; | ||
420 | - cc->tcg_initialize = uc32_translate_init; | ||
421 | + cc->tcg_ops.initialize = uc32_translate_init; | ||
422 | dc->vmsd = &vmstate_uc32_cpu; | ||
423 | } | ||
424 | |||
425 | diff --git a/target/xtensa/cpu.c b/target/xtensa/cpu.c | ||
426 | index XXXXXXX..XXXXXXX 100644 | ||
427 | --- a/target/xtensa/cpu.c | ||
428 | +++ b/target/xtensa/cpu.c | ||
429 | @@ -XXX,XX +XXX,XX @@ static void xtensa_cpu_class_init(ObjectClass *oc, void *data) | ||
430 | #endif | ||
431 | cc->debug_excp_handler = xtensa_breakpoint_handler; | ||
432 | cc->disas_set_info = xtensa_cpu_disas_set_info; | ||
433 | - cc->tcg_initialize = xtensa_translate_init; | ||
434 | + cc->tcg_ops.initialize = xtensa_translate_init; | ||
435 | dc->vmsd = &vmstate_xtensa_cpu; | ||
436 | } | ||
437 | |||
438 | diff --git a/target/ppc/translate_init.c.inc b/target/ppc/translate_init.c.inc | ||
439 | index XXXXXXX..XXXXXXX 100644 | ||
440 | --- a/target/ppc/translate_init.c.inc | ||
441 | +++ b/target/ppc/translate_init.c.inc | ||
442 | @@ -XXX,XX +XXX,XX @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data) | ||
443 | cc->virtio_is_big_endian = ppc_cpu_is_big_endian; | ||
444 | #endif | ||
445 | #ifdef CONFIG_TCG | ||
446 | - cc->tcg_initialize = ppc_translate_init; | ||
447 | + cc->tcg_ops.initialize = ppc_translate_init; | ||
448 | cc->tlb_fill = ppc_cpu_tlb_fill; | ||
449 | #endif | ||
450 | #ifndef CONFIG_USER_ONLY | ||
451 | -- | 91 | -- |
452 | 2.25.1 | 92 | 2.25.1 |
453 | 93 | ||
454 | 94 | diff view generated by jsdifflib |
1 | From: Eduardo Habkost <ehabkost@redhat.com> | 1 | Pull the "op r, a, a => mov r, a" optimization into a function, |
---|---|---|---|
2 | and use it in the outer opcode fold functions. | ||
2 | 3 | ||
3 | Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> | 4 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> |
4 | [claudio: wrapped target code in CONFIG_TCG, reworded comments] | 5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
5 | Signed-off-by: Claudio Fontana <cfontana@suse.de> | ||
6 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | ||
7 | Message-Id: <20210204163931.7358-5-cfontana@suse.de> | ||
8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
9 | --- | 7 | --- |
10 | include/hw/core/cpu.h | 22 +++++++++++++--------- | 8 | tcg/optimize.c | 39 ++++++++++++++++++++++++--------------- |
11 | accel/tcg/cpu-exec.c | 4 ++-- | 9 | 1 file changed, 24 insertions(+), 15 deletions(-) |
12 | target/arm/cpu.c | 4 +++- | ||
13 | target/avr/cpu.c | 2 +- | ||
14 | target/hppa/cpu.c | 2 +- | ||
15 | target/i386/tcg/tcg-cpu.c | 2 +- | ||
16 | target/microblaze/cpu.c | 2 +- | ||
17 | target/mips/cpu.c | 4 +++- | ||
18 | target/riscv/cpu.c | 2 +- | ||
19 | target/rx/cpu.c | 2 +- | ||
20 | target/sh4/cpu.c | 2 +- | ||
21 | target/sparc/cpu.c | 2 +- | ||
22 | target/tricore/cpu.c | 2 +- | ||
23 | 13 files changed, 30 insertions(+), 22 deletions(-) | ||
24 | 10 | ||
25 | diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h | 11 | diff --git a/tcg/optimize.c b/tcg/optimize.c |
26 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
27 | --- a/include/hw/core/cpu.h | 13 | --- a/tcg/optimize.c |
28 | +++ b/include/hw/core/cpu.h | 14 | +++ b/tcg/optimize.c |
29 | @@ -XXX,XX +XXX,XX @@ typedef struct TcgCpuOperations { | 15 | @@ -XXX,XX +XXX,XX @@ static bool fold_xx_to_i(OptContext *ctx, TCGOp *op, uint64_t i) |
30 | * Called when the first CPU is realized. | 16 | return false; |
31 | */ | ||
32 | void (*initialize)(void); | ||
33 | + /** | ||
34 | + * @synchronize_from_tb: Synchronize state from a TCG #TranslationBlock | ||
35 | + * | ||
36 | + * This is called when we abandon execution of a TB before starting it, | ||
37 | + * and must set all parts of the CPU state which the previous TB in the | ||
38 | + * chain may not have updated. | ||
39 | + * By default, when this is NULL, a call is made to @set_pc(tb->pc). | ||
40 | + * | ||
41 | + * If more state needs to be restored, the target must implement a | ||
42 | + * function to restore all the state, and register it here. | ||
43 | + */ | ||
44 | + void (*synchronize_from_tb)(CPUState *cpu, | ||
45 | + const struct TranslationBlock *tb); | ||
46 | |||
47 | } TcgCpuOperations; | ||
48 | |||
49 | @@ -XXX,XX +XXX,XX @@ typedef struct TcgCpuOperations { | ||
50 | * If the target behaviour here is anything other than "set | ||
51 | * the PC register to the value passed in" then the target must | ||
52 | * also implement the synchronize_from_tb hook. | ||
53 | - * @synchronize_from_tb: Callback for synchronizing state from a TCG | ||
54 | - * #TranslationBlock. This is called when we abandon execution | ||
55 | - * of a TB before starting it, and must set all parts of the CPU | ||
56 | - * state which the previous TB in the chain may not have updated. | ||
57 | - * This always includes at least the program counter; some targets | ||
58 | - * will need to do more. If this hook is not implemented then the | ||
59 | - * default is to call @set_pc(tb->pc). | ||
60 | * @tlb_fill: Callback for handling a softmmu tlb miss or user-only | ||
61 | * address fault. For system mode, if the access is valid, call | ||
62 | * tlb_set_page and return true; if the access is invalid, and | ||
63 | @@ -XXX,XX +XXX,XX @@ struct CPUClass { | ||
64 | void (*get_memory_mapping)(CPUState *cpu, MemoryMappingList *list, | ||
65 | Error **errp); | ||
66 | void (*set_pc)(CPUState *cpu, vaddr value); | ||
67 | - void (*synchronize_from_tb)(CPUState *cpu, | ||
68 | - const struct TranslationBlock *tb); | ||
69 | bool (*tlb_fill)(CPUState *cpu, vaddr address, int size, | ||
70 | MMUAccessType access_type, int mmu_idx, | ||
71 | bool probe, uintptr_t retaddr); | ||
72 | diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c | ||
73 | index XXXXXXX..XXXXXXX 100644 | ||
74 | --- a/accel/tcg/cpu-exec.c | ||
75 | +++ b/accel/tcg/cpu-exec.c | ||
76 | @@ -XXX,XX +XXX,XX @@ cpu_tb_exec(CPUState *cpu, TranslationBlock *itb, int *tb_exit) | ||
77 | TARGET_FMT_lx "] %s\n", | ||
78 | last_tb->tc.ptr, last_tb->pc, | ||
79 | lookup_symbol(last_tb->pc)); | ||
80 | - if (cc->synchronize_from_tb) { | ||
81 | - cc->synchronize_from_tb(cpu, last_tb); | ||
82 | + if (cc->tcg_ops.synchronize_from_tb) { | ||
83 | + cc->tcg_ops.synchronize_from_tb(cpu, last_tb); | ||
84 | } else { | ||
85 | assert(cc->set_pc); | ||
86 | cc->set_pc(cpu, last_tb->pc); | ||
87 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | ||
88 | index XXXXXXX..XXXXXXX 100644 | ||
89 | --- a/target/arm/cpu.c | ||
90 | +++ b/target/arm/cpu.c | ||
91 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_set_pc(CPUState *cs, vaddr value) | ||
92 | } | ||
93 | } | 17 | } |
94 | 18 | ||
95 | +#ifdef CONFIG_TCG | 19 | +/* If the binary operation has both arguments equal, fold to identity. */ |
96 | static void arm_cpu_synchronize_from_tb(CPUState *cs, | 20 | +static bool fold_xx_to_x(OptContext *ctx, TCGOp *op) |
97 | const TranslationBlock *tb) | 21 | +{ |
22 | + if (args_are_copies(op->args[1], op->args[2])) { | ||
23 | + return tcg_opt_gen_mov(ctx, op, op->args[0], op->args[1]); | ||
24 | + } | ||
25 | + return false; | ||
26 | +} | ||
27 | + | ||
28 | /* | ||
29 | * These outermost fold_<op> functions are sorted alphabetically. | ||
30 | + * | ||
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) | ||
98 | { | 41 | { |
99 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_synchronize_from_tb(CPUState *cs, | 42 | - return fold_const2(ctx, op); |
100 | env->regs[15] = tb->pc; | 43 | + if (fold_const2(ctx, op) || |
101 | } | 44 | + fold_xx_to_x(ctx, op)) { |
45 | + return true; | ||
46 | + } | ||
47 | + return false; | ||
102 | } | 48 | } |
103 | +#endif /* CONFIG_TCG */ | 49 | |
104 | 50 | static bool fold_andc(OptContext *ctx, TCGOp *op) | |
105 | static bool arm_cpu_has_work(CPUState *cs) | 51 | @@ -XXX,XX +XXX,XX @@ static bool fold_not(OptContext *ctx, TCGOp *op) |
52 | |||
53 | static bool fold_or(OptContext *ctx, TCGOp *op) | ||
106 | { | 54 | { |
107 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_class_init(ObjectClass *oc, void *data) | 55 | - return fold_const2(ctx, op); |
108 | cc->cpu_exec_interrupt = arm_cpu_exec_interrupt; | 56 | + if (fold_const2(ctx, op) || |
109 | cc->dump_state = arm_cpu_dump_state; | 57 | + fold_xx_to_x(ctx, op)) { |
110 | cc->set_pc = arm_cpu_set_pc; | 58 | + return true; |
111 | - cc->synchronize_from_tb = arm_cpu_synchronize_from_tb; | 59 | + } |
112 | cc->gdb_read_register = arm_cpu_gdb_read_register; | 60 | + return false; |
113 | cc->gdb_write_register = arm_cpu_gdb_write_register; | ||
114 | #ifndef CONFIG_USER_ONLY | ||
115 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_class_init(ObjectClass *oc, void *data) | ||
116 | cc->disas_set_info = arm_disas_set_info; | ||
117 | #ifdef CONFIG_TCG | ||
118 | cc->tcg_ops.initialize = arm_translate_init; | ||
119 | + cc->tcg_ops.synchronize_from_tb = arm_cpu_synchronize_from_tb; | ||
120 | cc->tlb_fill = arm_cpu_tlb_fill; | ||
121 | cc->debug_excp_handler = arm_debug_excp_handler; | ||
122 | cc->debug_check_watchpoint = arm_debug_check_watchpoint; | ||
123 | diff --git a/target/avr/cpu.c b/target/avr/cpu.c | ||
124 | index XXXXXXX..XXXXXXX 100644 | ||
125 | --- a/target/avr/cpu.c | ||
126 | +++ b/target/avr/cpu.c | ||
127 | @@ -XXX,XX +XXX,XX @@ static void avr_cpu_class_init(ObjectClass *oc, void *data) | ||
128 | cc->vmsd = &vms_avr_cpu; | ||
129 | cc->disas_set_info = avr_cpu_disas_set_info; | ||
130 | cc->tcg_ops.initialize = avr_cpu_tcg_init; | ||
131 | - cc->synchronize_from_tb = avr_cpu_synchronize_from_tb; | ||
132 | + cc->tcg_ops.synchronize_from_tb = avr_cpu_synchronize_from_tb; | ||
133 | cc->gdb_read_register = avr_cpu_gdb_read_register; | ||
134 | cc->gdb_write_register = avr_cpu_gdb_write_register; | ||
135 | cc->gdb_num_core_regs = 35; | ||
136 | diff --git a/target/hppa/cpu.c b/target/hppa/cpu.c | ||
137 | index XXXXXXX..XXXXXXX 100644 | ||
138 | --- a/target/hppa/cpu.c | ||
139 | +++ b/target/hppa/cpu.c | ||
140 | @@ -XXX,XX +XXX,XX @@ static void hppa_cpu_class_init(ObjectClass *oc, void *data) | ||
141 | cc->cpu_exec_interrupt = hppa_cpu_exec_interrupt; | ||
142 | cc->dump_state = hppa_cpu_dump_state; | ||
143 | cc->set_pc = hppa_cpu_set_pc; | ||
144 | - cc->synchronize_from_tb = hppa_cpu_synchronize_from_tb; | ||
145 | + cc->tcg_ops.synchronize_from_tb = hppa_cpu_synchronize_from_tb; | ||
146 | cc->gdb_read_register = hppa_cpu_gdb_read_register; | ||
147 | cc->gdb_write_register = hppa_cpu_gdb_write_register; | ||
148 | cc->tlb_fill = hppa_cpu_tlb_fill; | ||
149 | diff --git a/target/i386/tcg/tcg-cpu.c b/target/i386/tcg/tcg-cpu.c | ||
150 | index XXXXXXX..XXXXXXX 100644 | ||
151 | --- a/target/i386/tcg/tcg-cpu.c | ||
152 | +++ b/target/i386/tcg/tcg-cpu.c | ||
153 | @@ -XXX,XX +XXX,XX @@ void tcg_cpu_common_class_init(CPUClass *cc) | ||
154 | { | ||
155 | cc->do_interrupt = x86_cpu_do_interrupt; | ||
156 | cc->cpu_exec_interrupt = x86_cpu_exec_interrupt; | ||
157 | - cc->synchronize_from_tb = x86_cpu_synchronize_from_tb; | ||
158 | + cc->tcg_ops.synchronize_from_tb = x86_cpu_synchronize_from_tb; | ||
159 | cc->cpu_exec_enter = x86_cpu_exec_enter; | ||
160 | cc->cpu_exec_exit = x86_cpu_exec_exit; | ||
161 | cc->tcg_ops.initialize = tcg_x86_init; | ||
162 | diff --git a/target/microblaze/cpu.c b/target/microblaze/cpu.c | ||
163 | index XXXXXXX..XXXXXXX 100644 | ||
164 | --- a/target/microblaze/cpu.c | ||
165 | +++ b/target/microblaze/cpu.c | ||
166 | @@ -XXX,XX +XXX,XX @@ static void mb_cpu_class_init(ObjectClass *oc, void *data) | ||
167 | cc->cpu_exec_interrupt = mb_cpu_exec_interrupt; | ||
168 | cc->dump_state = mb_cpu_dump_state; | ||
169 | cc->set_pc = mb_cpu_set_pc; | ||
170 | - cc->synchronize_from_tb = mb_cpu_synchronize_from_tb; | ||
171 | + cc->tcg_ops.synchronize_from_tb = mb_cpu_synchronize_from_tb; | ||
172 | cc->gdb_read_register = mb_cpu_gdb_read_register; | ||
173 | cc->gdb_write_register = mb_cpu_gdb_write_register; | ||
174 | cc->tlb_fill = mb_cpu_tlb_fill; | ||
175 | diff --git a/target/mips/cpu.c b/target/mips/cpu.c | ||
176 | index XXXXXXX..XXXXXXX 100644 | ||
177 | --- a/target/mips/cpu.c | ||
178 | +++ b/target/mips/cpu.c | ||
179 | @@ -XXX,XX +XXX,XX @@ static void mips_cpu_set_pc(CPUState *cs, vaddr value) | ||
180 | } | ||
181 | } | 61 | } |
182 | 62 | ||
183 | +#ifdef CONFIG_TCG | 63 | static bool fold_orc(OptContext *ctx, TCGOp *op) |
184 | static void mips_cpu_synchronize_from_tb(CPUState *cs, | 64 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) |
185 | const TranslationBlock *tb) | 65 | break; |
186 | { | 66 | } |
187 | @@ -XXX,XX +XXX,XX @@ static void mips_cpu_synchronize_from_tb(CPUState *cs, | 67 | |
188 | env->hflags &= ~MIPS_HFLAG_BMASK; | 68 | - /* Simplify expression for "op r, a, a => mov r, a" cases */ |
189 | env->hflags |= tb->flags & MIPS_HFLAG_BMASK; | 69 | - switch (opc) { |
190 | } | 70 | - CASE_OP_32_64_VEC(or): |
191 | +#endif /* CONFIG_TCG */ | 71 | - CASE_OP_32_64_VEC(and): |
192 | 72 | - if (args_are_copies(op->args[1], op->args[2])) { | |
193 | static bool mips_cpu_has_work(CPUState *cs) | 73 | - tcg_opt_gen_mov(&ctx, op, op->args[0], op->args[1]); |
194 | { | 74 | - continue; |
195 | @@ -XXX,XX +XXX,XX @@ static void mips_cpu_class_init(ObjectClass *c, void *data) | 75 | - } |
196 | cc->cpu_exec_interrupt = mips_cpu_exec_interrupt; | 76 | - break; |
197 | cc->dump_state = mips_cpu_dump_state; | 77 | - default: |
198 | cc->set_pc = mips_cpu_set_pc; | 78 | - break; |
199 | - cc->synchronize_from_tb = mips_cpu_synchronize_from_tb; | 79 | - } |
200 | cc->gdb_read_register = mips_cpu_gdb_read_register; | 80 | - |
201 | cc->gdb_write_register = mips_cpu_gdb_write_register; | 81 | /* |
202 | #ifndef CONFIG_USER_ONLY | 82 | * Process each opcode. |
203 | @@ -XXX,XX +XXX,XX @@ static void mips_cpu_class_init(ObjectClass *c, void *data) | 83 | * Sorted alphabetically by opcode as much as possible. |
204 | cc->disas_set_info = mips_cpu_disas_set_info; | ||
205 | #ifdef CONFIG_TCG | ||
206 | cc->tcg_ops.initialize = mips_tcg_init; | ||
207 | + cc->tcg_ops.synchronize_from_tb = mips_cpu_synchronize_from_tb; | ||
208 | cc->tlb_fill = mips_cpu_tlb_fill; | ||
209 | #endif | ||
210 | |||
211 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
212 | index XXXXXXX..XXXXXXX 100644 | ||
213 | --- a/target/riscv/cpu.c | ||
214 | +++ b/target/riscv/cpu.c | ||
215 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_class_init(ObjectClass *c, void *data) | ||
216 | cc->cpu_exec_interrupt = riscv_cpu_exec_interrupt; | ||
217 | cc->dump_state = riscv_cpu_dump_state; | ||
218 | cc->set_pc = riscv_cpu_set_pc; | ||
219 | - cc->synchronize_from_tb = riscv_cpu_synchronize_from_tb; | ||
220 | + cc->tcg_ops.synchronize_from_tb = riscv_cpu_synchronize_from_tb; | ||
221 | cc->gdb_read_register = riscv_cpu_gdb_read_register; | ||
222 | cc->gdb_write_register = riscv_cpu_gdb_write_register; | ||
223 | cc->gdb_num_core_regs = 33; | ||
224 | diff --git a/target/rx/cpu.c b/target/rx/cpu.c | ||
225 | index XXXXXXX..XXXXXXX 100644 | ||
226 | --- a/target/rx/cpu.c | ||
227 | +++ b/target/rx/cpu.c | ||
228 | @@ -XXX,XX +XXX,XX @@ static void rx_cpu_class_init(ObjectClass *klass, void *data) | ||
229 | cc->cpu_exec_interrupt = rx_cpu_exec_interrupt; | ||
230 | cc->dump_state = rx_cpu_dump_state; | ||
231 | cc->set_pc = rx_cpu_set_pc; | ||
232 | - cc->synchronize_from_tb = rx_cpu_synchronize_from_tb; | ||
233 | + cc->tcg_ops.synchronize_from_tb = rx_cpu_synchronize_from_tb; | ||
234 | cc->gdb_read_register = rx_cpu_gdb_read_register; | ||
235 | cc->gdb_write_register = rx_cpu_gdb_write_register; | ||
236 | cc->get_phys_page_debug = rx_cpu_get_phys_page_debug; | ||
237 | diff --git a/target/sh4/cpu.c b/target/sh4/cpu.c | ||
238 | index XXXXXXX..XXXXXXX 100644 | ||
239 | --- a/target/sh4/cpu.c | ||
240 | +++ b/target/sh4/cpu.c | ||
241 | @@ -XXX,XX +XXX,XX @@ static void superh_cpu_class_init(ObjectClass *oc, void *data) | ||
242 | cc->cpu_exec_interrupt = superh_cpu_exec_interrupt; | ||
243 | cc->dump_state = superh_cpu_dump_state; | ||
244 | cc->set_pc = superh_cpu_set_pc; | ||
245 | - cc->synchronize_from_tb = superh_cpu_synchronize_from_tb; | ||
246 | + cc->tcg_ops.synchronize_from_tb = superh_cpu_synchronize_from_tb; | ||
247 | cc->gdb_read_register = superh_cpu_gdb_read_register; | ||
248 | cc->gdb_write_register = superh_cpu_gdb_write_register; | ||
249 | cc->tlb_fill = superh_cpu_tlb_fill; | ||
250 | diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c | ||
251 | index XXXXXXX..XXXXXXX 100644 | ||
252 | --- a/target/sparc/cpu.c | ||
253 | +++ b/target/sparc/cpu.c | ||
254 | @@ -XXX,XX +XXX,XX @@ static void sparc_cpu_class_init(ObjectClass *oc, void *data) | ||
255 | cc->memory_rw_debug = sparc_cpu_memory_rw_debug; | ||
256 | #endif | ||
257 | cc->set_pc = sparc_cpu_set_pc; | ||
258 | - cc->synchronize_from_tb = sparc_cpu_synchronize_from_tb; | ||
259 | + cc->tcg_ops.synchronize_from_tb = sparc_cpu_synchronize_from_tb; | ||
260 | cc->gdb_read_register = sparc_cpu_gdb_read_register; | ||
261 | cc->gdb_write_register = sparc_cpu_gdb_write_register; | ||
262 | cc->tlb_fill = sparc_cpu_tlb_fill; | ||
263 | diff --git a/target/tricore/cpu.c b/target/tricore/cpu.c | ||
264 | index XXXXXXX..XXXXXXX 100644 | ||
265 | --- a/target/tricore/cpu.c | ||
266 | +++ b/target/tricore/cpu.c | ||
267 | @@ -XXX,XX +XXX,XX @@ static void tricore_cpu_class_init(ObjectClass *c, void *data) | ||
268 | |||
269 | cc->dump_state = tricore_cpu_dump_state; | ||
270 | cc->set_pc = tricore_cpu_set_pc; | ||
271 | - cc->synchronize_from_tb = tricore_cpu_synchronize_from_tb; | ||
272 | + cc->tcg_ops.synchronize_from_tb = tricore_cpu_synchronize_from_tb; | ||
273 | cc->get_phys_page_debug = tricore_cpu_get_phys_page_debug; | ||
274 | cc->tcg_ops.initialize = tricore_tcg_init; | ||
275 | cc->tlb_fill = tricore_cpu_tlb_fill; | ||
276 | -- | 84 | -- |
277 | 2.25.1 | 85 | 2.25.1 |
278 | 86 | ||
279 | 87 | diff view generated by jsdifflib |
1 | From: Claudio Fontana <cfontana@suse.de> | 1 | Pull the "op r, a, 0 => movi r, 0" optimization into a function, |
---|---|---|---|
2 | and use it in the outer opcode fold functions. | ||
2 | 3 | ||
3 | commit 568496c0c0f1 ("cpu: Add callback to check architectural") and | 4 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> |
4 | commit 3826121d9298 ("target-arm: Implement checking of fired") | 5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
5 | introduced an ARM-specific hack for cpu_check_watchpoint. | ||
6 | |||
7 | Make debug_check_watchpoint optional, and move it to tcg_ops. | ||
8 | |||
9 | Signed-off-by: Claudio Fontana <cfontana@suse.de> | ||
10 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | ||
11 | Message-Id: <20210204163931.7358-15-cfontana@suse.de> | ||
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/core/cpu.h | 9 ++++++--- | 8 | tcg/optimize.c | 38 ++++++++++++++++++++------------------ |
15 | accel/tcg/user-exec.c | 3 ++- | 9 | 1 file changed, 20 insertions(+), 18 deletions(-) |
16 | hw/core/cpu.c | 9 --------- | ||
17 | softmmu/physmem.c | 4 ++-- | ||
18 | target/arm/cpu.c | 4 ++-- | ||
19 | 5 files changed, 12 insertions(+), 17 deletions(-) | ||
20 | 10 | ||
21 | diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h | 11 | diff --git a/tcg/optimize.c b/tcg/optimize.c |
22 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
23 | --- a/include/hw/core/cpu.h | 13 | --- a/tcg/optimize.c |
24 | +++ b/include/hw/core/cpu.h | 14 | +++ b/tcg/optimize.c |
25 | @@ -XXX,XX +XXX,XX @@ typedef struct TcgCpuOperations { | 15 | @@ -XXX,XX +XXX,XX @@ static bool fold_const2(OptContext *ctx, TCGOp *op) |
26 | */ | 16 | return false; |
27 | vaddr (*adjust_watchpoint_address)(CPUState *cpu, vaddr addr, int len); | 17 | } |
28 | 18 | ||
29 | + /** | 19 | +/* If the binary operation has second argument @i, fold to @i. */ |
30 | + * @debug_check_watchpoint: return true if the architectural | 20 | +static bool fold_xi_to_i(OptContext *ctx, TCGOp *op, uint64_t i) |
31 | + * watchpoint whose address has matched should really fire, used by ARM | 21 | +{ |
32 | + */ | 22 | + if (arg_is_const(op->args[2]) && arg_info(op->args[2])->val == i) { |
33 | + bool (*debug_check_watchpoint)(CPUState *cpu, CPUWatchpoint *wp); | 23 | + return tcg_opt_gen_movi(ctx, op, op->args[0], i); |
24 | + } | ||
25 | + return false; | ||
26 | +} | ||
34 | + | 27 | + |
35 | } TcgCpuOperations; | 28 | /* If the binary operation has both arguments equal, fold to @i. */ |
36 | 29 | static bool fold_xx_to_i(OptContext *ctx, TCGOp *op, uint64_t i) | |
37 | /** | 30 | { |
38 | @@ -XXX,XX +XXX,XX @@ typedef struct TcgCpuOperations { | 31 | @@ -XXX,XX +XXX,XX @@ static bool fold_add2_i32(OptContext *ctx, TCGOp *op) |
39 | * a memory access with the specified memory transaction attributes. | 32 | static bool fold_and(OptContext *ctx, TCGOp *op) |
40 | * @gdb_read_register: Callback for letting GDB read a register. | 33 | { |
41 | * @gdb_write_register: Callback for letting GDB write a register. | 34 | if (fold_const2(ctx, op) || |
42 | - * @debug_check_watchpoint: Callback: return true if the architectural | 35 | + fold_xi_to_i(ctx, op, 0) || |
43 | - * watchpoint whose address has matched should really fire. | 36 | fold_xx_to_x(ctx, op)) { |
44 | * @write_elf64_note: Callback for writing a CPU-specific ELF note to a | 37 | return true; |
45 | * 64-bit VM coredump. | 38 | } |
46 | * @write_elf32_qemunote: Callback for writing a CPU- and QEMU-specific ELF | 39 | @@ -XXX,XX +XXX,XX @@ static bool fold_movcond(OptContext *ctx, TCGOp *op) |
47 | @@ -XXX,XX +XXX,XX @@ struct CPUClass { | 40 | |
48 | int (*asidx_from_attrs)(CPUState *cpu, MemTxAttrs attrs); | 41 | static bool fold_mul(OptContext *ctx, TCGOp *op) |
49 | int (*gdb_read_register)(CPUState *cpu, GByteArray *buf, int reg); | 42 | { |
50 | int (*gdb_write_register)(CPUState *cpu, uint8_t *buf, int reg); | 43 | - return fold_const2(ctx, op); |
51 | - bool (*debug_check_watchpoint)(CPUState *cpu, CPUWatchpoint *wp); | 44 | + if (fold_const2(ctx, op) || |
52 | 45 | + fold_xi_to_i(ctx, op, 0)) { | |
53 | int (*write_elf64_note)(WriteCoreDumpFunction f, CPUState *cpu, | 46 | + return true; |
54 | int cpuid, void *opaque); | 47 | + } |
55 | diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c | 48 | + return false; |
56 | index XXXXXXX..XXXXXXX 100644 | ||
57 | --- a/accel/tcg/user-exec.c | ||
58 | +++ b/accel/tcg/user-exec.c | ||
59 | @@ -XXX,XX +XXX,XX @@ static inline int handle_cpu_signal(uintptr_t pc, siginfo_t *info, | ||
60 | clear_helper_retaddr(); | ||
61 | |||
62 | cc = CPU_GET_CLASS(cpu); | ||
63 | - cc->tcg_ops.tlb_fill(cpu, address, 0, access_type, MMU_USER_IDX, false, pc); | ||
64 | + cc->tcg_ops.tlb_fill(cpu, address, 0, access_type, | ||
65 | + MMU_USER_IDX, false, pc); | ||
66 | g_assert_not_reached(); | ||
67 | } | 49 | } |
68 | 50 | ||
69 | diff --git a/hw/core/cpu.c b/hw/core/cpu.c | 51 | static bool fold_mul_highpart(OptContext *ctx, TCGOp *op) |
70 | index XXXXXXX..XXXXXXX 100644 | 52 | { |
71 | --- a/hw/core/cpu.c | 53 | - return fold_const2(ctx, op); |
72 | +++ b/hw/core/cpu.c | 54 | + if (fold_const2(ctx, op) || |
73 | @@ -XXX,XX +XXX,XX @@ static int cpu_common_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg) | 55 | + fold_xi_to_i(ctx, op, 0)) { |
74 | return 0; | 56 | + return true; |
57 | + } | ||
58 | + return false; | ||
75 | } | 59 | } |
76 | 60 | ||
77 | -static bool cpu_common_debug_check_watchpoint(CPUState *cpu, CPUWatchpoint *wp) | 61 | static bool fold_mulu2_i32(OptContext *ctx, TCGOp *op) |
78 | -{ | 62 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) |
79 | - /* If no extra check is required, QEMU watchpoint match can be considered | 63 | continue; |
80 | - * as an architectural match. | 64 | } |
81 | - */ | 65 | |
82 | - return true; | 66 | - /* Simplify expression for "op r, a, 0 => movi r, 0" cases */ |
83 | -} | 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 | - } | ||
84 | - | 81 | - |
85 | static bool cpu_common_virtio_is_big_endian(CPUState *cpu) | 82 | /* |
86 | { | 83 | * Process each opcode. |
87 | return target_words_bigendian(); | 84 | * Sorted alphabetically by opcode as much as possible. |
88 | @@ -XXX,XX +XXX,XX @@ static void cpu_class_init(ObjectClass *klass, void *data) | ||
89 | k->gdb_read_register = cpu_common_gdb_read_register; | ||
90 | k->gdb_write_register = cpu_common_gdb_write_register; | ||
91 | k->virtio_is_big_endian = cpu_common_virtio_is_big_endian; | ||
92 | - k->debug_check_watchpoint = cpu_common_debug_check_watchpoint; | ||
93 | set_bit(DEVICE_CATEGORY_CPU, dc->categories); | ||
94 | dc->realize = cpu_common_realizefn; | ||
95 | dc->unrealize = cpu_common_unrealizefn; | ||
96 | diff --git a/softmmu/physmem.c b/softmmu/physmem.c | ||
97 | index XXXXXXX..XXXXXXX 100644 | ||
98 | --- a/softmmu/physmem.c | ||
99 | +++ b/softmmu/physmem.c | ||
100 | @@ -XXX,XX +XXX,XX @@ void cpu_check_watchpoint(CPUState *cpu, vaddr addr, vaddr len, | ||
101 | wp->hitaddr = MAX(addr, wp->vaddr); | ||
102 | wp->hitattrs = attrs; | ||
103 | if (!cpu->watchpoint_hit) { | ||
104 | - if (wp->flags & BP_CPU && | ||
105 | - !cc->debug_check_watchpoint(cpu, wp)) { | ||
106 | + if (wp->flags & BP_CPU && cc->tcg_ops.debug_check_watchpoint && | ||
107 | + !cc->tcg_ops.debug_check_watchpoint(cpu, wp)) { | ||
108 | wp->flags &= ~BP_WATCHPOINT_HIT; | ||
109 | continue; | ||
110 | } | ||
111 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | ||
112 | index XXXXXXX..XXXXXXX 100644 | ||
113 | --- a/target/arm/cpu.c | ||
114 | +++ b/target/arm/cpu.c | ||
115 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_class_init(ObjectClass *oc, void *data) | ||
116 | cc->tcg_ops.synchronize_from_tb = arm_cpu_synchronize_from_tb; | ||
117 | cc->tcg_ops.tlb_fill = arm_cpu_tlb_fill; | ||
118 | cc->tcg_ops.debug_excp_handler = arm_debug_excp_handler; | ||
119 | - cc->debug_check_watchpoint = arm_debug_check_watchpoint; | ||
120 | #if !defined(CONFIG_USER_ONLY) | ||
121 | + cc->tcg_ops.do_interrupt = arm_cpu_do_interrupt; | ||
122 | cc->tcg_ops.do_transaction_failed = arm_cpu_do_transaction_failed; | ||
123 | cc->tcg_ops.do_unaligned_access = arm_cpu_do_unaligned_access; | ||
124 | cc->tcg_ops.adjust_watchpoint_address = arm_adjust_watchpoint_address; | ||
125 | - cc->tcg_ops.do_interrupt = arm_cpu_do_interrupt; | ||
126 | + cc->tcg_ops.debug_check_watchpoint = arm_debug_check_watchpoint; | ||
127 | #endif /* CONFIG_TCG && !CONFIG_USER_ONLY */ | ||
128 | #endif /* CONFIG_TCG */ | ||
129 | } | ||
130 | -- | 85 | -- |
131 | 2.25.1 | 86 | 2.25.1 |
132 | 87 | ||
133 | 88 | diff view generated by jsdifflib |
1 | From: Stefan Weil <sw@weilnetz.de> | 1 | Compute the type of the operation early. |
---|---|---|---|
2 | 2 | ||
3 | That TCG opcode is used by debian-buster (arm64) running ffmpeg: | 3 | There are at least 4 places that used a def->flags ladder |
4 | 4 | to determine the type of the operation being optimized. | |
5 | qemu-aarch64 /usr/bin/ffmpeg -i theora.mkv theora.webm | 5 | |
6 | 6 | There were two places that assumed !TCG_OPF_64BIT means | |
7 | Tested-by: Alex Bennée <alex.bennee@linaro.org> | 7 | TCG_TYPE_I32, and so could potentially compute incorrect |
8 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 8 | results for vector operations. |
9 | Reported-by: Alex Bennée <alex.bennee@linaro.org> | 9 | |
10 | Signed-off-by: Stefan Weil <sw@weilnetz.de> | 10 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> |
11 | Message-Id: <20210128020425.2055454-1-sw@weilnetz.de> | ||
12 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 11 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
13 | --- | 12 | --- |
14 | tcg/tci.c | 5 ++++- | 13 | tcg/optimize.c | 149 +++++++++++++++++++++++++++++-------------------- |
15 | 1 file changed, 4 insertions(+), 1 deletion(-) | 14 | 1 file changed, 89 insertions(+), 60 deletions(-) |
16 | 15 | ||
17 | diff --git a/tcg/tci.c b/tcg/tci.c | 16 | diff --git a/tcg/optimize.c b/tcg/optimize.c |
18 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/tcg/tci.c | 18 | --- a/tcg/optimize.c |
20 | +++ b/tcg/tci.c | 19 | +++ b/tcg/optimize.c |
21 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 20 | @@ -XXX,XX +XXX,XX @@ typedef struct OptContext { |
22 | tci_write_reg8(regs, t0, *(uint8_t *)(t1 + t2)); | 21 | |
23 | break; | 22 | /* In flight values from optimization. */ |
24 | case INDEX_op_ld8s_i64: | 23 | uint64_t z_mask; |
25 | - TODO(); | 24 | + TCGType type; |
26 | + t0 = *tb_ptr++; | 25 | } OptContext; |
27 | + t1 = tci_read_r(regs, &tb_ptr); | 26 | |
28 | + t2 = tci_read_s32(&tb_ptr); | 27 | static inline TempOptInfo *ts_info(TCGTemp *ts) |
29 | + tci_write_reg(regs, t0, *(int8_t *)(t1 + t2)); | 28 | @@ -XXX,XX +XXX,XX @@ static bool tcg_opt_gen_mov(OptContext *ctx, TCGOp *op, TCGArg dst, TCGArg src) |
30 | break; | 29 | { |
31 | case INDEX_op_ld16u_i64: | 30 | TCGTemp *dst_ts = arg_temp(dst); |
32 | t0 = *tb_ptr++; | 31 | TCGTemp *src_ts = arg_temp(src); |
32 | - const TCGOpDef *def; | ||
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 | + | ||
47 | + switch (ctx->type) { | ||
48 | + case TCG_TYPE_I32: | ||
49 | new_op = INDEX_op_mov_i32; | ||
50 | + break; | ||
51 | + case TCG_TYPE_I64: | ||
52 | + new_op = INDEX_op_mov_i64; | ||
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 | } | ||
93 | } | ||
94 | |||
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; | ||
33 | -- | 345 | -- |
34 | 2.25.1 | 346 | 2.25.1 |
35 | 347 | ||
36 | 348 | diff view generated by jsdifflib |
1 | From: Stefan Weil <sw@weilnetz.de> | 1 | Split out the conditional conversion from a more complex logical |
---|---|---|---|
2 | 2 | operation to a simple NOT. Create a couple more helpers to make | |
3 | That TCG opcode is used by debian-buster (arm64) running ffmpeg: | 3 | this easy for the outer-most logical operations. |
4 | 4 | ||
5 | qemu-aarch64 /usr/bin/ffmpeg -i theora.mkv theora.webm | 5 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> |
6 | |||
7 | Tested-by: Alex Bennée <alex.bennee@linaro.org> | ||
8 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | ||
9 | Reported-by: Alex Bennée <alex.bennee@linaro.org> | ||
10 | Signed-off-by: Stefan Weil <sw@weilnetz.de> | ||
11 | Message-Id: <20210128024814.2056958-1-sw@weilnetz.de> | ||
12 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
13 | --- | 7 | --- |
14 | tcg/tci.c | 5 ++++- | 8 | tcg/optimize.c | 158 +++++++++++++++++++++++++++---------------------- |
15 | 1 file changed, 4 insertions(+), 1 deletion(-) | 9 | 1 file changed, 86 insertions(+), 72 deletions(-) |
16 | 10 | ||
17 | diff --git a/tcg/tci.c b/tcg/tci.c | 11 | diff --git a/tcg/optimize.c b/tcg/optimize.c |
18 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/tcg/tci.c | 13 | --- a/tcg/optimize.c |
20 | +++ b/tcg/tci.c | 14 | +++ b/tcg/optimize.c |
21 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 15 | @@ -XXX,XX +XXX,XX @@ static bool fold_const2(OptContext *ctx, TCGOp *op) |
22 | TODO(); | 16 | return false; |
17 | } | ||
18 | |||
19 | +/* | ||
20 | + * Convert @op to NOT, if NOT is supported by the host. | ||
21 | + * Return true f the conversion is successful, which will still | ||
22 | + * indicate that the processing is complete. | ||
23 | + */ | ||
24 | +static bool fold_not(OptContext *ctx, TCGOp *op); | ||
25 | +static bool fold_to_not(OptContext *ctx, TCGOp *op, int idx) | ||
26 | +{ | ||
27 | + TCGOpcode not_op; | ||
28 | + bool have_not; | ||
29 | + | ||
30 | + switch (ctx->type) { | ||
31 | + 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: | ||
40 | + case TCG_TYPE_V128: | ||
41 | + case TCG_TYPE_V256: | ||
42 | + not_op = INDEX_op_not_vec; | ||
43 | + have_not = TCG_TARGET_HAS_not_vec; | ||
44 | + break; | ||
45 | + default: | ||
46 | + g_assert_not_reached(); | ||
47 | + } | ||
48 | + if (have_not) { | ||
49 | + op->opc = not_op; | ||
50 | + op->args[1] = op->args[idx]; | ||
51 | + return fold_not(ctx, op); | ||
52 | + } | ||
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 | } | ||
71 | |||
72 | +/* If the binary operation has second argument @i, fold to NOT. */ | ||
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 | } | ||
23 | break; | 171 | break; |
24 | case INDEX_op_ld16s_i32: | 172 | - CASE_OP_32_64_VEC(xor): |
25 | - TODO(); | 173 | - CASE_OP_32_64(nand): |
26 | + t0 = *tb_ptr++; | 174 | - if (!arg_is_const(op->args[1]) |
27 | + t1 = tci_read_r(regs, &tb_ptr); | 175 | - && arg_is_const(op->args[2]) |
28 | + t2 = tci_read_s32(&tb_ptr); | 176 | - && arg_info(op->args[2])->val == -1) { |
29 | + tci_write_reg(regs, t0, *(int16_t *)(t1 + t2)); | 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: | ||
30 | break; | 238 | break; |
31 | case INDEX_op_ld_i32: | 239 | } |
32 | t0 = *tb_ptr++; | ||
33 | -- | 240 | -- |
34 | 2.25.1 | 241 | 2.25.1 |
35 | 242 | ||
36 | 243 | diff view generated by jsdifflib |
1 | From: Eduardo Habkost <ehabkost@redhat.com> | 1 | Even though there is only one user, place this more complex |
---|---|---|---|
2 | conversion into its own helper. | ||
2 | 3 | ||
3 | [claudio: wrapped target code in CONFIG_TCG] | 4 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> |
4 | |||
5 | Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> | ||
6 | Signed-off-by: Claudio Fontana <cfontana@suse.de> | ||
7 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
8 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | ||
9 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
10 | Message-Id: <20210204163931.7358-7-cfontana@suse.de> | ||
11 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
12 | --- | 6 | --- |
13 | include/hw/core/cpu.h | 21 ++++++++++++--------- | 7 | tcg/optimize.c | 89 ++++++++++++++++++++++++++------------------------ |
14 | accel/tcg/cputlb.c | 7 ++++--- | 8 | 1 file changed, 47 insertions(+), 42 deletions(-) |
15 | accel/tcg/user-exec.c | 6 +++--- | ||
16 | target/alpha/cpu.c | 2 +- | ||
17 | target/arm/cpu.c | 2 +- | ||
18 | target/avr/cpu.c | 2 +- | ||
19 | target/cris/cpu.c | 2 +- | ||
20 | target/hppa/cpu.c | 2 +- | ||
21 | target/i386/tcg/tcg-cpu.c | 2 +- | ||
22 | target/lm32/cpu.c | 2 +- | ||
23 | target/m68k/cpu.c | 2 +- | ||
24 | target/microblaze/cpu.c | 2 +- | ||
25 | target/mips/cpu.c | 2 +- | ||
26 | target/moxie/cpu.c | 2 +- | ||
27 | target/nios2/cpu.c | 2 +- | ||
28 | target/openrisc/cpu.c | 2 +- | ||
29 | target/riscv/cpu.c | 2 +- | ||
30 | target/rx/cpu.c | 2 +- | ||
31 | target/s390x/cpu.c | 2 +- | ||
32 | target/sh4/cpu.c | 2 +- | ||
33 | target/sparc/cpu.c | 2 +- | ||
34 | target/tilegx/cpu.c | 2 +- | ||
35 | target/tricore/cpu.c | 2 +- | ||
36 | target/unicore32/cpu.c | 2 +- | ||
37 | target/xtensa/cpu.c | 2 +- | ||
38 | target/ppc/translate_init.c.inc | 2 +- | ||
39 | 26 files changed, 42 insertions(+), 38 deletions(-) | ||
40 | 9 | ||
41 | diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h | 10 | diff --git a/tcg/optimize.c b/tcg/optimize.c |
42 | index XXXXXXX..XXXXXXX 100644 | 11 | index XXXXXXX..XXXXXXX 100644 |
43 | --- a/include/hw/core/cpu.h | 12 | --- a/tcg/optimize.c |
44 | +++ b/include/hw/core/cpu.h | 13 | +++ b/tcg/optimize.c |
45 | @@ -XXX,XX +XXX,XX @@ typedef struct TcgCpuOperations { | 14 | @@ -XXX,XX +XXX,XX @@ static bool fold_nand(OptContext *ctx, TCGOp *op) |
46 | void (*cpu_exec_exit)(CPUState *cpu); | 15 | |
47 | /** @cpu_exec_interrupt: Callback for processing interrupts in cpu_exec */ | 16 | static bool fold_neg(OptContext *ctx, TCGOp *op) |
48 | bool (*cpu_exec_interrupt)(CPUState *cpu, int interrupt_request); | 17 | { |
49 | + /** | 18 | - return fold_const1(ctx, op); |
50 | + * @tlb_fill: Handle a softmmu tlb miss or user-only address fault | 19 | + if (fold_const1(ctx, op)) { |
51 | + * | 20 | + return true; |
52 | + * For system mode, if the access is valid, call tlb_set_page | 21 | + } |
53 | + * and return true; if the access is invalid, and probe is | 22 | + /* |
54 | + * true, return false; otherwise raise an exception and do | 23 | + * Because of fold_sub_to_neg, we want to always return true, |
55 | + * not return. For user-only mode, always raise an exception | 24 | + * via finish_folding. |
56 | + * and do not return. | ||
57 | + */ | 25 | + */ |
58 | + bool (*tlb_fill)(CPUState *cpu, vaddr address, int size, | 26 | + finish_folding(ctx, op); |
59 | + MMUAccessType access_type, int mmu_idx, | 27 | + return true; |
60 | + bool probe, uintptr_t retaddr); | ||
61 | |||
62 | } TcgCpuOperations; | ||
63 | |||
64 | @@ -XXX,XX +XXX,XX @@ typedef struct TcgCpuOperations { | ||
65 | * If the target behaviour here is anything other than "set | ||
66 | * the PC register to the value passed in" then the target must | ||
67 | * also implement the synchronize_from_tb hook. | ||
68 | - * @tlb_fill: Callback for handling a softmmu tlb miss or user-only | ||
69 | - * address fault. For system mode, if the access is valid, call | ||
70 | - * tlb_set_page and return true; if the access is invalid, and | ||
71 | - * probe is true, return false; otherwise raise an exception and | ||
72 | - * do not return. For user-only mode, always raise an exception | ||
73 | - * and do not return. | ||
74 | * @get_phys_page_debug: Callback for obtaining a physical address. | ||
75 | * @get_phys_page_attrs_debug: Callback for obtaining a physical address and the | ||
76 | * associated memory transaction attributes to use for the access. | ||
77 | @@ -XXX,XX +XXX,XX @@ struct CPUClass { | ||
78 | void (*get_memory_mapping)(CPUState *cpu, MemoryMappingList *list, | ||
79 | Error **errp); | ||
80 | void (*set_pc)(CPUState *cpu, vaddr value); | ||
81 | - bool (*tlb_fill)(CPUState *cpu, vaddr address, int size, | ||
82 | - MMUAccessType access_type, int mmu_idx, | ||
83 | - bool probe, uintptr_t retaddr); | ||
84 | hwaddr (*get_phys_page_debug)(CPUState *cpu, vaddr addr); | ||
85 | hwaddr (*get_phys_page_attrs_debug)(CPUState *cpu, vaddr addr, | ||
86 | MemTxAttrs *attrs); | ||
87 | diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c | ||
88 | index XXXXXXX..XXXXXXX 100644 | ||
89 | --- a/accel/tcg/cputlb.c | ||
90 | +++ b/accel/tcg/cputlb.c | ||
91 | @@ -XXX,XX +XXX,XX @@ static void tlb_fill(CPUState *cpu, target_ulong addr, int size, | ||
92 | * This is not a probe, so only valid return is success; failure | ||
93 | * should result in exception + longjmp to the cpu loop. | ||
94 | */ | ||
95 | - ok = cc->tlb_fill(cpu, addr, size, access_type, mmu_idx, false, retaddr); | ||
96 | + ok = cc->tcg_ops.tlb_fill(cpu, addr, size, | ||
97 | + access_type, mmu_idx, false, retaddr); | ||
98 | assert(ok); | ||
99 | } | 28 | } |
100 | 29 | ||
101 | @@ -XXX,XX +XXX,XX @@ static int probe_access_internal(CPUArchState *env, target_ulong addr, | 30 | static bool fold_nor(OptContext *ctx, TCGOp *op) |
102 | CPUState *cs = env_cpu(env); | 31 | @@ -XXX,XX +XXX,XX @@ static bool fold_shift(OptContext *ctx, TCGOp *op) |
103 | CPUClass *cc = CPU_GET_CLASS(cs); | 32 | return fold_const2(ctx, op); |
104 | |||
105 | - if (!cc->tlb_fill(cs, addr, fault_size, access_type, | ||
106 | - mmu_idx, nonfault, retaddr)) { | ||
107 | + if (!cc->tcg_ops.tlb_fill(cs, addr, fault_size, access_type, | ||
108 | + mmu_idx, nonfault, retaddr)) { | ||
109 | /* Non-faulting page table read failed. */ | ||
110 | *phost = NULL; | ||
111 | return TLB_INVALID_MASK; | ||
112 | diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c | ||
113 | index XXXXXXX..XXXXXXX 100644 | ||
114 | --- a/accel/tcg/user-exec.c | ||
115 | +++ b/accel/tcg/user-exec.c | ||
116 | @@ -XXX,XX +XXX,XX @@ static inline int handle_cpu_signal(uintptr_t pc, siginfo_t *info, | ||
117 | clear_helper_retaddr(); | ||
118 | |||
119 | cc = CPU_GET_CLASS(cpu); | ||
120 | - cc->tlb_fill(cpu, address, 0, access_type, MMU_USER_IDX, false, pc); | ||
121 | + cc->tcg_ops.tlb_fill(cpu, address, 0, access_type, MMU_USER_IDX, false, pc); | ||
122 | g_assert_not_reached(); | ||
123 | } | 33 | } |
124 | 34 | ||
125 | @@ -XXX,XX +XXX,XX @@ static int probe_access_internal(CPUArchState *env, target_ulong addr, | 35 | +static bool fold_sub_to_neg(OptContext *ctx, TCGOp *op) |
126 | } else { | 36 | +{ |
127 | CPUState *cpu = env_cpu(env); | 37 | + TCGOpcode neg_op; |
128 | CPUClass *cc = CPU_GET_CLASS(cpu); | 38 | + bool have_neg; |
129 | - cc->tlb_fill(cpu, addr, fault_size, access_type, | 39 | + |
130 | - MMU_USER_IDX, false, ra); | 40 | + if (!arg_is_const(op->args[1]) || arg_info(op->args[1])->val != 0) { |
131 | + cc->tcg_ops.tlb_fill(cpu, addr, fault_size, access_type, | 41 | + return false; |
132 | + MMU_USER_IDX, false, ra); | 42 | + } |
133 | g_assert_not_reached(); | 43 | + |
44 | + switch (ctx->type) { | ||
45 | + case TCG_TYPE_I32: | ||
46 | + neg_op = INDEX_op_neg_i32; | ||
47 | + have_neg = TCG_TARGET_HAS_neg_i32; | ||
48 | + break; | ||
49 | + case TCG_TYPE_I64: | ||
50 | + neg_op = INDEX_op_neg_i64; | ||
51 | + have_neg = TCG_TARGET_HAS_neg_i64; | ||
52 | + break; | ||
53 | + case TCG_TYPE_V64: | ||
54 | + case TCG_TYPE_V128: | ||
55 | + case TCG_TYPE_V256: | ||
56 | + neg_op = INDEX_op_neg_vec; | ||
57 | + have_neg = (TCG_TARGET_HAS_neg_vec && | ||
58 | + tcg_can_emit_vec_op(neg_op, ctx->type, TCGOP_VECE(op)) > 0); | ||
59 | + break; | ||
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 | { | ||
73 | if (fold_const2(ctx, op) || | ||
74 | - fold_xx_to_i(ctx, op, 0)) { | ||
75 | + fold_xx_to_i(ctx, op, 0) || | ||
76 | + fold_sub_to_neg(ctx, op)) { | ||
77 | return true; | ||
78 | } | ||
79 | return false; | ||
80 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
81 | continue; | ||
82 | } | ||
83 | break; | ||
84 | - CASE_OP_32_64_VEC(sub): | ||
85 | - { | ||
86 | - TCGOpcode neg_op; | ||
87 | - bool have_neg; | ||
88 | - | ||
89 | - if (arg_is_const(op->args[2])) { | ||
90 | - /* Proceed with possible constant folding. */ | ||
91 | - break; | ||
92 | - } | ||
93 | - switch (ctx.type) { | ||
94 | - case TCG_TYPE_I32: | ||
95 | - neg_op = INDEX_op_neg_i32; | ||
96 | - have_neg = TCG_TARGET_HAS_neg_i32; | ||
97 | - break; | ||
98 | - case TCG_TYPE_I64: | ||
99 | - neg_op = INDEX_op_neg_i64; | ||
100 | - have_neg = TCG_TARGET_HAS_neg_i64; | ||
101 | - break; | ||
102 | - case TCG_TYPE_V64: | ||
103 | - case TCG_TYPE_V128: | ||
104 | - case TCG_TYPE_V256: | ||
105 | - neg_op = INDEX_op_neg_vec; | ||
106 | - have_neg = tcg_can_emit_vec_op(neg_op, ctx.type, | ||
107 | - TCGOP_VECE(op)) > 0; | ||
108 | - break; | ||
109 | - default: | ||
110 | - g_assert_not_reached(); | ||
111 | - } | ||
112 | - if (!have_neg) { | ||
113 | - break; | ||
114 | - } | ||
115 | - if (arg_is_const(op->args[1]) | ||
116 | - && arg_info(op->args[1])->val == 0) { | ||
117 | - op->opc = neg_op; | ||
118 | - reset_temp(op->args[0]); | ||
119 | - op->args[1] = op->args[2]; | ||
120 | - continue; | ||
121 | - } | ||
122 | - } | ||
123 | - break; | ||
124 | default: | ||
125 | break; | ||
134 | } | 126 | } |
135 | } | ||
136 | diff --git a/target/alpha/cpu.c b/target/alpha/cpu.c | ||
137 | index XXXXXXX..XXXXXXX 100644 | ||
138 | --- a/target/alpha/cpu.c | ||
139 | +++ b/target/alpha/cpu.c | ||
140 | @@ -XXX,XX +XXX,XX @@ static void alpha_cpu_class_init(ObjectClass *oc, void *data) | ||
141 | cc->set_pc = alpha_cpu_set_pc; | ||
142 | cc->gdb_read_register = alpha_cpu_gdb_read_register; | ||
143 | cc->gdb_write_register = alpha_cpu_gdb_write_register; | ||
144 | - cc->tlb_fill = alpha_cpu_tlb_fill; | ||
145 | + cc->tcg_ops.tlb_fill = alpha_cpu_tlb_fill; | ||
146 | #ifndef CONFIG_USER_ONLY | ||
147 | cc->do_transaction_failed = alpha_cpu_do_transaction_failed; | ||
148 | cc->do_unaligned_access = alpha_cpu_do_unaligned_access; | ||
149 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | ||
150 | index XXXXXXX..XXXXXXX 100644 | ||
151 | --- a/target/arm/cpu.c | ||
152 | +++ b/target/arm/cpu.c | ||
153 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_class_init(ObjectClass *oc, void *data) | ||
154 | cc->tcg_ops.initialize = arm_translate_init; | ||
155 | cc->tcg_ops.cpu_exec_interrupt = arm_cpu_exec_interrupt; | ||
156 | cc->tcg_ops.synchronize_from_tb = arm_cpu_synchronize_from_tb; | ||
157 | - cc->tlb_fill = arm_cpu_tlb_fill; | ||
158 | + cc->tcg_ops.tlb_fill = arm_cpu_tlb_fill; | ||
159 | cc->debug_excp_handler = arm_debug_excp_handler; | ||
160 | cc->debug_check_watchpoint = arm_debug_check_watchpoint; | ||
161 | cc->do_unaligned_access = arm_cpu_do_unaligned_access; | ||
162 | diff --git a/target/avr/cpu.c b/target/avr/cpu.c | ||
163 | index XXXXXXX..XXXXXXX 100644 | ||
164 | --- a/target/avr/cpu.c | ||
165 | +++ b/target/avr/cpu.c | ||
166 | @@ -XXX,XX +XXX,XX @@ static void avr_cpu_class_init(ObjectClass *oc, void *data) | ||
167 | cc->set_pc = avr_cpu_set_pc; | ||
168 | cc->memory_rw_debug = avr_cpu_memory_rw_debug; | ||
169 | cc->get_phys_page_debug = avr_cpu_get_phys_page_debug; | ||
170 | - cc->tlb_fill = avr_cpu_tlb_fill; | ||
171 | + cc->tcg_ops.tlb_fill = avr_cpu_tlb_fill; | ||
172 | cc->vmsd = &vms_avr_cpu; | ||
173 | cc->disas_set_info = avr_cpu_disas_set_info; | ||
174 | cc->tcg_ops.initialize = avr_cpu_tcg_init; | ||
175 | diff --git a/target/cris/cpu.c b/target/cris/cpu.c | ||
176 | index XXXXXXX..XXXXXXX 100644 | ||
177 | --- a/target/cris/cpu.c | ||
178 | +++ b/target/cris/cpu.c | ||
179 | @@ -XXX,XX +XXX,XX @@ static void cris_cpu_class_init(ObjectClass *oc, void *data) | ||
180 | cc->set_pc = cris_cpu_set_pc; | ||
181 | cc->gdb_read_register = cris_cpu_gdb_read_register; | ||
182 | cc->gdb_write_register = cris_cpu_gdb_write_register; | ||
183 | - cc->tlb_fill = cris_cpu_tlb_fill; | ||
184 | + cc->tcg_ops.tlb_fill = cris_cpu_tlb_fill; | ||
185 | #ifndef CONFIG_USER_ONLY | ||
186 | cc->get_phys_page_debug = cris_cpu_get_phys_page_debug; | ||
187 | dc->vmsd = &vmstate_cris_cpu; | ||
188 | diff --git a/target/hppa/cpu.c b/target/hppa/cpu.c | ||
189 | index XXXXXXX..XXXXXXX 100644 | ||
190 | --- a/target/hppa/cpu.c | ||
191 | +++ b/target/hppa/cpu.c | ||
192 | @@ -XXX,XX +XXX,XX @@ static void hppa_cpu_class_init(ObjectClass *oc, void *data) | ||
193 | cc->tcg_ops.synchronize_from_tb = hppa_cpu_synchronize_from_tb; | ||
194 | cc->gdb_read_register = hppa_cpu_gdb_read_register; | ||
195 | cc->gdb_write_register = hppa_cpu_gdb_write_register; | ||
196 | - cc->tlb_fill = hppa_cpu_tlb_fill; | ||
197 | + cc->tcg_ops.tlb_fill = hppa_cpu_tlb_fill; | ||
198 | #ifndef CONFIG_USER_ONLY | ||
199 | cc->get_phys_page_debug = hppa_cpu_get_phys_page_debug; | ||
200 | dc->vmsd = &vmstate_hppa_cpu; | ||
201 | diff --git a/target/i386/tcg/tcg-cpu.c b/target/i386/tcg/tcg-cpu.c | ||
202 | index XXXXXXX..XXXXXXX 100644 | ||
203 | --- a/target/i386/tcg/tcg-cpu.c | ||
204 | +++ b/target/i386/tcg/tcg-cpu.c | ||
205 | @@ -XXX,XX +XXX,XX @@ void tcg_cpu_common_class_init(CPUClass *cc) | ||
206 | cc->tcg_ops.cpu_exec_enter = x86_cpu_exec_enter; | ||
207 | cc->tcg_ops.cpu_exec_exit = x86_cpu_exec_exit; | ||
208 | cc->tcg_ops.initialize = tcg_x86_init; | ||
209 | - cc->tlb_fill = x86_cpu_tlb_fill; | ||
210 | + cc->tcg_ops.tlb_fill = x86_cpu_tlb_fill; | ||
211 | #ifndef CONFIG_USER_ONLY | ||
212 | cc->debug_excp_handler = breakpoint_handler; | ||
213 | #endif | ||
214 | diff --git a/target/lm32/cpu.c b/target/lm32/cpu.c | ||
215 | index XXXXXXX..XXXXXXX 100644 | ||
216 | --- a/target/lm32/cpu.c | ||
217 | +++ b/target/lm32/cpu.c | ||
218 | @@ -XXX,XX +XXX,XX @@ static void lm32_cpu_class_init(ObjectClass *oc, void *data) | ||
219 | cc->set_pc = lm32_cpu_set_pc; | ||
220 | cc->gdb_read_register = lm32_cpu_gdb_read_register; | ||
221 | cc->gdb_write_register = lm32_cpu_gdb_write_register; | ||
222 | - cc->tlb_fill = lm32_cpu_tlb_fill; | ||
223 | + cc->tcg_ops.tlb_fill = lm32_cpu_tlb_fill; | ||
224 | #ifndef CONFIG_USER_ONLY | ||
225 | cc->get_phys_page_debug = lm32_cpu_get_phys_page_debug; | ||
226 | cc->vmsd = &vmstate_lm32_cpu; | ||
227 | diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c | ||
228 | index XXXXXXX..XXXXXXX 100644 | ||
229 | --- a/target/m68k/cpu.c | ||
230 | +++ b/target/m68k/cpu.c | ||
231 | @@ -XXX,XX +XXX,XX @@ static void m68k_cpu_class_init(ObjectClass *c, void *data) | ||
232 | cc->set_pc = m68k_cpu_set_pc; | ||
233 | cc->gdb_read_register = m68k_cpu_gdb_read_register; | ||
234 | cc->gdb_write_register = m68k_cpu_gdb_write_register; | ||
235 | - cc->tlb_fill = m68k_cpu_tlb_fill; | ||
236 | + cc->tcg_ops.tlb_fill = m68k_cpu_tlb_fill; | ||
237 | #if defined(CONFIG_SOFTMMU) | ||
238 | cc->do_transaction_failed = m68k_cpu_transaction_failed; | ||
239 | cc->get_phys_page_debug = m68k_cpu_get_phys_page_debug; | ||
240 | diff --git a/target/microblaze/cpu.c b/target/microblaze/cpu.c | ||
241 | index XXXXXXX..XXXXXXX 100644 | ||
242 | --- a/target/microblaze/cpu.c | ||
243 | +++ b/target/microblaze/cpu.c | ||
244 | @@ -XXX,XX +XXX,XX @@ static void mb_cpu_class_init(ObjectClass *oc, void *data) | ||
245 | cc->tcg_ops.synchronize_from_tb = mb_cpu_synchronize_from_tb; | ||
246 | cc->gdb_read_register = mb_cpu_gdb_read_register; | ||
247 | cc->gdb_write_register = mb_cpu_gdb_write_register; | ||
248 | - cc->tlb_fill = mb_cpu_tlb_fill; | ||
249 | + cc->tcg_ops.tlb_fill = mb_cpu_tlb_fill; | ||
250 | #ifndef CONFIG_USER_ONLY | ||
251 | cc->do_transaction_failed = mb_cpu_transaction_failed; | ||
252 | cc->get_phys_page_attrs_debug = mb_cpu_get_phys_page_attrs_debug; | ||
253 | diff --git a/target/mips/cpu.c b/target/mips/cpu.c | ||
254 | index XXXXXXX..XXXXXXX 100644 | ||
255 | --- a/target/mips/cpu.c | ||
256 | +++ b/target/mips/cpu.c | ||
257 | @@ -XXX,XX +XXX,XX @@ static void mips_cpu_class_init(ObjectClass *c, void *data) | ||
258 | cc->tcg_ops.initialize = mips_tcg_init; | ||
259 | cc->tcg_ops.cpu_exec_interrupt = mips_cpu_exec_interrupt; | ||
260 | cc->tcg_ops.synchronize_from_tb = mips_cpu_synchronize_from_tb; | ||
261 | - cc->tlb_fill = mips_cpu_tlb_fill; | ||
262 | + cc->tcg_ops.tlb_fill = mips_cpu_tlb_fill; | ||
263 | #endif | ||
264 | |||
265 | cc->gdb_num_core_regs = 73; | ||
266 | diff --git a/target/moxie/cpu.c b/target/moxie/cpu.c | ||
267 | index XXXXXXX..XXXXXXX 100644 | ||
268 | --- a/target/moxie/cpu.c | ||
269 | +++ b/target/moxie/cpu.c | ||
270 | @@ -XXX,XX +XXX,XX @@ static void moxie_cpu_class_init(ObjectClass *oc, void *data) | ||
271 | cc->do_interrupt = moxie_cpu_do_interrupt; | ||
272 | cc->dump_state = moxie_cpu_dump_state; | ||
273 | cc->set_pc = moxie_cpu_set_pc; | ||
274 | - cc->tlb_fill = moxie_cpu_tlb_fill; | ||
275 | + cc->tcg_ops.tlb_fill = moxie_cpu_tlb_fill; | ||
276 | #ifndef CONFIG_USER_ONLY | ||
277 | cc->get_phys_page_debug = moxie_cpu_get_phys_page_debug; | ||
278 | cc->vmsd = &vmstate_moxie_cpu; | ||
279 | diff --git a/target/nios2/cpu.c b/target/nios2/cpu.c | ||
280 | index XXXXXXX..XXXXXXX 100644 | ||
281 | --- a/target/nios2/cpu.c | ||
282 | +++ b/target/nios2/cpu.c | ||
283 | @@ -XXX,XX +XXX,XX @@ static void nios2_cpu_class_init(ObjectClass *oc, void *data) | ||
284 | cc->dump_state = nios2_cpu_dump_state; | ||
285 | cc->set_pc = nios2_cpu_set_pc; | ||
286 | cc->disas_set_info = nios2_cpu_disas_set_info; | ||
287 | - cc->tlb_fill = nios2_cpu_tlb_fill; | ||
288 | + cc->tcg_ops.tlb_fill = nios2_cpu_tlb_fill; | ||
289 | #ifndef CONFIG_USER_ONLY | ||
290 | cc->do_unaligned_access = nios2_cpu_do_unaligned_access; | ||
291 | cc->get_phys_page_debug = nios2_cpu_get_phys_page_debug; | ||
292 | diff --git a/target/openrisc/cpu.c b/target/openrisc/cpu.c | ||
293 | index XXXXXXX..XXXXXXX 100644 | ||
294 | --- a/target/openrisc/cpu.c | ||
295 | +++ b/target/openrisc/cpu.c | ||
296 | @@ -XXX,XX +XXX,XX @@ static void openrisc_cpu_class_init(ObjectClass *oc, void *data) | ||
297 | cc->set_pc = openrisc_cpu_set_pc; | ||
298 | cc->gdb_read_register = openrisc_cpu_gdb_read_register; | ||
299 | cc->gdb_write_register = openrisc_cpu_gdb_write_register; | ||
300 | - cc->tlb_fill = openrisc_cpu_tlb_fill; | ||
301 | + cc->tcg_ops.tlb_fill = openrisc_cpu_tlb_fill; | ||
302 | #ifndef CONFIG_USER_ONLY | ||
303 | cc->get_phys_page_debug = openrisc_cpu_get_phys_page_debug; | ||
304 | dc->vmsd = &vmstate_openrisc_cpu; | ||
305 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
306 | index XXXXXXX..XXXXXXX 100644 | ||
307 | --- a/target/riscv/cpu.c | ||
308 | +++ b/target/riscv/cpu.c | ||
309 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_class_init(ObjectClass *c, void *data) | ||
310 | cc->gdb_arch_name = riscv_gdb_arch_name; | ||
311 | cc->gdb_get_dynamic_xml = riscv_gdb_get_dynamic_xml; | ||
312 | cc->tcg_ops.initialize = riscv_translate_init; | ||
313 | - cc->tlb_fill = riscv_cpu_tlb_fill; | ||
314 | + cc->tcg_ops.tlb_fill = riscv_cpu_tlb_fill; | ||
315 | |||
316 | device_class_set_props(dc, riscv_cpu_properties); | ||
317 | } | ||
318 | diff --git a/target/rx/cpu.c b/target/rx/cpu.c | ||
319 | index XXXXXXX..XXXXXXX 100644 | ||
320 | --- a/target/rx/cpu.c | ||
321 | +++ b/target/rx/cpu.c | ||
322 | @@ -XXX,XX +XXX,XX @@ static void rx_cpu_class_init(ObjectClass *klass, void *data) | ||
323 | cc->get_phys_page_debug = rx_cpu_get_phys_page_debug; | ||
324 | cc->disas_set_info = rx_cpu_disas_set_info; | ||
325 | cc->tcg_ops.initialize = rx_translate_init; | ||
326 | - cc->tlb_fill = rx_cpu_tlb_fill; | ||
327 | + cc->tcg_ops.tlb_fill = rx_cpu_tlb_fill; | ||
328 | |||
329 | cc->gdb_num_core_regs = 26; | ||
330 | cc->gdb_core_xml_file = "rx-core.xml"; | ||
331 | diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c | ||
332 | index XXXXXXX..XXXXXXX 100644 | ||
333 | --- a/target/s390x/cpu.c | ||
334 | +++ b/target/s390x/cpu.c | ||
335 | @@ -XXX,XX +XXX,XX @@ static void s390_cpu_class_init(ObjectClass *oc, void *data) | ||
336 | cc->disas_set_info = s390_cpu_disas_set_info; | ||
337 | #ifdef CONFIG_TCG | ||
338 | cc->tcg_ops.initialize = s390x_translate_init; | ||
339 | - cc->tlb_fill = s390_cpu_tlb_fill; | ||
340 | + cc->tcg_ops.tlb_fill = s390_cpu_tlb_fill; | ||
341 | #endif | ||
342 | |||
343 | cc->gdb_num_core_regs = S390_NUM_CORE_REGS; | ||
344 | diff --git a/target/sh4/cpu.c b/target/sh4/cpu.c | ||
345 | index XXXXXXX..XXXXXXX 100644 | ||
346 | --- a/target/sh4/cpu.c | ||
347 | +++ b/target/sh4/cpu.c | ||
348 | @@ -XXX,XX +XXX,XX @@ static void superh_cpu_class_init(ObjectClass *oc, void *data) | ||
349 | cc->tcg_ops.synchronize_from_tb = superh_cpu_synchronize_from_tb; | ||
350 | cc->gdb_read_register = superh_cpu_gdb_read_register; | ||
351 | cc->gdb_write_register = superh_cpu_gdb_write_register; | ||
352 | - cc->tlb_fill = superh_cpu_tlb_fill; | ||
353 | + cc->tcg_ops.tlb_fill = superh_cpu_tlb_fill; | ||
354 | #ifndef CONFIG_USER_ONLY | ||
355 | cc->do_unaligned_access = superh_cpu_do_unaligned_access; | ||
356 | cc->get_phys_page_debug = superh_cpu_get_phys_page_debug; | ||
357 | diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c | ||
358 | index XXXXXXX..XXXXXXX 100644 | ||
359 | --- a/target/sparc/cpu.c | ||
360 | +++ b/target/sparc/cpu.c | ||
361 | @@ -XXX,XX +XXX,XX @@ static void sparc_cpu_class_init(ObjectClass *oc, void *data) | ||
362 | cc->tcg_ops.synchronize_from_tb = sparc_cpu_synchronize_from_tb; | ||
363 | cc->gdb_read_register = sparc_cpu_gdb_read_register; | ||
364 | cc->gdb_write_register = sparc_cpu_gdb_write_register; | ||
365 | - cc->tlb_fill = sparc_cpu_tlb_fill; | ||
366 | + cc->tcg_ops.tlb_fill = sparc_cpu_tlb_fill; | ||
367 | #ifndef CONFIG_USER_ONLY | ||
368 | cc->do_transaction_failed = sparc_cpu_do_transaction_failed; | ||
369 | cc->do_unaligned_access = sparc_cpu_do_unaligned_access; | ||
370 | diff --git a/target/tilegx/cpu.c b/target/tilegx/cpu.c | ||
371 | index XXXXXXX..XXXXXXX 100644 | ||
372 | --- a/target/tilegx/cpu.c | ||
373 | +++ b/target/tilegx/cpu.c | ||
374 | @@ -XXX,XX +XXX,XX @@ static void tilegx_cpu_class_init(ObjectClass *oc, void *data) | ||
375 | cc->tcg_ops.cpu_exec_interrupt = tilegx_cpu_exec_interrupt; | ||
376 | cc->dump_state = tilegx_cpu_dump_state; | ||
377 | cc->set_pc = tilegx_cpu_set_pc; | ||
378 | - cc->tlb_fill = tilegx_cpu_tlb_fill; | ||
379 | + cc->tcg_ops.tlb_fill = tilegx_cpu_tlb_fill; | ||
380 | cc->gdb_num_core_regs = 0; | ||
381 | cc->tcg_ops.initialize = tilegx_tcg_init; | ||
382 | } | ||
383 | diff --git a/target/tricore/cpu.c b/target/tricore/cpu.c | ||
384 | index XXXXXXX..XXXXXXX 100644 | ||
385 | --- a/target/tricore/cpu.c | ||
386 | +++ b/target/tricore/cpu.c | ||
387 | @@ -XXX,XX +XXX,XX @@ static void tricore_cpu_class_init(ObjectClass *c, void *data) | ||
388 | cc->tcg_ops.synchronize_from_tb = tricore_cpu_synchronize_from_tb; | ||
389 | cc->get_phys_page_debug = tricore_cpu_get_phys_page_debug; | ||
390 | cc->tcg_ops.initialize = tricore_tcg_init; | ||
391 | - cc->tlb_fill = tricore_cpu_tlb_fill; | ||
392 | + cc->tcg_ops.tlb_fill = tricore_cpu_tlb_fill; | ||
393 | } | ||
394 | |||
395 | #define DEFINE_TRICORE_CPU_TYPE(cpu_model, initfn) \ | ||
396 | diff --git a/target/unicore32/cpu.c b/target/unicore32/cpu.c | ||
397 | index XXXXXXX..XXXXXXX 100644 | ||
398 | --- a/target/unicore32/cpu.c | ||
399 | +++ b/target/unicore32/cpu.c | ||
400 | @@ -XXX,XX +XXX,XX @@ static void uc32_cpu_class_init(ObjectClass *oc, void *data) | ||
401 | cc->tcg_ops.cpu_exec_interrupt = uc32_cpu_exec_interrupt; | ||
402 | cc->dump_state = uc32_cpu_dump_state; | ||
403 | cc->set_pc = uc32_cpu_set_pc; | ||
404 | - cc->tlb_fill = uc32_cpu_tlb_fill; | ||
405 | + cc->tcg_ops.tlb_fill = uc32_cpu_tlb_fill; | ||
406 | cc->get_phys_page_debug = uc32_cpu_get_phys_page_debug; | ||
407 | cc->tcg_ops.initialize = uc32_translate_init; | ||
408 | dc->vmsd = &vmstate_uc32_cpu; | ||
409 | diff --git a/target/xtensa/cpu.c b/target/xtensa/cpu.c | ||
410 | index XXXXXXX..XXXXXXX 100644 | ||
411 | --- a/target/xtensa/cpu.c | ||
412 | +++ b/target/xtensa/cpu.c | ||
413 | @@ -XXX,XX +XXX,XX @@ static void xtensa_cpu_class_init(ObjectClass *oc, void *data) | ||
414 | cc->gdb_read_register = xtensa_cpu_gdb_read_register; | ||
415 | cc->gdb_write_register = xtensa_cpu_gdb_write_register; | ||
416 | cc->gdb_stop_before_watchpoint = true; | ||
417 | - cc->tlb_fill = xtensa_cpu_tlb_fill; | ||
418 | + cc->tcg_ops.tlb_fill = xtensa_cpu_tlb_fill; | ||
419 | #ifndef CONFIG_USER_ONLY | ||
420 | cc->do_unaligned_access = xtensa_cpu_do_unaligned_access; | ||
421 | cc->get_phys_page_debug = xtensa_cpu_get_phys_page_debug; | ||
422 | diff --git a/target/ppc/translate_init.c.inc b/target/ppc/translate_init.c.inc | ||
423 | index XXXXXXX..XXXXXXX 100644 | ||
424 | --- a/target/ppc/translate_init.c.inc | ||
425 | +++ b/target/ppc/translate_init.c.inc | ||
426 | @@ -XXX,XX +XXX,XX @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data) | ||
427 | #ifdef CONFIG_TCG | ||
428 | cc->tcg_ops.initialize = ppc_translate_init; | ||
429 | cc->tcg_ops.cpu_exec_interrupt = ppc_cpu_exec_interrupt; | ||
430 | - cc->tlb_fill = ppc_cpu_tlb_fill; | ||
431 | + cc->tcg_ops.tlb_fill = ppc_cpu_tlb_fill; | ||
432 | #ifndef CONFIG_USER_ONLY | ||
433 | cc->tcg_ops.cpu_exec_enter = ppc_cpu_exec_enter; | ||
434 | cc->tcg_ops.cpu_exec_exit = ppc_cpu_exec_exit; | ||
435 | -- | 127 | -- |
436 | 2.25.1 | 128 | 2.25.1 |
437 | 129 | ||
438 | 130 | diff view generated by jsdifflib |
1 | From: Claudio Fontana <cfontana@suse.de> | 1 | Pull the "op r, a, i => mov r, a" optimization into a function, |
---|---|---|---|
2 | and use them in the outer-most logical operations. | ||
2 | 3 | ||
3 | make it consistently SOFTMMU-only. | 4 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> |
4 | |||
5 | Signed-off-by: Claudio Fontana <cfontana@suse.de> | ||
6 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | ||
7 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
9 | |||
10 | [claudio: make the field presence in cpu.h unconditional, removing the ifdefs] | ||
11 | Message-Id: <20210204163931.7358-12-cfontana@suse.de> | ||
12 | |||
13 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
14 | --- | 6 | --- |
15 | include/hw/core/cpu.h | 13 +++++++------ | 7 | tcg/optimize.c | 61 +++++++++++++++++++++----------------------------- |
16 | target/alpha/cpu.c | 2 +- | 8 | 1 file changed, 26 insertions(+), 35 deletions(-) |
17 | target/arm/cpu.c | 2 +- | ||
18 | target/hppa/cpu.c | 4 +++- | ||
19 | target/microblaze/cpu.c | 2 +- | ||
20 | target/mips/cpu.c | 3 ++- | ||
21 | target/nios2/cpu.c | 2 +- | ||
22 | target/riscv/cpu.c | 2 +- | ||
23 | target/s390x/cpu.c | 2 +- | ||
24 | target/s390x/excp_helper.c | 2 +- | ||
25 | target/sh4/cpu.c | 2 +- | ||
26 | target/sparc/cpu.c | 2 +- | ||
27 | target/xtensa/cpu.c | 2 +- | ||
28 | target/ppc/translate_init.c.inc | 2 +- | ||
29 | 14 files changed, 23 insertions(+), 19 deletions(-) | ||
30 | 9 | ||
31 | diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h | 10 | diff --git a/tcg/optimize.c b/tcg/optimize.c |
32 | index XXXXXXX..XXXXXXX 100644 | 11 | index XXXXXXX..XXXXXXX 100644 |
33 | --- a/include/hw/core/cpu.h | 12 | --- a/tcg/optimize.c |
34 | +++ b/include/hw/core/cpu.h | 13 | +++ b/tcg/optimize.c |
35 | @@ -XXX,XX +XXX,XX @@ typedef struct TcgCpuOperations { | 14 | @@ -XXX,XX +XXX,XX @@ static bool fold_xi_to_i(OptContext *ctx, TCGOp *op, uint64_t i) |
36 | unsigned size, MMUAccessType access_type, | 15 | return false; |
37 | int mmu_idx, MemTxAttrs attrs, | 16 | } |
38 | MemTxResult response, uintptr_t retaddr); | 17 | |
39 | + /** | 18 | +/* If the binary operation has second argument @i, fold to identity. */ |
40 | + * @do_unaligned_access: Callback for unaligned access handling | 19 | +static bool fold_xi_to_x(OptContext *ctx, TCGOp *op, uint64_t i) |
41 | + */ | 20 | +{ |
42 | + void (*do_unaligned_access)(CPUState *cpu, vaddr addr, | 21 | + if (arg_is_const(op->args[2]) && arg_info(op->args[2])->val == i) { |
43 | + MMUAccessType access_type, | 22 | + return tcg_opt_gen_mov(ctx, op, op->args[0], op->args[1]); |
44 | + int mmu_idx, uintptr_t retaddr); | 23 | + } |
45 | } TcgCpuOperations; | 24 | + return false; |
46 | 25 | +} | |
47 | /** | 26 | + |
48 | @@ -XXX,XX +XXX,XX @@ typedef struct TcgCpuOperations { | 27 | /* If the binary operation has second argument @i, fold to NOT. */ |
49 | * @parse_features: Callback to parse command line arguments. | 28 | static bool fold_xi_to_not(OptContext *ctx, TCGOp *op, uint64_t i) |
50 | * @reset_dump_flags: #CPUDumpFlags to use for reset logging. | ||
51 | * @has_work: Callback for checking if there is work to do. | ||
52 | - * @do_unaligned_access: Callback for unaligned access handling, if | ||
53 | - * the target defines #TARGET_ALIGNED_ONLY. | ||
54 | * @virtio_is_big_endian: Callback to return %true if a CPU which supports | ||
55 | * runtime configurable endianness is currently big-endian. Non-configurable | ||
56 | * CPUs can use the default implementation of this method. This method should | ||
57 | @@ -XXX,XX +XXX,XX @@ struct CPUClass { | ||
58 | |||
59 | int reset_dump_flags; | ||
60 | bool (*has_work)(CPUState *cpu); | ||
61 | - void (*do_unaligned_access)(CPUState *cpu, vaddr addr, | ||
62 | - MMUAccessType access_type, | ||
63 | - int mmu_idx, uintptr_t retaddr); | ||
64 | bool (*virtio_is_big_endian)(CPUState *cpu); | ||
65 | int (*memory_rw_debug)(CPUState *cpu, vaddr addr, | ||
66 | uint8_t *buf, int len, bool is_write); | ||
67 | @@ -XXX,XX +XXX,XX @@ static inline void cpu_unaligned_access(CPUState *cpu, vaddr addr, | ||
68 | { | 29 | { |
69 | CPUClass *cc = CPU_GET_CLASS(cpu); | 30 | @@ -XXX,XX +XXX,XX @@ static bool fold_xx_to_x(OptContext *ctx, TCGOp *op) |
70 | 31 | ||
71 | - cc->do_unaligned_access(cpu, addr, access_type, mmu_idx, retaddr); | 32 | static bool fold_add(OptContext *ctx, TCGOp *op) |
72 | + cc->tcg_ops.do_unaligned_access(cpu, addr, access_type, mmu_idx, retaddr); | 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; | ||
73 | } | 40 | } |
74 | 41 | ||
75 | static inline void cpu_transaction_failed(CPUState *cpu, hwaddr physaddr, | 42 | static bool fold_addsub2_i32(OptContext *ctx, TCGOp *op, bool add) |
76 | diff --git a/target/alpha/cpu.c b/target/alpha/cpu.c | 43 | @@ -XXX,XX +XXX,XX @@ static bool fold_and(OptContext *ctx, TCGOp *op) |
77 | index XXXXXXX..XXXXXXX 100644 | 44 | { |
78 | --- a/target/alpha/cpu.c | 45 | if (fold_const2(ctx, op) || |
79 | +++ b/target/alpha/cpu.c | 46 | fold_xi_to_i(ctx, op, 0) || |
80 | @@ -XXX,XX +XXX,XX @@ static void alpha_cpu_class_init(ObjectClass *oc, void *data) | 47 | + fold_xi_to_x(ctx, op, -1) || |
81 | cc->tcg_ops.tlb_fill = alpha_cpu_tlb_fill; | 48 | fold_xx_to_x(ctx, op)) { |
82 | #ifndef CONFIG_USER_ONLY | 49 | return true; |
83 | cc->tcg_ops.do_transaction_failed = alpha_cpu_do_transaction_failed; | 50 | } |
84 | - cc->do_unaligned_access = alpha_cpu_do_unaligned_access; | 51 | @@ -XXX,XX +XXX,XX @@ static bool fold_andc(OptContext *ctx, TCGOp *op) |
85 | + cc->tcg_ops.do_unaligned_access = alpha_cpu_do_unaligned_access; | 52 | { |
86 | cc->get_phys_page_debug = alpha_cpu_get_phys_page_debug; | 53 | if (fold_const2(ctx, op) || |
87 | dc->vmsd = &vmstate_alpha_cpu; | 54 | fold_xx_to_i(ctx, op, 0) || |
88 | #endif | 55 | + fold_xi_to_x(ctx, op, 0) || |
89 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | 56 | fold_ix_to_not(ctx, op, -1)) { |
90 | index XXXXXXX..XXXXXXX 100644 | 57 | return true; |
91 | --- a/target/arm/cpu.c | 58 | } |
92 | +++ b/target/arm/cpu.c | 59 | @@ -XXX,XX +XXX,XX @@ static bool fold_dup2(OptContext *ctx, TCGOp *op) |
93 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_class_init(ObjectClass *oc, void *data) | 60 | static bool fold_eqv(OptContext *ctx, TCGOp *op) |
94 | cc->tcg_ops.tlb_fill = arm_cpu_tlb_fill; | 61 | { |
95 | cc->tcg_ops.debug_excp_handler = arm_debug_excp_handler; | 62 | if (fold_const2(ctx, op) || |
96 | cc->debug_check_watchpoint = arm_debug_check_watchpoint; | 63 | + fold_xi_to_x(ctx, op, -1) || |
97 | - cc->do_unaligned_access = arm_cpu_do_unaligned_access; | 64 | fold_xi_to_not(ctx, op, 0)) { |
98 | #if !defined(CONFIG_USER_ONLY) | 65 | return true; |
99 | cc->tcg_ops.do_transaction_failed = arm_cpu_do_transaction_failed; | 66 | } |
100 | + cc->tcg_ops.do_unaligned_access = arm_cpu_do_unaligned_access; | 67 | @@ -XXX,XX +XXX,XX @@ static bool fold_not(OptContext *ctx, TCGOp *op) |
101 | cc->adjust_watchpoint_address = arm_adjust_watchpoint_address; | 68 | static bool fold_or(OptContext *ctx, TCGOp *op) |
102 | cc->tcg_ops.do_interrupt = arm_cpu_do_interrupt; | 69 | { |
103 | #endif /* CONFIG_TCG && !CONFIG_USER_ONLY */ | 70 | if (fold_const2(ctx, op) || |
104 | diff --git a/target/hppa/cpu.c b/target/hppa/cpu.c | 71 | + fold_xi_to_x(ctx, op, 0) || |
105 | index XXXXXXX..XXXXXXX 100644 | 72 | fold_xx_to_x(ctx, op)) { |
106 | --- a/target/hppa/cpu.c | 73 | return true; |
107 | +++ b/target/hppa/cpu.c | 74 | } |
108 | @@ -XXX,XX +XXX,XX @@ static void hppa_cpu_disas_set_info(CPUState *cs, disassemble_info *info) | 75 | @@ -XXX,XX +XXX,XX @@ static bool fold_or(OptContext *ctx, TCGOp *op) |
109 | info->print_insn = print_insn_hppa; | 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; | ||
110 | } | 93 | } |
111 | 94 | ||
112 | +#ifndef CONFIG_USER_ONLY | 95 | static bool fold_sub_to_neg(OptContext *ctx, TCGOp *op) |
113 | static void hppa_cpu_do_unaligned_access(CPUState *cs, vaddr addr, | 96 | @@ -XXX,XX +XXX,XX @@ static bool fold_sub(OptContext *ctx, TCGOp *op) |
114 | MMUAccessType access_type, | ||
115 | int mmu_idx, uintptr_t retaddr) | ||
116 | @@ -XXX,XX +XXX,XX @@ static void hppa_cpu_do_unaligned_access(CPUState *cs, vaddr addr, | ||
117 | |||
118 | cpu_loop_exit_restore(cs, retaddr); | ||
119 | } | ||
120 | +#endif /* CONFIG_USER_ONLY */ | ||
121 | |||
122 | static void hppa_cpu_realizefn(DeviceState *dev, Error **errp) | ||
123 | { | 97 | { |
124 | @@ -XXX,XX +XXX,XX @@ static void hppa_cpu_class_init(ObjectClass *oc, void *data) | 98 | if (fold_const2(ctx, op) || |
125 | cc->tcg_ops.tlb_fill = hppa_cpu_tlb_fill; | 99 | fold_xx_to_i(ctx, op, 0) || |
126 | #ifndef CONFIG_USER_ONLY | 100 | + fold_xi_to_x(ctx, op, 0) || |
127 | cc->get_phys_page_debug = hppa_cpu_get_phys_page_debug; | 101 | fold_sub_to_neg(ctx, op)) { |
128 | + cc->tcg_ops.do_unaligned_access = hppa_cpu_do_unaligned_access; | 102 | return true; |
129 | dc->vmsd = &vmstate_hppa_cpu; | ||
130 | #endif | ||
131 | - cc->do_unaligned_access = hppa_cpu_do_unaligned_access; | ||
132 | cc->disas_set_info = hppa_cpu_disas_set_info; | ||
133 | cc->tcg_ops.initialize = hppa_translate_init; | ||
134 | |||
135 | diff --git a/target/microblaze/cpu.c b/target/microblaze/cpu.c | ||
136 | index XXXXXXX..XXXXXXX 100644 | ||
137 | --- a/target/microblaze/cpu.c | ||
138 | +++ b/target/microblaze/cpu.c | ||
139 | @@ -XXX,XX +XXX,XX @@ static void mb_cpu_class_init(ObjectClass *oc, void *data) | ||
140 | cc->class_by_name = mb_cpu_class_by_name; | ||
141 | cc->has_work = mb_cpu_has_work; | ||
142 | cc->tcg_ops.do_interrupt = mb_cpu_do_interrupt; | ||
143 | - cc->do_unaligned_access = mb_cpu_do_unaligned_access; | ||
144 | cc->tcg_ops.cpu_exec_interrupt = mb_cpu_exec_interrupt; | ||
145 | cc->dump_state = mb_cpu_dump_state; | ||
146 | cc->set_pc = mb_cpu_set_pc; | ||
147 | @@ -XXX,XX +XXX,XX @@ static void mb_cpu_class_init(ObjectClass *oc, void *data) | ||
148 | cc->tcg_ops.tlb_fill = mb_cpu_tlb_fill; | ||
149 | #ifndef CONFIG_USER_ONLY | ||
150 | cc->tcg_ops.do_transaction_failed = mb_cpu_transaction_failed; | ||
151 | + cc->tcg_ops.do_unaligned_access = mb_cpu_do_unaligned_access; | ||
152 | cc->get_phys_page_attrs_debug = mb_cpu_get_phys_page_attrs_debug; | ||
153 | dc->vmsd = &vmstate_mb_cpu; | ||
154 | #endif | ||
155 | diff --git a/target/mips/cpu.c b/target/mips/cpu.c | ||
156 | index XXXXXXX..XXXXXXX 100644 | ||
157 | --- a/target/mips/cpu.c | ||
158 | +++ b/target/mips/cpu.c | ||
159 | @@ -XXX,XX +XXX,XX @@ static void mips_cpu_class_init(ObjectClass *c, void *data) | ||
160 | cc->gdb_read_register = mips_cpu_gdb_read_register; | ||
161 | cc->gdb_write_register = mips_cpu_gdb_write_register; | ||
162 | #ifndef CONFIG_USER_ONLY | ||
163 | - cc->do_unaligned_access = mips_cpu_do_unaligned_access; | ||
164 | cc->get_phys_page_debug = mips_cpu_get_phys_page_debug; | ||
165 | cc->vmsd = &vmstate_mips_cpu; | ||
166 | #endif | ||
167 | @@ -XXX,XX +XXX,XX @@ static void mips_cpu_class_init(ObjectClass *c, void *data) | ||
168 | cc->tcg_ops.tlb_fill = mips_cpu_tlb_fill; | ||
169 | #ifndef CONFIG_USER_ONLY | ||
170 | cc->tcg_ops.do_transaction_failed = mips_cpu_do_transaction_failed; | ||
171 | + cc->tcg_ops.do_unaligned_access = mips_cpu_do_unaligned_access; | ||
172 | + | ||
173 | #endif /* CONFIG_USER_ONLY */ | ||
174 | #endif /* CONFIG_TCG */ | ||
175 | |||
176 | diff --git a/target/nios2/cpu.c b/target/nios2/cpu.c | ||
177 | index XXXXXXX..XXXXXXX 100644 | ||
178 | --- a/target/nios2/cpu.c | ||
179 | +++ b/target/nios2/cpu.c | ||
180 | @@ -XXX,XX +XXX,XX @@ static void nios2_cpu_class_init(ObjectClass *oc, void *data) | ||
181 | cc->disas_set_info = nios2_cpu_disas_set_info; | ||
182 | cc->tcg_ops.tlb_fill = nios2_cpu_tlb_fill; | ||
183 | #ifndef CONFIG_USER_ONLY | ||
184 | - cc->do_unaligned_access = nios2_cpu_do_unaligned_access; | ||
185 | + cc->tcg_ops.do_unaligned_access = nios2_cpu_do_unaligned_access; | ||
186 | cc->get_phys_page_debug = nios2_cpu_get_phys_page_debug; | ||
187 | #endif | ||
188 | cc->gdb_read_register = nios2_cpu_gdb_read_register; | ||
189 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
190 | index XXXXXXX..XXXXXXX 100644 | ||
191 | --- a/target/riscv/cpu.c | ||
192 | +++ b/target/riscv/cpu.c | ||
193 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_class_init(ObjectClass *c, void *data) | ||
194 | cc->disas_set_info = riscv_cpu_disas_set_info; | ||
195 | #ifndef CONFIG_USER_ONLY | ||
196 | cc->tcg_ops.do_transaction_failed = riscv_cpu_do_transaction_failed; | ||
197 | - cc->do_unaligned_access = riscv_cpu_do_unaligned_access; | ||
198 | + cc->tcg_ops.do_unaligned_access = riscv_cpu_do_unaligned_access; | ||
199 | cc->get_phys_page_debug = riscv_cpu_get_phys_page_debug; | ||
200 | /* For now, mark unmigratable: */ | ||
201 | cc->vmsd = &vmstate_riscv_cpu; | ||
202 | diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c | ||
203 | index XXXXXXX..XXXXXXX 100644 | ||
204 | --- a/target/s390x/cpu.c | ||
205 | +++ b/target/s390x/cpu.c | ||
206 | @@ -XXX,XX +XXX,XX @@ static void s390_cpu_class_init(ObjectClass *oc, void *data) | ||
207 | #ifdef CONFIG_TCG | ||
208 | cc->tcg_ops.cpu_exec_interrupt = s390_cpu_exec_interrupt; | ||
209 | cc->tcg_ops.debug_excp_handler = s390x_cpu_debug_excp_handler; | ||
210 | - cc->do_unaligned_access = s390x_cpu_do_unaligned_access; | ||
211 | + cc->tcg_ops.do_unaligned_access = s390x_cpu_do_unaligned_access; | ||
212 | #endif | ||
213 | #endif | ||
214 | cc->disas_set_info = s390_cpu_disas_set_info; | ||
215 | diff --git a/target/s390x/excp_helper.c b/target/s390x/excp_helper.c | ||
216 | index XXXXXXX..XXXXXXX 100644 | ||
217 | --- a/target/s390x/excp_helper.c | ||
218 | +++ b/target/s390x/excp_helper.c | ||
219 | @@ -XXX,XX +XXX,XX @@ void HELPER(monitor_call)(CPUS390XState *env, uint64_t monitor_code, | ||
220 | } | 103 | } |
221 | } | 104 | @@ -XXX,XX +XXX,XX @@ static bool fold_xor(OptContext *ctx, TCGOp *op) |
222 | 105 | { | |
223 | -#endif /* CONFIG_USER_ONLY */ | 106 | if (fold_const2(ctx, op) || |
224 | +#endif /* !CONFIG_USER_ONLY */ | 107 | fold_xx_to_i(ctx, op, 0) || |
225 | diff --git a/target/sh4/cpu.c b/target/sh4/cpu.c | 108 | + fold_xi_to_x(ctx, op, 0) || |
226 | index XXXXXXX..XXXXXXX 100644 | 109 | fold_xi_to_not(ctx, op, -1)) { |
227 | --- a/target/sh4/cpu.c | 110 | return true; |
228 | +++ b/target/sh4/cpu.c | 111 | } |
229 | @@ -XXX,XX +XXX,XX @@ static void superh_cpu_class_init(ObjectClass *oc, void *data) | 112 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) |
230 | cc->gdb_write_register = superh_cpu_gdb_write_register; | 113 | break; |
231 | cc->tcg_ops.tlb_fill = superh_cpu_tlb_fill; | 114 | } |
232 | #ifndef CONFIG_USER_ONLY | 115 | |
233 | - cc->do_unaligned_access = superh_cpu_do_unaligned_access; | 116 | - /* Simplify expression for "op r, a, const => mov r, a" cases */ |
234 | + cc->tcg_ops.do_unaligned_access = superh_cpu_do_unaligned_access; | 117 | - switch (opc) { |
235 | cc->get_phys_page_debug = superh_cpu_get_phys_page_debug; | 118 | - CASE_OP_32_64_VEC(add): |
236 | #endif | 119 | - CASE_OP_32_64_VEC(sub): |
237 | cc->disas_set_info = superh_cpu_disas_set_info; | 120 | - CASE_OP_32_64_VEC(or): |
238 | diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c | 121 | - CASE_OP_32_64_VEC(xor): |
239 | index XXXXXXX..XXXXXXX 100644 | 122 | - CASE_OP_32_64_VEC(andc): |
240 | --- a/target/sparc/cpu.c | 123 | - CASE_OP_32_64(shl): |
241 | +++ b/target/sparc/cpu.c | 124 | - CASE_OP_32_64(shr): |
242 | @@ -XXX,XX +XXX,XX @@ static void sparc_cpu_class_init(ObjectClass *oc, void *data) | 125 | - CASE_OP_32_64(sar): |
243 | cc->tcg_ops.tlb_fill = sparc_cpu_tlb_fill; | 126 | - CASE_OP_32_64(rotl): |
244 | #ifndef CONFIG_USER_ONLY | 127 | - CASE_OP_32_64(rotr): |
245 | cc->tcg_ops.do_transaction_failed = sparc_cpu_do_transaction_failed; | 128 | - if (!arg_is_const(op->args[1]) |
246 | - cc->do_unaligned_access = sparc_cpu_do_unaligned_access; | 129 | - && arg_is_const(op->args[2]) |
247 | + cc->tcg_ops.do_unaligned_access = sparc_cpu_do_unaligned_access; | 130 | - && arg_info(op->args[2])->val == 0) { |
248 | cc->get_phys_page_debug = sparc_cpu_get_phys_page_debug; | 131 | - tcg_opt_gen_mov(&ctx, op, op->args[0], op->args[1]); |
249 | cc->vmsd = &vmstate_sparc_cpu; | 132 | - continue; |
250 | #endif | 133 | - } |
251 | diff --git a/target/xtensa/cpu.c b/target/xtensa/cpu.c | 134 | - break; |
252 | index XXXXXXX..XXXXXXX 100644 | 135 | - CASE_OP_32_64_VEC(and): |
253 | --- a/target/xtensa/cpu.c | 136 | - CASE_OP_32_64_VEC(orc): |
254 | +++ b/target/xtensa/cpu.c | 137 | - CASE_OP_32_64(eqv): |
255 | @@ -XXX,XX +XXX,XX @@ static void xtensa_cpu_class_init(ObjectClass *oc, void *data) | 138 | - if (!arg_is_const(op->args[1]) |
256 | cc->gdb_stop_before_watchpoint = true; | 139 | - && arg_is_const(op->args[2]) |
257 | cc->tcg_ops.tlb_fill = xtensa_cpu_tlb_fill; | 140 | - && arg_info(op->args[2])->val == -1) { |
258 | #ifndef CONFIG_USER_ONLY | 141 | - tcg_opt_gen_mov(&ctx, op, op->args[0], op->args[1]); |
259 | - cc->do_unaligned_access = xtensa_cpu_do_unaligned_access; | 142 | - continue; |
260 | + cc->tcg_ops.do_unaligned_access = xtensa_cpu_do_unaligned_access; | 143 | - } |
261 | cc->get_phys_page_debug = xtensa_cpu_get_phys_page_debug; | 144 | - break; |
262 | cc->tcg_ops.do_transaction_failed = xtensa_cpu_do_transaction_failed; | 145 | - default: |
263 | #endif | 146 | - break; |
264 | diff --git a/target/ppc/translate_init.c.inc b/target/ppc/translate_init.c.inc | 147 | - } |
265 | index XXXXXXX..XXXXXXX 100644 | 148 | - |
266 | --- a/target/ppc/translate_init.c.inc | 149 | /* Simplify using known-zero bits. Currently only ops with a single |
267 | +++ b/target/ppc/translate_init.c.inc | 150 | output argument is supported. */ |
268 | @@ -XXX,XX +XXX,XX @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data) | 151 | z_mask = -1; |
269 | cc->set_pc = ppc_cpu_set_pc; | ||
270 | cc->gdb_read_register = ppc_cpu_gdb_read_register; | ||
271 | cc->gdb_write_register = ppc_cpu_gdb_write_register; | ||
272 | - cc->do_unaligned_access = ppc_cpu_do_unaligned_access; | ||
273 | #ifndef CONFIG_USER_ONLY | ||
274 | cc->get_phys_page_debug = ppc_cpu_get_phys_page_debug; | ||
275 | cc->vmsd = &vmstate_ppc_cpu; | ||
276 | @@ -XXX,XX +XXX,XX @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data) | ||
277 | #ifndef CONFIG_USER_ONLY | ||
278 | cc->tcg_ops.cpu_exec_enter = ppc_cpu_exec_enter; | ||
279 | cc->tcg_ops.cpu_exec_exit = ppc_cpu_exec_exit; | ||
280 | + cc->tcg_ops.do_unaligned_access = ppc_cpu_do_unaligned_access; | ||
281 | #endif /* !CONFIG_USER_ONLY */ | ||
282 | #endif /* CONFIG_TCG */ | ||
283 | |||
284 | -- | 152 | -- |
285 | 2.25.1 | 153 | 2.25.1 |
286 | 154 | ||
287 | 155 | diff view generated by jsdifflib |
1 | Tested-by: Alex Bennée <alex.bennee@linaro.org> | 1 | Pull the "op r, 0, b => movi r, 0" optimization into a function, |
---|---|---|---|
2 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 2 | and use it in fold_shift. |
3 | |||
4 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | ||
5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
4 | --- | 7 | --- |
5 | tcg/tci.c | 10 +--------- | 8 | tcg/optimize.c | 28 ++++++++++------------------ |
6 | 1 file changed, 1 insertion(+), 9 deletions(-) | 9 | 1 file changed, 10 insertions(+), 18 deletions(-) |
7 | 10 | ||
8 | diff --git a/tcg/tci.c b/tcg/tci.c | 11 | diff --git a/tcg/optimize.c b/tcg/optimize.c |
9 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
10 | --- a/tcg/tci.c | 13 | --- a/tcg/optimize.c |
11 | +++ b/tcg/tci.c | 14 | +++ b/tcg/optimize.c |
12 | @@ -XXX,XX +XXX,XX @@ tci_write_reg(tcg_target_ulong *regs, TCGReg index, tcg_target_ulong value) | 15 | @@ -XXX,XX +XXX,XX @@ static bool fold_to_not(OptContext *ctx, TCGOp *op, int idx) |
13 | regs[index] = value; | 16 | return false; |
14 | } | 17 | } |
15 | 18 | ||
16 | -#if TCG_TARGET_REG_BITS == 64 | 19 | +/* If the binary operation has first argument @i, fold to @i. */ |
17 | -static void | 20 | +static bool fold_ix_to_i(OptContext *ctx, TCGOp *op, uint64_t i) |
18 | -tci_write_reg16(tcg_target_ulong *regs, TCGReg index, uint16_t value) | 21 | +{ |
19 | -{ | 22 | + if (arg_is_const(op->args[1]) && arg_info(op->args[1])->val == i) { |
20 | - tci_write_reg(regs, index, value); | 23 | + return tcg_opt_gen_movi(ctx, op, op->args[0], i); |
21 | -} | 24 | + } |
22 | -#endif | 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 | { | ||
31 | @@ -XXX,XX +XXX,XX @@ static bool fold_sextract(OptContext *ctx, TCGOp *op) | ||
32 | static bool fold_shift(OptContext *ctx, TCGOp *op) | ||
33 | { | ||
34 | if (fold_const2(ctx, op) || | ||
35 | + fold_ix_to_i(ctx, op, 0) || | ||
36 | fold_xi_to_x(ctx, op, 0)) { | ||
37 | return true; | ||
38 | } | ||
39 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
40 | break; | ||
41 | } | ||
42 | |||
43 | - /* Simplify expressions for "shift/rot r, 0, a => movi r, 0", | ||
44 | - and "sub r, 0, a => neg r, a" case. */ | ||
45 | - switch (opc) { | ||
46 | - CASE_OP_32_64(shl): | ||
47 | - CASE_OP_32_64(shr): | ||
48 | - CASE_OP_32_64(sar): | ||
49 | - CASE_OP_32_64(rotl): | ||
50 | - CASE_OP_32_64(rotr): | ||
51 | - if (arg_is_const(op->args[1]) | ||
52 | - && arg_info(op->args[1])->val == 0) { | ||
53 | - tcg_opt_gen_movi(&ctx, op, op->args[0], 0); | ||
54 | - continue; | ||
55 | - } | ||
56 | - break; | ||
57 | - default: | ||
58 | - break; | ||
59 | - } | ||
23 | - | 60 | - |
24 | static void | 61 | /* Simplify using known-zero bits. Currently only ops with a single |
25 | tci_write_reg32(tcg_target_ulong *regs, TCGReg index, uint32_t value) | 62 | output argument is supported. */ |
26 | { | 63 | z_mask = -1; |
27 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | ||
28 | t0 = *tb_ptr++; | ||
29 | t1 = tci_read_r(regs, &tb_ptr); | ||
30 | t2 = tci_read_s32(&tb_ptr); | ||
31 | - tci_write_reg16(regs, t0, *(uint16_t *)(t1 + t2)); | ||
32 | + tci_write_reg(regs, t0, *(uint16_t *)(t1 + t2)); | ||
33 | break; | ||
34 | case INDEX_op_ld16s_i64: | ||
35 | TODO(); | ||
36 | -- | 64 | -- |
37 | 2.25.1 | 65 | 2.25.1 |
38 | 66 | ||
39 | 67 | diff view generated by jsdifflib |
1 | The configure option was backward, and we failed to | 1 | Move all of the known-zero optimizations into the per-opcode |
---|---|---|---|
2 | pass the value on to meson. | 2 | functions. Use fold_masks when there is a possibility of the |
3 | result being determined, and simply set ctx->z_mask otherwise. | ||
3 | 4 | ||
4 | Fixes: 23a77b2d18b ("build-system: clean up TCG/TCI configury") | ||
5 | Tested-by: Stefan Weil <sw@weilnetz.de> | ||
6 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 5 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> |
7 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 6 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> |
8 | Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> | ||
9 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
10 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
11 | --- | 8 | --- |
12 | configure | 5 +++-- | 9 | tcg/optimize.c | 545 ++++++++++++++++++++++++++----------------------- |
13 | 1 file changed, 3 insertions(+), 2 deletions(-) | 10 | 1 file changed, 294 insertions(+), 251 deletions(-) |
14 | 11 | ||
15 | diff --git a/configure b/configure | 12 | diff --git a/tcg/optimize.c b/tcg/optimize.c |
16 | index XXXXXXX..XXXXXXX 100755 | 13 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/configure | 14 | --- a/tcg/optimize.c |
18 | +++ b/configure | 15 | +++ b/tcg/optimize.c |
19 | @@ -XXX,XX +XXX,XX @@ for opt do | 16 | @@ -XXX,XX +XXX,XX @@ typedef struct OptContext { |
20 | ;; | 17 | TCGTempSet temps_used; |
21 | --enable-whpx) whpx="enabled" | 18 | |
22 | ;; | 19 | /* In flight values from optimization. */ |
23 | - --disable-tcg-interpreter) tcg_interpreter="true" | 20 | - uint64_t z_mask; |
24 | + --disable-tcg-interpreter) tcg_interpreter="false" | 21 | + uint64_t a_mask; /* mask bit is 0 iff value identical to first input */ |
25 | ;; | 22 | + uint64_t z_mask; /* mask bit is 0 iff value bit is 0 */ |
26 | - --enable-tcg-interpreter) tcg_interpreter="false" | 23 | TCGType type; |
27 | + --enable-tcg-interpreter) tcg_interpreter="true" | 24 | } OptContext; |
28 | ;; | 25 | |
29 | --disable-cap-ng) cap_ng="disabled" | 26 | @@ -XXX,XX +XXX,XX @@ static bool fold_const2(OptContext *ctx, TCGOp *op) |
30 | ;; | 27 | return false; |
31 | @@ -XXX,XX +XXX,XX @@ NINJA=$ninja $meson setup \ | 28 | } |
32 | -Dvhost_user_blk_server=$vhost_user_blk_server \ | 29 | |
33 | -Dfuse=$fuse -Dfuse_lseek=$fuse_lseek -Dguest_agent_msi=$guest_agent_msi \ | 30 | +static bool fold_masks(OptContext *ctx, TCGOp *op) |
34 | $(if test "$default_features" = no; then echo "-Dauto_features=disabled"; fi) \ | 31 | +{ |
35 | + -Dtcg_interpreter=$tcg_interpreter \ | 32 | + uint64_t a_mask = ctx->a_mask; |
36 | $cross_arg \ | 33 | + uint64_t z_mask = ctx->z_mask; |
37 | "$PWD" "$source_path" | 34 | + |
38 | 35 | + /* | |
36 | + * 32-bit ops generate 32-bit results. For the result is zero test | ||
37 | + * below, we can ignore high bits, but for further optimizations we | ||
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 | { | ||
62 | + uint64_t z1, z2; | ||
63 | + | ||
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 | } | ||
86 | |||
87 | static bool fold_andc(OptContext *ctx, TCGOp *op) | ||
88 | { | ||
89 | + uint64_t z1; | ||
90 | + | ||
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 | } | ||
114 | |||
115 | static bool fold_brcond(OptContext *ctx, TCGOp *op) | ||
116 | @@ -XXX,XX +XXX,XX @@ static bool fold_brcond2(OptContext *ctx, TCGOp *op) | ||
117 | |||
118 | static bool fold_bswap(OptContext *ctx, TCGOp *op) | ||
119 | { | ||
120 | + uint64_t z_mask, sign; | ||
121 | + | ||
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 | } | ||
168 | |||
169 | static bool fold_call(OptContext *ctx, TCGOp *op) | ||
170 | @@ -XXX,XX +XXX,XX @@ static bool fold_call(OptContext *ctx, TCGOp *op) | ||
171 | |||
172 | static bool fold_count_zeros(OptContext *ctx, TCGOp *op) | ||
173 | { | ||
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; | ||
39 | -- | 763 | -- |
40 | 2.25.1 | 764 | 2.25.1 |
41 | 765 | ||
42 | 766 | diff view generated by jsdifflib |
1 | Tested-by: Alex Bennée <alex.bennee@linaro.org> | 1 | Rename to fold_multiply2, and handle muls2_i32, mulu2_i64, |
---|---|---|---|
2 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 2 | and muls2_i64. |
3 | |||
4 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | ||
5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
4 | --- | 7 | --- |
5 | tcg/tci.c | 9 ++------- | 8 | tcg/optimize.c | 44 +++++++++++++++++++++++++++++++++++--------- |
6 | 1 file changed, 2 insertions(+), 7 deletions(-) | 9 | 1 file changed, 35 insertions(+), 9 deletions(-) |
7 | 10 | ||
8 | diff --git a/tcg/tci.c b/tcg/tci.c | 11 | diff --git a/tcg/optimize.c b/tcg/optimize.c |
9 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
10 | --- a/tcg/tci.c | 13 | --- a/tcg/optimize.c |
11 | +++ b/tcg/tci.c | 14 | +++ b/tcg/optimize.c |
12 | @@ -XXX,XX +XXX,XX @@ tci_write_reg(tcg_target_ulong *regs, TCGReg index, tcg_target_ulong value) | 15 | @@ -XXX,XX +XXX,XX @@ static bool fold_mul_highpart(OptContext *ctx, TCGOp *op) |
13 | regs[index] = value; | 16 | return false; |
14 | } | 17 | } |
15 | 18 | ||
16 | -static void tci_write_reg8(tcg_target_ulong *regs, TCGReg index, uint8_t value) | 19 | -static bool fold_mulu2_i32(OptContext *ctx, TCGOp *op) |
17 | -{ | 20 | +static bool fold_multiply2(OptContext *ctx, TCGOp *op) |
18 | - tci_write_reg(regs, index, value); | 21 | { |
19 | -} | 22 | if (arg_is_const(op->args[2]) && arg_is_const(op->args[3])) { |
20 | - | 23 | - uint32_t a = arg_info(op->args[2])->val; |
21 | #if TCG_TARGET_REG_BITS == 64 | 24 | - uint32_t b = arg_info(op->args[3])->val; |
22 | static void | 25 | - uint64_t r = (uint64_t)a * b; |
23 | tci_write_reg16(tcg_target_ulong *regs, TCGReg index, uint16_t value) | 26 | + uint64_t a = arg_info(op->args[2])->val; |
24 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 27 | + uint64_t b = arg_info(op->args[3])->val; |
25 | t0 = *tb_ptr++; | 28 | + uint64_t h, l; |
26 | t1 = tci_read_r(regs, &tb_ptr); | 29 | TCGArg rl, rh; |
27 | t2 = tci_read_s32(&tb_ptr); | 30 | - TCGOp *op2 = tcg_op_insert_before(ctx->tcg, op, INDEX_op_mov_i32); |
28 | - tci_write_reg8(regs, t0, *(uint8_t *)(t1 + t2)); | 31 | + TCGOp *op2; |
29 | + tci_write_reg(regs, t0, *(uint8_t *)(t1 + t2)); | 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); | ||
30 | break; | 70 | break; |
31 | case INDEX_op_ld8s_i32: | 71 | - case INDEX_op_mulu2_i32: |
32 | TODO(); | 72 | - done = fold_mulu2_i32(&ctx, op); |
33 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 73 | + CASE_OP_32_64(muls2): |
34 | t0 = *tb_ptr++; | 74 | + CASE_OP_32_64(mulu2): |
35 | t1 = tci_read_r(regs, &tb_ptr); | 75 | + done = fold_multiply2(&ctx, op); |
36 | t2 = tci_read_s32(&tb_ptr); | ||
37 | - tci_write_reg8(regs, t0, *(uint8_t *)(t1 + t2)); | ||
38 | + tci_write_reg(regs, t0, *(uint8_t *)(t1 + t2)); | ||
39 | break; | 76 | break; |
40 | case INDEX_op_ld8s_i64: | 77 | CASE_OP_32_64(nand): |
41 | t0 = *tb_ptr++; | 78 | done = fold_nand(&ctx, op); |
42 | -- | 79 | -- |
43 | 2.25.1 | 80 | 2.25.1 |
44 | 81 | ||
45 | 82 | diff view generated by jsdifflib |
1 | From: Claudio Fontana <cfontana@suse.de> | 1 | Rename to fold_addsub2. |
---|---|---|---|
2 | 2 | Use Int128 to implement the wider operation. | |
3 | move away TCG-only code, make it compile only on TCG. | ||
4 | 3 | ||
5 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 4 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> |
6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 5 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> |
7 | [claudio: moved the prototypes from hw/core/cpu.h to exec/cpu-all.h] | 6 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
8 | Signed-off-by: Claudio Fontana <cfontana@suse.de> | ||
9 | Message-Id: <20210204163931.7358-4-cfontana@suse.de> | ||
10 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
11 | --- | 8 | --- |
12 | include/exec/cpu-all.h | 11 +++++-- | 9 | tcg/optimize.c | 65 ++++++++++++++++++++++++++++++++++---------------- |
13 | include/hw/core/cpu.h | 2 ++ | 10 | 1 file changed, 44 insertions(+), 21 deletions(-) |
14 | accel/tcg/cpu-exec.c | 28 +++++++++++++++++ | ||
15 | cpu.c | 70 ++++++++++++++++++++---------------------- | ||
16 | hw/core/cpu.c | 6 +++- | ||
17 | 5 files changed, 77 insertions(+), 40 deletions(-) | ||
18 | 11 | ||
19 | diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h | 12 | diff --git a/tcg/optimize.c b/tcg/optimize.c |
20 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/include/exec/cpu-all.h | 14 | --- a/tcg/optimize.c |
22 | +++ b/include/exec/cpu-all.h | 15 | +++ b/tcg/optimize.c |
23 | @@ -XXX,XX +XXX,XX @@ static inline bool tlb_hit(target_ulong tlb_addr, target_ulong addr) | 16 | @@ -XXX,XX +XXX,XX @@ |
17 | */ | ||
18 | |||
19 | #include "qemu/osdep.h" | ||
20 | +#include "qemu/int128.h" | ||
21 | #include "tcg/tcg-op.h" | ||
22 | #include "tcg-internal.h" | ||
23 | |||
24 | @@ -XXX,XX +XXX,XX @@ static bool fold_add(OptContext *ctx, TCGOp *op) | ||
25 | return false; | ||
24 | } | 26 | } |
25 | 27 | ||
26 | #ifdef CONFIG_TCG | 28 | -static bool fold_addsub2_i32(OptContext *ctx, TCGOp *op, bool add) |
27 | +/* accel/tcg/cpu-exec.c */ | 29 | +static bool fold_addsub2(OptContext *ctx, TCGOp *op, bool add) |
28 | void dump_drift_info(void); | 30 | { |
29 | +/* accel/tcg/translate-all.c */ | 31 | if (arg_is_const(op->args[2]) && arg_is_const(op->args[3]) && |
30 | void dump_exec_info(void); | 32 | arg_is_const(op->args[4]) && arg_is_const(op->args[5])) { |
31 | void dump_opcount_info(void); | 33 | - uint32_t al = arg_info(op->args[2])->val; |
32 | #endif /* CONFIG_TCG */ | 34 | - uint32_t ah = arg_info(op->args[3])->val; |
33 | 35 | - uint32_t bl = arg_info(op->args[4])->val; | |
34 | #endif /* !CONFIG_USER_ONLY */ | 36 | - uint32_t bh = arg_info(op->args[5])->val; |
35 | 37 | - uint64_t a = ((uint64_t)ah << 32) | al; | |
36 | +#ifdef CONFIG_TCG | 38 | - uint64_t b = ((uint64_t)bh << 32) | bl; |
37 | +/* accel/tcg/cpu-exec.c */ | 39 | + uint64_t al = arg_info(op->args[2])->val; |
38 | +int cpu_exec(CPUState *cpu); | 40 | + uint64_t ah = arg_info(op->args[3])->val; |
39 | +void tcg_exec_realizefn(CPUState *cpu, Error **errp); | 41 | + uint64_t bl = arg_info(op->args[4])->val; |
40 | +void tcg_exec_unrealizefn(CPUState *cpu); | 42 | + uint64_t bh = arg_info(op->args[5])->val; |
41 | +#endif /* CONFIG_TCG */ | 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); | ||
42 | + | 52 | + |
43 | /* Returns: 0 on success, -1 on error */ | 53 | + if (add) { |
44 | int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr, | 54 | + a += b; |
45 | void *ptr, target_ulong len, bool is_write); | 55 | + } else { |
46 | 56 | + a -= b; | |
47 | -int cpu_exec(CPUState *cpu); | 57 | + } |
48 | - | ||
49 | /** | ||
50 | * cpu_set_cpustate_pointers(cpu) | ||
51 | * @cpu: The cpu object | ||
52 | diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h | ||
53 | index XXXXXXX..XXXXXXX 100644 | ||
54 | --- a/include/hw/core/cpu.h | ||
55 | +++ b/include/hw/core/cpu.h | ||
56 | @@ -XXX,XX +XXX,XX @@ AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx); | ||
57 | |||
58 | void QEMU_NORETURN cpu_abort(CPUState *cpu, const char *fmt, ...) | ||
59 | GCC_FMT_ATTR(2, 3); | ||
60 | + | 58 | + |
61 | +/* $(top_srcdir)/cpu.c */ | 59 | + al = sextract64(a, 0, 32); |
62 | void cpu_exec_initfn(CPUState *cpu); | 60 | + ah = sextract64(a, 32, 32); |
63 | void cpu_exec_realizefn(CPUState *cpu, Error **errp); | 61 | } else { |
64 | void cpu_exec_unrealizefn(CPUState *cpu); | 62 | - a -= b; |
65 | diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c | 63 | + Int128 a = int128_make128(al, ah); |
66 | index XXXXXXX..XXXXXXX 100644 | 64 | + Int128 b = int128_make128(bl, bh); |
67 | --- a/accel/tcg/cpu-exec.c | 65 | + |
68 | +++ b/accel/tcg/cpu-exec.c | 66 | + if (add) { |
69 | @@ -XXX,XX +XXX,XX @@ int cpu_exec(CPUState *cpu) | 67 | + a = int128_add(a, b); |
70 | return ret; | 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; | ||
71 | } | 89 | } |
72 | 90 | ||
73 | +void tcg_exec_realizefn(CPUState *cpu, Error **errp) | 91 | -static bool fold_add2_i32(OptContext *ctx, TCGOp *op) |
74 | +{ | 92 | +static bool fold_add2(OptContext *ctx, TCGOp *op) |
75 | + static bool tcg_target_initialized; | ||
76 | + CPUClass *cc = CPU_GET_CLASS(cpu); | ||
77 | + | ||
78 | + if (!tcg_target_initialized) { | ||
79 | + cc->tcg_ops.initialize(); | ||
80 | + tcg_target_initialized = true; | ||
81 | + } | ||
82 | + tlb_init(cpu); | ||
83 | + qemu_plugin_vcpu_init_hook(cpu); | ||
84 | + | ||
85 | +#ifndef CONFIG_USER_ONLY | ||
86 | + tcg_iommu_init_notifier_list(cpu); | ||
87 | +#endif /* !CONFIG_USER_ONLY */ | ||
88 | +} | ||
89 | + | ||
90 | +/* undo the initializations in reverse order */ | ||
91 | +void tcg_exec_unrealizefn(CPUState *cpu) | ||
92 | +{ | ||
93 | +#ifndef CONFIG_USER_ONLY | ||
94 | + tcg_iommu_free_notifier_list(cpu); | ||
95 | +#endif /* !CONFIG_USER_ONLY */ | ||
96 | + | ||
97 | + qemu_plugin_vcpu_exit_hook(cpu); | ||
98 | + tlb_destroy(cpu); | ||
99 | +} | ||
100 | + | ||
101 | #ifndef CONFIG_USER_ONLY | ||
102 | |||
103 | void dump_drift_info(void) | ||
104 | diff --git a/cpu.c b/cpu.c | ||
105 | index XXXXXXX..XXXXXXX 100644 | ||
106 | --- a/cpu.c | ||
107 | +++ b/cpu.c | ||
108 | @@ -XXX,XX +XXX,XX @@ const VMStateDescription vmstate_cpu_common = { | ||
109 | }; | ||
110 | #endif | ||
111 | |||
112 | -void cpu_exec_unrealizefn(CPUState *cpu) | ||
113 | +void cpu_exec_realizefn(CPUState *cpu, Error **errp) | ||
114 | { | 93 | { |
115 | CPUClass *cc = CPU_GET_CLASS(cpu); | 94 | - return fold_addsub2_i32(ctx, op, true); |
116 | 95 | + return fold_addsub2(ctx, op, true); | |
117 | - tlb_destroy(cpu); | ||
118 | - cpu_list_remove(cpu); | ||
119 | + cpu_list_add(cpu); | ||
120 | + | ||
121 | +#ifdef CONFIG_TCG | ||
122 | + /* NB: errp parameter is unused currently */ | ||
123 | + if (tcg_enabled()) { | ||
124 | + tcg_exec_realizefn(cpu, errp); | ||
125 | + } | ||
126 | +#endif /* CONFIG_TCG */ | ||
127 | + | ||
128 | +#ifdef CONFIG_USER_ONLY | ||
129 | + assert(cc->vmsd == NULL); | ||
130 | +#else | ||
131 | + if (qdev_get_vmsd(DEVICE(cpu)) == NULL) { | ||
132 | + vmstate_register(NULL, cpu->cpu_index, &vmstate_cpu_common, cpu); | ||
133 | + } | ||
134 | + if (cc->vmsd != NULL) { | ||
135 | + vmstate_register(NULL, cpu->cpu_index, cc->vmsd, cpu); | ||
136 | + } | ||
137 | +#endif /* CONFIG_USER_ONLY */ | ||
138 | +} | ||
139 | + | ||
140 | +void cpu_exec_unrealizefn(CPUState *cpu) | ||
141 | +{ | ||
142 | + CPUClass *cc = CPU_GET_CLASS(cpu); | ||
143 | |||
144 | #ifdef CONFIG_USER_ONLY | ||
145 | assert(cc->vmsd == NULL); | ||
146 | @@ -XXX,XX +XXX,XX @@ void cpu_exec_unrealizefn(CPUState *cpu) | ||
147 | if (qdev_get_vmsd(DEVICE(cpu)) == NULL) { | ||
148 | vmstate_unregister(NULL, &vmstate_cpu_common, cpu); | ||
149 | } | ||
150 | - tcg_iommu_free_notifier_list(cpu); | ||
151 | #endif | ||
152 | +#ifdef CONFIG_TCG | ||
153 | + /* NB: errp parameter is unused currently */ | ||
154 | + if (tcg_enabled()) { | ||
155 | + tcg_exec_unrealizefn(cpu); | ||
156 | + } | ||
157 | +#endif /* CONFIG_TCG */ | ||
158 | + | ||
159 | + cpu_list_remove(cpu); | ||
160 | } | 96 | } |
161 | 97 | ||
162 | void cpu_exec_initfn(CPUState *cpu) | 98 | static bool fold_and(OptContext *ctx, TCGOp *op) |
163 | @@ -XXX,XX +XXX,XX @@ void cpu_exec_initfn(CPUState *cpu) | 99 | @@ -XXX,XX +XXX,XX @@ static bool fold_sub(OptContext *ctx, TCGOp *op) |
164 | #endif | 100 | return false; |
165 | } | 101 | } |
166 | 102 | ||
167 | -void cpu_exec_realizefn(CPUState *cpu, Error **errp) | 103 | -static bool fold_sub2_i32(OptContext *ctx, TCGOp *op) |
168 | -{ | 104 | +static bool fold_sub2(OptContext *ctx, TCGOp *op) |
169 | - CPUClass *cc = CPU_GET_CLASS(cpu); | ||
170 | -#ifdef CONFIG_TCG | ||
171 | - static bool tcg_target_initialized; | ||
172 | -#endif /* CONFIG_TCG */ | ||
173 | - | ||
174 | - cpu_list_add(cpu); | ||
175 | - | ||
176 | -#ifdef CONFIG_TCG | ||
177 | - if (tcg_enabled() && !tcg_target_initialized) { | ||
178 | - tcg_target_initialized = true; | ||
179 | - cc->tcg_ops.initialize(); | ||
180 | - } | ||
181 | -#endif /* CONFIG_TCG */ | ||
182 | - tlb_init(cpu); | ||
183 | - | ||
184 | - qemu_plugin_vcpu_init_hook(cpu); | ||
185 | - | ||
186 | -#ifdef CONFIG_USER_ONLY | ||
187 | - assert(cc->vmsd == NULL); | ||
188 | -#else /* !CONFIG_USER_ONLY */ | ||
189 | - if (qdev_get_vmsd(DEVICE(cpu)) == NULL) { | ||
190 | - vmstate_register(NULL, cpu->cpu_index, &vmstate_cpu_common, cpu); | ||
191 | - } | ||
192 | - if (cc->vmsd != NULL) { | ||
193 | - vmstate_register(NULL, cpu->cpu_index, cc->vmsd, cpu); | ||
194 | - } | ||
195 | - | ||
196 | - tcg_iommu_init_notifier_list(cpu); | ||
197 | -#endif | ||
198 | -} | ||
199 | - | ||
200 | const char *parse_cpu_option(const char *cpu_option) | ||
201 | { | 105 | { |
202 | ObjectClass *oc; | 106 | - return fold_addsub2_i32(ctx, op, false); |
203 | diff --git a/hw/core/cpu.c b/hw/core/cpu.c | 107 | + return fold_addsub2(ctx, op, false); |
204 | index XXXXXXX..XXXXXXX 100644 | ||
205 | --- a/hw/core/cpu.c | ||
206 | +++ b/hw/core/cpu.c | ||
207 | @@ -XXX,XX +XXX,XX @@ static bool cpu_common_virtio_is_big_endian(CPUState *cpu) | ||
208 | return target_words_bigendian(); | ||
209 | } | 108 | } |
210 | 109 | ||
211 | +/* | 110 | static bool fold_tcg_ld(OptContext *ctx, TCGOp *op) |
212 | + * XXX the following #if is always true because this is a common_ss | 111 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) |
213 | + * module, so target CONFIG_* is never defined. | 112 | CASE_OP_32_64_VEC(add): |
214 | + */ | 113 | done = fold_add(&ctx, op); |
215 | #if !defined(CONFIG_USER_ONLY) | 114 | break; |
216 | GuestPanicInformation *cpu_get_crash_info(CPUState *cpu) | 115 | - case INDEX_op_add2_i32: |
217 | { | 116 | - done = fold_add2_i32(&ctx, op); |
218 | @@ -XXX,XX +XXX,XX @@ static void cpu_common_realizefn(DeviceState *dev, Error **errp) | 117 | + CASE_OP_32_64(add2): |
219 | static void cpu_common_unrealizefn(DeviceState *dev) | 118 | + done = fold_add2(&ctx, op); |
220 | { | 119 | break; |
221 | CPUState *cpu = CPU(dev); | 120 | CASE_OP_32_64_VEC(and): |
222 | + | 121 | done = fold_and(&ctx, op); |
223 | /* NOTE: latest generic point before the cpu is fully unrealized */ | 122 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) |
224 | trace_fini_vcpu(cpu); | 123 | CASE_OP_32_64_VEC(sub): |
225 | - qemu_plugin_vcpu_exit_hook(cpu); | 124 | done = fold_sub(&ctx, op); |
226 | cpu_exec_unrealizefn(cpu); | 125 | break; |
227 | } | 126 | - case INDEX_op_sub2_i32: |
228 | 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); | ||
229 | -- | 133 | -- |
230 | 2.25.1 | 134 | 2.25.1 |
231 | 135 | ||
232 | 136 | diff view generated by jsdifflib |
1 | From: Claudio Fontana <cfontana@suse.de> | 1 | Most of these are handled by creating a fold_const2_commutative |
---|---|---|---|
2 | 2 | to handle all of the binary operators. The rest were already | |
3 | add a new optional interface to CPUClass, which allows accelerators | 3 | handled on a case-by-case basis in the switch, and have their |
4 | to extend the CPUClass with additional accelerator-specific | 4 | own fold function in which to place the call. |
5 | initializations. | 5 | |
6 | 6 | We now have only one major switch on TCGOpcode. | |
7 | This will allow to separate the target cpu code that is specific | 7 | |
8 | to each accelerator, and register it automatically with object | 8 | Introduce NO_DEST and a block comment for swap_commutative in |
9 | hierarchy lookup depending on accelerator code availability, | 9 | order to make the handling of brcond and movcond opcodes cleaner. |
10 | as part of the accel_init_interfaces() initialization step. | 10 | |
11 | 11 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | |
12 | Signed-off-by: Claudio Fontana <cfontana@suse.de> | ||
13 | Message-Id: <20210204163931.7358-19-cfontana@suse.de> | ||
14 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 12 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
15 | --- | 13 | --- |
16 | include/hw/core/accel-cpu.h | 38 ++++++++++++++++++++++++++++++++ | 14 | tcg/optimize.c | 142 ++++++++++++++++++++++++------------------------- |
17 | include/hw/core/cpu.h | 4 ++++ | 15 | 1 file changed, 70 insertions(+), 72 deletions(-) |
18 | accel/accel-common.c | 44 +++++++++++++++++++++++++++++++++++++ | 16 | |
19 | MAINTAINERS | 1 + | 17 | diff --git a/tcg/optimize.c b/tcg/optimize.c |
20 | 4 files changed, 87 insertions(+) | 18 | index XXXXXXX..XXXXXXX 100644 |
21 | create mode 100644 include/hw/core/accel-cpu.h | 19 | --- a/tcg/optimize.c |
22 | 20 | +++ b/tcg/optimize.c | |
23 | diff --git a/include/hw/core/accel-cpu.h b/include/hw/core/accel-cpu.h | 21 | @@ -XXX,XX +XXX,XX @@ static int do_constant_folding_cond2(TCGArg *p1, TCGArg *p2, TCGCond c) |
24 | new file mode 100644 | 22 | return -1; |
25 | index XXXXXXX..XXXXXXX | 23 | } |
26 | --- /dev/null | 24 | |
27 | +++ b/include/hw/core/accel-cpu.h | 25 | +/** |
28 | @@ -XXX,XX +XXX,XX @@ | 26 | + * swap_commutative: |
29 | +/* | 27 | + * @dest: TCGArg of the destination argument, or NO_DEST. |
30 | + * Accelerator interface, specializes CPUClass | 28 | + * @p1: first paired argument |
31 | + * This header is used only by target-specific code. | 29 | + * @p2: second paired argument |
32 | + * | 30 | + * |
33 | + * Copyright 2021 SUSE LLC | 31 | + * If *@p1 is a constant and *@p2 is not, swap. |
34 | + * | 32 | + * If *@p2 matches @dest, swap. |
35 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | 33 | + * Return true if a swap was performed. |
36 | + * See the COPYING file in the top-level directory. | ||
37 | + */ | 34 | + */ |
38 | + | 35 | + |
39 | +#ifndef ACCEL_CPU_H | 36 | +#define NO_DEST temp_arg(NULL) |
40 | +#define ACCEL_CPU_H | 37 | + |
41 | + | 38 | static bool swap_commutative(TCGArg dest, TCGArg *p1, TCGArg *p2) |
42 | +/* | 39 | { |
43 | + * This header is used to define new accelerator-specific target-specific | 40 | TCGArg a1 = *p1, a2 = *p2; |
44 | + * accelerator cpu subclasses. | 41 | @@ -XXX,XX +XXX,XX @@ static bool fold_const2(OptContext *ctx, TCGOp *op) |
45 | + * It uses CPU_RESOLVING_TYPE, so this is clearly target-specific. | 42 | return false; |
46 | + * | ||
47 | + * Do not try to use for any other purpose than the implementation of new | ||
48 | + * subclasses in target/, or the accel implementation itself in accel/ | ||
49 | + */ | ||
50 | + | ||
51 | +#define TYPE_ACCEL_CPU "accel-" CPU_RESOLVING_TYPE | ||
52 | +#define ACCEL_CPU_NAME(name) (name "-" TYPE_ACCEL_CPU) | ||
53 | +typedef struct AccelCPUClass AccelCPUClass; | ||
54 | +DECLARE_CLASS_CHECKERS(AccelCPUClass, ACCEL_CPU, TYPE_ACCEL_CPU) | ||
55 | + | ||
56 | +typedef struct AccelCPUClass { | ||
57 | + /*< private >*/ | ||
58 | + ObjectClass parent_class; | ||
59 | + /*< public >*/ | ||
60 | + | ||
61 | + void (*cpu_class_init)(CPUClass *cc); | ||
62 | + void (*cpu_instance_init)(CPUState *cpu); | ||
63 | + void (*cpu_realizefn)(CPUState *cpu, Error **errp); | ||
64 | +} AccelCPUClass; | ||
65 | + | ||
66 | +#endif /* ACCEL_CPU_H */ | ||
67 | diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h | ||
68 | index XXXXXXX..XXXXXXX 100644 | ||
69 | --- a/include/hw/core/cpu.h | ||
70 | +++ b/include/hw/core/cpu.h | ||
71 | @@ -XXX,XX +XXX,XX @@ struct TranslationBlock; | ||
72 | /* see tcg-cpu-ops.h */ | ||
73 | struct TCGCPUOps; | ||
74 | |||
75 | +/* see accel-cpu.h */ | ||
76 | +struct AccelCPUClass; | ||
77 | + | ||
78 | /** | ||
79 | * CPUClass: | ||
80 | * @class_by_name: Callback to map -cpu command line model name to an | ||
81 | @@ -XXX,XX +XXX,XX @@ struct CPUClass { | ||
82 | /* Keep non-pointer data at the end to minimize holes. */ | ||
83 | int gdb_num_core_regs; | ||
84 | bool gdb_stop_before_watchpoint; | ||
85 | + struct AccelCPUClass *accel_cpu; | ||
86 | |||
87 | /* when TCG is not available, this pointer is NULL */ | ||
88 | struct TCGCPUOps *tcg_ops; | ||
89 | diff --git a/accel/accel-common.c b/accel/accel-common.c | ||
90 | index XXXXXXX..XXXXXXX 100644 | ||
91 | --- a/accel/accel-common.c | ||
92 | +++ b/accel/accel-common.c | ||
93 | @@ -XXX,XX +XXX,XX @@ | ||
94 | #include "qemu/osdep.h" | ||
95 | #include "qemu/accel.h" | ||
96 | |||
97 | +#include "cpu.h" | ||
98 | +#include "hw/core/accel-cpu.h" | ||
99 | + | ||
100 | #ifndef CONFIG_USER_ONLY | ||
101 | #include "accel-softmmu.h" | ||
102 | #endif /* !CONFIG_USER_ONLY */ | ||
103 | @@ -XXX,XX +XXX,XX @@ AccelClass *accel_find(const char *opt_name) | ||
104 | return ac; | ||
105 | } | 43 | } |
106 | 44 | ||
107 | +static void accel_init_cpu_int_aux(ObjectClass *klass, void *opaque) | 45 | +static bool fold_const2_commutative(OptContext *ctx, TCGOp *op) |
108 | +{ | 46 | +{ |
109 | + CPUClass *cc = CPU_CLASS(klass); | 47 | + swap_commutative(op->args[0], &op->args[1], &op->args[2]); |
110 | + AccelCPUClass *accel_cpu = opaque; | 48 | + return fold_const2(ctx, op); |
111 | + | ||
112 | + cc->accel_cpu = accel_cpu; | ||
113 | + if (accel_cpu->cpu_class_init) { | ||
114 | + accel_cpu->cpu_class_init(cc); | ||
115 | + } | ||
116 | +} | 49 | +} |
117 | + | 50 | + |
118 | +/* initialize the arch-specific accel CpuClass interfaces */ | 51 | static bool fold_masks(OptContext *ctx, TCGOp *op) |
119 | +static void accel_init_cpu_interfaces(AccelClass *ac) | 52 | { |
120 | +{ | 53 | uint64_t a_mask = ctx->a_mask; |
121 | + const char *ac_name; /* AccelClass name */ | 54 | @@ -XXX,XX +XXX,XX @@ static bool fold_xx_to_x(OptContext *ctx, TCGOp *op) |
122 | + char *acc_name; /* AccelCPUClass name */ | 55 | |
123 | + ObjectClass *acc; /* AccelCPUClass */ | 56 | static bool fold_add(OptContext *ctx, TCGOp *op) |
124 | + | 57 | { |
125 | + ac_name = object_class_get_name(OBJECT_CLASS(ac)); | 58 | - if (fold_const2(ctx, op) || |
126 | + g_assert(ac_name != NULL); | 59 | + if (fold_const2_commutative(ctx, op) || |
127 | + | 60 | fold_xi_to_x(ctx, op, 0)) { |
128 | + acc_name = g_strdup_printf("%s-%s", ac_name, CPU_RESOLVING_TYPE); | 61 | return true; |
129 | + acc = object_class_by_name(acc_name); | 62 | } |
130 | + g_free(acc_name); | 63 | @@ -XXX,XX +XXX,XX @@ static bool fold_addsub2(OptContext *ctx, TCGOp *op, bool add) |
131 | + | 64 | |
132 | + if (acc) { | 65 | static bool fold_add2(OptContext *ctx, TCGOp *op) |
133 | + object_class_foreach(accel_init_cpu_int_aux, | 66 | { |
134 | + CPU_RESOLVING_TYPE, false, acc); | 67 | + /* Note that the high and low parts may be independently swapped. */ |
135 | + } | 68 | + swap_commutative(op->args[0], &op->args[2], &op->args[4]); |
136 | +} | 69 | + swap_commutative(op->args[1], &op->args[3], &op->args[5]); |
137 | + | 70 | + |
138 | void accel_init_interfaces(AccelClass *ac) | 71 | return fold_addsub2(ctx, op, true); |
139 | { | ||
140 | #ifndef CONFIG_USER_ONLY | ||
141 | accel_init_ops_interfaces(ac); | ||
142 | #endif /* !CONFIG_USER_ONLY */ | ||
143 | + | ||
144 | + accel_init_cpu_interfaces(ac); | ||
145 | } | 72 | } |
146 | 73 | ||
147 | +static const TypeInfo accel_cpu_type = { | 74 | @@ -XXX,XX +XXX,XX @@ static bool fold_and(OptContext *ctx, TCGOp *op) |
148 | + .name = TYPE_ACCEL_CPU, | 75 | { |
149 | + .parent = TYPE_OBJECT, | 76 | uint64_t z1, z2; |
150 | + .abstract = true, | 77 | |
151 | + .class_size = sizeof(AccelCPUClass), | 78 | - if (fold_const2(ctx, op) || |
152 | +}; | 79 | + if (fold_const2_commutative(ctx, op) || |
153 | + | 80 | fold_xi_to_i(ctx, op, 0) || |
154 | static void register_accel_types(void) | 81 | fold_xi_to_x(ctx, op, -1) || |
155 | { | 82 | fold_xx_to_x(ctx, op)) { |
156 | type_register_static(&accel_type); | 83 | @@ -XXX,XX +XXX,XX @@ static bool fold_andc(OptContext *ctx, TCGOp *op) |
157 | + type_register_static(&accel_cpu_type); | 84 | static bool fold_brcond(OptContext *ctx, TCGOp *op) |
158 | } | 85 | { |
159 | 86 | TCGCond cond = op->args[2]; | |
160 | type_init(register_accel_types); | 87 | - int i = do_constant_folding_cond(ctx->type, op->args[0], op->args[1], cond); |
161 | diff --git a/MAINTAINERS b/MAINTAINERS | 88 | + int i; |
162 | index XXXXXXX..XXXXXXX 100644 | 89 | |
163 | --- a/MAINTAINERS | 90 | + if (swap_commutative(NO_DEST, &op->args[0], &op->args[1])) { |
164 | +++ b/MAINTAINERS | 91 | + op->args[2] = cond = tcg_swap_cond(cond); |
165 | @@ -XXX,XX +XXX,XX @@ R: Paolo Bonzini <pbonzini@redhat.com> | 92 | + } |
166 | S: Maintained | 93 | + |
167 | F: include/qemu/accel.h | 94 | + i = do_constant_folding_cond(ctx->type, op->args[0], op->args[1], cond); |
168 | F: include/sysemu/accel-ops.h | 95 | if (i == 0) { |
169 | +F: include/hw/core/accel-cpu.h | 96 | tcg_op_remove(ctx->tcg, op); |
170 | F: accel/accel-*.c | 97 | return true; |
171 | F: accel/Makefile.objs | 98 | @@ -XXX,XX +XXX,XX @@ static bool fold_brcond(OptContext *ctx, TCGOp *op) |
172 | F: accel/stubs/Makefile.objs | 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; | ||
173 | -- | 295 | -- |
174 | 2.25.1 | 296 | 2.25.1 |
175 | 297 | ||
176 | 298 | diff view generated by jsdifflib |
1 | This was removed from tcg_target_reg_alloc_order and | 1 | This "garbage" setting pre-dates the addition of the type |
---|---|---|---|
2 | tcg_target_call_iarg_regs on the assumption that it | 2 | changing opcodes INDEX_op_ext_i32_i64, INDEX_op_extu_i32_i64, |
3 | was the stack. This was incorrectly copied from i386. | 3 | and INDEX_op_extr{l,h}_i64_i32. |
4 | For tci, the stack is R15. | ||
5 | 4 | ||
6 | By adding R4 back to tcg_target_call_iarg_regs, adjust the other | 5 | So now we have a definitive points at which to adjust z_mask |
7 | entries so that 6 (or 12) entries are still present in the array, | 6 | to eliminate such bits from the 32-bit operands. |
8 | and adjust the numbers in the interpreter. | ||
9 | 7 | ||
10 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 8 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> |
9 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | ||
11 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 10 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
12 | --- | 11 | --- |
13 | tcg/tci.c | 8 ++++---- | 12 | tcg/optimize.c | 35 ++++++++++++++++------------------- |
14 | tcg/tci/tcg-target.c.inc | 7 +------ | 13 | 1 file changed, 16 insertions(+), 19 deletions(-) |
15 | 2 files changed, 5 insertions(+), 10 deletions(-) | ||
16 | 14 | ||
17 | diff --git a/tcg/tci.c b/tcg/tci.c | 15 | diff --git a/tcg/optimize.c b/tcg/optimize.c |
18 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/tcg/tci.c | 17 | --- a/tcg/optimize.c |
20 | +++ b/tcg/tci.c | 18 | +++ b/tcg/optimize.c |
21 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 19 | @@ -XXX,XX +XXX,XX @@ static void init_ts_info(OptContext *ctx, TCGTemp *ts) |
22 | tci_read_reg(regs, TCG_REG_R1), | 20 | ti->is_const = true; |
23 | tci_read_reg(regs, TCG_REG_R2), | 21 | ti->val = ts->val; |
24 | tci_read_reg(regs, TCG_REG_R3), | 22 | ti->z_mask = ts->val; |
25 | + tci_read_reg(regs, TCG_REG_R4), | 23 | - if (TCG_TARGET_REG_BITS > 32 && ts->type == TCG_TYPE_I32) { |
26 | tci_read_reg(regs, TCG_REG_R5), | 24 | - /* High bits of a 32-bit quantity are garbage. */ |
27 | tci_read_reg(regs, TCG_REG_R6), | 25 | - ti->z_mask |= ~0xffffffffull; |
28 | tci_read_reg(regs, TCG_REG_R7), | 26 | - } |
29 | tci_read_reg(regs, TCG_REG_R8), | 27 | } else { |
30 | tci_read_reg(regs, TCG_REG_R9), | 28 | ti->is_const = false; |
31 | tci_read_reg(regs, TCG_REG_R10), | 29 | ti->z_mask = -1; |
32 | - tci_read_reg(regs, TCG_REG_R11), | 30 | @@ -XXX,XX +XXX,XX @@ static bool tcg_opt_gen_mov(OptContext *ctx, TCGOp *op, TCGArg dst, TCGArg src) |
33 | - tci_read_reg(regs, TCG_REG_R12)); | 31 | TCGTemp *src_ts = arg_temp(src); |
34 | + tci_read_reg(regs, TCG_REG_R11)); | 32 | TempOptInfo *di; |
35 | tci_write_reg(regs, TCG_REG_R0, tmp64); | 33 | TempOptInfo *si; |
36 | tci_write_reg(regs, TCG_REG_R1, tmp64 >> 32); | 34 | - uint64_t z_mask; |
37 | #else | 35 | TCGOpcode new_op; |
38 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 36 | |
39 | tci_read_reg(regs, TCG_REG_R1), | 37 | if (ts_are_copies(dst_ts, src_ts)) { |
40 | tci_read_reg(regs, TCG_REG_R2), | 38 | @@ -XXX,XX +XXX,XX @@ static bool tcg_opt_gen_mov(OptContext *ctx, TCGOp *op, TCGArg dst, TCGArg src) |
41 | tci_read_reg(regs, TCG_REG_R3), | 39 | op->args[0] = dst; |
42 | - tci_read_reg(regs, TCG_REG_R5), | 40 | op->args[1] = src; |
43 | - tci_read_reg(regs, TCG_REG_R6)); | 41 | |
44 | + tci_read_reg(regs, TCG_REG_R4), | 42 | - z_mask = si->z_mask; |
45 | + tci_read_reg(regs, TCG_REG_R5)); | 43 | - if (TCG_TARGET_REG_BITS > 32 && new_op == INDEX_op_mov_i32) { |
46 | tci_write_reg(regs, TCG_REG_R0, tmp64); | 44 | - /* High bits of the destination are now garbage. */ |
47 | #endif | 45 | - z_mask |= ~0xffffffffull; |
48 | break; | 46 | - } |
49 | diff --git a/tcg/tci/tcg-target.c.inc b/tcg/tci/tcg-target.c.inc | 47 | - di->z_mask = z_mask; |
50 | index XXXXXXX..XXXXXXX 100644 | 48 | + di->z_mask = si->z_mask; |
51 | --- a/tcg/tci/tcg-target.c.inc | 49 | |
52 | +++ b/tcg/tci/tcg-target.c.inc | 50 | if (src_ts->type == dst_ts->type) { |
53 | @@ -XXX,XX +XXX,XX @@ static const int tcg_target_reg_alloc_order[] = { | 51 | TempOptInfo *ni = ts_info(si->next_copy); |
54 | TCG_REG_R1, | 52 | @@ -XXX,XX +XXX,XX @@ static bool tcg_opt_gen_mov(OptContext *ctx, TCGOp *op, TCGArg dst, TCGArg src) |
55 | TCG_REG_R2, | 53 | static bool tcg_opt_gen_movi(OptContext *ctx, TCGOp *op, |
56 | TCG_REG_R3, | 54 | TCGArg dst, uint64_t val) |
57 | -#if 0 /* used for TCG_REG_CALL_STACK */ | 55 | { |
58 | TCG_REG_R4, | 56 | - /* Convert movi to mov with constant temp. */ |
59 | -#endif | 57 | - TCGTemp *tv = tcg_constant_internal(ctx->type, val); |
60 | TCG_REG_R5, | 58 | + TCGTemp *tv; |
61 | TCG_REG_R6, | 59 | |
62 | TCG_REG_R7, | 60 | + if (ctx->type == TCG_TYPE_I32) { |
63 | @@ -XXX,XX +XXX,XX @@ static const int tcg_target_call_iarg_regs[] = { | 61 | + val = (int32_t)val; |
64 | TCG_REG_R1, | 62 | + } |
65 | TCG_REG_R2, | 63 | + |
66 | TCG_REG_R3, | 64 | + /* Convert movi to mov with constant temp. */ |
67 | -#if 0 /* used for TCG_REG_CALL_STACK */ | 65 | + tv = tcg_constant_internal(ctx->type, val); |
68 | TCG_REG_R4, | 66 | init_ts_info(ctx, tv); |
69 | -#endif | 67 | return tcg_opt_gen_mov(ctx, op, dst, temp_arg(tv)); |
70 | TCG_REG_R5, | 68 | } |
71 | - TCG_REG_R6, | 69 | @@ -XXX,XX +XXX,XX @@ static bool fold_masks(OptContext *ctx, TCGOp *op) |
72 | #if TCG_TARGET_REG_BITS == 32 | 70 | uint64_t z_mask = ctx->z_mask; |
73 | /* 32 bit hosts need 2 * MAX_OPC_PARAM_IARGS registers. */ | 71 | |
74 | + TCG_REG_R6, | 72 | /* |
75 | TCG_REG_R7, | 73 | - * 32-bit ops generate 32-bit results. For the result is zero test |
76 | TCG_REG_R8, | 74 | - * below, we can ignore high bits, but for further optimizations we |
77 | TCG_REG_R9, | 75 | - * need to record that the high bits contain garbage. |
78 | TCG_REG_R10, | 76 | + * 32-bit ops generate 32-bit results, which for the purpose of |
79 | TCG_REG_R11, | 77 | + * simplifying tcg are sign-extended. Certainly that's how we |
80 | - TCG_REG_R12, | 78 | + * represent our constants elsewhere. Note that the bits will |
81 | #endif | 79 | + * be reset properly for a 64-bit value when encountering the |
82 | }; | 80 | + * type changing opcodes. |
83 | 81 | */ | |
82 | if (ctx->type == TCG_TYPE_I32) { | ||
83 | - ctx->z_mask |= MAKE_64BIT_MASK(32, 32); | ||
84 | - a_mask &= MAKE_64BIT_MASK(0, 32); | ||
85 | - z_mask &= MAKE_64BIT_MASK(0, 32); | ||
86 | + a_mask = (int32_t)a_mask; | ||
87 | + z_mask = (int32_t)z_mask; | ||
88 | + ctx->z_mask = z_mask; | ||
89 | } | ||
90 | |||
91 | if (z_mask == 0) { | ||
84 | -- | 92 | -- |
85 | 2.25.1 | 93 | 2.25.1 |
86 | 94 | ||
87 | 95 | diff view generated by jsdifflib |
1 | Each thread must have its own pc, even under TCI. | 1 | Recognize the constant function for or-complement. |
---|---|---|---|
2 | |||
3 | Remove the GETPC ifdef, because GETPC is always available for | ||
4 | helpers, and thus is always required. Move the assignment | ||
5 | under INDEX_op_call, because the value is only visible when | ||
6 | we make a call to a helper function. | ||
7 | 2 | ||
8 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 3 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> |
4 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | ||
5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
9 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
10 | Message-Id: <20210204014509.882821-6-richard.henderson@linaro.org> | ||
11 | --- | 7 | --- |
12 | include/exec/exec-all.h | 2 +- | 8 | tcg/optimize.c | 1 + |
13 | tcg/tcg-common.c | 4 ---- | 9 | 1 file changed, 1 insertion(+) |
14 | tcg/tci.c | 7 +++---- | ||
15 | 3 files changed, 4 insertions(+), 9 deletions(-) | ||
16 | 10 | ||
17 | diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h | 11 | diff --git a/tcg/optimize.c b/tcg/optimize.c |
18 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/include/exec/exec-all.h | 13 | --- a/tcg/optimize.c |
20 | +++ b/include/exec/exec-all.h | 14 | +++ b/tcg/optimize.c |
21 | @@ -XXX,XX +XXX,XX @@ void tb_set_jmp_target(TranslationBlock *tb, int n, uintptr_t addr); | 15 | @@ -XXX,XX +XXX,XX @@ static bool fold_or(OptContext *ctx, TCGOp *op) |
22 | 16 | static bool fold_orc(OptContext *ctx, TCGOp *op) | |
23 | /* GETPC is the true target of the return instruction that we'll execute. */ | ||
24 | #if defined(CONFIG_TCG_INTERPRETER) | ||
25 | -extern uintptr_t tci_tb_ptr; | ||
26 | +extern __thread uintptr_t tci_tb_ptr; | ||
27 | # define GETPC() tci_tb_ptr | ||
28 | #else | ||
29 | # define GETPC() \ | ||
30 | diff --git a/tcg/tcg-common.c b/tcg/tcg-common.c | ||
31 | index XXXXXXX..XXXXXXX 100644 | ||
32 | --- a/tcg/tcg-common.c | ||
33 | +++ b/tcg/tcg-common.c | ||
34 | @@ -XXX,XX +XXX,XX @@ | ||
35 | #include "qemu/osdep.h" | ||
36 | #include "tcg/tcg.h" | ||
37 | |||
38 | -#if defined(CONFIG_TCG_INTERPRETER) | ||
39 | -uintptr_t tci_tb_ptr; | ||
40 | -#endif | ||
41 | - | ||
42 | TCGOpDef tcg_op_defs[] = { | ||
43 | #define DEF(s, oargs, iargs, cargs, flags) \ | ||
44 | { #s, oargs, iargs, cargs, iargs + oargs + cargs, flags }, | ||
45 | diff --git a/tcg/tci.c b/tcg/tci.c | ||
46 | index XXXXXXX..XXXXXXX 100644 | ||
47 | --- a/tcg/tci.c | ||
48 | +++ b/tcg/tci.c | ||
49 | @@ -XXX,XX +XXX,XX @@ typedef uint64_t (*helper_function)(tcg_target_ulong, tcg_target_ulong, | ||
50 | tcg_target_ulong, tcg_target_ulong); | ||
51 | #endif | ||
52 | |||
53 | +__thread uintptr_t tci_tb_ptr; | ||
54 | + | ||
55 | static tcg_target_ulong tci_read_reg(const tcg_target_ulong *regs, TCGReg index) | ||
56 | { | 17 | { |
57 | tci_assert(index < TCG_TARGET_NB_REGS); | 18 | if (fold_const2(ctx, op) || |
58 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | 19 | + fold_xx_to_i(ctx, op, -1) || |
59 | #endif | 20 | fold_xi_to_x(ctx, op, -1) || |
60 | TCGMemOpIdx oi; | 21 | fold_ix_to_not(ctx, op, 0)) { |
61 | 22 | return true; | |
62 | -#if defined(GETPC) | ||
63 | - tci_tb_ptr = (uintptr_t)tb_ptr; | ||
64 | -#endif | ||
65 | - | ||
66 | /* Skip opcode and size entry. */ | ||
67 | tb_ptr += 2; | ||
68 | |||
69 | switch (opc) { | ||
70 | case INDEX_op_call: | ||
71 | t0 = tci_read_ri(regs, &tb_ptr); | ||
72 | + tci_tb_ptr = (uintptr_t)tb_ptr; | ||
73 | #if TCG_TARGET_REG_BITS == 32 | ||
74 | tmp64 = ((helper_function)t0)(tci_read_reg(regs, TCG_REG_R0), | ||
75 | tci_read_reg(regs, TCG_REG_R1), | ||
76 | -- | 23 | -- |
77 | 2.25.1 | 24 | 2.25.1 |
78 | 25 | ||
79 | 26 | diff view generated by jsdifflib |
1 | From: Claudio Fontana <cfontana@suse.de> | 1 | Recognize the identity function for low-part multiply. |
---|---|---|---|
2 | 2 | ||
3 | cc->do_interrupt is in theory a TCG callback used in accel/tcg only, | 3 | Suggested-by: Luis Pires <luis.pires@eldorado.org.br> |
4 | to prepare the emulated architecture to take an interrupt as defined | 4 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> |
5 | in the hardware specifications, | 5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
6 | |||
7 | but in reality the _do_interrupt style of functions in targets are | ||
8 | also occasionally reused by KVM to prepare the architecture state in a | ||
9 | similar way where userspace code has identified that it needs to | ||
10 | deliver an exception to the guest. | ||
11 | |||
12 | In the case of ARM, that includes: | ||
13 | |||
14 | 1) the vcpu thread got a SIGBUS indicating a memory error, | ||
15 | and we need to deliver a Synchronous External Abort to the guest to | ||
16 | let it know about the error. | ||
17 | 2) the kernel told us about a debug exception (breakpoint, watchpoint) | ||
18 | but it is not for one of QEMU's own gdbstub breakpoints/watchpoints | ||
19 | so it must be a breakpoint the guest itself has set up, therefore | ||
20 | we need to deliver it to the guest. | ||
21 | |||
22 | So in order to reuse code, the same arm_do_interrupt function is used. | ||
23 | This is all fine, but we need to avoid calling it using the callback | ||
24 | registered in CPUClass, since that one is now TCG-only. | ||
25 | |||
26 | Fortunately this is easily solved by replacing calls to | ||
27 | CPUClass::do_interrupt() with explicit calls to arm_do_interrupt(). | ||
28 | |||
29 | Signed-off-by: Claudio Fontana <cfontana@suse.de> | ||
30 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | ||
31 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
32 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
33 | Cc: Peter Maydell <peter.maydell@linaro.org> | ||
34 | Message-Id: <20210204163931.7358-9-cfontana@suse.de> | ||
35 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
36 | --- | 7 | --- |
37 | target/arm/helper.c | 4 ++++ | 8 | tcg/optimize.c | 3 ++- |
38 | target/arm/kvm64.c | 6 ++---- | 9 | 1 file changed, 2 insertions(+), 1 deletion(-) |
39 | 2 files changed, 6 insertions(+), 4 deletions(-) | ||
40 | 10 | ||
41 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 11 | diff --git a/tcg/optimize.c b/tcg/optimize.c |
42 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
43 | --- a/target/arm/helper.c | 13 | --- a/tcg/optimize.c |
44 | +++ b/target/arm/helper.c | 14 | +++ b/tcg/optimize.c |
45 | @@ -XXX,XX +XXX,XX @@ static void handle_semihosting(CPUState *cs) | 15 | @@ -XXX,XX +XXX,XX @@ static bool fold_movcond(OptContext *ctx, TCGOp *op) |
46 | * Do any appropriate logging, handle PSCI calls, and then hand off | 16 | static bool fold_mul(OptContext *ctx, TCGOp *op) |
47 | * to the AArch64-entry or AArch32-entry function depending on the | ||
48 | * target exception level's register width. | ||
49 | + * | ||
50 | + * Note: this is used for both TCG (as the do_interrupt tcg op), | ||
51 | + * and KVM to re-inject guest debug exceptions, and to | ||
52 | + * inject a Synchronous-External-Abort. | ||
53 | */ | ||
54 | void arm_cpu_do_interrupt(CPUState *cs) | ||
55 | { | 17 | { |
56 | diff --git a/target/arm/kvm64.c b/target/arm/kvm64.c | 18 | if (fold_const2(ctx, op) || |
57 | index XXXXXXX..XXXXXXX 100644 | 19 | - fold_xi_to_i(ctx, op, 0)) { |
58 | --- a/target/arm/kvm64.c | 20 | + fold_xi_to_i(ctx, op, 0) || |
59 | +++ b/target/arm/kvm64.c | 21 | + fold_xi_to_x(ctx, op, 1)) { |
60 | @@ -XXX,XX +XXX,XX @@ static void kvm_inject_arm_sea(CPUState *c) | 22 | return true; |
61 | { | 23 | } |
62 | ARMCPU *cpu = ARM_CPU(c); | ||
63 | CPUARMState *env = &cpu->env; | ||
64 | - CPUClass *cc = CPU_GET_CLASS(c); | ||
65 | uint32_t esr; | ||
66 | bool same_el; | ||
67 | |||
68 | @@ -XXX,XX +XXX,XX @@ static void kvm_inject_arm_sea(CPUState *c) | ||
69 | |||
70 | env->exception.syndrome = esr; | ||
71 | |||
72 | - cc->do_interrupt(c); | ||
73 | + arm_cpu_do_interrupt(c); | ||
74 | } | ||
75 | |||
76 | #define AARCH64_CORE_REG(x) (KVM_REG_ARM64 | KVM_REG_SIZE_U64 | \ | ||
77 | @@ -XXX,XX +XXX,XX @@ bool kvm_arm_handle_debug(CPUState *cs, struct kvm_debug_exit_arch *debug_exit) | ||
78 | { | ||
79 | int hsr_ec = syn_get_ec(debug_exit->hsr); | ||
80 | ARMCPU *cpu = ARM_CPU(cs); | ||
81 | - CPUClass *cc = CPU_GET_CLASS(cs); | ||
82 | CPUARMState *env = &cpu->env; | ||
83 | |||
84 | /* Ensure PC is synchronised */ | ||
85 | @@ -XXX,XX +XXX,XX @@ bool kvm_arm_handle_debug(CPUState *cs, struct kvm_debug_exit_arch *debug_exit) | ||
86 | env->exception.vaddress = debug_exit->far; | ||
87 | env->exception.target_el = 1; | ||
88 | qemu_mutex_lock_iothread(); | ||
89 | - cc->do_interrupt(cs); | ||
90 | + arm_cpu_do_interrupt(cs); | ||
91 | qemu_mutex_unlock_iothread(); | ||
92 | |||
93 | return false; | 24 | return false; |
94 | -- | 25 | -- |
95 | 2.25.1 | 26 | 2.25.1 |
96 | 27 | ||
97 | 28 | diff view generated by jsdifflib |
1 | From: Claudio Fontana <cfontana@suse.de> | 1 | Recognize the identity function for division. |
---|---|---|---|
2 | 2 | ||
3 | for now only TCG is allowed as an accelerator for riscv, | 3 | Suggested-by: Luis Pires <luis.pires@eldorado.org.br> |
4 | so remove the CONFIG_TCG use. | 4 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> |
5 | 5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | |
6 | Signed-off-by: Claudio Fontana <cfontana@suse.de> | ||
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
8 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | ||
9 | Message-Id: <20210204163931.7358-3-cfontana@suse.de> | ||
10 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
11 | --- | 7 | --- |
12 | target/riscv/cpu.c | 3 +-- | 8 | tcg/optimize.c | 6 +++++- |
13 | 1 file changed, 1 insertion(+), 2 deletions(-) | 9 | 1 file changed, 5 insertions(+), 1 deletion(-) |
14 | 10 | ||
15 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 11 | diff --git a/tcg/optimize.c b/tcg/optimize.c |
16 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/riscv/cpu.c | 13 | --- a/tcg/optimize.c |
18 | +++ b/target/riscv/cpu.c | 14 | +++ b/tcg/optimize.c |
19 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_class_init(ObjectClass *c, void *data) | 15 | @@ -XXX,XX +XXX,XX @@ static bool fold_deposit(OptContext *ctx, TCGOp *op) |
20 | #endif | 16 | |
21 | cc->gdb_arch_name = riscv_gdb_arch_name; | 17 | static bool fold_divide(OptContext *ctx, TCGOp *op) |
22 | cc->gdb_get_dynamic_xml = riscv_gdb_get_dynamic_xml; | 18 | { |
23 | -#ifdef CONFIG_TCG | 19 | - return fold_const2(ctx, op); |
24 | cc->tcg_ops.initialize = riscv_translate_init; | 20 | + if (fold_const2(ctx, op) || |
25 | cc->tlb_fill = riscv_cpu_tlb_fill; | 21 | + fold_xi_to_x(ctx, op, 1)) { |
26 | -#endif | 22 | + return true; |
27 | + | 23 | + } |
28 | device_class_set_props(dc, riscv_cpu_properties); | 24 | + return false; |
29 | } | 25 | } |
30 | 26 | ||
27 | static bool fold_dup(OptContext *ctx, TCGOp *op) | ||
31 | -- | 28 | -- |
32 | 2.25.1 | 29 | 2.25.1 |
33 | 30 | ||
34 | 31 | diff view generated by jsdifflib |
1 | Tested-by: Alex Bennée <alex.bennee@linaro.org> | 1 | Recognize the constant function for remainder. |
---|---|---|---|
2 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 2 | |
3 | Suggested-by: Luis Pires <luis.pires@eldorado.org.br> | ||
4 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.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/tci.c | 10 +--------- | 7 | tcg/optimize.c | 6 +++++- |
6 | 1 file changed, 1 insertion(+), 9 deletions(-) | 8 | 1 file changed, 5 insertions(+), 1 deletion(-) |
7 | 9 | ||
8 | diff --git a/tcg/tci.c b/tcg/tci.c | 10 | diff --git a/tcg/optimize.c b/tcg/optimize.c |
9 | index XXXXXXX..XXXXXXX 100644 | 11 | index XXXXXXX..XXXXXXX 100644 |
10 | --- a/tcg/tci.c | 12 | --- a/tcg/optimize.c |
11 | +++ b/tcg/tci.c | 13 | +++ b/tcg/optimize.c |
12 | @@ -XXX,XX +XXX,XX @@ tci_write_reg(tcg_target_ulong *regs, TCGReg index, tcg_target_ulong value) | 14 | @@ -XXX,XX +XXX,XX @@ static bool fold_qemu_st(OptContext *ctx, TCGOp *op) |
13 | regs[index] = value; | 15 | |
16 | static bool fold_remainder(OptContext *ctx, TCGOp *op) | ||
17 | { | ||
18 | - return fold_const2(ctx, op); | ||
19 | + if (fold_const2(ctx, op) || | ||
20 | + fold_xx_to_i(ctx, op, 0)) { | ||
21 | + return true; | ||
22 | + } | ||
23 | + return false; | ||
14 | } | 24 | } |
15 | 25 | ||
16 | -#if TCG_TARGET_REG_BITS == 64 | 26 | static bool fold_setcond(OptContext *ctx, TCGOp *op) |
17 | -static void | ||
18 | -tci_write_reg32s(tcg_target_ulong *regs, TCGReg index, int32_t value) | ||
19 | -{ | ||
20 | - tci_write_reg(regs, index, value); | ||
21 | -} | ||
22 | -#endif | ||
23 | - | ||
24 | static void tci_write_reg8(tcg_target_ulong *regs, TCGReg index, uint8_t value) | ||
25 | { | ||
26 | tci_write_reg(regs, index, value); | ||
27 | @@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env, | ||
28 | t0 = *tb_ptr++; | ||
29 | t1 = tci_read_r(regs, &tb_ptr); | ||
30 | t2 = tci_read_s32(&tb_ptr); | ||
31 | - tci_write_reg32s(regs, t0, *(int32_t *)(t1 + t2)); | ||
32 | + tci_write_reg(regs, t0, *(int32_t *)(t1 + t2)); | ||
33 | break; | ||
34 | case INDEX_op_ld_i64: | ||
35 | t0 = *tb_ptr++; | ||
36 | -- | 27 | -- |
37 | 2.25.1 | 28 | 2.25.1 |
38 | 29 | ||
39 | 30 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | 1 | Certain targets, like riscv, produce signed 32-bit results. |
---|---|---|---|
2 | 2 | This can lead to lots of redundant extensions as values are | |
3 | The code is currently comparing c2 to the type promotion of | 3 | manipulated. |
4 | uint32_t and int32_t. That is, the conversion rules are as: | 4 | |
5 | 5 | Begin by tracking only the obvious sign-extensions, and | |
6 | (common_type) c2 == (common_type) (uint32_t) | 6 | converting them to simple copies when possible. |
7 | (is_unsigned | 7 | |
8 | ? (uint32_t)c2 | 8 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> |
9 | : (uint32_t)(int32_t)c2) | 9 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> |
10 | |||
11 | In the signed case we lose the desired sign extensions because | ||
12 | of the argument promotion rules of the ternary operator. | ||
13 | |||
14 | Solve the problem by doing the round-trip parsing through the | ||
15 | intermediate type and back to the desired common type (all at | ||
16 | one expression). | ||
17 | |||
18 | Fixes: a534bb15f30 ("tcg/s390: Use constant pool for cmpi") | ||
19 | Tested-by: Richard W.M. Jones <rjones@redhat.com> | ||
20 | Reviewed-by: David Hildenbrand <david@redhat.com> | ||
21 | Reported-by: Miroslav Rezanina <mrezanin@redhat.com> | ||
22 | Reported-by: Richard W.M. Jones <rjones@redhat.com> | ||
23 | Suggested-by: David Hildenbrand <david@redhat.com> | ||
24 | Suggested-by: Eric Blake <eblake@redhat.com> | ||
25 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
26 | Message-Id: <20210204182902.1742826-1-f4bug@amsat.org> | ||
27 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 10 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
28 | --- | 11 | --- |
29 | tcg/s390/tcg-target.c.inc | 2 +- | 12 | tcg/optimize.c | 123 ++++++++++++++++++++++++++++++++++++++++--------- |
30 | 1 file changed, 1 insertion(+), 1 deletion(-) | 13 | 1 file changed, 102 insertions(+), 21 deletions(-) |
31 | 14 | ||
32 | diff --git a/tcg/s390/tcg-target.c.inc b/tcg/s390/tcg-target.c.inc | 15 | diff --git a/tcg/optimize.c b/tcg/optimize.c |
33 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
34 | --- a/tcg/s390/tcg-target.c.inc | 17 | --- a/tcg/optimize.c |
35 | +++ b/tcg/s390/tcg-target.c.inc | 18 | +++ b/tcg/optimize.c |
36 | @@ -XXX,XX +XXX,XX @@ static int tgen_cmp(TCGContext *s, TCGType type, TCGCond c, TCGReg r1, | 19 | @@ -XXX,XX +XXX,XX @@ typedef struct TempOptInfo { |
37 | op = (is_unsigned ? RIL_CLFI : RIL_CFI); | 20 | TCGTemp *next_copy; |
38 | tcg_out_insn_RIL(s, op, r1, c2); | 21 | uint64_t val; |
39 | goto exit; | 22 | uint64_t z_mask; /* mask bit is 0 if and only if value bit is 0 */ |
40 | - } else if (c2 == (is_unsigned ? (uint32_t)c2 : (int32_t)c2)) { | 23 | + uint64_t s_mask; /* a left-aligned mask of clrsb(value) bits. */ |
41 | + } else if (c2 == (is_unsigned ? (TCGArg)(uint32_t)c2 : (TCGArg)(int32_t)c2)) { | 24 | } TempOptInfo; |
42 | op = (is_unsigned ? RIL_CLGFI : RIL_CGFI); | 25 | |
43 | tcg_out_insn_RIL(s, op, r1, c2); | 26 | typedef struct OptContext { |
44 | goto exit; | 27 | @@ -XXX,XX +XXX,XX @@ typedef struct OptContext { |
28 | /* In flight values from optimization. */ | ||
29 | uint64_t a_mask; /* mask bit is 0 iff value identical to first input */ | ||
30 | uint64_t z_mask; /* mask bit is 0 iff value bit is 0 */ | ||
31 | + uint64_t s_mask; /* mask of clrsb(value) bits */ | ||
32 | TCGType type; | ||
33 | } OptContext; | ||
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 | { | ||
64 | return ts->state_ptr; | ||
65 | @@ -XXX,XX +XXX,XX @@ static void reset_ts(TCGTemp *ts) | ||
66 | ti->prev_copy = ts; | ||
67 | ti->is_const = false; | ||
68 | ti->z_mask = -1; | ||
69 | + ti->s_mask = 0; | ||
70 | } | ||
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 | */ | ||
105 | if (i == 0) { | ||
106 | - arg_info(op->args[i])->z_mask = ctx->z_mask; | ||
107 | + ts_info(ts)->z_mask = ctx->z_mask; | ||
108 | + ts_info(ts)->s_mask = ctx->s_mask; | ||
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; | ||
324 | default: | ||
325 | g_assert_not_reached(); | ||
326 | @@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s) | ||
327 | ctx.type = TCG_TYPE_I32; | ||
328 | } | ||
329 | |||
330 | - /* Assume all bits affected, and no bits known zero. */ | ||
331 | + /* Assume all bits affected, no bits known zero, no sign reps. */ | ||
332 | ctx.a_mask = -1; | ||
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; | ||
342 | + CASE_OP_32_64(ld8s): | ||
343 | CASE_OP_32_64(ld8u): | ||
344 | + CASE_OP_32_64(ld16s): | ||
345 | CASE_OP_32_64(ld16u): | ||
346 | + case INDEX_op_ld32s_i64: | ||
347 | case INDEX_op_ld32u_i64: | ||
348 | done = fold_tcg_ld(&ctx, op); | ||
349 | break; | ||
45 | -- | 350 | -- |
46 | 2.25.1 | 351 | 2.25.1 |
47 | 352 | ||
48 | 353 | diff view generated by jsdifflib |
1 | From: Eduardo Habkost <ehabkost@redhat.com> | 1 | Sign repetitions are perforce all identical, whether they are 1 or 0. |
---|---|---|---|
2 | Bitwise operations preserve the relative quantity of the repetitions. | ||
2 | 3 | ||
3 | Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> | ||
4 | [claudio: wrapped target code in CONFIG_TCG] | ||
5 | Signed-off-by: Claudio Fontana <cfontana@suse.de> | ||
6 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
7 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 4 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> |
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 5 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> |
9 | Message-Id: <20210204163931.7358-6-cfontana@suse.de> | 6 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
10 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
11 | --- | 8 | --- |
12 | include/hw/core/cpu.h | 12 ++++++------ | 9 | tcg/optimize.c | 29 +++++++++++++++++++++++++++++ |
13 | accel/tcg/cpu-exec.c | 12 ++++++------ | 10 | 1 file changed, 29 insertions(+) |
14 | target/alpha/cpu.c | 2 +- | ||
15 | target/arm/cpu.c | 2 +- | ||
16 | target/arm/cpu64.c | 5 ++++- | ||
17 | target/arm/cpu_tcg.c | 7 ++++++- | ||
18 | target/avr/cpu.c | 2 +- | ||
19 | target/cris/cpu.c | 2 +- | ||
20 | target/hppa/cpu.c | 2 +- | ||
21 | target/i386/tcg/tcg-cpu.c | 6 +++--- | ||
22 | target/lm32/cpu.c | 2 +- | ||
23 | target/m68k/cpu.c | 2 +- | ||
24 | target/microblaze/cpu.c | 2 +- | ||
25 | target/mips/cpu.c | 2 +- | ||
26 | target/nios2/cpu.c | 2 +- | ||
27 | target/openrisc/cpu.c | 2 +- | ||
28 | target/riscv/cpu.c | 2 +- | ||
29 | target/rx/cpu.c | 2 +- | ||
30 | target/s390x/cpu.c | 2 +- | ||
31 | target/sh4/cpu.c | 2 +- | ||
32 | target/sparc/cpu.c | 2 +- | ||
33 | target/tilegx/cpu.c | 2 +- | ||
34 | target/unicore32/cpu.c | 2 +- | ||
35 | target/xtensa/cpu.c | 2 +- | ||
36 | target/ppc/translate_init.c.inc | 16 ++++++++++------ | ||
37 | 25 files changed, 54 insertions(+), 42 deletions(-) | ||
38 | 11 | ||
39 | diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h | 12 | diff --git a/tcg/optimize.c b/tcg/optimize.c |
40 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
41 | --- a/include/hw/core/cpu.h | 14 | --- a/tcg/optimize.c |
42 | +++ b/include/hw/core/cpu.h | 15 | +++ b/tcg/optimize.c |
43 | @@ -XXX,XX +XXX,XX @@ typedef struct TcgCpuOperations { | 16 | @@ -XXX,XX +XXX,XX @@ static bool fold_and(OptContext *ctx, TCGOp *op) |
44 | */ | 17 | z2 = arg_info(op->args[2])->z_mask; |
45 | void (*synchronize_from_tb)(CPUState *cpu, | 18 | ctx->z_mask = z1 & z2; |
46 | const struct TranslationBlock *tb); | 19 | |
47 | + /** @cpu_exec_enter: Callback for cpu_exec preparation */ | 20 | + /* |
48 | + void (*cpu_exec_enter)(CPUState *cpu); | 21 | + * Sign repetitions are perforce all identical, whether they are 1 or 0. |
49 | + /** @cpu_exec_exit: Callback for cpu_exec cleanup */ | 22 | + * Bitwise operations preserve the relative quantity of the repetitions. |
50 | + void (*cpu_exec_exit)(CPUState *cpu); | 23 | + */ |
51 | + /** @cpu_exec_interrupt: Callback for processing interrupts in cpu_exec */ | 24 | + ctx->s_mask = arg_info(op->args[1])->s_mask |
52 | + bool (*cpu_exec_interrupt)(CPUState *cpu, int interrupt_request); | 25 | + & arg_info(op->args[2])->s_mask; |
53 | 26 | + | |
54 | } TcgCpuOperations; | 27 | /* |
55 | 28 | * Known-zeros does not imply known-ones. Therefore unless | |
56 | @@ -XXX,XX +XXX,XX @@ typedef struct TcgCpuOperations { | 29 | * arg2 is constant, we can't infer affected bits from it. |
57 | * @gdb_get_dynamic_xml: Callback to return dynamically generated XML for the | 30 | @@ -XXX,XX +XXX,XX @@ static bool fold_andc(OptContext *ctx, TCGOp *op) |
58 | * gdb stub. Returns a pointer to the XML contents for the specified XML file | ||
59 | * or NULL if the CPU doesn't have a dynamically generated content for it. | ||
60 | - * @cpu_exec_enter: Callback for cpu_exec preparation. | ||
61 | - * @cpu_exec_exit: Callback for cpu_exec cleanup. | ||
62 | - * @cpu_exec_interrupt: Callback for processing interrupts in cpu_exec. | ||
63 | * @disas_set_info: Setup architecture specific components of disassembly info | ||
64 | * @adjust_watchpoint_address: Perform a target-specific adjustment to an | ||
65 | * address before attempting to match it against watchpoints. | ||
66 | @@ -XXX,XX +XXX,XX @@ struct CPUClass { | ||
67 | const char *gdb_core_xml_file; | ||
68 | gchar * (*gdb_arch_name)(CPUState *cpu); | ||
69 | const char * (*gdb_get_dynamic_xml)(CPUState *cpu, const char *xmlname); | ||
70 | - void (*cpu_exec_enter)(CPUState *cpu); | ||
71 | - void (*cpu_exec_exit)(CPUState *cpu); | ||
72 | - bool (*cpu_exec_interrupt)(CPUState *cpu, int interrupt_request); | ||
73 | |||
74 | void (*disas_set_info)(CPUState *cpu, disassemble_info *info); | ||
75 | vaddr (*adjust_watchpoint_address)(CPUState *cpu, vaddr addr, int len); | ||
76 | diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c | ||
77 | index XXXXXXX..XXXXXXX 100644 | ||
78 | --- a/accel/tcg/cpu-exec.c | ||
79 | +++ b/accel/tcg/cpu-exec.c | ||
80 | @@ -XXX,XX +XXX,XX @@ static void cpu_exec_enter(CPUState *cpu) | ||
81 | { | ||
82 | CPUClass *cc = CPU_GET_CLASS(cpu); | ||
83 | |||
84 | - if (cc->cpu_exec_enter) { | ||
85 | - cc->cpu_exec_enter(cpu); | ||
86 | + if (cc->tcg_ops.cpu_exec_enter) { | ||
87 | + cc->tcg_ops.cpu_exec_enter(cpu); | ||
88 | } | 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); | ||
89 | } | 37 | } |
90 | 38 | ||
91 | @@ -XXX,XX +XXX,XX @@ static void cpu_exec_exit(CPUState *cpu) | 39 | @@ -XXX,XX +XXX,XX @@ static bool fold_eqv(OptContext *ctx, TCGOp *op) |
92 | { | 40 | fold_xi_to_not(ctx, op, 0)) { |
93 | CPUClass *cc = CPU_GET_CLASS(cpu); | 41 | return true; |
94 | |||
95 | - if (cc->cpu_exec_exit) { | ||
96 | - cc->cpu_exec_exit(cpu); | ||
97 | + if (cc->tcg_ops.cpu_exec_exit) { | ||
98 | + cc->tcg_ops.cpu_exec_exit(cpu); | ||
99 | } | 42 | } |
43 | + | ||
44 | + ctx->s_mask = arg_info(op->args[1])->s_mask | ||
45 | + & arg_info(op->args[2])->s_mask; | ||
46 | return false; | ||
100 | } | 47 | } |
101 | 48 | ||
102 | @@ -XXX,XX +XXX,XX @@ static inline bool cpu_handle_interrupt(CPUState *cpu, | 49 | @@ -XXX,XX +XXX,XX @@ static bool fold_movcond(OptContext *ctx, TCGOp *op) |
103 | True when it is, and we should restart on a new TB, | 50 | |
104 | and via longjmp via cpu_loop_exit. */ | 51 | ctx->z_mask = arg_info(op->args[3])->z_mask |
105 | else { | 52 | | arg_info(op->args[4])->z_mask; |
106 | - if (cc->cpu_exec_interrupt && | 53 | + ctx->s_mask = arg_info(op->args[3])->s_mask |
107 | - cc->cpu_exec_interrupt(cpu, interrupt_request)) { | 54 | + & arg_info(op->args[4])->s_mask; |
108 | + if (cc->tcg_ops.cpu_exec_interrupt && | 55 | |
109 | + cc->tcg_ops.cpu_exec_interrupt(cpu, interrupt_request)) { | 56 | if (arg_is_const(op->args[3]) && arg_is_const(op->args[4])) { |
110 | if (need_replay_interrupt(interrupt_request)) { | 57 | uint64_t tv = arg_info(op->args[3])->val; |
111 | replay_interrupt(); | 58 | @@ -XXX,XX +XXX,XX @@ static bool fold_nand(OptContext *ctx, TCGOp *op) |
112 | } | 59 | fold_xi_to_not(ctx, op, -1)) { |
113 | diff --git a/target/alpha/cpu.c b/target/alpha/cpu.c | 60 | return true; |
114 | index XXXXXXX..XXXXXXX 100644 | 61 | } |
115 | --- a/target/alpha/cpu.c | ||
116 | +++ b/target/alpha/cpu.c | ||
117 | @@ -XXX,XX +XXX,XX @@ static void alpha_cpu_class_init(ObjectClass *oc, void *data) | ||
118 | cc->class_by_name = alpha_cpu_class_by_name; | ||
119 | cc->has_work = alpha_cpu_has_work; | ||
120 | cc->do_interrupt = alpha_cpu_do_interrupt; | ||
121 | - cc->cpu_exec_interrupt = alpha_cpu_exec_interrupt; | ||
122 | + cc->tcg_ops.cpu_exec_interrupt = alpha_cpu_exec_interrupt; | ||
123 | cc->dump_state = alpha_cpu_dump_state; | ||
124 | cc->set_pc = alpha_cpu_set_pc; | ||
125 | cc->gdb_read_register = alpha_cpu_gdb_read_register; | ||
126 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | ||
127 | index XXXXXXX..XXXXXXX 100644 | ||
128 | --- a/target/arm/cpu.c | ||
129 | +++ b/target/arm/cpu.c | ||
130 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_class_init(ObjectClass *oc, void *data) | ||
131 | |||
132 | cc->class_by_name = arm_cpu_class_by_name; | ||
133 | cc->has_work = arm_cpu_has_work; | ||
134 | - cc->cpu_exec_interrupt = arm_cpu_exec_interrupt; | ||
135 | cc->dump_state = arm_cpu_dump_state; | ||
136 | cc->set_pc = arm_cpu_set_pc; | ||
137 | cc->gdb_read_register = arm_cpu_gdb_read_register; | ||
138 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_class_init(ObjectClass *oc, void *data) | ||
139 | cc->disas_set_info = arm_disas_set_info; | ||
140 | #ifdef CONFIG_TCG | ||
141 | cc->tcg_ops.initialize = arm_translate_init; | ||
142 | + cc->tcg_ops.cpu_exec_interrupt = arm_cpu_exec_interrupt; | ||
143 | cc->tcg_ops.synchronize_from_tb = arm_cpu_synchronize_from_tb; | ||
144 | cc->tlb_fill = arm_cpu_tlb_fill; | ||
145 | cc->debug_excp_handler = arm_debug_excp_handler; | ||
146 | diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c | ||
147 | index XXXXXXX..XXXXXXX 100644 | ||
148 | --- a/target/arm/cpu64.c | ||
149 | +++ b/target/arm/cpu64.c | ||
150 | @@ -XXX,XX +XXX,XX @@ static void aarch64_cpu_class_init(ObjectClass *oc, void *data) | ||
151 | { | ||
152 | CPUClass *cc = CPU_CLASS(oc); | ||
153 | |||
154 | - cc->cpu_exec_interrupt = arm_cpu_exec_interrupt; | ||
155 | +#ifdef CONFIG_TCG | ||
156 | + cc->tcg_ops.cpu_exec_interrupt = arm_cpu_exec_interrupt; | ||
157 | +#endif /* CONFIG_TCG */ | ||
158 | + | 62 | + |
159 | cc->gdb_read_register = aarch64_cpu_gdb_read_register; | 63 | + ctx->s_mask = arg_info(op->args[1])->s_mask |
160 | cc->gdb_write_register = aarch64_cpu_gdb_write_register; | 64 | + & arg_info(op->args[2])->s_mask; |
161 | cc->gdb_num_core_regs = 34; | 65 | return false; |
162 | diff --git a/target/arm/cpu_tcg.c b/target/arm/cpu_tcg.c | 66 | } |
163 | index XXXXXXX..XXXXXXX 100644 | 67 | |
164 | --- a/target/arm/cpu_tcg.c | 68 | @@ -XXX,XX +XXX,XX @@ static bool fold_nor(OptContext *ctx, TCGOp *op) |
165 | +++ b/target/arm/cpu_tcg.c | 69 | fold_xi_to_not(ctx, op, 0)) { |
166 | @@ -XXX,XX +XXX,XX @@ | 70 | return true; |
167 | /* CPU models. These are not needed for the AArch64 linux-user build. */ | ||
168 | #if !defined(CONFIG_USER_ONLY) || !defined(TARGET_AARCH64) | ||
169 | |||
170 | +#ifdef CONFIG_TCG | ||
171 | static bool arm_v7m_cpu_exec_interrupt(CPUState *cs, int interrupt_request) | ||
172 | { | ||
173 | CPUClass *cc = CPU_GET_CLASS(cs); | ||
174 | @@ -XXX,XX +XXX,XX @@ static bool arm_v7m_cpu_exec_interrupt(CPUState *cs, int interrupt_request) | ||
175 | } | 71 | } |
176 | return ret; | 72 | + |
73 | + ctx->s_mask = arg_info(op->args[1])->s_mask | ||
74 | + & arg_info(op->args[2])->s_mask; | ||
75 | return false; | ||
177 | } | 76 | } |
178 | +#endif /* CONFIG_TCG */ | 77 | |
179 | 78 | @@ -XXX,XX +XXX,XX @@ static bool fold_not(OptContext *ctx, TCGOp *op) | |
180 | static void arm926_initfn(Object *obj) | 79 | return true; |
181 | { | 80 | } |
182 | @@ -XXX,XX +XXX,XX @@ static void arm_v7m_class_init(ObjectClass *oc, void *data) | 81 | |
183 | cc->do_interrupt = arm_v7m_cpu_do_interrupt; | 82 | + ctx->s_mask = arg_info(op->args[1])->s_mask; |
184 | #endif | ||
185 | |||
186 | - cc->cpu_exec_interrupt = arm_v7m_cpu_exec_interrupt; | ||
187 | +#ifdef CONFIG_TCG | ||
188 | + cc->tcg_ops.cpu_exec_interrupt = arm_v7m_cpu_exec_interrupt; | ||
189 | +#endif /* CONFIG_TCG */ | ||
190 | + | 83 | + |
191 | cc->gdb_core_xml_file = "arm-m-profile.xml"; | 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); | ||
192 | } | 94 | } |
193 | 95 | ||
194 | diff --git a/target/avr/cpu.c b/target/avr/cpu.c | 96 | @@ -XXX,XX +XXX,XX @@ static bool fold_orc(OptContext *ctx, TCGOp *op) |
195 | index XXXXXXX..XXXXXXX 100644 | 97 | fold_ix_to_not(ctx, op, 0)) { |
196 | --- a/target/avr/cpu.c | 98 | return true; |
197 | +++ b/target/avr/cpu.c | 99 | } |
198 | @@ -XXX,XX +XXX,XX @@ static void avr_cpu_class_init(ObjectClass *oc, void *data) | 100 | + |
199 | 101 | + ctx->s_mask = arg_info(op->args[1])->s_mask | |
200 | cc->has_work = avr_cpu_has_work; | 102 | + & arg_info(op->args[2])->s_mask; |
201 | cc->do_interrupt = avr_cpu_do_interrupt; | 103 | return false; |
202 | - cc->cpu_exec_interrupt = avr_cpu_exec_interrupt; | ||
203 | + cc->tcg_ops.cpu_exec_interrupt = avr_cpu_exec_interrupt; | ||
204 | cc->dump_state = avr_cpu_dump_state; | ||
205 | cc->set_pc = avr_cpu_set_pc; | ||
206 | cc->memory_rw_debug = avr_cpu_memory_rw_debug; | ||
207 | diff --git a/target/cris/cpu.c b/target/cris/cpu.c | ||
208 | index XXXXXXX..XXXXXXX 100644 | ||
209 | --- a/target/cris/cpu.c | ||
210 | +++ b/target/cris/cpu.c | ||
211 | @@ -XXX,XX +XXX,XX @@ static void cris_cpu_class_init(ObjectClass *oc, void *data) | ||
212 | cc->class_by_name = cris_cpu_class_by_name; | ||
213 | cc->has_work = cris_cpu_has_work; | ||
214 | cc->do_interrupt = cris_cpu_do_interrupt; | ||
215 | - cc->cpu_exec_interrupt = cris_cpu_exec_interrupt; | ||
216 | + cc->tcg_ops.cpu_exec_interrupt = cris_cpu_exec_interrupt; | ||
217 | cc->dump_state = cris_cpu_dump_state; | ||
218 | cc->set_pc = cris_cpu_set_pc; | ||
219 | cc->gdb_read_register = cris_cpu_gdb_read_register; | ||
220 | diff --git a/target/hppa/cpu.c b/target/hppa/cpu.c | ||
221 | index XXXXXXX..XXXXXXX 100644 | ||
222 | --- a/target/hppa/cpu.c | ||
223 | +++ b/target/hppa/cpu.c | ||
224 | @@ -XXX,XX +XXX,XX @@ static void hppa_cpu_class_init(ObjectClass *oc, void *data) | ||
225 | cc->class_by_name = hppa_cpu_class_by_name; | ||
226 | cc->has_work = hppa_cpu_has_work; | ||
227 | cc->do_interrupt = hppa_cpu_do_interrupt; | ||
228 | - cc->cpu_exec_interrupt = hppa_cpu_exec_interrupt; | ||
229 | + cc->tcg_ops.cpu_exec_interrupt = hppa_cpu_exec_interrupt; | ||
230 | cc->dump_state = hppa_cpu_dump_state; | ||
231 | cc->set_pc = hppa_cpu_set_pc; | ||
232 | cc->tcg_ops.synchronize_from_tb = hppa_cpu_synchronize_from_tb; | ||
233 | diff --git a/target/i386/tcg/tcg-cpu.c b/target/i386/tcg/tcg-cpu.c | ||
234 | index XXXXXXX..XXXXXXX 100644 | ||
235 | --- a/target/i386/tcg/tcg-cpu.c | ||
236 | +++ b/target/i386/tcg/tcg-cpu.c | ||
237 | @@ -XXX,XX +XXX,XX @@ static void x86_cpu_synchronize_from_tb(CPUState *cs, | ||
238 | void tcg_cpu_common_class_init(CPUClass *cc) | ||
239 | { | ||
240 | cc->do_interrupt = x86_cpu_do_interrupt; | ||
241 | - cc->cpu_exec_interrupt = x86_cpu_exec_interrupt; | ||
242 | + cc->tcg_ops.cpu_exec_interrupt = x86_cpu_exec_interrupt; | ||
243 | cc->tcg_ops.synchronize_from_tb = x86_cpu_synchronize_from_tb; | ||
244 | - cc->cpu_exec_enter = x86_cpu_exec_enter; | ||
245 | - cc->cpu_exec_exit = x86_cpu_exec_exit; | ||
246 | + cc->tcg_ops.cpu_exec_enter = x86_cpu_exec_enter; | ||
247 | + cc->tcg_ops.cpu_exec_exit = x86_cpu_exec_exit; | ||
248 | cc->tcg_ops.initialize = tcg_x86_init; | ||
249 | cc->tlb_fill = x86_cpu_tlb_fill; | ||
250 | #ifndef CONFIG_USER_ONLY | ||
251 | diff --git a/target/lm32/cpu.c b/target/lm32/cpu.c | ||
252 | index XXXXXXX..XXXXXXX 100644 | ||
253 | --- a/target/lm32/cpu.c | ||
254 | +++ b/target/lm32/cpu.c | ||
255 | @@ -XXX,XX +XXX,XX @@ static void lm32_cpu_class_init(ObjectClass *oc, void *data) | ||
256 | cc->class_by_name = lm32_cpu_class_by_name; | ||
257 | cc->has_work = lm32_cpu_has_work; | ||
258 | cc->do_interrupt = lm32_cpu_do_interrupt; | ||
259 | - cc->cpu_exec_interrupt = lm32_cpu_exec_interrupt; | ||
260 | + cc->tcg_ops.cpu_exec_interrupt = lm32_cpu_exec_interrupt; | ||
261 | cc->dump_state = lm32_cpu_dump_state; | ||
262 | cc->set_pc = lm32_cpu_set_pc; | ||
263 | cc->gdb_read_register = lm32_cpu_gdb_read_register; | ||
264 | diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c | ||
265 | index XXXXXXX..XXXXXXX 100644 | ||
266 | --- a/target/m68k/cpu.c | ||
267 | +++ b/target/m68k/cpu.c | ||
268 | @@ -XXX,XX +XXX,XX @@ static void m68k_cpu_class_init(ObjectClass *c, void *data) | ||
269 | cc->class_by_name = m68k_cpu_class_by_name; | ||
270 | cc->has_work = m68k_cpu_has_work; | ||
271 | cc->do_interrupt = m68k_cpu_do_interrupt; | ||
272 | - cc->cpu_exec_interrupt = m68k_cpu_exec_interrupt; | ||
273 | + cc->tcg_ops.cpu_exec_interrupt = m68k_cpu_exec_interrupt; | ||
274 | cc->dump_state = m68k_cpu_dump_state; | ||
275 | cc->set_pc = m68k_cpu_set_pc; | ||
276 | cc->gdb_read_register = m68k_cpu_gdb_read_register; | ||
277 | diff --git a/target/microblaze/cpu.c b/target/microblaze/cpu.c | ||
278 | index XXXXXXX..XXXXXXX 100644 | ||
279 | --- a/target/microblaze/cpu.c | ||
280 | +++ b/target/microblaze/cpu.c | ||
281 | @@ -XXX,XX +XXX,XX @@ static void mb_cpu_class_init(ObjectClass *oc, void *data) | ||
282 | cc->has_work = mb_cpu_has_work; | ||
283 | cc->do_interrupt = mb_cpu_do_interrupt; | ||
284 | cc->do_unaligned_access = mb_cpu_do_unaligned_access; | ||
285 | - cc->cpu_exec_interrupt = mb_cpu_exec_interrupt; | ||
286 | + cc->tcg_ops.cpu_exec_interrupt = mb_cpu_exec_interrupt; | ||
287 | cc->dump_state = mb_cpu_dump_state; | ||
288 | cc->set_pc = mb_cpu_set_pc; | ||
289 | cc->tcg_ops.synchronize_from_tb = mb_cpu_synchronize_from_tb; | ||
290 | diff --git a/target/mips/cpu.c b/target/mips/cpu.c | ||
291 | index XXXXXXX..XXXXXXX 100644 | ||
292 | --- a/target/mips/cpu.c | ||
293 | +++ b/target/mips/cpu.c | ||
294 | @@ -XXX,XX +XXX,XX @@ static void mips_cpu_class_init(ObjectClass *c, void *data) | ||
295 | cc->class_by_name = mips_cpu_class_by_name; | ||
296 | cc->has_work = mips_cpu_has_work; | ||
297 | cc->do_interrupt = mips_cpu_do_interrupt; | ||
298 | - cc->cpu_exec_interrupt = mips_cpu_exec_interrupt; | ||
299 | cc->dump_state = mips_cpu_dump_state; | ||
300 | cc->set_pc = mips_cpu_set_pc; | ||
301 | cc->gdb_read_register = mips_cpu_gdb_read_register; | ||
302 | @@ -XXX,XX +XXX,XX @@ static void mips_cpu_class_init(ObjectClass *c, void *data) | ||
303 | cc->disas_set_info = mips_cpu_disas_set_info; | ||
304 | #ifdef CONFIG_TCG | ||
305 | cc->tcg_ops.initialize = mips_tcg_init; | ||
306 | + cc->tcg_ops.cpu_exec_interrupt = mips_cpu_exec_interrupt; | ||
307 | cc->tcg_ops.synchronize_from_tb = mips_cpu_synchronize_from_tb; | ||
308 | cc->tlb_fill = mips_cpu_tlb_fill; | ||
309 | #endif | ||
310 | diff --git a/target/nios2/cpu.c b/target/nios2/cpu.c | ||
311 | index XXXXXXX..XXXXXXX 100644 | ||
312 | --- a/target/nios2/cpu.c | ||
313 | +++ b/target/nios2/cpu.c | ||
314 | @@ -XXX,XX +XXX,XX @@ static void nios2_cpu_class_init(ObjectClass *oc, void *data) | ||
315 | cc->class_by_name = nios2_cpu_class_by_name; | ||
316 | cc->has_work = nios2_cpu_has_work; | ||
317 | cc->do_interrupt = nios2_cpu_do_interrupt; | ||
318 | - cc->cpu_exec_interrupt = nios2_cpu_exec_interrupt; | ||
319 | + cc->tcg_ops.cpu_exec_interrupt = nios2_cpu_exec_interrupt; | ||
320 | cc->dump_state = nios2_cpu_dump_state; | ||
321 | cc->set_pc = nios2_cpu_set_pc; | ||
322 | cc->disas_set_info = nios2_cpu_disas_set_info; | ||
323 | diff --git a/target/openrisc/cpu.c b/target/openrisc/cpu.c | ||
324 | index XXXXXXX..XXXXXXX 100644 | ||
325 | --- a/target/openrisc/cpu.c | ||
326 | +++ b/target/openrisc/cpu.c | ||
327 | @@ -XXX,XX +XXX,XX @@ static void openrisc_cpu_class_init(ObjectClass *oc, void *data) | ||
328 | cc->class_by_name = openrisc_cpu_class_by_name; | ||
329 | cc->has_work = openrisc_cpu_has_work; | ||
330 | cc->do_interrupt = openrisc_cpu_do_interrupt; | ||
331 | - cc->cpu_exec_interrupt = openrisc_cpu_exec_interrupt; | ||
332 | + cc->tcg_ops.cpu_exec_interrupt = openrisc_cpu_exec_interrupt; | ||
333 | cc->dump_state = openrisc_cpu_dump_state; | ||
334 | cc->set_pc = openrisc_cpu_set_pc; | ||
335 | cc->gdb_read_register = openrisc_cpu_gdb_read_register; | ||
336 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
337 | index XXXXXXX..XXXXXXX 100644 | ||
338 | --- a/target/riscv/cpu.c | ||
339 | +++ b/target/riscv/cpu.c | ||
340 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_class_init(ObjectClass *c, void *data) | ||
341 | cc->class_by_name = riscv_cpu_class_by_name; | ||
342 | cc->has_work = riscv_cpu_has_work; | ||
343 | cc->do_interrupt = riscv_cpu_do_interrupt; | ||
344 | - cc->cpu_exec_interrupt = riscv_cpu_exec_interrupt; | ||
345 | + cc->tcg_ops.cpu_exec_interrupt = riscv_cpu_exec_interrupt; | ||
346 | cc->dump_state = riscv_cpu_dump_state; | ||
347 | cc->set_pc = riscv_cpu_set_pc; | ||
348 | cc->tcg_ops.synchronize_from_tb = riscv_cpu_synchronize_from_tb; | ||
349 | diff --git a/target/rx/cpu.c b/target/rx/cpu.c | ||
350 | index XXXXXXX..XXXXXXX 100644 | ||
351 | --- a/target/rx/cpu.c | ||
352 | +++ b/target/rx/cpu.c | ||
353 | @@ -XXX,XX +XXX,XX @@ static void rx_cpu_class_init(ObjectClass *klass, void *data) | ||
354 | cc->class_by_name = rx_cpu_class_by_name; | ||
355 | cc->has_work = rx_cpu_has_work; | ||
356 | cc->do_interrupt = rx_cpu_do_interrupt; | ||
357 | - cc->cpu_exec_interrupt = rx_cpu_exec_interrupt; | ||
358 | + cc->tcg_ops.cpu_exec_interrupt = rx_cpu_exec_interrupt; | ||
359 | cc->dump_state = rx_cpu_dump_state; | ||
360 | cc->set_pc = rx_cpu_set_pc; | ||
361 | cc->tcg_ops.synchronize_from_tb = rx_cpu_synchronize_from_tb; | ||
362 | diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c | ||
363 | index XXXXXXX..XXXXXXX 100644 | ||
364 | --- a/target/s390x/cpu.c | ||
365 | +++ b/target/s390x/cpu.c | ||
366 | @@ -XXX,XX +XXX,XX @@ static void s390_cpu_class_init(ObjectClass *oc, void *data) | ||
367 | cc->get_crash_info = s390_cpu_get_crash_info; | ||
368 | cc->write_elf64_note = s390_cpu_write_elf64_note; | ||
369 | #ifdef CONFIG_TCG | ||
370 | - cc->cpu_exec_interrupt = s390_cpu_exec_interrupt; | ||
371 | + cc->tcg_ops.cpu_exec_interrupt = s390_cpu_exec_interrupt; | ||
372 | cc->debug_excp_handler = s390x_cpu_debug_excp_handler; | ||
373 | cc->do_unaligned_access = s390x_cpu_do_unaligned_access; | ||
374 | #endif | ||
375 | diff --git a/target/sh4/cpu.c b/target/sh4/cpu.c | ||
376 | index XXXXXXX..XXXXXXX 100644 | ||
377 | --- a/target/sh4/cpu.c | ||
378 | +++ b/target/sh4/cpu.c | ||
379 | @@ -XXX,XX +XXX,XX @@ static void superh_cpu_class_init(ObjectClass *oc, void *data) | ||
380 | cc->class_by_name = superh_cpu_class_by_name; | ||
381 | cc->has_work = superh_cpu_has_work; | ||
382 | cc->do_interrupt = superh_cpu_do_interrupt; | ||
383 | - cc->cpu_exec_interrupt = superh_cpu_exec_interrupt; | ||
384 | + cc->tcg_ops.cpu_exec_interrupt = superh_cpu_exec_interrupt; | ||
385 | cc->dump_state = superh_cpu_dump_state; | ||
386 | cc->set_pc = superh_cpu_set_pc; | ||
387 | cc->tcg_ops.synchronize_from_tb = superh_cpu_synchronize_from_tb; | ||
388 | diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c | ||
389 | index XXXXXXX..XXXXXXX 100644 | ||
390 | --- a/target/sparc/cpu.c | ||
391 | +++ b/target/sparc/cpu.c | ||
392 | @@ -XXX,XX +XXX,XX @@ static void sparc_cpu_class_init(ObjectClass *oc, void *data) | ||
393 | cc->parse_features = sparc_cpu_parse_features; | ||
394 | cc->has_work = sparc_cpu_has_work; | ||
395 | cc->do_interrupt = sparc_cpu_do_interrupt; | ||
396 | - cc->cpu_exec_interrupt = sparc_cpu_exec_interrupt; | ||
397 | + cc->tcg_ops.cpu_exec_interrupt = sparc_cpu_exec_interrupt; | ||
398 | cc->dump_state = sparc_cpu_dump_state; | ||
399 | #if !defined(TARGET_SPARC64) && !defined(CONFIG_USER_ONLY) | ||
400 | cc->memory_rw_debug = sparc_cpu_memory_rw_debug; | ||
401 | diff --git a/target/tilegx/cpu.c b/target/tilegx/cpu.c | ||
402 | index XXXXXXX..XXXXXXX 100644 | ||
403 | --- a/target/tilegx/cpu.c | ||
404 | +++ b/target/tilegx/cpu.c | ||
405 | @@ -XXX,XX +XXX,XX @@ static void tilegx_cpu_class_init(ObjectClass *oc, void *data) | ||
406 | cc->class_by_name = tilegx_cpu_class_by_name; | ||
407 | cc->has_work = tilegx_cpu_has_work; | ||
408 | cc->do_interrupt = tilegx_cpu_do_interrupt; | ||
409 | - cc->cpu_exec_interrupt = tilegx_cpu_exec_interrupt; | ||
410 | + cc->tcg_ops.cpu_exec_interrupt = tilegx_cpu_exec_interrupt; | ||
411 | cc->dump_state = tilegx_cpu_dump_state; | ||
412 | cc->set_pc = tilegx_cpu_set_pc; | ||
413 | cc->tlb_fill = tilegx_cpu_tlb_fill; | ||
414 | diff --git a/target/unicore32/cpu.c b/target/unicore32/cpu.c | ||
415 | index XXXXXXX..XXXXXXX 100644 | ||
416 | --- a/target/unicore32/cpu.c | ||
417 | +++ b/target/unicore32/cpu.c | ||
418 | @@ -XXX,XX +XXX,XX @@ static void uc32_cpu_class_init(ObjectClass *oc, void *data) | ||
419 | cc->class_by_name = uc32_cpu_class_by_name; | ||
420 | cc->has_work = uc32_cpu_has_work; | ||
421 | cc->do_interrupt = uc32_cpu_do_interrupt; | ||
422 | - cc->cpu_exec_interrupt = uc32_cpu_exec_interrupt; | ||
423 | + cc->tcg_ops.cpu_exec_interrupt = uc32_cpu_exec_interrupt; | ||
424 | cc->dump_state = uc32_cpu_dump_state; | ||
425 | cc->set_pc = uc32_cpu_set_pc; | ||
426 | cc->tlb_fill = uc32_cpu_tlb_fill; | ||
427 | diff --git a/target/xtensa/cpu.c b/target/xtensa/cpu.c | ||
428 | index XXXXXXX..XXXXXXX 100644 | ||
429 | --- a/target/xtensa/cpu.c | ||
430 | +++ b/target/xtensa/cpu.c | ||
431 | @@ -XXX,XX +XXX,XX @@ static void xtensa_cpu_class_init(ObjectClass *oc, void *data) | ||
432 | cc->class_by_name = xtensa_cpu_class_by_name; | ||
433 | cc->has_work = xtensa_cpu_has_work; | ||
434 | cc->do_interrupt = xtensa_cpu_do_interrupt; | ||
435 | - cc->cpu_exec_interrupt = xtensa_cpu_exec_interrupt; | ||
436 | + cc->tcg_ops.cpu_exec_interrupt = xtensa_cpu_exec_interrupt; | ||
437 | cc->dump_state = xtensa_cpu_dump_state; | ||
438 | cc->set_pc = xtensa_cpu_set_pc; | ||
439 | cc->gdb_read_register = xtensa_cpu_gdb_read_register; | ||
440 | diff --git a/target/ppc/translate_init.c.inc b/target/ppc/translate_init.c.inc | ||
441 | index XXXXXXX..XXXXXXX 100644 | ||
442 | --- a/target/ppc/translate_init.c.inc | ||
443 | +++ b/target/ppc/translate_init.c.inc | ||
444 | @@ -XXX,XX +XXX,XX @@ static void ppc_cpu_reset(DeviceState *dev) | ||
445 | } | 104 | } |
446 | 105 | ||
447 | #ifndef CONFIG_USER_ONLY | 106 | @@ -XXX,XX +XXX,XX @@ static bool fold_xor(OptContext *ctx, TCGOp *op) |
448 | + | 107 | |
449 | static bool ppc_cpu_is_big_endian(CPUState *cs) | 108 | ctx->z_mask = arg_info(op->args[1])->z_mask |
450 | { | 109 | | arg_info(op->args[2])->z_mask; |
451 | PowerPCCPU *cpu = POWERPC_CPU(cs); | 110 | + ctx->s_mask = arg_info(op->args[1])->s_mask |
452 | @@ -XXX,XX +XXX,XX @@ static bool ppc_cpu_is_big_endian(CPUState *cs) | 111 | + & arg_info(op->args[2])->s_mask; |
453 | return !msr_le; | 112 | return fold_masks(ctx, op); |
454 | } | 113 | } |
455 | |||
456 | +#ifdef CONFIG_TCG | ||
457 | static void ppc_cpu_exec_enter(CPUState *cs) | ||
458 | { | ||
459 | PowerPCCPU *cpu = POWERPC_CPU(cs); | ||
460 | @@ -XXX,XX +XXX,XX @@ static void ppc_cpu_exec_exit(CPUState *cs) | ||
461 | vhc->cpu_exec_exit(cpu->vhyp, cpu); | ||
462 | } | ||
463 | } | ||
464 | -#endif | ||
465 | +#endif /* CONFIG_TCG */ | ||
466 | + | ||
467 | +#endif /* !CONFIG_USER_ONLY */ | ||
468 | |||
469 | static void ppc_cpu_instance_init(Object *obj) | ||
470 | { | ||
471 | @@ -XXX,XX +XXX,XX @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data) | ||
472 | cc->class_by_name = ppc_cpu_class_by_name; | ||
473 | cc->has_work = ppc_cpu_has_work; | ||
474 | cc->do_interrupt = ppc_cpu_do_interrupt; | ||
475 | - cc->cpu_exec_interrupt = ppc_cpu_exec_interrupt; | ||
476 | cc->dump_state = ppc_cpu_dump_state; | ||
477 | cc->dump_statistics = ppc_cpu_dump_statistics; | ||
478 | cc->set_pc = ppc_cpu_set_pc; | ||
479 | @@ -XXX,XX +XXX,XX @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data) | ||
480 | #endif | ||
481 | #ifdef CONFIG_TCG | ||
482 | cc->tcg_ops.initialize = ppc_translate_init; | ||
483 | + cc->tcg_ops.cpu_exec_interrupt = ppc_cpu_exec_interrupt; | ||
484 | cc->tlb_fill = ppc_cpu_tlb_fill; | ||
485 | -#endif | ||
486 | #ifndef CONFIG_USER_ONLY | ||
487 | - cc->cpu_exec_enter = ppc_cpu_exec_enter; | ||
488 | - cc->cpu_exec_exit = ppc_cpu_exec_exit; | ||
489 | -#endif | ||
490 | + cc->tcg_ops.cpu_exec_enter = ppc_cpu_exec_enter; | ||
491 | + cc->tcg_ops.cpu_exec_exit = ppc_cpu_exec_exit; | ||
492 | +#endif /* !CONFIG_USER_ONLY */ | ||
493 | +#endif /* CONFIG_TCG */ | ||
494 | |||
495 | cc->disas_set_info = ppc_disas_set_info; | ||
496 | 114 | ||
497 | -- | 115 | -- |
498 | 2.25.1 | 116 | 2.25.1 |
499 | 117 | ||
500 | 118 | diff view generated by jsdifflib |
1 | From: Claudio Fontana <cfontana@suse.de> | 1 | The result is either 0 or 1, which means that we have |
---|---|---|---|
2 | a 2 bit signed result, and thus 62 bits of sign. | ||
3 | For clarity, use the smask_from_zmask function. | ||
2 | 4 | ||
3 | commit 40612000599e ("arm: Correctly handle watchpoints for BE32 CPUs") | ||
4 | |||
5 | introduced this ARM-specific, TCG-specific hack to adjust the address, | ||
6 | before checking it with cpu_check_watchpoint. | ||
7 | |||
8 | Make adjust_watchpoint_address optional and move it to tcg_ops. | ||
9 | |||
10 | Signed-off-by: Claudio Fontana <cfontana@suse.de> | ||
11 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 5 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> |
12 | Message-Id: <20210204163931.7358-14-cfontana@suse.de> | 6 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> |
13 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
14 | --- | 8 | --- |
15 | include/hw/core/cpu.h | 6 +++++- | 9 | tcg/optimize.c | 2 ++ |
16 | hw/core/cpu.c | 6 ------ | 10 | 1 file changed, 2 insertions(+) |
17 | softmmu/physmem.c | 5 ++++- | ||
18 | target/arm/cpu.c | 2 +- | ||
19 | 4 files changed, 10 insertions(+), 9 deletions(-) | ||
20 | 11 | ||
21 | diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h | 12 | diff --git a/tcg/optimize.c b/tcg/optimize.c |
22 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
23 | --- a/include/hw/core/cpu.h | 14 | --- a/tcg/optimize.c |
24 | +++ b/include/hw/core/cpu.h | 15 | +++ b/tcg/optimize.c |
25 | @@ -XXX,XX +XXX,XX @@ typedef struct TcgCpuOperations { | 16 | @@ -XXX,XX +XXX,XX @@ static bool fold_setcond(OptContext *ctx, TCGOp *op) |
26 | void (*do_unaligned_access)(CPUState *cpu, vaddr addr, | 17 | } |
27 | MMUAccessType access_type, | 18 | |
28 | int mmu_idx, uintptr_t retaddr); | 19 | ctx->z_mask = 1; |
29 | + /** | 20 | + ctx->s_mask = smask_from_zmask(1); |
30 | + * @adjust_watchpoint_address: hack for cpu_check_watchpoint used by ARM | 21 | return false; |
31 | + */ | ||
32 | + vaddr (*adjust_watchpoint_address)(CPUState *cpu, vaddr addr, int len); | ||
33 | + | ||
34 | } TcgCpuOperations; | ||
35 | |||
36 | /** | ||
37 | @@ -XXX,XX +XXX,XX @@ struct CPUClass { | ||
38 | const char * (*gdb_get_dynamic_xml)(CPUState *cpu, const char *xmlname); | ||
39 | |||
40 | void (*disas_set_info)(CPUState *cpu, disassemble_info *info); | ||
41 | - vaddr (*adjust_watchpoint_address)(CPUState *cpu, vaddr addr, int len); | ||
42 | |||
43 | const char *deprecation_note; | ||
44 | /* Keep non-pointer data at the end to minimize holes. */ | ||
45 | diff --git a/hw/core/cpu.c b/hw/core/cpu.c | ||
46 | index XXXXXXX..XXXXXXX 100644 | ||
47 | --- a/hw/core/cpu.c | ||
48 | +++ b/hw/core/cpu.c | ||
49 | @@ -XXX,XX +XXX,XX @@ static int64_t cpu_common_get_arch_id(CPUState *cpu) | ||
50 | return cpu->cpu_index; | ||
51 | } | 22 | } |
52 | 23 | ||
53 | -static vaddr cpu_adjust_watchpoint_address(CPUState *cpu, vaddr addr, int len) | 24 | @@ -XXX,XX +XXX,XX @@ static bool fold_setcond2(OptContext *ctx, TCGOp *op) |
54 | -{ | ||
55 | - return addr; | ||
56 | -} | ||
57 | - | ||
58 | static Property cpu_common_props[] = { | ||
59 | #ifndef CONFIG_USER_ONLY | ||
60 | /* Create a memory property for softmmu CPU object, | ||
61 | @@ -XXX,XX +XXX,XX @@ static void cpu_class_init(ObjectClass *klass, void *data) | ||
62 | k->gdb_write_register = cpu_common_gdb_write_register; | ||
63 | k->virtio_is_big_endian = cpu_common_virtio_is_big_endian; | ||
64 | k->debug_check_watchpoint = cpu_common_debug_check_watchpoint; | ||
65 | - k->adjust_watchpoint_address = cpu_adjust_watchpoint_address; | ||
66 | set_bit(DEVICE_CATEGORY_CPU, dc->categories); | ||
67 | dc->realize = cpu_common_realizefn; | ||
68 | dc->unrealize = cpu_common_unrealizefn; | ||
69 | diff --git a/softmmu/physmem.c b/softmmu/physmem.c | ||
70 | index XXXXXXX..XXXXXXX 100644 | ||
71 | --- a/softmmu/physmem.c | ||
72 | +++ b/softmmu/physmem.c | ||
73 | @@ -XXX,XX +XXX,XX @@ void cpu_check_watchpoint(CPUState *cpu, vaddr addr, vaddr len, | ||
74 | return; | ||
75 | } | 25 | } |
76 | 26 | ||
77 | - addr = cc->adjust_watchpoint_address(cpu, addr, len); | 27 | ctx->z_mask = 1; |
78 | + if (cc->tcg_ops.adjust_watchpoint_address) { | 28 | + ctx->s_mask = smask_from_zmask(1); |
79 | + /* this is currently used only by ARM BE32 */ | 29 | return false; |
80 | + addr = cc->tcg_ops.adjust_watchpoint_address(cpu, addr, len); | 30 | |
81 | + } | 31 | do_setcond_const: |
82 | QTAILQ_FOREACH(wp, &cpu->watchpoints, entry) { | ||
83 | if (watchpoint_address_matches(wp, addr, len) | ||
84 | && (wp->flags & flags)) { | ||
85 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | ||
86 | index XXXXXXX..XXXXXXX 100644 | ||
87 | --- a/target/arm/cpu.c | ||
88 | +++ b/target/arm/cpu.c | ||
89 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_class_init(ObjectClass *oc, void *data) | ||
90 | #if !defined(CONFIG_USER_ONLY) | ||
91 | cc->tcg_ops.do_transaction_failed = arm_cpu_do_transaction_failed; | ||
92 | cc->tcg_ops.do_unaligned_access = arm_cpu_do_unaligned_access; | ||
93 | - cc->adjust_watchpoint_address = arm_adjust_watchpoint_address; | ||
94 | + cc->tcg_ops.adjust_watchpoint_address = arm_adjust_watchpoint_address; | ||
95 | cc->tcg_ops.do_interrupt = arm_cpu_do_interrupt; | ||
96 | #endif /* CONFIG_TCG && !CONFIG_USER_ONLY */ | ||
97 | #endif /* CONFIG_TCG */ | ||
98 | -- | 32 | -- |
99 | 2.25.1 | 33 | 2.25.1 |
100 | 34 | ||
101 | 35 | diff view generated by jsdifflib |
1 | Fixes INDEX_op_rotli_vec for aarch64 host, where the 3rd | 1 | The results are generally 6 bit unsigned values, though |
---|---|---|---|
2 | argument is an integer, not a temporary, which now tickles | 2 | the count leading and trailing bits may produce any value |
3 | an assert added in e89b28a6350. | 3 | for a zero input. |
4 | 4 | ||
5 | Previously, the value computed into v2 would be garbage for | 5 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> |
6 | rotli_vec, but as the value was unused it caused no harm. | 6 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> |
7 | |||
8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
9 | --- | 8 | --- |
10 | tcg/aarch64/tcg-target.c.inc | 7 ++++--- | 9 | tcg/optimize.c | 3 ++- |
11 | 1 file changed, 4 insertions(+), 3 deletions(-) | 10 | 1 file changed, 2 insertions(+), 1 deletion(-) |
12 | 11 | ||
13 | diff --git a/tcg/aarch64/tcg-target.c.inc b/tcg/aarch64/tcg-target.c.inc | 12 | diff --git a/tcg/optimize.c b/tcg/optimize.c |
14 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/tcg/aarch64/tcg-target.c.inc | 14 | --- a/tcg/optimize.c |
16 | +++ b/tcg/aarch64/tcg-target.c.inc | 15 | +++ b/tcg/optimize.c |
17 | @@ -XXX,XX +XXX,XX @@ void tcg_expand_vec_op(TCGOpcode opc, TCGType type, unsigned vece, | 16 | @@ -XXX,XX +XXX,XX @@ static bool fold_count_zeros(OptContext *ctx, TCGOp *op) |
18 | v0 = temp_tcgv_vec(arg_temp(a0)); | 17 | g_assert_not_reached(); |
19 | v1 = temp_tcgv_vec(arg_temp(va_arg(va, TCGArg))); | 18 | } |
20 | a2 = va_arg(va, TCGArg); | 19 | ctx->z_mask = arg_info(op->args[2])->z_mask | z_mask; |
21 | - v2 = temp_tcgv_vec(arg_temp(a2)); | 20 | - |
22 | + va_end(va); | 21 | + ctx->s_mask = smask_from_zmask(ctx->z_mask); |
23 | 22 | return false; | |
24 | switch (opc) { | 23 | } |
25 | case INDEX_op_rotli_vec: | 24 | |
26 | @@ -XXX,XX +XXX,XX @@ void tcg_expand_vec_op(TCGOpcode opc, TCGType type, unsigned vece, | 25 | @@ -XXX,XX +XXX,XX @@ static bool fold_ctpop(OptContext *ctx, TCGOp *op) |
27 | case INDEX_op_shrv_vec: | ||
28 | case INDEX_op_sarv_vec: | ||
29 | /* Right shifts are negative left shifts for AArch64. */ | ||
30 | + v2 = temp_tcgv_vec(arg_temp(a2)); | ||
31 | t1 = tcg_temp_new_vec(type); | ||
32 | tcg_gen_neg_vec(vece, t1, v2); | ||
33 | opc = (opc == INDEX_op_shrv_vec | ||
34 | @@ -XXX,XX +XXX,XX @@ void tcg_expand_vec_op(TCGOpcode opc, TCGType type, unsigned vece, | ||
35 | break; | ||
36 | |||
37 | case INDEX_op_rotlv_vec: | ||
38 | + v2 = temp_tcgv_vec(arg_temp(a2)); | ||
39 | t1 = tcg_temp_new_vec(type); | ||
40 | c1 = tcg_constant_vec(type, vece, 8 << vece); | ||
41 | tcg_gen_sub_vec(vece, t1, v2, c1); | ||
42 | @@ -XXX,XX +XXX,XX @@ void tcg_expand_vec_op(TCGOpcode opc, TCGType type, unsigned vece, | ||
43 | break; | ||
44 | |||
45 | case INDEX_op_rotrv_vec: | ||
46 | + v2 = temp_tcgv_vec(arg_temp(a2)); | ||
47 | t1 = tcg_temp_new_vec(type); | ||
48 | t2 = tcg_temp_new_vec(type); | ||
49 | c1 = tcg_constant_vec(type, vece, 8 << vece); | ||
50 | @@ -XXX,XX +XXX,XX @@ void tcg_expand_vec_op(TCGOpcode opc, TCGType type, unsigned vece, | ||
51 | default: | 26 | default: |
52 | g_assert_not_reached(); | 27 | g_assert_not_reached(); |
53 | } | 28 | } |
54 | - | 29 | + ctx->s_mask = smask_from_zmask(ctx->z_mask); |
55 | - va_end(va); | 30 | return false; |
56 | } | 31 | } |
57 | 32 | ||
58 | static TCGConstraintSetIndex tcg_target_op_def(TCGOpcode op) | ||
59 | -- | 33 | -- |
60 | 2.25.1 | 34 | 2.25.1 |
61 | 35 | ||
62 | 36 | diff view generated by jsdifflib |
1 | As noted in several comments, 8 regs is not enough for 32-bit | 1 | For constant shifts, we can simply shift the s_mask. |
---|---|---|---|
2 | to perform calls, as currently implemented. Shortly, we will | 2 | |
3 | rearrange the encoding which will make 32 regs impossible. | 3 | For variable shifts, we know that sar does not reduce |
4 | the s_mask, which helps for sequences like | ||
5 | |||
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. | ||
4 | 11 | ||
5 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 12 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> |
13 | Reviewed-by: Luis Pires <luis.pires@eldorado.org.br> | ||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 14 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
7 | --- | 15 | --- |
8 | tcg/tci/tcg-target.h | 32 +++++--------------------------- | 16 | tcg/optimize.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++--- |
9 | tcg/tci/tcg-target.c.inc | 26 -------------------------- | 17 | 1 file changed, 47 insertions(+), 3 deletions(-) |
10 | 2 files changed, 5 insertions(+), 53 deletions(-) | ||
11 | 18 | ||
12 | diff --git a/tcg/tci/tcg-target.h b/tcg/tci/tcg-target.h | 19 | diff --git a/tcg/optimize.c b/tcg/optimize.c |
13 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/tcg/tci/tcg-target.h | 21 | --- a/tcg/optimize.c |
15 | +++ b/tcg/tci/tcg-target.h | 22 | +++ b/tcg/optimize.c |
16 | @@ -XXX,XX +XXX,XX @@ | 23 | @@ -XXX,XX +XXX,XX @@ static uint64_t smask_from_zmask(uint64_t zmask) |
17 | #define TCG_TARGET_HAS_mulu2_i32 1 | 24 | return ~(~0ull >> rep); |
18 | #endif /* TCG_TARGET_REG_BITS == 64 */ | 25 | } |
19 | 26 | ||
20 | -/* Number of registers available. | 27 | +/* |
21 | - For 32 bit hosts, we need more than 8 registers (call arguments). */ | 28 | + * Recreate a properly left-aligned smask after manipulation. |
22 | -/* #define TCG_TARGET_NB_REGS 8 */ | 29 | + * Some bit-shuffling, particularly shifts and rotates, may |
23 | +/* Number of registers available. */ | 30 | + * retain sign bits on the left, but may scatter disconnected |
24 | #define TCG_TARGET_NB_REGS 16 | 31 | + * sign bits on the right. Retain only what remains to the left. |
25 | -/* #define TCG_TARGET_NB_REGS 32 */ | 32 | + */ |
26 | 33 | +static uint64_t smask_from_smask(int64_t smask) | |
27 | /* List of registers which are used by TCG. */ | 34 | +{ |
28 | typedef enum { | 35 | + /* Only the 1 bits are significant for smask */ |
29 | @@ -XXX,XX +XXX,XX @@ typedef enum { | 36 | + return smask_from_zmask(~smask); |
30 | TCG_REG_R5, | 37 | +} |
31 | TCG_REG_R6, | ||
32 | TCG_REG_R7, | ||
33 | -#if TCG_TARGET_NB_REGS >= 16 | ||
34 | TCG_REG_R8, | ||
35 | TCG_REG_R9, | ||
36 | TCG_REG_R10, | ||
37 | @@ -XXX,XX +XXX,XX @@ typedef enum { | ||
38 | TCG_REG_R13, | ||
39 | TCG_REG_R14, | ||
40 | TCG_REG_R15, | ||
41 | -#if TCG_TARGET_NB_REGS >= 32 | ||
42 | - TCG_REG_R16, | ||
43 | - TCG_REG_R17, | ||
44 | - TCG_REG_R18, | ||
45 | - TCG_REG_R19, | ||
46 | - TCG_REG_R20, | ||
47 | - TCG_REG_R21, | ||
48 | - TCG_REG_R22, | ||
49 | - TCG_REG_R23, | ||
50 | - TCG_REG_R24, | ||
51 | - TCG_REG_R25, | ||
52 | - TCG_REG_R26, | ||
53 | - TCG_REG_R27, | ||
54 | - TCG_REG_R28, | ||
55 | - TCG_REG_R29, | ||
56 | - TCG_REG_R30, | ||
57 | - TCG_REG_R31, | ||
58 | -#endif | ||
59 | -#endif | ||
60 | + | 38 | + |
61 | + TCG_AREG0 = TCG_REG_R14, | 39 | static inline TempOptInfo *ts_info(TCGTemp *ts) |
62 | + TCG_REG_CALL_STACK = TCG_REG_R15, | 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; | ||
63 | + | 47 | + |
64 | /* Special value UINT8_MAX is used by TCI to encode constant values. */ | 48 | if (fold_const2(ctx, op) || |
65 | TCG_CONST = UINT8_MAX | 49 | fold_ix_to_i(ctx, op, 0) || |
66 | } TCGReg; | 50 | fold_xi_to_x(ctx, op, 0)) { |
67 | 51 | return true; | |
68 | -#define TCG_AREG0 (TCG_TARGET_NB_REGS - 2) | 52 | } |
69 | - | 53 | |
70 | /* Used for function call generation. */ | 54 | + s_mask = arg_info(op->args[1])->s_mask; |
71 | -#define TCG_REG_CALL_STACK (TCG_TARGET_NB_REGS - 1) | 55 | + z_mask = arg_info(op->args[1])->z_mask; |
72 | #define TCG_TARGET_CALL_STACK_OFFSET 0 | 56 | + |
73 | #define TCG_TARGET_STACK_ALIGN 16 | 57 | if (arg_is_const(op->args[2])) { |
74 | 58 | - ctx->z_mask = do_constant_folding(op->opc, ctx->type, | |
75 | diff --git a/tcg/tci/tcg-target.c.inc b/tcg/tci/tcg-target.c.inc | 59 | - arg_info(op->args[1])->z_mask, |
76 | index XXXXXXX..XXXXXXX 100644 | 60 | - arg_info(op->args[2])->val); |
77 | --- a/tcg/tci/tcg-target.c.inc | 61 | + int sh = arg_info(op->args[2])->val; |
78 | +++ b/tcg/tci/tcg-target.c.inc | 62 | + |
79 | @@ -XXX,XX +XXX,XX @@ static const int tcg_target_reg_alloc_order[] = { | 63 | + ctx->z_mask = do_constant_folding(op->opc, ctx->type, z_mask, sh); |
80 | TCG_REG_R5, | 64 | + |
81 | TCG_REG_R6, | 65 | + s_mask = do_constant_folding(op->opc, ctx->type, s_mask, sh); |
82 | TCG_REG_R7, | 66 | + ctx->s_mask = smask_from_smask(s_mask); |
83 | -#if TCG_TARGET_NB_REGS >= 16 | 67 | + |
84 | TCG_REG_R8, | 68 | return fold_masks(ctx, op); |
85 | TCG_REG_R9, | 69 | } |
86 | TCG_REG_R10, | 70 | + |
87 | @@ -XXX,XX +XXX,XX @@ static const int tcg_target_reg_alloc_order[] = { | 71 | + switch (op->opc) { |
88 | TCG_REG_R13, | 72 | + CASE_OP_32_64(sar): |
89 | TCG_REG_R14, | 73 | + /* |
90 | TCG_REG_R15, | 74 | + * Arithmetic right shift will not reduce the number of |
91 | -#endif | 75 | + * input sign repetitions. |
92 | }; | 76 | + */ |
93 | 77 | + ctx->s_mask = s_mask; | |
94 | #if MAX_OPC_PARAM_IARGS != 6 | 78 | + break; |
95 | @@ -XXX,XX +XXX,XX @@ static const int tcg_target_call_iarg_regs[] = { | 79 | + CASE_OP_32_64(shr): |
96 | #if TCG_TARGET_REG_BITS == 32 | 80 | + /* |
97 | /* 32 bit hosts need 2 * MAX_OPC_PARAM_IARGS registers. */ | 81 | + * If the sign bit is known zero, then logical right shift |
98 | TCG_REG_R7, | 82 | + * will not reduced the number of input sign repetitions. |
99 | -#if TCG_TARGET_NB_REGS >= 16 | 83 | + */ |
100 | TCG_REG_R8, | 84 | + sign = (s_mask & -s_mask) >> 1; |
101 | TCG_REG_R9, | 85 | + if (!(z_mask & sign)) { |
102 | TCG_REG_R10, | 86 | + ctx->s_mask = s_mask; |
103 | TCG_REG_R11, | 87 | + } |
104 | TCG_REG_R12, | 88 | + break; |
105 | -#else | 89 | + default: |
106 | -# error Too few input registers available | 90 | + break; |
107 | -#endif | 91 | + } |
108 | #endif | 92 | + |
109 | }; | 93 | return false; |
110 | 94 | } | |
111 | @@ -XXX,XX +XXX,XX @@ static const char *const tcg_target_reg_names[TCG_TARGET_NB_REGS] = { | ||
112 | "r05", | ||
113 | "r06", | ||
114 | "r07", | ||
115 | -#if TCG_TARGET_NB_REGS >= 16 | ||
116 | "r08", | ||
117 | "r09", | ||
118 | "r10", | ||
119 | @@ -XXX,XX +XXX,XX @@ static const char *const tcg_target_reg_names[TCG_TARGET_NB_REGS] = { | ||
120 | "r13", | ||
121 | "r14", | ||
122 | "r15", | ||
123 | -#if TCG_TARGET_NB_REGS >= 32 | ||
124 | - "r16", | ||
125 | - "r17", | ||
126 | - "r18", | ||
127 | - "r19", | ||
128 | - "r20", | ||
129 | - "r21", | ||
130 | - "r22", | ||
131 | - "r23", | ||
132 | - "r24", | ||
133 | - "r25", | ||
134 | - "r26", | ||
135 | - "r27", | ||
136 | - "r28", | ||
137 | - "r29", | ||
138 | - "r30", | ||
139 | - "r31" | ||
140 | -#endif | ||
141 | -#endif | ||
142 | }; | ||
143 | #endif | ||
144 | 95 | ||
145 | -- | 96 | -- |
146 | 2.25.1 | 97 | 2.25.1 |
147 | 98 | ||
148 | 99 | diff view generated by jsdifflib |