1 | The following changes since commit 2ecfc0657afa5d29a373271b342f704a1a3c6737: | 1 | The following changes since commit 1cbd2d914939ee6028e9688d4ba859a528c28405: |
---|---|---|---|
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/jasowang/tags/net-pull-request' into staging (2021-06-04 13:38:49 +0100) |
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-20210604 |
8 | 8 | ||
9 | for you to fetch changes up to 9e2658d62ebc23efe7df43fc0e306f129510d874: | 9 | for you to fetch changes up to 0006039e29b9e6118beab300146f7c4931f7a217: |
10 | 10 | ||
11 | accel/tcg: rename tcg-cpus functions to match module name (2020-12-10 17:44:10 -0600) | 11 | tcg/arm: Implement TCG_TARGET_HAS_rotv_vec (2021-06-04 11:50:11 -0700) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | Split CpusAccel for tcg variants | 14 | Host vector support for arm neon. |
15 | 15 | ||
16 | ---------------------------------------------------------------- | 16 | ---------------------------------------------------------------- |
17 | Claudio Fontana (3): | 17 | Richard Henderson (15): |
18 | accel/tcg: split CpusAccel into three TCG variants | 18 | tcg: Change parameters for tcg_target_const_match |
19 | accel/tcg: split tcg_start_vcpu_thread | 19 | tcg/arm: Add host vector framework |
20 | accel/tcg: rename tcg-cpus functions to match module name | 20 | tcg/arm: Implement tcg_out_ld/st for vector types |
21 | tcg/arm: Implement tcg_out_mov for vector types | ||
22 | tcg/arm: Implement tcg_out_dup*_vec | ||
23 | tcg/arm: Implement minimal vector operations | ||
24 | tcg/arm: Implement andc, orc, abs, neg, not vector operations | ||
25 | tcg/arm: Implement TCG_TARGET_HAS_shi_vec | ||
26 | tcg/arm: Implement TCG_TARGET_HAS_mul_vec | ||
27 | tcg/arm: Implement TCG_TARGET_HAS_sat_vec | ||
28 | tcg/arm: Implement TCG_TARGET_HAS_minmax_vec | ||
29 | tcg/arm: Implement TCG_TARGET_HAS_bitsel_vec | ||
30 | tcg/arm: Implement TCG_TARGET_HAS_shv_vec | ||
31 | tcg/arm: Implement TCG_TARGET_HAS_roti_vec | ||
32 | tcg/arm: Implement TCG_TARGET_HAS_rotv_vec | ||
21 | 33 | ||
22 | accel/tcg/tcg-cpus-icount.h | 17 ++ | 34 | tcg/arm/tcg-target-con-set.h | 10 + |
23 | accel/tcg/tcg-cpus-rr.h | 21 ++ | 35 | tcg/arm/tcg-target-con-str.h | 3 + |
24 | accel/tcg/tcg-cpus.h | 12 +- | 36 | tcg/arm/tcg-target.h | 52 ++- |
25 | accel/tcg/tcg-all.c | 13 +- | 37 | tcg/arm/tcg-target.opc.h | 16 + |
26 | accel/tcg/tcg-cpus-icount.c | 147 +++++++++++++ | 38 | tcg/tcg.c | 5 +- |
27 | accel/tcg/tcg-cpus-mttcg.c | 140 ++++++++++++ | 39 | tcg/aarch64/tcg-target.c.inc | 5 +- |
28 | accel/tcg/tcg-cpus-rr.c | 305 ++++++++++++++++++++++++++ | 40 | tcg/arm/tcg-target.c.inc | 956 +++++++++++++++++++++++++++++++++++++++++-- |
29 | accel/tcg/tcg-cpus.c | 506 +------------------------------------------- | 41 | tcg/i386/tcg-target.c.inc | 4 +- |
30 | softmmu/icount.c | 2 +- | 42 | tcg/mips/tcg-target.c.inc | 5 +- |
31 | accel/tcg/meson.build | 9 +- | 43 | tcg/ppc/tcg-target.c.inc | 4 +- |
32 | 10 files changed, 670 insertions(+), 502 deletions(-) | 44 | tcg/riscv/tcg-target.c.inc | 4 +- |
33 | create mode 100644 accel/tcg/tcg-cpus-icount.h | 45 | tcg/s390/tcg-target.c.inc | 5 +- |
34 | create mode 100644 accel/tcg/tcg-cpus-rr.h | 46 | tcg/sparc/tcg-target.c.inc | 5 +- |
35 | create mode 100644 accel/tcg/tcg-cpus-icount.c | 47 | tcg/tci/tcg-target.c.inc | 6 +- |
36 | create mode 100644 accel/tcg/tcg-cpus-mttcg.c | 48 | 14 files changed, 1001 insertions(+), 79 deletions(-) |
37 | create mode 100644 accel/tcg/tcg-cpus-rr.c | 49 | create mode 100644 tcg/arm/tcg-target.opc.h |
38 | 50 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | Change the return value to bool, because that's what is should | |
2 | have been from the start. Pass the ct mask instead of the whole | ||
3 | TCGArgConstraint, as that's the only part that's relevant. | ||
4 | |||
5 | Change the value argument to int64_t. We will need the extra | ||
6 | width for 32-bit hosts wanting to match vector constants. | ||
7 | |||
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
10 | --- | ||
11 | tcg/tcg.c | 5 ++--- | ||
12 | tcg/aarch64/tcg-target.c.inc | 5 +---- | ||
13 | tcg/arm/tcg-target.c.inc | 5 +---- | ||
14 | tcg/i386/tcg-target.c.inc | 4 +--- | ||
15 | tcg/mips/tcg-target.c.inc | 5 +---- | ||
16 | tcg/ppc/tcg-target.c.inc | 4 +--- | ||
17 | tcg/riscv/tcg-target.c.inc | 4 +--- | ||
18 | tcg/s390/tcg-target.c.inc | 5 +---- | ||
19 | tcg/sparc/tcg-target.c.inc | 5 +---- | ||
20 | tcg/tci/tcg-target.c.inc | 6 ++---- | ||
21 | 10 files changed, 12 insertions(+), 36 deletions(-) | ||
22 | |||
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 tcg_out_st(TCGContext *s, TCGType type, TCGReg arg, TCGReg arg1, | ||
28 | static bool tcg_out_sti(TCGContext *s, TCGType type, TCGArg val, | ||
29 | TCGReg base, intptr_t ofs); | ||
30 | static void tcg_out_call(TCGContext *s, const tcg_insn_unit *target); | ||
31 | -static int tcg_target_const_match(tcg_target_long val, TCGType type, | ||
32 | - const TCGArgConstraint *arg_ct); | ||
33 | +static bool tcg_target_const_match(int64_t val, TCGType type, int ct); | ||
34 | #ifdef TCG_TARGET_NEED_LDST_LABELS | ||
35 | static int tcg_out_ldst_finalize(TCGContext *s); | ||
36 | #endif | ||
37 | @@ -XXX,XX +XXX,XX @@ static void tcg_reg_alloc_op(TCGContext *s, const TCGOp *op) | ||
38 | ts = arg_temp(arg); | ||
39 | |||
40 | if (ts->val_type == TEMP_VAL_CONST | ||
41 | - && tcg_target_const_match(ts->val, ts->type, arg_ct)) { | ||
42 | + && tcg_target_const_match(ts->val, ts->type, arg_ct->ct)) { | ||
43 | /* constant is OK for instruction */ | ||
44 | const_args[i] = 1; | ||
45 | new_args[i] = ts->val; | ||
46 | diff --git a/tcg/aarch64/tcg-target.c.inc b/tcg/aarch64/tcg-target.c.inc | ||
47 | index XXXXXXX..XXXXXXX 100644 | ||
48 | --- a/tcg/aarch64/tcg-target.c.inc | ||
49 | +++ b/tcg/aarch64/tcg-target.c.inc | ||
50 | @@ -XXX,XX +XXX,XX @@ static bool is_shimm1632(uint32_t v32, int *cmode, int *imm8) | ||
51 | } | ||
52 | } | ||
53 | |||
54 | -static int tcg_target_const_match(tcg_target_long val, TCGType type, | ||
55 | - const TCGArgConstraint *arg_ct) | ||
56 | +static bool tcg_target_const_match(int64_t val, TCGType type, int ct) | ||
57 | { | ||
58 | - int ct = arg_ct->ct; | ||
59 | - | ||
60 | if (ct & TCG_CT_CONST) { | ||
61 | return 1; | ||
62 | } | ||
63 | diff --git a/tcg/arm/tcg-target.c.inc b/tcg/arm/tcg-target.c.inc | ||
64 | index XXXXXXX..XXXXXXX 100644 | ||
65 | --- a/tcg/arm/tcg-target.c.inc | ||
66 | +++ b/tcg/arm/tcg-target.c.inc | ||
67 | @@ -XXX,XX +XXX,XX @@ static inline int check_fit_imm(uint32_t imm) | ||
68 | * mov operand2: values represented with x << (2 * y), x < 0x100 | ||
69 | * add, sub, eor...: ditto | ||
70 | */ | ||
71 | -static inline int tcg_target_const_match(tcg_target_long val, TCGType type, | ||
72 | - const TCGArgConstraint *arg_ct) | ||
73 | +static bool tcg_target_const_match(int64_t val, TCGType type, int ct) | ||
74 | { | ||
75 | - int ct; | ||
76 | - ct = arg_ct->ct; | ||
77 | if (ct & TCG_CT_CONST) { | ||
78 | return 1; | ||
79 | } else if ((ct & TCG_CT_CONST_ARM) && check_fit_imm(val)) { | ||
80 | diff --git a/tcg/i386/tcg-target.c.inc b/tcg/i386/tcg-target.c.inc | ||
81 | index XXXXXXX..XXXXXXX 100644 | ||
82 | --- a/tcg/i386/tcg-target.c.inc | ||
83 | +++ b/tcg/i386/tcg-target.c.inc | ||
84 | @@ -XXX,XX +XXX,XX @@ static bool patch_reloc(tcg_insn_unit *code_ptr, int type, | ||
85 | } | ||
86 | |||
87 | /* test if a constant matches the constraint */ | ||
88 | -static inline int tcg_target_const_match(tcg_target_long val, TCGType type, | ||
89 | - const TCGArgConstraint *arg_ct) | ||
90 | +static bool tcg_target_const_match(int64_t val, TCGType type, int ct) | ||
91 | { | ||
92 | - int ct = arg_ct->ct; | ||
93 | if (ct & TCG_CT_CONST) { | ||
94 | return 1; | ||
95 | } | ||
96 | diff --git a/tcg/mips/tcg-target.c.inc b/tcg/mips/tcg-target.c.inc | ||
97 | index XXXXXXX..XXXXXXX 100644 | ||
98 | --- a/tcg/mips/tcg-target.c.inc | ||
99 | +++ b/tcg/mips/tcg-target.c.inc | ||
100 | @@ -XXX,XX +XXX,XX @@ static inline bool is_p2m1(tcg_target_long val) | ||
101 | } | ||
102 | |||
103 | /* test if a constant matches the constraint */ | ||
104 | -static inline int tcg_target_const_match(tcg_target_long val, TCGType type, | ||
105 | - const TCGArgConstraint *arg_ct) | ||
106 | +static bool tcg_target_const_match(int64_t val, TCGType type, int ct) | ||
107 | { | ||
108 | - int ct; | ||
109 | - ct = arg_ct->ct; | ||
110 | if (ct & TCG_CT_CONST) { | ||
111 | return 1; | ||
112 | } else if ((ct & TCG_CT_CONST_ZERO) && val == 0) { | ||
113 | diff --git a/tcg/ppc/tcg-target.c.inc b/tcg/ppc/tcg-target.c.inc | ||
114 | index XXXXXXX..XXXXXXX 100644 | ||
115 | --- a/tcg/ppc/tcg-target.c.inc | ||
116 | +++ b/tcg/ppc/tcg-target.c.inc | ||
117 | @@ -XXX,XX +XXX,XX @@ static bool reloc_pc14(tcg_insn_unit *src_rw, const tcg_insn_unit *target) | ||
118 | } | ||
119 | |||
120 | /* test if a constant matches the constraint */ | ||
121 | -static int tcg_target_const_match(tcg_target_long val, TCGType type, | ||
122 | - const TCGArgConstraint *arg_ct) | ||
123 | +static bool tcg_target_const_match(int64_t val, TCGType type, int ct) | ||
124 | { | ||
125 | - int ct = arg_ct->ct; | ||
126 | if (ct & TCG_CT_CONST) { | ||
127 | return 1; | ||
128 | } | ||
129 | diff --git a/tcg/riscv/tcg-target.c.inc b/tcg/riscv/tcg-target.c.inc | ||
130 | index XXXXXXX..XXXXXXX 100644 | ||
131 | --- a/tcg/riscv/tcg-target.c.inc | ||
132 | +++ b/tcg/riscv/tcg-target.c.inc | ||
133 | @@ -XXX,XX +XXX,XX @@ static inline tcg_target_long sextreg(tcg_target_long val, int pos, int len) | ||
134 | } | ||
135 | |||
136 | /* test if a constant matches the constraint */ | ||
137 | -static int tcg_target_const_match(tcg_target_long val, TCGType type, | ||
138 | - const TCGArgConstraint *arg_ct) | ||
139 | +static bool tcg_target_const_match(int64_t val, TCGType type, int ct) | ||
140 | { | ||
141 | - int ct = arg_ct->ct; | ||
142 | if (ct & TCG_CT_CONST) { | ||
143 | return 1; | ||
144 | } | ||
145 | diff --git a/tcg/s390/tcg-target.c.inc b/tcg/s390/tcg-target.c.inc | ||
146 | index XXXXXXX..XXXXXXX 100644 | ||
147 | --- a/tcg/s390/tcg-target.c.inc | ||
148 | +++ b/tcg/s390/tcg-target.c.inc | ||
149 | @@ -XXX,XX +XXX,XX @@ static bool patch_reloc(tcg_insn_unit *src_rw, int type, | ||
150 | } | ||
151 | |||
152 | /* Test if a constant matches the constraint. */ | ||
153 | -static int tcg_target_const_match(tcg_target_long val, TCGType type, | ||
154 | - const TCGArgConstraint *arg_ct) | ||
155 | +static bool tcg_target_const_match(int64_t val, TCGType type, int ct) | ||
156 | { | ||
157 | - int ct = arg_ct->ct; | ||
158 | - | ||
159 | if (ct & TCG_CT_CONST) { | ||
160 | return 1; | ||
161 | } | ||
162 | diff --git a/tcg/sparc/tcg-target.c.inc b/tcg/sparc/tcg-target.c.inc | ||
163 | index XXXXXXX..XXXXXXX 100644 | ||
164 | --- a/tcg/sparc/tcg-target.c.inc | ||
165 | +++ b/tcg/sparc/tcg-target.c.inc | ||
166 | @@ -XXX,XX +XXX,XX @@ static bool patch_reloc(tcg_insn_unit *src_rw, int type, | ||
167 | } | ||
168 | |||
169 | /* test if a constant matches the constraint */ | ||
170 | -static inline int tcg_target_const_match(tcg_target_long val, TCGType type, | ||
171 | - const TCGArgConstraint *arg_ct) | ||
172 | +static bool tcg_target_const_match(int64_t val, TCGType type, int ct) | ||
173 | { | ||
174 | - int ct = arg_ct->ct; | ||
175 | - | ||
176 | if (ct & TCG_CT_CONST) { | ||
177 | return 1; | ||
178 | } | ||
179 | diff --git a/tcg/tci/tcg-target.c.inc b/tcg/tci/tcg-target.c.inc | ||
180 | index XXXXXXX..XXXXXXX 100644 | ||
181 | --- a/tcg/tci/tcg-target.c.inc | ||
182 | +++ b/tcg/tci/tcg-target.c.inc | ||
183 | @@ -XXX,XX +XXX,XX @@ static inline bool tcg_out_sti(TCGContext *s, TCGType type, TCGArg val, | ||
184 | } | ||
185 | |||
186 | /* Test if a constant matches the constraint. */ | ||
187 | -static int tcg_target_const_match(tcg_target_long val, TCGType type, | ||
188 | - const TCGArgConstraint *arg_ct) | ||
189 | +static bool tcg_target_const_match(int64_t val, TCGType type, int ct) | ||
190 | { | ||
191 | - /* No need to return 0 or 1, 0 or != 0 is good enough. */ | ||
192 | - return arg_ct->ct & TCG_CT_CONST; | ||
193 | + return ct & TCG_CT_CONST; | ||
194 | } | ||
195 | |||
196 | static void tcg_target_init(TCGContext *s) | ||
197 | -- | ||
198 | 2.25.1 | ||
199 | |||
200 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | Add registers and function stubs. The functionality | |
2 | is disabled via use_neon_instructions defined to 0. | ||
3 | |||
4 | We must still include results for the mandatory opcodes in | ||
5 | tcg_target_op_def, as all opcodes are checked during tcg init. | ||
6 | |||
7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
9 | --- | ||
10 | tcg/arm/tcg-target-con-set.h | 4 ++ | ||
11 | tcg/arm/tcg-target-con-str.h | 1 + | ||
12 | tcg/arm/tcg-target.h | 48 ++++++++++++-- | ||
13 | tcg/arm/tcg-target.opc.h | 12 ++++ | ||
14 | tcg/arm/tcg-target.c.inc | 117 +++++++++++++++++++++++++++++------ | ||
15 | 5 files changed, 158 insertions(+), 24 deletions(-) | ||
16 | create mode 100644 tcg/arm/tcg-target.opc.h | ||
17 | |||
18 | diff --git a/tcg/arm/tcg-target-con-set.h b/tcg/arm/tcg-target-con-set.h | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/tcg/arm/tcg-target-con-set.h | ||
21 | +++ b/tcg/arm/tcg-target-con-set.h | ||
22 | @@ -XXX,XX +XXX,XX @@ C_O0_I1(r) | ||
23 | C_O0_I2(r, r) | ||
24 | C_O0_I2(r, rIN) | ||
25 | C_O0_I2(s, s) | ||
26 | +C_O0_I2(w, r) | ||
27 | C_O0_I3(s, s, s) | ||
28 | C_O0_I4(r, r, rI, rI) | ||
29 | C_O0_I4(s, s, s, s) | ||
30 | C_O1_I1(r, l) | ||
31 | C_O1_I1(r, r) | ||
32 | +C_O1_I1(w, r) | ||
33 | +C_O1_I1(w, wr) | ||
34 | C_O1_I2(r, 0, rZ) | ||
35 | C_O1_I2(r, l, l) | ||
36 | C_O1_I2(r, r, r) | ||
37 | @@ -XXX,XX +XXX,XX @@ C_O1_I2(r, r, rIK) | ||
38 | C_O1_I2(r, r, rIN) | ||
39 | C_O1_I2(r, r, ri) | ||
40 | C_O1_I2(r, rZ, rZ) | ||
41 | +C_O1_I2(w, w, w) | ||
42 | C_O1_I4(r, r, r, rI, rI) | ||
43 | C_O1_I4(r, r, rIN, rIK, 0) | ||
44 | C_O2_I1(r, r, l) | ||
45 | diff --git a/tcg/arm/tcg-target-con-str.h b/tcg/arm/tcg-target-con-str.h | ||
46 | index XXXXXXX..XXXXXXX 100644 | ||
47 | --- a/tcg/arm/tcg-target-con-str.h | ||
48 | +++ b/tcg/arm/tcg-target-con-str.h | ||
49 | @@ -XXX,XX +XXX,XX @@ | ||
50 | REGS('r', ALL_GENERAL_REGS) | ||
51 | REGS('l', ALL_QLOAD_REGS) | ||
52 | REGS('s', ALL_QSTORE_REGS) | ||
53 | +REGS('w', ALL_VECTOR_REGS) | ||
54 | |||
55 | /* | ||
56 | * Define constraint letters for constants: | ||
57 | diff --git a/tcg/arm/tcg-target.h b/tcg/arm/tcg-target.h | ||
58 | index XXXXXXX..XXXXXXX 100644 | ||
59 | --- a/tcg/arm/tcg-target.h | ||
60 | +++ b/tcg/arm/tcg-target.h | ||
61 | @@ -XXX,XX +XXX,XX @@ typedef enum { | ||
62 | TCG_REG_R13, | ||
63 | TCG_REG_R14, | ||
64 | TCG_REG_PC, | ||
65 | + | ||
66 | + TCG_REG_Q0, | ||
67 | + TCG_REG_Q1, | ||
68 | + TCG_REG_Q2, | ||
69 | + TCG_REG_Q3, | ||
70 | + TCG_REG_Q4, | ||
71 | + TCG_REG_Q5, | ||
72 | + TCG_REG_Q6, | ||
73 | + TCG_REG_Q7, | ||
74 | + TCG_REG_Q8, | ||
75 | + TCG_REG_Q9, | ||
76 | + TCG_REG_Q10, | ||
77 | + TCG_REG_Q11, | ||
78 | + TCG_REG_Q12, | ||
79 | + TCG_REG_Q13, | ||
80 | + TCG_REG_Q14, | ||
81 | + TCG_REG_Q15, | ||
82 | + | ||
83 | + TCG_AREG0 = TCG_REG_R6, | ||
84 | + TCG_REG_CALL_STACK = TCG_REG_R13, | ||
85 | } TCGReg; | ||
86 | |||
87 | -#define TCG_TARGET_NB_REGS 16 | ||
88 | +#define TCG_TARGET_NB_REGS 32 | ||
89 | |||
90 | #ifdef __ARM_ARCH_EXT_IDIV__ | ||
91 | #define use_idiv_instructions 1 | ||
92 | #else | ||
93 | extern bool use_idiv_instructions; | ||
94 | #endif | ||
95 | - | ||
96 | +#define use_neon_instructions 0 | ||
97 | |||
98 | /* used for function call generation */ | ||
99 | -#define TCG_REG_CALL_STACK TCG_REG_R13 | ||
100 | #define TCG_TARGET_STACK_ALIGN 8 | ||
101 | #define TCG_TARGET_CALL_ALIGN_ARGS 1 | ||
102 | #define TCG_TARGET_CALL_STACK_OFFSET 0 | ||
103 | @@ -XXX,XX +XXX,XX @@ extern bool use_idiv_instructions; | ||
104 | #define TCG_TARGET_HAS_direct_jump 0 | ||
105 | #define TCG_TARGET_HAS_qemu_st8_i32 0 | ||
106 | |||
107 | -enum { | ||
108 | - TCG_AREG0 = TCG_REG_R6, | ||
109 | -}; | ||
110 | +#define TCG_TARGET_HAS_v64 use_neon_instructions | ||
111 | +#define TCG_TARGET_HAS_v128 use_neon_instructions | ||
112 | +#define TCG_TARGET_HAS_v256 0 | ||
113 | + | ||
114 | +#define TCG_TARGET_HAS_andc_vec 0 | ||
115 | +#define TCG_TARGET_HAS_orc_vec 0 | ||
116 | +#define TCG_TARGET_HAS_not_vec 0 | ||
117 | +#define TCG_TARGET_HAS_neg_vec 0 | ||
118 | +#define TCG_TARGET_HAS_abs_vec 0 | ||
119 | +#define TCG_TARGET_HAS_roti_vec 0 | ||
120 | +#define TCG_TARGET_HAS_rots_vec 0 | ||
121 | +#define TCG_TARGET_HAS_rotv_vec 0 | ||
122 | +#define TCG_TARGET_HAS_shi_vec 0 | ||
123 | +#define TCG_TARGET_HAS_shs_vec 0 | ||
124 | +#define TCG_TARGET_HAS_shv_vec 0 | ||
125 | +#define TCG_TARGET_HAS_mul_vec 0 | ||
126 | +#define TCG_TARGET_HAS_sat_vec 0 | ||
127 | +#define TCG_TARGET_HAS_minmax_vec 0 | ||
128 | +#define TCG_TARGET_HAS_bitsel_vec 0 | ||
129 | +#define TCG_TARGET_HAS_cmpsel_vec 0 | ||
130 | |||
131 | #define TCG_TARGET_DEFAULT_MO (0) | ||
132 | #define TCG_TARGET_HAS_MEMORY_BSWAP 1 | ||
133 | diff --git a/tcg/arm/tcg-target.opc.h b/tcg/arm/tcg-target.opc.h | ||
134 | new file mode 100644 | ||
135 | index XXXXXXX..XXXXXXX | ||
136 | --- /dev/null | ||
137 | +++ b/tcg/arm/tcg-target.opc.h | ||
138 | @@ -XXX,XX +XXX,XX @@ | ||
139 | +/* | ||
140 | + * Copyright (c) 2019 Linaro | ||
141 | + * | ||
142 | + * This work is licensed under the terms of the GNU GPL, version 2 or | ||
143 | + * (at your option) any later version. | ||
144 | + * | ||
145 | + * See the COPYING file in the top-level directory for details. | ||
146 | + * | ||
147 | + * Target-specific opcodes for host vector expansion. These will be | ||
148 | + * emitted by tcg_expand_vec_op. For those familiar with GCC internals, | ||
149 | + * consider these to be UNSPEC with names. | ||
150 | + */ | ||
151 | diff --git a/tcg/arm/tcg-target.c.inc b/tcg/arm/tcg-target.c.inc | ||
152 | index XXXXXXX..XXXXXXX 100644 | ||
153 | --- a/tcg/arm/tcg-target.c.inc | ||
154 | +++ b/tcg/arm/tcg-target.c.inc | ||
155 | @@ -XXX,XX +XXX,XX @@ bool use_idiv_instructions; | ||
156 | |||
157 | #ifdef CONFIG_DEBUG_TCG | ||
158 | static const char * const tcg_target_reg_names[TCG_TARGET_NB_REGS] = { | ||
159 | - "%r0", | ||
160 | - "%r1", | ||
161 | - "%r2", | ||
162 | - "%r3", | ||
163 | - "%r4", | ||
164 | - "%r5", | ||
165 | - "%r6", | ||
166 | - "%r7", | ||
167 | - "%r8", | ||
168 | - "%r9", | ||
169 | - "%r10", | ||
170 | - "%r11", | ||
171 | - "%r12", | ||
172 | - "%r13", | ||
173 | - "%r14", | ||
174 | - "%pc", | ||
175 | + "%r0", "%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7", | ||
176 | + "%r8", "%r9", "%r10", "%r11", "%r12", "%sp", "%r14", "%pc", | ||
177 | + "%q0", "%q1", "%q2", "%q3", "%q4", "%q5", "%q6", "%q7", | ||
178 | + "%q8", "%q9", "%q10", "%q11", "%q12", "%q13", "%q14", "%q15", | ||
179 | }; | ||
180 | #endif | ||
181 | |||
182 | @@ -XXX,XX +XXX,XX @@ static const int tcg_target_reg_alloc_order[] = { | ||
183 | TCG_REG_R3, | ||
184 | TCG_REG_R12, | ||
185 | TCG_REG_R14, | ||
186 | + | ||
187 | + TCG_REG_Q0, | ||
188 | + TCG_REG_Q1, | ||
189 | + TCG_REG_Q2, | ||
190 | + TCG_REG_Q3, | ||
191 | + /* Q4 - Q7 are call-saved, and skipped. */ | ||
192 | + TCG_REG_Q8, | ||
193 | + TCG_REG_Q9, | ||
194 | + TCG_REG_Q10, | ||
195 | + TCG_REG_Q11, | ||
196 | + TCG_REG_Q12, | ||
197 | + TCG_REG_Q13, | ||
198 | + TCG_REG_Q14, | ||
199 | + TCG_REG_Q15, | ||
200 | }; | ||
201 | |||
202 | static const int tcg_target_call_iarg_regs[4] = { | ||
203 | @@ -XXX,XX +XXX,XX @@ static const int tcg_target_call_oarg_regs[2] = { | ||
204 | }; | ||
205 | |||
206 | #define TCG_REG_TMP TCG_REG_R12 | ||
207 | +#define TCG_VEC_TMP TCG_REG_Q15 | ||
208 | |||
209 | enum arm_cond_code_e { | ||
210 | COND_EQ = 0x0, | ||
211 | @@ -XXX,XX +XXX,XX @@ static bool patch_reloc(tcg_insn_unit *code_ptr, int type, | ||
212 | #define TCG_CT_CONST_ZERO 0x800 | ||
213 | |||
214 | #define ALL_GENERAL_REGS 0xffffu | ||
215 | +#define ALL_VECTOR_REGS 0xffff0000u | ||
216 | |||
217 | /* | ||
218 | * r0-r2 will be overwritten when reading the tlb entry (softmmu only) | ||
219 | @@ -XXX,XX +XXX,XX @@ static TCGConstraintSetIndex tcg_target_op_def(TCGOpcode op) | ||
220 | case INDEX_op_qemu_st_i64: | ||
221 | return TARGET_LONG_BITS == 32 ? C_O0_I3(s, s, s) : C_O0_I4(s, s, s, s); | ||
222 | |||
223 | + case INDEX_op_st_vec: | ||
224 | + return C_O0_I2(w, r); | ||
225 | + case INDEX_op_ld_vec: | ||
226 | + case INDEX_op_dupm_vec: | ||
227 | + return C_O1_I1(w, r); | ||
228 | + case INDEX_op_dup_vec: | ||
229 | + return C_O1_I1(w, wr); | ||
230 | + case INDEX_op_dup2_vec: | ||
231 | + case INDEX_op_add_vec: | ||
232 | + case INDEX_op_sub_vec: | ||
233 | + case INDEX_op_xor_vec: | ||
234 | + case INDEX_op_or_vec: | ||
235 | + case INDEX_op_and_vec: | ||
236 | + case INDEX_op_cmp_vec: | ||
237 | + return C_O1_I2(w, w, w); | ||
238 | + | ||
239 | default: | ||
240 | g_assert_not_reached(); | ||
241 | } | ||
242 | @@ -XXX,XX +XXX,XX @@ static void tcg_target_init(TCGContext *s) | ||
243 | { | ||
244 | /* Only probe for the platform and capabilities if we havn't already | ||
245 | determined maximum values at compile time. */ | ||
246 | -#ifndef use_idiv_instructions | ||
247 | +#if !defined(use_idiv_instructions) || !defined(use_neon_instructions) | ||
248 | { | ||
249 | unsigned long hwcap = qemu_getauxval(AT_HWCAP); | ||
250 | +#ifndef use_idiv_instructions | ||
251 | use_idiv_instructions = (hwcap & HWCAP_ARM_IDIVA) != 0; | ||
252 | +#endif | ||
253 | +#ifndef use_neon_instructions | ||
254 | + use_neon_instructions = (hwcap & HWCAP_ARM_NEON) != 0; | ||
255 | +#endif | ||
256 | } | ||
257 | #endif | ||
258 | + | ||
259 | if (__ARM_ARCH < 7) { | ||
260 | const char *pl = (const char *)qemu_getauxval(AT_PLATFORM); | ||
261 | if (pl != NULL && pl[0] == 'v' && pl[1] >= '4' && pl[1] <= '9') { | ||
262 | @@ -XXX,XX +XXX,XX @@ static void tcg_target_init(TCGContext *s) | ||
263 | } | ||
264 | } | ||
265 | |||
266 | - tcg_target_available_regs[TCG_TYPE_I32] = 0xffff; | ||
267 | + tcg_target_available_regs[TCG_TYPE_I32] = ALL_GENERAL_REGS; | ||
268 | |||
269 | tcg_target_call_clobber_regs = 0; | ||
270 | tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R0); | ||
271 | @@ -XXX,XX +XXX,XX @@ static void tcg_target_init(TCGContext *s) | ||
272 | tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R12); | ||
273 | tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_R14); | ||
274 | |||
275 | + if (use_neon_instructions) { | ||
276 | + tcg_target_available_regs[TCG_TYPE_V64] = ALL_VECTOR_REGS; | ||
277 | + tcg_target_available_regs[TCG_TYPE_V128] = ALL_VECTOR_REGS; | ||
278 | + | ||
279 | + tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_Q0); | ||
280 | + tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_Q1); | ||
281 | + tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_Q2); | ||
282 | + tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_Q3); | ||
283 | + tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_Q8); | ||
284 | + tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_Q9); | ||
285 | + tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_Q10); | ||
286 | + tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_Q11); | ||
287 | + tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_Q12); | ||
288 | + tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_Q13); | ||
289 | + tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_Q14); | ||
290 | + tcg_regset_set_reg(tcg_target_call_clobber_regs, TCG_REG_Q15); | ||
291 | + } | ||
292 | + | ||
293 | s->reserved_regs = 0; | ||
294 | tcg_regset_set_reg(s->reserved_regs, TCG_REG_CALL_STACK); | ||
295 | tcg_regset_set_reg(s->reserved_regs, TCG_REG_TMP); | ||
296 | tcg_regset_set_reg(s->reserved_regs, TCG_REG_PC); | ||
297 | + tcg_regset_set_reg(s->reserved_regs, TCG_VEC_TMP); | ||
298 | } | ||
299 | |||
300 | static inline void tcg_out_ld(TCGContext *s, TCGType type, TCGReg arg, | ||
301 | @@ -XXX,XX +XXX,XX @@ static inline void tcg_out_movi(TCGContext *s, TCGType type, | ||
302 | tcg_out_movi32(s, COND_AL, ret, arg); | ||
303 | } | ||
304 | |||
305 | +static bool tcg_out_dup_vec(TCGContext *s, TCGType type, unsigned vece, | ||
306 | + TCGReg rd, TCGReg rs) | ||
307 | +{ | ||
308 | + g_assert_not_reached(); | ||
309 | +} | ||
310 | + | ||
311 | +static bool tcg_out_dupm_vec(TCGContext *s, TCGType type, unsigned vece, | ||
312 | + TCGReg rd, TCGReg base, intptr_t offset) | ||
313 | +{ | ||
314 | + g_assert_not_reached(); | ||
315 | +} | ||
316 | + | ||
317 | +static void tcg_out_dupi_vec(TCGContext *s, TCGType type, unsigned vece, | ||
318 | + TCGReg rd, int64_t v64) | ||
319 | +{ | ||
320 | + g_assert_not_reached(); | ||
321 | +} | ||
322 | + | ||
323 | +static void tcg_out_vec_op(TCGContext *s, TCGOpcode opc, | ||
324 | + unsigned vecl, unsigned vece, | ||
325 | + const TCGArg *args, const int *const_args) | ||
326 | +{ | ||
327 | + g_assert_not_reached(); | ||
328 | +} | ||
329 | + | ||
330 | +int tcg_can_emit_vec_op(TCGOpcode opc, TCGType type, unsigned vece) | ||
331 | +{ | ||
332 | + return 0; | ||
333 | +} | ||
334 | + | ||
335 | +void tcg_expand_vec_op(TCGOpcode opc, TCGType type, unsigned vece, | ||
336 | + TCGArg a0, ...) | ||
337 | +{ | ||
338 | + g_assert_not_reached(); | ||
339 | +} | ||
340 | + | ||
341 | static void tcg_out_nop_fill(tcg_insn_unit *p, int count) | ||
342 | { | ||
343 | int i; | ||
344 | -- | ||
345 | 2.25.1 | ||
346 | |||
347 | diff view generated by jsdifflib |
1 | From: Claudio Fontana <cfontana@suse.de> | 1 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
---|---|---|---|
2 | |||
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> | 2 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
7 | --- | 3 | --- |
8 | accel/tcg/tcg-cpus-icount.h | 6 +-- | 4 | tcg/arm/tcg-target.c.inc | 70 ++++++++++++++++++++++++++++++++++++---- |
9 | accel/tcg/tcg-cpus-rr.h | 2 +- | 5 | 1 file changed, 64 insertions(+), 6 deletions(-) |
10 | accel/tcg/tcg-cpus.h | 6 +-- | ||
11 | accel/tcg/tcg-cpus-icount.c | 24 ++++++------ | ||
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 | 6 | ||
17 | diff --git a/accel/tcg/tcg-cpus-icount.h b/accel/tcg/tcg-cpus-icount.h | 7 | diff --git a/tcg/arm/tcg-target.c.inc b/tcg/arm/tcg-target.c.inc |
18 | index XXXXXXX..XXXXXXX 100644 | 8 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/accel/tcg/tcg-cpus-icount.h | 9 | --- a/tcg/arm/tcg-target.c.inc |
20 | +++ b/accel/tcg/tcg-cpus-icount.h | 10 | +++ b/tcg/arm/tcg-target.c.inc |
21 | @@ -XXX,XX +XXX,XX @@ | 11 | @@ -XXX,XX +XXX,XX @@ typedef enum { |
22 | #ifndef TCG_CPUS_ICOUNT_H | 12 | INSN_NOP_v6k = 0xe320f000, |
23 | #define TCG_CPUS_ICOUNT_H | 13 | /* Otherwise the assembler uses mov r0,r0 */ |
24 | 14 | INSN_NOP_v4 = (COND_AL << 28) | ARITH_MOV, | |
25 | -void handle_icount_deadline(void); | 15 | + |
26 | -void prepare_icount_for_run(CPUState *cpu); | 16 | + INSN_VLD1 = 0xf4200000, /* VLD1 (multiple single elements) */ |
27 | -void process_icount_data(CPUState *cpu); | 17 | + INSN_VST1 = 0xf4000000, /* VST1 (multiple single elements) */ |
28 | +void icount_handle_deadline(void); | 18 | } ARMInsn; |
29 | +void icount_prepare_for_run(CPUState *cpu); | 19 | |
30 | +void icount_process_data(CPUState *cpu); | 20 | #define INSN_NOP (use_armv7_instructions ? INSN_NOP_v6k : INSN_NOP_v4) |
31 | 21 | @@ -XXX,XX +XXX,XX @@ static TCGCond tcg_out_cmp2(TCGContext *s, const TCGArg *args, | |
32 | #endif /* TCG_CPUS_ICOUNT_H */ | ||
33 | diff --git a/accel/tcg/tcg-cpus-rr.h b/accel/tcg/tcg-cpus-rr.h | ||
34 | index XXXXXXX..XXXXXXX 100644 | ||
35 | --- a/accel/tcg/tcg-cpus-rr.h | ||
36 | +++ b/accel/tcg/tcg-cpus-rr.h | ||
37 | @@ -XXX,XX +XXX,XX @@ | ||
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 | } | 22 | } |
77 | } | 23 | } |
78 | 24 | ||
79 | -static void notify_aio_contexts(void) | 25 | +/* |
80 | +static void icount_notify_aio_contexts(void) | 26 | + * Note that TCGReg references Q-registers. |
27 | + * Q-regno = 2 * D-regno, so shift left by 1 whlie inserting. | ||
28 | + */ | ||
29 | +static uint32_t encode_vd(TCGReg rd) | ||
30 | +{ | ||
31 | + tcg_debug_assert(rd >= TCG_REG_Q0); | ||
32 | + return (extract32(rd, 3, 1) << 22) | (extract32(rd, 0, 3) << 13); | ||
33 | +} | ||
34 | + | ||
35 | +static void tcg_out_vldst(TCGContext *s, ARMInsn insn, | ||
36 | + TCGReg rd, TCGReg rn, int offset) | ||
37 | +{ | ||
38 | + if (offset != 0) { | ||
39 | + if (check_fit_imm(offset) || check_fit_imm(-offset)) { | ||
40 | + tcg_out_dat_rIN(s, COND_AL, ARITH_ADD, ARITH_SUB, | ||
41 | + TCG_REG_TMP, rn, offset, true); | ||
42 | + } else { | ||
43 | + tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_TMP, offset); | ||
44 | + tcg_out_dat_reg(s, COND_AL, ARITH_ADD, | ||
45 | + TCG_REG_TMP, TCG_REG_TMP, rn, 0); | ||
46 | + } | ||
47 | + rn = TCG_REG_TMP; | ||
48 | + } | ||
49 | + tcg_out32(s, insn | (rn << 16) | encode_vd(rd) | 0xf); | ||
50 | +} | ||
51 | + | ||
52 | #ifdef CONFIG_SOFTMMU | ||
53 | #include "../tcg-ldst.c.inc" | ||
54 | |||
55 | @@ -XXX,XX +XXX,XX @@ static void tcg_target_init(TCGContext *s) | ||
56 | tcg_regset_set_reg(s->reserved_regs, TCG_VEC_TMP); | ||
57 | } | ||
58 | |||
59 | -static inline void tcg_out_ld(TCGContext *s, TCGType type, TCGReg arg, | ||
60 | - TCGReg arg1, intptr_t arg2) | ||
61 | +static void tcg_out_ld(TCGContext *s, TCGType type, TCGReg arg, | ||
62 | + TCGReg arg1, intptr_t arg2) | ||
81 | { | 63 | { |
82 | /* Wake up other AioContexts. */ | 64 | - tcg_out_ld32u(s, COND_AL, arg, arg1, arg2); |
83 | qemu_clock_notify(QEMU_CLOCK_VIRTUAL); | 65 | + switch (type) { |
84 | qemu_clock_run_timers(QEMU_CLOCK_VIRTUAL); | 66 | + case TCG_TYPE_I32: |
67 | + tcg_out_ld32u(s, COND_AL, arg, arg1, arg2); | ||
68 | + return; | ||
69 | + case TCG_TYPE_V64: | ||
70 | + /* regs 1; size 8; align 8 */ | ||
71 | + tcg_out_vldst(s, INSN_VLD1 | 0x7d0, arg, arg1, arg2); | ||
72 | + return; | ||
73 | + case TCG_TYPE_V128: | ||
74 | + /* regs 2; size 8; align 16 */ | ||
75 | + tcg_out_vldst(s, INSN_VLD1 | 0xae0, arg, arg1, arg2); | ||
76 | + return; | ||
77 | + default: | ||
78 | + g_assert_not_reached(); | ||
79 | + } | ||
85 | } | 80 | } |
86 | 81 | ||
87 | -void handle_icount_deadline(void) | 82 | -static inline void tcg_out_st(TCGContext *s, TCGType type, TCGReg arg, |
88 | +void icount_handle_deadline(void) | 83 | - TCGReg arg1, intptr_t arg2) |
84 | +static void tcg_out_st(TCGContext *s, TCGType type, TCGReg arg, | ||
85 | + TCGReg arg1, intptr_t arg2) | ||
89 | { | 86 | { |
90 | assert(qemu_in_vcpu_thread()); | 87 | - tcg_out_st32(s, COND_AL, arg, arg1, arg2); |
91 | int64_t deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL, | 88 | + switch (type) { |
92 | QEMU_TIMER_ATTR_ALL); | 89 | + case TCG_TYPE_I32: |
93 | 90 | + tcg_out_st32(s, COND_AL, arg, arg1, arg2); | |
94 | if (deadline == 0) { | 91 | + return; |
95 | - notify_aio_contexts(); | 92 | + case TCG_TYPE_V64: |
96 | + icount_notify_aio_contexts(); | 93 | + /* regs 1; size 8; align 8 */ |
97 | } | 94 | + tcg_out_vldst(s, INSN_VST1 | 0x7d0, arg, arg1, arg2); |
95 | + return; | ||
96 | + case TCG_TYPE_V128: | ||
97 | + /* regs 2; size 8; align 16 */ | ||
98 | + tcg_out_vldst(s, INSN_VST1 | 0xae0, arg, arg1, arg2); | ||
99 | + return; | ||
100 | + default: | ||
101 | + g_assert_not_reached(); | ||
102 | + } | ||
98 | } | 103 | } |
99 | 104 | ||
100 | -void prepare_icount_for_run(CPUState *cpu) | 105 | static inline bool tcg_out_sti(TCGContext *s, TCGType type, TCGArg val, |
101 | +void icount_prepare_for_run(CPUState *cpu) | ||
102 | { | ||
103 | int insns_left; | ||
104 | |||
105 | /* | ||
106 | - * These should always be cleared by process_icount_data after | ||
107 | + * These should always be cleared by icount_process_data after | ||
108 | * each vCPU execution. However u16.high can be raised | ||
109 | - * asynchronously by cpu_exit/cpu_interrupt/tcg_handle_interrupt | ||
110 | + * asynchronously by cpu_exit/cpu_interrupt/tcg_cpus_handle_interrupt | ||
111 | */ | ||
112 | g_assert(cpu_neg(cpu)->icount_decr.u16.low == 0); | ||
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 | } | ||
128 | |||
129 | -void process_icount_data(CPUState *cpu) | ||
130 | +void icount_process_data(CPUState *cpu) | ||
131 | { | ||
132 | /* Account for executed instructions */ | ||
133 | icount_update(cpu); | ||
134 | @@ -XXX,XX +XXX,XX @@ static void icount_handle_interrupt(CPUState *cpu, int mask) | ||
135 | { | ||
136 | int old_mask = cpu->interrupt_request; | ||
137 | |||
138 | - tcg_handle_interrupt(cpu, mask); | ||
139 | + tcg_cpus_handle_interrupt(cpu, mask); | ||
140 | if (qemu_cpu_is_self(cpu) && | ||
141 | !cpu->can_do_io | ||
142 | && (mask & ~old_mask) != 0) { | ||
143 | @@ -XXX,XX +XXX,XX @@ static void icount_handle_interrupt(CPUState *cpu, int mask) | ||
144 | |||
145 | const CpusAccel tcg_cpus_icount = { | ||
146 | .create_vcpu_thread = rr_start_vcpu_thread, | ||
147 | - .kick_vcpu_thread = qemu_cpu_kick_rr_cpus, | ||
148 | + .kick_vcpu_thread = rr_kick_vcpu_thread, | ||
149 | |||
150 | .handle_interrupt = icount_handle_interrupt, | ||
151 | .get_virtual_clock = icount_get, | ||
152 | diff --git a/accel/tcg/tcg-cpus-mttcg.c b/accel/tcg/tcg-cpus-mttcg.c | ||
153 | index XXXXXXX..XXXXXXX 100644 | ||
154 | --- a/accel/tcg/tcg-cpus-mttcg.c | ||
155 | +++ b/accel/tcg/tcg-cpus-mttcg.c | ||
156 | @@ -XXX,XX +XXX,XX @@ | ||
157 | * current CPUState for a given thread. | ||
158 | */ | ||
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 | */ | ||
334 | - handle_icount_deadline(); | ||
335 | + icount_handle_deadline(); | ||
336 | } | ||
337 | |||
338 | replay_mutex_unlock(); | ||
339 | @@ -XXX,XX +XXX,XX @@ static void *tcg_rr_cpu_thread_fn(void *arg) | ||
340 | |||
341 | while (cpu && cpu_work_list_empty(cpu) && !cpu->exit_request) { | ||
342 | |||
343 | - qatomic_mb_set(&tcg_current_rr_cpu, cpu); | ||
344 | + qatomic_mb_set(&rr_current_cpu, cpu); | ||
345 | current_cpu = cpu; | ||
346 | |||
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 | |||
430 | -- | 106 | -- |
431 | 2.25.1 | 107 | 2.25.1 |
432 | 108 | ||
433 | 109 | diff view generated by jsdifflib |
1 | From: Claudio Fontana <cfontana@suse.de> | 1 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
---|---|---|---|
2 | |||
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> | 2 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
15 | --- | 3 | --- |
16 | accel/tcg/tcg-cpus-icount.h | 17 ++ | 4 | tcg/arm/tcg-target.c.inc | 52 +++++++++++++++++++++++++++++++++++----- |
17 | accel/tcg/tcg-cpus-mttcg.h | 21 ++ | 5 | 1 file changed, 46 insertions(+), 6 deletions(-) |
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 | 6 | ||
35 | diff --git a/accel/tcg/tcg-cpus-icount.h b/accel/tcg/tcg-cpus-icount.h | 7 | diff --git a/tcg/arm/tcg-target.c.inc b/tcg/arm/tcg-target.c.inc |
36 | new file mode 100644 | 8 | index XXXXXXX..XXXXXXX 100644 |
37 | index XXXXXXX..XXXXXXX | 9 | --- a/tcg/arm/tcg-target.c.inc |
38 | --- /dev/null | 10 | +++ b/tcg/arm/tcg-target.c.inc |
39 | +++ b/accel/tcg/tcg-cpus-icount.h | 11 | @@ -XXX,XX +XXX,XX @@ typedef enum { |
40 | @@ -XXX,XX +XXX,XX @@ | 12 | /* Otherwise the assembler uses mov r0,r0 */ |
41 | +/* | 13 | INSN_NOP_v4 = (COND_AL << 28) | ARITH_MOV, |
42 | + * QEMU TCG Single Threaded vCPUs implementation using instruction counting | 14 | |
43 | + * | 15 | + INSN_VORR = 0xf2200110, |
44 | + * Copyright 2020 SUSE LLC | ||
45 | + * | ||
46 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
47 | + * See the COPYING file in the top-level directory. | ||
48 | + */ | ||
49 | + | 16 | + |
50 | +#ifndef TCG_CPUS_ICOUNT_H | 17 | INSN_VLD1 = 0xf4200000, /* VLD1 (multiple single elements) */ |
51 | +#define TCG_CPUS_ICOUNT_H | 18 | INSN_VST1 = 0xf4000000, /* VST1 (multiple single elements) */ |
52 | + | 19 | } ARMInsn; |
53 | +void handle_icount_deadline(void); | 20 | @@ -XXX,XX +XXX,XX @@ static uint32_t encode_vd(TCGReg rd) |
54 | +void prepare_icount_for_run(CPUState *cpu); | 21 | return (extract32(rd, 3, 1) << 22) | (extract32(rd, 0, 3) << 13); |
55 | +void process_icount_data(CPUState *cpu); | ||
56 | + | ||
57 | +#endif /* TCG_CPUS_ICOUNT_H */ | ||
58 | diff --git a/accel/tcg/tcg-cpus-mttcg.h b/accel/tcg/tcg-cpus-mttcg.h | ||
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 | + | ||
73 | +#ifndef TCG_CPUS_MTTCG_H | ||
74 | +#define TCG_CPUS_MTTCG_H | ||
75 | + | ||
76 | +/* | ||
77 | + * In the multi-threaded case each vCPU has its own thread. The TLS | ||
78 | + * variable current_cpu can be used deep in the code to find the | ||
79 | + * current CPUState for a given thread. | ||
80 | + */ | ||
81 | + | ||
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 | } | 22 | } |
158 | 23 | ||
159 | diff --git a/accel/tcg/tcg-cpus-icount.c b/accel/tcg/tcg-cpus-icount.c | 24 | +static uint32_t encode_vn(TCGReg rn) |
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 | +{ | 25 | +{ |
205 | + int64_t deadline; | 26 | + tcg_debug_assert(rn >= TCG_REG_Q0); |
206 | + | 27 | + return (extract32(rn, 3, 1) << 7) | (extract32(rn, 0, 3) << 17); |
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 | + } | ||
228 | + | ||
229 | + return icount_round(deadline); | ||
230 | + } else { | ||
231 | + return replay_get_instructions(); | ||
232 | + } | ||
233 | +} | 28 | +} |
234 | + | 29 | + |
235 | +static void notify_aio_contexts(void) | 30 | +static uint32_t encode_vm(TCGReg rm) |
236 | +{ | 31 | +{ |
237 | + /* Wake up other AioContexts. */ | 32 | + tcg_debug_assert(rm >= TCG_REG_Q0); |
238 | + qemu_clock_notify(QEMU_CLOCK_VIRTUAL); | 33 | + return (extract32(rm, 3, 1) << 5) | (extract32(rm, 0, 3) << 1); |
239 | + qemu_clock_run_timers(QEMU_CLOCK_VIRTUAL); | ||
240 | +} | 34 | +} |
241 | + | 35 | + |
242 | +void handle_icount_deadline(void) | 36 | +static void tcg_out_vreg3(TCGContext *s, ARMInsn insn, int q, int vece, |
37 | + TCGReg d, TCGReg n, TCGReg m) | ||
243 | +{ | 38 | +{ |
244 | + assert(qemu_in_vcpu_thread()); | 39 | + tcg_out32(s, insn | (vece << 20) | (q << 6) | |
245 | + int64_t deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL, | 40 | + encode_vd(d) | encode_vn(n) | encode_vm(m)); |
246 | + QEMU_TIMER_ATTR_ALL); | ||
247 | + | ||
248 | + if (deadline == 0) { | ||
249 | + notify_aio_contexts(); | ||
250 | + } | ||
251 | +} | 41 | +} |
252 | + | 42 | + |
253 | +void prepare_icount_for_run(CPUState *cpu) | 43 | static void tcg_out_vldst(TCGContext *s, ARMInsn insn, |
254 | +{ | 44 | TCGReg rd, TCGReg rn, int offset) |
255 | + int insns_left; | 45 | { |
46 | @@ -XXX,XX +XXX,XX @@ static inline bool tcg_out_sti(TCGContext *s, TCGType type, TCGArg val, | ||
47 | return false; | ||
48 | } | ||
49 | |||
50 | -static inline bool tcg_out_mov(TCGContext *s, TCGType type, | ||
51 | - TCGReg ret, TCGReg arg) | ||
52 | +static bool tcg_out_mov(TCGContext *s, TCGType type, TCGReg ret, TCGReg arg) | ||
53 | { | ||
54 | - tcg_out_mov_reg(s, COND_AL, ret, arg); | ||
55 | - return true; | ||
56 | + if (ret == arg) { | ||
57 | + return true; | ||
58 | + } | ||
59 | + switch (type) { | ||
60 | + case TCG_TYPE_I32: | ||
61 | + if (ret < TCG_REG_Q0 && arg < TCG_REG_Q0) { | ||
62 | + tcg_out_mov_reg(s, COND_AL, ret, arg); | ||
63 | + return true; | ||
64 | + } | ||
65 | + return false; | ||
256 | + | 66 | + |
257 | + /* | 67 | + case TCG_TYPE_V64: |
258 | + * These should always be cleared by process_icount_data after | 68 | + case TCG_TYPE_V128: |
259 | + * each vCPU execution. However u16.high can be raised | 69 | + /* "VMOV D,N" is an alias for "VORR D,N,N". */ |
260 | + * asynchronously by cpu_exit/cpu_interrupt/tcg_handle_interrupt | 70 | + tcg_out_vreg3(s, INSN_VORR, type - TCG_TYPE_V64, 0, ret, arg, arg); |
261 | + */ | 71 | + return true; |
262 | + g_assert(cpu_neg(cpu)->icount_decr.u16.low == 0); | ||
263 | + g_assert(cpu->icount_extra == 0); | ||
264 | + | 72 | + |
265 | + cpu->icount_budget = tcg_get_icount_limit(); | 73 | + default: |
266 | + insns_left = MIN(0xffff, cpu->icount_budget); | 74 | + g_assert_not_reached(); |
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 | + } | 75 | + } |
275 | +} | 76 | } |
276 | + | 77 | |
277 | +void process_icount_data(CPUState *cpu) | 78 | -static inline void tcg_out_movi(TCGContext *s, TCGType type, |
278 | +{ | 79 | - TCGReg ret, tcg_target_long arg) |
279 | + /* Account for executed instructions */ | 80 | +static void tcg_out_movi(TCGContext *s, TCGType type, |
280 | + icount_update(cpu); | 81 | + TCGReg ret, tcg_target_long arg) |
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 | + } | ||
413 | + | ||
414 | + qatomic_mb_set(&cpu->exit_request, 0); | ||
415 | + qemu_wait_io_event(cpu); | ||
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 | + } | ||
555 | + | ||
556 | + start_tcg_kick_timer(); | ||
557 | + | ||
558 | + CPU_FOREACH(cpu) { | ||
559 | + qemu_wait_io_event_common(cpu); | ||
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 | + } | ||
576 | + } | ||
577 | +} | ||
578 | + | ||
579 | +/* | ||
580 | + * In the single-threaded case each vCPU is simulated in turn. If | ||
581 | + * there is more than a single vCPU we create a simple timer to kick | ||
582 | + * the vCPU and ensure we don't get stuck in a tight loop in one vCPU. | ||
583 | + * This is done explicitly rather than relying on side-effects | ||
584 | + * elsewhere. | ||
585 | + */ | ||
586 | + | ||
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 | + } | ||
612 | + } | ||
613 | + | ||
614 | + start_tcg_kick_timer(); | ||
615 | + | ||
616 | + cpu = first_cpu; | ||
617 | + | ||
618 | + /* process any pending work */ | ||
619 | + cpu->exit_request = 1; | ||
620 | + | ||
621 | + while (1) { | ||
622 | + qemu_mutex_unlock_iothread(); | ||
623 | + replay_mutex_lock(); | ||
624 | + qemu_mutex_lock_iothread(); | ||
625 | + | ||
626 | + if (icount_enabled()) { | ||
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; | ||
677 | + } | ||
678 | + | ||
679 | + cpu = CPU_NEXT(cpu); | ||
680 | + } /* while (cpu && !cpu->exit_request).. */ | ||
681 | + | ||
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 | { | 82 | { |
1163 | char thread_name[VCPU_THREAD_NAME_SIZE]; | 83 | + tcg_debug_assert(type == TCG_TYPE_I32); |
1164 | static QemuCond *single_tcg_halt_cond; | 84 | + tcg_debug_assert(ret < TCG_REG_Q0); |
1165 | @@ -XXX,XX +XXX,XX @@ static void tcg_start_vcpu_thread(CPUState *cpu) | 85 | tcg_out_movi32(s, COND_AL, ret, arg); |
1166 | } | ||
1167 | } | 86 | } |
1168 | 87 | ||
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 | -- | 88 | -- |
1267 | 2.25.1 | 89 | 2.25.1 |
1268 | 90 | ||
1269 | 91 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Most of dupi is copied from tcg/aarch64, which has the same | ||
2 | encoding for AdvSimdExpandImm. | ||
1 | 3 | ||
4 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | --- | ||
7 | tcg/arm/tcg-target.c.inc | 283 +++++++++++++++++++++++++++++++++++++-- | ||
8 | 1 file changed, 275 insertions(+), 8 deletions(-) | ||
9 | |||
10 | diff --git a/tcg/arm/tcg-target.c.inc b/tcg/arm/tcg-target.c.inc | ||
11 | index XXXXXXX..XXXXXXX 100644 | ||
12 | --- a/tcg/arm/tcg-target.c.inc | ||
13 | +++ b/tcg/arm/tcg-target.c.inc | ||
14 | @@ -XXX,XX +XXX,XX @@ typedef enum { | ||
15 | |||
16 | INSN_VORR = 0xf2200110, | ||
17 | |||
18 | + INSN_VDUP_G = 0xee800b10, /* VDUP (ARM core register) */ | ||
19 | + INSN_VDUP_S = 0xf3b00c00, /* VDUP (scalar) */ | ||
20 | + INSN_VLDR_D = 0xed100b00, /* VLDR.64 */ | ||
21 | INSN_VLD1 = 0xf4200000, /* VLD1 (multiple single elements) */ | ||
22 | + INSN_VLD1R = 0xf4a00c00, /* VLD1 (single element to all lanes) */ | ||
23 | INSN_VST1 = 0xf4000000, /* VST1 (multiple single elements) */ | ||
24 | + INSN_VMOVI = 0xf2800010, /* VMOV (immediate) */ | ||
25 | } ARMInsn; | ||
26 | |||
27 | #define INSN_NOP (use_armv7_instructions ? INSN_NOP_v6k : INSN_NOP_v4) | ||
28 | @@ -XXX,XX +XXX,XX @@ static const uint8_t tcg_cond_to_arm_cond[] = { | ||
29 | [TCG_COND_GTU] = COND_HI, | ||
30 | }; | ||
31 | |||
32 | +static int encode_imm(uint32_t imm); | ||
33 | + | ||
34 | +/* TCG private relocation type: add with pc+imm8 */ | ||
35 | +#define R_ARM_PC8 11 | ||
36 | + | ||
37 | +/* TCG private relocation type: vldr with imm8 << 2 */ | ||
38 | +#define R_ARM_PC11 12 | ||
39 | + | ||
40 | static bool reloc_pc24(tcg_insn_unit *src_rw, const tcg_insn_unit *target) | ||
41 | { | ||
42 | const tcg_insn_unit *src_rx = tcg_splitwx_to_rx(src_rw); | ||
43 | @@ -XXX,XX +XXX,XX @@ static bool reloc_pc13(tcg_insn_unit *src_rw, const tcg_insn_unit *target) | ||
44 | return false; | ||
45 | } | ||
46 | |||
47 | +static bool reloc_pc11(tcg_insn_unit *src_rw, const tcg_insn_unit *target) | ||
48 | +{ | ||
49 | + const tcg_insn_unit *src_rx = tcg_splitwx_to_rx(src_rw); | ||
50 | + ptrdiff_t offset = (tcg_ptr_byte_diff(target, src_rx) - 8) / 4; | ||
51 | + | ||
52 | + if (offset >= -0xff && offset <= 0xff) { | ||
53 | + tcg_insn_unit insn = *src_rw; | ||
54 | + bool u = (offset >= 0); | ||
55 | + if (!u) { | ||
56 | + offset = -offset; | ||
57 | + } | ||
58 | + insn = deposit32(insn, 23, 1, u); | ||
59 | + insn = deposit32(insn, 0, 8, offset); | ||
60 | + *src_rw = insn; | ||
61 | + return true; | ||
62 | + } | ||
63 | + return false; | ||
64 | +} | ||
65 | + | ||
66 | +static bool reloc_pc8(tcg_insn_unit *src_rw, const tcg_insn_unit *target) | ||
67 | +{ | ||
68 | + const tcg_insn_unit *src_rx = tcg_splitwx_to_rx(src_rw); | ||
69 | + ptrdiff_t offset = tcg_ptr_byte_diff(target, src_rx) - 8; | ||
70 | + int rot = encode_imm(offset); | ||
71 | + | ||
72 | + if (rot >= 0) { | ||
73 | + *src_rw = deposit32(*src_rw, 0, 12, rol32(offset, rot) | (rot << 7)); | ||
74 | + return true; | ||
75 | + } | ||
76 | + return false; | ||
77 | +} | ||
78 | + | ||
79 | static bool patch_reloc(tcg_insn_unit *code_ptr, int type, | ||
80 | intptr_t value, intptr_t addend) | ||
81 | { | ||
82 | tcg_debug_assert(addend == 0); | ||
83 | - | ||
84 | - if (type == R_ARM_PC24) { | ||
85 | + switch (type) { | ||
86 | + case R_ARM_PC24: | ||
87 | return reloc_pc24(code_ptr, (const tcg_insn_unit *)value); | ||
88 | - } else if (type == R_ARM_PC13) { | ||
89 | + case R_ARM_PC13: | ||
90 | return reloc_pc13(code_ptr, (const tcg_insn_unit *)value); | ||
91 | - } else { | ||
92 | + case R_ARM_PC11: | ||
93 | + return reloc_pc11(code_ptr, (const tcg_insn_unit *)value); | ||
94 | + case R_ARM_PC8: | ||
95 | + return reloc_pc8(code_ptr, (const tcg_insn_unit *)value); | ||
96 | + default: | ||
97 | g_assert_not_reached(); | ||
98 | } | ||
99 | } | ||
100 | @@ -XXX,XX +XXX,XX @@ static inline uint32_t rotl(uint32_t val, int n) | ||
101 | |||
102 | /* ARM immediates for ALU instructions are made of an unsigned 8-bit | ||
103 | right-rotated by an even amount between 0 and 30. */ | ||
104 | -static inline int encode_imm(uint32_t imm) | ||
105 | +static int encode_imm(uint32_t imm) | ||
106 | { | ||
107 | int shift; | ||
108 | |||
109 | @@ -XXX,XX +XXX,XX @@ static inline int check_fit_imm(uint32_t imm) | ||
110 | return encode_imm(imm) >= 0; | ||
111 | } | ||
112 | |||
113 | +/* Return true if v16 is a valid 16-bit shifted immediate. */ | ||
114 | +static bool is_shimm16(uint16_t v16, int *cmode, int *imm8) | ||
115 | +{ | ||
116 | + if (v16 == (v16 & 0xff)) { | ||
117 | + *cmode = 0x8; | ||
118 | + *imm8 = v16 & 0xff; | ||
119 | + return true; | ||
120 | + } else if (v16 == (v16 & 0xff00)) { | ||
121 | + *cmode = 0xa; | ||
122 | + *imm8 = v16 >> 8; | ||
123 | + return true; | ||
124 | + } | ||
125 | + return false; | ||
126 | +} | ||
127 | + | ||
128 | +/* Return true if v32 is a valid 32-bit shifted immediate. */ | ||
129 | +static bool is_shimm32(uint32_t v32, int *cmode, int *imm8) | ||
130 | +{ | ||
131 | + if (v32 == (v32 & 0xff)) { | ||
132 | + *cmode = 0x0; | ||
133 | + *imm8 = v32 & 0xff; | ||
134 | + return true; | ||
135 | + } else if (v32 == (v32 & 0xff00)) { | ||
136 | + *cmode = 0x2; | ||
137 | + *imm8 = (v32 >> 8) & 0xff; | ||
138 | + return true; | ||
139 | + } else if (v32 == (v32 & 0xff0000)) { | ||
140 | + *cmode = 0x4; | ||
141 | + *imm8 = (v32 >> 16) & 0xff; | ||
142 | + return true; | ||
143 | + } else if (v32 == (v32 & 0xff000000)) { | ||
144 | + *cmode = 0x6; | ||
145 | + *imm8 = v32 >> 24; | ||
146 | + return true; | ||
147 | + } | ||
148 | + return false; | ||
149 | +} | ||
150 | + | ||
151 | +/* Return true if v32 is a valid 32-bit shifting ones immediate. */ | ||
152 | +static bool is_soimm32(uint32_t v32, int *cmode, int *imm8) | ||
153 | +{ | ||
154 | + if ((v32 & 0xffff00ff) == 0xff) { | ||
155 | + *cmode = 0xc; | ||
156 | + *imm8 = (v32 >> 8) & 0xff; | ||
157 | + return true; | ||
158 | + } else if ((v32 & 0xff00ffff) == 0xffff) { | ||
159 | + *cmode = 0xd; | ||
160 | + *imm8 = (v32 >> 16) & 0xff; | ||
161 | + return true; | ||
162 | + } | ||
163 | + return false; | ||
164 | +} | ||
165 | + | ||
166 | +/* | ||
167 | + * Return non-zero if v32 can be formed by MOVI+ORR. | ||
168 | + * Place the parameters for MOVI in (cmode, imm8). | ||
169 | + * Return the cmode for ORR; the imm8 can be had via extraction from v32. | ||
170 | + */ | ||
171 | +static int is_shimm32_pair(uint32_t v32, int *cmode, int *imm8) | ||
172 | +{ | ||
173 | + int i; | ||
174 | + | ||
175 | + for (i = 6; i > 0; i -= 2) { | ||
176 | + /* Mask out one byte we can add with ORR. */ | ||
177 | + uint32_t tmp = v32 & ~(0xffu << (i * 4)); | ||
178 | + if (is_shimm32(tmp, cmode, imm8) || | ||
179 | + is_soimm32(tmp, cmode, imm8)) { | ||
180 | + break; | ||
181 | + } | ||
182 | + } | ||
183 | + return i; | ||
184 | +} | ||
185 | + | ||
186 | /* Test if a constant matches the constraint. | ||
187 | * TODO: define constraints for: | ||
188 | * | ||
189 | @@ -XXX,XX +XXX,XX @@ static void tcg_out_vreg3(TCGContext *s, ARMInsn insn, int q, int vece, | ||
190 | encode_vd(d) | encode_vn(n) | encode_vm(m)); | ||
191 | } | ||
192 | |||
193 | +static void tcg_out_vmovi(TCGContext *s, TCGReg rd, | ||
194 | + int q, int op, int cmode, uint8_t imm8) | ||
195 | +{ | ||
196 | + tcg_out32(s, INSN_VMOVI | encode_vd(rd) | (q << 6) | (op << 5) | ||
197 | + | (cmode << 8) | extract32(imm8, 0, 4) | ||
198 | + | (extract32(imm8, 4, 3) << 16) | ||
199 | + | (extract32(imm8, 7, 1) << 24)); | ||
200 | +} | ||
201 | + | ||
202 | static void tcg_out_vldst(TCGContext *s, ARMInsn insn, | ||
203 | TCGReg rd, TCGReg rn, int offset) | ||
204 | { | ||
205 | @@ -XXX,XX +XXX,XX @@ static void tcg_out_movi(TCGContext *s, TCGType type, | ||
206 | tcg_out_movi32(s, COND_AL, ret, arg); | ||
207 | } | ||
208 | |||
209 | +/* Type is always V128, with I64 elements. */ | ||
210 | +static void tcg_out_dup2_vec(TCGContext *s, TCGReg rd, TCGReg rl, TCGReg rh) | ||
211 | +{ | ||
212 | + /* Move high element into place first. */ | ||
213 | + /* VMOV Dd+1, Ds */ | ||
214 | + tcg_out_vreg3(s, INSN_VORR | (1 << 12), 0, 0, rd, rh, rh); | ||
215 | + /* Move low element into place; tcg_out_mov will check for nop. */ | ||
216 | + tcg_out_mov(s, TCG_TYPE_V64, rd, rl); | ||
217 | +} | ||
218 | + | ||
219 | static bool tcg_out_dup_vec(TCGContext *s, TCGType type, unsigned vece, | ||
220 | TCGReg rd, TCGReg rs) | ||
221 | { | ||
222 | - g_assert_not_reached(); | ||
223 | + int q = type - TCG_TYPE_V64; | ||
224 | + | ||
225 | + if (vece == MO_64) { | ||
226 | + if (type == TCG_TYPE_V128) { | ||
227 | + tcg_out_dup2_vec(s, rd, rs, rs); | ||
228 | + } else { | ||
229 | + tcg_out_mov(s, TCG_TYPE_V64, rd, rs); | ||
230 | + } | ||
231 | + } else if (rs < TCG_REG_Q0) { | ||
232 | + int b = (vece == MO_8); | ||
233 | + int e = (vece == MO_16); | ||
234 | + tcg_out32(s, INSN_VDUP_G | (b << 22) | (q << 21) | (e << 5) | | ||
235 | + encode_vn(rd) | (rs << 12)); | ||
236 | + } else { | ||
237 | + int imm4 = 1 << vece; | ||
238 | + tcg_out32(s, INSN_VDUP_S | (imm4 << 16) | (q << 6) | | ||
239 | + encode_vd(rd) | encode_vm(rs)); | ||
240 | + } | ||
241 | + return true; | ||
242 | } | ||
243 | |||
244 | static bool tcg_out_dupm_vec(TCGContext *s, TCGType type, unsigned vece, | ||
245 | TCGReg rd, TCGReg base, intptr_t offset) | ||
246 | { | ||
247 | - g_assert_not_reached(); | ||
248 | + if (vece == MO_64) { | ||
249 | + tcg_out_ld(s, TCG_TYPE_V64, rd, base, offset); | ||
250 | + if (type == TCG_TYPE_V128) { | ||
251 | + tcg_out_dup2_vec(s, rd, rd, rd); | ||
252 | + } | ||
253 | + } else { | ||
254 | + int q = type - TCG_TYPE_V64; | ||
255 | + tcg_out_vldst(s, INSN_VLD1R | (vece << 6) | (q << 5), | ||
256 | + rd, base, offset); | ||
257 | + } | ||
258 | + return true; | ||
259 | } | ||
260 | |||
261 | static void tcg_out_dupi_vec(TCGContext *s, TCGType type, unsigned vece, | ||
262 | TCGReg rd, int64_t v64) | ||
263 | { | ||
264 | - g_assert_not_reached(); | ||
265 | + int q = type - TCG_TYPE_V64; | ||
266 | + int cmode, imm8, i; | ||
267 | + | ||
268 | + /* Test all bytes equal first. */ | ||
269 | + if (vece == MO_8) { | ||
270 | + tcg_out_vmovi(s, rd, q, 0, 0xe, v64); | ||
271 | + return; | ||
272 | + } | ||
273 | + | ||
274 | + /* | ||
275 | + * Test all bytes 0x00 or 0xff second. This can match cases that | ||
276 | + * might otherwise take 2 or 3 insns for MO_16 or MO_32 below. | ||
277 | + */ | ||
278 | + for (i = imm8 = 0; i < 8; i++) { | ||
279 | + uint8_t byte = v64 >> (i * 8); | ||
280 | + if (byte == 0xff) { | ||
281 | + imm8 |= 1 << i; | ||
282 | + } else if (byte != 0) { | ||
283 | + goto fail_bytes; | ||
284 | + } | ||
285 | + } | ||
286 | + tcg_out_vmovi(s, rd, q, 1, 0xe, imm8); | ||
287 | + return; | ||
288 | + fail_bytes: | ||
289 | + | ||
290 | + /* | ||
291 | + * Tests for various replications. For each element width, if we | ||
292 | + * cannot find an expansion there's no point checking a larger | ||
293 | + * width because we already know by replication it cannot match. | ||
294 | + */ | ||
295 | + if (vece == MO_16) { | ||
296 | + uint16_t v16 = v64; | ||
297 | + | ||
298 | + if (is_shimm16(v16, &cmode, &imm8)) { | ||
299 | + tcg_out_vmovi(s, rd, q, 0, cmode, imm8); | ||
300 | + return; | ||
301 | + } | ||
302 | + if (is_shimm16(~v16, &cmode, &imm8)) { | ||
303 | + tcg_out_vmovi(s, rd, q, 1, cmode, imm8); | ||
304 | + return; | ||
305 | + } | ||
306 | + | ||
307 | + /* | ||
308 | + * Otherwise, all remaining constants can be loaded in two insns: | ||
309 | + * rd = v16 & 0xff, rd |= v16 & 0xff00. | ||
310 | + */ | ||
311 | + tcg_out_vmovi(s, rd, q, 0, 0x8, v16 & 0xff); | ||
312 | + tcg_out_vmovi(s, rd, q, 0, 0xb, v16 >> 8); /* VORRI */ | ||
313 | + return; | ||
314 | + } | ||
315 | + | ||
316 | + if (vece == MO_32) { | ||
317 | + uint32_t v32 = v64; | ||
318 | + | ||
319 | + if (is_shimm32(v32, &cmode, &imm8) || | ||
320 | + is_soimm32(v32, &cmode, &imm8)) { | ||
321 | + tcg_out_vmovi(s, rd, q, 0, cmode, imm8); | ||
322 | + return; | ||
323 | + } | ||
324 | + if (is_shimm32(~v32, &cmode, &imm8) || | ||
325 | + is_soimm32(~v32, &cmode, &imm8)) { | ||
326 | + tcg_out_vmovi(s, rd, q, 1, cmode, imm8); | ||
327 | + return; | ||
328 | + } | ||
329 | + | ||
330 | + /* | ||
331 | + * Restrict the set of constants to those we can load with | ||
332 | + * two instructions. Others we load from the pool. | ||
333 | + */ | ||
334 | + i = is_shimm32_pair(v32, &cmode, &imm8); | ||
335 | + if (i) { | ||
336 | + tcg_out_vmovi(s, rd, q, 0, cmode, imm8); | ||
337 | + tcg_out_vmovi(s, rd, q, 0, i | 1, extract32(v32, i * 4, 8)); | ||
338 | + return; | ||
339 | + } | ||
340 | + i = is_shimm32_pair(~v32, &cmode, &imm8); | ||
341 | + if (i) { | ||
342 | + tcg_out_vmovi(s, rd, q, 1, cmode, imm8); | ||
343 | + tcg_out_vmovi(s, rd, q, 1, i | 1, extract32(~v32, i * 4, 8)); | ||
344 | + return; | ||
345 | + } | ||
346 | + } | ||
347 | + | ||
348 | + /* | ||
349 | + * As a last resort, load from the constant pool. | ||
350 | + */ | ||
351 | + if (!q || vece == MO_64) { | ||
352 | + new_pool_l2(s, R_ARM_PC11, s->code_ptr, 0, v64, v64 >> 32); | ||
353 | + /* VLDR Dd, [pc + offset] */ | ||
354 | + tcg_out32(s, INSN_VLDR_D | encode_vd(rd) | (0xf << 16)); | ||
355 | + if (q) { | ||
356 | + tcg_out_dup2_vec(s, rd, rd, rd); | ||
357 | + } | ||
358 | + } else { | ||
359 | + new_pool_label(s, (uint32_t)v64, R_ARM_PC8, s->code_ptr, 0); | ||
360 | + /* add tmp, pc, offset */ | ||
361 | + tcg_out_dat_imm(s, COND_AL, ARITH_ADD, TCG_REG_TMP, TCG_REG_PC, 0); | ||
362 | + tcg_out_dupm_vec(s, type, MO_32, rd, TCG_REG_TMP, 0); | ||
363 | + } | ||
364 | } | ||
365 | |||
366 | static void tcg_out_vec_op(TCGContext *s, TCGOpcode opc, | ||
367 | -- | ||
368 | 2.25.1 | ||
369 | |||
370 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Implementing dup2, add, sub, and, or, xor as the minimal set. | ||
2 | This allows us to actually enable neon in the header file. | ||
1 | 3 | ||
4 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | --- | ||
7 | tcg/arm/tcg-target-con-set.h | 3 + | ||
8 | tcg/arm/tcg-target-con-str.h | 2 + | ||
9 | tcg/arm/tcg-target.h | 6 +- | ||
10 | tcg/arm/tcg-target.c.inc | 201 +++++++++++++++++++++++++++++++++-- | ||
11 | 4 files changed, 204 insertions(+), 8 deletions(-) | ||
12 | |||
13 | diff --git a/tcg/arm/tcg-target-con-set.h b/tcg/arm/tcg-target-con-set.h | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/tcg/arm/tcg-target-con-set.h | ||
16 | +++ b/tcg/arm/tcg-target-con-set.h | ||
17 | @@ -XXX,XX +XXX,XX @@ C_O1_I2(r, r, rIN) | ||
18 | C_O1_I2(r, r, ri) | ||
19 | C_O1_I2(r, rZ, rZ) | ||
20 | C_O1_I2(w, w, w) | ||
21 | +C_O1_I2(w, w, wO) | ||
22 | +C_O1_I2(w, w, wV) | ||
23 | +C_O1_I2(w, w, wZ) | ||
24 | C_O1_I4(r, r, r, rI, rI) | ||
25 | C_O1_I4(r, r, rIN, rIK, 0) | ||
26 | C_O2_I1(r, r, l) | ||
27 | diff --git a/tcg/arm/tcg-target-con-str.h b/tcg/arm/tcg-target-con-str.h | ||
28 | index XXXXXXX..XXXXXXX 100644 | ||
29 | --- a/tcg/arm/tcg-target-con-str.h | ||
30 | +++ b/tcg/arm/tcg-target-con-str.h | ||
31 | @@ -XXX,XX +XXX,XX @@ REGS('w', ALL_VECTOR_REGS) | ||
32 | CONST('I', TCG_CT_CONST_ARM) | ||
33 | CONST('K', TCG_CT_CONST_INV) | ||
34 | CONST('N', TCG_CT_CONST_NEG) | ||
35 | +CONST('O', TCG_CT_CONST_ORRI) | ||
36 | +CONST('V', TCG_CT_CONST_ANDI) | ||
37 | CONST('Z', TCG_CT_CONST_ZERO) | ||
38 | diff --git a/tcg/arm/tcg-target.h b/tcg/arm/tcg-target.h | ||
39 | index XXXXXXX..XXXXXXX 100644 | ||
40 | --- a/tcg/arm/tcg-target.h | ||
41 | +++ b/tcg/arm/tcg-target.h | ||
42 | @@ -XXX,XX +XXX,XX @@ typedef enum { | ||
43 | #else | ||
44 | extern bool use_idiv_instructions; | ||
45 | #endif | ||
46 | -#define use_neon_instructions 0 | ||
47 | +#ifdef __ARM_NEON__ | ||
48 | +#define use_neon_instructions 1 | ||
49 | +#else | ||
50 | +extern bool use_neon_instructions; | ||
51 | +#endif | ||
52 | |||
53 | /* used for function call generation */ | ||
54 | #define TCG_TARGET_STACK_ALIGN 8 | ||
55 | diff --git a/tcg/arm/tcg-target.c.inc b/tcg/arm/tcg-target.c.inc | ||
56 | index XXXXXXX..XXXXXXX 100644 | ||
57 | --- a/tcg/arm/tcg-target.c.inc | ||
58 | +++ b/tcg/arm/tcg-target.c.inc | ||
59 | @@ -XXX,XX +XXX,XX @@ int arm_arch = __ARM_ARCH; | ||
60 | #ifndef use_idiv_instructions | ||
61 | bool use_idiv_instructions; | ||
62 | #endif | ||
63 | +#ifndef use_neon_instructions | ||
64 | +bool use_neon_instructions; | ||
65 | +#endif | ||
66 | |||
67 | /* ??? Ought to think about changing CONFIG_SOFTMMU to always defined. */ | ||
68 | #ifdef CONFIG_SOFTMMU | ||
69 | @@ -XXX,XX +XXX,XX @@ typedef enum { | ||
70 | /* Otherwise the assembler uses mov r0,r0 */ | ||
71 | INSN_NOP_v4 = (COND_AL << 28) | ARITH_MOV, | ||
72 | |||
73 | + INSN_VADD = 0xf2000800, | ||
74 | + INSN_VAND = 0xf2000110, | ||
75 | + INSN_VEOR = 0xf3000110, | ||
76 | INSN_VORR = 0xf2200110, | ||
77 | + INSN_VSUB = 0xf3000800, | ||
78 | + | ||
79 | + INSN_VMVN = 0xf3b00580, | ||
80 | + | ||
81 | + INSN_VCEQ0 = 0xf3b10100, | ||
82 | + INSN_VCGT0 = 0xf3b10000, | ||
83 | + INSN_VCGE0 = 0xf3b10080, | ||
84 | + INSN_VCLE0 = 0xf3b10180, | ||
85 | + INSN_VCLT0 = 0xf3b10200, | ||
86 | + | ||
87 | + INSN_VCEQ = 0xf3000810, | ||
88 | + INSN_VCGE = 0xf2000310, | ||
89 | + INSN_VCGT = 0xf2000300, | ||
90 | + INSN_VCGE_U = 0xf3000310, | ||
91 | + INSN_VCGT_U = 0xf3000300, | ||
92 | + | ||
93 | + INSN_VTST = 0xf2000810, | ||
94 | |||
95 | INSN_VDUP_G = 0xee800b10, /* VDUP (ARM core register) */ | ||
96 | INSN_VDUP_S = 0xf3b00c00, /* VDUP (scalar) */ | ||
97 | @@ -XXX,XX +XXX,XX @@ static bool patch_reloc(tcg_insn_unit *code_ptr, int type, | ||
98 | #define TCG_CT_CONST_INV 0x200 | ||
99 | #define TCG_CT_CONST_NEG 0x400 | ||
100 | #define TCG_CT_CONST_ZERO 0x800 | ||
101 | +#define TCG_CT_CONST_ORRI 0x1000 | ||
102 | +#define TCG_CT_CONST_ANDI 0x2000 | ||
103 | |||
104 | #define ALL_GENERAL_REGS 0xffffu | ||
105 | #define ALL_VECTOR_REGS 0xffff0000u | ||
106 | @@ -XXX,XX +XXX,XX @@ static int is_shimm32_pair(uint32_t v32, int *cmode, int *imm8) | ||
107 | return i; | ||
108 | } | ||
109 | |||
110 | +/* Return true if V is a valid 16-bit or 32-bit shifted immediate. */ | ||
111 | +static bool is_shimm1632(uint32_t v32, int *cmode, int *imm8) | ||
112 | +{ | ||
113 | + if (v32 == deposit32(v32, 16, 16, v32)) { | ||
114 | + return is_shimm16(v32, cmode, imm8); | ||
115 | + } else { | ||
116 | + return is_shimm32(v32, cmode, imm8); | ||
117 | + } | ||
118 | +} | ||
119 | + | ||
120 | /* Test if a constant matches the constraint. | ||
121 | * TODO: define constraints for: | ||
122 | * | ||
123 | @@ -XXX,XX +XXX,XX @@ static bool tcg_target_const_match(int64_t val, TCGType type, int ct) | ||
124 | return 1; | ||
125 | } else if ((ct & TCG_CT_CONST_ZERO) && val == 0) { | ||
126 | return 1; | ||
127 | - } else { | ||
128 | - return 0; | ||
129 | } | ||
130 | + | ||
131 | + switch (ct & (TCG_CT_CONST_ORRI | TCG_CT_CONST_ANDI)) { | ||
132 | + case 0: | ||
133 | + break; | ||
134 | + case TCG_CT_CONST_ANDI: | ||
135 | + val = ~val; | ||
136 | + /* fallthru */ | ||
137 | + case TCG_CT_CONST_ORRI: | ||
138 | + if (val == deposit64(val, 32, 32, val)) { | ||
139 | + int cmode, imm8; | ||
140 | + return is_shimm1632(val, &cmode, &imm8); | ||
141 | + } | ||
142 | + break; | ||
143 | + default: | ||
144 | + /* Both bits should not be set for the same insn. */ | ||
145 | + g_assert_not_reached(); | ||
146 | + } | ||
147 | + | ||
148 | + return 0; | ||
149 | } | ||
150 | |||
151 | static inline void tcg_out_b(TCGContext *s, int cond, int32_t offset) | ||
152 | @@ -XXX,XX +XXX,XX @@ static uint32_t encode_vm(TCGReg rm) | ||
153 | return (extract32(rm, 3, 1) << 5) | (extract32(rm, 0, 3) << 1); | ||
154 | } | ||
155 | |||
156 | +static void tcg_out_vreg2(TCGContext *s, ARMInsn insn, int q, int vece, | ||
157 | + TCGReg d, TCGReg m) | ||
158 | +{ | ||
159 | + tcg_out32(s, insn | (vece << 18) | (q << 6) | | ||
160 | + encode_vd(d) | encode_vm(m)); | ||
161 | +} | ||
162 | + | ||
163 | static void tcg_out_vreg3(TCGContext *s, ARMInsn insn, int q, int vece, | ||
164 | TCGReg d, TCGReg n, TCGReg m) | ||
165 | { | ||
166 | @@ -XXX,XX +XXX,XX @@ static TCGConstraintSetIndex tcg_target_op_def(TCGOpcode op) | ||
167 | case INDEX_op_add_vec: | ||
168 | case INDEX_op_sub_vec: | ||
169 | case INDEX_op_xor_vec: | ||
170 | - case INDEX_op_or_vec: | ||
171 | - case INDEX_op_and_vec: | ||
172 | - case INDEX_op_cmp_vec: | ||
173 | return C_O1_I2(w, w, w); | ||
174 | + case INDEX_op_or_vec: | ||
175 | + return C_O1_I2(w, w, wO); | ||
176 | + case INDEX_op_and_vec: | ||
177 | + return C_O1_I2(w, w, wV); | ||
178 | + case INDEX_op_cmp_vec: | ||
179 | + return C_O1_I2(w, w, wZ); | ||
180 | |||
181 | default: | ||
182 | g_assert_not_reached(); | ||
183 | @@ -XXX,XX +XXX,XX @@ static void tcg_out_dupi_vec(TCGContext *s, TCGType type, unsigned vece, | ||
184 | } | ||
185 | } | ||
186 | |||
187 | +static const ARMInsn vec_cmp_insn[16] = { | ||
188 | + [TCG_COND_EQ] = INSN_VCEQ, | ||
189 | + [TCG_COND_GT] = INSN_VCGT, | ||
190 | + [TCG_COND_GE] = INSN_VCGE, | ||
191 | + [TCG_COND_GTU] = INSN_VCGT_U, | ||
192 | + [TCG_COND_GEU] = INSN_VCGE_U, | ||
193 | +}; | ||
194 | + | ||
195 | +static const ARMInsn vec_cmp0_insn[16] = { | ||
196 | + [TCG_COND_EQ] = INSN_VCEQ0, | ||
197 | + [TCG_COND_GT] = INSN_VCGT0, | ||
198 | + [TCG_COND_GE] = INSN_VCGE0, | ||
199 | + [TCG_COND_LT] = INSN_VCLT0, | ||
200 | + [TCG_COND_LE] = INSN_VCLE0, | ||
201 | +}; | ||
202 | + | ||
203 | static void tcg_out_vec_op(TCGContext *s, TCGOpcode opc, | ||
204 | unsigned vecl, unsigned vece, | ||
205 | const TCGArg *args, const int *const_args) | ||
206 | { | ||
207 | - g_assert_not_reached(); | ||
208 | + TCGType type = vecl + TCG_TYPE_V64; | ||
209 | + unsigned q = vecl; | ||
210 | + TCGArg a0, a1, a2; | ||
211 | + int cmode, imm8; | ||
212 | + | ||
213 | + a0 = args[0]; | ||
214 | + a1 = args[1]; | ||
215 | + a2 = args[2]; | ||
216 | + | ||
217 | + switch (opc) { | ||
218 | + case INDEX_op_ld_vec: | ||
219 | + tcg_out_ld(s, type, a0, a1, a2); | ||
220 | + return; | ||
221 | + case INDEX_op_st_vec: | ||
222 | + tcg_out_st(s, type, a0, a1, a2); | ||
223 | + return; | ||
224 | + case INDEX_op_dupm_vec: | ||
225 | + tcg_out_dupm_vec(s, type, vece, a0, a1, a2); | ||
226 | + return; | ||
227 | + case INDEX_op_dup2_vec: | ||
228 | + tcg_out_dup2_vec(s, a0, a1, a2); | ||
229 | + return; | ||
230 | + case INDEX_op_add_vec: | ||
231 | + tcg_out_vreg3(s, INSN_VADD, q, vece, a0, a1, a2); | ||
232 | + return; | ||
233 | + case INDEX_op_sub_vec: | ||
234 | + tcg_out_vreg3(s, INSN_VSUB, q, vece, a0, a1, a2); | ||
235 | + return; | ||
236 | + case INDEX_op_xor_vec: | ||
237 | + tcg_out_vreg3(s, INSN_VEOR, q, 0, a0, a1, a2); | ||
238 | + return; | ||
239 | + | ||
240 | + case INDEX_op_and_vec: | ||
241 | + if (const_args[2]) { | ||
242 | + is_shimm1632(~a2, &cmode, &imm8); | ||
243 | + if (a0 == a1) { | ||
244 | + tcg_out_vmovi(s, a0, q, 1, cmode | 1, imm8); /* VBICI */ | ||
245 | + return; | ||
246 | + } | ||
247 | + tcg_out_vmovi(s, a0, q, 1, cmode, imm8); /* VMVNI */ | ||
248 | + a2 = a0; | ||
249 | + } | ||
250 | + tcg_out_vreg3(s, INSN_VAND, q, 0, a0, a1, a2); | ||
251 | + return; | ||
252 | + | ||
253 | + case INDEX_op_or_vec: | ||
254 | + if (const_args[2]) { | ||
255 | + is_shimm1632(a2, &cmode, &imm8); | ||
256 | + if (a0 == a1) { | ||
257 | + tcg_out_vmovi(s, a0, q, 0, cmode | 1, imm8); /* VORRI */ | ||
258 | + return; | ||
259 | + } | ||
260 | + tcg_out_vmovi(s, a0, q, 0, cmode, imm8); /* VMOVI */ | ||
261 | + a2 = a0; | ||
262 | + } | ||
263 | + tcg_out_vreg3(s, INSN_VORR, q, 0, a0, a1, a2); | ||
264 | + return; | ||
265 | + | ||
266 | + case INDEX_op_cmp_vec: | ||
267 | + { | ||
268 | + TCGCond cond = args[3]; | ||
269 | + | ||
270 | + if (cond == TCG_COND_NE) { | ||
271 | + if (const_args[2]) { | ||
272 | + tcg_out_vreg3(s, INSN_VTST, q, vece, a0, a1, a1); | ||
273 | + } else { | ||
274 | + tcg_out_vreg3(s, INSN_VCEQ, q, vece, a0, a1, a2); | ||
275 | + tcg_out_vreg2(s, INSN_VMVN, q, 0, a0, a0); | ||
276 | + } | ||
277 | + } else { | ||
278 | + ARMInsn insn; | ||
279 | + | ||
280 | + if (const_args[2]) { | ||
281 | + insn = vec_cmp0_insn[cond]; | ||
282 | + if (insn) { | ||
283 | + tcg_out_vreg2(s, insn, q, vece, a0, a1); | ||
284 | + return; | ||
285 | + } | ||
286 | + tcg_out_dupi_vec(s, type, MO_8, TCG_VEC_TMP, 0); | ||
287 | + a2 = TCG_VEC_TMP; | ||
288 | + } | ||
289 | + insn = vec_cmp_insn[cond]; | ||
290 | + if (insn == 0) { | ||
291 | + TCGArg t; | ||
292 | + t = a1, a1 = a2, a2 = t; | ||
293 | + cond = tcg_swap_cond(cond); | ||
294 | + insn = vec_cmp_insn[cond]; | ||
295 | + tcg_debug_assert(insn != 0); | ||
296 | + } | ||
297 | + tcg_out_vreg3(s, insn, q, vece, a0, a1, a2); | ||
298 | + } | ||
299 | + } | ||
300 | + return; | ||
301 | + | ||
302 | + case INDEX_op_mov_vec: /* Always emitted via tcg_out_mov. */ | ||
303 | + case INDEX_op_dup_vec: /* Always emitted via tcg_out_dup_vec. */ | ||
304 | + default: | ||
305 | + g_assert_not_reached(); | ||
306 | + } | ||
307 | } | ||
308 | |||
309 | int tcg_can_emit_vec_op(TCGOpcode opc, TCGType type, unsigned vece) | ||
310 | { | ||
311 | - return 0; | ||
312 | + switch (opc) { | ||
313 | + case INDEX_op_add_vec: | ||
314 | + case INDEX_op_sub_vec: | ||
315 | + case INDEX_op_and_vec: | ||
316 | + case INDEX_op_or_vec: | ||
317 | + case INDEX_op_xor_vec: | ||
318 | + return 1; | ||
319 | + case INDEX_op_cmp_vec: | ||
320 | + return vece < MO_64; | ||
321 | + default: | ||
322 | + return 0; | ||
323 | + } | ||
324 | } | ||
325 | |||
326 | void tcg_expand_vec_op(TCGOpcode opc, TCGType type, unsigned vece, | ||
327 | -- | ||
328 | 2.25.1 | ||
329 | |||
330 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | These logical and arithmetic operations are optional, but are | ||
2 | trivial to accomplish with the existing infrastructure. | ||
1 | 3 | ||
4 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | --- | ||
7 | tcg/arm/tcg-target-con-set.h | 1 + | ||
8 | tcg/arm/tcg-target.h | 10 +++++----- | ||
9 | tcg/arm/tcg-target.c.inc | 38 ++++++++++++++++++++++++++++++++++++ | ||
10 | 3 files changed, 44 insertions(+), 5 deletions(-) | ||
11 | |||
12 | diff --git a/tcg/arm/tcg-target-con-set.h b/tcg/arm/tcg-target-con-set.h | ||
13 | index XXXXXXX..XXXXXXX 100644 | ||
14 | --- a/tcg/arm/tcg-target-con-set.h | ||
15 | +++ b/tcg/arm/tcg-target-con-set.h | ||
16 | @@ -XXX,XX +XXX,XX @@ C_O0_I4(s, s, s, s) | ||
17 | C_O1_I1(r, l) | ||
18 | C_O1_I1(r, r) | ||
19 | C_O1_I1(w, r) | ||
20 | +C_O1_I1(w, w) | ||
21 | C_O1_I1(w, wr) | ||
22 | C_O1_I2(r, 0, rZ) | ||
23 | C_O1_I2(r, l, l) | ||
24 | diff --git a/tcg/arm/tcg-target.h b/tcg/arm/tcg-target.h | ||
25 | index XXXXXXX..XXXXXXX 100644 | ||
26 | --- a/tcg/arm/tcg-target.h | ||
27 | +++ b/tcg/arm/tcg-target.h | ||
28 | @@ -XXX,XX +XXX,XX @@ extern bool use_neon_instructions; | ||
29 | #define TCG_TARGET_HAS_v128 use_neon_instructions | ||
30 | #define TCG_TARGET_HAS_v256 0 | ||
31 | |||
32 | -#define TCG_TARGET_HAS_andc_vec 0 | ||
33 | -#define TCG_TARGET_HAS_orc_vec 0 | ||
34 | -#define TCG_TARGET_HAS_not_vec 0 | ||
35 | -#define TCG_TARGET_HAS_neg_vec 0 | ||
36 | -#define TCG_TARGET_HAS_abs_vec 0 | ||
37 | +#define TCG_TARGET_HAS_andc_vec 1 | ||
38 | +#define TCG_TARGET_HAS_orc_vec 1 | ||
39 | +#define TCG_TARGET_HAS_not_vec 1 | ||
40 | +#define TCG_TARGET_HAS_neg_vec 1 | ||
41 | +#define TCG_TARGET_HAS_abs_vec 1 | ||
42 | #define TCG_TARGET_HAS_roti_vec 0 | ||
43 | #define TCG_TARGET_HAS_rots_vec 0 | ||
44 | #define TCG_TARGET_HAS_rotv_vec 0 | ||
45 | diff --git a/tcg/arm/tcg-target.c.inc b/tcg/arm/tcg-target.c.inc | ||
46 | index XXXXXXX..XXXXXXX 100644 | ||
47 | --- a/tcg/arm/tcg-target.c.inc | ||
48 | +++ b/tcg/arm/tcg-target.c.inc | ||
49 | @@ -XXX,XX +XXX,XX @@ typedef enum { | ||
50 | |||
51 | INSN_VADD = 0xf2000800, | ||
52 | INSN_VAND = 0xf2000110, | ||
53 | + INSN_VBIC = 0xf2100110, | ||
54 | INSN_VEOR = 0xf3000110, | ||
55 | + INSN_VORN = 0xf2300110, | ||
56 | INSN_VORR = 0xf2200110, | ||
57 | INSN_VSUB = 0xf3000800, | ||
58 | |||
59 | + INSN_VABS = 0xf3b10300, | ||
60 | INSN_VMVN = 0xf3b00580, | ||
61 | + INSN_VNEG = 0xf3b10380, | ||
62 | |||
63 | INSN_VCEQ0 = 0xf3b10100, | ||
64 | INSN_VCGT0 = 0xf3b10000, | ||
65 | @@ -XXX,XX +XXX,XX @@ static TCGConstraintSetIndex tcg_target_op_def(TCGOpcode op) | ||
66 | return C_O1_I1(w, r); | ||
67 | case INDEX_op_dup_vec: | ||
68 | return C_O1_I1(w, wr); | ||
69 | + case INDEX_op_abs_vec: | ||
70 | + case INDEX_op_neg_vec: | ||
71 | + case INDEX_op_not_vec: | ||
72 | + return C_O1_I1(w, w); | ||
73 | case INDEX_op_dup2_vec: | ||
74 | case INDEX_op_add_vec: | ||
75 | case INDEX_op_sub_vec: | ||
76 | case INDEX_op_xor_vec: | ||
77 | return C_O1_I2(w, w, w); | ||
78 | case INDEX_op_or_vec: | ||
79 | + case INDEX_op_andc_vec: | ||
80 | return C_O1_I2(w, w, wO); | ||
81 | case INDEX_op_and_vec: | ||
82 | + case INDEX_op_orc_vec: | ||
83 | return C_O1_I2(w, w, wV); | ||
84 | case INDEX_op_cmp_vec: | ||
85 | return C_O1_I2(w, w, wZ); | ||
86 | @@ -XXX,XX +XXX,XX @@ static void tcg_out_vec_op(TCGContext *s, TCGOpcode opc, | ||
87 | case INDEX_op_dup2_vec: | ||
88 | tcg_out_dup2_vec(s, a0, a1, a2); | ||
89 | return; | ||
90 | + case INDEX_op_abs_vec: | ||
91 | + tcg_out_vreg2(s, INSN_VABS, q, vece, a0, a1); | ||
92 | + return; | ||
93 | + case INDEX_op_neg_vec: | ||
94 | + tcg_out_vreg2(s, INSN_VNEG, q, vece, a0, a1); | ||
95 | + return; | ||
96 | + case INDEX_op_not_vec: | ||
97 | + tcg_out_vreg2(s, INSN_VMVN, q, 0, a0, a1); | ||
98 | + return; | ||
99 | case INDEX_op_add_vec: | ||
100 | tcg_out_vreg3(s, INSN_VADD, q, vece, a0, a1, a2); | ||
101 | return; | ||
102 | @@ -XXX,XX +XXX,XX @@ static void tcg_out_vec_op(TCGContext *s, TCGOpcode opc, | ||
103 | tcg_out_vreg3(s, INSN_VEOR, q, 0, a0, a1, a2); | ||
104 | return; | ||
105 | |||
106 | + case INDEX_op_andc_vec: | ||
107 | + if (!const_args[2]) { | ||
108 | + tcg_out_vreg3(s, INSN_VBIC, q, 0, a0, a1, a2); | ||
109 | + return; | ||
110 | + } | ||
111 | + a2 = ~a2; | ||
112 | + /* fall through */ | ||
113 | case INDEX_op_and_vec: | ||
114 | if (const_args[2]) { | ||
115 | is_shimm1632(~a2, &cmode, &imm8); | ||
116 | @@ -XXX,XX +XXX,XX @@ static void tcg_out_vec_op(TCGContext *s, TCGOpcode opc, | ||
117 | tcg_out_vreg3(s, INSN_VAND, q, 0, a0, a1, a2); | ||
118 | return; | ||
119 | |||
120 | + case INDEX_op_orc_vec: | ||
121 | + if (!const_args[2]) { | ||
122 | + tcg_out_vreg3(s, INSN_VORN, q, 0, a0, a1, a2); | ||
123 | + return; | ||
124 | + } | ||
125 | + a2 = ~a2; | ||
126 | + /* fall through */ | ||
127 | case INDEX_op_or_vec: | ||
128 | if (const_args[2]) { | ||
129 | is_shimm1632(a2, &cmode, &imm8); | ||
130 | @@ -XXX,XX +XXX,XX @@ int tcg_can_emit_vec_op(TCGOpcode opc, TCGType type, unsigned vece) | ||
131 | case INDEX_op_add_vec: | ||
132 | case INDEX_op_sub_vec: | ||
133 | case INDEX_op_and_vec: | ||
134 | + case INDEX_op_andc_vec: | ||
135 | case INDEX_op_or_vec: | ||
136 | + case INDEX_op_orc_vec: | ||
137 | case INDEX_op_xor_vec: | ||
138 | + case INDEX_op_not_vec: | ||
139 | return 1; | ||
140 | + case INDEX_op_abs_vec: | ||
141 | case INDEX_op_cmp_vec: | ||
142 | + case INDEX_op_neg_vec: | ||
143 | return vece < MO_64; | ||
144 | default: | ||
145 | return 0; | ||
146 | -- | ||
147 | 2.25.1 | ||
148 | |||
149 | diff view generated by jsdifflib |
1 | From: Claudio Fontana <cfontana@suse.de> | 1 | This consists of the three immediate shifts: shli, shri, sari. |
---|---|---|---|
2 | 2 | ||
3 | after the initial split into 3 tcg variants, we proceed to also | 3 | Reviewed-by: Peter Maydell <peter.maydell@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/arm/tcg-target.h | 2 +- |
15 | accel/tcg/tcg-cpus-rr.h | 3 +- | 7 | tcg/arm/tcg-target.c.inc | 27 +++++++++++++++++++++++++++ |
16 | accel/tcg/tcg-cpus.h | 1 - | 8 | 2 files changed, 28 insertions(+), 1 deletion(-) |
17 | accel/tcg/tcg-all.c | 5 ++++ | ||
18 | accel/tcg/tcg-cpus-icount.c | 2 +- | ||
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 | 9 | ||
25 | diff --git a/accel/tcg/tcg-cpus-mttcg.h b/accel/tcg/tcg-cpus-mttcg.h | 10 | diff --git a/tcg/arm/tcg-target.h b/tcg/arm/tcg-target.h |
26 | deleted file mode 100644 | ||
27 | index XXXXXXX..XXXXXXX | ||
28 | --- a/accel/tcg/tcg-cpus-mttcg.h | ||
29 | +++ /dev/null | ||
30 | @@ -XXX,XX +XXX,XX @@ | ||
31 | -/* | ||
32 | - * QEMU TCG Multi Threaded vCPUs implementation | ||
33 | - * | ||
34 | - * Copyright 2020 SUSE LLC | ||
35 | - * | ||
36 | - * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
37 | - * See the COPYING file in the top-level directory. | ||
38 | - */ | ||
39 | - | ||
40 | -#ifndef TCG_CPUS_MTTCG_H | ||
41 | -#define TCG_CPUS_MTTCG_H | ||
42 | - | ||
43 | -/* | ||
44 | - * In the multi-threaded case each vCPU has its own thread. The TLS | ||
45 | - * variable current_cpu can be used deep in the code to find the | ||
46 | - * current CPUState for a given thread. | ||
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 | 11 | index XXXXXXX..XXXXXXX 100644 |
54 | --- a/accel/tcg/tcg-cpus-rr.h | 12 | --- a/tcg/arm/tcg-target.h |
55 | +++ b/accel/tcg/tcg-cpus-rr.h | 13 | +++ b/tcg/arm/tcg-target.h |
56 | @@ -XXX,XX +XXX,XX @@ | 14 | @@ -XXX,XX +XXX,XX @@ extern bool use_neon_instructions; |
57 | /* Kick all RR vCPUs. */ | 15 | #define TCG_TARGET_HAS_roti_vec 0 |
58 | void qemu_cpu_kick_rr_cpus(CPUState *unused); | 16 | #define TCG_TARGET_HAS_rots_vec 0 |
59 | 17 | #define TCG_TARGET_HAS_rotv_vec 0 | |
60 | -void *tcg_rr_cpu_thread_fn(void *arg); | 18 | -#define TCG_TARGET_HAS_shi_vec 0 |
61 | +/* start the round robin vcpu thread */ | 19 | +#define TCG_TARGET_HAS_shi_vec 1 |
62 | +void rr_start_vcpu_thread(CPUState *cpu); | 20 | #define TCG_TARGET_HAS_shs_vec 0 |
63 | 21 | #define TCG_TARGET_HAS_shv_vec 0 | |
64 | #endif /* TCG_CPUS_RR_H */ | 22 | #define TCG_TARGET_HAS_mul_vec 0 |
65 | diff --git a/accel/tcg/tcg-cpus.h b/accel/tcg/tcg-cpus.h | 23 | diff --git a/tcg/arm/tcg-target.c.inc b/tcg/arm/tcg-target.c.inc |
66 | index XXXXXXX..XXXXXXX 100644 | 24 | index XXXXXXX..XXXXXXX 100644 |
67 | --- a/accel/tcg/tcg-cpus.h | 25 | --- a/tcg/arm/tcg-target.c.inc |
68 | +++ b/accel/tcg/tcg-cpus.h | 26 | +++ b/tcg/arm/tcg-target.c.inc |
69 | @@ -XXX,XX +XXX,XX @@ extern const CpusAccel tcg_cpus_mttcg; | 27 | @@ -XXX,XX +XXX,XX @@ typedef enum { |
70 | extern const CpusAccel tcg_cpus_icount; | 28 | INSN_VCGE_U = 0xf3000310, |
71 | extern const CpusAccel tcg_cpus_rr; | 29 | INSN_VCGT_U = 0xf3000300, |
72 | 30 | ||
73 | -void tcg_start_vcpu_thread(CPUState *cpu); | 31 | + INSN_VSHLI = 0xf2800510, /* VSHL (immediate) */ |
74 | void qemu_tcg_destroy_vcpu(CPUState *cpu); | 32 | + INSN_VSARI = 0xf2800010, /* VSHR.S */ |
75 | int tcg_cpu_exec(CPUState *cpu); | 33 | + INSN_VSHRI = 0xf3800010, /* VSHR.U */ |
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 | + | 34 | + |
90 | if (mttcg_enabled) { | 35 | INSN_VTST = 0xf2000810, |
91 | cpus_register_accel(&tcg_cpus_mttcg); | 36 | |
92 | } else if (icount_enabled()) { | 37 | INSN_VDUP_G = 0xee800b10, /* VDUP (ARM core register) */ |
93 | diff --git a/accel/tcg/tcg-cpus-icount.c b/accel/tcg/tcg-cpus-icount.c | 38 | @@ -XXX,XX +XXX,XX @@ static void tcg_out_vmovi(TCGContext *s, TCGReg rd, |
94 | index XXXXXXX..XXXXXXX 100644 | 39 | | (extract32(imm8, 7, 1) << 24)); |
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 | } | 40 | } |
99 | 41 | ||
100 | const CpusAccel tcg_cpus_icount = { | 42 | +static void tcg_out_vshifti(TCGContext *s, ARMInsn insn, int q, |
101 | - .create_vcpu_thread = tcg_start_vcpu_thread, | 43 | + TCGReg rd, TCGReg rm, int l_imm6) |
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 | +{ | 44 | +{ |
133 | + char thread_name[VCPU_THREAD_NAME_SIZE]; | 45 | + tcg_out32(s, insn | (q << 6) | encode_vd(rd) | encode_vm(rm) | |
134 | + | 46 | + (extract32(l_imm6, 6, 1) << 7) | |
135 | + g_assert(tcg_enabled()); | 47 | + (extract32(l_imm6, 0, 6) << 16)); |
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 | +} | 48 | +} |
154 | + | 49 | + |
155 | const CpusAccel tcg_cpus_mttcg = { | 50 | static void tcg_out_vldst(TCGContext *s, ARMInsn insn, |
156 | - .create_vcpu_thread = tcg_start_vcpu_thread, | 51 | TCGReg rd, TCGReg rn, int offset) |
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 | { | 52 | { |
172 | CPUState *cpu = arg; | 53 | @@ -XXX,XX +XXX,XX @@ static TCGConstraintSetIndex tcg_target_op_def(TCGOpcode op) |
173 | 54 | case INDEX_op_abs_vec: | |
174 | @@ -XXX,XX +XXX,XX @@ void *tcg_rr_cpu_thread_fn(void *arg) | 55 | case INDEX_op_neg_vec: |
175 | return NULL; | 56 | case INDEX_op_not_vec: |
176 | } | 57 | + case INDEX_op_shli_vec: |
177 | 58 | + case INDEX_op_shri_vec: | |
178 | +void rr_start_vcpu_thread(CPUState *cpu) | 59 | + case INDEX_op_sari_vec: |
179 | +{ | 60 | return C_O1_I1(w, w); |
180 | + char thread_name[VCPU_THREAD_NAME_SIZE]; | 61 | case INDEX_op_dup2_vec: |
181 | + static QemuCond *single_tcg_halt_cond; | 62 | case INDEX_op_add_vec: |
182 | + static QemuThread *single_tcg_cpu_thread; | 63 | @@ -XXX,XX +XXX,XX @@ static void tcg_out_vec_op(TCGContext *s, TCGOpcode opc, |
183 | + | 64 | case INDEX_op_xor_vec: |
184 | + g_assert(tcg_enabled()); | 65 | tcg_out_vreg3(s, INSN_VEOR, q, 0, a0, a1, a2); |
185 | + parallel_cpus = false; | 66 | return; |
186 | + | 67 | + case INDEX_op_shli_vec: |
187 | + if (!single_tcg_cpu_thread) { | 68 | + tcg_out_vshifti(s, INSN_VSHLI, q, a0, a1, a2 + (8 << vece)); |
188 | + cpu->thread = g_malloc0(sizeof(QemuThread)); | 69 | + return; |
189 | + cpu->halt_cond = g_malloc0(sizeof(QemuCond)); | 70 | + case INDEX_op_shri_vec: |
190 | + qemu_cond_init(cpu->halt_cond); | 71 | + tcg_out_vshifti(s, INSN_VSHRI, q, a0, a1, (16 << vece) - a2); |
191 | + | 72 | + return; |
192 | + /* share a single thread for all cpus with TCG */ | 73 | + case INDEX_op_sari_vec: |
193 | + snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "ALL CPUs/TCG"); | 74 | + tcg_out_vshifti(s, INSN_VSARI, q, a0, a1, (16 << vece) - a2); |
194 | + qemu_thread_create(cpu->thread, thread_name, | 75 | + return; |
195 | + tcg_rr_cpu_thread_fn, | 76 | |
196 | + cpu, QEMU_THREAD_JOINABLE); | 77 | case INDEX_op_andc_vec: |
197 | + | 78 | if (!const_args[2]) { |
198 | + single_tcg_halt_cond = cpu->halt_cond; | 79 | @@ -XXX,XX +XXX,XX @@ int tcg_can_emit_vec_op(TCGOpcode opc, TCGType type, unsigned vece) |
199 | + single_tcg_cpu_thread = cpu->thread; | 80 | case INDEX_op_orc_vec: |
200 | +#ifdef _WIN32 | 81 | case INDEX_op_xor_vec: |
201 | + cpu->hThread = qemu_thread_get_handle(cpu->thread); | 82 | case INDEX_op_not_vec: |
202 | +#endif | 83 | + case INDEX_op_shli_vec: |
203 | + } else { | 84 | + case INDEX_op_shri_vec: |
204 | + /* we share the thread */ | 85 | + case INDEX_op_sari_vec: |
205 | + cpu->thread = single_tcg_cpu_thread; | 86 | return 1; |
206 | + cpu->halt_cond = single_tcg_halt_cond; | 87 | case INDEX_op_abs_vec: |
207 | + cpu->thread_id = first_cpu->thread_id; | 88 | case INDEX_op_cmp_vec: |
208 | + cpu->can_do_io = 1; | ||
209 | + cpu->created = true; | ||
210 | + } | ||
211 | +} | ||
212 | + | ||
213 | const CpusAccel tcg_cpus_rr = { | ||
214 | - .create_vcpu_thread = tcg_start_vcpu_thread, | ||
215 | + .create_vcpu_thread = rr_start_vcpu_thread, | ||
216 | .kick_vcpu_thread = qemu_cpu_kick_rr_cpus, | ||
217 | |||
218 | .handle_interrupt = tcg_handle_interrupt, | ||
219 | diff --git a/accel/tcg/tcg-cpus.c b/accel/tcg/tcg-cpus.c | ||
220 | index XXXXXXX..XXXXXXX 100644 | ||
221 | --- a/accel/tcg/tcg-cpus.c | ||
222 | +++ b/accel/tcg/tcg-cpus.c | ||
223 | @@ -XXX,XX +XXX,XX @@ | ||
224 | #include "hw/boards.h" | ||
225 | |||
226 | #include "tcg-cpus.h" | ||
227 | -#include "tcg-cpus-mttcg.h" | ||
228 | -#include "tcg-cpus-rr.h" | ||
229 | |||
230 | /* common functionality among all TCG variants */ | ||
231 | |||
232 | -void tcg_start_vcpu_thread(CPUState *cpu) | ||
233 | -{ | ||
234 | - char thread_name[VCPU_THREAD_NAME_SIZE]; | ||
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 | - } | ||
251 | - | ||
252 | - if (qemu_tcg_mttcg_enabled() || !single_tcg_cpu_thread) { | ||
253 | - cpu->thread = g_malloc0(sizeof(QemuThread)); | ||
254 | - cpu->halt_cond = g_malloc0(sizeof(QemuCond)); | ||
255 | - qemu_cond_init(cpu->halt_cond); | ||
256 | - | ||
257 | - if (qemu_tcg_mttcg_enabled()) { | ||
258 | - /* create a thread per vCPU with TCG (MTTCG) */ | ||
259 | - snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/TCG", | ||
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 | -- | 89 | -- |
292 | 2.25.1 | 90 | 2.25.1 |
293 | 91 | ||
294 | 92 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
2 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
3 | --- | ||
4 | tcg/arm/tcg-target.h | 2 +- | ||
5 | tcg/arm/tcg-target.c.inc | 6 ++++++ | ||
6 | 2 files changed, 7 insertions(+), 1 deletion(-) | ||
1 | 7 | ||
8 | diff --git a/tcg/arm/tcg-target.h b/tcg/arm/tcg-target.h | ||
9 | index XXXXXXX..XXXXXXX 100644 | ||
10 | --- a/tcg/arm/tcg-target.h | ||
11 | +++ b/tcg/arm/tcg-target.h | ||
12 | @@ -XXX,XX +XXX,XX @@ extern bool use_neon_instructions; | ||
13 | #define TCG_TARGET_HAS_shi_vec 1 | ||
14 | #define TCG_TARGET_HAS_shs_vec 0 | ||
15 | #define TCG_TARGET_HAS_shv_vec 0 | ||
16 | -#define TCG_TARGET_HAS_mul_vec 0 | ||
17 | +#define TCG_TARGET_HAS_mul_vec 1 | ||
18 | #define TCG_TARGET_HAS_sat_vec 0 | ||
19 | #define TCG_TARGET_HAS_minmax_vec 0 | ||
20 | #define TCG_TARGET_HAS_bitsel_vec 0 | ||
21 | diff --git a/tcg/arm/tcg-target.c.inc b/tcg/arm/tcg-target.c.inc | ||
22 | index XXXXXXX..XXXXXXX 100644 | ||
23 | --- a/tcg/arm/tcg-target.c.inc | ||
24 | +++ b/tcg/arm/tcg-target.c.inc | ||
25 | @@ -XXX,XX +XXX,XX @@ typedef enum { | ||
26 | INSN_VORN = 0xf2300110, | ||
27 | INSN_VORR = 0xf2200110, | ||
28 | INSN_VSUB = 0xf3000800, | ||
29 | + INSN_VMUL = 0xf2000910, | ||
30 | |||
31 | INSN_VABS = 0xf3b10300, | ||
32 | INSN_VMVN = 0xf3b00580, | ||
33 | @@ -XXX,XX +XXX,XX @@ static TCGConstraintSetIndex tcg_target_op_def(TCGOpcode op) | ||
34 | return C_O1_I1(w, w); | ||
35 | case INDEX_op_dup2_vec: | ||
36 | case INDEX_op_add_vec: | ||
37 | + case INDEX_op_mul_vec: | ||
38 | case INDEX_op_sub_vec: | ||
39 | case INDEX_op_xor_vec: | ||
40 | return C_O1_I2(w, w, w); | ||
41 | @@ -XXX,XX +XXX,XX @@ static void tcg_out_vec_op(TCGContext *s, TCGOpcode opc, | ||
42 | case INDEX_op_add_vec: | ||
43 | tcg_out_vreg3(s, INSN_VADD, q, vece, a0, a1, a2); | ||
44 | return; | ||
45 | + case INDEX_op_mul_vec: | ||
46 | + tcg_out_vreg3(s, INSN_VMUL, q, vece, a0, a1, a2); | ||
47 | + return; | ||
48 | case INDEX_op_sub_vec: | ||
49 | tcg_out_vreg3(s, INSN_VSUB, q, vece, a0, a1, a2); | ||
50 | return; | ||
51 | @@ -XXX,XX +XXX,XX @@ int tcg_can_emit_vec_op(TCGOpcode opc, TCGType type, unsigned vece) | ||
52 | return 1; | ||
53 | case INDEX_op_abs_vec: | ||
54 | case INDEX_op_cmp_vec: | ||
55 | + case INDEX_op_mul_vec: | ||
56 | case INDEX_op_neg_vec: | ||
57 | return vece < MO_64; | ||
58 | default: | ||
59 | -- | ||
60 | 2.25.1 | ||
61 | |||
62 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | This is saturating add and subtract, signed and unsigned. | ||
1 | 2 | ||
3 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
5 | --- | ||
6 | tcg/arm/tcg-target.h | 2 +- | ||
7 | tcg/arm/tcg-target.c.inc | 24 ++++++++++++++++++++++++ | ||
8 | 2 files changed, 25 insertions(+), 1 deletion(-) | ||
9 | |||
10 | diff --git a/tcg/arm/tcg-target.h b/tcg/arm/tcg-target.h | ||
11 | index XXXXXXX..XXXXXXX 100644 | ||
12 | --- a/tcg/arm/tcg-target.h | ||
13 | +++ b/tcg/arm/tcg-target.h | ||
14 | @@ -XXX,XX +XXX,XX @@ extern bool use_neon_instructions; | ||
15 | #define TCG_TARGET_HAS_shs_vec 0 | ||
16 | #define TCG_TARGET_HAS_shv_vec 0 | ||
17 | #define TCG_TARGET_HAS_mul_vec 1 | ||
18 | -#define TCG_TARGET_HAS_sat_vec 0 | ||
19 | +#define TCG_TARGET_HAS_sat_vec 1 | ||
20 | #define TCG_TARGET_HAS_minmax_vec 0 | ||
21 | #define TCG_TARGET_HAS_bitsel_vec 0 | ||
22 | #define TCG_TARGET_HAS_cmpsel_vec 0 | ||
23 | diff --git a/tcg/arm/tcg-target.c.inc b/tcg/arm/tcg-target.c.inc | ||
24 | index XXXXXXX..XXXXXXX 100644 | ||
25 | --- a/tcg/arm/tcg-target.c.inc | ||
26 | +++ b/tcg/arm/tcg-target.c.inc | ||
27 | @@ -XXX,XX +XXX,XX @@ typedef enum { | ||
28 | INSN_VORR = 0xf2200110, | ||
29 | INSN_VSUB = 0xf3000800, | ||
30 | INSN_VMUL = 0xf2000910, | ||
31 | + INSN_VQADD = 0xf2000010, | ||
32 | + INSN_VQADD_U = 0xf3000010, | ||
33 | + INSN_VQSUB = 0xf2000210, | ||
34 | + INSN_VQSUB_U = 0xf3000210, | ||
35 | |||
36 | INSN_VABS = 0xf3b10300, | ||
37 | INSN_VMVN = 0xf3b00580, | ||
38 | @@ -XXX,XX +XXX,XX @@ static TCGConstraintSetIndex tcg_target_op_def(TCGOpcode op) | ||
39 | case INDEX_op_dup2_vec: | ||
40 | case INDEX_op_add_vec: | ||
41 | case INDEX_op_mul_vec: | ||
42 | + case INDEX_op_ssadd_vec: | ||
43 | + case INDEX_op_sssub_vec: | ||
44 | case INDEX_op_sub_vec: | ||
45 | + case INDEX_op_usadd_vec: | ||
46 | + case INDEX_op_ussub_vec: | ||
47 | case INDEX_op_xor_vec: | ||
48 | return C_O1_I2(w, w, w); | ||
49 | case INDEX_op_or_vec: | ||
50 | @@ -XXX,XX +XXX,XX @@ static void tcg_out_vec_op(TCGContext *s, TCGOpcode opc, | ||
51 | case INDEX_op_sub_vec: | ||
52 | tcg_out_vreg3(s, INSN_VSUB, q, vece, a0, a1, a2); | ||
53 | return; | ||
54 | + case INDEX_op_ssadd_vec: | ||
55 | + tcg_out_vreg3(s, INSN_VQADD, q, vece, a0, a1, a2); | ||
56 | + return; | ||
57 | + case INDEX_op_sssub_vec: | ||
58 | + tcg_out_vreg3(s, INSN_VQSUB, q, vece, a0, a1, a2); | ||
59 | + return; | ||
60 | + case INDEX_op_usadd_vec: | ||
61 | + tcg_out_vreg3(s, INSN_VQADD_U, q, vece, a0, a1, a2); | ||
62 | + return; | ||
63 | + case INDEX_op_ussub_vec: | ||
64 | + tcg_out_vreg3(s, INSN_VQSUB_U, q, vece, a0, a1, a2); | ||
65 | + return; | ||
66 | case INDEX_op_xor_vec: | ||
67 | tcg_out_vreg3(s, INSN_VEOR, q, 0, a0, a1, a2); | ||
68 | return; | ||
69 | @@ -XXX,XX +XXX,XX @@ int tcg_can_emit_vec_op(TCGOpcode opc, TCGType type, unsigned vece) | ||
70 | case INDEX_op_shli_vec: | ||
71 | case INDEX_op_shri_vec: | ||
72 | case INDEX_op_sari_vec: | ||
73 | + case INDEX_op_ssadd_vec: | ||
74 | + case INDEX_op_sssub_vec: | ||
75 | + case INDEX_op_usadd_vec: | ||
76 | + case INDEX_op_ussub_vec: | ||
77 | return 1; | ||
78 | case INDEX_op_abs_vec: | ||
79 | case INDEX_op_cmp_vec: | ||
80 | -- | ||
81 | 2.25.1 | ||
82 | |||
83 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | This is minimum and maximum, signed and unsigned. | ||
1 | 2 | ||
3 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
5 | --- | ||
6 | tcg/arm/tcg-target.h | 2 +- | ||
7 | tcg/arm/tcg-target.c.inc | 24 ++++++++++++++++++++++++ | ||
8 | 2 files changed, 25 insertions(+), 1 deletion(-) | ||
9 | |||
10 | diff --git a/tcg/arm/tcg-target.h b/tcg/arm/tcg-target.h | ||
11 | index XXXXXXX..XXXXXXX 100644 | ||
12 | --- a/tcg/arm/tcg-target.h | ||
13 | +++ b/tcg/arm/tcg-target.h | ||
14 | @@ -XXX,XX +XXX,XX @@ extern bool use_neon_instructions; | ||
15 | #define TCG_TARGET_HAS_shv_vec 0 | ||
16 | #define TCG_TARGET_HAS_mul_vec 1 | ||
17 | #define TCG_TARGET_HAS_sat_vec 1 | ||
18 | -#define TCG_TARGET_HAS_minmax_vec 0 | ||
19 | +#define TCG_TARGET_HAS_minmax_vec 1 | ||
20 | #define TCG_TARGET_HAS_bitsel_vec 0 | ||
21 | #define TCG_TARGET_HAS_cmpsel_vec 0 | ||
22 | |||
23 | diff --git a/tcg/arm/tcg-target.c.inc b/tcg/arm/tcg-target.c.inc | ||
24 | index XXXXXXX..XXXXXXX 100644 | ||
25 | --- a/tcg/arm/tcg-target.c.inc | ||
26 | +++ b/tcg/arm/tcg-target.c.inc | ||
27 | @@ -XXX,XX +XXX,XX @@ typedef enum { | ||
28 | INSN_VQADD_U = 0xf3000010, | ||
29 | INSN_VQSUB = 0xf2000210, | ||
30 | INSN_VQSUB_U = 0xf3000210, | ||
31 | + INSN_VMAX = 0xf2000600, | ||
32 | + INSN_VMAX_U = 0xf3000600, | ||
33 | + INSN_VMIN = 0xf2000610, | ||
34 | + INSN_VMIN_U = 0xf3000610, | ||
35 | |||
36 | INSN_VABS = 0xf3b10300, | ||
37 | INSN_VMVN = 0xf3b00580, | ||
38 | @@ -XXX,XX +XXX,XX @@ static TCGConstraintSetIndex tcg_target_op_def(TCGOpcode op) | ||
39 | case INDEX_op_dup2_vec: | ||
40 | case INDEX_op_add_vec: | ||
41 | case INDEX_op_mul_vec: | ||
42 | + case INDEX_op_smax_vec: | ||
43 | + case INDEX_op_smin_vec: | ||
44 | case INDEX_op_ssadd_vec: | ||
45 | case INDEX_op_sssub_vec: | ||
46 | case INDEX_op_sub_vec: | ||
47 | + case INDEX_op_umax_vec: | ||
48 | + case INDEX_op_umin_vec: | ||
49 | case INDEX_op_usadd_vec: | ||
50 | case INDEX_op_ussub_vec: | ||
51 | case INDEX_op_xor_vec: | ||
52 | @@ -XXX,XX +XXX,XX @@ static void tcg_out_vec_op(TCGContext *s, TCGOpcode opc, | ||
53 | case INDEX_op_mul_vec: | ||
54 | tcg_out_vreg3(s, INSN_VMUL, q, vece, a0, a1, a2); | ||
55 | return; | ||
56 | + case INDEX_op_smax_vec: | ||
57 | + tcg_out_vreg3(s, INSN_VMAX, q, vece, a0, a1, a2); | ||
58 | + return; | ||
59 | + case INDEX_op_smin_vec: | ||
60 | + tcg_out_vreg3(s, INSN_VMIN, q, vece, a0, a1, a2); | ||
61 | + return; | ||
62 | case INDEX_op_sub_vec: | ||
63 | tcg_out_vreg3(s, INSN_VSUB, q, vece, a0, a1, a2); | ||
64 | return; | ||
65 | @@ -XXX,XX +XXX,XX @@ static void tcg_out_vec_op(TCGContext *s, TCGOpcode opc, | ||
66 | case INDEX_op_sssub_vec: | ||
67 | tcg_out_vreg3(s, INSN_VQSUB, q, vece, a0, a1, a2); | ||
68 | return; | ||
69 | + case INDEX_op_umax_vec: | ||
70 | + tcg_out_vreg3(s, INSN_VMAX_U, q, vece, a0, a1, a2); | ||
71 | + return; | ||
72 | + case INDEX_op_umin_vec: | ||
73 | + tcg_out_vreg3(s, INSN_VMIN_U, q, vece, a0, a1, a2); | ||
74 | + return; | ||
75 | case INDEX_op_usadd_vec: | ||
76 | tcg_out_vreg3(s, INSN_VQADD_U, q, vece, a0, a1, a2); | ||
77 | return; | ||
78 | @@ -XXX,XX +XXX,XX @@ int tcg_can_emit_vec_op(TCGOpcode opc, TCGType type, unsigned vece) | ||
79 | case INDEX_op_cmp_vec: | ||
80 | case INDEX_op_mul_vec: | ||
81 | case INDEX_op_neg_vec: | ||
82 | + case INDEX_op_smax_vec: | ||
83 | + case INDEX_op_smin_vec: | ||
84 | + case INDEX_op_umax_vec: | ||
85 | + case INDEX_op_umin_vec: | ||
86 | return vece < MO_64; | ||
87 | default: | ||
88 | return 0; | ||
89 | -- | ||
90 | 2.25.1 | ||
91 | |||
92 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | NEON has 3 instructions implementing this 4 argument operation, | ||
2 | with each insn overlapping a different logical input onto the | ||
3 | destination register. | ||
1 | 4 | ||
5 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | --- | ||
8 | tcg/arm/tcg-target-con-set.h | 1 + | ||
9 | tcg/arm/tcg-target.h | 2 +- | ||
10 | tcg/arm/tcg-target.c.inc | 22 ++++++++++++++++++++-- | ||
11 | 3 files changed, 22 insertions(+), 3 deletions(-) | ||
12 | |||
13 | diff --git a/tcg/arm/tcg-target-con-set.h b/tcg/arm/tcg-target-con-set.h | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/tcg/arm/tcg-target-con-set.h | ||
16 | +++ b/tcg/arm/tcg-target-con-set.h | ||
17 | @@ -XXX,XX +XXX,XX @@ C_O1_I2(w, w, w) | ||
18 | C_O1_I2(w, w, wO) | ||
19 | C_O1_I2(w, w, wV) | ||
20 | C_O1_I2(w, w, wZ) | ||
21 | +C_O1_I3(w, w, w, w) | ||
22 | C_O1_I4(r, r, r, rI, rI) | ||
23 | C_O1_I4(r, r, rIN, rIK, 0) | ||
24 | C_O2_I1(r, r, l) | ||
25 | diff --git a/tcg/arm/tcg-target.h b/tcg/arm/tcg-target.h | ||
26 | index XXXXXXX..XXXXXXX 100644 | ||
27 | --- a/tcg/arm/tcg-target.h | ||
28 | +++ b/tcg/arm/tcg-target.h | ||
29 | @@ -XXX,XX +XXX,XX @@ extern bool use_neon_instructions; | ||
30 | #define TCG_TARGET_HAS_mul_vec 1 | ||
31 | #define TCG_TARGET_HAS_sat_vec 1 | ||
32 | #define TCG_TARGET_HAS_minmax_vec 1 | ||
33 | -#define TCG_TARGET_HAS_bitsel_vec 0 | ||
34 | +#define TCG_TARGET_HAS_bitsel_vec 1 | ||
35 | #define TCG_TARGET_HAS_cmpsel_vec 0 | ||
36 | |||
37 | #define TCG_TARGET_DEFAULT_MO (0) | ||
38 | diff --git a/tcg/arm/tcg-target.c.inc b/tcg/arm/tcg-target.c.inc | ||
39 | index XXXXXXX..XXXXXXX 100644 | ||
40 | --- a/tcg/arm/tcg-target.c.inc | ||
41 | +++ b/tcg/arm/tcg-target.c.inc | ||
42 | @@ -XXX,XX +XXX,XX @@ typedef enum { | ||
43 | INSN_VSARI = 0xf2800010, /* VSHR.S */ | ||
44 | INSN_VSHRI = 0xf3800010, /* VSHR.U */ | ||
45 | |||
46 | + INSN_VBSL = 0xf3100110, | ||
47 | + INSN_VBIT = 0xf3200110, | ||
48 | + INSN_VBIF = 0xf3300110, | ||
49 | + | ||
50 | INSN_VTST = 0xf2000810, | ||
51 | |||
52 | INSN_VDUP_G = 0xee800b10, /* VDUP (ARM core register) */ | ||
53 | @@ -XXX,XX +XXX,XX @@ static TCGConstraintSetIndex tcg_target_op_def(TCGOpcode op) | ||
54 | return C_O1_I2(w, w, wV); | ||
55 | case INDEX_op_cmp_vec: | ||
56 | return C_O1_I2(w, w, wZ); | ||
57 | - | ||
58 | + case INDEX_op_bitsel_vec: | ||
59 | + return C_O1_I3(w, w, w, w); | ||
60 | default: | ||
61 | g_assert_not_reached(); | ||
62 | } | ||
63 | @@ -XXX,XX +XXX,XX @@ static void tcg_out_vec_op(TCGContext *s, TCGOpcode opc, | ||
64 | { | ||
65 | TCGType type = vecl + TCG_TYPE_V64; | ||
66 | unsigned q = vecl; | ||
67 | - TCGArg a0, a1, a2; | ||
68 | + TCGArg a0, a1, a2, a3; | ||
69 | int cmode, imm8; | ||
70 | |||
71 | a0 = args[0]; | ||
72 | @@ -XXX,XX +XXX,XX @@ static void tcg_out_vec_op(TCGContext *s, TCGOpcode opc, | ||
73 | } | ||
74 | return; | ||
75 | |||
76 | + case INDEX_op_bitsel_vec: | ||
77 | + a3 = args[3]; | ||
78 | + if (a0 == a3) { | ||
79 | + tcg_out_vreg3(s, INSN_VBIT, q, 0, a0, a2, a1); | ||
80 | + } else if (a0 == a2) { | ||
81 | + tcg_out_vreg3(s, INSN_VBIF, q, 0, a0, a3, a1); | ||
82 | + } else { | ||
83 | + tcg_out_mov(s, type, a0, a1); | ||
84 | + tcg_out_vreg3(s, INSN_VBSL, q, 0, a0, a2, a3); | ||
85 | + } | ||
86 | + return; | ||
87 | + | ||
88 | case INDEX_op_mov_vec: /* Always emitted via tcg_out_mov. */ | ||
89 | case INDEX_op_dup_vec: /* Always emitted via tcg_out_dup_vec. */ | ||
90 | default: | ||
91 | @@ -XXX,XX +XXX,XX @@ int tcg_can_emit_vec_op(TCGOpcode opc, TCGType type, unsigned vece) | ||
92 | case INDEX_op_sssub_vec: | ||
93 | case INDEX_op_usadd_vec: | ||
94 | case INDEX_op_ussub_vec: | ||
95 | + case INDEX_op_bitsel_vec: | ||
96 | return 1; | ||
97 | case INDEX_op_abs_vec: | ||
98 | case INDEX_op_cmp_vec: | ||
99 | -- | ||
100 | 2.25.1 | ||
101 | |||
102 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | The three vector shift by vector operations are all implemented via | ||
2 | expansion. Therefore do not actually set TCG_TARGET_HAS_shv_vec, | ||
3 | as none of shlv_vec, shrv_vec, sarv_vec may actually appear in the | ||
4 | instruction stream, and therefore also do not appear in tcg_target_op_def. | ||
1 | 5 | ||
6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | --- | ||
9 | tcg/arm/tcg-target.opc.h | 3 ++ | ||
10 | tcg/arm/tcg-target.c.inc | 61 +++++++++++++++++++++++++++++++++++++++- | ||
11 | 2 files changed, 63 insertions(+), 1 deletion(-) | ||
12 | |||
13 | diff --git a/tcg/arm/tcg-target.opc.h b/tcg/arm/tcg-target.opc.h | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/tcg/arm/tcg-target.opc.h | ||
16 | +++ b/tcg/arm/tcg-target.opc.h | ||
17 | @@ -XXX,XX +XXX,XX @@ | ||
18 | * emitted by tcg_expand_vec_op. For those familiar with GCC internals, | ||
19 | * consider these to be UNSPEC with names. | ||
20 | */ | ||
21 | + | ||
22 | +DEF(arm_sshl_vec, 1, 2, 0, IMPLVEC) | ||
23 | +DEF(arm_ushl_vec, 1, 2, 0, IMPLVEC) | ||
24 | diff --git a/tcg/arm/tcg-target.c.inc b/tcg/arm/tcg-target.c.inc | ||
25 | index XXXXXXX..XXXXXXX 100644 | ||
26 | --- a/tcg/arm/tcg-target.c.inc | ||
27 | +++ b/tcg/arm/tcg-target.c.inc | ||
28 | @@ -XXX,XX +XXX,XX @@ typedef enum { | ||
29 | INSN_VSHLI = 0xf2800510, /* VSHL (immediate) */ | ||
30 | INSN_VSARI = 0xf2800010, /* VSHR.S */ | ||
31 | INSN_VSHRI = 0xf3800010, /* VSHR.U */ | ||
32 | + INSN_VSHL_S = 0xf2000400, /* VSHL.S (register) */ | ||
33 | + INSN_VSHL_U = 0xf3000400, /* VSHL.U (register) */ | ||
34 | |||
35 | INSN_VBSL = 0xf3100110, | ||
36 | INSN_VBIT = 0xf3200110, | ||
37 | @@ -XXX,XX +XXX,XX @@ static TCGConstraintSetIndex tcg_target_op_def(TCGOpcode op) | ||
38 | case INDEX_op_usadd_vec: | ||
39 | case INDEX_op_ussub_vec: | ||
40 | case INDEX_op_xor_vec: | ||
41 | + case INDEX_op_arm_sshl_vec: | ||
42 | + case INDEX_op_arm_ushl_vec: | ||
43 | return C_O1_I2(w, w, w); | ||
44 | case INDEX_op_or_vec: | ||
45 | case INDEX_op_andc_vec: | ||
46 | @@ -XXX,XX +XXX,XX @@ static void tcg_out_vec_op(TCGContext *s, TCGOpcode opc, | ||
47 | case INDEX_op_xor_vec: | ||
48 | tcg_out_vreg3(s, INSN_VEOR, q, 0, a0, a1, a2); | ||
49 | return; | ||
50 | + case INDEX_op_arm_sshl_vec: | ||
51 | + /* | ||
52 | + * Note that Vm is the data and Vn is the shift count, | ||
53 | + * therefore the arguments appear reversed. | ||
54 | + */ | ||
55 | + tcg_out_vreg3(s, INSN_VSHL_S, q, vece, a0, a2, a1); | ||
56 | + return; | ||
57 | + case INDEX_op_arm_ushl_vec: | ||
58 | + /* See above. */ | ||
59 | + tcg_out_vreg3(s, INSN_VSHL_U, q, vece, a0, a2, a1); | ||
60 | + return; | ||
61 | case INDEX_op_shli_vec: | ||
62 | tcg_out_vshifti(s, INSN_VSHLI, q, a0, a1, a2 + (8 << vece)); | ||
63 | return; | ||
64 | @@ -XXX,XX +XXX,XX @@ int tcg_can_emit_vec_op(TCGOpcode opc, TCGType type, unsigned vece) | ||
65 | case INDEX_op_umax_vec: | ||
66 | case INDEX_op_umin_vec: | ||
67 | return vece < MO_64; | ||
68 | + case INDEX_op_shlv_vec: | ||
69 | + case INDEX_op_shrv_vec: | ||
70 | + case INDEX_op_sarv_vec: | ||
71 | + return -1; | ||
72 | default: | ||
73 | return 0; | ||
74 | } | ||
75 | @@ -XXX,XX +XXX,XX @@ int tcg_can_emit_vec_op(TCGOpcode opc, TCGType type, unsigned vece) | ||
76 | void tcg_expand_vec_op(TCGOpcode opc, TCGType type, unsigned vece, | ||
77 | TCGArg a0, ...) | ||
78 | { | ||
79 | - g_assert_not_reached(); | ||
80 | + va_list va; | ||
81 | + TCGv_vec v0, v1, v2, t1; | ||
82 | + TCGArg a2; | ||
83 | + | ||
84 | + va_start(va, a0); | ||
85 | + v0 = temp_tcgv_vec(arg_temp(a0)); | ||
86 | + v1 = temp_tcgv_vec(arg_temp(va_arg(va, TCGArg))); | ||
87 | + a2 = va_arg(va, TCGArg); | ||
88 | + va_end(va); | ||
89 | + | ||
90 | + switch (opc) { | ||
91 | + case INDEX_op_shlv_vec: | ||
92 | + /* | ||
93 | + * Merely propagate shlv_vec to arm_ushl_vec. | ||
94 | + * In this way we don't set TCG_TARGET_HAS_shv_vec | ||
95 | + * because everything is done via expansion. | ||
96 | + */ | ||
97 | + v2 = temp_tcgv_vec(arg_temp(a2)); | ||
98 | + vec_gen_3(INDEX_op_arm_ushl_vec, type, vece, tcgv_vec_arg(v0), | ||
99 | + tcgv_vec_arg(v1), tcgv_vec_arg(v2)); | ||
100 | + break; | ||
101 | + | ||
102 | + case INDEX_op_shrv_vec: | ||
103 | + case INDEX_op_sarv_vec: | ||
104 | + /* Right shifts are negative left shifts for NEON. */ | ||
105 | + v2 = temp_tcgv_vec(arg_temp(a2)); | ||
106 | + t1 = tcg_temp_new_vec(type); | ||
107 | + tcg_gen_neg_vec(vece, t1, v2); | ||
108 | + if (opc == INDEX_op_shrv_vec) { | ||
109 | + opc = INDEX_op_arm_ushl_vec; | ||
110 | + } else { | ||
111 | + opc = INDEX_op_arm_sshl_vec; | ||
112 | + } | ||
113 | + vec_gen_3(opc, type, vece, tcgv_vec_arg(v0), | ||
114 | + tcgv_vec_arg(v1), tcgv_vec_arg(t1)); | ||
115 | + tcg_temp_free_vec(t1); | ||
116 | + break; | ||
117 | + | ||
118 | + default: | ||
119 | + g_assert_not_reached(); | ||
120 | + } | ||
121 | } | ||
122 | |||
123 | static void tcg_out_nop_fill(tcg_insn_unit *p, int count) | ||
124 | -- | ||
125 | 2.25.1 | ||
126 | |||
127 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Implement via expansion, so don't actually set TCG_TARGET_HAS_roti_vec. | ||
2 | For NEON, this is shift-right followed by shift-left-and-insert. | ||
1 | 3 | ||
4 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | --- | ||
7 | tcg/arm/tcg-target-con-set.h | 1 + | ||
8 | tcg/arm/tcg-target.opc.h | 1 + | ||
9 | tcg/arm/tcg-target.c.inc | 15 +++++++++++++++ | ||
10 | 3 files changed, 17 insertions(+) | ||
11 | |||
12 | diff --git a/tcg/arm/tcg-target-con-set.h b/tcg/arm/tcg-target-con-set.h | ||
13 | index XXXXXXX..XXXXXXX 100644 | ||
14 | --- a/tcg/arm/tcg-target-con-set.h | ||
15 | +++ b/tcg/arm/tcg-target-con-set.h | ||
16 | @@ -XXX,XX +XXX,XX @@ C_O1_I2(r, r, rIK) | ||
17 | C_O1_I2(r, r, rIN) | ||
18 | C_O1_I2(r, r, ri) | ||
19 | C_O1_I2(r, rZ, rZ) | ||
20 | +C_O1_I2(w, 0, w) | ||
21 | C_O1_I2(w, w, w) | ||
22 | C_O1_I2(w, w, wO) | ||
23 | C_O1_I2(w, w, wV) | ||
24 | diff --git a/tcg/arm/tcg-target.opc.h b/tcg/arm/tcg-target.opc.h | ||
25 | index XXXXXXX..XXXXXXX 100644 | ||
26 | --- a/tcg/arm/tcg-target.opc.h | ||
27 | +++ b/tcg/arm/tcg-target.opc.h | ||
28 | @@ -XXX,XX +XXX,XX @@ | ||
29 | * consider these to be UNSPEC with names. | ||
30 | */ | ||
31 | |||
32 | +DEF(arm_sli_vec, 1, 2, 1, IMPLVEC) | ||
33 | DEF(arm_sshl_vec, 1, 2, 0, IMPLVEC) | ||
34 | DEF(arm_ushl_vec, 1, 2, 0, IMPLVEC) | ||
35 | diff --git a/tcg/arm/tcg-target.c.inc b/tcg/arm/tcg-target.c.inc | ||
36 | index XXXXXXX..XXXXXXX 100644 | ||
37 | --- a/tcg/arm/tcg-target.c.inc | ||
38 | +++ b/tcg/arm/tcg-target.c.inc | ||
39 | @@ -XXX,XX +XXX,XX @@ typedef enum { | ||
40 | INSN_VSHLI = 0xf2800510, /* VSHL (immediate) */ | ||
41 | INSN_VSARI = 0xf2800010, /* VSHR.S */ | ||
42 | INSN_VSHRI = 0xf3800010, /* VSHR.U */ | ||
43 | + INSN_VSLI = 0xf3800510, | ||
44 | INSN_VSHL_S = 0xf2000400, /* VSHL.S (register) */ | ||
45 | INSN_VSHL_U = 0xf3000400, /* VSHL.U (register) */ | ||
46 | |||
47 | @@ -XXX,XX +XXX,XX @@ static TCGConstraintSetIndex tcg_target_op_def(TCGOpcode op) | ||
48 | case INDEX_op_arm_sshl_vec: | ||
49 | case INDEX_op_arm_ushl_vec: | ||
50 | return C_O1_I2(w, w, w); | ||
51 | + case INDEX_op_arm_sli_vec: | ||
52 | + return C_O1_I2(w, 0, w); | ||
53 | case INDEX_op_or_vec: | ||
54 | case INDEX_op_andc_vec: | ||
55 | return C_O1_I2(w, w, wO); | ||
56 | @@ -XXX,XX +XXX,XX @@ static void tcg_out_vec_op(TCGContext *s, TCGOpcode opc, | ||
57 | case INDEX_op_sari_vec: | ||
58 | tcg_out_vshifti(s, INSN_VSARI, q, a0, a1, (16 << vece) - a2); | ||
59 | return; | ||
60 | + case INDEX_op_arm_sli_vec: | ||
61 | + tcg_out_vshifti(s, INSN_VSLI, q, a0, a2, args[3] + (8 << vece)); | ||
62 | + return; | ||
63 | |||
64 | case INDEX_op_andc_vec: | ||
65 | if (!const_args[2]) { | ||
66 | @@ -XXX,XX +XXX,XX @@ int tcg_can_emit_vec_op(TCGOpcode opc, TCGType type, unsigned vece) | ||
67 | case INDEX_op_shlv_vec: | ||
68 | case INDEX_op_shrv_vec: | ||
69 | case INDEX_op_sarv_vec: | ||
70 | + case INDEX_op_rotli_vec: | ||
71 | return -1; | ||
72 | default: | ||
73 | return 0; | ||
74 | @@ -XXX,XX +XXX,XX @@ void tcg_expand_vec_op(TCGOpcode opc, TCGType type, unsigned vece, | ||
75 | tcg_temp_free_vec(t1); | ||
76 | break; | ||
77 | |||
78 | + case INDEX_op_rotli_vec: | ||
79 | + t1 = tcg_temp_new_vec(type); | ||
80 | + tcg_gen_shri_vec(vece, t1, v1, -a2 & ((8 << vece) - 1)); | ||
81 | + vec_gen_4(INDEX_op_arm_sli_vec, type, vece, | ||
82 | + tcgv_vec_arg(v0), tcgv_vec_arg(t1), tcgv_vec_arg(v1), a2); | ||
83 | + tcg_temp_free_vec(t1); | ||
84 | + break; | ||
85 | + | ||
86 | default: | ||
87 | g_assert_not_reached(); | ||
88 | } | ||
89 | -- | ||
90 | 2.25.1 | ||
91 | |||
92 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Implement via expansion, so don't actually set TCG_TARGET_HAS_rotv_vec. | ||
1 | 2 | ||
3 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
5 | --- | ||
6 | tcg/arm/tcg-target.c.inc | 35 ++++++++++++++++++++++++++++++++++- | ||
7 | 1 file changed, 34 insertions(+), 1 deletion(-) | ||
8 | |||
9 | diff --git a/tcg/arm/tcg-target.c.inc b/tcg/arm/tcg-target.c.inc | ||
10 | index XXXXXXX..XXXXXXX 100644 | ||
11 | --- a/tcg/arm/tcg-target.c.inc | ||
12 | +++ b/tcg/arm/tcg-target.c.inc | ||
13 | @@ -XXX,XX +XXX,XX @@ int tcg_can_emit_vec_op(TCGOpcode opc, TCGType type, unsigned vece) | ||
14 | case INDEX_op_shrv_vec: | ||
15 | case INDEX_op_sarv_vec: | ||
16 | case INDEX_op_rotli_vec: | ||
17 | + case INDEX_op_rotlv_vec: | ||
18 | + case INDEX_op_rotrv_vec: | ||
19 | return -1; | ||
20 | default: | ||
21 | return 0; | ||
22 | @@ -XXX,XX +XXX,XX @@ void tcg_expand_vec_op(TCGOpcode opc, TCGType type, unsigned vece, | ||
23 | TCGArg a0, ...) | ||
24 | { | ||
25 | va_list va; | ||
26 | - TCGv_vec v0, v1, v2, t1; | ||
27 | + TCGv_vec v0, v1, v2, t1, t2, c1; | ||
28 | TCGArg a2; | ||
29 | |||
30 | va_start(va, a0); | ||
31 | @@ -XXX,XX +XXX,XX @@ void tcg_expand_vec_op(TCGOpcode opc, TCGType type, unsigned vece, | ||
32 | tcg_temp_free_vec(t1); | ||
33 | break; | ||
34 | |||
35 | + case INDEX_op_rotlv_vec: | ||
36 | + v2 = temp_tcgv_vec(arg_temp(a2)); | ||
37 | + t1 = tcg_temp_new_vec(type); | ||
38 | + c1 = tcg_constant_vec(type, vece, 8 << vece); | ||
39 | + tcg_gen_sub_vec(vece, t1, v2, c1); | ||
40 | + /* Right shifts are negative left shifts for NEON. */ | ||
41 | + vec_gen_3(INDEX_op_arm_ushl_vec, type, vece, tcgv_vec_arg(t1), | ||
42 | + tcgv_vec_arg(v1), tcgv_vec_arg(t1)); | ||
43 | + vec_gen_3(INDEX_op_arm_ushl_vec, type, vece, tcgv_vec_arg(v0), | ||
44 | + tcgv_vec_arg(v1), tcgv_vec_arg(v2)); | ||
45 | + tcg_gen_or_vec(vece, v0, v0, t1); | ||
46 | + tcg_temp_free_vec(t1); | ||
47 | + break; | ||
48 | + | ||
49 | + case INDEX_op_rotrv_vec: | ||
50 | + v2 = temp_tcgv_vec(arg_temp(a2)); | ||
51 | + t1 = tcg_temp_new_vec(type); | ||
52 | + t2 = tcg_temp_new_vec(type); | ||
53 | + c1 = tcg_constant_vec(type, vece, 8 << vece); | ||
54 | + tcg_gen_neg_vec(vece, t1, v2); | ||
55 | + tcg_gen_sub_vec(vece, t2, c1, v2); | ||
56 | + /* Right shifts are negative left shifts for NEON. */ | ||
57 | + vec_gen_3(INDEX_op_arm_ushl_vec, type, vece, tcgv_vec_arg(t1), | ||
58 | + tcgv_vec_arg(v1), tcgv_vec_arg(t1)); | ||
59 | + vec_gen_3(INDEX_op_arm_ushl_vec, type, vece, tcgv_vec_arg(t2), | ||
60 | + tcgv_vec_arg(v1), tcgv_vec_arg(t2)); | ||
61 | + tcg_gen_or_vec(vece, v0, t1, t2); | ||
62 | + tcg_temp_free_vec(t1); | ||
63 | + tcg_temp_free_vec(t2); | ||
64 | + break; | ||
65 | + | ||
66 | default: | ||
67 | g_assert_not_reached(); | ||
68 | } | ||
69 | -- | ||
70 | 2.25.1 | ||
71 | |||
72 | diff view generated by jsdifflib |