1
The following changes since commit 2ecfc0657afa5d29a373271b342f704a1a3c6737:
1
The following changes since commit 45240eed4f064576d589ea60ebadf3c11d7ab891:
2
2
3
Merge remote-tracking branch 'remotes/armbru/tags/pull-misc-2020-12-10' into staging (2020-12-10 17:01:05 +0000)
3
Merge remote-tracking branch 'remotes/armbru/tags/pull-yank-2021-01-13' into staging (2021-01-13 14:19:24 +0000)
4
4
5
are available in the Git repository at:
5
are available in the Git repository at:
6
6
7
https://gitlab.com/rth7680/qemu.git tags/pull-tcg-20201210
7
https://gitlab.com/rth7680/qemu.git tags/pull-tcg-20210113
8
8
9
for you to fetch changes up to 9e2658d62ebc23efe7df43fc0e306f129510d874:
9
for you to fetch changes up to 4cacecaaa2bbf8af0967bd3eee43297fada475a9:
10
10
11
accel/tcg: rename tcg-cpus functions to match module name (2020-12-10 17:44:10 -0600)
11
decodetree: Open files with encoding='utf-8' (2021-01-13 08:39:08 -1000)
12
12
13
----------------------------------------------------------------
13
----------------------------------------------------------------
14
Split CpusAccel for tcg variants
14
Improvements to tcg constant handling.
15
Force utf8 for decodetree.
15
16
16
----------------------------------------------------------------
17
----------------------------------------------------------------
17
Claudio Fontana (3):
18
Philippe Mathieu-Daudé (1):
18
accel/tcg: split CpusAccel into three TCG variants
19
decodetree: Open files with encoding='utf-8'
19
accel/tcg: split tcg_start_vcpu_thread
20
accel/tcg: rename tcg-cpus functions to match module name
21
20
22
accel/tcg/tcg-cpus-icount.h | 17 ++
21
Richard Henderson (23):
23
accel/tcg/tcg-cpus-rr.h | 21 ++
22
tcg: Use tcg_out_dupi_vec from temp_load
24
accel/tcg/tcg-cpus.h | 12 +-
23
tcg: Increase tcg_out_dupi_vec immediate to int64_t
25
accel/tcg/tcg-all.c | 13 +-
24
tcg: Consolidate 3 bits into enum TCGTempKind
26
accel/tcg/tcg-cpus-icount.c | 147 +++++++++++++
25
tcg: Add temp_readonly
27
accel/tcg/tcg-cpus-mttcg.c | 140 ++++++++++++
26
tcg: Expand TCGTemp.val to 64-bits
28
accel/tcg/tcg-cpus-rr.c | 305 ++++++++++++++++++++++++++
27
tcg: Rename struct tcg_temp_info to TempOptInfo
29
accel/tcg/tcg-cpus.c | 506 +-------------------------------------------
28
tcg: Expand TempOptInfo to 64-bits
30
softmmu/icount.c | 2 +-
29
tcg: Introduce TYPE_CONST temporaries
31
accel/tcg/meson.build | 9 +-
30
tcg/optimize: Improve find_better_copy
32
10 files changed, 670 insertions(+), 502 deletions(-)
31
tcg/optimize: Adjust TempOptInfo allocation
33
create mode 100644 accel/tcg/tcg-cpus-icount.h
32
tcg/optimize: Use tcg_constant_internal with constant folding
34
create mode 100644 accel/tcg/tcg-cpus-rr.h
33
tcg: Convert tcg_gen_dupi_vec to TCG_CONST
35
create mode 100644 accel/tcg/tcg-cpus-icount.c
34
tcg: Use tcg_constant_i32 with icount expander
36
create mode 100644 accel/tcg/tcg-cpus-mttcg.c
35
tcg: Use tcg_constant_{i32,i64} with tcg int expanders
37
create mode 100644 accel/tcg/tcg-cpus-rr.c
36
tcg: Use tcg_constant_{i32,i64} with tcg plugins
37
tcg: Use tcg_constant_{i32,i64,vec} with gvec expanders
38
tcg/tci: Add special tci_movi_{i32,i64} opcodes
39
tcg: Remove movi and dupi opcodes
40
tcg: Add tcg_reg_alloc_dup2
41
tcg/i386: Use tcg_constant_vec with tcg vec expanders
42
tcg: Remove tcg_gen_dup{8,16,32,64}i_vec
43
tcg/ppc: Use tcg_constant_vec with tcg vec expanders
44
tcg/aarch64: Use tcg_constant_vec with tcg vec expanders
38
45
46
include/exec/gen-icount.h | 25 +--
47
include/tcg/tcg-op.h | 17 +-
48
include/tcg/tcg-opc.h | 11 +-
49
include/tcg/tcg.h | 50 ++++-
50
accel/tcg/plugin-gen.c | 49 ++---
51
tcg/optimize.c | 249 +++++++++++-----------
52
tcg/tcg-op-gvec.c | 129 +++++-------
53
tcg/tcg-op-vec.c | 52 +----
54
tcg/tcg-op.c | 227 ++++++++++----------
55
tcg/tcg.c | 488 +++++++++++++++++++++++++++++++++----------
56
tcg/tci.c | 4 +-
57
tcg/aarch64/tcg-target.c.inc | 32 +--
58
tcg/arm/tcg-target.c.inc | 1 -
59
tcg/i386/tcg-target.c.inc | 112 ++++++----
60
tcg/mips/tcg-target.c.inc | 2 -
61
tcg/ppc/tcg-target.c.inc | 90 ++++----
62
tcg/riscv/tcg-target.c.inc | 2 -
63
tcg/s390/tcg-target.c.inc | 2 -
64
tcg/sparc/tcg-target.c.inc | 2 -
65
tcg/tci/tcg-target.c.inc | 6 +-
66
scripts/decodetree.py | 9 +-
67
21 files changed, 890 insertions(+), 669 deletions(-)
68
diff view generated by jsdifflib
1
From: Claudio Fontana <cfontana@suse.de>
1
Having dupi pass though movi is confusing and arguably wrong.
2
2
3
after the initial split into 3 tcg variants, we proceed to also
3
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
4
split tcg_start_vcpu_thread.
5
6
We actually split it in 2 this time, since the icount variant
7
just uses the round robin function.
8
9
Suggested-by: Richard Henderson <richard.henderson@linaro.org>
10
Signed-off-by: Claudio Fontana <cfontana@suse.de>
11
Message-Id: <20201015143217.29337-3-cfontana@suse.de>
12
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
4
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
13
---
5
---
14
accel/tcg/tcg-cpus-mttcg.h | 21 --------------
6
tcg/tcg.c | 6 +++-
15
accel/tcg/tcg-cpus-rr.h | 3 +-
7
tcg/aarch64/tcg-target.c.inc | 7 ----
16
accel/tcg/tcg-cpus.h | 1 -
8
tcg/i386/tcg-target.c.inc | 63 ++++++++++++++++++++++++------------
17
accel/tcg/tcg-all.c | 5 ++++
9
tcg/ppc/tcg-target.c.inc | 6 ----
18
accel/tcg/tcg-cpus-icount.c | 2 +-
10
4 files changed, 47 insertions(+), 35 deletions(-)
19
accel/tcg/tcg-cpus-mttcg.c | 29 +++++++++++++++++--
20
accel/tcg/tcg-cpus-rr.c | 39 +++++++++++++++++++++++--
21
accel/tcg/tcg-cpus.c | 58 -------------------------------------
22
8 files changed, 71 insertions(+), 87 deletions(-)
23
delete mode 100644 accel/tcg/tcg-cpus-mttcg.h
24
11
25
diff --git a/accel/tcg/tcg-cpus-mttcg.h b/accel/tcg/tcg-cpus-mttcg.h
12
diff --git a/tcg/tcg.c b/tcg/tcg.c
26
deleted file mode 100644
13
index XXXXXXX..XXXXXXX 100644
27
index XXXXXXX..XXXXXXX
14
--- a/tcg/tcg.c
28
--- a/accel/tcg/tcg-cpus-mttcg.h
15
+++ b/tcg/tcg.c
29
+++ /dev/null
16
@@ -XXX,XX +XXX,XX @@ static void temp_load(TCGContext *s, TCGTemp *ts, TCGRegSet desired_regs,
30
@@ -XXX,XX +XXX,XX @@
17
case TEMP_VAL_CONST:
31
-/*
18
reg = tcg_reg_alloc(s, desired_regs, allocated_regs,
32
- * QEMU TCG Multi Threaded vCPUs implementation
19
preferred_regs, ts->indirect_base);
33
- *
20
- tcg_out_movi(s, ts->type, reg, ts->val);
34
- * Copyright 2020 SUSE LLC
21
+ if (ts->type <= TCG_TYPE_I64) {
35
- *
22
+ tcg_out_movi(s, ts->type, reg, ts->val);
36
- * This work is licensed under the terms of the GNU GPL, version 2 or later.
23
+ } else {
37
- * See the COPYING file in the top-level directory.
24
+ tcg_out_dupi_vec(s, ts->type, reg, ts->val);
38
- */
25
+ }
26
ts->mem_coherent = 0;
27
break;
28
case TEMP_VAL_MEM:
29
diff --git a/tcg/aarch64/tcg-target.c.inc b/tcg/aarch64/tcg-target.c.inc
30
index XXXXXXX..XXXXXXX 100644
31
--- a/tcg/aarch64/tcg-target.c.inc
32
+++ b/tcg/aarch64/tcg-target.c.inc
33
@@ -XXX,XX +XXX,XX @@ static void tcg_out_movi(TCGContext *s, TCGType type, TCGReg rd,
34
case TCG_TYPE_I64:
35
tcg_debug_assert(rd < 32);
36
break;
39
-
37
-
40
-#ifndef TCG_CPUS_MTTCG_H
38
- case TCG_TYPE_V64:
41
-#define TCG_CPUS_MTTCG_H
39
- case TCG_TYPE_V128:
40
- tcg_debug_assert(rd >= 32);
41
- tcg_out_dupi_vec(s, type, rd, value);
42
- return;
42
-
43
-
43
-/*
44
default:
44
- * In the multi-threaded case each vCPU has its own thread. The TLS
45
g_assert_not_reached();
45
- * variable current_cpu can be used deep in the code to find the
46
}
46
- * current CPUState for a given thread.
47
diff --git a/tcg/i386/tcg-target.c.inc b/tcg/i386/tcg-target.c.inc
47
- */
48
-
49
-void *tcg_cpu_thread_fn(void *arg);
50
-
51
-#endif /* TCG_CPUS_MTTCG_H */
52
diff --git a/accel/tcg/tcg-cpus-rr.h b/accel/tcg/tcg-cpus-rr.h
53
index XXXXXXX..XXXXXXX 100644
48
index XXXXXXX..XXXXXXX 100644
54
--- a/accel/tcg/tcg-cpus-rr.h
49
--- a/tcg/i386/tcg-target.c.inc
55
+++ b/accel/tcg/tcg-cpus-rr.h
50
+++ b/tcg/i386/tcg-target.c.inc
56
@@ -XXX,XX +XXX,XX @@
51
@@ -XXX,XX +XXX,XX @@ static void tcg_out_dupi_vec(TCGContext *s, TCGType type,
57
/* Kick all RR vCPUs. */
52
}
58
void qemu_cpu_kick_rr_cpus(CPUState *unused);
53
}
59
54
60
-void *tcg_rr_cpu_thread_fn(void *arg);
55
-static void tcg_out_movi(TCGContext *s, TCGType type,
61
+/* start the round robin vcpu thread */
56
- TCGReg ret, tcg_target_long arg)
62
+void rr_start_vcpu_thread(CPUState *cpu);
57
+static void tcg_out_movi_vec(TCGContext *s, TCGType type,
63
58
+ TCGReg ret, tcg_target_long arg)
64
#endif /* TCG_CPUS_RR_H */
59
+{
65
diff --git a/accel/tcg/tcg-cpus.h b/accel/tcg/tcg-cpus.h
60
+ if (arg == 0) {
66
index XXXXXXX..XXXXXXX 100644
61
+ tcg_out_vex_modrm(s, OPC_PXOR, ret, ret, ret);
67
--- a/accel/tcg/tcg-cpus.h
62
+ return;
68
+++ b/accel/tcg/tcg-cpus.h
63
+ }
69
@@ -XXX,XX +XXX,XX @@ extern const CpusAccel tcg_cpus_mttcg;
64
+ if (arg == -1) {
70
extern const CpusAccel tcg_cpus_icount;
65
+ tcg_out_vex_modrm(s, OPC_PCMPEQB, ret, ret, ret);
71
extern const CpusAccel tcg_cpus_rr;
66
+ return;
72
67
+ }
73
-void tcg_start_vcpu_thread(CPUState *cpu);
74
void qemu_tcg_destroy_vcpu(CPUState *cpu);
75
int tcg_cpu_exec(CPUState *cpu);
76
void tcg_handle_interrupt(CPUState *cpu, int mask);
77
diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c
78
index XXXXXXX..XXXXXXX 100644
79
--- a/accel/tcg/tcg-all.c
80
+++ b/accel/tcg/tcg-all.c
81
@@ -XXX,XX +XXX,XX @@ static int tcg_init(MachineState *ms)
82
tcg_exec_init(s->tb_size * 1024 * 1024);
83
mttcg_enabled = s->mttcg_enabled;
84
85
+ /*
86
+ * Initialize TCG regions
87
+ */
88
+ tcg_region_init();
89
+
68
+
90
if (mttcg_enabled) {
69
+ int rexw = (type == TCG_TYPE_I32 ? 0 : P_REXW);
91
cpus_register_accel(&tcg_cpus_mttcg);
70
+ tcg_out_vex_modrm_pool(s, OPC_MOVD_VyEy + rexw, ret);
92
} else if (icount_enabled()) {
71
+ if (TCG_TARGET_REG_BITS == 64) {
93
diff --git a/accel/tcg/tcg-cpus-icount.c b/accel/tcg/tcg-cpus-icount.c
72
+ new_pool_label(s, arg, R_386_PC32, s->code_ptr - 4, -4);
94
index XXXXXXX..XXXXXXX 100644
95
--- a/accel/tcg/tcg-cpus-icount.c
96
+++ b/accel/tcg/tcg-cpus-icount.c
97
@@ -XXX,XX +XXX,XX @@ static void icount_handle_interrupt(CPUState *cpu, int mask)
98
}
99
100
const CpusAccel tcg_cpus_icount = {
101
- .create_vcpu_thread = tcg_start_vcpu_thread,
102
+ .create_vcpu_thread = rr_start_vcpu_thread,
103
.kick_vcpu_thread = qemu_cpu_kick_rr_cpus,
104
105
.handle_interrupt = icount_handle_interrupt,
106
diff --git a/accel/tcg/tcg-cpus-mttcg.c b/accel/tcg/tcg-cpus-mttcg.c
107
index XXXXXXX..XXXXXXX 100644
108
--- a/accel/tcg/tcg-cpus-mttcg.c
109
+++ b/accel/tcg/tcg-cpus-mttcg.c
110
@@ -XXX,XX +XXX,XX @@
111
#include "hw/boards.h"
112
113
#include "tcg-cpus.h"
114
-#include "tcg-cpus-mttcg.h"
115
116
/*
117
* In the multi-threaded case each vCPU has its own thread. The TLS
118
@@ -XXX,XX +XXX,XX @@
119
* current CPUState for a given thread.
120
*/
121
122
-void *tcg_cpu_thread_fn(void *arg)
123
+static void *tcg_cpu_thread_fn(void *arg)
124
{
125
CPUState *cpu = arg;
126
127
@@ -XXX,XX +XXX,XX @@ static void mttcg_kick_vcpu_thread(CPUState *cpu)
128
cpu_exit(cpu);
129
}
130
131
+static void mttcg_start_vcpu_thread(CPUState *cpu)
132
+{
133
+ char thread_name[VCPU_THREAD_NAME_SIZE];
134
+
135
+ g_assert(tcg_enabled());
136
+
137
+ parallel_cpus = (current_machine->smp.max_cpus > 1);
138
+
139
+ cpu->thread = g_malloc0(sizeof(QemuThread));
140
+ cpu->halt_cond = g_malloc0(sizeof(QemuCond));
141
+ qemu_cond_init(cpu->halt_cond);
142
+
143
+ /* create a thread per vCPU with TCG (MTTCG) */
144
+ snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/TCG",
145
+ cpu->cpu_index);
146
+
147
+ qemu_thread_create(cpu->thread, thread_name, tcg_cpu_thread_fn,
148
+ cpu, QEMU_THREAD_JOINABLE);
149
+
150
+#ifdef _WIN32
151
+ cpu->hThread = qemu_thread_get_handle(cpu->thread);
152
+#endif
153
+}
154
+
155
const CpusAccel tcg_cpus_mttcg = {
156
- .create_vcpu_thread = tcg_start_vcpu_thread,
157
+ .create_vcpu_thread = mttcg_start_vcpu_thread,
158
.kick_vcpu_thread = mttcg_kick_vcpu_thread,
159
160
.handle_interrupt = tcg_handle_interrupt,
161
diff --git a/accel/tcg/tcg-cpus-rr.c b/accel/tcg/tcg-cpus-rr.c
162
index XXXXXXX..XXXXXXX 100644
163
--- a/accel/tcg/tcg-cpus-rr.c
164
+++ b/accel/tcg/tcg-cpus-rr.c
165
@@ -XXX,XX +XXX,XX @@ static void deal_with_unplugged_cpus(void)
166
* elsewhere.
167
*/
168
169
-void *tcg_rr_cpu_thread_fn(void *arg)
170
+static void *tcg_rr_cpu_thread_fn(void *arg)
171
{
172
CPUState *cpu = arg;
173
174
@@ -XXX,XX +XXX,XX @@ void *tcg_rr_cpu_thread_fn(void *arg)
175
return NULL;
176
}
177
178
+void rr_start_vcpu_thread(CPUState *cpu)
179
+{
180
+ char thread_name[VCPU_THREAD_NAME_SIZE];
181
+ static QemuCond *single_tcg_halt_cond;
182
+ static QemuThread *single_tcg_cpu_thread;
183
+
184
+ g_assert(tcg_enabled());
185
+ parallel_cpus = false;
186
+
187
+ if (!single_tcg_cpu_thread) {
188
+ cpu->thread = g_malloc0(sizeof(QemuThread));
189
+ cpu->halt_cond = g_malloc0(sizeof(QemuCond));
190
+ qemu_cond_init(cpu->halt_cond);
191
+
192
+ /* share a single thread for all cpus with TCG */
193
+ snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "ALL CPUs/TCG");
194
+ qemu_thread_create(cpu->thread, thread_name,
195
+ tcg_rr_cpu_thread_fn,
196
+ cpu, QEMU_THREAD_JOINABLE);
197
+
198
+ single_tcg_halt_cond = cpu->halt_cond;
199
+ single_tcg_cpu_thread = cpu->thread;
200
+#ifdef _WIN32
201
+ cpu->hThread = qemu_thread_get_handle(cpu->thread);
202
+#endif
203
+ } else {
73
+ } else {
204
+ /* we share the thread */
74
+ new_pool_label(s, arg, R_386_32, s->code_ptr - 4, 0);
205
+ cpu->thread = single_tcg_cpu_thread;
206
+ cpu->halt_cond = single_tcg_halt_cond;
207
+ cpu->thread_id = first_cpu->thread_id;
208
+ cpu->can_do_io = 1;
209
+ cpu->created = true;
210
+ }
75
+ }
211
+}
76
+}
212
+
77
+
213
const CpusAccel tcg_cpus_rr = {
78
+static void tcg_out_movi_int(TCGContext *s, TCGType type,
214
- .create_vcpu_thread = tcg_start_vcpu_thread,
79
+ TCGReg ret, tcg_target_long arg)
215
+ .create_vcpu_thread = rr_start_vcpu_thread,
80
{
216
.kick_vcpu_thread = qemu_cpu_kick_rr_cpus,
81
tcg_target_long diff;
217
82
218
.handle_interrupt = tcg_handle_interrupt,
83
- switch (type) {
219
diff --git a/accel/tcg/tcg-cpus.c b/accel/tcg/tcg-cpus.c
84
- case TCG_TYPE_I32:
220
index XXXXXXX..XXXXXXX 100644
85
-#if TCG_TARGET_REG_BITS == 64
221
--- a/accel/tcg/tcg-cpus.c
86
- case TCG_TYPE_I64:
222
+++ b/accel/tcg/tcg-cpus.c
87
-#endif
223
@@ -XXX,XX +XXX,XX @@
88
- if (ret < 16) {
224
#include "hw/boards.h"
89
- break;
225
90
- }
226
#include "tcg-cpus.h"
91
- /* fallthru */
227
-#include "tcg-cpus-mttcg.h"
92
- case TCG_TYPE_V64:
228
-#include "tcg-cpus-rr.h"
93
- case TCG_TYPE_V128:
229
94
- case TCG_TYPE_V256:
230
/* common functionality among all TCG variants */
95
- tcg_debug_assert(ret >= 16);
231
96
- tcg_out_dupi_vec(s, type, ret, arg);
232
-void tcg_start_vcpu_thread(CPUState *cpu)
97
- return;
233
-{
98
- default:
234
- char thread_name[VCPU_THREAD_NAME_SIZE];
99
- g_assert_not_reached();
235
- static QemuCond *single_tcg_halt_cond;
236
- static QemuThread *single_tcg_cpu_thread;
237
- static int tcg_region_inited;
238
-
239
- assert(tcg_enabled());
240
- /*
241
- * Initialize TCG regions--once. Now is a good time, because:
242
- * (1) TCG's init context, prologue and target globals have been set up.
243
- * (2) qemu_tcg_mttcg_enabled() works now (TCG init code runs before the
244
- * -accel flag is processed, so the check doesn't work then).
245
- */
246
- if (!tcg_region_inited) {
247
- tcg_region_inited = 1;
248
- tcg_region_init();
249
- parallel_cpus = qemu_tcg_mttcg_enabled() && current_machine->smp.max_cpus > 1;
250
- }
100
- }
251
-
101
-
252
- if (qemu_tcg_mttcg_enabled() || !single_tcg_cpu_thread) {
102
if (arg == 0) {
253
- cpu->thread = g_malloc0(sizeof(QemuThread));
103
tgen_arithr(s, ARITH_XOR, ret, ret);
254
- cpu->halt_cond = g_malloc0(sizeof(QemuCond));
104
return;
255
- qemu_cond_init(cpu->halt_cond);
105
@@ -XXX,XX +XXX,XX @@ static void tcg_out_movi(TCGContext *s, TCGType type,
106
tcg_out64(s, arg);
107
}
108
109
+static void tcg_out_movi(TCGContext *s, TCGType type,
110
+ TCGReg ret, tcg_target_long arg)
111
+{
112
+ switch (type) {
113
+ case TCG_TYPE_I32:
114
+#if TCG_TARGET_REG_BITS == 64
115
+ case TCG_TYPE_I64:
116
+#endif
117
+ if (ret < 16) {
118
+ tcg_out_movi_int(s, type, ret, arg);
119
+ } else {
120
+ tcg_out_movi_vec(s, type, ret, arg);
121
+ }
122
+ break;
123
+ default:
124
+ g_assert_not_reached();
125
+ }
126
+}
127
+
128
static inline void tcg_out_pushi(TCGContext *s, tcg_target_long val)
129
{
130
if (val == (int8_t)val) {
131
diff --git a/tcg/ppc/tcg-target.c.inc b/tcg/ppc/tcg-target.c.inc
132
index XXXXXXX..XXXXXXX 100644
133
--- a/tcg/ppc/tcg-target.c.inc
134
+++ b/tcg/ppc/tcg-target.c.inc
135
@@ -XXX,XX +XXX,XX @@ static void tcg_out_movi(TCGContext *s, TCGType type, TCGReg ret,
136
tcg_out_movi_int(s, type, ret, arg, false);
137
break;
138
139
- case TCG_TYPE_V64:
140
- case TCG_TYPE_V128:
141
- tcg_debug_assert(ret >= TCG_REG_V0);
142
- tcg_out_dupi_vec(s, type, ret, arg);
143
- break;
256
-
144
-
257
- if (qemu_tcg_mttcg_enabled()) {
145
default:
258
- /* create a thread per vCPU with TCG (MTTCG) */
146
g_assert_not_reached();
259
- snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/TCG",
147
}
260
- cpu->cpu_index);
261
-
262
- qemu_thread_create(cpu->thread, thread_name, tcg_cpu_thread_fn,
263
- cpu, QEMU_THREAD_JOINABLE);
264
-
265
- } else {
266
- /* share a single thread for all cpus with TCG */
267
- snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "ALL CPUs/TCG");
268
- qemu_thread_create(cpu->thread, thread_name,
269
- tcg_rr_cpu_thread_fn,
270
- cpu, QEMU_THREAD_JOINABLE);
271
-
272
- single_tcg_halt_cond = cpu->halt_cond;
273
- single_tcg_cpu_thread = cpu->thread;
274
- }
275
-#ifdef _WIN32
276
- cpu->hThread = qemu_thread_get_handle(cpu->thread);
277
-#endif
278
- } else {
279
- /* For non-MTTCG cases we share the thread */
280
- cpu->thread = single_tcg_cpu_thread;
281
- cpu->halt_cond = single_tcg_halt_cond;
282
- cpu->thread_id = first_cpu->thread_id;
283
- cpu->can_do_io = 1;
284
- cpu->created = true;
285
- }
286
-}
287
-
288
void qemu_tcg_destroy_vcpu(CPUState *cpu)
289
{
290
cpu_thread_signal_destroyed(cpu);
291
--
148
--
292
2.25.1
149
2.25.1
293
150
294
151
diff view generated by jsdifflib
New patch
1
1
While we don't store more than tcg_target_long in TCGTemp,
2
we shouldn't be limited to that for code generation. We will
3
be able to use this for INDEX_op_dup2_vec with 2 constants.
4
5
Also pass along the minimal vece that may be said to apply
6
to the constant. This allows some simplification in the
7
various backends.
8
9
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
10
---
11
tcg/tcg.c | 31 +++++++++++++++++++++++++-----
12
tcg/aarch64/tcg-target.c.inc | 12 ++++++------
13
tcg/i386/tcg-target.c.inc | 22 ++++++++++++---------
14
tcg/ppc/tcg-target.c.inc | 37 +++++++++++++++++++++++-------------
15
4 files changed, 69 insertions(+), 33 deletions(-)
16
17
diff --git a/tcg/tcg.c b/tcg/tcg.c
18
index XXXXXXX..XXXXXXX 100644
19
--- a/tcg/tcg.c
20
+++ b/tcg/tcg.c
21
@@ -XXX,XX +XXX,XX @@ static bool tcg_out_dup_vec(TCGContext *s, TCGType type, unsigned vece,
22
TCGReg dst, TCGReg src);
23
static bool tcg_out_dupm_vec(TCGContext *s, TCGType type, unsigned vece,
24
TCGReg dst, TCGReg base, intptr_t offset);
25
-static void tcg_out_dupi_vec(TCGContext *s, TCGType type,
26
- TCGReg dst, tcg_target_long arg);
27
+static void tcg_out_dupi_vec(TCGContext *s, TCGType type, unsigned vece,
28
+ TCGReg dst, int64_t arg);
29
static void tcg_out_vec_op(TCGContext *s, TCGOpcode opc, unsigned vecl,
30
unsigned vece, const TCGArg *args,
31
const int *const_args);
32
@@ -XXX,XX +XXX,XX @@ static inline bool tcg_out_dupm_vec(TCGContext *s, TCGType type, unsigned vece,
33
{
34
g_assert_not_reached();
35
}
36
-static inline void tcg_out_dupi_vec(TCGContext *s, TCGType type,
37
- TCGReg dst, tcg_target_long arg)
38
+static inline void tcg_out_dupi_vec(TCGContext *s, TCGType type, unsigned vece,
39
+ TCGReg dst, int64_t arg)
40
{
41
g_assert_not_reached();
42
}
43
@@ -XXX,XX +XXX,XX @@ static void temp_load(TCGContext *s, TCGTemp *ts, TCGRegSet desired_regs,
44
if (ts->type <= TCG_TYPE_I64) {
45
tcg_out_movi(s, ts->type, reg, ts->val);
46
} else {
47
- tcg_out_dupi_vec(s, ts->type, reg, ts->val);
48
+ uint64_t val = ts->val;
49
+ MemOp vece = MO_64;
50
+
51
+ /*
52
+ * Find the minimal vector element that matches the constant.
53
+ * The targets will, in general, have to do this search anyway,
54
+ * do this generically.
55
+ */
56
+ if (TCG_TARGET_REG_BITS == 32) {
57
+ val = dup_const(MO_32, val);
58
+ vece = MO_32;
59
+ }
60
+ if (val == dup_const(MO_8, val)) {
61
+ vece = MO_8;
62
+ } else if (val == dup_const(MO_16, val)) {
63
+ vece = MO_16;
64
+ } else if (TCG_TARGET_REG_BITS == 64 &&
65
+ val == dup_const(MO_32, val)) {
66
+ vece = MO_32;
67
+ }
68
+
69
+ tcg_out_dupi_vec(s, ts->type, vece, reg, ts->val);
70
}
71
ts->mem_coherent = 0;
72
break;
73
diff --git a/tcg/aarch64/tcg-target.c.inc b/tcg/aarch64/tcg-target.c.inc
74
index XXXXXXX..XXXXXXX 100644
75
--- a/tcg/aarch64/tcg-target.c.inc
76
+++ b/tcg/aarch64/tcg-target.c.inc
77
@@ -XXX,XX +XXX,XX @@ static void tcg_out_logicali(TCGContext *s, AArch64Insn insn, TCGType ext,
78
tcg_out_insn_3404(s, insn, ext, rd, rn, ext, r, c);
79
}
80
81
-static void tcg_out_dupi_vec(TCGContext *s, TCGType type,
82
- TCGReg rd, tcg_target_long v64)
83
+static void tcg_out_dupi_vec(TCGContext *s, TCGType type, unsigned vece,
84
+ TCGReg rd, int64_t v64)
85
{
86
bool q = type == TCG_TYPE_V128;
87
int cmode, imm8, i;
88
89
/* Test all bytes equal first. */
90
- if (v64 == dup_const(MO_8, v64)) {
91
+ if (vece == MO_8) {
92
imm8 = (uint8_t)v64;
93
tcg_out_insn(s, 3606, MOVI, q, rd, 0, 0xe, imm8);
94
return;
95
@@ -XXX,XX +XXX,XX @@ static void tcg_out_dupi_vec(TCGContext *s, TCGType type,
96
* cannot find an expansion there's no point checking a larger
97
* width because we already know by replication it cannot match.
98
*/
99
- if (v64 == dup_const(MO_16, v64)) {
100
+ if (vece == MO_16) {
101
uint16_t v16 = v64;
102
103
if (is_shimm16(v16, &cmode, &imm8)) {
104
@@ -XXX,XX +XXX,XX @@ static void tcg_out_dupi_vec(TCGContext *s, TCGType type,
105
tcg_out_insn(s, 3606, MOVI, q, rd, 0, 0x8, v16 & 0xff);
106
tcg_out_insn(s, 3606, ORR, q, rd, 0, 0xa, v16 >> 8);
107
return;
108
- } else if (v64 == dup_const(MO_32, v64)) {
109
+ } else if (vece == MO_32) {
110
uint32_t v32 = v64;
111
uint32_t n32 = ~v32;
112
113
@@ -XXX,XX +XXX,XX @@ static void tcg_out_vec_op(TCGContext *s, TCGOpcode opc,
114
tcg_out_insn_3617(s, insn, is_q, vece, a0, a1);
115
break;
116
}
117
- tcg_out_dupi_vec(s, type, TCG_VEC_TMP, 0);
118
+ tcg_out_dupi_vec(s, type, MO_8, TCG_VEC_TMP, 0);
119
a2 = TCG_VEC_TMP;
120
}
121
insn = cmp_insn[cond];
122
diff --git a/tcg/i386/tcg-target.c.inc b/tcg/i386/tcg-target.c.inc
123
index XXXXXXX..XXXXXXX 100644
124
--- a/tcg/i386/tcg-target.c.inc
125
+++ b/tcg/i386/tcg-target.c.inc
126
@@ -XXX,XX +XXX,XX @@ static bool tcg_out_dupm_vec(TCGContext *s, TCGType type, unsigned vece,
127
return true;
128
}
129
130
-static void tcg_out_dupi_vec(TCGContext *s, TCGType type,
131
- TCGReg ret, tcg_target_long arg)
132
+static void tcg_out_dupi_vec(TCGContext *s, TCGType type, unsigned vece,
133
+ TCGReg ret, int64_t arg)
134
{
135
int vex_l = (type == TCG_TYPE_V256 ? P_VEXL : 0);
136
137
@@ -XXX,XX +XXX,XX @@ static void tcg_out_dupi_vec(TCGContext *s, TCGType type,
138
return;
139
}
140
141
- if (TCG_TARGET_REG_BITS == 64) {
142
+ if (TCG_TARGET_REG_BITS == 32 && vece < MO_64) {
143
+ if (have_avx2) {
144
+ tcg_out_vex_modrm_pool(s, OPC_VPBROADCASTD + vex_l, ret);
145
+ } else {
146
+ tcg_out_vex_modrm_pool(s, OPC_VBROADCASTSS, ret);
147
+ }
148
+ new_pool_label(s, arg, R_386_32, s->code_ptr - 4, 0);
149
+ } else {
150
if (type == TCG_TYPE_V64) {
151
tcg_out_vex_modrm_pool(s, OPC_MOVQ_VqWq, ret);
152
} else if (have_avx2) {
153
@@ -XXX,XX +XXX,XX @@ static void tcg_out_dupi_vec(TCGContext *s, TCGType type,
154
} else {
155
tcg_out_vex_modrm_pool(s, OPC_MOVDDUP, ret);
156
}
157
- new_pool_label(s, arg, R_386_PC32, s->code_ptr - 4, -4);
158
- } else {
159
- if (have_avx2) {
160
- tcg_out_vex_modrm_pool(s, OPC_VPBROADCASTD + vex_l, ret);
161
+ if (TCG_TARGET_REG_BITS == 64) {
162
+ new_pool_label(s, arg, R_386_PC32, s->code_ptr - 4, -4);
163
} else {
164
- tcg_out_vex_modrm_pool(s, OPC_VBROADCASTSS, ret);
165
+ new_pool_l2(s, R_386_32, s->code_ptr - 4, 0, arg, arg >> 32);
166
}
167
- new_pool_label(s, arg, R_386_32, s->code_ptr - 4, 0);
168
}
169
}
170
171
diff --git a/tcg/ppc/tcg-target.c.inc b/tcg/ppc/tcg-target.c.inc
172
index XXXXXXX..XXXXXXX 100644
173
--- a/tcg/ppc/tcg-target.c.inc
174
+++ b/tcg/ppc/tcg-target.c.inc
175
@@ -XXX,XX +XXX,XX @@ static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret,
176
}
177
}
178
179
-static void tcg_out_dupi_vec(TCGContext *s, TCGType type, TCGReg ret,
180
- tcg_target_long val)
181
+static void tcg_out_dupi_vec(TCGContext *s, TCGType type, unsigned vece,
182
+ TCGReg ret, int64_t val)
183
{
184
uint32_t load_insn;
185
int rel, low;
186
intptr_t add;
187
188
- low = (int8_t)val;
189
- if (low >= -16 && low < 16) {
190
- if (val == (tcg_target_long)dup_const(MO_8, low)) {
191
+ switch (vece) {
192
+ case MO_8:
193
+ low = (int8_t)val;
194
+ if (low >= -16 && low < 16) {
195
tcg_out32(s, VSPLTISB | VRT(ret) | ((val & 31) << 16));
196
return;
197
}
198
- if (val == (tcg_target_long)dup_const(MO_16, low)) {
199
+ if (have_isa_3_00) {
200
+ tcg_out32(s, XXSPLTIB | VRT(ret) | ((val & 0xff) << 11));
201
+ return;
202
+ }
203
+ break;
204
+
205
+ case MO_16:
206
+ low = (int16_t)val;
207
+ if (low >= -16 && low < 16) {
208
tcg_out32(s, VSPLTISH | VRT(ret) | ((val & 31) << 16));
209
return;
210
}
211
- if (val == (tcg_target_long)dup_const(MO_32, low)) {
212
+ break;
213
+
214
+ case MO_32:
215
+ low = (int32_t)val;
216
+ if (low >= -16 && low < 16) {
217
tcg_out32(s, VSPLTISW | VRT(ret) | ((val & 31) << 16));
218
return;
219
}
220
- }
221
- if (have_isa_3_00 && val == (tcg_target_long)dup_const(MO_8, val)) {
222
- tcg_out32(s, XXSPLTIB | VRT(ret) | ((val & 0xff) << 11));
223
- return;
224
+ break;
225
}
226
227
/*
228
@@ -XXX,XX +XXX,XX @@ static void tcg_out_dupi_vec(TCGContext *s, TCGType type, TCGReg ret,
229
if (TCG_TARGET_REG_BITS == 64) {
230
new_pool_label(s, val, rel, s->code_ptr, add);
231
} else {
232
- new_pool_l2(s, rel, s->code_ptr, add, val, val);
233
+ new_pool_l2(s, rel, s->code_ptr, add, val >> 32, val);
234
}
235
} else {
236
load_insn = LVX | VRT(ret) | RB(TCG_REG_TMP1);
237
if (TCG_TARGET_REG_BITS == 64) {
238
new_pool_l2(s, rel, s->code_ptr, add, val, val);
239
} else {
240
- new_pool_l4(s, rel, s->code_ptr, add, val, val, val, val);
241
+ new_pool_l4(s, rel, s->code_ptr, add,
242
+ val >> 32, val, val >> 32, val);
243
}
244
}
245
246
--
247
2.25.1
248
249
diff view generated by jsdifflib
New patch
1
The temp_fixed, temp_global, temp_local bits are all related.
2
Combine them into a single enumeration.
1
3
4
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>
7
---
8
include/tcg/tcg.h | 20 +++++---
9
tcg/optimize.c | 8 +--
10
tcg/tcg.c | 126 ++++++++++++++++++++++++++++------------------
11
3 files changed, 92 insertions(+), 62 deletions(-)
12
13
diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h
14
index XXXXXXX..XXXXXXX 100644
15
--- a/include/tcg/tcg.h
16
+++ b/include/tcg/tcg.h
17
@@ -XXX,XX +XXX,XX @@ typedef enum TCGTempVal {
18
TEMP_VAL_CONST,
19
} TCGTempVal;
20
21
+typedef enum TCGTempKind {
22
+ /* Temp is dead at the end of all basic blocks. */
23
+ TEMP_NORMAL,
24
+ /* Temp is saved across basic blocks but dead at the end of TBs. */
25
+ TEMP_LOCAL,
26
+ /* Temp is saved across both basic blocks and translation blocks. */
27
+ TEMP_GLOBAL,
28
+ /* Temp is in a fixed register. */
29
+ TEMP_FIXED,
30
+} TCGTempKind;
31
+
32
typedef struct TCGTemp {
33
TCGReg reg:8;
34
TCGTempVal val_type:8;
35
TCGType base_type:8;
36
TCGType type:8;
37
- unsigned int fixed_reg:1;
38
+ TCGTempKind kind:3;
39
unsigned int indirect_reg:1;
40
unsigned int indirect_base:1;
41
unsigned int mem_coherent:1;
42
unsigned int mem_allocated:1;
43
- /* If true, the temp is saved across both basic blocks and
44
- translation blocks. */
45
- unsigned int temp_global:1;
46
- /* If true, the temp is saved across basic blocks but dead
47
- at the end of translation blocks. If false, the temp is
48
- dead at the end of basic blocks. */
49
- unsigned int temp_local:1;
50
unsigned int temp_allocated:1;
51
52
tcg_target_long val;
53
diff --git a/tcg/optimize.c b/tcg/optimize.c
54
index XXXXXXX..XXXXXXX 100644
55
--- a/tcg/optimize.c
56
+++ b/tcg/optimize.c
57
@@ -XXX,XX +XXX,XX @@ static TCGTemp *find_better_copy(TCGContext *s, TCGTemp *ts)
58
TCGTemp *i;
59
60
/* If this is already a global, we can't do better. */
61
- if (ts->temp_global) {
62
+ if (ts->kind >= TEMP_GLOBAL) {
63
return ts;
64
}
65
66
/* Search for a global first. */
67
for (i = ts_info(ts)->next_copy; i != ts; i = ts_info(i)->next_copy) {
68
- if (i->temp_global) {
69
+ if (i->kind >= TEMP_GLOBAL) {
70
return i;
71
}
72
}
73
74
/* If it is a temp, search for a temp local. */
75
- if (!ts->temp_local) {
76
+ if (ts->kind == TEMP_NORMAL) {
77
for (i = ts_info(ts)->next_copy; i != ts; i = ts_info(i)->next_copy) {
78
- if (ts->temp_local) {
79
+ if (i->kind >= TEMP_LOCAL) {
80
return i;
81
}
82
}
83
diff --git a/tcg/tcg.c b/tcg/tcg.c
84
index XXXXXXX..XXXXXXX 100644
85
--- a/tcg/tcg.c
86
+++ b/tcg/tcg.c
87
@@ -XXX,XX +XXX,XX @@ static inline TCGTemp *tcg_global_alloc(TCGContext *s)
88
tcg_debug_assert(s->nb_globals == s->nb_temps);
89
s->nb_globals++;
90
ts = tcg_temp_alloc(s);
91
- ts->temp_global = 1;
92
+ ts->kind = TEMP_GLOBAL;
93
94
return ts;
95
}
96
@@ -XXX,XX +XXX,XX @@ static TCGTemp *tcg_global_reg_new_internal(TCGContext *s, TCGType type,
97
ts = tcg_global_alloc(s);
98
ts->base_type = type;
99
ts->type = type;
100
- ts->fixed_reg = 1;
101
+ ts->kind = TEMP_FIXED;
102
ts->reg = reg;
103
ts->name = name;
104
tcg_regset_set_reg(s->reserved_regs, reg);
105
@@ -XXX,XX +XXX,XX @@ TCGTemp *tcg_global_mem_new_internal(TCGType type, TCGv_ptr base,
106
bigendian = 1;
107
#endif
108
109
- if (!base_ts->fixed_reg) {
110
+ if (base_ts->kind != TEMP_FIXED) {
111
/* We do not support double-indirect registers. */
112
tcg_debug_assert(!base_ts->indirect_reg);
113
base_ts->indirect_base = 1;
114
@@ -XXX,XX +XXX,XX @@ TCGTemp *tcg_global_mem_new_internal(TCGType type, TCGv_ptr base,
115
TCGTemp *tcg_temp_new_internal(TCGType type, bool temp_local)
116
{
117
TCGContext *s = tcg_ctx;
118
+ TCGTempKind kind = temp_local ? TEMP_LOCAL : TEMP_NORMAL;
119
TCGTemp *ts;
120
int idx, k;
121
122
@@ -XXX,XX +XXX,XX @@ TCGTemp *tcg_temp_new_internal(TCGType type, bool temp_local)
123
ts = &s->temps[idx];
124
ts->temp_allocated = 1;
125
tcg_debug_assert(ts->base_type == type);
126
- tcg_debug_assert(ts->temp_local == temp_local);
127
+ tcg_debug_assert(ts->kind == kind);
128
} else {
129
ts = tcg_temp_alloc(s);
130
if (TCG_TARGET_REG_BITS == 32 && type == TCG_TYPE_I64) {
131
@@ -XXX,XX +XXX,XX @@ TCGTemp *tcg_temp_new_internal(TCGType type, bool temp_local)
132
ts->base_type = type;
133
ts->type = TCG_TYPE_I32;
134
ts->temp_allocated = 1;
135
- ts->temp_local = temp_local;
136
+ ts->kind = kind;
137
138
tcg_debug_assert(ts2 == ts + 1);
139
ts2->base_type = TCG_TYPE_I64;
140
ts2->type = TCG_TYPE_I32;
141
ts2->temp_allocated = 1;
142
- ts2->temp_local = temp_local;
143
+ ts2->kind = kind;
144
} else {
145
ts->base_type = type;
146
ts->type = type;
147
ts->temp_allocated = 1;
148
- ts->temp_local = temp_local;
149
+ ts->kind = kind;
150
}
151
}
152
153
@@ -XXX,XX +XXX,XX @@ void tcg_temp_free_internal(TCGTemp *ts)
154
}
155
#endif
156
157
- tcg_debug_assert(ts->temp_global == 0);
158
+ tcg_debug_assert(ts->kind < TEMP_GLOBAL);
159
tcg_debug_assert(ts->temp_allocated != 0);
160
ts->temp_allocated = 0;
161
162
idx = temp_idx(ts);
163
- k = ts->base_type + (ts->temp_local ? TCG_TYPE_COUNT : 0);
164
+ k = ts->base_type + (ts->kind == TEMP_NORMAL ? 0 : TCG_TYPE_COUNT);
165
set_bit(idx, s->free_temps[k].l);
166
}
167
168
@@ -XXX,XX +XXX,XX @@ void tcg_gen_callN(void *func, TCGTemp *ret, int nargs, TCGTemp **args)
169
static void tcg_reg_alloc_start(TCGContext *s)
170
{
171
int i, n;
172
- TCGTemp *ts;
173
174
- for (i = 0, n = s->nb_globals; i < n; i++) {
175
- ts = &s->temps[i];
176
- ts->val_type = (ts->fixed_reg ? TEMP_VAL_REG : TEMP_VAL_MEM);
177
- }
178
- for (n = s->nb_temps; i < n; i++) {
179
- ts = &s->temps[i];
180
- ts->val_type = (ts->temp_local ? TEMP_VAL_MEM : TEMP_VAL_DEAD);
181
- ts->mem_allocated = 0;
182
- ts->fixed_reg = 0;
183
+ for (i = 0, n = s->nb_temps; i < n; i++) {
184
+ TCGTemp *ts = &s->temps[i];
185
+ TCGTempVal val = TEMP_VAL_MEM;
186
+
187
+ switch (ts->kind) {
188
+ case TEMP_FIXED:
189
+ val = TEMP_VAL_REG;
190
+ break;
191
+ case TEMP_GLOBAL:
192
+ break;
193
+ case TEMP_NORMAL:
194
+ val = TEMP_VAL_DEAD;
195
+ /* fall through */
196
+ case TEMP_LOCAL:
197
+ ts->mem_allocated = 0;
198
+ break;
199
+ default:
200
+ g_assert_not_reached();
201
+ }
202
+ ts->val_type = val;
203
}
204
205
memset(s->reg_to_temp, 0, sizeof(s->reg_to_temp));
206
@@ -XXX,XX +XXX,XX @@ static char *tcg_get_arg_str_ptr(TCGContext *s, char *buf, int buf_size,
207
{
208
int idx = temp_idx(ts);
209
210
- if (ts->temp_global) {
211
+ switch (ts->kind) {
212
+ case TEMP_FIXED:
213
+ case TEMP_GLOBAL:
214
pstrcpy(buf, buf_size, ts->name);
215
- } else if (ts->temp_local) {
216
+ break;
217
+ case TEMP_LOCAL:
218
snprintf(buf, buf_size, "loc%d", idx - s->nb_globals);
219
- } else {
220
+ break;
221
+ case TEMP_NORMAL:
222
snprintf(buf, buf_size, "tmp%d", idx - s->nb_globals);
223
+ break;
224
}
225
return buf;
226
}
227
@@ -XXX,XX +XXX,XX @@ static void la_bb_end(TCGContext *s, int ng, int nt)
228
{
229
int i;
230
231
- for (i = 0; i < ng; ++i) {
232
- s->temps[i].state = TS_DEAD | TS_MEM;
233
- la_reset_pref(&s->temps[i]);
234
- }
235
- for (i = ng; i < nt; ++i) {
236
- s->temps[i].state = (s->temps[i].temp_local
237
- ? TS_DEAD | TS_MEM
238
- : TS_DEAD);
239
- la_reset_pref(&s->temps[i]);
240
+ for (i = 0; i < nt; ++i) {
241
+ TCGTemp *ts = &s->temps[i];
242
+ int state;
243
+
244
+ switch (ts->kind) {
245
+ case TEMP_FIXED:
246
+ case TEMP_GLOBAL:
247
+ case TEMP_LOCAL:
248
+ state = TS_DEAD | TS_MEM;
249
+ break;
250
+ case TEMP_NORMAL:
251
+ state = TS_DEAD;
252
+ break;
253
+ default:
254
+ g_assert_not_reached();
255
+ }
256
+ ts->state = state;
257
+ la_reset_pref(ts);
258
}
259
}
260
261
@@ -XXX,XX +XXX,XX @@ static void la_bb_sync(TCGContext *s, int ng, int nt)
262
la_global_sync(s, ng);
263
264
for (int i = ng; i < nt; ++i) {
265
- if (s->temps[i].temp_local) {
266
+ if (s->temps[i].kind == TEMP_LOCAL) {
267
int state = s->temps[i].state;
268
s->temps[i].state = state | TS_MEM;
269
if (state != TS_DEAD) {
270
@@ -XXX,XX +XXX,XX @@ static void check_regs(TCGContext *s)
271
}
272
for (k = 0; k < s->nb_temps; k++) {
273
ts = &s->temps[k];
274
- if (ts->val_type == TEMP_VAL_REG && !ts->fixed_reg
275
+ if (ts->val_type == TEMP_VAL_REG
276
+ && ts->kind != TEMP_FIXED
277
&& s->reg_to_temp[ts->reg] != ts) {
278
printf("Inconsistency for temp %s:\n",
279
tcg_get_arg_str_ptr(s, buf, sizeof(buf), ts));
280
@@ -XXX,XX +XXX,XX @@ static void temp_load(TCGContext *, TCGTemp *, TCGRegSet, TCGRegSet, TCGRegSet);
281
mark it free; otherwise mark it dead. */
282
static void temp_free_or_dead(TCGContext *s, TCGTemp *ts, int free_or_dead)
283
{
284
- if (ts->fixed_reg) {
285
+ if (ts->kind == TEMP_FIXED) {
286
return;
287
}
288
if (ts->val_type == TEMP_VAL_REG) {
289
s->reg_to_temp[ts->reg] = NULL;
290
}
291
ts->val_type = (free_or_dead < 0
292
- || ts->temp_local
293
- || ts->temp_global
294
+ || ts->kind != TEMP_NORMAL
295
? TEMP_VAL_MEM : TEMP_VAL_DEAD);
296
}
297
298
@@ -XXX,XX +XXX,XX @@ static inline void temp_dead(TCGContext *s, TCGTemp *ts)
299
static void temp_sync(TCGContext *s, TCGTemp *ts, TCGRegSet allocated_regs,
300
TCGRegSet preferred_regs, int free_or_dead)
301
{
302
- if (ts->fixed_reg) {
303
+ if (ts->kind == TEMP_FIXED) {
304
return;
305
}
306
if (!ts->mem_coherent) {
307
@@ -XXX,XX +XXX,XX @@ static void temp_save(TCGContext *s, TCGTemp *ts, TCGRegSet allocated_regs)
308
{
309
/* The liveness analysis already ensures that globals are back
310
in memory. Keep an tcg_debug_assert for safety. */
311
- tcg_debug_assert(ts->val_type == TEMP_VAL_MEM || ts->fixed_reg);
312
+ tcg_debug_assert(ts->val_type == TEMP_VAL_MEM
313
+ || ts->kind == TEMP_FIXED);
314
}
315
316
/* save globals to their canonical location and assume they can be
317
@@ -XXX,XX +XXX,XX @@ static void sync_globals(TCGContext *s, TCGRegSet allocated_regs)
318
for (i = 0, n = s->nb_globals; i < n; i++) {
319
TCGTemp *ts = &s->temps[i];
320
tcg_debug_assert(ts->val_type != TEMP_VAL_REG
321
- || ts->fixed_reg
322
+ || ts->kind == TEMP_FIXED
323
|| ts->mem_coherent);
324
}
325
}
326
@@ -XXX,XX +XXX,XX @@ static void tcg_reg_alloc_bb_end(TCGContext *s, TCGRegSet allocated_regs)
327
328
for (i = s->nb_globals; i < s->nb_temps; i++) {
329
TCGTemp *ts = &s->temps[i];
330
- if (ts->temp_local) {
331
+ if (ts->kind == TEMP_LOCAL) {
332
temp_save(s, ts, allocated_regs);
333
} else {
334
/* The liveness analysis already ensures that temps are dead.
335
@@ -XXX,XX +XXX,XX @@ static void tcg_reg_alloc_cbranch(TCGContext *s, TCGRegSet allocated_regs)
336
* The liveness analysis already ensures that temps are dead.
337
* Keep tcg_debug_asserts for safety.
338
*/
339
- if (ts->temp_local) {
340
+ if (ts->kind == TEMP_LOCAL) {
341
tcg_debug_assert(ts->val_type != TEMP_VAL_REG || ts->mem_coherent);
342
} else {
343
tcg_debug_assert(ts->val_type == TEMP_VAL_DEAD);
344
@@ -XXX,XX +XXX,XX @@ static void tcg_reg_alloc_do_movi(TCGContext *s, TCGTemp *ots,
345
TCGRegSet preferred_regs)
346
{
347
/* ENV should not be modified. */
348
- tcg_debug_assert(!ots->fixed_reg);
349
+ tcg_debug_assert(ots->kind != TEMP_FIXED);
350
351
/* The movi is not explicitly generated here. */
352
if (ots->val_type == TEMP_VAL_REG) {
353
@@ -XXX,XX +XXX,XX @@ static void tcg_reg_alloc_mov(TCGContext *s, const TCGOp *op)
354
ts = arg_temp(op->args[1]);
355
356
/* ENV should not be modified. */
357
- tcg_debug_assert(!ots->fixed_reg);
358
+ tcg_debug_assert(ots->kind != TEMP_FIXED);
359
360
/* Note that otype != itype for no-op truncation. */
361
otype = ots->type;
362
@@ -XXX,XX +XXX,XX @@ static void tcg_reg_alloc_mov(TCGContext *s, const TCGOp *op)
363
}
364
temp_dead(s, ots);
365
} else {
366
- if (IS_DEAD_ARG(1) && !ts->fixed_reg) {
367
+ if (IS_DEAD_ARG(1) && ts->kind != TEMP_FIXED) {
368
/* the mov can be suppressed */
369
if (ots->val_type == TEMP_VAL_REG) {
370
s->reg_to_temp[ots->reg] = NULL;
371
@@ -XXX,XX +XXX,XX @@ static void tcg_reg_alloc_mov(TCGContext *s, const TCGOp *op)
372
* Store the source register into the destination slot
373
* and leave the destination temp as TEMP_VAL_MEM.
374
*/
375
- assert(!ots->fixed_reg);
376
+ assert(ots->kind != TEMP_FIXED);
377
if (!ts->mem_allocated) {
378
temp_allocate_frame(s, ots);
379
}
380
@@ -XXX,XX +XXX,XX @@ static void tcg_reg_alloc_dup(TCGContext *s, const TCGOp *op)
381
its = arg_temp(op->args[1]);
382
383
/* ENV should not be modified. */
384
- tcg_debug_assert(!ots->fixed_reg);
385
+ tcg_debug_assert(ots->kind != TEMP_FIXED);
386
387
itype = its->type;
388
vece = TCGOP_VECE(op);
389
@@ -XXX,XX +XXX,XX @@ static void tcg_reg_alloc_op(TCGContext *s, const TCGOp *op)
390
i_preferred_regs = o_preferred_regs = 0;
391
if (arg_ct->ialias) {
392
o_preferred_regs = op->output_pref[arg_ct->alias_index];
393
- if (ts->fixed_reg) {
394
+ if (ts->kind == TEMP_FIXED) {
395
/* if fixed register, we must allocate a new register
396
if the alias is not the same register */
397
if (arg != op->args[arg_ct->alias_index]) {
398
@@ -XXX,XX +XXX,XX @@ static void tcg_reg_alloc_op(TCGContext *s, const TCGOp *op)
399
ts = arg_temp(arg);
400
401
/* ENV should not be modified. */
402
- tcg_debug_assert(!ts->fixed_reg);
403
+ tcg_debug_assert(ts->kind != TEMP_FIXED);
404
405
if (arg_ct->oalias && !const_args[arg_ct->alias_index]) {
406
reg = new_args[arg_ct->alias_index];
407
@@ -XXX,XX +XXX,XX @@ static void tcg_reg_alloc_op(TCGContext *s, const TCGOp *op)
408
ts = arg_temp(op->args[i]);
409
410
/* ENV should not be modified. */
411
- tcg_debug_assert(!ts->fixed_reg);
412
+ tcg_debug_assert(ts->kind != TEMP_FIXED);
413
414
if (NEED_SYNC_ARG(i)) {
415
temp_sync(s, ts, o_allocated_regs, 0, IS_DEAD_ARG(i));
416
@@ -XXX,XX +XXX,XX @@ static void tcg_reg_alloc_call(TCGContext *s, TCGOp *op)
417
ts = arg_temp(arg);
418
419
/* ENV should not be modified. */
420
- tcg_debug_assert(!ts->fixed_reg);
421
+ tcg_debug_assert(ts->kind != TEMP_FIXED);
422
423
reg = tcg_target_call_oarg_regs[i];
424
tcg_debug_assert(s->reg_to_temp[reg] == NULL);
425
--
426
2.25.1
427
428
diff view generated by jsdifflib
New patch
1
In most, but not all, places that we check for TEMP_FIXED,
2
we are really testing that we do not modify the temporary.
1
3
4
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>
7
---
8
include/tcg/tcg.h | 5 +++++
9
tcg/tcg.c | 21 ++++++++++-----------
10
2 files changed, 15 insertions(+), 11 deletions(-)
11
12
diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h
13
index XXXXXXX..XXXXXXX 100644
14
--- a/include/tcg/tcg.h
15
+++ b/include/tcg/tcg.h
16
@@ -XXX,XX +XXX,XX @@ struct TCGContext {
17
target_ulong gen_insn_data[TCG_MAX_INSNS][TARGET_INSN_START_WORDS];
18
};
19
20
+static inline bool temp_readonly(TCGTemp *ts)
21
+{
22
+ return ts->kind == TEMP_FIXED;
23
+}
24
+
25
extern TCGContext tcg_init_ctx;
26
extern __thread TCGContext *tcg_ctx;
27
extern const void *tcg_code_gen_epilogue;
28
diff --git a/tcg/tcg.c b/tcg/tcg.c
29
index XXXXXXX..XXXXXXX 100644
30
--- a/tcg/tcg.c
31
+++ b/tcg/tcg.c
32
@@ -XXX,XX +XXX,XX @@ static void temp_load(TCGContext *, TCGTemp *, TCGRegSet, TCGRegSet, TCGRegSet);
33
mark it free; otherwise mark it dead. */
34
static void temp_free_or_dead(TCGContext *s, TCGTemp *ts, int free_or_dead)
35
{
36
- if (ts->kind == TEMP_FIXED) {
37
+ if (temp_readonly(ts)) {
38
return;
39
}
40
if (ts->val_type == TEMP_VAL_REG) {
41
@@ -XXX,XX +XXX,XX @@ static inline void temp_dead(TCGContext *s, TCGTemp *ts)
42
static void temp_sync(TCGContext *s, TCGTemp *ts, TCGRegSet allocated_regs,
43
TCGRegSet preferred_regs, int free_or_dead)
44
{
45
- if (ts->kind == TEMP_FIXED) {
46
+ if (temp_readonly(ts)) {
47
return;
48
}
49
if (!ts->mem_coherent) {
50
@@ -XXX,XX +XXX,XX @@ static void temp_save(TCGContext *s, TCGTemp *ts, TCGRegSet allocated_regs)
51
{
52
/* The liveness analysis already ensures that globals are back
53
in memory. Keep an tcg_debug_assert for safety. */
54
- tcg_debug_assert(ts->val_type == TEMP_VAL_MEM
55
- || ts->kind == TEMP_FIXED);
56
+ tcg_debug_assert(ts->val_type == TEMP_VAL_MEM || temp_readonly(ts));
57
}
58
59
/* save globals to their canonical location and assume they can be
60
@@ -XXX,XX +XXX,XX @@ static void tcg_reg_alloc_do_movi(TCGContext *s, TCGTemp *ots,
61
TCGRegSet preferred_regs)
62
{
63
/* ENV should not be modified. */
64
- tcg_debug_assert(ots->kind != TEMP_FIXED);
65
+ tcg_debug_assert(!temp_readonly(ots));
66
67
/* The movi is not explicitly generated here. */
68
if (ots->val_type == TEMP_VAL_REG) {
69
@@ -XXX,XX +XXX,XX @@ static void tcg_reg_alloc_mov(TCGContext *s, const TCGOp *op)
70
ts = arg_temp(op->args[1]);
71
72
/* ENV should not be modified. */
73
- tcg_debug_assert(ots->kind != TEMP_FIXED);
74
+ tcg_debug_assert(!temp_readonly(ots));
75
76
/* Note that otype != itype for no-op truncation. */
77
otype = ots->type;
78
@@ -XXX,XX +XXX,XX @@ static void tcg_reg_alloc_mov(TCGContext *s, const TCGOp *op)
79
* Store the source register into the destination slot
80
* and leave the destination temp as TEMP_VAL_MEM.
81
*/
82
- assert(ots->kind != TEMP_FIXED);
83
+ assert(!temp_readonly(ots));
84
if (!ts->mem_allocated) {
85
temp_allocate_frame(s, ots);
86
}
87
@@ -XXX,XX +XXX,XX @@ static void tcg_reg_alloc_dup(TCGContext *s, const TCGOp *op)
88
its = arg_temp(op->args[1]);
89
90
/* ENV should not be modified. */
91
- tcg_debug_assert(ots->kind != TEMP_FIXED);
92
+ tcg_debug_assert(!temp_readonly(ots));
93
94
itype = its->type;
95
vece = TCGOP_VECE(op);
96
@@ -XXX,XX +XXX,XX @@ static void tcg_reg_alloc_op(TCGContext *s, const TCGOp *op)
97
ts = arg_temp(arg);
98
99
/* ENV should not be modified. */
100
- tcg_debug_assert(ts->kind != TEMP_FIXED);
101
+ tcg_debug_assert(!temp_readonly(ts));
102
103
if (arg_ct->oalias && !const_args[arg_ct->alias_index]) {
104
reg = new_args[arg_ct->alias_index];
105
@@ -XXX,XX +XXX,XX @@ static void tcg_reg_alloc_op(TCGContext *s, const TCGOp *op)
106
ts = arg_temp(op->args[i]);
107
108
/* ENV should not be modified. */
109
- tcg_debug_assert(ts->kind != TEMP_FIXED);
110
+ tcg_debug_assert(!temp_readonly(ts));
111
112
if (NEED_SYNC_ARG(i)) {
113
temp_sync(s, ts, o_allocated_regs, 0, IS_DEAD_ARG(i));
114
@@ -XXX,XX +XXX,XX @@ static void tcg_reg_alloc_call(TCGContext *s, TCGOp *op)
115
ts = arg_temp(arg);
116
117
/* ENV should not be modified. */
118
- tcg_debug_assert(ts->kind != TEMP_FIXED);
119
+ tcg_debug_assert(!temp_readonly(ts));
120
121
reg = tcg_target_call_oarg_regs[i];
122
tcg_debug_assert(s->reg_to_temp[reg] == NULL);
123
--
124
2.25.1
125
126
diff view generated by jsdifflib
New patch
1
This will reduce the differences between 32-bit and 64-bit hosts,
2
allowing full 64-bit constants to be created with the same interface.
1
3
4
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
5
---
6
include/tcg/tcg.h | 2 +-
7
tcg/tcg.c | 2 +-
8
2 files changed, 2 insertions(+), 2 deletions(-)
9
10
diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h
11
index XXXXXXX..XXXXXXX 100644
12
--- a/include/tcg/tcg.h
13
+++ b/include/tcg/tcg.h
14
@@ -XXX,XX +XXX,XX @@ typedef struct TCGTemp {
15
unsigned int mem_allocated:1;
16
unsigned int temp_allocated:1;
17
18
- tcg_target_long val;
19
+ int64_t val;
20
struct TCGTemp *mem_base;
21
intptr_t mem_offset;
22
const char *name;
23
diff --git a/tcg/tcg.c b/tcg/tcg.c
24
index XXXXXXX..XXXXXXX 100644
25
--- a/tcg/tcg.c
26
+++ b/tcg/tcg.c
27
@@ -XXX,XX +XXX,XX @@ static void dump_regs(TCGContext *s)
28
tcg_target_reg_names[ts->mem_base->reg]);
29
break;
30
case TEMP_VAL_CONST:
31
- printf("$0x%" TCG_PRIlx, ts->val);
32
+ printf("$0x%" PRIx64, ts->val);
33
break;
34
case TEMP_VAL_DEAD:
35
printf("D");
36
--
37
2.25.1
38
39
diff view generated by jsdifflib
New patch
1
Fix this name vs our coding style.
1
2
3
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
4
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
5
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
6
---
7
tcg/optimize.c | 32 ++++++++++++++++----------------
8
1 file changed, 16 insertions(+), 16 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 @@
15
glue(glue(case INDEX_op_, x), _i64): \
16
glue(glue(case INDEX_op_, x), _vec)
17
18
-struct tcg_temp_info {
19
+typedef struct TempOptInfo {
20
bool is_const;
21
TCGTemp *prev_copy;
22
TCGTemp *next_copy;
23
tcg_target_ulong val;
24
tcg_target_ulong mask;
25
-};
26
+} TempOptInfo;
27
28
-static inline struct tcg_temp_info *ts_info(TCGTemp *ts)
29
+static inline TempOptInfo *ts_info(TCGTemp *ts)
30
{
31
return ts->state_ptr;
32
}
33
34
-static inline struct tcg_temp_info *arg_info(TCGArg arg)
35
+static inline TempOptInfo *arg_info(TCGArg arg)
36
{
37
return ts_info(arg_temp(arg));
38
}
39
@@ -XXX,XX +XXX,XX @@ static inline bool ts_is_copy(TCGTemp *ts)
40
/* Reset TEMP's state, possibly removing the temp for the list of copies. */
41
static void reset_ts(TCGTemp *ts)
42
{
43
- struct tcg_temp_info *ti = ts_info(ts);
44
- struct tcg_temp_info *pi = ts_info(ti->prev_copy);
45
- struct tcg_temp_info *ni = ts_info(ti->next_copy);
46
+ TempOptInfo *ti = ts_info(ts);
47
+ TempOptInfo *pi = ts_info(ti->prev_copy);
48
+ TempOptInfo *ni = ts_info(ti->next_copy);
49
50
ni->prev_copy = ti->prev_copy;
51
pi->next_copy = ti->next_copy;
52
@@ -XXX,XX +XXX,XX @@ static void reset_temp(TCGArg arg)
53
}
54
55
/* Initialize and activate a temporary. */
56
-static void init_ts_info(struct tcg_temp_info *infos,
57
+static void init_ts_info(TempOptInfo *infos,
58
TCGTempSet *temps_used, TCGTemp *ts)
59
{
60
size_t idx = temp_idx(ts);
61
if (!test_bit(idx, temps_used->l)) {
62
- struct tcg_temp_info *ti = &infos[idx];
63
+ TempOptInfo *ti = &infos[idx];
64
65
ts->state_ptr = ti;
66
ti->next_copy = ts;
67
@@ -XXX,XX +XXX,XX @@ static void init_ts_info(struct tcg_temp_info *infos,
68
}
69
}
70
71
-static void init_arg_info(struct tcg_temp_info *infos,
72
+static void init_arg_info(TempOptInfo *infos,
73
TCGTempSet *temps_used, TCGArg arg)
74
{
75
init_ts_info(infos, temps_used, arg_temp(arg));
76
@@ -XXX,XX +XXX,XX @@ static void tcg_opt_gen_movi(TCGContext *s, TCGOp *op, TCGArg dst, TCGArg val)
77
const TCGOpDef *def;
78
TCGOpcode new_op;
79
tcg_target_ulong mask;
80
- struct tcg_temp_info *di = arg_info(dst);
81
+ TempOptInfo *di = arg_info(dst);
82
83
def = &tcg_op_defs[op->opc];
84
if (def->flags & TCG_OPF_VECTOR) {
85
@@ -XXX,XX +XXX,XX @@ static void tcg_opt_gen_mov(TCGContext *s, TCGOp *op, TCGArg dst, TCGArg src)
86
TCGTemp *dst_ts = arg_temp(dst);
87
TCGTemp *src_ts = arg_temp(src);
88
const TCGOpDef *def;
89
- struct tcg_temp_info *di;
90
- struct tcg_temp_info *si;
91
+ TempOptInfo *di;
92
+ TempOptInfo *si;
93
tcg_target_ulong mask;
94
TCGOpcode new_op;
95
96
@@ -XXX,XX +XXX,XX @@ static void tcg_opt_gen_mov(TCGContext *s, TCGOp *op, TCGArg dst, TCGArg src)
97
di->mask = mask;
98
99
if (src_ts->type == dst_ts->type) {
100
- struct tcg_temp_info *ni = ts_info(si->next_copy);
101
+ TempOptInfo *ni = ts_info(si->next_copy);
102
103
di->next_copy = si->next_copy;
104
di->prev_copy = src_ts;
105
@@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s)
106
{
107
int nb_temps, nb_globals;
108
TCGOp *op, *op_next, *prev_mb = NULL;
109
- struct tcg_temp_info *infos;
110
+ TempOptInfo *infos;
111
TCGTempSet temps_used;
112
113
/* Array VALS has an element for each temp.
114
@@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s)
115
nb_temps = s->nb_temps;
116
nb_globals = s->nb_globals;
117
bitmap_zero(temps_used.l, nb_temps);
118
- infos = tcg_malloc(sizeof(struct tcg_temp_info) * nb_temps);
119
+ infos = tcg_malloc(sizeof(TempOptInfo) * nb_temps);
120
121
QTAILQ_FOREACH_SAFE(op, &s->ops, link, op_next) {
122
tcg_target_ulong mask, partmask, affected;
123
--
124
2.25.1
125
126
diff view generated by jsdifflib
New patch
1
This propagates the extended value of TCGTemp.val that we did before.
2
In addition, it will be required for vector constants.
1
3
4
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
5
---
6
tcg/optimize.c | 40 +++++++++++++++++++++-------------------
7
1 file changed, 21 insertions(+), 19 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 @@ typedef struct TempOptInfo {
14
bool is_const;
15
TCGTemp *prev_copy;
16
TCGTemp *next_copy;
17
- tcg_target_ulong val;
18
- tcg_target_ulong mask;
19
+ uint64_t val;
20
+ uint64_t mask;
21
} TempOptInfo;
22
23
static inline TempOptInfo *ts_info(TCGTemp *ts)
24
@@ -XXX,XX +XXX,XX @@ static bool args_are_copies(TCGArg arg1, TCGArg arg2)
25
return ts_are_copies(arg_temp(arg1), arg_temp(arg2));
26
}
27
28
-static void tcg_opt_gen_movi(TCGContext *s, TCGOp *op, TCGArg dst, TCGArg val)
29
+static void tcg_opt_gen_movi(TCGContext *s, TCGOp *op, TCGArg dst, uint64_t val)
30
{
31
const TCGOpDef *def;
32
TCGOpcode new_op;
33
- tcg_target_ulong mask;
34
+ uint64_t mask;
35
TempOptInfo *di = arg_info(dst);
36
37
def = &tcg_op_defs[op->opc];
38
@@ -XXX,XX +XXX,XX @@ static void tcg_opt_gen_mov(TCGContext *s, TCGOp *op, TCGArg dst, TCGArg src)
39
const TCGOpDef *def;
40
TempOptInfo *di;
41
TempOptInfo *si;
42
- tcg_target_ulong mask;
43
+ uint64_t mask;
44
TCGOpcode new_op;
45
46
if (ts_are_copies(dst_ts, src_ts)) {
47
@@ -XXX,XX +XXX,XX @@ static void tcg_opt_gen_mov(TCGContext *s, TCGOp *op, TCGArg dst, TCGArg src)
48
}
49
}
50
51
-static TCGArg do_constant_folding_2(TCGOpcode op, TCGArg x, TCGArg y)
52
+static uint64_t do_constant_folding_2(TCGOpcode op, uint64_t x, uint64_t y)
53
{
54
uint64_t l64, h64;
55
56
@@ -XXX,XX +XXX,XX @@ static TCGArg do_constant_folding_2(TCGOpcode op, TCGArg x, TCGArg y)
57
}
58
}
59
60
-static TCGArg do_constant_folding(TCGOpcode op, TCGArg x, TCGArg y)
61
+static uint64_t do_constant_folding(TCGOpcode op, uint64_t x, uint64_t y)
62
{
63
const TCGOpDef *def = &tcg_op_defs[op];
64
- TCGArg res = do_constant_folding_2(op, x, y);
65
+ uint64_t res = do_constant_folding_2(op, x, y);
66
if (!(def->flags & TCG_OPF_64BIT)) {
67
res = (int32_t)res;
68
}
69
@@ -XXX,XX +XXX,XX @@ static bool do_constant_folding_cond_eq(TCGCond c)
70
static TCGArg do_constant_folding_cond(TCGOpcode op, TCGArg x,
71
TCGArg y, TCGCond c)
72
{
73
- tcg_target_ulong xv = arg_info(x)->val;
74
- tcg_target_ulong yv = arg_info(y)->val;
75
+ uint64_t xv = arg_info(x)->val;
76
+ uint64_t yv = arg_info(y)->val;
77
+
78
if (arg_is_const(x) && arg_is_const(y)) {
79
const TCGOpDef *def = &tcg_op_defs[op];
80
tcg_debug_assert(!(def->flags & TCG_OPF_VECTOR));
81
@@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s)
82
infos = tcg_malloc(sizeof(TempOptInfo) * nb_temps);
83
84
QTAILQ_FOREACH_SAFE(op, &s->ops, link, op_next) {
85
- tcg_target_ulong mask, partmask, affected;
86
+ uint64_t mask, partmask, affected, tmp;
87
int nb_oargs, nb_iargs, i;
88
- TCGArg tmp;
89
TCGOpcode opc = op->opc;
90
const TCGOpDef *def = &tcg_op_defs[opc];
91
92
@@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s)
93
94
CASE_OP_32_64(extract2):
95
if (arg_is_const(op->args[1]) && arg_is_const(op->args[2])) {
96
- TCGArg v1 = arg_info(op->args[1])->val;
97
- TCGArg v2 = arg_info(op->args[2])->val;
98
+ uint64_t v1 = arg_info(op->args[1])->val;
99
+ uint64_t v2 = arg_info(op->args[2])->val;
100
+ int shr = op->args[3];
101
102
if (opc == INDEX_op_extract2_i64) {
103
- tmp = (v1 >> op->args[3]) | (v2 << (64 - op->args[3]));
104
+ tmp = (v1 >> shr) | (v2 << (64 - shr));
105
} else {
106
- tmp = (int32_t)(((uint32_t)v1 >> op->args[3]) |
107
- ((uint32_t)v2 << (32 - op->args[3])));
108
+ tmp = (int32_t)(((uint32_t)v1 >> shr) |
109
+ ((uint32_t)v2 << (32 - shr)));
110
}
111
tcg_opt_gen_movi(s, op, op->args[0], tmp);
112
break;
113
@@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s)
114
break;
115
}
116
if (arg_is_const(op->args[3]) && arg_is_const(op->args[4])) {
117
- tcg_target_ulong tv = arg_info(op->args[3])->val;
118
- tcg_target_ulong fv = arg_info(op->args[4])->val;
119
+ uint64_t tv = arg_info(op->args[3])->val;
120
+ uint64_t fv = arg_info(op->args[4])->val;
121
TCGCond cond = op->args[5];
122
+
123
if (fv == 1 && tv == 0) {
124
cond = tcg_invert_cond(cond);
125
} else if (!(tv == 1 && fv == 0)) {
126
--
127
2.25.1
128
129
diff view generated by jsdifflib
New patch
1
These will hold a single constant for the duration of the TB.
2
They are hashed, so that each value has one temp across the TB.
1
3
4
Not used yet, this is all infrastructure.
5
6
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
7
---
8
include/tcg/tcg.h | 24 ++++-
9
tcg/optimize.c | 13 ++-
10
tcg/tcg.c | 224 ++++++++++++++++++++++++++++++++++++----------
11
3 files changed, 211 insertions(+), 50 deletions(-)
12
13
diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h
14
index XXXXXXX..XXXXXXX 100644
15
--- a/include/tcg/tcg.h
16
+++ b/include/tcg/tcg.h
17
@@ -XXX,XX +XXX,XX @@ typedef enum TCGTempKind {
18
TEMP_GLOBAL,
19
/* Temp is in a fixed register. */
20
TEMP_FIXED,
21
+ /* Temp is a fixed constant. */
22
+ TEMP_CONST,
23
} TCGTempKind;
24
25
typedef struct TCGTemp {
26
@@ -XXX,XX +XXX,XX @@ struct TCGContext {
27
QSIMPLEQ_HEAD(, TCGOp) plugin_ops;
28
#endif
29
30
+ GHashTable *const_table[TCG_TYPE_COUNT];
31
TCGTempSet free_temps[TCG_TYPE_COUNT * 2];
32
TCGTemp temps[TCG_MAX_TEMPS]; /* globals first, temps after */
33
34
@@ -XXX,XX +XXX,XX @@ struct TCGContext {
35
36
static inline bool temp_readonly(TCGTemp *ts)
37
{
38
- return ts->kind == TEMP_FIXED;
39
+ return ts->kind >= TEMP_FIXED;
40
}
41
42
extern TCGContext tcg_init_ctx;
43
@@ -XXX,XX +XXX,XX @@ TCGOp *tcg_op_insert_after(TCGContext *s, TCGOp *op, TCGOpcode opc);
44
45
void tcg_optimize(TCGContext *s);
46
47
+/* Allocate a new temporary and initialize it with a constant. */
48
TCGv_i32 tcg_const_i32(int32_t val);
49
TCGv_i64 tcg_const_i64(int64_t val);
50
TCGv_i32 tcg_const_local_i32(int32_t val);
51
@@ -XXX,XX +XXX,XX @@ TCGv_vec tcg_const_ones_vec(TCGType);
52
TCGv_vec tcg_const_zeros_vec_matching(TCGv_vec);
53
TCGv_vec tcg_const_ones_vec_matching(TCGv_vec);
54
55
+/*
56
+ * Locate or create a read-only temporary that is a constant.
57
+ * This kind of temporary need not and should not be freed.
58
+ */
59
+TCGTemp *tcg_constant_internal(TCGType type, int64_t val);
60
+
61
+static inline TCGv_i32 tcg_constant_i32(int32_t val)
62
+{
63
+ return temp_tcgv_i32(tcg_constant_internal(TCG_TYPE_I32, val));
64
+}
65
+
66
+static inline TCGv_i64 tcg_constant_i64(int64_t val)
67
+{
68
+ return temp_tcgv_i64(tcg_constant_internal(TCG_TYPE_I64, val));
69
+}
70
+
71
+TCGv_vec tcg_constant_vec(TCGType type, unsigned vece, int64_t val);
72
+
73
#if UINTPTR_MAX == UINT32_MAX
74
# define tcg_const_ptr(x) ((TCGv_ptr)tcg_const_i32((intptr_t)(x)))
75
# define tcg_const_local_ptr(x) ((TCGv_ptr)tcg_const_local_i32((intptr_t)(x)))
76
diff --git a/tcg/optimize.c b/tcg/optimize.c
77
index XXXXXXX..XXXXXXX 100644
78
--- a/tcg/optimize.c
79
+++ b/tcg/optimize.c
80
@@ -XXX,XX +XXX,XX @@ static void init_ts_info(TempOptInfo *infos,
81
ts->state_ptr = ti;
82
ti->next_copy = ts;
83
ti->prev_copy = ts;
84
- ti->is_const = false;
85
- ti->mask = -1;
86
+ if (ts->kind == TEMP_CONST) {
87
+ ti->is_const = true;
88
+ ti->val = ti->mask = ts->val;
89
+ if (TCG_TARGET_REG_BITS > 32 && ts->type == TCG_TYPE_I32) {
90
+ /* High bits of a 32-bit quantity are garbage. */
91
+ ti->mask |= ~0xffffffffull;
92
+ }
93
+ } else {
94
+ ti->is_const = false;
95
+ ti->mask = -1;
96
+ }
97
set_bit(idx, temps_used->l);
98
}
99
}
100
diff --git a/tcg/tcg.c b/tcg/tcg.c
101
index XXXXXXX..XXXXXXX 100644
102
--- a/tcg/tcg.c
103
+++ b/tcg/tcg.c
104
@@ -XXX,XX +XXX,XX @@ void tcg_func_start(TCGContext *s)
105
/* No temps have been previously allocated for size or locality. */
106
memset(s->free_temps, 0, sizeof(s->free_temps));
107
108
+ /* No constant temps have been previously allocated. */
109
+ for (int i = 0; i < TCG_TYPE_COUNT; ++i) {
110
+ if (s->const_table[i]) {
111
+ g_hash_table_remove_all(s->const_table[i]);
112
+ }
113
+ }
114
+
115
s->nb_ops = 0;
116
s->nb_labels = 0;
117
s->current_frame_offset = s->frame_start;
118
@@ -XXX,XX +XXX,XX @@ TCGTemp *tcg_global_mem_new_internal(TCGType type, TCGv_ptr base,
119
bigendian = 1;
120
#endif
121
122
- if (base_ts->kind != TEMP_FIXED) {
123
+ switch (base_ts->kind) {
124
+ case TEMP_FIXED:
125
+ break;
126
+ case TEMP_GLOBAL:
127
/* We do not support double-indirect registers. */
128
tcg_debug_assert(!base_ts->indirect_reg);
129
base_ts->indirect_base = 1;
130
s->nb_indirects += (TCG_TARGET_REG_BITS == 32 && type == TCG_TYPE_I64
131
? 2 : 1);
132
indirect_reg = 1;
133
+ break;
134
+ default:
135
+ g_assert_not_reached();
136
}
137
138
if (TCG_TARGET_REG_BITS == 32 && type == TCG_TYPE_I64) {
139
@@ -XXX,XX +XXX,XX @@ void tcg_temp_free_internal(TCGTemp *ts)
140
TCGContext *s = tcg_ctx;
141
int k, idx;
142
143
+ /* In order to simplify users of tcg_constant_*, silently ignore free. */
144
+ if (ts->kind == TEMP_CONST) {
145
+ return;
146
+ }
147
+
148
#if defined(CONFIG_DEBUG_TCG)
149
s->temps_in_use--;
150
if (s->temps_in_use < 0) {
151
@@ -XXX,XX +XXX,XX @@ void tcg_temp_free_internal(TCGTemp *ts)
152
set_bit(idx, s->free_temps[k].l);
153
}
154
155
+TCGTemp *tcg_constant_internal(TCGType type, int64_t val)
156
+{
157
+ TCGContext *s = tcg_ctx;
158
+ GHashTable *h = s->const_table[type];
159
+ TCGTemp *ts;
160
+
161
+ if (h == NULL) {
162
+ h = g_hash_table_new(g_int64_hash, g_int64_equal);
163
+ s->const_table[type] = h;
164
+ }
165
+
166
+ ts = g_hash_table_lookup(h, &val);
167
+ if (ts == NULL) {
168
+ ts = tcg_temp_alloc(s);
169
+
170
+ if (TCG_TARGET_REG_BITS == 32 && type == TCG_TYPE_I64) {
171
+ TCGTemp *ts2 = tcg_temp_alloc(s);
172
+
173
+ ts->base_type = TCG_TYPE_I64;
174
+ ts->type = TCG_TYPE_I32;
175
+ ts->kind = TEMP_CONST;
176
+ ts->temp_allocated = 1;
177
+ /*
178
+ * Retain the full value of the 64-bit constant in the low
179
+ * part, so that the hash table works. Actual uses will
180
+ * truncate the value to the low part.
181
+ */
182
+ ts->val = val;
183
+
184
+ tcg_debug_assert(ts2 == ts + 1);
185
+ ts2->base_type = TCG_TYPE_I64;
186
+ ts2->type = TCG_TYPE_I32;
187
+ ts2->kind = TEMP_CONST;
188
+ ts2->temp_allocated = 1;
189
+ ts2->val = val >> 32;
190
+ } else {
191
+ ts->base_type = type;
192
+ ts->type = type;
193
+ ts->kind = TEMP_CONST;
194
+ ts->temp_allocated = 1;
195
+ ts->val = val;
196
+ }
197
+ g_hash_table_insert(h, &ts->val, ts);
198
+ }
199
+
200
+ return ts;
201
+}
202
+
203
+TCGv_vec tcg_constant_vec(TCGType type, unsigned vece, int64_t val)
204
+{
205
+ val = dup_const(vece, val);
206
+ return temp_tcgv_vec(tcg_constant_internal(type, val));
207
+}
208
+
209
TCGv_i32 tcg_const_i32(int32_t val)
210
{
211
TCGv_i32 t0;
212
@@ -XXX,XX +XXX,XX @@ static void tcg_reg_alloc_start(TCGContext *s)
213
TCGTempVal val = TEMP_VAL_MEM;
214
215
switch (ts->kind) {
216
+ case TEMP_CONST:
217
+ val = TEMP_VAL_CONST;
218
+ break;
219
case TEMP_FIXED:
220
val = TEMP_VAL_REG;
221
break;
222
@@ -XXX,XX +XXX,XX @@ static char *tcg_get_arg_str_ptr(TCGContext *s, char *buf, int buf_size,
223
case TEMP_NORMAL:
224
snprintf(buf, buf_size, "tmp%d", idx - s->nb_globals);
225
break;
226
+ case TEMP_CONST:
227
+ switch (ts->type) {
228
+ case TCG_TYPE_I32:
229
+ snprintf(buf, buf_size, "$0x%x", (int32_t)ts->val);
230
+ break;
231
+#if TCG_TARGET_REG_BITS > 32
232
+ case TCG_TYPE_I64:
233
+ snprintf(buf, buf_size, "$0x%" PRIx64, ts->val);
234
+ break;
235
+#endif
236
+ case TCG_TYPE_V64:
237
+ case TCG_TYPE_V128:
238
+ case TCG_TYPE_V256:
239
+ snprintf(buf, buf_size, "v%d$0x%" PRIx64,
240
+ 64 << (ts->type - TCG_TYPE_V64), ts->val);
241
+ break;
242
+ default:
243
+ g_assert_not_reached();
244
+ }
245
+ break;
246
}
247
return buf;
248
}
249
@@ -XXX,XX +XXX,XX @@ static void la_bb_end(TCGContext *s, int ng, int nt)
250
state = TS_DEAD | TS_MEM;
251
break;
252
case TEMP_NORMAL:
253
+ case TEMP_CONST:
254
state = TS_DEAD;
255
break;
256
default:
257
@@ -XXX,XX +XXX,XX @@ static void la_bb_sync(TCGContext *s, int ng, int nt)
258
la_global_sync(s, ng);
259
260
for (int i = ng; i < nt; ++i) {
261
- if (s->temps[i].kind == TEMP_LOCAL) {
262
- int state = s->temps[i].state;
263
- s->temps[i].state = state | TS_MEM;
264
+ TCGTemp *ts = &s->temps[i];
265
+ int state;
266
+
267
+ switch (ts->kind) {
268
+ case TEMP_LOCAL:
269
+ state = ts->state;
270
+ ts->state = state | TS_MEM;
271
if (state != TS_DEAD) {
272
continue;
273
}
274
- } else {
275
+ break;
276
+ case TEMP_NORMAL:
277
s->temps[i].state = TS_DEAD;
278
+ break;
279
+ case TEMP_CONST:
280
+ continue;
281
+ default:
282
+ g_assert_not_reached();
283
}
284
la_reset_pref(&s->temps[i]);
285
}
286
@@ -XXX,XX +XXX,XX @@ static void temp_load(TCGContext *, TCGTemp *, TCGRegSet, TCGRegSet, TCGRegSet);
287
mark it free; otherwise mark it dead. */
288
static void temp_free_or_dead(TCGContext *s, TCGTemp *ts, int free_or_dead)
289
{
290
- if (temp_readonly(ts)) {
291
+ TCGTempVal new_type;
292
+
293
+ switch (ts->kind) {
294
+ case TEMP_FIXED:
295
return;
296
+ case TEMP_GLOBAL:
297
+ case TEMP_LOCAL:
298
+ new_type = TEMP_VAL_MEM;
299
+ break;
300
+ case TEMP_NORMAL:
301
+ new_type = free_or_dead < 0 ? TEMP_VAL_MEM : TEMP_VAL_DEAD;
302
+ break;
303
+ case TEMP_CONST:
304
+ new_type = TEMP_VAL_CONST;
305
+ break;
306
+ default:
307
+ g_assert_not_reached();
308
}
309
if (ts->val_type == TEMP_VAL_REG) {
310
s->reg_to_temp[ts->reg] = NULL;
311
}
312
- ts->val_type = (free_or_dead < 0
313
- || ts->kind != TEMP_NORMAL
314
- ? TEMP_VAL_MEM : TEMP_VAL_DEAD);
315
+ ts->val_type = new_type;
316
}
317
318
/* Mark a temporary as dead. */
319
@@ -XXX,XX +XXX,XX @@ static inline void temp_dead(TCGContext *s, TCGTemp *ts)
320
static void temp_sync(TCGContext *s, TCGTemp *ts, TCGRegSet allocated_regs,
321
TCGRegSet preferred_regs, int free_or_dead)
322
{
323
- if (temp_readonly(ts)) {
324
- return;
325
- }
326
- if (!ts->mem_coherent) {
327
+ if (!temp_readonly(ts) && !ts->mem_coherent) {
328
if (!ts->mem_allocated) {
329
temp_allocate_frame(s, ts);
330
}
331
@@ -XXX,XX +XXX,XX @@ static void tcg_reg_alloc_bb_end(TCGContext *s, TCGRegSet allocated_regs)
332
333
for (i = s->nb_globals; i < s->nb_temps; i++) {
334
TCGTemp *ts = &s->temps[i];
335
- if (ts->kind == TEMP_LOCAL) {
336
+
337
+ switch (ts->kind) {
338
+ case TEMP_LOCAL:
339
temp_save(s, ts, allocated_regs);
340
- } else {
341
+ break;
342
+ case TEMP_NORMAL:
343
/* The liveness analysis already ensures that temps are dead.
344
Keep an tcg_debug_assert for safety. */
345
tcg_debug_assert(ts->val_type == TEMP_VAL_DEAD);
346
+ break;
347
+ case TEMP_CONST:
348
+ /* Similarly, we should have freed any allocated register. */
349
+ tcg_debug_assert(ts->val_type == TEMP_VAL_CONST);
350
+ break;
351
+ default:
352
+ g_assert_not_reached();
353
}
354
}
355
356
@@ -XXX,XX +XXX,XX @@ static void tcg_reg_alloc_cbranch(TCGContext *s, TCGRegSet allocated_regs)
357
* The liveness analysis already ensures that temps are dead.
358
* Keep tcg_debug_asserts for safety.
359
*/
360
- if (ts->kind == TEMP_LOCAL) {
361
+ switch (ts->kind) {
362
+ case TEMP_LOCAL:
363
tcg_debug_assert(ts->val_type != TEMP_VAL_REG || ts->mem_coherent);
364
- } else {
365
+ break;
366
+ case TEMP_NORMAL:
367
tcg_debug_assert(ts->val_type == TEMP_VAL_DEAD);
368
+ break;
369
+ case TEMP_CONST:
370
+ break;
371
+ default:
372
+ g_assert_not_reached();
373
}
374
}
375
}
376
@@ -XXX,XX +XXX,XX @@ static void tcg_reg_alloc_op(TCGContext *s, const TCGOp *op)
377
i_preferred_regs = o_preferred_regs = 0;
378
if (arg_ct->ialias) {
379
o_preferred_regs = op->output_pref[arg_ct->alias_index];
380
- if (ts->kind == TEMP_FIXED) {
381
- /* if fixed register, we must allocate a new register
382
- if the alias is not the same register */
383
- if (arg != op->args[arg_ct->alias_index]) {
384
- goto allocate_in_reg;
385
- }
386
- } else {
387
- /* if the input is aliased to an output and if it is
388
- not dead after the instruction, we must allocate
389
- a new register and move it */
390
- if (!IS_DEAD_ARG(i)) {
391
- goto allocate_in_reg;
392
- }
393
394
- /* check if the current register has already been allocated
395
- for another input aliased to an output */
396
- if (ts->val_type == TEMP_VAL_REG) {
397
- int k2, i2;
398
- reg = ts->reg;
399
- for (k2 = 0 ; k2 < k ; k2++) {
400
- i2 = def->args_ct[nb_oargs + k2].sort_index;
401
- if (def->args_ct[i2].ialias && reg == new_args[i2]) {
402
- goto allocate_in_reg;
403
- }
404
+ /*
405
+ * If the input is readonly, then it cannot also be an
406
+ * output and aliased to itself. If the input is not
407
+ * dead after the instruction, we must allocate a new
408
+ * register and move it.
409
+ */
410
+ if (temp_readonly(ts) || !IS_DEAD_ARG(i)) {
411
+ goto allocate_in_reg;
412
+ }
413
+
414
+ /*
415
+ * Check if the current register has already been allocated
416
+ * for another input aliased to an output.
417
+ */
418
+ if (ts->val_type == TEMP_VAL_REG) {
419
+ reg = ts->reg;
420
+ for (int k2 = 0; k2 < k; k2++) {
421
+ int i2 = def->args_ct[nb_oargs + k2].sort_index;
422
+ if (def->args_ct[i2].ialias && reg == new_args[i2]) {
423
+ goto allocate_in_reg;
424
}
425
}
426
- i_preferred_regs = o_preferred_regs;
427
}
428
+ i_preferred_regs = o_preferred_regs;
429
}
430
431
temp_load(s, ts, arg_ct->regs, i_allocated_regs, i_preferred_regs);
432
reg = ts->reg;
433
434
- if (tcg_regset_test_reg(arg_ct->regs, reg)) {
435
- /* nothing to do : the constraint is satisfied */
436
- } else {
437
- allocate_in_reg:
438
- /* allocate a new register matching the constraint
439
- and move the temporary register into it */
440
+ if (!tcg_regset_test_reg(arg_ct->regs, reg)) {
441
+ allocate_in_reg:
442
+ /*
443
+ * Allocate a new register matching the constraint
444
+ * and move the temporary register into it.
445
+ */
446
temp_load(s, ts, tcg_target_available_regs[ts->type],
447
i_allocated_regs, 0);
448
reg = tcg_reg_alloc(s, arg_ct->regs, i_allocated_regs,
449
--
450
2.25.1
451
452
diff view generated by jsdifflib
New patch
1
Prefer TEMP_CONST over anything else.
1
2
3
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
4
---
5
tcg/optimize.c | 27 ++++++++++++---------------
6
1 file changed, 12 insertions(+), 15 deletions(-)
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 void init_arg_info(TempOptInfo *infos,
13
14
static TCGTemp *find_better_copy(TCGContext *s, TCGTemp *ts)
15
{
16
- TCGTemp *i;
17
+ TCGTemp *i, *g, *l;
18
19
- /* If this is already a global, we can't do better. */
20
- if (ts->kind >= TEMP_GLOBAL) {
21
+ /* If this is already readonly, we can't do better. */
22
+ if (temp_readonly(ts)) {
23
return ts;
24
}
25
26
- /* Search for a global first. */
27
+ g = l = NULL;
28
for (i = ts_info(ts)->next_copy; i != ts; i = ts_info(i)->next_copy) {
29
- if (i->kind >= TEMP_GLOBAL) {
30
+ if (temp_readonly(i)) {
31
return i;
32
- }
33
- }
34
-
35
- /* If it is a temp, search for a temp local. */
36
- if (ts->kind == TEMP_NORMAL) {
37
- for (i = ts_info(ts)->next_copy; i != ts; i = ts_info(i)->next_copy) {
38
- if (i->kind >= TEMP_LOCAL) {
39
- return i;
40
+ } else if (i->kind > ts->kind) {
41
+ if (i->kind == TEMP_GLOBAL) {
42
+ g = i;
43
+ } else if (i->kind == TEMP_LOCAL) {
44
+ l = i;
45
}
46
}
47
}
48
49
- /* Failure to find a better representation, return the same temp. */
50
- return ts;
51
+ /* If we didn't find a better representation, return the same temp. */
52
+ return g ? g : l ? l : ts;
53
}
54
55
static bool ts_are_copies(TCGTemp *ts1, TCGTemp *ts2)
56
--
57
2.25.1
58
59
diff view generated by jsdifflib
New patch
1
Do not allocate a large block for indexing. Instead, allocate
2
for each temporary as they are seen.
1
3
4
In general, this will use less memory, if we consider that most
5
TBs do not touch every target register. This also allows us to
6
allocate TempOptInfo for new temps created during optimization.
7
8
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
9
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
10
---
11
tcg/optimize.c | 60 ++++++++++++++++++++++++++++----------------------
12
1 file changed, 34 insertions(+), 26 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 @@ static void reset_temp(TCGArg arg)
19
}
20
21
/* Initialize and activate a temporary. */
22
-static void init_ts_info(TempOptInfo *infos,
23
- TCGTempSet *temps_used, TCGTemp *ts)
24
+static void init_ts_info(TCGTempSet *temps_used, TCGTemp *ts)
25
{
26
size_t idx = temp_idx(ts);
27
- if (!test_bit(idx, temps_used->l)) {
28
- TempOptInfo *ti = &infos[idx];
29
+ TempOptInfo *ti;
30
31
+ if (test_bit(idx, temps_used->l)) {
32
+ return;
33
+ }
34
+ set_bit(idx, temps_used->l);
35
+
36
+ ti = ts->state_ptr;
37
+ if (ti == NULL) {
38
+ ti = tcg_malloc(sizeof(TempOptInfo));
39
ts->state_ptr = ti;
40
- ti->next_copy = ts;
41
- ti->prev_copy = ts;
42
- if (ts->kind == TEMP_CONST) {
43
- ti->is_const = true;
44
- ti->val = ti->mask = ts->val;
45
- if (TCG_TARGET_REG_BITS > 32 && ts->type == TCG_TYPE_I32) {
46
- /* High bits of a 32-bit quantity are garbage. */
47
- ti->mask |= ~0xffffffffull;
48
- }
49
- } else {
50
- ti->is_const = false;
51
- ti->mask = -1;
52
+ }
53
+
54
+ ti->next_copy = ts;
55
+ ti->prev_copy = ts;
56
+ if (ts->kind == TEMP_CONST) {
57
+ ti->is_const = true;
58
+ ti->val = ts->val;
59
+ ti->mask = ts->val;
60
+ if (TCG_TARGET_REG_BITS > 32 && ts->type == TCG_TYPE_I32) {
61
+ /* High bits of a 32-bit quantity are garbage. */
62
+ ti->mask |= ~0xffffffffull;
63
}
64
- set_bit(idx, temps_used->l);
65
+ } else {
66
+ ti->is_const = false;
67
+ ti->mask = -1;
68
}
69
}
70
71
-static void init_arg_info(TempOptInfo *infos,
72
- TCGTempSet *temps_used, TCGArg arg)
73
+static void init_arg_info(TCGTempSet *temps_used, TCGArg arg)
74
{
75
- init_ts_info(infos, temps_used, arg_temp(arg));
76
+ init_ts_info(temps_used, arg_temp(arg));
77
}
78
79
static TCGTemp *find_better_copy(TCGContext *s, TCGTemp *ts)
80
@@ -XXX,XX +XXX,XX @@ static bool swap_commutative2(TCGArg *p1, TCGArg *p2)
81
/* Propagate constants and copies, fold constant expressions. */
82
void tcg_optimize(TCGContext *s)
83
{
84
- int nb_temps, nb_globals;
85
+ int nb_temps, nb_globals, i;
86
TCGOp *op, *op_next, *prev_mb = NULL;
87
- TempOptInfo *infos;
88
TCGTempSet temps_used;
89
90
/* Array VALS has an element for each temp.
91
@@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s)
92
93
nb_temps = s->nb_temps;
94
nb_globals = s->nb_globals;
95
+
96
bitmap_zero(temps_used.l, nb_temps);
97
- infos = tcg_malloc(sizeof(TempOptInfo) * nb_temps);
98
+ for (i = 0; i < nb_temps; ++i) {
99
+ s->temps[i].state_ptr = NULL;
100
+ }
101
102
QTAILQ_FOREACH_SAFE(op, &s->ops, link, op_next) {
103
uint64_t mask, partmask, affected, tmp;
104
- int nb_oargs, nb_iargs, i;
105
+ int nb_oargs, nb_iargs;
106
TCGOpcode opc = op->opc;
107
const TCGOpDef *def = &tcg_op_defs[opc];
108
109
@@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s)
110
for (i = 0; i < nb_oargs + nb_iargs; i++) {
111
TCGTemp *ts = arg_temp(op->args[i]);
112
if (ts) {
113
- init_ts_info(infos, &temps_used, ts);
114
+ init_ts_info(&temps_used, ts);
115
}
116
}
117
} else {
118
nb_oargs = def->nb_oargs;
119
nb_iargs = def->nb_iargs;
120
for (i = 0; i < nb_oargs + nb_iargs; i++) {
121
- init_arg_info(infos, &temps_used, op->args[i]);
122
+ init_arg_info(&temps_used, op->args[i]);
123
}
124
}
125
126
--
127
2.25.1
128
129
diff view generated by jsdifflib
New patch
1
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
2
---
3
tcg/optimize.c | 108 ++++++++++++++++++++++---------------------------
4
1 file changed, 49 insertions(+), 59 deletions(-)
1
5
6
diff --git a/tcg/optimize.c b/tcg/optimize.c
7
index XXXXXXX..XXXXXXX 100644
8
--- a/tcg/optimize.c
9
+++ b/tcg/optimize.c
10
@@ -XXX,XX +XXX,XX @@ static bool args_are_copies(TCGArg arg1, TCGArg arg2)
11
return ts_are_copies(arg_temp(arg1), arg_temp(arg2));
12
}
13
14
-static void tcg_opt_gen_movi(TCGContext *s, TCGOp *op, TCGArg dst, uint64_t val)
15
-{
16
- const TCGOpDef *def;
17
- TCGOpcode new_op;
18
- uint64_t mask;
19
- TempOptInfo *di = arg_info(dst);
20
-
21
- def = &tcg_op_defs[op->opc];
22
- if (def->flags & TCG_OPF_VECTOR) {
23
- new_op = INDEX_op_dupi_vec;
24
- } else if (def->flags & TCG_OPF_64BIT) {
25
- new_op = INDEX_op_movi_i64;
26
- } else {
27
- new_op = INDEX_op_movi_i32;
28
- }
29
- op->opc = new_op;
30
- /* TCGOP_VECL and TCGOP_VECE remain unchanged. */
31
- op->args[0] = dst;
32
- op->args[1] = val;
33
-
34
- reset_temp(dst);
35
- di->is_const = true;
36
- di->val = val;
37
- mask = val;
38
- if (TCG_TARGET_REG_BITS > 32 && new_op == INDEX_op_movi_i32) {
39
- /* High bits of the destination are now garbage. */
40
- mask |= ~0xffffffffull;
41
- }
42
- di->mask = mask;
43
-}
44
-
45
static void tcg_opt_gen_mov(TCGContext *s, TCGOp *op, TCGArg dst, TCGArg src)
46
{
47
TCGTemp *dst_ts = arg_temp(dst);
48
@@ -XXX,XX +XXX,XX @@ static void tcg_opt_gen_mov(TCGContext *s, TCGOp *op, TCGArg dst, TCGArg src)
49
}
50
}
51
52
+static void tcg_opt_gen_movi(TCGContext *s, TCGTempSet *temps_used,
53
+ TCGOp *op, TCGArg dst, uint64_t val)
54
+{
55
+ const TCGOpDef *def = &tcg_op_defs[op->opc];
56
+ TCGType type;
57
+ TCGTemp *tv;
58
+
59
+ if (def->flags & TCG_OPF_VECTOR) {
60
+ type = TCGOP_VECL(op) + TCG_TYPE_V64;
61
+ } else if (def->flags & TCG_OPF_64BIT) {
62
+ type = TCG_TYPE_I64;
63
+ } else {
64
+ type = TCG_TYPE_I32;
65
+ }
66
+
67
+ /* Convert movi to mov with constant temp. */
68
+ tv = tcg_constant_internal(type, val);
69
+ init_ts_info(temps_used, tv);
70
+ tcg_opt_gen_mov(s, op, dst, temp_arg(tv));
71
+}
72
+
73
static uint64_t do_constant_folding_2(TCGOpcode op, uint64_t x, uint64_t y)
74
{
75
uint64_t l64, h64;
76
@@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s)
77
nb_temps = s->nb_temps;
78
nb_globals = s->nb_globals;
79
80
- bitmap_zero(temps_used.l, nb_temps);
81
+ memset(&temps_used, 0, sizeof(temps_used));
82
for (i = 0; i < nb_temps; ++i) {
83
s->temps[i].state_ptr = NULL;
84
}
85
@@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s)
86
CASE_OP_32_64(rotr):
87
if (arg_is_const(op->args[1])
88
&& arg_info(op->args[1])->val == 0) {
89
- tcg_opt_gen_movi(s, op, op->args[0], 0);
90
+ tcg_opt_gen_movi(s, &temps_used, op, op->args[0], 0);
91
continue;
92
}
93
break;
94
@@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s)
95
96
if (partmask == 0) {
97
tcg_debug_assert(nb_oargs == 1);
98
- tcg_opt_gen_movi(s, op, op->args[0], 0);
99
+ tcg_opt_gen_movi(s, &temps_used, op, op->args[0], 0);
100
continue;
101
}
102
if (affected == 0) {
103
@@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s)
104
CASE_OP_32_64(mulsh):
105
if (arg_is_const(op->args[2])
106
&& arg_info(op->args[2])->val == 0) {
107
- tcg_opt_gen_movi(s, op, op->args[0], 0);
108
+ tcg_opt_gen_movi(s, &temps_used, op, op->args[0], 0);
109
continue;
110
}
111
break;
112
@@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s)
113
CASE_OP_32_64_VEC(sub):
114
CASE_OP_32_64_VEC(xor):
115
if (args_are_copies(op->args[1], op->args[2])) {
116
- tcg_opt_gen_movi(s, op, op->args[0], 0);
117
+ tcg_opt_gen_movi(s, &temps_used, op, op->args[0], 0);
118
continue;
119
}
120
break;
121
@@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s)
122
break;
123
CASE_OP_32_64(movi):
124
case INDEX_op_dupi_vec:
125
- tcg_opt_gen_movi(s, op, op->args[0], op->args[1]);
126
+ tcg_opt_gen_movi(s, &temps_used, op, op->args[0], op->args[1]);
127
break;
128
129
case INDEX_op_dup_vec:
130
if (arg_is_const(op->args[1])) {
131
tmp = arg_info(op->args[1])->val;
132
tmp = dup_const(TCGOP_VECE(op), tmp);
133
- tcg_opt_gen_movi(s, op, op->args[0], tmp);
134
+ tcg_opt_gen_movi(s, &temps_used, op, op->args[0], tmp);
135
break;
136
}
137
goto do_default;
138
@@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s)
139
if (arg_is_const(op->args[1]) && arg_is_const(op->args[2])) {
140
tmp = arg_info(op->args[1])->val;
141
if (tmp == arg_info(op->args[2])->val) {
142
- tcg_opt_gen_movi(s, op, op->args[0], tmp);
143
+ tcg_opt_gen_movi(s, &temps_used, op, op->args[0], tmp);
144
break;
145
}
146
} else if (args_are_copies(op->args[1], op->args[2])) {
147
@@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s)
148
case INDEX_op_extrh_i64_i32:
149
if (arg_is_const(op->args[1])) {
150
tmp = do_constant_folding(opc, arg_info(op->args[1])->val, 0);
151
- tcg_opt_gen_movi(s, op, op->args[0], tmp);
152
+ tcg_opt_gen_movi(s, &temps_used, op, op->args[0], tmp);
153
break;
154
}
155
goto do_default;
156
@@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s)
157
if (arg_is_const(op->args[1]) && arg_is_const(op->args[2])) {
158
tmp = do_constant_folding(opc, arg_info(op->args[1])->val,
159
arg_info(op->args[2])->val);
160
- tcg_opt_gen_movi(s, op, op->args[0], tmp);
161
+ tcg_opt_gen_movi(s, &temps_used, op, op->args[0], tmp);
162
break;
163
}
164
goto do_default;
165
@@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s)
166
TCGArg v = arg_info(op->args[1])->val;
167
if (v != 0) {
168
tmp = do_constant_folding(opc, v, 0);
169
- tcg_opt_gen_movi(s, op, op->args[0], tmp);
170
+ tcg_opt_gen_movi(s, &temps_used, op, op->args[0], tmp);
171
} else {
172
tcg_opt_gen_mov(s, op, op->args[0], op->args[2]);
173
}
174
@@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s)
175
tmp = deposit64(arg_info(op->args[1])->val,
176
op->args[3], op->args[4],
177
arg_info(op->args[2])->val);
178
- tcg_opt_gen_movi(s, op, op->args[0], tmp);
179
+ tcg_opt_gen_movi(s, &temps_used, op, op->args[0], tmp);
180
break;
181
}
182
goto do_default;
183
@@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s)
184
if (arg_is_const(op->args[1])) {
185
tmp = extract64(arg_info(op->args[1])->val,
186
op->args[2], op->args[3]);
187
- tcg_opt_gen_movi(s, op, op->args[0], tmp);
188
+ tcg_opt_gen_movi(s, &temps_used, op, op->args[0], tmp);
189
break;
190
}
191
goto do_default;
192
@@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s)
193
if (arg_is_const(op->args[1])) {
194
tmp = sextract64(arg_info(op->args[1])->val,
195
op->args[2], op->args[3]);
196
- tcg_opt_gen_movi(s, op, op->args[0], tmp);
197
+ tcg_opt_gen_movi(s, &temps_used, op, op->args[0], tmp);
198
break;
199
}
200
goto do_default;
201
@@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s)
202
tmp = (int32_t)(((uint32_t)v1 >> shr) |
203
((uint32_t)v2 << (32 - shr)));
204
}
205
- tcg_opt_gen_movi(s, op, op->args[0], tmp);
206
+ tcg_opt_gen_movi(s, &temps_used, op, op->args[0], tmp);
207
break;
208
}
209
goto do_default;
210
@@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s)
211
tmp = do_constant_folding_cond(opc, op->args[1],
212
op->args[2], op->args[3]);
213
if (tmp != 2) {
214
- tcg_opt_gen_movi(s, op, op->args[0], tmp);
215
+ tcg_opt_gen_movi(s, &temps_used, op, op->args[0], tmp);
216
break;
217
}
218
goto do_default;
219
@@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s)
220
op->args[1], op->args[2]);
221
if (tmp != 2) {
222
if (tmp) {
223
- bitmap_zero(temps_used.l, nb_temps);
224
+ memset(&temps_used, 0, sizeof(temps_used));
225
op->opc = INDEX_op_br;
226
op->args[0] = op->args[3];
227
} else {
228
@@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s)
229
uint64_t a = ((uint64_t)ah << 32) | al;
230
uint64_t b = ((uint64_t)bh << 32) | bl;
231
TCGArg rl, rh;
232
- TCGOp *op2 = tcg_op_insert_before(s, op, INDEX_op_movi_i32);
233
+ TCGOp *op2 = tcg_op_insert_before(s, op, INDEX_op_mov_i32);
234
235
if (opc == INDEX_op_add2_i32) {
236
a += b;
237
@@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s)
238
239
rl = op->args[0];
240
rh = op->args[1];
241
- tcg_opt_gen_movi(s, op, rl, (int32_t)a);
242
- tcg_opt_gen_movi(s, op2, rh, (int32_t)(a >> 32));
243
+ tcg_opt_gen_movi(s, &temps_used, op, rl, (int32_t)a);
244
+ tcg_opt_gen_movi(s, &temps_used, op2, rh, (int32_t)(a >> 32));
245
break;
246
}
247
goto do_default;
248
@@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s)
249
uint32_t b = arg_info(op->args[3])->val;
250
uint64_t r = (uint64_t)a * b;
251
TCGArg rl, rh;
252
- TCGOp *op2 = tcg_op_insert_before(s, op, INDEX_op_movi_i32);
253
+ TCGOp *op2 = tcg_op_insert_before(s, op, INDEX_op_mov_i32);
254
255
rl = op->args[0];
256
rh = op->args[1];
257
- tcg_opt_gen_movi(s, op, rl, (int32_t)r);
258
- tcg_opt_gen_movi(s, op2, rh, (int32_t)(r >> 32));
259
+ tcg_opt_gen_movi(s, &temps_used, op, rl, (int32_t)r);
260
+ tcg_opt_gen_movi(s, &temps_used, op2, rh, (int32_t)(r >> 32));
261
break;
262
}
263
goto do_default;
264
@@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s)
265
if (tmp != 2) {
266
if (tmp) {
267
do_brcond_true:
268
- bitmap_zero(temps_used.l, nb_temps);
269
+ memset(&temps_used, 0, sizeof(temps_used));
270
op->opc = INDEX_op_br;
271
op->args[0] = op->args[5];
272
} else {
273
@@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s)
274
/* Simplify LT/GE comparisons vs zero to a single compare
275
vs the high word of the input. */
276
do_brcond_high:
277
- bitmap_zero(temps_used.l, nb_temps);
278
+ memset(&temps_used, 0, sizeof(temps_used));
279
op->opc = INDEX_op_brcond_i32;
280
op->args[0] = op->args[1];
281
op->args[1] = op->args[3];
282
@@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s)
283
goto do_default;
284
}
285
do_brcond_low:
286
- bitmap_zero(temps_used.l, nb_temps);
287
+ memset(&temps_used, 0, sizeof(temps_used));
288
op->opc = INDEX_op_brcond_i32;
289
op->args[1] = op->args[2];
290
op->args[2] = op->args[4];
291
@@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s)
292
op->args[5]);
293
if (tmp != 2) {
294
do_setcond_const:
295
- tcg_opt_gen_movi(s, op, op->args[0], tmp);
296
+ tcg_opt_gen_movi(s, &temps_used, op, op->args[0], tmp);
297
} else if ((op->args[5] == TCG_COND_LT
298
|| op->args[5] == TCG_COND_GE)
299
&& arg_is_const(op->args[3])
300
@@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s)
301
block, otherwise we only trash the output args. "mask" is
302
the non-zero bits mask for the first output arg. */
303
if (def->flags & TCG_OPF_BB_END) {
304
- bitmap_zero(temps_used.l, nb_temps);
305
+ memset(&temps_used, 0, sizeof(temps_used));
306
} else {
307
do_reset_output:
308
for (i = 0; i < nb_oargs; i++) {
309
--
310
2.25.1
311
312
diff view generated by jsdifflib
1
From: Claudio Fontana <cfontana@suse.de>
1
Because we now store uint64_t in TCGTemp, we can now always
2
store the full 64-bit duplicate immediate. So remove the
3
difference between 32- and 64-bit hosts.
2
4
3
Signed-off-by: Claudio Fontana <cfontana@suse.de>
4
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
5
Message-Id: <20201015143217.29337-4-cfontana@suse.de>
6
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
5
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
7
---
6
---
8
accel/tcg/tcg-cpus-icount.h | 6 +--
7
tcg/optimize.c | 9 ++++-----
9
accel/tcg/tcg-cpus-rr.h | 2 +-
8
tcg/tcg-op-vec.c | 39 ++++++++++-----------------------------
10
accel/tcg/tcg-cpus.h | 6 +--
9
tcg/tcg.c | 7 +------
11
accel/tcg/tcg-cpus-icount.c | 24 ++++++------
10
3 files changed, 15 insertions(+), 40 deletions(-)
12
accel/tcg/tcg-cpus-mttcg.c | 10 ++---
13
accel/tcg/tcg-cpus-rr.c | 74 ++++++++++++++++++-------------------
14
accel/tcg/tcg-cpus.c | 6 +--
15
7 files changed, 64 insertions(+), 64 deletions(-)
16
11
17
diff --git a/accel/tcg/tcg-cpus-icount.h b/accel/tcg/tcg-cpus-icount.h
12
diff --git a/tcg/optimize.c b/tcg/optimize.c
18
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
19
--- a/accel/tcg/tcg-cpus-icount.h
14
--- a/tcg/optimize.c
20
+++ b/accel/tcg/tcg-cpus-icount.h
15
+++ b/tcg/optimize.c
21
@@ -XXX,XX +XXX,XX @@
16
@@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s)
22
#ifndef TCG_CPUS_ICOUNT_H
17
case INDEX_op_dup2_vec:
23
#define TCG_CPUS_ICOUNT_H
18
assert(TCG_TARGET_REG_BITS == 32);
24
19
if (arg_is_const(op->args[1]) && arg_is_const(op->args[2])) {
25
-void handle_icount_deadline(void);
20
- tmp = arg_info(op->args[1])->val;
26
-void prepare_icount_for_run(CPUState *cpu);
21
- if (tmp == arg_info(op->args[2])->val) {
27
-void process_icount_data(CPUState *cpu);
22
- tcg_opt_gen_movi(s, &temps_used, op, op->args[0], tmp);
28
+void icount_handle_deadline(void);
23
- break;
29
+void icount_prepare_for_run(CPUState *cpu);
24
- }
30
+void icount_process_data(CPUState *cpu);
25
+ tcg_opt_gen_movi(s, &temps_used, op, op->args[0],
31
26
+ deposit64(arg_info(op->args[1])->val, 32, 32,
32
#endif /* TCG_CPUS_ICOUNT_H */
27
+ arg_info(op->args[2])->val));
33
diff --git a/accel/tcg/tcg-cpus-rr.h b/accel/tcg/tcg-cpus-rr.h
28
+ break;
29
} else if (args_are_copies(op->args[1], op->args[2])) {
30
op->opc = INDEX_op_dup_vec;
31
TCGOP_VECE(op) = MO_32;
32
diff --git a/tcg/tcg-op-vec.c b/tcg/tcg-op-vec.c
34
index XXXXXXX..XXXXXXX 100644
33
index XXXXXXX..XXXXXXX 100644
35
--- a/accel/tcg/tcg-cpus-rr.h
34
--- a/tcg/tcg-op-vec.c
36
+++ b/accel/tcg/tcg-cpus-rr.h
35
+++ b/tcg/tcg-op-vec.c
37
@@ -XXX,XX +XXX,XX @@
36
@@ -XXX,XX +XXX,XX @@ void tcg_gen_mov_vec(TCGv_vec r, TCGv_vec a)
38
#define TCG_KICK_PERIOD (NANOSECONDS_PER_SECOND / 10)
39
40
/* Kick all RR vCPUs. */
41
-void qemu_cpu_kick_rr_cpus(CPUState *unused);
42
+void rr_kick_vcpu_thread(CPUState *unused);
43
44
/* start the round robin vcpu thread */
45
void rr_start_vcpu_thread(CPUState *cpu);
46
diff --git a/accel/tcg/tcg-cpus.h b/accel/tcg/tcg-cpus.h
47
index XXXXXXX..XXXXXXX 100644
48
--- a/accel/tcg/tcg-cpus.h
49
+++ b/accel/tcg/tcg-cpus.h
50
@@ -XXX,XX +XXX,XX @@ extern const CpusAccel tcg_cpus_mttcg;
51
extern const CpusAccel tcg_cpus_icount;
52
extern const CpusAccel tcg_cpus_rr;
53
54
-void qemu_tcg_destroy_vcpu(CPUState *cpu);
55
-int tcg_cpu_exec(CPUState *cpu);
56
-void tcg_handle_interrupt(CPUState *cpu, int mask);
57
+void tcg_cpus_destroy(CPUState *cpu);
58
+int tcg_cpus_exec(CPUState *cpu);
59
+void tcg_cpus_handle_interrupt(CPUState *cpu, int mask);
60
61
#endif /* TCG_CPUS_H */
62
diff --git a/accel/tcg/tcg-cpus-icount.c b/accel/tcg/tcg-cpus-icount.c
63
index XXXXXXX..XXXXXXX 100644
64
--- a/accel/tcg/tcg-cpus-icount.c
65
+++ b/accel/tcg/tcg-cpus-icount.c
66
@@ -XXX,XX +XXX,XX @@
67
#include "tcg-cpus-icount.h"
68
#include "tcg-cpus-rr.h"
69
70
-static int64_t tcg_get_icount_limit(void)
71
+static int64_t icount_get_limit(void)
72
{
73
int64_t deadline;
74
75
@@ -XXX,XX +XXX,XX @@ static int64_t tcg_get_icount_limit(void)
76
}
37
}
77
}
38
}
78
39
79
-static void notify_aio_contexts(void)
40
-#define MO_REG (TCG_TARGET_REG_BITS == 64 ? MO_64 : MO_32)
80
+static void icount_notify_aio_contexts(void)
41
-
42
-static void do_dupi_vec(TCGv_vec r, unsigned vece, TCGArg a)
43
-{
44
- TCGTemp *rt = tcgv_vec_temp(r);
45
- vec_gen_2(INDEX_op_dupi_vec, rt->base_type, vece, temp_arg(rt), a);
46
-}
47
-
48
TCGv_vec tcg_const_zeros_vec(TCGType type)
81
{
49
{
82
/* Wake up other AioContexts. */
50
TCGv_vec ret = tcg_temp_new_vec(type);
83
qemu_clock_notify(QEMU_CLOCK_VIRTUAL);
51
- do_dupi_vec(ret, MO_REG, 0);
84
qemu_clock_run_timers(QEMU_CLOCK_VIRTUAL);
52
+ tcg_gen_dupi_vec(MO_64, ret, 0);
53
return ret;
85
}
54
}
86
55
87
-void handle_icount_deadline(void)
56
TCGv_vec tcg_const_ones_vec(TCGType type)
88
+void icount_handle_deadline(void)
89
{
57
{
90
assert(qemu_in_vcpu_thread());
58
TCGv_vec ret = tcg_temp_new_vec(type);
91
int64_t deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL,
59
- do_dupi_vec(ret, MO_REG, -1);
92
QEMU_TIMER_ATTR_ALL);
60
+ tcg_gen_dupi_vec(MO_64, ret, -1);
93
61
return ret;
94
if (deadline == 0) {
95
- notify_aio_contexts();
96
+ icount_notify_aio_contexts();
97
}
98
}
62
}
99
63
100
-void prepare_icount_for_run(CPUState *cpu)
64
@@ -XXX,XX +XXX,XX @@ TCGv_vec tcg_const_ones_vec_matching(TCGv_vec m)
101
+void icount_prepare_for_run(CPUState *cpu)
65
66
void tcg_gen_dup64i_vec(TCGv_vec r, uint64_t a)
102
{
67
{
103
int insns_left;
68
- if (TCG_TARGET_REG_BITS == 64) {
104
69
- do_dupi_vec(r, MO_64, a);
105
/*
70
- } else if (a == dup_const(MO_32, a)) {
106
- * These should always be cleared by process_icount_data after
71
- do_dupi_vec(r, MO_32, a);
107
+ * These should always be cleared by icount_process_data after
72
- } else {
108
* each vCPU execution. However u16.high can be raised
73
- TCGv_i64 c = tcg_const_i64(a);
109
- * asynchronously by cpu_exit/cpu_interrupt/tcg_handle_interrupt
74
- tcg_gen_dup_i64_vec(MO_64, r, c);
110
+ * asynchronously by cpu_exit/cpu_interrupt/tcg_cpus_handle_interrupt
75
- tcg_temp_free_i64(c);
111
*/
76
- }
112
g_assert(cpu_neg(cpu)->icount_decr.u16.low == 0);
77
+ tcg_gen_dupi_vec(MO_64, r, a);
113
g_assert(cpu->icount_extra == 0);
114
115
- cpu->icount_budget = tcg_get_icount_limit();
116
+ cpu->icount_budget = icount_get_limit();
117
insns_left = MIN(0xffff, cpu->icount_budget);
118
cpu_neg(cpu)->icount_decr.u16.low = insns_left;
119
cpu->icount_extra = cpu->icount_budget - insns_left;
120
@@ -XXX,XX +XXX,XX @@ void prepare_icount_for_run(CPUState *cpu)
121
replay_mutex_lock();
122
123
if (cpu->icount_budget == 0 && replay_has_checkpoint()) {
124
- notify_aio_contexts();
125
+ icount_notify_aio_contexts();
126
}
127
}
78
}
128
79
129
-void process_icount_data(CPUState *cpu)
80
void tcg_gen_dup32i_vec(TCGv_vec r, uint32_t a)
130
+void icount_process_data(CPUState *cpu)
131
{
81
{
132
/* Account for executed instructions */
82
- do_dupi_vec(r, MO_REG, dup_const(MO_32, a));
133
icount_update(cpu);
83
+ tcg_gen_dupi_vec(MO_32, r, a);
134
@@ -XXX,XX +XXX,XX @@ static void icount_handle_interrupt(CPUState *cpu, int mask)
84
}
85
86
void tcg_gen_dup16i_vec(TCGv_vec r, uint32_t a)
135
{
87
{
136
int old_mask = cpu->interrupt_request;
88
- do_dupi_vec(r, MO_REG, dup_const(MO_16, a));
137
89
+ tcg_gen_dupi_vec(MO_16, r, a);
138
- tcg_handle_interrupt(cpu, mask);
90
}
139
+ tcg_cpus_handle_interrupt(cpu, mask);
91
140
if (qemu_cpu_is_self(cpu) &&
92
void tcg_gen_dup8i_vec(TCGv_vec r, uint32_t a)
141
!cpu->can_do_io
93
{
142
&& (mask & ~old_mask) != 0) {
94
- do_dupi_vec(r, MO_REG, dup_const(MO_8, a));
143
@@ -XXX,XX +XXX,XX @@ static void icount_handle_interrupt(CPUState *cpu, int mask)
95
+ tcg_gen_dupi_vec(MO_8, r, a);
144
96
}
145
const CpusAccel tcg_cpus_icount = {
97
146
.create_vcpu_thread = rr_start_vcpu_thread,
98
void tcg_gen_dupi_vec(unsigned vece, TCGv_vec r, uint64_t a)
147
- .kick_vcpu_thread = qemu_cpu_kick_rr_cpus,
99
{
148
+ .kick_vcpu_thread = rr_kick_vcpu_thread,
100
- if (vece == MO_64) {
149
101
- tcg_gen_dup64i_vec(r, a);
150
.handle_interrupt = icount_handle_interrupt,
102
- } else {
151
.get_virtual_clock = icount_get,
103
- do_dupi_vec(r, MO_REG, dup_const(vece, a));
152
diff --git a/accel/tcg/tcg-cpus-mttcg.c b/accel/tcg/tcg-cpus-mttcg.c
104
- }
105
+ TCGTemp *rt = tcgv_vec_temp(r);
106
+ tcg_gen_mov_vec(r, tcg_constant_vec(rt->base_type, vece, a));
107
}
108
109
void tcg_gen_dup_i64_vec(unsigned vece, TCGv_vec r, TCGv_i64 a)
110
@@ -XXX,XX +XXX,XX @@ void tcg_gen_abs_vec(unsigned vece, TCGv_vec r, TCGv_vec a)
111
if (tcg_can_emit_vec_op(INDEX_op_sari_vec, type, vece) > 0) {
112
tcg_gen_sari_vec(vece, t, a, (8 << vece) - 1);
113
} else {
114
- do_dupi_vec(t, MO_REG, 0);
115
- tcg_gen_cmp_vec(TCG_COND_LT, vece, t, a, t);
116
+ tcg_gen_cmp_vec(TCG_COND_LT, vece, t, a,
117
+ tcg_constant_vec(type, vece, 0));
118
}
119
tcg_gen_xor_vec(vece, r, a, t);
120
tcg_gen_sub_vec(vece, r, r, t);
121
diff --git a/tcg/tcg.c b/tcg/tcg.c
153
index XXXXXXX..XXXXXXX 100644
122
index XXXXXXX..XXXXXXX 100644
154
--- a/accel/tcg/tcg-cpus-mttcg.c
123
--- a/tcg/tcg.c
155
+++ b/accel/tcg/tcg-cpus-mttcg.c
124
+++ b/tcg/tcg.c
156
@@ -XXX,XX +XXX,XX @@
125
@@ -XXX,XX +XXX,XX @@ static void temp_load(TCGContext *s, TCGTemp *ts, TCGRegSet desired_regs,
157
* current CPUState for a given thread.
126
* The targets will, in general, have to do this search anyway,
158
*/
127
* do this generically.
159
160
-static void *tcg_cpu_thread_fn(void *arg)
161
+static void *mttcg_cpu_thread_fn(void *arg)
162
{
163
CPUState *cpu = arg;
164
165
@@ -XXX,XX +XXX,XX @@ static void *tcg_cpu_thread_fn(void *arg)
166
if (cpu_can_run(cpu)) {
167
int r;
168
qemu_mutex_unlock_iothread();
169
- r = tcg_cpu_exec(cpu);
170
+ r = tcg_cpus_exec(cpu);
171
qemu_mutex_lock_iothread();
172
switch (r) {
173
case EXCP_DEBUG:
174
@@ -XXX,XX +XXX,XX @@ static void *tcg_cpu_thread_fn(void *arg)
175
qemu_wait_io_event(cpu);
176
} while (!cpu->unplug || cpu_can_run(cpu));
177
178
- qemu_tcg_destroy_vcpu(cpu);
179
+ tcg_cpus_destroy(cpu);
180
qemu_mutex_unlock_iothread();
181
rcu_unregister_thread();
182
return NULL;
183
@@ -XXX,XX +XXX,XX @@ static void mttcg_start_vcpu_thread(CPUState *cpu)
184
snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/TCG",
185
cpu->cpu_index);
186
187
- qemu_thread_create(cpu->thread, thread_name, tcg_cpu_thread_fn,
188
+ qemu_thread_create(cpu->thread, thread_name, mttcg_cpu_thread_fn,
189
cpu, QEMU_THREAD_JOINABLE);
190
191
#ifdef _WIN32
192
@@ -XXX,XX +XXX,XX @@ const CpusAccel tcg_cpus_mttcg = {
193
.create_vcpu_thread = mttcg_start_vcpu_thread,
194
.kick_vcpu_thread = mttcg_kick_vcpu_thread,
195
196
- .handle_interrupt = tcg_handle_interrupt,
197
+ .handle_interrupt = tcg_cpus_handle_interrupt,
198
};
199
diff --git a/accel/tcg/tcg-cpus-rr.c b/accel/tcg/tcg-cpus-rr.c
200
index XXXXXXX..XXXXXXX 100644
201
--- a/accel/tcg/tcg-cpus-rr.c
202
+++ b/accel/tcg/tcg-cpus-rr.c
203
@@ -XXX,XX +XXX,XX @@
204
#include "tcg-cpus-icount.h"
205
206
/* Kick all RR vCPUs */
207
-void qemu_cpu_kick_rr_cpus(CPUState *unused)
208
+void rr_kick_vcpu_thread(CPUState *unused)
209
{
210
CPUState *cpu;
211
212
@@ -XXX,XX +XXX,XX @@ void qemu_cpu_kick_rr_cpus(CPUState *unused)
213
* idleness is complete.
214
*/
215
216
-static QEMUTimer *tcg_kick_vcpu_timer;
217
-static CPUState *tcg_current_rr_cpu;
218
+static QEMUTimer *rr_kick_vcpu_timer;
219
+static CPUState *rr_current_cpu;
220
221
#define TCG_KICK_PERIOD (NANOSECONDS_PER_SECOND / 10)
222
223
-static inline int64_t qemu_tcg_next_kick(void)
224
+static inline int64_t rr_next_kick_time(void)
225
{
226
return qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + TCG_KICK_PERIOD;
227
}
228
229
/* Kick the currently round-robin scheduled vCPU to next */
230
-static void qemu_cpu_kick_rr_next_cpu(void)
231
+static void rr_kick_next_cpu(void)
232
{
233
CPUState *cpu;
234
do {
235
- cpu = qatomic_mb_read(&tcg_current_rr_cpu);
236
+ cpu = qatomic_mb_read(&rr_current_cpu);
237
if (cpu) {
238
cpu_exit(cpu);
239
}
240
- } while (cpu != qatomic_mb_read(&tcg_current_rr_cpu));
241
+ } while (cpu != qatomic_mb_read(&rr_current_cpu));
242
}
243
244
-static void kick_tcg_thread(void *opaque)
245
+static void rr_kick_thread(void *opaque)
246
{
247
- timer_mod(tcg_kick_vcpu_timer, qemu_tcg_next_kick());
248
- qemu_cpu_kick_rr_next_cpu();
249
+ timer_mod(rr_kick_vcpu_timer, rr_next_kick_time());
250
+ rr_kick_next_cpu();
251
}
252
253
-static void start_tcg_kick_timer(void)
254
+static void rr_start_kick_timer(void)
255
{
256
- if (!tcg_kick_vcpu_timer && CPU_NEXT(first_cpu)) {
257
- tcg_kick_vcpu_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
258
- kick_tcg_thread, NULL);
259
+ if (!rr_kick_vcpu_timer && CPU_NEXT(first_cpu)) {
260
+ rr_kick_vcpu_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
261
+ rr_kick_thread, NULL);
262
}
263
- if (tcg_kick_vcpu_timer && !timer_pending(tcg_kick_vcpu_timer)) {
264
- timer_mod(tcg_kick_vcpu_timer, qemu_tcg_next_kick());
265
+ if (rr_kick_vcpu_timer && !timer_pending(rr_kick_vcpu_timer)) {
266
+ timer_mod(rr_kick_vcpu_timer, rr_next_kick_time());
267
}
268
}
269
270
-static void stop_tcg_kick_timer(void)
271
+static void rr_stop_kick_timer(void)
272
{
273
- if (tcg_kick_vcpu_timer && timer_pending(tcg_kick_vcpu_timer)) {
274
- timer_del(tcg_kick_vcpu_timer);
275
+ if (rr_kick_vcpu_timer && timer_pending(rr_kick_vcpu_timer)) {
276
+ timer_del(rr_kick_vcpu_timer);
277
}
278
}
279
280
-static void qemu_tcg_rr_wait_io_event(void)
281
+static void rr_wait_io_event(void)
282
{
283
CPUState *cpu;
284
285
while (all_cpu_threads_idle()) {
286
- stop_tcg_kick_timer();
287
+ rr_stop_kick_timer();
288
qemu_cond_wait_iothread(first_cpu->halt_cond);
289
}
290
291
- start_tcg_kick_timer();
292
+ rr_start_kick_timer();
293
294
CPU_FOREACH(cpu) {
295
qemu_wait_io_event_common(cpu);
296
@@ -XXX,XX +XXX,XX @@ static void qemu_tcg_rr_wait_io_event(void)
297
* Destroy any remaining vCPUs which have been unplugged and have
298
* finished running
299
*/
300
-static void deal_with_unplugged_cpus(void)
301
+static void rr_deal_with_unplugged_cpus(void)
302
{
303
CPUState *cpu;
304
305
CPU_FOREACH(cpu) {
306
if (cpu->unplug && !cpu_can_run(cpu)) {
307
- qemu_tcg_destroy_vcpu(cpu);
308
+ tcg_cpus_destroy(cpu);
309
break;
310
}
311
}
312
@@ -XXX,XX +XXX,XX @@ static void deal_with_unplugged_cpus(void)
313
* elsewhere.
314
*/
315
316
-static void *tcg_rr_cpu_thread_fn(void *arg)
317
+static void *rr_cpu_thread_fn(void *arg)
318
{
319
CPUState *cpu = arg;
320
321
@@ -XXX,XX +XXX,XX @@ static void *tcg_rr_cpu_thread_fn(void *arg)
322
}
323
}
324
325
- start_tcg_kick_timer();
326
+ rr_start_kick_timer();
327
328
cpu = first_cpu;
329
330
@@ -XXX,XX +XXX,XX @@ static void *tcg_rr_cpu_thread_fn(void *arg)
331
* Run the timers here. This is much more efficient than
332
* waking up the I/O thread and waiting for completion.
333
*/
128
*/
334
- handle_icount_deadline();
129
- if (TCG_TARGET_REG_BITS == 32) {
335
+ icount_handle_deadline();
130
- val = dup_const(MO_32, val);
336
}
131
- vece = MO_32;
337
132
- }
338
replay_mutex_unlock();
133
if (val == dup_const(MO_8, val)) {
339
@@ -XXX,XX +XXX,XX @@ static void *tcg_rr_cpu_thread_fn(void *arg)
134
vece = MO_8;
340
135
} else if (val == dup_const(MO_16, val)) {
341
while (cpu && cpu_work_list_empty(cpu) && !cpu->exit_request) {
136
vece = MO_16;
342
137
- } else if (TCG_TARGET_REG_BITS == 64 &&
343
- qatomic_mb_set(&tcg_current_rr_cpu, cpu);
138
- val == dup_const(MO_32, val)) {
344
+ qatomic_mb_set(&rr_current_cpu, cpu);
139
+ } else if (val == dup_const(MO_32, val)) {
345
current_cpu = cpu;
140
vece = MO_32;
346
141
}
347
qemu_clock_enable(QEMU_CLOCK_VIRTUAL,
348
@@ -XXX,XX +XXX,XX @@ static void *tcg_rr_cpu_thread_fn(void *arg)
349
350
qemu_mutex_unlock_iothread();
351
if (icount_enabled()) {
352
- prepare_icount_for_run(cpu);
353
+ icount_prepare_for_run(cpu);
354
}
355
- r = tcg_cpu_exec(cpu);
356
+ r = tcg_cpus_exec(cpu);
357
if (icount_enabled()) {
358
- process_icount_data(cpu);
359
+ icount_process_data(cpu);
360
}
361
qemu_mutex_lock_iothread();
362
363
@@ -XXX,XX +XXX,XX @@ static void *tcg_rr_cpu_thread_fn(void *arg)
364
} /* while (cpu && !cpu->exit_request).. */
365
366
/* Does not need qatomic_mb_set because a spurious wakeup is okay. */
367
- qatomic_set(&tcg_current_rr_cpu, NULL);
368
+ qatomic_set(&rr_current_cpu, NULL);
369
370
if (cpu && cpu->exit_request) {
371
qatomic_mb_set(&cpu->exit_request, 0);
372
@@ -XXX,XX +XXX,XX @@ static void *tcg_rr_cpu_thread_fn(void *arg)
373
qemu_notify_event();
374
}
375
376
- qemu_tcg_rr_wait_io_event();
377
- deal_with_unplugged_cpus();
378
+ rr_wait_io_event();
379
+ rr_deal_with_unplugged_cpus();
380
}
381
382
rcu_unregister_thread();
383
@@ -XXX,XX +XXX,XX @@ void rr_start_vcpu_thread(CPUState *cpu)
384
/* share a single thread for all cpus with TCG */
385
snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "ALL CPUs/TCG");
386
qemu_thread_create(cpu->thread, thread_name,
387
- tcg_rr_cpu_thread_fn,
388
+ rr_cpu_thread_fn,
389
cpu, QEMU_THREAD_JOINABLE);
390
391
single_tcg_halt_cond = cpu->halt_cond;
392
@@ -XXX,XX +XXX,XX @@ void rr_start_vcpu_thread(CPUState *cpu)
393
394
const CpusAccel tcg_cpus_rr = {
395
.create_vcpu_thread = rr_start_vcpu_thread,
396
- .kick_vcpu_thread = qemu_cpu_kick_rr_cpus,
397
+ .kick_vcpu_thread = rr_kick_vcpu_thread,
398
399
- .handle_interrupt = tcg_handle_interrupt,
400
+ .handle_interrupt = tcg_cpus_handle_interrupt,
401
};
402
diff --git a/accel/tcg/tcg-cpus.c b/accel/tcg/tcg-cpus.c
403
index XXXXXXX..XXXXXXX 100644
404
--- a/accel/tcg/tcg-cpus.c
405
+++ b/accel/tcg/tcg-cpus.c
406
@@ -XXX,XX +XXX,XX @@
407
408
/* common functionality among all TCG variants */
409
410
-void qemu_tcg_destroy_vcpu(CPUState *cpu)
411
+void tcg_cpus_destroy(CPUState *cpu)
412
{
413
cpu_thread_signal_destroyed(cpu);
414
}
415
416
-int tcg_cpu_exec(CPUState *cpu)
417
+int tcg_cpus_exec(CPUState *cpu)
418
{
419
int ret;
420
#ifdef CONFIG_PROFILER
421
@@ -XXX,XX +XXX,XX @@ int tcg_cpu_exec(CPUState *cpu)
422
}
423
424
/* mask must never be zero, except for A20 change call */
425
-void tcg_handle_interrupt(CPUState *cpu, int mask)
426
+void tcg_cpus_handle_interrupt(CPUState *cpu, int mask)
427
{
428
g_assert(qemu_mutex_iothread_locked());
429
142
430
--
143
--
431
2.25.1
144
2.25.1
432
145
433
146
diff view generated by jsdifflib
New patch
1
We must do this before we adjust tcg_out_movi_i32, lest the
2
under-the-hood poking that we do for icount be broken.
1
3
4
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
5
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
6
---
7
include/exec/gen-icount.h | 25 +++++++++++++------------
8
1 file changed, 13 insertions(+), 12 deletions(-)
9
10
diff --git a/include/exec/gen-icount.h b/include/exec/gen-icount.h
11
index XXXXXXX..XXXXXXX 100644
12
--- a/include/exec/gen-icount.h
13
+++ b/include/exec/gen-icount.h
14
@@ -XXX,XX +XXX,XX @@ static inline void gen_io_end(void)
15
16
static inline void gen_tb_start(const TranslationBlock *tb)
17
{
18
- TCGv_i32 count, imm;
19
+ TCGv_i32 count;
20
21
tcg_ctx->exitreq_label = gen_new_label();
22
if (tb_cflags(tb) & CF_USE_ICOUNT) {
23
@@ -XXX,XX +XXX,XX @@ static inline void gen_tb_start(const TranslationBlock *tb)
24
offsetof(ArchCPU, env));
25
26
if (tb_cflags(tb) & CF_USE_ICOUNT) {
27
- imm = tcg_temp_new_i32();
28
- /* We emit a movi with a dummy immediate argument. Keep the insn index
29
- * of the movi so that we later (when we know the actual insn count)
30
- * can update the immediate argument with the actual insn count. */
31
- tcg_gen_movi_i32(imm, 0xdeadbeef);
32
+ /*
33
+ * We emit a sub with a dummy immediate argument. Keep the insn index
34
+ * of the sub so that we later (when we know the actual insn count)
35
+ * can update the argument with the actual insn count.
36
+ */
37
+ tcg_gen_sub_i32(count, count, tcg_constant_i32(0));
38
icount_start_insn = tcg_last_op();
39
-
40
- tcg_gen_sub_i32(count, count, imm);
41
- tcg_temp_free_i32(imm);
42
}
43
44
tcg_gen_brcondi_i32(TCG_COND_LT, count, 0, tcg_ctx->exitreq_label);
45
@@ -XXX,XX +XXX,XX @@ static inline void gen_tb_start(const TranslationBlock *tb)
46
static inline void gen_tb_end(const TranslationBlock *tb, int num_insns)
47
{
48
if (tb_cflags(tb) & CF_USE_ICOUNT) {
49
- /* Update the num_insn immediate parameter now that we know
50
- * the actual insn count. */
51
- tcg_set_insn_param(icount_start_insn, 1, num_insns);
52
+ /*
53
+ * Update the num_insn immediate parameter now that we know
54
+ * the actual insn count.
55
+ */
56
+ tcg_set_insn_param(icount_start_insn, 2,
57
+ tcgv_i32_arg(tcg_constant_i32(num_insns)));
58
}
59
60
gen_set_label(tcg_ctx->exitreq_label);
61
--
62
2.25.1
63
64
diff view generated by jsdifflib
New patch
1
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
2
---
3
include/tcg/tcg-op.h | 13 +--
4
tcg/tcg-op.c | 227 ++++++++++++++++++++-----------------------
5
2 files changed, 109 insertions(+), 131 deletions(-)
1
6
7
diff --git a/include/tcg/tcg-op.h b/include/tcg/tcg-op.h
8
index XXXXXXX..XXXXXXX 100644
9
--- a/include/tcg/tcg-op.h
10
+++ b/include/tcg/tcg-op.h
11
@@ -XXX,XX +XXX,XX @@ void tcg_gen_mb(TCGBar);
12
13
/* 32 bit ops */
14
15
+void tcg_gen_movi_i32(TCGv_i32 ret, int32_t arg);
16
void tcg_gen_addi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
17
void tcg_gen_subfi_i32(TCGv_i32 ret, int32_t arg1, TCGv_i32 arg2);
18
void tcg_gen_subi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2);
19
@@ -XXX,XX +XXX,XX @@ static inline void tcg_gen_mov_i32(TCGv_i32 ret, TCGv_i32 arg)
20
}
21
}
22
23
-static inline void tcg_gen_movi_i32(TCGv_i32 ret, int32_t arg)
24
-{
25
- tcg_gen_op2i_i32(INDEX_op_movi_i32, ret, arg);
26
-}
27
-
28
static inline void tcg_gen_ld8u_i32(TCGv_i32 ret, TCGv_ptr arg2,
29
tcg_target_long offset)
30
{
31
@@ -XXX,XX +XXX,XX @@ static inline void tcg_gen_not_i32(TCGv_i32 ret, TCGv_i32 arg)
32
33
/* 64 bit ops */
34
35
+void tcg_gen_movi_i64(TCGv_i64 ret, int64_t arg);
36
void tcg_gen_addi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
37
void tcg_gen_subfi_i64(TCGv_i64 ret, int64_t arg1, TCGv_i64 arg2);
38
void tcg_gen_subi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2);
39
@@ -XXX,XX +XXX,XX @@ static inline void tcg_gen_mov_i64(TCGv_i64 ret, TCGv_i64 arg)
40
}
41
}
42
43
-static inline void tcg_gen_movi_i64(TCGv_i64 ret, int64_t arg)
44
-{
45
- tcg_gen_op2i_i64(INDEX_op_movi_i64, ret, arg);
46
-}
47
-
48
static inline void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_ptr arg2,
49
tcg_target_long offset)
50
{
51
@@ -XXX,XX +XXX,XX @@ static inline void tcg_gen_sub_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
52
53
void tcg_gen_discard_i64(TCGv_i64 arg);
54
void tcg_gen_mov_i64(TCGv_i64 ret, TCGv_i64 arg);
55
-void tcg_gen_movi_i64(TCGv_i64 ret, int64_t arg);
56
void tcg_gen_ld8u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
57
void tcg_gen_ld8s_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
58
void tcg_gen_ld16u_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset);
59
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
60
index XXXXXXX..XXXXXXX 100644
61
--- a/tcg/tcg-op.c
62
+++ b/tcg/tcg-op.c
63
@@ -XXX,XX +XXX,XX @@ void tcg_gen_mb(TCGBar mb_type)
64
65
/* 32 bit ops */
66
67
+void tcg_gen_movi_i32(TCGv_i32 ret, int32_t arg)
68
+{
69
+ tcg_gen_mov_i32(ret, tcg_constant_i32(arg));
70
+}
71
+
72
void tcg_gen_addi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
73
{
74
/* some cases can be optimized here */
75
if (arg2 == 0) {
76
tcg_gen_mov_i32(ret, arg1);
77
} else {
78
- TCGv_i32 t0 = tcg_const_i32(arg2);
79
- tcg_gen_add_i32(ret, arg1, t0);
80
- tcg_temp_free_i32(t0);
81
+ tcg_gen_add_i32(ret, arg1, tcg_constant_i32(arg2));
82
}
83
}
84
85
@@ -XXX,XX +XXX,XX @@ void tcg_gen_subfi_i32(TCGv_i32 ret, int32_t arg1, TCGv_i32 arg2)
86
/* Don't recurse with tcg_gen_neg_i32. */
87
tcg_gen_op2_i32(INDEX_op_neg_i32, ret, arg2);
88
} else {
89
- TCGv_i32 t0 = tcg_const_i32(arg1);
90
- tcg_gen_sub_i32(ret, t0, arg2);
91
- tcg_temp_free_i32(t0);
92
+ tcg_gen_sub_i32(ret, tcg_constant_i32(arg1), arg2);
93
}
94
}
95
96
@@ -XXX,XX +XXX,XX @@ void tcg_gen_subi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
97
if (arg2 == 0) {
98
tcg_gen_mov_i32(ret, arg1);
99
} else {
100
- TCGv_i32 t0 = tcg_const_i32(arg2);
101
- tcg_gen_sub_i32(ret, arg1, t0);
102
- tcg_temp_free_i32(t0);
103
+ tcg_gen_sub_i32(ret, arg1, tcg_constant_i32(arg2));
104
}
105
}
106
107
void tcg_gen_andi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
108
{
109
- TCGv_i32 t0;
110
/* Some cases can be optimized here. */
111
switch (arg2) {
112
case 0:
113
@@ -XXX,XX +XXX,XX @@ void tcg_gen_andi_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
114
}
115
break;
116
}
117
- t0 = tcg_const_i32(arg2);
118
- tcg_gen_and_i32(ret, arg1, t0);
119
- tcg_temp_free_i32(t0);
120
+
121
+ tcg_gen_and_i32(ret, arg1, tcg_constant_i32(arg2));
122
}
123
124
void tcg_gen_ori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
125
@@ -XXX,XX +XXX,XX @@ void tcg_gen_ori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
126
} else if (arg2 == 0) {
127
tcg_gen_mov_i32(ret, arg1);
128
} else {
129
- TCGv_i32 t0 = tcg_const_i32(arg2);
130
- tcg_gen_or_i32(ret, arg1, t0);
131
- tcg_temp_free_i32(t0);
132
+ tcg_gen_or_i32(ret, arg1, tcg_constant_i32(arg2));
133
}
134
}
135
136
@@ -XXX,XX +XXX,XX @@ void tcg_gen_xori_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
137
/* Don't recurse with tcg_gen_not_i32. */
138
tcg_gen_op2_i32(INDEX_op_not_i32, ret, arg1);
139
} else {
140
- TCGv_i32 t0 = tcg_const_i32(arg2);
141
- tcg_gen_xor_i32(ret, arg1, t0);
142
- tcg_temp_free_i32(t0);
143
+ tcg_gen_xor_i32(ret, arg1, tcg_constant_i32(arg2));
144
}
145
}
146
147
@@ -XXX,XX +XXX,XX @@ void tcg_gen_shli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
148
if (arg2 == 0) {
149
tcg_gen_mov_i32(ret, arg1);
150
} else {
151
- TCGv_i32 t0 = tcg_const_i32(arg2);
152
- tcg_gen_shl_i32(ret, arg1, t0);
153
- tcg_temp_free_i32(t0);
154
+ tcg_gen_shl_i32(ret, arg1, tcg_constant_i32(arg2));
155
}
156
}
157
158
@@ -XXX,XX +XXX,XX @@ void tcg_gen_shri_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
159
if (arg2 == 0) {
160
tcg_gen_mov_i32(ret, arg1);
161
} else {
162
- TCGv_i32 t0 = tcg_const_i32(arg2);
163
- tcg_gen_shr_i32(ret, arg1, t0);
164
- tcg_temp_free_i32(t0);
165
+ tcg_gen_shr_i32(ret, arg1, tcg_constant_i32(arg2));
166
}
167
}
168
169
@@ -XXX,XX +XXX,XX @@ void tcg_gen_sari_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
170
if (arg2 == 0) {
171
tcg_gen_mov_i32(ret, arg1);
172
} else {
173
- TCGv_i32 t0 = tcg_const_i32(arg2);
174
- tcg_gen_sar_i32(ret, arg1, t0);
175
- tcg_temp_free_i32(t0);
176
+ tcg_gen_sar_i32(ret, arg1, tcg_constant_i32(arg2));
177
}
178
}
179
180
@@ -XXX,XX +XXX,XX @@ void tcg_gen_brcondi_i32(TCGCond cond, TCGv_i32 arg1, int32_t arg2, TCGLabel *l)
181
if (cond == TCG_COND_ALWAYS) {
182
tcg_gen_br(l);
183
} else if (cond != TCG_COND_NEVER) {
184
- TCGv_i32 t0 = tcg_const_i32(arg2);
185
- tcg_gen_brcond_i32(cond, arg1, t0, l);
186
- tcg_temp_free_i32(t0);
187
+ tcg_gen_brcond_i32(cond, arg1, tcg_constant_i32(arg2), l);
188
}
189
}
190
191
@@ -XXX,XX +XXX,XX @@ void tcg_gen_setcond_i32(TCGCond cond, TCGv_i32 ret,
192
void tcg_gen_setcondi_i32(TCGCond cond, TCGv_i32 ret,
193
TCGv_i32 arg1, int32_t arg2)
194
{
195
- TCGv_i32 t0 = tcg_const_i32(arg2);
196
- tcg_gen_setcond_i32(cond, ret, arg1, t0);
197
- tcg_temp_free_i32(t0);
198
+ tcg_gen_setcond_i32(cond, ret, arg1, tcg_constant_i32(arg2));
199
}
200
201
void tcg_gen_muli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
202
@@ -XXX,XX +XXX,XX @@ void tcg_gen_muli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
203
} else if (is_power_of_2(arg2)) {
204
tcg_gen_shli_i32(ret, arg1, ctz32(arg2));
205
} else {
206
- TCGv_i32 t0 = tcg_const_i32(arg2);
207
- tcg_gen_mul_i32(ret, arg1, t0);
208
- tcg_temp_free_i32(t0);
209
+ tcg_gen_mul_i32(ret, arg1, tcg_constant_i32(arg2));
210
}
211
}
212
213
@@ -XXX,XX +XXX,XX @@ void tcg_gen_clz_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
214
215
void tcg_gen_clzi_i32(TCGv_i32 ret, TCGv_i32 arg1, uint32_t arg2)
216
{
217
- TCGv_i32 t = tcg_const_i32(arg2);
218
- tcg_gen_clz_i32(ret, arg1, t);
219
- tcg_temp_free_i32(t);
220
+ tcg_gen_clz_i32(ret, arg1, tcg_constant_i32(arg2));
221
}
222
223
void tcg_gen_ctz_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
224
@@ -XXX,XX +XXX,XX @@ void tcg_gen_ctz_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
225
tcg_gen_clzi_i32(t, t, 32);
226
tcg_gen_xori_i32(t, t, 31);
227
}
228
- z = tcg_const_i32(0);
229
+ z = tcg_constant_i32(0);
230
tcg_gen_movcond_i32(TCG_COND_EQ, ret, arg1, z, arg2, t);
231
tcg_temp_free_i32(t);
232
- tcg_temp_free_i32(z);
233
} else {
234
gen_helper_ctz_i32(ret, arg1, arg2);
235
}
236
@@ -XXX,XX +XXX,XX @@ void tcg_gen_ctzi_i32(TCGv_i32 ret, TCGv_i32 arg1, uint32_t arg2)
237
tcg_gen_ctpop_i32(ret, t);
238
tcg_temp_free_i32(t);
239
} else {
240
- TCGv_i32 t = tcg_const_i32(arg2);
241
- tcg_gen_ctz_i32(ret, arg1, t);
242
- tcg_temp_free_i32(t);
243
+ tcg_gen_ctz_i32(ret, arg1, tcg_constant_i32(arg2));
244
}
245
}
246
247
@@ -XXX,XX +XXX,XX @@ void tcg_gen_rotli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
248
if (arg2 == 0) {
249
tcg_gen_mov_i32(ret, arg1);
250
} else if (TCG_TARGET_HAS_rot_i32) {
251
- TCGv_i32 t0 = tcg_const_i32(arg2);
252
- tcg_gen_rotl_i32(ret, arg1, t0);
253
- tcg_temp_free_i32(t0);
254
+ tcg_gen_rotl_i32(ret, arg1, tcg_constant_i32(arg2));
255
} else {
256
TCGv_i32 t0, t1;
257
t0 = tcg_temp_new_i32();
258
@@ -XXX,XX +XXX,XX @@ void tcg_gen_deposit_z_i32(TCGv_i32 ret, TCGv_i32 arg,
259
tcg_gen_andi_i32(ret, arg, (1u << len) - 1);
260
} else if (TCG_TARGET_HAS_deposit_i32
261
&& TCG_TARGET_deposit_i32_valid(ofs, len)) {
262
- TCGv_i32 zero = tcg_const_i32(0);
263
+ TCGv_i32 zero = tcg_constant_i32(0);
264
tcg_gen_op5ii_i32(INDEX_op_deposit_i32, ret, zero, arg, ofs, len);
265
- tcg_temp_free_i32(zero);
266
} else {
267
/* To help two-operand hosts we prefer to zero-extend first,
268
which allows ARG to stay live. */
269
@@ -XXX,XX +XXX,XX @@ void tcg_gen_bswap32_i32(TCGv_i32 ret, TCGv_i32 arg)
270
} else {
271
TCGv_i32 t0 = tcg_temp_new_i32();
272
TCGv_i32 t1 = tcg_temp_new_i32();
273
- TCGv_i32 t2 = tcg_const_i32(0x00ff00ff);
274
+ TCGv_i32 t2 = tcg_constant_i32(0x00ff00ff);
275
276
/* arg = abcd */
277
tcg_gen_shri_i32(t0, arg, 8); /* t0 = .abc */
278
@@ -XXX,XX +XXX,XX @@ void tcg_gen_bswap32_i32(TCGv_i32 ret, TCGv_i32 arg)
279
280
tcg_temp_free_i32(t0);
281
tcg_temp_free_i32(t1);
282
- tcg_temp_free_i32(t2);
283
}
284
}
285
286
@@ -XXX,XX +XXX,XX @@ void tcg_gen_discard_i64(TCGv_i64 arg)
287
288
void tcg_gen_mov_i64(TCGv_i64 ret, TCGv_i64 arg)
289
{
290
- tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
291
- tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
292
+ TCGTemp *ts = tcgv_i64_temp(arg);
293
+
294
+ /* Canonicalize TCGv_i64 TEMP_CONST into TCGv_i32 TEMP_CONST. */
295
+ if (ts->kind == TEMP_CONST) {
296
+ tcg_gen_movi_i64(ret, ts->val);
297
+ } else {
298
+ tcg_gen_mov_i32(TCGV_LOW(ret), TCGV_LOW(arg));
299
+ tcg_gen_mov_i32(TCGV_HIGH(ret), TCGV_HIGH(arg));
300
+ }
301
}
302
303
void tcg_gen_movi_i64(TCGv_i64 ret, int64_t arg)
304
@@ -XXX,XX +XXX,XX @@ void tcg_gen_mul_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
305
tcg_temp_free_i64(t0);
306
tcg_temp_free_i32(t1);
307
}
308
+
309
+#else
310
+
311
+void tcg_gen_movi_i64(TCGv_i64 ret, int64_t arg)
312
+{
313
+ tcg_gen_mov_i64(ret, tcg_constant_i64(arg));
314
+}
315
+
316
#endif /* TCG_TARGET_REG_SIZE == 32 */
317
318
void tcg_gen_addi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
319
@@ -XXX,XX +XXX,XX @@ void tcg_gen_addi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
320
/* some cases can be optimized here */
321
if (arg2 == 0) {
322
tcg_gen_mov_i64(ret, arg1);
323
+ } else if (TCG_TARGET_REG_BITS == 64) {
324
+ tcg_gen_add_i64(ret, arg1, tcg_constant_i64(arg2));
325
} else {
326
- TCGv_i64 t0 = tcg_const_i64(arg2);
327
- tcg_gen_add_i64(ret, arg1, t0);
328
- tcg_temp_free_i64(t0);
329
+ tcg_gen_add2_i32(TCGV_LOW(ret), TCGV_HIGH(ret),
330
+ TCGV_LOW(arg1), TCGV_HIGH(arg1),
331
+ tcg_constant_i32(arg2), tcg_constant_i32(arg2 >> 32));
332
}
333
}
334
335
@@ -XXX,XX +XXX,XX @@ void tcg_gen_subfi_i64(TCGv_i64 ret, int64_t arg1, TCGv_i64 arg2)
336
if (arg1 == 0 && TCG_TARGET_HAS_neg_i64) {
337
/* Don't recurse with tcg_gen_neg_i64. */
338
tcg_gen_op2_i64(INDEX_op_neg_i64, ret, arg2);
339
+ } else if (TCG_TARGET_REG_BITS == 64) {
340
+ tcg_gen_sub_i64(ret, tcg_constant_i64(arg1), arg2);
341
} else {
342
- TCGv_i64 t0 = tcg_const_i64(arg1);
343
- tcg_gen_sub_i64(ret, t0, arg2);
344
- tcg_temp_free_i64(t0);
345
+ tcg_gen_sub2_i32(TCGV_LOW(ret), TCGV_HIGH(ret),
346
+ tcg_constant_i32(arg1), tcg_constant_i32(arg1 >> 32),
347
+ TCGV_LOW(arg2), TCGV_HIGH(arg2));
348
}
349
}
350
351
@@ -XXX,XX +XXX,XX @@ void tcg_gen_subi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
352
/* some cases can be optimized here */
353
if (arg2 == 0) {
354
tcg_gen_mov_i64(ret, arg1);
355
+ } else if (TCG_TARGET_REG_BITS == 64) {
356
+ tcg_gen_sub_i64(ret, arg1, tcg_constant_i64(arg2));
357
} else {
358
- TCGv_i64 t0 = tcg_const_i64(arg2);
359
- tcg_gen_sub_i64(ret, arg1, t0);
360
- tcg_temp_free_i64(t0);
361
+ tcg_gen_sub2_i32(TCGV_LOW(ret), TCGV_HIGH(ret),
362
+ TCGV_LOW(arg1), TCGV_HIGH(arg1),
363
+ tcg_constant_i32(arg2), tcg_constant_i32(arg2 >> 32));
364
}
365
}
366
367
void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
368
{
369
- TCGv_i64 t0;
370
-
371
if (TCG_TARGET_REG_BITS == 32) {
372
tcg_gen_andi_i32(TCGV_LOW(ret), TCGV_LOW(arg1), arg2);
373
tcg_gen_andi_i32(TCGV_HIGH(ret), TCGV_HIGH(arg1), arg2 >> 32);
374
@@ -XXX,XX +XXX,XX @@ void tcg_gen_andi_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
375
}
376
break;
377
}
378
- t0 = tcg_const_i64(arg2);
379
- tcg_gen_and_i64(ret, arg1, t0);
380
- tcg_temp_free_i64(t0);
381
+
382
+ tcg_gen_and_i64(ret, arg1, tcg_constant_i64(arg2));
383
}
384
385
void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
386
@@ -XXX,XX +XXX,XX @@ void tcg_gen_ori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
387
} else if (arg2 == 0) {
388
tcg_gen_mov_i64(ret, arg1);
389
} else {
390
- TCGv_i64 t0 = tcg_const_i64(arg2);
391
- tcg_gen_or_i64(ret, arg1, t0);
392
- tcg_temp_free_i64(t0);
393
+ tcg_gen_or_i64(ret, arg1, tcg_constant_i64(arg2));
394
}
395
}
396
397
@@ -XXX,XX +XXX,XX @@ void tcg_gen_xori_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
398
/* Don't recurse with tcg_gen_not_i64. */
399
tcg_gen_op2_i64(INDEX_op_not_i64, ret, arg1);
400
} else {
401
- TCGv_i64 t0 = tcg_const_i64(arg2);
402
- tcg_gen_xor_i64(ret, arg1, t0);
403
- tcg_temp_free_i64(t0);
404
+ tcg_gen_xor_i64(ret, arg1, tcg_constant_i64(arg2));
405
}
406
}
407
408
@@ -XXX,XX +XXX,XX @@ void tcg_gen_shli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
409
} else if (arg2 == 0) {
410
tcg_gen_mov_i64(ret, arg1);
411
} else {
412
- TCGv_i64 t0 = tcg_const_i64(arg2);
413
- tcg_gen_shl_i64(ret, arg1, t0);
414
- tcg_temp_free_i64(t0);
415
+ tcg_gen_shl_i64(ret, arg1, tcg_constant_i64(arg2));
416
}
417
}
418
419
@@ -XXX,XX +XXX,XX @@ void tcg_gen_shri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
420
} else if (arg2 == 0) {
421
tcg_gen_mov_i64(ret, arg1);
422
} else {
423
- TCGv_i64 t0 = tcg_const_i64(arg2);
424
- tcg_gen_shr_i64(ret, arg1, t0);
425
- tcg_temp_free_i64(t0);
426
+ tcg_gen_shr_i64(ret, arg1, tcg_constant_i64(arg2));
427
}
428
}
429
430
@@ -XXX,XX +XXX,XX @@ void tcg_gen_sari_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
431
} else if (arg2 == 0) {
432
tcg_gen_mov_i64(ret, arg1);
433
} else {
434
- TCGv_i64 t0 = tcg_const_i64(arg2);
435
- tcg_gen_sar_i64(ret, arg1, t0);
436
- tcg_temp_free_i64(t0);
437
+ tcg_gen_sar_i64(ret, arg1, tcg_constant_i64(arg2));
438
}
439
}
440
441
@@ -XXX,XX +XXX,XX @@ void tcg_gen_brcond_i64(TCGCond cond, TCGv_i64 arg1, TCGv_i64 arg2, TCGLabel *l)
442
443
void tcg_gen_brcondi_i64(TCGCond cond, TCGv_i64 arg1, int64_t arg2, TCGLabel *l)
444
{
445
- if (cond == TCG_COND_ALWAYS) {
446
+ if (TCG_TARGET_REG_BITS == 64) {
447
+ tcg_gen_brcond_i64(cond, arg1, tcg_constant_i64(arg2), l);
448
+ } else if (cond == TCG_COND_ALWAYS) {
449
tcg_gen_br(l);
450
} else if (cond != TCG_COND_NEVER) {
451
- TCGv_i64 t0 = tcg_const_i64(arg2);
452
- tcg_gen_brcond_i64(cond, arg1, t0, l);
453
- tcg_temp_free_i64(t0);
454
+ l->refs++;
455
+ tcg_gen_op6ii_i32(INDEX_op_brcond2_i32,
456
+ TCGV_LOW(arg1), TCGV_HIGH(arg1),
457
+ tcg_constant_i32(arg2),
458
+ tcg_constant_i32(arg2 >> 32),
459
+ cond, label_arg(l));
460
}
461
}
462
463
@@ -XXX,XX +XXX,XX @@ void tcg_gen_setcond_i64(TCGCond cond, TCGv_i64 ret,
464
void tcg_gen_setcondi_i64(TCGCond cond, TCGv_i64 ret,
465
TCGv_i64 arg1, int64_t arg2)
466
{
467
- TCGv_i64 t0 = tcg_const_i64(arg2);
468
- tcg_gen_setcond_i64(cond, ret, arg1, t0);
469
- tcg_temp_free_i64(t0);
470
+ if (TCG_TARGET_REG_BITS == 64) {
471
+ tcg_gen_setcond_i64(cond, ret, arg1, tcg_constant_i64(arg2));
472
+ } else if (cond == TCG_COND_ALWAYS) {
473
+ tcg_gen_movi_i64(ret, 1);
474
+ } else if (cond == TCG_COND_NEVER) {
475
+ tcg_gen_movi_i64(ret, 0);
476
+ } else {
477
+ tcg_gen_op6i_i32(INDEX_op_setcond2_i32, TCGV_LOW(ret),
478
+ TCGV_LOW(arg1), TCGV_HIGH(arg1),
479
+ tcg_constant_i32(arg2),
480
+ tcg_constant_i32(arg2 >> 32), cond);
481
+ tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
482
+ }
483
}
484
485
void tcg_gen_muli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
486
@@ -XXX,XX +XXX,XX @@ void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg)
487
} else {
488
TCGv_i64 t0 = tcg_temp_new_i64();
489
TCGv_i64 t1 = tcg_temp_new_i64();
490
- TCGv_i64 t2 = tcg_const_i64(0x00ff00ff);
491
+ TCGv_i64 t2 = tcg_constant_i64(0x00ff00ff);
492
493
/* arg = ....abcd */
494
tcg_gen_shri_i64(t0, arg, 8); /* t0 = .....abc */
495
@@ -XXX,XX +XXX,XX @@ void tcg_gen_bswap32_i64(TCGv_i64 ret, TCGv_i64 arg)
496
497
tcg_temp_free_i64(t0);
498
tcg_temp_free_i64(t1);
499
- tcg_temp_free_i64(t2);
500
}
501
}
502
503
@@ -XXX,XX +XXX,XX @@ void tcg_gen_clzi_i64(TCGv_i64 ret, TCGv_i64 arg1, uint64_t arg2)
504
if (TCG_TARGET_REG_BITS == 32
505
&& TCG_TARGET_HAS_clz_i32
506
&& arg2 <= 0xffffffffu) {
507
- TCGv_i32 t = tcg_const_i32((uint32_t)arg2 - 32);
508
- tcg_gen_clz_i32(t, TCGV_LOW(arg1), t);
509
+ TCGv_i32 t = tcg_temp_new_i32();
510
+ tcg_gen_clzi_i32(t, TCGV_LOW(arg1), arg2 - 32);
511
tcg_gen_addi_i32(t, t, 32);
512
tcg_gen_clz_i32(TCGV_LOW(ret), TCGV_HIGH(arg1), t);
513
tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
514
tcg_temp_free_i32(t);
515
} else {
516
- TCGv_i64 t = tcg_const_i64(arg2);
517
- tcg_gen_clz_i64(ret, arg1, t);
518
- tcg_temp_free_i64(t);
519
+ TCGv_i64 t0 = tcg_const_i64(arg2);
520
+ tcg_gen_clz_i64(ret, arg1, t0);
521
+ tcg_temp_free_i64(t0);
522
}
523
}
524
525
@@ -XXX,XX +XXX,XX @@ void tcg_gen_ctz_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
526
tcg_gen_clzi_i64(t, t, 64);
527
tcg_gen_xori_i64(t, t, 63);
528
}
529
- z = tcg_const_i64(0);
530
+ z = tcg_constant_i64(0);
531
tcg_gen_movcond_i64(TCG_COND_EQ, ret, arg1, z, arg2, t);
532
tcg_temp_free_i64(t);
533
tcg_temp_free_i64(z);
534
@@ -XXX,XX +XXX,XX @@ void tcg_gen_ctzi_i64(TCGv_i64 ret, TCGv_i64 arg1, uint64_t arg2)
535
if (TCG_TARGET_REG_BITS == 32
536
&& TCG_TARGET_HAS_ctz_i32
537
&& arg2 <= 0xffffffffu) {
538
- TCGv_i32 t32 = tcg_const_i32((uint32_t)arg2 - 32);
539
- tcg_gen_ctz_i32(t32, TCGV_HIGH(arg1), t32);
540
+ TCGv_i32 t32 = tcg_temp_new_i32();
541
+ tcg_gen_ctzi_i32(t32, TCGV_HIGH(arg1), arg2 - 32);
542
tcg_gen_addi_i32(t32, t32, 32);
543
tcg_gen_ctz_i32(TCGV_LOW(ret), TCGV_LOW(arg1), t32);
544
tcg_gen_movi_i32(TCGV_HIGH(ret), 0);
545
@@ -XXX,XX +XXX,XX @@ void tcg_gen_ctzi_i64(TCGv_i64 ret, TCGv_i64 arg1, uint64_t arg2)
546
tcg_gen_ctpop_i64(ret, t);
547
tcg_temp_free_i64(t);
548
} else {
549
- TCGv_i64 t64 = tcg_const_i64(arg2);
550
- tcg_gen_ctz_i64(ret, arg1, t64);
551
- tcg_temp_free_i64(t64);
552
+ TCGv_i64 t0 = tcg_const_i64(arg2);
553
+ tcg_gen_ctz_i64(ret, arg1, t0);
554
+ tcg_temp_free_i64(t0);
555
}
556
}
557
558
@@ -XXX,XX +XXX,XX @@ void tcg_gen_rotli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
559
if (arg2 == 0) {
560
tcg_gen_mov_i64(ret, arg1);
561
} else if (TCG_TARGET_HAS_rot_i64) {
562
- TCGv_i64 t0 = tcg_const_i64(arg2);
563
- tcg_gen_rotl_i64(ret, arg1, t0);
564
- tcg_temp_free_i64(t0);
565
+ tcg_gen_rotl_i64(ret, arg1, tcg_constant_i64(arg2));
566
} else {
567
TCGv_i64 t0, t1;
568
t0 = tcg_temp_new_i64();
569
@@ -XXX,XX +XXX,XX @@ void tcg_gen_deposit_z_i64(TCGv_i64 ret, TCGv_i64 arg,
570
tcg_gen_andi_i64(ret, arg, (1ull << len) - 1);
571
} else if (TCG_TARGET_HAS_deposit_i64
572
&& TCG_TARGET_deposit_i64_valid(ofs, len)) {
573
- TCGv_i64 zero = tcg_const_i64(0);
574
+ TCGv_i64 zero = tcg_constant_i64(0);
575
tcg_gen_op5ii_i64(INDEX_op_deposit_i64, ret, zero, arg, ofs, len);
576
- tcg_temp_free_i64(zero);
577
} else {
578
if (TCG_TARGET_REG_BITS == 32) {
579
if (ofs >= 32) {
580
@@ -XXX,XX +XXX,XX @@ void tcg_gen_atomic_cmpxchg_i32(TCGv_i32 retv, TCGv addr, TCGv_i32 cmpv,
581
582
#ifdef CONFIG_SOFTMMU
583
{
584
- TCGv_i32 oi = tcg_const_i32(make_memop_idx(memop & ~MO_SIGN, idx));
585
- gen(retv, cpu_env, addr, cmpv, newv, oi);
586
- tcg_temp_free_i32(oi);
587
+ TCGMemOpIdx oi = make_memop_idx(memop & ~MO_SIGN, idx);
588
+ gen(retv, cpu_env, addr, cmpv, newv, tcg_constant_i32(oi));
589
}
590
#else
591
gen(retv, cpu_env, addr, cmpv, newv);
592
@@ -XXX,XX +XXX,XX @@ void tcg_gen_atomic_cmpxchg_i64(TCGv_i64 retv, TCGv addr, TCGv_i64 cmpv,
593
594
#ifdef CONFIG_SOFTMMU
595
{
596
- TCGv_i32 oi = tcg_const_i32(make_memop_idx(memop, idx));
597
- gen(retv, cpu_env, addr, cmpv, newv, oi);
598
- tcg_temp_free_i32(oi);
599
+ TCGMemOpIdx oi = make_memop_idx(memop, idx);
600
+ gen(retv, cpu_env, addr, cmpv, newv, tcg_constant_i32(oi));
601
}
602
#else
603
gen(retv, cpu_env, addr, cmpv, newv);
604
@@ -XXX,XX +XXX,XX @@ static void do_atomic_op_i32(TCGv_i32 ret, TCGv addr, TCGv_i32 val,
605
606
#ifdef CONFIG_SOFTMMU
607
{
608
- TCGv_i32 oi = tcg_const_i32(make_memop_idx(memop & ~MO_SIGN, idx));
609
- gen(ret, cpu_env, addr, val, oi);
610
- tcg_temp_free_i32(oi);
611
+ TCGMemOpIdx oi = make_memop_idx(memop & ~MO_SIGN, idx);
612
+ gen(ret, cpu_env, addr, val, tcg_constant_i32(oi));
613
}
614
#else
615
gen(ret, cpu_env, addr, val);
616
@@ -XXX,XX +XXX,XX @@ static void do_atomic_op_i64(TCGv_i64 ret, TCGv addr, TCGv_i64 val,
617
618
#ifdef CONFIG_SOFTMMU
619
{
620
- TCGv_i32 oi = tcg_const_i32(make_memop_idx(memop & ~MO_SIGN, idx));
621
- gen(ret, cpu_env, addr, val, oi);
622
- tcg_temp_free_i32(oi);
623
+ TCGMemOpIdx oi = make_memop_idx(memop & ~MO_SIGN, idx);
624
+ gen(ret, cpu_env, addr, val, tcg_constant_i32(oi));
625
}
626
#else
627
gen(ret, cpu_env, addr, val);
628
--
629
2.25.1
630
631
diff view generated by jsdifflib
New patch
1
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
2
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
3
---
4
accel/tcg/plugin-gen.c | 49 +++++++++++++++++++-----------------------
5
1 file changed, 22 insertions(+), 27 deletions(-)
1
6
7
diff --git a/accel/tcg/plugin-gen.c b/accel/tcg/plugin-gen.c
8
index XXXXXXX..XXXXXXX 100644
9
--- a/accel/tcg/plugin-gen.c
10
+++ b/accel/tcg/plugin-gen.c
11
@@ -XXX,XX +XXX,XX @@ static TCGOp *copy_extu_i32_i64(TCGOp **begin_op, TCGOp *op)
12
if (TCG_TARGET_REG_BITS == 32) {
13
/* mov_i32 */
14
op = copy_op(begin_op, op, INDEX_op_mov_i32);
15
- /* movi_i32 */
16
- op = copy_op(begin_op, op, INDEX_op_movi_i32);
17
+ /* mov_i32 w/ $0 */
18
+ op = copy_op(begin_op, op, INDEX_op_mov_i32);
19
} else {
20
/* extu_i32_i64 */
21
op = copy_op(begin_op, op, INDEX_op_extu_i32_i64);
22
@@ -XXX,XX +XXX,XX @@ static TCGOp *copy_mov_i64(TCGOp **begin_op, TCGOp *op)
23
return op;
24
}
25
26
-static TCGOp *copy_movi_i64(TCGOp **begin_op, TCGOp *op, uint64_t v)
27
-{
28
- if (TCG_TARGET_REG_BITS == 32) {
29
- /* 2x movi_i32 */
30
- op = copy_op(begin_op, op, INDEX_op_movi_i32);
31
- op->args[1] = v;
32
-
33
- op = copy_op(begin_op, op, INDEX_op_movi_i32);
34
- op->args[1] = v >> 32;
35
- } else {
36
- /* movi_i64 */
37
- op = copy_op(begin_op, op, INDEX_op_movi_i64);
38
- op->args[1] = v;
39
- }
40
- return op;
41
-}
42
-
43
static TCGOp *copy_const_ptr(TCGOp **begin_op, TCGOp *op, void *ptr)
44
{
45
if (UINTPTR_MAX == UINT32_MAX) {
46
- /* movi_i32 */
47
- op = copy_op(begin_op, op, INDEX_op_movi_i32);
48
- op->args[1] = (uintptr_t)ptr;
49
+ /* mov_i32 */
50
+ op = copy_op(begin_op, op, INDEX_op_mov_i32);
51
+ op->args[1] = tcgv_i32_arg(tcg_constant_i32((uintptr_t)ptr));
52
} else {
53
- /* movi_i64 */
54
- op = copy_movi_i64(begin_op, op, (uint64_t)(uintptr_t)ptr);
55
+ /* mov_i64 */
56
+ op = copy_op(begin_op, op, INDEX_op_mov_i64);
57
+ op->args[1] = tcgv_i64_arg(tcg_constant_i64((uintptr_t)ptr));
58
}
59
return op;
60
}
61
62
static TCGOp *copy_const_i64(TCGOp **begin_op, TCGOp *op, uint64_t v)
63
{
64
- return copy_movi_i64(begin_op, op, v);
65
+ if (TCG_TARGET_REG_BITS == 32) {
66
+ /* 2x mov_i32 */
67
+ op = copy_op(begin_op, op, INDEX_op_mov_i32);
68
+ op->args[1] = tcgv_i32_arg(tcg_constant_i32(v));
69
+ op = copy_op(begin_op, op, INDEX_op_mov_i32);
70
+ op->args[1] = tcgv_i32_arg(tcg_constant_i32(v >> 32));
71
+ } else {
72
+ /* mov_i64 */
73
+ op = copy_op(begin_op, op, INDEX_op_mov_i64);
74
+ op->args[1] = tcgv_i64_arg(tcg_constant_i64(v));
75
+ }
76
+ return op;
77
}
78
79
static TCGOp *copy_extu_tl_i64(TCGOp **begin_op, TCGOp *op)
80
@@ -XXX,XX +XXX,XX @@ static TCGOp *append_mem_cb(const struct qemu_plugin_dyn_cb *cb,
81
82
tcg_debug_assert(type == PLUGIN_GEN_CB_MEM);
83
84
- /* const_i32 == movi_i32 ("info", so it remains as is) */
85
- op = copy_op(&begin_op, op, INDEX_op_movi_i32);
86
+ /* const_i32 == mov_i32 ("info", so it remains as is) */
87
+ op = copy_op(&begin_op, op, INDEX_op_mov_i32);
88
89
/* const_ptr */
90
op = copy_const_ptr(&begin_op, op, cb->userp);
91
--
92
2.25.1
93
94
diff view generated by jsdifflib
New patch
1
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
2
---
3
include/tcg/tcg.h | 1 +
4
tcg/tcg-op-gvec.c | 129 ++++++++++++++++++----------------------------
5
tcg/tcg.c | 8 +++
6
3 files changed, 60 insertions(+), 78 deletions(-)
1
7
8
diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h
9
index XXXXXXX..XXXXXXX 100644
10
--- a/include/tcg/tcg.h
11
+++ b/include/tcg/tcg.h
12
@@ -XXX,XX +XXX,XX @@ static inline TCGv_i64 tcg_constant_i64(int64_t val)
13
}
14
15
TCGv_vec tcg_constant_vec(TCGType type, unsigned vece, int64_t val);
16
+TCGv_vec tcg_constant_vec_matching(TCGv_vec match, unsigned vece, int64_t val);
17
18
#if UINTPTR_MAX == UINT32_MAX
19
# define tcg_const_ptr(x) ((TCGv_ptr)tcg_const_i32((intptr_t)(x)))
20
diff --git a/tcg/tcg-op-gvec.c b/tcg/tcg-op-gvec.c
21
index XXXXXXX..XXXXXXX 100644
22
--- a/tcg/tcg-op-gvec.c
23
+++ b/tcg/tcg-op-gvec.c
24
@@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_2_ool(uint32_t dofs, uint32_t aofs,
25
gen_helper_gvec_2 *fn)
26
{
27
TCGv_ptr a0, a1;
28
- TCGv_i32 desc = tcg_const_i32(simd_desc(oprsz, maxsz, data));
29
+ TCGv_i32 desc = tcg_constant_i32(simd_desc(oprsz, maxsz, data));
30
31
a0 = tcg_temp_new_ptr();
32
a1 = tcg_temp_new_ptr();
33
@@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_2_ool(uint32_t dofs, uint32_t aofs,
34
35
tcg_temp_free_ptr(a0);
36
tcg_temp_free_ptr(a1);
37
- tcg_temp_free_i32(desc);
38
}
39
40
/* Generate a call to a gvec-style helper with two vector operands
41
@@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_2i_ool(uint32_t dofs, uint32_t aofs, TCGv_i64 c,
42
gen_helper_gvec_2i *fn)
43
{
44
TCGv_ptr a0, a1;
45
- TCGv_i32 desc = tcg_const_i32(simd_desc(oprsz, maxsz, data));
46
+ TCGv_i32 desc = tcg_constant_i32(simd_desc(oprsz, maxsz, data));
47
48
a0 = tcg_temp_new_ptr();
49
a1 = tcg_temp_new_ptr();
50
@@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_2i_ool(uint32_t dofs, uint32_t aofs, TCGv_i64 c,
51
52
tcg_temp_free_ptr(a0);
53
tcg_temp_free_ptr(a1);
54
- tcg_temp_free_i32(desc);
55
}
56
57
/* Generate a call to a gvec-style helper with three vector operands. */
58
@@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_3_ool(uint32_t dofs, uint32_t aofs, uint32_t bofs,
59
gen_helper_gvec_3 *fn)
60
{
61
TCGv_ptr a0, a1, a2;
62
- TCGv_i32 desc = tcg_const_i32(simd_desc(oprsz, maxsz, data));
63
+ TCGv_i32 desc = tcg_constant_i32(simd_desc(oprsz, maxsz, data));
64
65
a0 = tcg_temp_new_ptr();
66
a1 = tcg_temp_new_ptr();
67
@@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_3_ool(uint32_t dofs, uint32_t aofs, uint32_t bofs,
68
tcg_temp_free_ptr(a0);
69
tcg_temp_free_ptr(a1);
70
tcg_temp_free_ptr(a2);
71
- tcg_temp_free_i32(desc);
72
}
73
74
/* Generate a call to a gvec-style helper with four vector operands. */
75
@@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_4_ool(uint32_t dofs, uint32_t aofs, uint32_t bofs,
76
int32_t data, gen_helper_gvec_4 *fn)
77
{
78
TCGv_ptr a0, a1, a2, a3;
79
- TCGv_i32 desc = tcg_const_i32(simd_desc(oprsz, maxsz, data));
80
+ TCGv_i32 desc = tcg_constant_i32(simd_desc(oprsz, maxsz, data));
81
82
a0 = tcg_temp_new_ptr();
83
a1 = tcg_temp_new_ptr();
84
@@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_4_ool(uint32_t dofs, uint32_t aofs, uint32_t bofs,
85
tcg_temp_free_ptr(a1);
86
tcg_temp_free_ptr(a2);
87
tcg_temp_free_ptr(a3);
88
- tcg_temp_free_i32(desc);
89
}
90
91
/* Generate a call to a gvec-style helper with five vector operands. */
92
@@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_5_ool(uint32_t dofs, uint32_t aofs, uint32_t bofs,
93
uint32_t maxsz, int32_t data, gen_helper_gvec_5 *fn)
94
{
95
TCGv_ptr a0, a1, a2, a3, a4;
96
- TCGv_i32 desc = tcg_const_i32(simd_desc(oprsz, maxsz, data));
97
+ TCGv_i32 desc = tcg_constant_i32(simd_desc(oprsz, maxsz, data));
98
99
a0 = tcg_temp_new_ptr();
100
a1 = tcg_temp_new_ptr();
101
@@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_5_ool(uint32_t dofs, uint32_t aofs, uint32_t bofs,
102
tcg_temp_free_ptr(a2);
103
tcg_temp_free_ptr(a3);
104
tcg_temp_free_ptr(a4);
105
- tcg_temp_free_i32(desc);
106
}
107
108
/* Generate a call to a gvec-style helper with three vector operands
109
@@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_2_ptr(uint32_t dofs, uint32_t aofs,
110
int32_t data, gen_helper_gvec_2_ptr *fn)
111
{
112
TCGv_ptr a0, a1;
113
- TCGv_i32 desc = tcg_const_i32(simd_desc(oprsz, maxsz, data));
114
+ TCGv_i32 desc = tcg_constant_i32(simd_desc(oprsz, maxsz, data));
115
116
a0 = tcg_temp_new_ptr();
117
a1 = tcg_temp_new_ptr();
118
@@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_2_ptr(uint32_t dofs, uint32_t aofs,
119
120
tcg_temp_free_ptr(a0);
121
tcg_temp_free_ptr(a1);
122
- tcg_temp_free_i32(desc);
123
}
124
125
/* Generate a call to a gvec-style helper with three vector operands
126
@@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_3_ptr(uint32_t dofs, uint32_t aofs, uint32_t bofs,
127
int32_t data, gen_helper_gvec_3_ptr *fn)
128
{
129
TCGv_ptr a0, a1, a2;
130
- TCGv_i32 desc = tcg_const_i32(simd_desc(oprsz, maxsz, data));
131
+ TCGv_i32 desc = tcg_constant_i32(simd_desc(oprsz, maxsz, data));
132
133
a0 = tcg_temp_new_ptr();
134
a1 = tcg_temp_new_ptr();
135
@@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_3_ptr(uint32_t dofs, uint32_t aofs, uint32_t bofs,
136
tcg_temp_free_ptr(a0);
137
tcg_temp_free_ptr(a1);
138
tcg_temp_free_ptr(a2);
139
- tcg_temp_free_i32(desc);
140
}
141
142
/* Generate a call to a gvec-style helper with four vector operands
143
@@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_4_ptr(uint32_t dofs, uint32_t aofs, uint32_t bofs,
144
gen_helper_gvec_4_ptr *fn)
145
{
146
TCGv_ptr a0, a1, a2, a3;
147
- TCGv_i32 desc = tcg_const_i32(simd_desc(oprsz, maxsz, data));
148
+ TCGv_i32 desc = tcg_constant_i32(simd_desc(oprsz, maxsz, data));
149
150
a0 = tcg_temp_new_ptr();
151
a1 = tcg_temp_new_ptr();
152
@@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_4_ptr(uint32_t dofs, uint32_t aofs, uint32_t bofs,
153
tcg_temp_free_ptr(a1);
154
tcg_temp_free_ptr(a2);
155
tcg_temp_free_ptr(a3);
156
- tcg_temp_free_i32(desc);
157
}
158
159
/* Generate a call to a gvec-style helper with five vector operands
160
@@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_5_ptr(uint32_t dofs, uint32_t aofs, uint32_t bofs,
161
gen_helper_gvec_5_ptr *fn)
162
{
163
TCGv_ptr a0, a1, a2, a3, a4;
164
- TCGv_i32 desc = tcg_const_i32(simd_desc(oprsz, maxsz, data));
165
+ TCGv_i32 desc = tcg_constant_i32(simd_desc(oprsz, maxsz, data));
166
167
a0 = tcg_temp_new_ptr();
168
a1 = tcg_temp_new_ptr();
169
@@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_5_ptr(uint32_t dofs, uint32_t aofs, uint32_t bofs,
170
tcg_temp_free_ptr(a2);
171
tcg_temp_free_ptr(a3);
172
tcg_temp_free_ptr(a4);
173
- tcg_temp_free_i32(desc);
174
}
175
176
/* Return true if we want to implement something of OPRSZ bytes
177
@@ -XXX,XX +XXX,XX @@ static void do_dup(unsigned vece, uint32_t dofs, uint32_t oprsz,
178
|| (TCG_TARGET_REG_BITS == 64
179
&& (in_c == 0 || in_c == -1
180
|| !check_size_impl(oprsz, 4)))) {
181
- t_64 = tcg_const_i64(in_c);
182
+ t_64 = tcg_constant_i64(in_c);
183
} else {
184
- t_32 = tcg_const_i32(in_c);
185
+ t_32 = tcg_constant_i32(in_c);
186
}
187
}
188
189
@@ -XXX,XX +XXX,XX @@ static void do_dup(unsigned vece, uint32_t dofs, uint32_t oprsz,
190
t_val = tcg_temp_new_i32();
191
tcg_gen_extrl_i64_i32(t_val, in_64);
192
} else {
193
- t_val = tcg_const_i32(in_c);
194
+ t_val = tcg_constant_i32(in_c);
195
}
196
gen_helper_memset(t_ptr, t_ptr, t_val, t_size);
197
198
- if (!in_32) {
199
+ if (in_64) {
200
tcg_temp_free_i32(t_val);
201
}
202
tcg_temp_free_ptr(t_size);
203
@@ -XXX,XX +XXX,XX @@ static void do_dup(unsigned vece, uint32_t dofs, uint32_t oprsz,
204
return;
205
}
206
207
- t_desc = tcg_const_i32(simd_desc(oprsz, maxsz, 0));
208
+ t_desc = tcg_constant_i32(simd_desc(oprsz, maxsz, 0));
209
210
if (vece == MO_64) {
211
if (in_64) {
212
gen_helper_gvec_dup64(t_ptr, t_desc, in_64);
213
} else {
214
- t_64 = tcg_const_i64(in_c);
215
+ t_64 = tcg_constant_i64(in_c);
216
gen_helper_gvec_dup64(t_ptr, t_desc, t_64);
217
- tcg_temp_free_i64(t_64);
218
}
219
} else {
220
typedef void dup_fn(TCGv_ptr, TCGv_i32, TCGv_i32);
221
@@ -XXX,XX +XXX,XX @@ static void do_dup(unsigned vece, uint32_t dofs, uint32_t oprsz,
222
223
if (in_32) {
224
fns[vece](t_ptr, t_desc, in_32);
225
- } else {
226
+ } else if (in_64) {
227
t_32 = tcg_temp_new_i32();
228
- if (in_64) {
229
- tcg_gen_extrl_i64_i32(t_32, in_64);
230
- } else if (vece == MO_8) {
231
- tcg_gen_movi_i32(t_32, in_c & 0xff);
232
- } else if (vece == MO_16) {
233
- tcg_gen_movi_i32(t_32, in_c & 0xffff);
234
- } else {
235
- tcg_gen_movi_i32(t_32, in_c);
236
- }
237
+ tcg_gen_extrl_i64_i32(t_32, in_64);
238
fns[vece](t_ptr, t_desc, t_32);
239
tcg_temp_free_i32(t_32);
240
+ } else {
241
+ if (vece == MO_8) {
242
+ in_c &= 0xff;
243
+ } else if (vece == MO_16) {
244
+ in_c &= 0xffff;
245
+ }
246
+ t_32 = tcg_constant_i32(in_c);
247
+ fns[vece](t_ptr, t_desc, t_32);
248
}
249
}
250
251
tcg_temp_free_ptr(t_ptr);
252
- tcg_temp_free_i32(t_desc);
253
return;
254
255
done:
256
@@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_2i(uint32_t dofs, uint32_t aofs, uint32_t oprsz,
257
if (g->fno) {
258
tcg_gen_gvec_2_ool(dofs, aofs, oprsz, maxsz, c, g->fno);
259
} else {
260
- TCGv_i64 tcg_c = tcg_const_i64(c);
261
+ TCGv_i64 tcg_c = tcg_constant_i64(c);
262
tcg_gen_gvec_2i_ool(dofs, aofs, tcg_c, oprsz,
263
maxsz, c, g->fnoi);
264
- tcg_temp_free_i64(tcg_c);
265
}
266
oprsz = maxsz;
267
}
268
@@ -XXX,XX +XXX,XX @@ static void gen_addv_mask(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b, TCGv_i64 m)
269
270
void tcg_gen_vec_add8_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b)
271
{
272
- TCGv_i64 m = tcg_const_i64(dup_const(MO_8, 0x80));
273
+ TCGv_i64 m = tcg_constant_i64(dup_const(MO_8, 0x80));
274
gen_addv_mask(d, a, b, m);
275
- tcg_temp_free_i64(m);
276
}
277
278
void tcg_gen_vec_add16_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b)
279
{
280
- TCGv_i64 m = tcg_const_i64(dup_const(MO_16, 0x8000));
281
+ TCGv_i64 m = tcg_constant_i64(dup_const(MO_16, 0x8000));
282
gen_addv_mask(d, a, b, m);
283
- tcg_temp_free_i64(m);
284
}
285
286
void tcg_gen_vec_add32_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b)
287
@@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_adds(unsigned vece, uint32_t dofs, uint32_t aofs,
288
void tcg_gen_gvec_addi(unsigned vece, uint32_t dofs, uint32_t aofs,
289
int64_t c, uint32_t oprsz, uint32_t maxsz)
290
{
291
- TCGv_i64 tmp = tcg_const_i64(c);
292
+ TCGv_i64 tmp = tcg_constant_i64(c);
293
tcg_gen_gvec_adds(vece, dofs, aofs, tmp, oprsz, maxsz);
294
- tcg_temp_free_i64(tmp);
295
}
296
297
static const TCGOpcode vecop_list_sub[] = { INDEX_op_sub_vec, 0 };
298
@@ -XXX,XX +XXX,XX @@ static void gen_subv_mask(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b, TCGv_i64 m)
299
300
void tcg_gen_vec_sub8_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b)
301
{
302
- TCGv_i64 m = tcg_const_i64(dup_const(MO_8, 0x80));
303
+ TCGv_i64 m = tcg_constant_i64(dup_const(MO_8, 0x80));
304
gen_subv_mask(d, a, b, m);
305
- tcg_temp_free_i64(m);
306
}
307
308
void tcg_gen_vec_sub16_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b)
309
{
310
- TCGv_i64 m = tcg_const_i64(dup_const(MO_16, 0x8000));
311
+ TCGv_i64 m = tcg_constant_i64(dup_const(MO_16, 0x8000));
312
gen_subv_mask(d, a, b, m);
313
- tcg_temp_free_i64(m);
314
}
315
316
void tcg_gen_vec_sub32_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b)
317
@@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_muls(unsigned vece, uint32_t dofs, uint32_t aofs,
318
void tcg_gen_gvec_muli(unsigned vece, uint32_t dofs, uint32_t aofs,
319
int64_t c, uint32_t oprsz, uint32_t maxsz)
320
{
321
- TCGv_i64 tmp = tcg_const_i64(c);
322
+ TCGv_i64 tmp = tcg_constant_i64(c);
323
tcg_gen_gvec_muls(vece, dofs, aofs, tmp, oprsz, maxsz);
324
- tcg_temp_free_i64(tmp);
325
}
326
327
void tcg_gen_gvec_ssadd(unsigned vece, uint32_t dofs, uint32_t aofs,
328
@@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_sssub(unsigned vece, uint32_t dofs, uint32_t aofs,
329
330
static void tcg_gen_usadd_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b)
331
{
332
- TCGv_i32 max = tcg_const_i32(-1);
333
+ TCGv_i32 max = tcg_constant_i32(-1);
334
tcg_gen_add_i32(d, a, b);
335
tcg_gen_movcond_i32(TCG_COND_LTU, d, d, a, max, d);
336
- tcg_temp_free_i32(max);
337
}
338
339
static void tcg_gen_usadd_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b)
340
{
341
- TCGv_i64 max = tcg_const_i64(-1);
342
+ TCGv_i64 max = tcg_constant_i64(-1);
343
tcg_gen_add_i64(d, a, b);
344
tcg_gen_movcond_i64(TCG_COND_LTU, d, d, a, max, d);
345
- tcg_temp_free_i64(max);
346
}
347
348
void tcg_gen_gvec_usadd(unsigned vece, uint32_t dofs, uint32_t aofs,
349
@@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_usadd(unsigned vece, uint32_t dofs, uint32_t aofs,
350
351
static void tcg_gen_ussub_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b)
352
{
353
- TCGv_i32 min = tcg_const_i32(0);
354
+ TCGv_i32 min = tcg_constant_i32(0);
355
tcg_gen_sub_i32(d, a, b);
356
tcg_gen_movcond_i32(TCG_COND_LTU, d, a, b, min, d);
357
- tcg_temp_free_i32(min);
358
}
359
360
static void tcg_gen_ussub_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b)
361
{
362
- TCGv_i64 min = tcg_const_i64(0);
363
+ TCGv_i64 min = tcg_constant_i64(0);
364
tcg_gen_sub_i64(d, a, b);
365
tcg_gen_movcond_i64(TCG_COND_LTU, d, a, b, min, d);
366
- tcg_temp_free_i64(min);
367
}
368
369
void tcg_gen_gvec_ussub(unsigned vece, uint32_t dofs, uint32_t aofs,
370
@@ -XXX,XX +XXX,XX @@ static void gen_negv_mask(TCGv_i64 d, TCGv_i64 b, TCGv_i64 m)
371
372
void tcg_gen_vec_neg8_i64(TCGv_i64 d, TCGv_i64 b)
373
{
374
- TCGv_i64 m = tcg_const_i64(dup_const(MO_8, 0x80));
375
+ TCGv_i64 m = tcg_constant_i64(dup_const(MO_8, 0x80));
376
gen_negv_mask(d, b, m);
377
- tcg_temp_free_i64(m);
378
}
379
380
void tcg_gen_vec_neg16_i64(TCGv_i64 d, TCGv_i64 b)
381
{
382
- TCGv_i64 m = tcg_const_i64(dup_const(MO_16, 0x8000));
383
+ TCGv_i64 m = tcg_constant_i64(dup_const(MO_16, 0x8000));
384
gen_negv_mask(d, b, m);
385
- tcg_temp_free_i64(m);
386
}
387
388
void tcg_gen_vec_neg32_i64(TCGv_i64 d, TCGv_i64 b)
389
@@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_ands(unsigned vece, uint32_t dofs, uint32_t aofs,
390
void tcg_gen_gvec_andi(unsigned vece, uint32_t dofs, uint32_t aofs,
391
int64_t c, uint32_t oprsz, uint32_t maxsz)
392
{
393
- TCGv_i64 tmp = tcg_const_i64(dup_const(vece, c));
394
+ TCGv_i64 tmp = tcg_constant_i64(dup_const(vece, c));
395
tcg_gen_gvec_2s(dofs, aofs, oprsz, maxsz, tmp, &gop_ands);
396
- tcg_temp_free_i64(tmp);
397
}
398
399
static const GVecGen2s gop_xors = {
400
@@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_xors(unsigned vece, uint32_t dofs, uint32_t aofs,
401
void tcg_gen_gvec_xori(unsigned vece, uint32_t dofs, uint32_t aofs,
402
int64_t c, uint32_t oprsz, uint32_t maxsz)
403
{
404
- TCGv_i64 tmp = tcg_const_i64(dup_const(vece, c));
405
+ TCGv_i64 tmp = tcg_constant_i64(dup_const(vece, c));
406
tcg_gen_gvec_2s(dofs, aofs, oprsz, maxsz, tmp, &gop_xors);
407
- tcg_temp_free_i64(tmp);
408
}
409
410
static const GVecGen2s gop_ors = {
411
@@ -XXX,XX +XXX,XX @@ void tcg_gen_gvec_ors(unsigned vece, uint32_t dofs, uint32_t aofs,
412
void tcg_gen_gvec_ori(unsigned vece, uint32_t dofs, uint32_t aofs,
413
int64_t c, uint32_t oprsz, uint32_t maxsz)
414
{
415
- TCGv_i64 tmp = tcg_const_i64(dup_const(vece, c));
416
+ TCGv_i64 tmp = tcg_constant_i64(dup_const(vece, c));
417
tcg_gen_gvec_2s(dofs, aofs, oprsz, maxsz, tmp, &gop_ors);
418
- tcg_temp_free_i64(tmp);
419
}
420
421
void tcg_gen_vec_shl8i_i64(TCGv_i64 d, TCGv_i64 a, int64_t c)
422
@@ -XXX,XX +XXX,XX @@ static void tcg_gen_shlv_mod_vec(unsigned vece, TCGv_vec d,
423
TCGv_vec a, TCGv_vec b)
424
{
425
TCGv_vec t = tcg_temp_new_vec_matching(d);
426
+ TCGv_vec m = tcg_constant_vec_matching(d, vece, (8 << vece) - 1);
427
428
- tcg_gen_dupi_vec(vece, t, (8 << vece) - 1);
429
- tcg_gen_and_vec(vece, t, t, b);
430
+ tcg_gen_and_vec(vece, t, b, m);
431
tcg_gen_shlv_vec(vece, d, a, t);
432
tcg_temp_free_vec(t);
433
}
434
@@ -XXX,XX +XXX,XX @@ static void tcg_gen_shrv_mod_vec(unsigned vece, TCGv_vec d,
435
TCGv_vec a, TCGv_vec b)
436
{
437
TCGv_vec t = tcg_temp_new_vec_matching(d);
438
+ TCGv_vec m = tcg_constant_vec_matching(d, vece, (8 << vece) - 1);
439
440
- tcg_gen_dupi_vec(vece, t, (8 << vece) - 1);
441
- tcg_gen_and_vec(vece, t, t, b);
442
+ tcg_gen_and_vec(vece, t, b, m);
443
tcg_gen_shrv_vec(vece, d, a, t);
444
tcg_temp_free_vec(t);
445
}
446
@@ -XXX,XX +XXX,XX @@ static void tcg_gen_sarv_mod_vec(unsigned vece, TCGv_vec d,
447
TCGv_vec a, TCGv_vec b)
448
{
449
TCGv_vec t = tcg_temp_new_vec_matching(d);
450
+ TCGv_vec m = tcg_constant_vec_matching(d, vece, (8 << vece) - 1);
451
452
- tcg_gen_dupi_vec(vece, t, (8 << vece) - 1);
453
- tcg_gen_and_vec(vece, t, t, b);
454
+ tcg_gen_and_vec(vece, t, b, m);
455
tcg_gen_sarv_vec(vece, d, a, t);
456
tcg_temp_free_vec(t);
457
}
458
@@ -XXX,XX +XXX,XX @@ static void tcg_gen_rotlv_mod_vec(unsigned vece, TCGv_vec d,
459
TCGv_vec a, TCGv_vec b)
460
{
461
TCGv_vec t = tcg_temp_new_vec_matching(d);
462
+ TCGv_vec m = tcg_constant_vec_matching(d, vece, (8 << vece) - 1);
463
464
- tcg_gen_dupi_vec(vece, t, (8 << vece) - 1);
465
- tcg_gen_and_vec(vece, t, t, b);
466
+ tcg_gen_and_vec(vece, t, b, m);
467
tcg_gen_rotlv_vec(vece, d, a, t);
468
tcg_temp_free_vec(t);
469
}
470
@@ -XXX,XX +XXX,XX @@ static void tcg_gen_rotrv_mod_vec(unsigned vece, TCGv_vec d,
471
TCGv_vec a, TCGv_vec b)
472
{
473
TCGv_vec t = tcg_temp_new_vec_matching(d);
474
+ TCGv_vec m = tcg_constant_vec_matching(d, vece, (8 << vece) - 1);
475
476
- tcg_gen_dupi_vec(vece, t, (8 << vece) - 1);
477
- tcg_gen_and_vec(vece, t, t, b);
478
+ tcg_gen_and_vec(vece, t, b, m);
479
tcg_gen_rotrv_vec(vece, d, a, t);
480
tcg_temp_free_vec(t);
481
}
482
diff --git a/tcg/tcg.c b/tcg/tcg.c
483
index XXXXXXX..XXXXXXX 100644
484
--- a/tcg/tcg.c
485
+++ b/tcg/tcg.c
486
@@ -XXX,XX +XXX,XX @@ TCGv_vec tcg_constant_vec(TCGType type, unsigned vece, int64_t val)
487
return temp_tcgv_vec(tcg_constant_internal(type, val));
488
}
489
490
+TCGv_vec tcg_constant_vec_matching(TCGv_vec match, unsigned vece, int64_t val)
491
+{
492
+ TCGTemp *t = tcgv_vec_temp(match);
493
+
494
+ tcg_debug_assert(t->temp_allocated != 0);
495
+ return tcg_constant_vec(t->base_type, vece, val);
496
+}
497
+
498
TCGv_i32 tcg_const_i32(int32_t val)
499
{
500
TCGv_i32 t0;
501
--
502
2.25.1
503
504
diff view generated by jsdifflib
New patch
1
The normal movi opcodes are going away. We need something
2
for TCI to use internally.
1
3
4
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
5
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
6
---
7
include/tcg/tcg-opc.h | 8 ++++++++
8
tcg/tci.c | 4 ++--
9
tcg/tci/tcg-target.c.inc | 4 ++--
10
3 files changed, 12 insertions(+), 4 deletions(-)
11
12
diff --git a/include/tcg/tcg-opc.h b/include/tcg/tcg-opc.h
13
index XXXXXXX..XXXXXXX 100644
14
--- a/include/tcg/tcg-opc.h
15
+++ b/include/tcg/tcg-opc.h
16
@@ -XXX,XX +XXX,XX @@ DEF(last_generic, 0, 0, 0, TCG_OPF_NOT_PRESENT)
17
#include "tcg-target.opc.h"
18
#endif
19
20
+#ifdef TCG_TARGET_INTERPRETER
21
+/* These opcodes are only for use between the tci generator and interpreter. */
22
+DEF(tci_movi_i32, 1, 0, 1, TCG_OPF_NOT_PRESENT)
23
+#if TCG_TARGET_REG_BITS == 64
24
+DEF(tci_movi_i64, 1, 0, 1, TCG_OPF_64BIT | TCG_OPF_NOT_PRESENT)
25
+#endif
26
+#endif
27
+
28
#undef TLADDR_ARGS
29
#undef DATA64_ARGS
30
#undef IMPL
31
diff --git a/tcg/tci.c b/tcg/tci.c
32
index XXXXXXX..XXXXXXX 100644
33
--- a/tcg/tci.c
34
+++ b/tcg/tci.c
35
@@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env,
36
t1 = tci_read_r32(regs, &tb_ptr);
37
tci_write_reg32(regs, t0, t1);
38
break;
39
- case INDEX_op_movi_i32:
40
+ case INDEX_op_tci_movi_i32:
41
t0 = *tb_ptr++;
42
t1 = tci_read_i32(&tb_ptr);
43
tci_write_reg32(regs, t0, t1);
44
@@ -XXX,XX +XXX,XX @@ uintptr_t QEMU_DISABLE_CFI tcg_qemu_tb_exec(CPUArchState *env,
45
t1 = tci_read_r64(regs, &tb_ptr);
46
tci_write_reg64(regs, t0, t1);
47
break;
48
- case INDEX_op_movi_i64:
49
+ case INDEX_op_tci_movi_i64:
50
t0 = *tb_ptr++;
51
t1 = tci_read_i64(&tb_ptr);
52
tci_write_reg64(regs, t0, t1);
53
diff --git a/tcg/tci/tcg-target.c.inc b/tcg/tci/tcg-target.c.inc
54
index XXXXXXX..XXXXXXX 100644
55
--- a/tcg/tci/tcg-target.c.inc
56
+++ b/tcg/tci/tcg-target.c.inc
57
@@ -XXX,XX +XXX,XX @@ static void tcg_out_movi(TCGContext *s, TCGType type,
58
uint8_t *old_code_ptr = s->code_ptr;
59
uint32_t arg32 = arg;
60
if (type == TCG_TYPE_I32 || arg == arg32) {
61
- tcg_out_op_t(s, INDEX_op_movi_i32);
62
+ tcg_out_op_t(s, INDEX_op_tci_movi_i32);
63
tcg_out_r(s, t0);
64
tcg_out32(s, arg32);
65
} else {
66
tcg_debug_assert(type == TCG_TYPE_I64);
67
#if TCG_TARGET_REG_BITS == 64
68
- tcg_out_op_t(s, INDEX_op_movi_i64);
69
+ tcg_out_op_t(s, INDEX_op_tci_movi_i64);
70
tcg_out_r(s, t0);
71
tcg_out64(s, arg);
72
#else
73
--
74
2.25.1
75
76
diff view generated by jsdifflib
New patch
1
1
These are now completely covered by mov from a
2
TYPE_CONST temporary.
3
4
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
5
Reviewed-by: Aleksandar Markovic <aleksandar.qemu.devel@gmail.com>
6
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
7
---
8
include/tcg/tcg-opc.h | 3 ---
9
tcg/optimize.c | 4 ----
10
tcg/tcg-op-vec.c | 1 -
11
tcg/tcg.c | 18 +-----------------
12
tcg/aarch64/tcg-target.c.inc | 3 ---
13
tcg/arm/tcg-target.c.inc | 1 -
14
tcg/i386/tcg-target.c.inc | 3 ---
15
tcg/mips/tcg-target.c.inc | 2 --
16
tcg/ppc/tcg-target.c.inc | 3 ---
17
tcg/riscv/tcg-target.c.inc | 2 --
18
tcg/s390/tcg-target.c.inc | 2 --
19
tcg/sparc/tcg-target.c.inc | 2 --
20
tcg/tci/tcg-target.c.inc | 2 --
21
13 files changed, 1 insertion(+), 45 deletions(-)
22
23
diff --git a/include/tcg/tcg-opc.h b/include/tcg/tcg-opc.h
24
index XXXXXXX..XXXXXXX 100644
25
--- a/include/tcg/tcg-opc.h
26
+++ b/include/tcg/tcg-opc.h
27
@@ -XXX,XX +XXX,XX @@ DEF(br, 0, 0, 1, TCG_OPF_BB_END)
28
DEF(mb, 0, 0, 1, 0)
29
30
DEF(mov_i32, 1, 1, 0, TCG_OPF_NOT_PRESENT)
31
-DEF(movi_i32, 1, 0, 1, TCG_OPF_NOT_PRESENT)
32
DEF(setcond_i32, 1, 2, 1, 0)
33
DEF(movcond_i32, 1, 4, 1, IMPL(TCG_TARGET_HAS_movcond_i32))
34
/* load/store */
35
@@ -XXX,XX +XXX,XX @@ DEF(ctz_i32, 1, 2, 0, IMPL(TCG_TARGET_HAS_ctz_i32))
36
DEF(ctpop_i32, 1, 1, 0, IMPL(TCG_TARGET_HAS_ctpop_i32))
37
38
DEF(mov_i64, 1, 1, 0, TCG_OPF_64BIT | TCG_OPF_NOT_PRESENT)
39
-DEF(movi_i64, 1, 0, 1, TCG_OPF_64BIT | TCG_OPF_NOT_PRESENT)
40
DEF(setcond_i64, 1, 2, 1, IMPL64)
41
DEF(movcond_i64, 1, 4, 1, IMPL64 | IMPL(TCG_TARGET_HAS_movcond_i64))
42
/* load/store */
43
@@ -XXX,XX +XXX,XX @@ DEF(qemu_st8_i32, 0, TLADDR_ARGS + 1, 1,
44
#define IMPLVEC TCG_OPF_VECTOR | IMPL(TCG_TARGET_MAYBE_vec)
45
46
DEF(mov_vec, 1, 1, 0, TCG_OPF_VECTOR | TCG_OPF_NOT_PRESENT)
47
-DEF(dupi_vec, 1, 0, 1, TCG_OPF_VECTOR | TCG_OPF_NOT_PRESENT)
48
49
DEF(dup_vec, 1, 1, 0, IMPLVEC)
50
DEF(dup2_vec, 1, 2, 0, IMPLVEC | IMPL(TCG_TARGET_REG_BITS == 32))
51
diff --git a/tcg/optimize.c b/tcg/optimize.c
52
index XXXXXXX..XXXXXXX 100644
53
--- a/tcg/optimize.c
54
+++ b/tcg/optimize.c
55
@@ -XXX,XX +XXX,XX @@ void tcg_optimize(TCGContext *s)
56
CASE_OP_32_64_VEC(mov):
57
tcg_opt_gen_mov(s, op, op->args[0], op->args[1]);
58
break;
59
- CASE_OP_32_64(movi):
60
- case INDEX_op_dupi_vec:
61
- tcg_opt_gen_movi(s, &temps_used, op, op->args[0], op->args[1]);
62
- break;
63
64
case INDEX_op_dup_vec:
65
if (arg_is_const(op->args[1])) {
66
diff --git a/tcg/tcg-op-vec.c b/tcg/tcg-op-vec.c
67
index XXXXXXX..XXXXXXX 100644
68
--- a/tcg/tcg-op-vec.c
69
+++ b/tcg/tcg-op-vec.c
70
@@ -XXX,XX +XXX,XX @@ bool tcg_can_emit_vecop_list(const TCGOpcode *list,
71
case INDEX_op_xor_vec:
72
case INDEX_op_mov_vec:
73
case INDEX_op_dup_vec:
74
- case INDEX_op_dupi_vec:
75
case INDEX_op_dup2_vec:
76
case INDEX_op_ld_vec:
77
case INDEX_op_st_vec:
78
diff --git a/tcg/tcg.c b/tcg/tcg.c
79
index XXXXXXX..XXXXXXX 100644
80
--- a/tcg/tcg.c
81
+++ b/tcg/tcg.c
82
@@ -XXX,XX +XXX,XX @@ bool tcg_op_supported(TCGOpcode op)
83
return TCG_TARGET_HAS_goto_ptr;
84
85
case INDEX_op_mov_i32:
86
- case INDEX_op_movi_i32:
87
case INDEX_op_setcond_i32:
88
case INDEX_op_brcond_i32:
89
case INDEX_op_ld8u_i32:
90
@@ -XXX,XX +XXX,XX @@ bool tcg_op_supported(TCGOpcode op)
91
return TCG_TARGET_REG_BITS == 32;
92
93
case INDEX_op_mov_i64:
94
- case INDEX_op_movi_i64:
95
case INDEX_op_setcond_i64:
96
case INDEX_op_brcond_i64:
97
case INDEX_op_ld8u_i64:
98
@@ -XXX,XX +XXX,XX @@ bool tcg_op_supported(TCGOpcode op)
99
100
case INDEX_op_mov_vec:
101
case INDEX_op_dup_vec:
102
- case INDEX_op_dupi_vec:
103
case INDEX_op_dupm_vec:
104
case INDEX_op_ld_vec:
105
case INDEX_op_st_vec:
106
@@ -XXX,XX +XXX,XX @@ static void tcg_reg_alloc_cbranch(TCGContext *s, TCGRegSet allocated_regs)
107
}
108
109
/*
110
- * Specialized code generation for INDEX_op_movi_*.
111
+ * Specialized code generation for INDEX_op_mov_* with a constant.
112
*/
113
static void tcg_reg_alloc_do_movi(TCGContext *s, TCGTemp *ots,
114
tcg_target_ulong val, TCGLifeData arg_life,
115
@@ -XXX,XX +XXX,XX @@ static void tcg_reg_alloc_do_movi(TCGContext *s, TCGTemp *ots,
116
}
117
}
118
119
-static void tcg_reg_alloc_movi(TCGContext *s, const TCGOp *op)
120
-{
121
- TCGTemp *ots = arg_temp(op->args[0]);
122
- tcg_target_ulong val = op->args[1];
123
-
124
- tcg_reg_alloc_do_movi(s, ots, val, op->life, op->output_pref[0]);
125
-}
126
-
127
/*
128
* Specialized code generation for INDEX_op_mov_*.
129
*/
130
@@ -XXX,XX +XXX,XX @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb)
131
case INDEX_op_mov_vec:
132
tcg_reg_alloc_mov(s, op);
133
break;
134
- case INDEX_op_movi_i32:
135
- case INDEX_op_movi_i64:
136
- case INDEX_op_dupi_vec:
137
- tcg_reg_alloc_movi(s, op);
138
- break;
139
case INDEX_op_dup_vec:
140
tcg_reg_alloc_dup(s, op);
141
break;
142
diff --git a/tcg/aarch64/tcg-target.c.inc b/tcg/aarch64/tcg-target.c.inc
143
index XXXXXXX..XXXXXXX 100644
144
--- a/tcg/aarch64/tcg-target.c.inc
145
+++ b/tcg/aarch64/tcg-target.c.inc
146
@@ -XXX,XX +XXX,XX @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc,
147
148
case INDEX_op_mov_i32: /* Always emitted via tcg_out_mov. */
149
case INDEX_op_mov_i64:
150
- case INDEX_op_movi_i32: /* Always emitted via tcg_out_movi. */
151
- case INDEX_op_movi_i64:
152
case INDEX_op_call: /* Always emitted via tcg_out_call. */
153
default:
154
g_assert_not_reached();
155
@@ -XXX,XX +XXX,XX @@ static void tcg_out_vec_op(TCGContext *s, TCGOpcode opc,
156
break;
157
158
case INDEX_op_mov_vec: /* Always emitted via tcg_out_mov. */
159
- case INDEX_op_dupi_vec: /* Always emitted via tcg_out_movi. */
160
case INDEX_op_dup_vec: /* Always emitted via tcg_out_dup_vec. */
161
default:
162
g_assert_not_reached();
163
diff --git a/tcg/arm/tcg-target.c.inc b/tcg/arm/tcg-target.c.inc
164
index XXXXXXX..XXXXXXX 100644
165
--- a/tcg/arm/tcg-target.c.inc
166
+++ b/tcg/arm/tcg-target.c.inc
167
@@ -XXX,XX +XXX,XX @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc,
168
break;
169
170
case INDEX_op_mov_i32: /* Always emitted via tcg_out_mov. */
171
- case INDEX_op_movi_i32: /* Always emitted via tcg_out_movi. */
172
case INDEX_op_call: /* Always emitted via tcg_out_call. */
173
default:
174
tcg_abort();
175
diff --git a/tcg/i386/tcg-target.c.inc b/tcg/i386/tcg-target.c.inc
176
index XXXXXXX..XXXXXXX 100644
177
--- a/tcg/i386/tcg-target.c.inc
178
+++ b/tcg/i386/tcg-target.c.inc
179
@@ -XXX,XX +XXX,XX @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc,
180
break;
181
case INDEX_op_mov_i32: /* Always emitted via tcg_out_mov. */
182
case INDEX_op_mov_i64:
183
- case INDEX_op_movi_i32: /* Always emitted via tcg_out_movi. */
184
- case INDEX_op_movi_i64:
185
case INDEX_op_call: /* Always emitted via tcg_out_call. */
186
default:
187
tcg_abort();
188
@@ -XXX,XX +XXX,XX @@ static void tcg_out_vec_op(TCGContext *s, TCGOpcode opc,
189
break;
190
191
case INDEX_op_mov_vec: /* Always emitted via tcg_out_mov. */
192
- case INDEX_op_dupi_vec: /* Always emitted via tcg_out_movi. */
193
case INDEX_op_dup_vec: /* Always emitted via tcg_out_dup_vec. */
194
default:
195
g_assert_not_reached();
196
diff --git a/tcg/mips/tcg-target.c.inc b/tcg/mips/tcg-target.c.inc
197
index XXXXXXX..XXXXXXX 100644
198
--- a/tcg/mips/tcg-target.c.inc
199
+++ b/tcg/mips/tcg-target.c.inc
200
@@ -XXX,XX +XXX,XX @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc,
201
break;
202
case INDEX_op_mov_i32: /* Always emitted via tcg_out_mov. */
203
case INDEX_op_mov_i64:
204
- case INDEX_op_movi_i32: /* Always emitted via tcg_out_movi. */
205
- case INDEX_op_movi_i64:
206
case INDEX_op_call: /* Always emitted via tcg_out_call. */
207
default:
208
tcg_abort();
209
diff --git a/tcg/ppc/tcg-target.c.inc b/tcg/ppc/tcg-target.c.inc
210
index XXXXXXX..XXXXXXX 100644
211
--- a/tcg/ppc/tcg-target.c.inc
212
+++ b/tcg/ppc/tcg-target.c.inc
213
@@ -XXX,XX +XXX,XX @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg *args,
214
215
case INDEX_op_mov_i32: /* Always emitted via tcg_out_mov. */
216
case INDEX_op_mov_i64:
217
- case INDEX_op_movi_i32: /* Always emitted via tcg_out_movi. */
218
- case INDEX_op_movi_i64:
219
case INDEX_op_call: /* Always emitted via tcg_out_call. */
220
default:
221
tcg_abort();
222
@@ -XXX,XX +XXX,XX @@ static void tcg_out_vec_op(TCGContext *s, TCGOpcode opc,
223
return;
224
225
case INDEX_op_mov_vec: /* Always emitted via tcg_out_mov. */
226
- case INDEX_op_dupi_vec: /* Always emitted via tcg_out_movi. */
227
case INDEX_op_dup_vec: /* Always emitted via tcg_out_dup_vec. */
228
default:
229
g_assert_not_reached();
230
diff --git a/tcg/riscv/tcg-target.c.inc b/tcg/riscv/tcg-target.c.inc
231
index XXXXXXX..XXXXXXX 100644
232
--- a/tcg/riscv/tcg-target.c.inc
233
+++ b/tcg/riscv/tcg-target.c.inc
234
@@ -XXX,XX +XXX,XX @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc,
235
236
case INDEX_op_mov_i32: /* Always emitted via tcg_out_mov. */
237
case INDEX_op_mov_i64:
238
- case INDEX_op_movi_i32: /* Always emitted via tcg_out_movi. */
239
- case INDEX_op_movi_i64:
240
case INDEX_op_call: /* Always emitted via tcg_out_call. */
241
default:
242
g_assert_not_reached();
243
diff --git a/tcg/s390/tcg-target.c.inc b/tcg/s390/tcg-target.c.inc
244
index XXXXXXX..XXXXXXX 100644
245
--- a/tcg/s390/tcg-target.c.inc
246
+++ b/tcg/s390/tcg-target.c.inc
247
@@ -XXX,XX +XXX,XX @@ static inline void tcg_out_op(TCGContext *s, TCGOpcode opc,
248
249
case INDEX_op_mov_i32: /* Always emitted via tcg_out_mov. */
250
case INDEX_op_mov_i64:
251
- case INDEX_op_movi_i32: /* Always emitted via tcg_out_movi. */
252
- case INDEX_op_movi_i64:
253
case INDEX_op_call: /* Always emitted via tcg_out_call. */
254
default:
255
tcg_abort();
256
diff --git a/tcg/sparc/tcg-target.c.inc b/tcg/sparc/tcg-target.c.inc
257
index XXXXXXX..XXXXXXX 100644
258
--- a/tcg/sparc/tcg-target.c.inc
259
+++ b/tcg/sparc/tcg-target.c.inc
260
@@ -XXX,XX +XXX,XX @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc,
261
262
case INDEX_op_mov_i32: /* Always emitted via tcg_out_mov. */
263
case INDEX_op_mov_i64:
264
- case INDEX_op_movi_i32: /* Always emitted via tcg_out_movi. */
265
- case INDEX_op_movi_i64:
266
case INDEX_op_call: /* Always emitted via tcg_out_call. */
267
default:
268
tcg_abort();
269
diff --git a/tcg/tci/tcg-target.c.inc b/tcg/tci/tcg-target.c.inc
270
index XXXXXXX..XXXXXXX 100644
271
--- a/tcg/tci/tcg-target.c.inc
272
+++ b/tcg/tci/tcg-target.c.inc
273
@@ -XXX,XX +XXX,XX @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, const TCGArg *args,
274
break;
275
case INDEX_op_mov_i32: /* Always emitted via tcg_out_mov. */
276
case INDEX_op_mov_i64:
277
- case INDEX_op_movi_i32: /* Always emitted via tcg_out_movi. */
278
- case INDEX_op_movi_i64:
279
case INDEX_op_call: /* Always emitted via tcg_out_call. */
280
default:
281
tcg_abort();
282
--
283
2.25.1
284
285
diff view generated by jsdifflib
1
From: Claudio Fontana <cfontana@suse.de>
1
There are several ways we can expand a vector dup of a 64-bit
2
element on a 32-bit host.
2
3
3
split up the CpusAccel tcg_cpus into three TCG variants:
4
5
tcg_cpus_rr (single threaded, round robin cpus)
6
tcg_cpus_icount (same as rr, but with instruction counting enabled)
7
tcg_cpus_mttcg (multi-threaded cpus)
8
9
Suggested-by: Richard Henderson <richard.henderson@linaro.org>
10
Signed-off-by: Claudio Fontana <cfontana@suse.de>
11
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
12
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
13
Message-Id: <20201015143217.29337-2-cfontana@suse.de>
14
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
4
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
15
---
5
---
16
accel/tcg/tcg-cpus-icount.h | 17 ++
6
tcg/tcg.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
17
accel/tcg/tcg-cpus-mttcg.h | 21 ++
7
1 file changed, 97 insertions(+)
18
accel/tcg/tcg-cpus-rr.h | 20 ++
19
accel/tcg/tcg-cpus.h | 13 +-
20
accel/tcg/tcg-all.c | 8 +-
21
accel/tcg/tcg-cpus-icount.c | 147 +++++++++++
22
accel/tcg/tcg-cpus-mttcg.c | 117 +++++++++
23
accel/tcg/tcg-cpus-rr.c | 270 ++++++++++++++++++++
24
accel/tcg/tcg-cpus.c | 484 ++----------------------------------
25
softmmu/icount.c | 2 +-
26
accel/tcg/meson.build | 9 +-
27
11 files changed, 646 insertions(+), 462 deletions(-)
28
create mode 100644 accel/tcg/tcg-cpus-icount.h
29
create mode 100644 accel/tcg/tcg-cpus-mttcg.h
30
create mode 100644 accel/tcg/tcg-cpus-rr.h
31
create mode 100644 accel/tcg/tcg-cpus-icount.c
32
create mode 100644 accel/tcg/tcg-cpus-mttcg.c
33
create mode 100644 accel/tcg/tcg-cpus-rr.c
34
8
35
diff --git a/accel/tcg/tcg-cpus-icount.h b/accel/tcg/tcg-cpus-icount.h
9
diff --git a/tcg/tcg.c b/tcg/tcg.c
36
new file mode 100644
10
index XXXXXXX..XXXXXXX 100644
37
index XXXXXXX..XXXXXXX
11
--- a/tcg/tcg.c
38
--- /dev/null
12
+++ b/tcg/tcg.c
39
+++ b/accel/tcg/tcg-cpus-icount.h
13
@@ -XXX,XX +XXX,XX @@ static void tcg_reg_alloc_op(TCGContext *s, const TCGOp *op)
40
@@ -XXX,XX +XXX,XX @@
14
}
41
+/*
15
}
42
+ * QEMU TCG Single Threaded vCPUs implementation using instruction counting
16
43
+ *
17
+static bool tcg_reg_alloc_dup2(TCGContext *s, const TCGOp *op)
44
+ * Copyright 2020 SUSE LLC
18
+{
45
+ *
19
+ const TCGLifeData arg_life = op->life;
46
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
20
+ TCGTemp *ots, *itsl, *itsh;
47
+ * See the COPYING file in the top-level directory.
21
+ TCGType vtype = TCGOP_VECL(op) + TCG_TYPE_V64;
48
+ */
49
+
22
+
50
+#ifndef TCG_CPUS_ICOUNT_H
23
+ /* This opcode is only valid for 32-bit hosts, for 64-bit elements. */
51
+#define TCG_CPUS_ICOUNT_H
24
+ tcg_debug_assert(TCG_TARGET_REG_BITS == 32);
25
+ tcg_debug_assert(TCGOP_VECE(op) == MO_64);
52
+
26
+
53
+void handle_icount_deadline(void);
27
+ ots = arg_temp(op->args[0]);
54
+void prepare_icount_for_run(CPUState *cpu);
28
+ itsl = arg_temp(op->args[1]);
55
+void process_icount_data(CPUState *cpu);
29
+ itsh = arg_temp(op->args[2]);
56
+
30
+
57
+#endif /* TCG_CPUS_ICOUNT_H */
31
+ /* ENV should not be modified. */
58
diff --git a/accel/tcg/tcg-cpus-mttcg.h b/accel/tcg/tcg-cpus-mttcg.h
32
+ tcg_debug_assert(!temp_readonly(ots));
59
new file mode 100644
60
index XXXXXXX..XXXXXXX
61
--- /dev/null
62
+++ b/accel/tcg/tcg-cpus-mttcg.h
63
@@ -XXX,XX +XXX,XX @@
64
+/*
65
+ * QEMU TCG Multi Threaded vCPUs implementation
66
+ *
67
+ * Copyright 2020 SUSE LLC
68
+ *
69
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
70
+ * See the COPYING file in the top-level directory.
71
+ */
72
+
33
+
73
+#ifndef TCG_CPUS_MTTCG_H
34
+ /* Allocate the output register now. */
74
+#define TCG_CPUS_MTTCG_H
35
+ if (ots->val_type != TEMP_VAL_REG) {
36
+ TCGRegSet allocated_regs = s->reserved_regs;
37
+ TCGRegSet dup_out_regs =
38
+ tcg_op_defs[INDEX_op_dup_vec].args_ct[0].regs;
75
+
39
+
76
+/*
40
+ /* Make sure to not spill the input registers. */
77
+ * In the multi-threaded case each vCPU has its own thread. The TLS
41
+ if (!IS_DEAD_ARG(1) && itsl->val_type == TEMP_VAL_REG) {
78
+ * variable current_cpu can be used deep in the code to find the
42
+ tcg_regset_set_reg(allocated_regs, itsl->reg);
79
+ * current CPUState for a given thread.
43
+ }
80
+ */
44
+ if (!IS_DEAD_ARG(2) && itsh->val_type == TEMP_VAL_REG) {
81
+
45
+ tcg_regset_set_reg(allocated_regs, itsh->reg);
82
+void *tcg_cpu_thread_fn(void *arg);
83
+
84
+#endif /* TCG_CPUS_MTTCG_H */
85
diff --git a/accel/tcg/tcg-cpus-rr.h b/accel/tcg/tcg-cpus-rr.h
86
new file mode 100644
87
index XXXXXXX..XXXXXXX
88
--- /dev/null
89
+++ b/accel/tcg/tcg-cpus-rr.h
90
@@ -XXX,XX +XXX,XX @@
91
+/*
92
+ * QEMU TCG Single Threaded vCPUs implementation
93
+ *
94
+ * Copyright 2020 SUSE LLC
95
+ *
96
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
97
+ * See the COPYING file in the top-level directory.
98
+ */
99
+
100
+#ifndef TCG_CPUS_RR_H
101
+#define TCG_CPUS_RR_H
102
+
103
+#define TCG_KICK_PERIOD (NANOSECONDS_PER_SECOND / 10)
104
+
105
+/* Kick all RR vCPUs. */
106
+void qemu_cpu_kick_rr_cpus(CPUState *unused);
107
+
108
+void *tcg_rr_cpu_thread_fn(void *arg);
109
+
110
+#endif /* TCG_CPUS_RR_H */
111
diff --git a/accel/tcg/tcg-cpus.h b/accel/tcg/tcg-cpus.h
112
index XXXXXXX..XXXXXXX 100644
113
--- a/accel/tcg/tcg-cpus.h
114
+++ b/accel/tcg/tcg-cpus.h
115
@@ -XXX,XX +XXX,XX @@
116
/*
117
- * Accelerator CPUS Interface
118
+ * QEMU TCG vCPU common functionality
119
+ *
120
+ * Functionality common to all TCG vcpu variants: mttcg, rr and icount.
121
*
122
* Copyright 2020 SUSE LLC
123
*
124
@@ -XXX,XX +XXX,XX @@
125
126
#include "sysemu/cpus.h"
127
128
-extern const CpusAccel tcg_cpus;
129
+extern const CpusAccel tcg_cpus_mttcg;
130
+extern const CpusAccel tcg_cpus_icount;
131
+extern const CpusAccel tcg_cpus_rr;
132
+
133
+void tcg_start_vcpu_thread(CPUState *cpu);
134
+void qemu_tcg_destroy_vcpu(CPUState *cpu);
135
+int tcg_cpu_exec(CPUState *cpu);
136
+void tcg_handle_interrupt(CPUState *cpu, int mask);
137
138
#endif /* TCG_CPUS_H */
139
diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c
140
index XXXXXXX..XXXXXXX 100644
141
--- a/accel/tcg/tcg-all.c
142
+++ b/accel/tcg/tcg-all.c
143
@@ -XXX,XX +XXX,XX @@ static int tcg_init(MachineState *ms)
144
145
tcg_exec_init(s->tb_size * 1024 * 1024);
146
mttcg_enabled = s->mttcg_enabled;
147
- cpus_register_accel(&tcg_cpus);
148
149
+ if (mttcg_enabled) {
150
+ cpus_register_accel(&tcg_cpus_mttcg);
151
+ } else if (icount_enabled()) {
152
+ cpus_register_accel(&tcg_cpus_icount);
153
+ } else {
154
+ cpus_register_accel(&tcg_cpus_rr);
155
+ }
156
return 0;
157
}
158
159
diff --git a/accel/tcg/tcg-cpus-icount.c b/accel/tcg/tcg-cpus-icount.c
160
new file mode 100644
161
index XXXXXXX..XXXXXXX
162
--- /dev/null
163
+++ b/accel/tcg/tcg-cpus-icount.c
164
@@ -XXX,XX +XXX,XX @@
165
+/*
166
+ * QEMU TCG Single Threaded vCPUs implementation using instruction counting
167
+ *
168
+ * Copyright (c) 2003-2008 Fabrice Bellard
169
+ * Copyright (c) 2014 Red Hat Inc.
170
+ *
171
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
172
+ * of this software and associated documentation files (the "Software"), to deal
173
+ * in the Software without restriction, including without limitation the rights
174
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
175
+ * copies of the Software, and to permit persons to whom the Software is
176
+ * furnished to do so, subject to the following conditions:
177
+ *
178
+ * The above copyright notice and this permission notice shall be included in
179
+ * all copies or substantial portions of the Software.
180
+ *
181
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
182
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
183
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
184
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
185
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
186
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
187
+ * THE SOFTWARE.
188
+ */
189
+
190
+#include "qemu/osdep.h"
191
+#include "qemu-common.h"
192
+#include "sysemu/tcg.h"
193
+#include "sysemu/replay.h"
194
+#include "qemu/main-loop.h"
195
+#include "qemu/guest-random.h"
196
+#include "exec/exec-all.h"
197
+#include "hw/boards.h"
198
+
199
+#include "tcg-cpus.h"
200
+#include "tcg-cpus-icount.h"
201
+#include "tcg-cpus-rr.h"
202
+
203
+static int64_t tcg_get_icount_limit(void)
204
+{
205
+ int64_t deadline;
206
+
207
+ if (replay_mode != REPLAY_MODE_PLAY) {
208
+ /*
209
+ * Include all the timers, because they may need an attention.
210
+ * Too long CPU execution may create unnecessary delay in UI.
211
+ */
212
+ deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL,
213
+ QEMU_TIMER_ATTR_ALL);
214
+ /* Check realtime timers, because they help with input processing */
215
+ deadline = qemu_soonest_timeout(deadline,
216
+ qemu_clock_deadline_ns_all(QEMU_CLOCK_REALTIME,
217
+ QEMU_TIMER_ATTR_ALL));
218
+
219
+ /*
220
+ * Maintain prior (possibly buggy) behaviour where if no deadline
221
+ * was set (as there is no QEMU_CLOCK_VIRTUAL timer) or it is more than
222
+ * INT32_MAX nanoseconds ahead, we still use INT32_MAX
223
+ * nanoseconds.
224
+ */
225
+ if ((deadline < 0) || (deadline > INT32_MAX)) {
226
+ deadline = INT32_MAX;
227
+ }
46
+ }
228
+
47
+
229
+ return icount_round(deadline);
48
+ ots->reg = tcg_reg_alloc(s, dup_out_regs, allocated_regs,
230
+ } else {
49
+ op->output_pref[0], ots->indirect_base);
231
+ return replay_get_instructions();
50
+ ots->val_type = TEMP_VAL_REG;
51
+ ots->mem_coherent = 0;
52
+ s->reg_to_temp[ots->reg] = ots;
232
+ }
53
+ }
233
+}
234
+
54
+
235
+static void notify_aio_contexts(void)
55
+ /* Promote dup2 of immediates to dupi_vec. */
236
+{
56
+ if (itsl->val_type == TEMP_VAL_CONST && itsh->val_type == TEMP_VAL_CONST) {
237
+ /* Wake up other AioContexts. */
57
+ uint64_t val = deposit64(itsl->val, 32, 32, itsh->val);
238
+ qemu_clock_notify(QEMU_CLOCK_VIRTUAL);
58
+ MemOp vece = MO_64;
239
+ qemu_clock_run_timers(QEMU_CLOCK_VIRTUAL);
240
+}
241
+
59
+
242
+void handle_icount_deadline(void)
60
+ if (val == dup_const(MO_8, val)) {
243
+{
61
+ vece = MO_8;
244
+ assert(qemu_in_vcpu_thread());
62
+ } else if (val == dup_const(MO_16, val)) {
245
+ int64_t deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL,
63
+ vece = MO_16;
246
+ QEMU_TIMER_ATTR_ALL);
64
+ } else if (val == dup_const(MO_32, val)) {
247
+
65
+ vece = MO_32;
248
+ if (deadline == 0) {
249
+ notify_aio_contexts();
250
+ }
251
+}
252
+
253
+void prepare_icount_for_run(CPUState *cpu)
254
+{
255
+ int insns_left;
256
+
257
+ /*
258
+ * These should always be cleared by process_icount_data after
259
+ * each vCPU execution. However u16.high can be raised
260
+ * asynchronously by cpu_exit/cpu_interrupt/tcg_handle_interrupt
261
+ */
262
+ g_assert(cpu_neg(cpu)->icount_decr.u16.low == 0);
263
+ g_assert(cpu->icount_extra == 0);
264
+
265
+ cpu->icount_budget = tcg_get_icount_limit();
266
+ insns_left = MIN(0xffff, cpu->icount_budget);
267
+ cpu_neg(cpu)->icount_decr.u16.low = insns_left;
268
+ cpu->icount_extra = cpu->icount_budget - insns_left;
269
+
270
+ replay_mutex_lock();
271
+
272
+ if (cpu->icount_budget == 0 && replay_has_checkpoint()) {
273
+ notify_aio_contexts();
274
+ }
275
+}
276
+
277
+void process_icount_data(CPUState *cpu)
278
+{
279
+ /* Account for executed instructions */
280
+ icount_update(cpu);
281
+
282
+ /* Reset the counters */
283
+ cpu_neg(cpu)->icount_decr.u16.low = 0;
284
+ cpu->icount_extra = 0;
285
+ cpu->icount_budget = 0;
286
+
287
+ replay_account_executed_instructions();
288
+
289
+ replay_mutex_unlock();
290
+}
291
+
292
+static void icount_handle_interrupt(CPUState *cpu, int mask)
293
+{
294
+ int old_mask = cpu->interrupt_request;
295
+
296
+ tcg_handle_interrupt(cpu, mask);
297
+ if (qemu_cpu_is_self(cpu) &&
298
+ !cpu->can_do_io
299
+ && (mask & ~old_mask) != 0) {
300
+ cpu_abort(cpu, "Raised interrupt while not in I/O function");
301
+ }
302
+}
303
+
304
+const CpusAccel tcg_cpus_icount = {
305
+ .create_vcpu_thread = tcg_start_vcpu_thread,
306
+ .kick_vcpu_thread = qemu_cpu_kick_rr_cpus,
307
+
308
+ .handle_interrupt = icount_handle_interrupt,
309
+ .get_virtual_clock = icount_get,
310
+ .get_elapsed_ticks = icount_get,
311
+};
312
diff --git a/accel/tcg/tcg-cpus-mttcg.c b/accel/tcg/tcg-cpus-mttcg.c
313
new file mode 100644
314
index XXXXXXX..XXXXXXX
315
--- /dev/null
316
+++ b/accel/tcg/tcg-cpus-mttcg.c
317
@@ -XXX,XX +XXX,XX @@
318
+/*
319
+ * QEMU TCG Multi Threaded vCPUs implementation
320
+ *
321
+ * Copyright (c) 2003-2008 Fabrice Bellard
322
+ * Copyright (c) 2014 Red Hat Inc.
323
+ *
324
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
325
+ * of this software and associated documentation files (the "Software"), to deal
326
+ * in the Software without restriction, including without limitation the rights
327
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
328
+ * copies of the Software, and to permit persons to whom the Software is
329
+ * furnished to do so, subject to the following conditions:
330
+ *
331
+ * The above copyright notice and this permission notice shall be included in
332
+ * all copies or substantial portions of the Software.
333
+ *
334
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
335
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
336
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
337
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
338
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
339
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
340
+ * THE SOFTWARE.
341
+ */
342
+
343
+#include "qemu/osdep.h"
344
+#include "qemu-common.h"
345
+#include "sysemu/tcg.h"
346
+#include "sysemu/replay.h"
347
+#include "qemu/main-loop.h"
348
+#include "qemu/guest-random.h"
349
+#include "exec/exec-all.h"
350
+#include "hw/boards.h"
351
+
352
+#include "tcg-cpus.h"
353
+#include "tcg-cpus-mttcg.h"
354
+
355
+/*
356
+ * In the multi-threaded case each vCPU has its own thread. The TLS
357
+ * variable current_cpu can be used deep in the code to find the
358
+ * current CPUState for a given thread.
359
+ */
360
+
361
+void *tcg_cpu_thread_fn(void *arg)
362
+{
363
+ CPUState *cpu = arg;
364
+
365
+ assert(tcg_enabled());
366
+ g_assert(!icount_enabled());
367
+
368
+ rcu_register_thread();
369
+ tcg_register_thread();
370
+
371
+ qemu_mutex_lock_iothread();
372
+ qemu_thread_get_self(cpu->thread);
373
+
374
+ cpu->thread_id = qemu_get_thread_id();
375
+ cpu->can_do_io = 1;
376
+ current_cpu = cpu;
377
+ cpu_thread_signal_created(cpu);
378
+ qemu_guest_random_seed_thread_part2(cpu->random_seed);
379
+
380
+ /* process any pending work */
381
+ cpu->exit_request = 1;
382
+
383
+ do {
384
+ if (cpu_can_run(cpu)) {
385
+ int r;
386
+ qemu_mutex_unlock_iothread();
387
+ r = tcg_cpu_exec(cpu);
388
+ qemu_mutex_lock_iothread();
389
+ switch (r) {
390
+ case EXCP_DEBUG:
391
+ cpu_handle_guest_debug(cpu);
392
+ break;
393
+ case EXCP_HALTED:
394
+ /*
395
+ * during start-up the vCPU is reset and the thread is
396
+ * kicked several times. If we don't ensure we go back
397
+ * to sleep in the halted state we won't cleanly
398
+ * start-up when the vCPU is enabled.
399
+ *
400
+ * cpu->halted should ensure we sleep in wait_io_event
401
+ */
402
+ g_assert(cpu->halted);
403
+ break;
404
+ case EXCP_ATOMIC:
405
+ qemu_mutex_unlock_iothread();
406
+ cpu_exec_step_atomic(cpu);
407
+ qemu_mutex_lock_iothread();
408
+ default:
409
+ /* Ignore everything else? */
410
+ break;
411
+ }
412
+ }
66
+ }
413
+
67
+
414
+ qatomic_mb_set(&cpu->exit_request, 0);
68
+ tcg_out_dupi_vec(s, vtype, vece, ots->reg, val);
415
+ qemu_wait_io_event(cpu);
69
+ goto done;
416
+ } while (!cpu->unplug || cpu_can_run(cpu));
417
+
418
+ qemu_tcg_destroy_vcpu(cpu);
419
+ qemu_mutex_unlock_iothread();
420
+ rcu_unregister_thread();
421
+ return NULL;
422
+}
423
+
424
+static void mttcg_kick_vcpu_thread(CPUState *cpu)
425
+{
426
+ cpu_exit(cpu);
427
+}
428
+
429
+const CpusAccel tcg_cpus_mttcg = {
430
+ .create_vcpu_thread = tcg_start_vcpu_thread,
431
+ .kick_vcpu_thread = mttcg_kick_vcpu_thread,
432
+
433
+ .handle_interrupt = tcg_handle_interrupt,
434
+};
435
diff --git a/accel/tcg/tcg-cpus-rr.c b/accel/tcg/tcg-cpus-rr.c
436
new file mode 100644
437
index XXXXXXX..XXXXXXX
438
--- /dev/null
439
+++ b/accel/tcg/tcg-cpus-rr.c
440
@@ -XXX,XX +XXX,XX @@
441
+/*
442
+ * QEMU TCG Single Threaded vCPUs implementation
443
+ *
444
+ * Copyright (c) 2003-2008 Fabrice Bellard
445
+ * Copyright (c) 2014 Red Hat Inc.
446
+ *
447
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
448
+ * of this software and associated documentation files (the "Software"), to deal
449
+ * in the Software without restriction, including without limitation the rights
450
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
451
+ * copies of the Software, and to permit persons to whom the Software is
452
+ * furnished to do so, subject to the following conditions:
453
+ *
454
+ * The above copyright notice and this permission notice shall be included in
455
+ * all copies or substantial portions of the Software.
456
+ *
457
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
458
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
459
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
460
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
461
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
462
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
463
+ * THE SOFTWARE.
464
+ */
465
+
466
+#include "qemu/osdep.h"
467
+#include "qemu-common.h"
468
+#include "sysemu/tcg.h"
469
+#include "sysemu/replay.h"
470
+#include "qemu/main-loop.h"
471
+#include "qemu/guest-random.h"
472
+#include "exec/exec-all.h"
473
+#include "hw/boards.h"
474
+
475
+#include "tcg-cpus.h"
476
+#include "tcg-cpus-rr.h"
477
+#include "tcg-cpus-icount.h"
478
+
479
+/* Kick all RR vCPUs */
480
+void qemu_cpu_kick_rr_cpus(CPUState *unused)
481
+{
482
+ CPUState *cpu;
483
+
484
+ CPU_FOREACH(cpu) {
485
+ cpu_exit(cpu);
486
+ };
487
+}
488
+
489
+/*
490
+ * TCG vCPU kick timer
491
+ *
492
+ * The kick timer is responsible for moving single threaded vCPU
493
+ * emulation on to the next vCPU. If more than one vCPU is running a
494
+ * timer event with force a cpu->exit so the next vCPU can get
495
+ * scheduled.
496
+ *
497
+ * The timer is removed if all vCPUs are idle and restarted again once
498
+ * idleness is complete.
499
+ */
500
+
501
+static QEMUTimer *tcg_kick_vcpu_timer;
502
+static CPUState *tcg_current_rr_cpu;
503
+
504
+#define TCG_KICK_PERIOD (NANOSECONDS_PER_SECOND / 10)
505
+
506
+static inline int64_t qemu_tcg_next_kick(void)
507
+{
508
+ return qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + TCG_KICK_PERIOD;
509
+}
510
+
511
+/* Kick the currently round-robin scheduled vCPU to next */
512
+static void qemu_cpu_kick_rr_next_cpu(void)
513
+{
514
+ CPUState *cpu;
515
+ do {
516
+ cpu = qatomic_mb_read(&tcg_current_rr_cpu);
517
+ if (cpu) {
518
+ cpu_exit(cpu);
519
+ }
520
+ } while (cpu != qatomic_mb_read(&tcg_current_rr_cpu));
521
+}
522
+
523
+static void kick_tcg_thread(void *opaque)
524
+{
525
+ timer_mod(tcg_kick_vcpu_timer, qemu_tcg_next_kick());
526
+ qemu_cpu_kick_rr_next_cpu();
527
+}
528
+
529
+static void start_tcg_kick_timer(void)
530
+{
531
+ if (!tcg_kick_vcpu_timer && CPU_NEXT(first_cpu)) {
532
+ tcg_kick_vcpu_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
533
+ kick_tcg_thread, NULL);
534
+ }
535
+ if (tcg_kick_vcpu_timer && !timer_pending(tcg_kick_vcpu_timer)) {
536
+ timer_mod(tcg_kick_vcpu_timer, qemu_tcg_next_kick());
537
+ }
538
+}
539
+
540
+static void stop_tcg_kick_timer(void)
541
+{
542
+ if (tcg_kick_vcpu_timer && timer_pending(tcg_kick_vcpu_timer)) {
543
+ timer_del(tcg_kick_vcpu_timer);
544
+ }
545
+}
546
+
547
+static void qemu_tcg_rr_wait_io_event(void)
548
+{
549
+ CPUState *cpu;
550
+
551
+ while (all_cpu_threads_idle()) {
552
+ stop_tcg_kick_timer();
553
+ qemu_cond_wait_iothread(first_cpu->halt_cond);
554
+ }
70
+ }
555
+
71
+
556
+ start_tcg_kick_timer();
72
+ /* If the two inputs form one 64-bit value, try dupm_vec. */
557
+
73
+ if (itsl + 1 == itsh && itsl->base_type == TCG_TYPE_I64) {
558
+ CPU_FOREACH(cpu) {
74
+ if (!itsl->mem_coherent) {
559
+ qemu_wait_io_event_common(cpu);
75
+ temp_sync(s, itsl, s->reserved_regs, 0, 0);
560
+ }
561
+}
562
+
563
+/*
564
+ * Destroy any remaining vCPUs which have been unplugged and have
565
+ * finished running
566
+ */
567
+static void deal_with_unplugged_cpus(void)
568
+{
569
+ CPUState *cpu;
570
+
571
+ CPU_FOREACH(cpu) {
572
+ if (cpu->unplug && !cpu_can_run(cpu)) {
573
+ qemu_tcg_destroy_vcpu(cpu);
574
+ break;
575
+ }
76
+ }
576
+ }
77
+ if (!itsh->mem_coherent) {
577
+}
78
+ temp_sync(s, itsh, s->reserved_regs, 0, 0);
578
+
79
+ }
579
+/*
80
+#ifdef HOST_WORDS_BIGENDIAN
580
+ * In the single-threaded case each vCPU is simulated in turn. If
81
+ TCGTemp *its = itsh;
581
+ * there is more than a single vCPU we create a simple timer to kick
82
+#else
582
+ * the vCPU and ensure we don't get stuck in a tight loop in one vCPU.
83
+ TCGTemp *its = itsl;
583
+ * This is done explicitly rather than relying on side-effects
84
+#endif
584
+ * elsewhere.
85
+ if (tcg_out_dupm_vec(s, vtype, MO_64, ots->reg,
585
+ */
86
+ its->mem_base->reg, its->mem_offset)) {
586
+
87
+ goto done;
587
+void *tcg_rr_cpu_thread_fn(void *arg)
588
+{
589
+ CPUState *cpu = arg;
590
+
591
+ assert(tcg_enabled());
592
+ rcu_register_thread();
593
+ tcg_register_thread();
594
+
595
+ qemu_mutex_lock_iothread();
596
+ qemu_thread_get_self(cpu->thread);
597
+
598
+ cpu->thread_id = qemu_get_thread_id();
599
+ cpu->can_do_io = 1;
600
+ cpu_thread_signal_created(cpu);
601
+ qemu_guest_random_seed_thread_part2(cpu->random_seed);
602
+
603
+ /* wait for initial kick-off after machine start */
604
+ while (first_cpu->stopped) {
605
+ qemu_cond_wait_iothread(first_cpu->halt_cond);
606
+
607
+ /* process any pending work */
608
+ CPU_FOREACH(cpu) {
609
+ current_cpu = cpu;
610
+ qemu_wait_io_event_common(cpu);
611
+ }
88
+ }
612
+ }
89
+ }
613
+
90
+
614
+ start_tcg_kick_timer();
91
+ /* Fall back to generic expansion. */
92
+ return false;
615
+
93
+
616
+ cpu = first_cpu;
94
+ done:
95
+ if (IS_DEAD_ARG(1)) {
96
+ temp_dead(s, itsl);
97
+ }
98
+ if (IS_DEAD_ARG(2)) {
99
+ temp_dead(s, itsh);
100
+ }
101
+ if (NEED_SYNC_ARG(0)) {
102
+ temp_sync(s, ots, s->reserved_regs, 0, IS_DEAD_ARG(0));
103
+ } else if (IS_DEAD_ARG(0)) {
104
+ temp_dead(s, ots);
105
+ }
106
+ return true;
107
+}
617
+
108
+
618
+ /* process any pending work */
109
#ifdef TCG_TARGET_STACK_GROWSUP
619
+ cpu->exit_request = 1;
110
#define STACK_DIR(x) (-(x))
620
+
111
#else
621
+ while (1) {
112
@@ -XXX,XX +XXX,XX @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb)
622
+ qemu_mutex_unlock_iothread();
113
case INDEX_op_call:
623
+ replay_mutex_lock();
114
tcg_reg_alloc_call(s, op);
624
+ qemu_mutex_lock_iothread();
115
break;
625
+
116
+ case INDEX_op_dup2_vec:
626
+ if (icount_enabled()) {
117
+ if (tcg_reg_alloc_dup2(s, op)) {
627
+ /* Account partial waits to QEMU_CLOCK_VIRTUAL. */
628
+ icount_account_warp_timer();
629
+ /*
630
+ * Run the timers here. This is much more efficient than
631
+ * waking up the I/O thread and waiting for completion.
632
+ */
633
+ handle_icount_deadline();
634
+ }
635
+
636
+ replay_mutex_unlock();
637
+
638
+ if (!cpu) {
639
+ cpu = first_cpu;
640
+ }
641
+
642
+ while (cpu && cpu_work_list_empty(cpu) && !cpu->exit_request) {
643
+
644
+ qatomic_mb_set(&tcg_current_rr_cpu, cpu);
645
+ current_cpu = cpu;
646
+
647
+ qemu_clock_enable(QEMU_CLOCK_VIRTUAL,
648
+ (cpu->singlestep_enabled & SSTEP_NOTIMER) == 0);
649
+
650
+ if (cpu_can_run(cpu)) {
651
+ int r;
652
+
653
+ qemu_mutex_unlock_iothread();
654
+ if (icount_enabled()) {
655
+ prepare_icount_for_run(cpu);
656
+ }
657
+ r = tcg_cpu_exec(cpu);
658
+ if (icount_enabled()) {
659
+ process_icount_data(cpu);
660
+ }
661
+ qemu_mutex_lock_iothread();
662
+
663
+ if (r == EXCP_DEBUG) {
664
+ cpu_handle_guest_debug(cpu);
665
+ break;
666
+ } else if (r == EXCP_ATOMIC) {
667
+ qemu_mutex_unlock_iothread();
668
+ cpu_exec_step_atomic(cpu);
669
+ qemu_mutex_lock_iothread();
670
+ break;
671
+ }
672
+ } else if (cpu->stop) {
673
+ if (cpu->unplug) {
674
+ cpu = CPU_NEXT(cpu);
675
+ }
676
+ break;
118
+ break;
677
+ }
119
+ }
678
+
120
+ /* fall through */
679
+ cpu = CPU_NEXT(cpu);
121
default:
680
+ } /* while (cpu && !cpu->exit_request).. */
122
/* Sanity check that we've not introduced any unhandled opcodes. */
681
+
123
tcg_debug_assert(tcg_op_supported(opc));
682
+ /* Does not need qatomic_mb_set because a spurious wakeup is okay. */
683
+ qatomic_set(&tcg_current_rr_cpu, NULL);
684
+
685
+ if (cpu && cpu->exit_request) {
686
+ qatomic_mb_set(&cpu->exit_request, 0);
687
+ }
688
+
689
+ if (icount_enabled() && all_cpu_threads_idle()) {
690
+ /*
691
+ * When all cpus are sleeping (e.g in WFI), to avoid a deadlock
692
+ * in the main_loop, wake it up in order to start the warp timer.
693
+ */
694
+ qemu_notify_event();
695
+ }
696
+
697
+ qemu_tcg_rr_wait_io_event();
698
+ deal_with_unplugged_cpus();
699
+ }
700
+
701
+ rcu_unregister_thread();
702
+ return NULL;
703
+}
704
+
705
+const CpusAccel tcg_cpus_rr = {
706
+ .create_vcpu_thread = tcg_start_vcpu_thread,
707
+ .kick_vcpu_thread = qemu_cpu_kick_rr_cpus,
708
+
709
+ .handle_interrupt = tcg_handle_interrupt,
710
+};
711
diff --git a/accel/tcg/tcg-cpus.c b/accel/tcg/tcg-cpus.c
712
index XXXXXXX..XXXXXXX 100644
713
--- a/accel/tcg/tcg-cpus.c
714
+++ b/accel/tcg/tcg-cpus.c
715
@@ -XXX,XX +XXX,XX @@
716
/*
717
- * QEMU System Emulator
718
+ * QEMU TCG vCPU common functionality
719
+ *
720
+ * Functionality common to all TCG vCPU variants: mttcg, rr and icount.
721
*
722
* Copyright (c) 2003-2008 Fabrice Bellard
723
* Copyright (c) 2014 Red Hat Inc.
724
@@ -XXX,XX +XXX,XX @@
725
#include "hw/boards.h"
726
727
#include "tcg-cpus.h"
728
+#include "tcg-cpus-mttcg.h"
729
+#include "tcg-cpus-rr.h"
730
731
-/* Kick all RR vCPUs */
732
-static void qemu_cpu_kick_rr_cpus(void)
733
-{
734
- CPUState *cpu;
735
+/* common functionality among all TCG variants */
736
737
- CPU_FOREACH(cpu) {
738
- cpu_exit(cpu);
739
- };
740
-}
741
-
742
-static void tcg_kick_vcpu_thread(CPUState *cpu)
743
-{
744
- if (qemu_tcg_mttcg_enabled()) {
745
- cpu_exit(cpu);
746
- } else {
747
- qemu_cpu_kick_rr_cpus();
748
- }
749
-}
750
-
751
-/*
752
- * TCG vCPU kick timer
753
- *
754
- * The kick timer is responsible for moving single threaded vCPU
755
- * emulation on to the next vCPU. If more than one vCPU is running a
756
- * timer event with force a cpu->exit so the next vCPU can get
757
- * scheduled.
758
- *
759
- * The timer is removed if all vCPUs are idle and restarted again once
760
- * idleness is complete.
761
- */
762
-
763
-static QEMUTimer *tcg_kick_vcpu_timer;
764
-static CPUState *tcg_current_rr_cpu;
765
-
766
-#define TCG_KICK_PERIOD (NANOSECONDS_PER_SECOND / 10)
767
-
768
-static inline int64_t qemu_tcg_next_kick(void)
769
-{
770
- return qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + TCG_KICK_PERIOD;
771
-}
772
-
773
-/* Kick the currently round-robin scheduled vCPU to next */
774
-static void qemu_cpu_kick_rr_next_cpu(void)
775
-{
776
- CPUState *cpu;
777
- do {
778
- cpu = qatomic_mb_read(&tcg_current_rr_cpu);
779
- if (cpu) {
780
- cpu_exit(cpu);
781
- }
782
- } while (cpu != qatomic_mb_read(&tcg_current_rr_cpu));
783
-}
784
-
785
-static void kick_tcg_thread(void *opaque)
786
-{
787
- timer_mod(tcg_kick_vcpu_timer, qemu_tcg_next_kick());
788
- qemu_cpu_kick_rr_next_cpu();
789
-}
790
-
791
-static void start_tcg_kick_timer(void)
792
-{
793
- assert(!mttcg_enabled);
794
- if (!tcg_kick_vcpu_timer && CPU_NEXT(first_cpu)) {
795
- tcg_kick_vcpu_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
796
- kick_tcg_thread, NULL);
797
- }
798
- if (tcg_kick_vcpu_timer && !timer_pending(tcg_kick_vcpu_timer)) {
799
- timer_mod(tcg_kick_vcpu_timer, qemu_tcg_next_kick());
800
- }
801
-}
802
-
803
-static void stop_tcg_kick_timer(void)
804
-{
805
- assert(!mttcg_enabled);
806
- if (tcg_kick_vcpu_timer && timer_pending(tcg_kick_vcpu_timer)) {
807
- timer_del(tcg_kick_vcpu_timer);
808
- }
809
-}
810
-
811
-static void qemu_tcg_destroy_vcpu(CPUState *cpu)
812
-{
813
-}
814
-
815
-static void qemu_tcg_rr_wait_io_event(void)
816
-{
817
- CPUState *cpu;
818
-
819
- while (all_cpu_threads_idle()) {
820
- stop_tcg_kick_timer();
821
- qemu_cond_wait_iothread(first_cpu->halt_cond);
822
- }
823
-
824
- start_tcg_kick_timer();
825
-
826
- CPU_FOREACH(cpu) {
827
- qemu_wait_io_event_common(cpu);
828
- }
829
-}
830
-
831
-static int64_t tcg_get_icount_limit(void)
832
-{
833
- int64_t deadline;
834
-
835
- if (replay_mode != REPLAY_MODE_PLAY) {
836
- /*
837
- * Include all the timers, because they may need an attention.
838
- * Too long CPU execution may create unnecessary delay in UI.
839
- */
840
- deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL,
841
- QEMU_TIMER_ATTR_ALL);
842
- /* Check realtime timers, because they help with input processing */
843
- deadline = qemu_soonest_timeout(deadline,
844
- qemu_clock_deadline_ns_all(QEMU_CLOCK_REALTIME,
845
- QEMU_TIMER_ATTR_ALL));
846
-
847
- /*
848
- * Maintain prior (possibly buggy) behaviour where if no deadline
849
- * was set (as there is no QEMU_CLOCK_VIRTUAL timer) or it is more than
850
- * INT32_MAX nanoseconds ahead, we still use INT32_MAX
851
- * nanoseconds.
852
- */
853
- if ((deadline < 0) || (deadline > INT32_MAX)) {
854
- deadline = INT32_MAX;
855
- }
856
-
857
- return icount_round(deadline);
858
- } else {
859
- return replay_get_instructions();
860
- }
861
-}
862
-
863
-static void notify_aio_contexts(void)
864
-{
865
- /* Wake up other AioContexts. */
866
- qemu_clock_notify(QEMU_CLOCK_VIRTUAL);
867
- qemu_clock_run_timers(QEMU_CLOCK_VIRTUAL);
868
-}
869
-
870
-static void handle_icount_deadline(void)
871
-{
872
- assert(qemu_in_vcpu_thread());
873
- if (icount_enabled()) {
874
- int64_t deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL,
875
- QEMU_TIMER_ATTR_ALL);
876
-
877
- if (deadline == 0) {
878
- notify_aio_contexts();
879
- }
880
- }
881
-}
882
-
883
-static void prepare_icount_for_run(CPUState *cpu)
884
-{
885
- if (icount_enabled()) {
886
- int insns_left;
887
-
888
- /*
889
- * These should always be cleared by process_icount_data after
890
- * each vCPU execution. However u16.high can be raised
891
- * asynchronously by cpu_exit/cpu_interrupt/tcg_handle_interrupt
892
- */
893
- g_assert(cpu_neg(cpu)->icount_decr.u16.low == 0);
894
- g_assert(cpu->icount_extra == 0);
895
-
896
- cpu->icount_budget = tcg_get_icount_limit();
897
- insns_left = MIN(0xffff, cpu->icount_budget);
898
- cpu_neg(cpu)->icount_decr.u16.low = insns_left;
899
- cpu->icount_extra = cpu->icount_budget - insns_left;
900
-
901
- replay_mutex_lock();
902
-
903
- if (cpu->icount_budget == 0 && replay_has_checkpoint()) {
904
- notify_aio_contexts();
905
- }
906
- }
907
-}
908
-
909
-static void process_icount_data(CPUState *cpu)
910
-{
911
- if (icount_enabled()) {
912
- /* Account for executed instructions */
913
- icount_update(cpu);
914
-
915
- /* Reset the counters */
916
- cpu_neg(cpu)->icount_decr.u16.low = 0;
917
- cpu->icount_extra = 0;
918
- cpu->icount_budget = 0;
919
-
920
- replay_account_executed_instructions();
921
-
922
- replay_mutex_unlock();
923
- }
924
-}
925
-
926
-static int tcg_cpu_exec(CPUState *cpu)
927
-{
928
- int ret;
929
-#ifdef CONFIG_PROFILER
930
- int64_t ti;
931
-#endif
932
-
933
- assert(tcg_enabled());
934
-#ifdef CONFIG_PROFILER
935
- ti = profile_getclock();
936
-#endif
937
- cpu_exec_start(cpu);
938
- ret = cpu_exec(cpu);
939
- cpu_exec_end(cpu);
940
-#ifdef CONFIG_PROFILER
941
- qatomic_set(&tcg_ctx->prof.cpu_exec_time,
942
- tcg_ctx->prof.cpu_exec_time + profile_getclock() - ti);
943
-#endif
944
- return ret;
945
-}
946
-
947
-/*
948
- * Destroy any remaining vCPUs which have been unplugged and have
949
- * finished running
950
- */
951
-static void deal_with_unplugged_cpus(void)
952
-{
953
- CPUState *cpu;
954
-
955
- CPU_FOREACH(cpu) {
956
- if (cpu->unplug && !cpu_can_run(cpu)) {
957
- qemu_tcg_destroy_vcpu(cpu);
958
- cpu_thread_signal_destroyed(cpu);
959
- break;
960
- }
961
- }
962
-}
963
-
964
-/*
965
- * Single-threaded TCG
966
- *
967
- * In the single-threaded case each vCPU is simulated in turn. If
968
- * there is more than a single vCPU we create a simple timer to kick
969
- * the vCPU and ensure we don't get stuck in a tight loop in one vCPU.
970
- * This is done explicitly rather than relying on side-effects
971
- * elsewhere.
972
- */
973
-
974
-static void *tcg_rr_cpu_thread_fn(void *arg)
975
-{
976
- CPUState *cpu = arg;
977
-
978
- assert(tcg_enabled());
979
- rcu_register_thread();
980
- tcg_register_thread();
981
-
982
- qemu_mutex_lock_iothread();
983
- qemu_thread_get_self(cpu->thread);
984
-
985
- cpu->thread_id = qemu_get_thread_id();
986
- cpu->can_do_io = 1;
987
- cpu_thread_signal_created(cpu);
988
- qemu_guest_random_seed_thread_part2(cpu->random_seed);
989
-
990
- /* wait for initial kick-off after machine start */
991
- while (first_cpu->stopped) {
992
- qemu_cond_wait_iothread(first_cpu->halt_cond);
993
-
994
- /* process any pending work */
995
- CPU_FOREACH(cpu) {
996
- current_cpu = cpu;
997
- qemu_wait_io_event_common(cpu);
998
- }
999
- }
1000
-
1001
- start_tcg_kick_timer();
1002
-
1003
- cpu = first_cpu;
1004
-
1005
- /* process any pending work */
1006
- cpu->exit_request = 1;
1007
-
1008
- while (1) {
1009
- qemu_mutex_unlock_iothread();
1010
- replay_mutex_lock();
1011
- qemu_mutex_lock_iothread();
1012
- /* Account partial waits to QEMU_CLOCK_VIRTUAL. */
1013
- icount_account_warp_timer();
1014
-
1015
- /*
1016
- * Run the timers here. This is much more efficient than
1017
- * waking up the I/O thread and waiting for completion.
1018
- */
1019
- handle_icount_deadline();
1020
-
1021
- replay_mutex_unlock();
1022
-
1023
- if (!cpu) {
1024
- cpu = first_cpu;
1025
- }
1026
-
1027
- while (cpu && cpu_work_list_empty(cpu) && !cpu->exit_request) {
1028
-
1029
- qatomic_mb_set(&tcg_current_rr_cpu, cpu);
1030
- current_cpu = cpu;
1031
-
1032
- qemu_clock_enable(QEMU_CLOCK_VIRTUAL,
1033
- (cpu->singlestep_enabled & SSTEP_NOTIMER) == 0);
1034
-
1035
- if (cpu_can_run(cpu)) {
1036
- int r;
1037
-
1038
- qemu_mutex_unlock_iothread();
1039
- prepare_icount_for_run(cpu);
1040
-
1041
- r = tcg_cpu_exec(cpu);
1042
-
1043
- process_icount_data(cpu);
1044
- qemu_mutex_lock_iothread();
1045
-
1046
- if (r == EXCP_DEBUG) {
1047
- cpu_handle_guest_debug(cpu);
1048
- break;
1049
- } else if (r == EXCP_ATOMIC) {
1050
- qemu_mutex_unlock_iothread();
1051
- cpu_exec_step_atomic(cpu);
1052
- qemu_mutex_lock_iothread();
1053
- break;
1054
- }
1055
- } else if (cpu->stop) {
1056
- if (cpu->unplug) {
1057
- cpu = CPU_NEXT(cpu);
1058
- }
1059
- break;
1060
- }
1061
-
1062
- cpu = CPU_NEXT(cpu);
1063
- } /* while (cpu && !cpu->exit_request).. */
1064
-
1065
- /* Does not need qatomic_mb_set because a spurious wakeup is okay. */
1066
- qatomic_set(&tcg_current_rr_cpu, NULL);
1067
-
1068
- if (cpu && cpu->exit_request) {
1069
- qatomic_mb_set(&cpu->exit_request, 0);
1070
- }
1071
-
1072
- if (icount_enabled() && all_cpu_threads_idle()) {
1073
- /*
1074
- * When all cpus are sleeping (e.g in WFI), to avoid a deadlock
1075
- * in the main_loop, wake it up in order to start the warp timer.
1076
- */
1077
- qemu_notify_event();
1078
- }
1079
-
1080
- qemu_tcg_rr_wait_io_event();
1081
- deal_with_unplugged_cpus();
1082
- }
1083
-
1084
- rcu_unregister_thread();
1085
- return NULL;
1086
-}
1087
-
1088
-/*
1089
- * Multi-threaded TCG
1090
- *
1091
- * In the multi-threaded case each vCPU has its own thread. The TLS
1092
- * variable current_cpu can be used deep in the code to find the
1093
- * current CPUState for a given thread.
1094
- */
1095
-
1096
-static void *tcg_cpu_thread_fn(void *arg)
1097
-{
1098
- CPUState *cpu = arg;
1099
-
1100
- assert(tcg_enabled());
1101
- g_assert(!icount_enabled());
1102
-
1103
- rcu_register_thread();
1104
- tcg_register_thread();
1105
-
1106
- qemu_mutex_lock_iothread();
1107
- qemu_thread_get_self(cpu->thread);
1108
-
1109
- cpu->thread_id = qemu_get_thread_id();
1110
- cpu->can_do_io = 1;
1111
- current_cpu = cpu;
1112
- cpu_thread_signal_created(cpu);
1113
- qemu_guest_random_seed_thread_part2(cpu->random_seed);
1114
-
1115
- /* process any pending work */
1116
- cpu->exit_request = 1;
1117
-
1118
- do {
1119
- if (cpu_can_run(cpu)) {
1120
- int r;
1121
- qemu_mutex_unlock_iothread();
1122
- r = tcg_cpu_exec(cpu);
1123
- qemu_mutex_lock_iothread();
1124
- switch (r) {
1125
- case EXCP_DEBUG:
1126
- cpu_handle_guest_debug(cpu);
1127
- break;
1128
- case EXCP_HALTED:
1129
- /*
1130
- * during start-up the vCPU is reset and the thread is
1131
- * kicked several times. If we don't ensure we go back
1132
- * to sleep in the halted state we won't cleanly
1133
- * start-up when the vCPU is enabled.
1134
- *
1135
- * cpu->halted should ensure we sleep in wait_io_event
1136
- */
1137
- g_assert(cpu->halted);
1138
- break;
1139
- case EXCP_ATOMIC:
1140
- qemu_mutex_unlock_iothread();
1141
- cpu_exec_step_atomic(cpu);
1142
- qemu_mutex_lock_iothread();
1143
- default:
1144
- /* Ignore everything else? */
1145
- break;
1146
- }
1147
- }
1148
-
1149
- qatomic_mb_set(&cpu->exit_request, 0);
1150
- qemu_wait_io_event(cpu);
1151
- } while (!cpu->unplug || cpu_can_run(cpu));
1152
-
1153
- qemu_tcg_destroy_vcpu(cpu);
1154
- cpu_thread_signal_destroyed(cpu);
1155
- qemu_mutex_unlock_iothread();
1156
- rcu_unregister_thread();
1157
- return NULL;
1158
-}
1159
-
1160
-static void tcg_start_vcpu_thread(CPUState *cpu)
1161
+void tcg_start_vcpu_thread(CPUState *cpu)
1162
{
1163
char thread_name[VCPU_THREAD_NAME_SIZE];
1164
static QemuCond *single_tcg_halt_cond;
1165
@@ -XXX,XX +XXX,XX @@ static void tcg_start_vcpu_thread(CPUState *cpu)
1166
}
1167
}
1168
1169
-static int64_t tcg_get_virtual_clock(void)
1170
+void qemu_tcg_destroy_vcpu(CPUState *cpu)
1171
{
1172
- if (icount_enabled()) {
1173
- return icount_get();
1174
- }
1175
- return cpu_get_clock();
1176
+ cpu_thread_signal_destroyed(cpu);
1177
}
1178
1179
-static int64_t tcg_get_elapsed_ticks(void)
1180
+int tcg_cpu_exec(CPUState *cpu)
1181
{
1182
- if (icount_enabled()) {
1183
- return icount_get();
1184
- }
1185
- return cpu_get_ticks();
1186
+ int ret;
1187
+#ifdef CONFIG_PROFILER
1188
+ int64_t ti;
1189
+#endif
1190
+ assert(tcg_enabled());
1191
+#ifdef CONFIG_PROFILER
1192
+ ti = profile_getclock();
1193
+#endif
1194
+ cpu_exec_start(cpu);
1195
+ ret = cpu_exec(cpu);
1196
+ cpu_exec_end(cpu);
1197
+#ifdef CONFIG_PROFILER
1198
+ qatomic_set(&tcg_ctx->prof.cpu_exec_time,
1199
+ tcg_ctx->prof.cpu_exec_time + profile_getclock() - ti);
1200
+#endif
1201
+ return ret;
1202
}
1203
1204
/* mask must never be zero, except for A20 change call */
1205
-static void tcg_handle_interrupt(CPUState *cpu, int mask)
1206
+void tcg_handle_interrupt(CPUState *cpu, int mask)
1207
{
1208
- int old_mask;
1209
g_assert(qemu_mutex_iothread_locked());
1210
1211
- old_mask = cpu->interrupt_request;
1212
cpu->interrupt_request |= mask;
1213
1214
/*
1215
@@ -XXX,XX +XXX,XX @@ static void tcg_handle_interrupt(CPUState *cpu, int mask)
1216
qemu_cpu_kick(cpu);
1217
} else {
1218
qatomic_set(&cpu_neg(cpu)->icount_decr.u16.high, -1);
1219
- if (icount_enabled() &&
1220
- !cpu->can_do_io
1221
- && (mask & ~old_mask) != 0) {
1222
- cpu_abort(cpu, "Raised interrupt while not in I/O function");
1223
- }
1224
}
1225
}
1226
-
1227
-const CpusAccel tcg_cpus = {
1228
- .create_vcpu_thread = tcg_start_vcpu_thread,
1229
- .kick_vcpu_thread = tcg_kick_vcpu_thread,
1230
-
1231
- .handle_interrupt = tcg_handle_interrupt,
1232
-
1233
- .get_virtual_clock = tcg_get_virtual_clock,
1234
- .get_elapsed_ticks = tcg_get_elapsed_ticks,
1235
-};
1236
diff --git a/softmmu/icount.c b/softmmu/icount.c
1237
index XXXXXXX..XXXXXXX 100644
1238
--- a/softmmu/icount.c
1239
+++ b/softmmu/icount.c
1240
@@ -XXX,XX +XXX,XX @@ void icount_start_warp_timer(void)
1241
1242
void icount_account_warp_timer(void)
1243
{
1244
- if (!icount_enabled() || !icount_sleep) {
1245
+ if (!icount_sleep) {
1246
return;
1247
}
1248
1249
diff --git a/accel/tcg/meson.build b/accel/tcg/meson.build
1250
index XXXXXXX..XXXXXXX 100644
1251
--- a/accel/tcg/meson.build
1252
+++ b/accel/tcg/meson.build
1253
@@ -XXX,XX +XXX,XX @@ tcg_ss.add(when: 'CONFIG_SOFTMMU', if_false: files('user-exec-stub.c'))
1254
tcg_ss.add(when: 'CONFIG_PLUGIN', if_true: [files('plugin-gen.c'), libdl])
1255
specific_ss.add_all(when: 'CONFIG_TCG', if_true: tcg_ss)
1256
1257
-specific_ss.add(when: ['CONFIG_SOFTMMU', 'CONFIG_TCG'], if_true: files('tcg-all.c', 'cputlb.c', 'tcg-cpus.c'))
1258
+specific_ss.add(when: ['CONFIG_SOFTMMU', 'CONFIG_TCG'], if_true: files(
1259
+ 'tcg-all.c',
1260
+ 'cputlb.c',
1261
+ 'tcg-cpus.c',
1262
+ 'tcg-cpus-mttcg.c',
1263
+ 'tcg-cpus-icount.c',
1264
+ 'tcg-cpus-rr.c'
1265
+))
1266
--
124
--
1267
2.25.1
125
2.25.1
1268
126
1269
127
diff view generated by jsdifflib
New patch
1
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
2
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
3
---
4
tcg/i386/tcg-target.c.inc | 26 +++++++++++++-------------
5
1 file changed, 13 insertions(+), 13 deletions(-)
1
6
7
diff --git a/tcg/i386/tcg-target.c.inc b/tcg/i386/tcg-target.c.inc
8
index XXXXXXX..XXXXXXX 100644
9
--- a/tcg/i386/tcg-target.c.inc
10
+++ b/tcg/i386/tcg-target.c.inc
11
@@ -XXX,XX +XXX,XX @@ static void expand_vec_rotv(TCGType type, unsigned vece, TCGv_vec v0,
12
static void expand_vec_mul(TCGType type, unsigned vece,
13
TCGv_vec v0, TCGv_vec v1, TCGv_vec v2)
14
{
15
- TCGv_vec t1, t2, t3, t4;
16
+ TCGv_vec t1, t2, t3, t4, zero;
17
18
tcg_debug_assert(vece == MO_8);
19
20
@@ -XXX,XX +XXX,XX @@ static void expand_vec_mul(TCGType type, unsigned vece,
21
case TCG_TYPE_V64:
22
t1 = tcg_temp_new_vec(TCG_TYPE_V128);
23
t2 = tcg_temp_new_vec(TCG_TYPE_V128);
24
- tcg_gen_dup16i_vec(t2, 0);
25
+ zero = tcg_constant_vec(TCG_TYPE_V128, MO_8, 0);
26
vec_gen_3(INDEX_op_x86_punpckl_vec, TCG_TYPE_V128, MO_8,
27
- tcgv_vec_arg(t1), tcgv_vec_arg(v1), tcgv_vec_arg(t2));
28
+ tcgv_vec_arg(t1), tcgv_vec_arg(v1), tcgv_vec_arg(zero));
29
vec_gen_3(INDEX_op_x86_punpckl_vec, TCG_TYPE_V128, MO_8,
30
- tcgv_vec_arg(t2), tcgv_vec_arg(t2), tcgv_vec_arg(v2));
31
+ tcgv_vec_arg(t2), tcgv_vec_arg(zero), tcgv_vec_arg(v2));
32
tcg_gen_mul_vec(MO_16, t1, t1, t2);
33
tcg_gen_shri_vec(MO_16, t1, t1, 8);
34
vec_gen_3(INDEX_op_x86_packus_vec, TCG_TYPE_V128, MO_8,
35
@@ -XXX,XX +XXX,XX @@ static void expand_vec_mul(TCGType type, unsigned vece,
36
t2 = tcg_temp_new_vec(type);
37
t3 = tcg_temp_new_vec(type);
38
t4 = tcg_temp_new_vec(type);
39
- tcg_gen_dup16i_vec(t4, 0);
40
+ zero = tcg_constant_vec(TCG_TYPE_V128, MO_8, 0);
41
vec_gen_3(INDEX_op_x86_punpckl_vec, type, MO_8,
42
- tcgv_vec_arg(t1), tcgv_vec_arg(v1), tcgv_vec_arg(t4));
43
+ tcgv_vec_arg(t1), tcgv_vec_arg(v1), tcgv_vec_arg(zero));
44
vec_gen_3(INDEX_op_x86_punpckl_vec, type, MO_8,
45
- tcgv_vec_arg(t2), tcgv_vec_arg(t4), tcgv_vec_arg(v2));
46
+ tcgv_vec_arg(t2), tcgv_vec_arg(zero), tcgv_vec_arg(v2));
47
vec_gen_3(INDEX_op_x86_punpckh_vec, type, MO_8,
48
- tcgv_vec_arg(t3), tcgv_vec_arg(v1), tcgv_vec_arg(t4));
49
+ tcgv_vec_arg(t3), tcgv_vec_arg(v1), tcgv_vec_arg(zero));
50
vec_gen_3(INDEX_op_x86_punpckh_vec, type, MO_8,
51
- tcgv_vec_arg(t4), tcgv_vec_arg(t4), tcgv_vec_arg(v2));
52
+ tcgv_vec_arg(t4), tcgv_vec_arg(zero), tcgv_vec_arg(v2));
53
tcg_gen_mul_vec(MO_16, t1, t1, t2);
54
tcg_gen_mul_vec(MO_16, t3, t3, t4);
55
tcg_gen_shri_vec(MO_16, t1, t1, 8);
56
@@ -XXX,XX +XXX,XX @@ static bool expand_vec_cmp_noinv(TCGType type, unsigned vece, TCGv_vec v0,
57
NEED_UMIN = 8,
58
NEED_UMAX = 16,
59
};
60
- TCGv_vec t1, t2;
61
+ TCGv_vec t1, t2, t3;
62
uint8_t fixup;
63
64
switch (cond) {
65
@@ -XXX,XX +XXX,XX @@ static bool expand_vec_cmp_noinv(TCGType type, unsigned vece, TCGv_vec v0,
66
} else if (fixup & NEED_BIAS) {
67
t1 = tcg_temp_new_vec(type);
68
t2 = tcg_temp_new_vec(type);
69
- tcg_gen_dupi_vec(vece, t2, 1ull << ((8 << vece) - 1));
70
- tcg_gen_sub_vec(vece, t1, v1, t2);
71
- tcg_gen_sub_vec(vece, t2, v2, t2);
72
+ t3 = tcg_constant_vec(type, vece, 1ull << ((8 << vece) - 1));
73
+ tcg_gen_sub_vec(vece, t1, v1, t3);
74
+ tcg_gen_sub_vec(vece, t2, v2, t3);
75
v1 = t1;
76
v2 = t2;
77
cond = tcg_signed_cond(cond);
78
--
79
2.25.1
80
81
diff view generated by jsdifflib
New patch
1
These interfaces have been replaced by tcg_gen_dupi_vec
2
and tcg_constant_vec.
1
3
4
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
5
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
6
---
7
include/tcg/tcg-op.h | 4 ----
8
tcg/tcg-op-vec.c | 20 --------------------
9
2 files changed, 24 deletions(-)
10
11
diff --git a/include/tcg/tcg-op.h b/include/tcg/tcg-op.h
12
index XXXXXXX..XXXXXXX 100644
13
--- a/include/tcg/tcg-op.h
14
+++ b/include/tcg/tcg-op.h
15
@@ -XXX,XX +XXX,XX @@ void tcg_gen_mov_vec(TCGv_vec, TCGv_vec);
16
void tcg_gen_dup_i32_vec(unsigned vece, TCGv_vec, TCGv_i32);
17
void tcg_gen_dup_i64_vec(unsigned vece, TCGv_vec, TCGv_i64);
18
void tcg_gen_dup_mem_vec(unsigned vece, TCGv_vec, TCGv_ptr, tcg_target_long);
19
-void tcg_gen_dup8i_vec(TCGv_vec, uint32_t);
20
-void tcg_gen_dup16i_vec(TCGv_vec, uint32_t);
21
-void tcg_gen_dup32i_vec(TCGv_vec, uint32_t);
22
-void tcg_gen_dup64i_vec(TCGv_vec, uint64_t);
23
void tcg_gen_dupi_vec(unsigned vece, TCGv_vec, uint64_t);
24
void tcg_gen_add_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b);
25
void tcg_gen_sub_vec(unsigned vece, TCGv_vec r, TCGv_vec a, TCGv_vec b);
26
diff --git a/tcg/tcg-op-vec.c b/tcg/tcg-op-vec.c
27
index XXXXXXX..XXXXXXX 100644
28
--- a/tcg/tcg-op-vec.c
29
+++ b/tcg/tcg-op-vec.c
30
@@ -XXX,XX +XXX,XX @@ TCGv_vec tcg_const_ones_vec_matching(TCGv_vec m)
31
return tcg_const_ones_vec(t->base_type);
32
}
33
34
-void tcg_gen_dup64i_vec(TCGv_vec r, uint64_t a)
35
-{
36
- tcg_gen_dupi_vec(MO_64, r, a);
37
-}
38
-
39
-void tcg_gen_dup32i_vec(TCGv_vec r, uint32_t a)
40
-{
41
- tcg_gen_dupi_vec(MO_32, r, a);
42
-}
43
-
44
-void tcg_gen_dup16i_vec(TCGv_vec r, uint32_t a)
45
-{
46
- tcg_gen_dupi_vec(MO_16, r, a);
47
-}
48
-
49
-void tcg_gen_dup8i_vec(TCGv_vec r, uint32_t a)
50
-{
51
- tcg_gen_dupi_vec(MO_8, r, a);
52
-}
53
-
54
void tcg_gen_dupi_vec(unsigned vece, TCGv_vec r, uint64_t a)
55
{
56
TCGTemp *rt = tcgv_vec_temp(r);
57
--
58
2.25.1
59
60
diff view generated by jsdifflib
New patch
1
Improve expand_vec_shi to use sign-extraction for MO_32.
2
This allows a single VSPLTISB instruction to load all of
3
the valid shift constants.
1
4
5
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
6
---
7
tcg/ppc/tcg-target.c.inc | 44 ++++++++++++++++++++++++----------------
8
1 file changed, 27 insertions(+), 17 deletions(-)
9
10
diff --git a/tcg/ppc/tcg-target.c.inc b/tcg/ppc/tcg-target.c.inc
11
index XXXXXXX..XXXXXXX 100644
12
--- a/tcg/ppc/tcg-target.c.inc
13
+++ b/tcg/ppc/tcg-target.c.inc
14
@@ -XXX,XX +XXX,XX @@ static void tcg_out_vec_op(TCGContext *s, TCGOpcode opc,
15
static void expand_vec_shi(TCGType type, unsigned vece, TCGv_vec v0,
16
TCGv_vec v1, TCGArg imm, TCGOpcode opci)
17
{
18
- TCGv_vec t1 = tcg_temp_new_vec(type);
19
+ TCGv_vec t1;
20
21
- /* Splat w/bytes for xxspltib. */
22
- tcg_gen_dupi_vec(MO_8, t1, imm & ((8 << vece) - 1));
23
+ if (vece == MO_32) {
24
+ /*
25
+ * Only 5 bits are significant, and VSPLTISB can represent -16..15.
26
+ * So using negative numbers gets us the 4th bit easily.
27
+ */
28
+ imm = sextract32(imm, 0, 5);
29
+ } else {
30
+ imm &= (8 << vece) - 1;
31
+ }
32
+
33
+ /* Splat w/bytes for xxspltib when 2.07 allows MO_64. */
34
+ t1 = tcg_constant_vec(type, MO_8, imm);
35
vec_gen_3(opci, type, vece, tcgv_vec_arg(v0),
36
tcgv_vec_arg(v1), tcgv_vec_arg(t1));
37
- tcg_temp_free_vec(t1);
38
}
39
40
static void expand_vec_cmp(TCGType type, unsigned vece, TCGv_vec v0,
41
@@ -XXX,XX +XXX,XX @@ static void expand_vec_mul(TCGType type, unsigned vece, TCGv_vec v0,
42
{
43
TCGv_vec t1 = tcg_temp_new_vec(type);
44
TCGv_vec t2 = tcg_temp_new_vec(type);
45
- TCGv_vec t3, t4;
46
+ TCGv_vec c0, c16;
47
48
switch (vece) {
49
case MO_8:
50
@@ -XXX,XX +XXX,XX @@ static void expand_vec_mul(TCGType type, unsigned vece, TCGv_vec v0,
51
52
case MO_32:
53
tcg_debug_assert(!have_isa_2_07);
54
- t3 = tcg_temp_new_vec(type);
55
- t4 = tcg_temp_new_vec(type);
56
- tcg_gen_dupi_vec(MO_8, t4, -16);
57
+ /*
58
+ * Only 5 bits are significant, and VSPLTISB can represent -16..15.
59
+ * So using -16 is a quick way to represent 16.
60
+ */
61
+ c16 = tcg_constant_vec(type, MO_8, -16);
62
+ c0 = tcg_constant_vec(type, MO_8, 0);
63
+
64
vec_gen_3(INDEX_op_rotlv_vec, type, MO_32, tcgv_vec_arg(t1),
65
- tcgv_vec_arg(v2), tcgv_vec_arg(t4));
66
+ tcgv_vec_arg(v2), tcgv_vec_arg(c16));
67
vec_gen_3(INDEX_op_ppc_mulou_vec, type, MO_16, tcgv_vec_arg(t2),
68
tcgv_vec_arg(v1), tcgv_vec_arg(v2));
69
- tcg_gen_dupi_vec(MO_8, t3, 0);
70
- vec_gen_4(INDEX_op_ppc_msum_vec, type, MO_16, tcgv_vec_arg(t3),
71
- tcgv_vec_arg(v1), tcgv_vec_arg(t1), tcgv_vec_arg(t3));
72
- vec_gen_3(INDEX_op_shlv_vec, type, MO_32, tcgv_vec_arg(t3),
73
- tcgv_vec_arg(t3), tcgv_vec_arg(t4));
74
- tcg_gen_add_vec(MO_32, v0, t2, t3);
75
- tcg_temp_free_vec(t3);
76
- tcg_temp_free_vec(t4);
77
+ vec_gen_4(INDEX_op_ppc_msum_vec, type, MO_16, tcgv_vec_arg(t1),
78
+ tcgv_vec_arg(v1), tcgv_vec_arg(t1), tcgv_vec_arg(c0));
79
+ vec_gen_3(INDEX_op_shlv_vec, type, MO_32, tcgv_vec_arg(t1),
80
+ tcgv_vec_arg(t1), tcgv_vec_arg(c16));
81
+ tcg_gen_add_vec(MO_32, v0, t1, t2);
82
break;
83
84
default:
85
--
86
2.25.1
87
88
diff view generated by jsdifflib
New patch
1
Improve rotrv_vec to reduce "t1 = -v2, t2 = t1 + c" to
2
"t1 = -v2, t2 = c - v2". This avoids a serial dependency
3
between t1 and t2.
1
4
5
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
6
---
7
tcg/aarch64/tcg-target.c.inc | 10 +++++-----
8
1 file changed, 5 insertions(+), 5 deletions(-)
9
10
diff --git a/tcg/aarch64/tcg-target.c.inc b/tcg/aarch64/tcg-target.c.inc
11
index XXXXXXX..XXXXXXX 100644
12
--- a/tcg/aarch64/tcg-target.c.inc
13
+++ b/tcg/aarch64/tcg-target.c.inc
14
@@ -XXX,XX +XXX,XX @@ void tcg_expand_vec_op(TCGOpcode opc, TCGType type, unsigned vece,
15
TCGArg a0, ...)
16
{
17
va_list va;
18
- TCGv_vec v0, v1, v2, t1, t2;
19
+ TCGv_vec v0, v1, v2, t1, t2, c1;
20
TCGArg a2;
21
22
va_start(va, a0);
23
@@ -XXX,XX +XXX,XX @@ void tcg_expand_vec_op(TCGOpcode opc, TCGType type, unsigned vece,
24
25
case INDEX_op_rotlv_vec:
26
t1 = tcg_temp_new_vec(type);
27
- tcg_gen_dupi_vec(vece, t1, 8 << vece);
28
- tcg_gen_sub_vec(vece, t1, v2, t1);
29
+ c1 = tcg_constant_vec(type, vece, 8 << vece);
30
+ tcg_gen_sub_vec(vece, t1, v2, c1);
31
/* Right shifts are negative left shifts for AArch64. */
32
vec_gen_3(INDEX_op_shlv_vec, type, vece, tcgv_vec_arg(t1),
33
tcgv_vec_arg(v1), tcgv_vec_arg(t1));
34
@@ -XXX,XX +XXX,XX @@ void tcg_expand_vec_op(TCGOpcode opc, TCGType type, unsigned vece,
35
case INDEX_op_rotrv_vec:
36
t1 = tcg_temp_new_vec(type);
37
t2 = tcg_temp_new_vec(type);
38
+ c1 = tcg_constant_vec(type, vece, 8 << vece);
39
tcg_gen_neg_vec(vece, t1, v2);
40
- tcg_gen_dupi_vec(vece, t2, 8 << vece);
41
- tcg_gen_add_vec(vece, t2, t1, t2);
42
+ tcg_gen_sub_vec(vece, t2, c1, v2);
43
/* Right shifts are negative left shifts for AArch64. */
44
vec_gen_3(INDEX_op_shlv_vec, type, vece, tcgv_vec_arg(t1),
45
tcgv_vec_arg(v1), tcgv_vec_arg(t1));
46
--
47
2.25.1
48
49
diff view generated by jsdifflib
New patch
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
2
3
When decodetree.py was added in commit 568ae7efae7, QEMU was
4
using Python 2 which happily reads UTF-8 files in text mode.
5
Python 3 requires either UTF-8 locale or an explicit encoding
6
passed to open(). Now that Python 3 is required, explicit
7
UTF-8 encoding for decodetree source files.
8
9
To avoid further problems with the user locale, also explicit
10
UTF-8 encoding for the generated C files.
11
12
Explicit both input/output are plain text by using the 't' mode.
13
14
This fixes:
15
16
$ /usr/bin/python3 scripts/decodetree.py test.decode
17
Traceback (most recent call last):
18
File "scripts/decodetree.py", line 1397, in <module>
19
main()
20
File "scripts/decodetree.py", line 1308, in main
21
parse_file(f, toppat)
22
File "scripts/decodetree.py", line 994, in parse_file
23
for line in f:
24
File "/usr/lib/python3.6/encodings/ascii.py", line 26, in decode
25
return codecs.ascii_decode(input, self.errors)[0]
26
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 80:
27
ordinal not in range(128)
28
29
Reported-by: Peter Maydell <peter.maydell@linaro.org>
30
Suggested-by: Yonggang Luo <luoyonggang@gmail.com>
31
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
32
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
33
Message-Id: <20210110000240.761122-1-f4bug@amsat.org>
34
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
35
---
36
scripts/decodetree.py | 9 ++++++---
37
1 file changed, 6 insertions(+), 3 deletions(-)
38
39
diff --git a/scripts/decodetree.py b/scripts/decodetree.py
40
index XXXXXXX..XXXXXXX 100644
41
--- a/scripts/decodetree.py
42
+++ b/scripts/decodetree.py
43
@@ -XXX,XX +XXX,XX @@
44
# See the syntax and semantics in docs/devel/decodetree.rst.
45
#
46
47
+import io
48
import os
49
import re
50
import sys
51
@@ -XXX,XX +XXX,XX @@ def main():
52
53
for filename in args:
54
input_file = filename
55
- f = open(filename, 'r')
56
+ f = open(filename, 'rt', encoding='utf-8')
57
parse_file(f, toppat)
58
f.close()
59
60
@@ -XXX,XX +XXX,XX @@ def main():
61
prop_size(stree)
62
63
if output_file:
64
- output_fd = open(output_file, 'w')
65
+ output_fd = open(output_file, 'wt', encoding='utf-8')
66
else:
67
- output_fd = sys.stdout
68
+ output_fd = io.TextIOWrapper(sys.stdout.buffer,
69
+ encoding=sys.stdout.encoding,
70
+ errors="ignore")
71
72
output_autogen()
73
for n in sorted(arguments.keys()):
74
--
75
2.25.1
76
77
diff view generated by jsdifflib