xref: /qemu/target/hexagon/translate.h (revision 763d2ce7)
18b453a2bSTaylor Simpson /*
276eaa971STaylor Simpson  *  Copyright(c) 2019-2024 Qualcomm Innovation Center, Inc. All Rights Reserved.
38b453a2bSTaylor Simpson  *
48b453a2bSTaylor Simpson  *  This program is free software; you can redistribute it and/or modify
58b453a2bSTaylor Simpson  *  it under the terms of the GNU General Public License as published by
68b453a2bSTaylor Simpson  *  the Free Software Foundation; either version 2 of the License, or
78b453a2bSTaylor Simpson  *  (at your option) any later version.
88b453a2bSTaylor Simpson  *
98b453a2bSTaylor Simpson  *  This program is distributed in the hope that it will be useful,
108b453a2bSTaylor Simpson  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
118b453a2bSTaylor Simpson  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
128b453a2bSTaylor Simpson  *  GNU General Public License for more details.
138b453a2bSTaylor Simpson  *
148b453a2bSTaylor Simpson  *  You should have received a copy of the GNU General Public License
158b453a2bSTaylor Simpson  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
168b453a2bSTaylor Simpson  */
178b453a2bSTaylor Simpson 
188b453a2bSTaylor Simpson #ifndef HEXAGON_TRANSLATE_H
198b453a2bSTaylor Simpson #define HEXAGON_TRANSLATE_H
208b453a2bSTaylor Simpson 
218b453a2bSTaylor Simpson #include "qemu/bitmap.h"
22cd617484SPhilippe Mathieu-Daudé #include "qemu/log.h"
238b453a2bSTaylor Simpson #include "cpu.h"
248b453a2bSTaylor Simpson #include "exec/translator.h"
258b453a2bSTaylor Simpson #include "tcg/tcg-op.h"
261e536334STaylor Simpson #include "insn.h"
278b453a2bSTaylor Simpson #include "internal.h"
288b453a2bSTaylor Simpson 
298b453a2bSTaylor Simpson typedef struct DisasContext {
308b453a2bSTaylor Simpson     DisasContextBase base;
311e536334STaylor Simpson     Packet *pkt;
321e536334STaylor Simpson     Insn *insn;
33613653e5STaylor Simpson     uint32_t next_PC;
348b453a2bSTaylor Simpson     uint32_t mem_idx;
358b453a2bSTaylor Simpson     uint32_t num_packets;
368b453a2bSTaylor Simpson     uint32_t num_insns;
37a82dd548STaylor Simpson     uint32_t num_hvx_insns;
388b453a2bSTaylor Simpson     int reg_log[REG_WRITES_MAX];
398b453a2bSTaylor Simpson     int reg_log_idx;
408b453a2bSTaylor Simpson     DECLARE_BITMAP(regs_written, TOTAL_PER_THREAD_REGS);
4110849c26STaylor Simpson     DECLARE_BITMAP(predicated_regs, TOTAL_PER_THREAD_REGS);
428b453a2bSTaylor Simpson     int preg_log[PRED_WRITES_MAX];
438b453a2bSTaylor Simpson     int preg_log_idx;
446c677c60STaylor Simpson     DECLARE_BITMAP(pregs_written, NUM_PREGS);
458b453a2bSTaylor Simpson     uint8_t store_width[STORES_MAX];
4692cfa25fSTaylor Simpson     bool s1_store_processed;
47a82dd548STaylor Simpson     int future_vregs_idx;
48a82dd548STaylor Simpson     int future_vregs_num[VECTOR_TEMPS_MAX];
49a82dd548STaylor Simpson     int tmp_vregs_idx;
50a82dd548STaylor Simpson     int tmp_vregs_num[VECTOR_TEMPS_MAX];
51a82dd548STaylor Simpson     int vreg_log[NUM_VREGS];
52a82dd548STaylor Simpson     int vreg_log_idx;
53763d2ce7STaylor Simpson     DECLARE_BITMAP(vregs_written, NUM_VREGS);
54763d2ce7STaylor Simpson     DECLARE_BITMAP(insn_vregs_written, NUM_VREGS);
55a82dd548STaylor Simpson     DECLARE_BITMAP(vregs_updated_tmp, NUM_VREGS);
56a82dd548STaylor Simpson     DECLARE_BITMAP(vregs_updated, NUM_VREGS);
57a82dd548STaylor Simpson     DECLARE_BITMAP(vregs_select, NUM_VREGS);
584d6f8420STaylor Simpson     DECLARE_BITMAP(predicated_future_vregs, NUM_VREGS);
594d6f8420STaylor Simpson     DECLARE_BITMAP(predicated_tmp_vregs, NUM_VREGS);
60763d2ce7STaylor Simpson     DECLARE_BITMAP(insn_vregs_read, NUM_VREGS);
61a82dd548STaylor Simpson     int qreg_log[NUM_QREGS];
62a82dd548STaylor Simpson     int qreg_log_idx;
63763d2ce7STaylor Simpson     DECLARE_BITMAP(qregs_written, NUM_QREGS);
64763d2ce7STaylor Simpson     DECLARE_BITMAP(insn_qregs_written, NUM_QREGS);
65763d2ce7STaylor Simpson     DECLARE_BITMAP(insn_qregs_read, NUM_QREGS);
66a82dd548STaylor Simpson     bool pre_commit;
67d54c5615STaylor Simpson     bool need_commit;
681b9a7f2aSTaylor Simpson     TCGCond branch_cond;
691b9a7f2aSTaylor Simpson     target_ulong branch_dest;
70564b2040STaylor Simpson     bool is_tight_loop;
71d54c5615STaylor Simpson     bool short_circuit;
72bd983f68STaylor Simpson     bool read_after_write;
73763d2ce7STaylor Simpson     bool has_hvx_overlap;
744ff56764STaylor Simpson     TCGv new_value[TOTAL_PER_THREAD_REGS];
75e22edc7cSTaylor Simpson     TCGv new_pred_value[NUM_PREGS];
76842b206fSTaylor Simpson     TCGv pred_written;
770fc56c43STaylor Simpson     TCGv branch_taken;
780fc56c43STaylor Simpson     TCGv dczero_addr;
798b453a2bSTaylor Simpson } DisasContext;
808b453a2bSTaylor Simpson 
8176eaa971STaylor Simpson bool is_gather_store_insn(DisasContext *ctx);
8276eaa971STaylor Simpson 
ctx_log_pred_write(DisasContext * ctx,int pnum)838b453a2bSTaylor Simpson static inline void ctx_log_pred_write(DisasContext *ctx, int pnum)
848b453a2bSTaylor Simpson {
8510849c26STaylor Simpson     if (!test_bit(pnum, ctx->pregs_written)) {
868b453a2bSTaylor Simpson         ctx->preg_log[ctx->preg_log_idx] = pnum;
878b453a2bSTaylor Simpson         ctx->preg_log_idx++;
886c677c60STaylor Simpson         set_bit(pnum, ctx->pregs_written);
898b453a2bSTaylor Simpson     }
9010849c26STaylor Simpson }
918b453a2bSTaylor Simpson 
ctx_log_pred_read(DisasContext * ctx,int pnum)92b9f0326bSTaylor Simpson static inline void ctx_log_pred_read(DisasContext *ctx, int pnum)
93b9f0326bSTaylor Simpson {
94bd983f68STaylor Simpson     if (test_bit(pnum, ctx->pregs_written)) {
95bd983f68STaylor Simpson         ctx->read_after_write = true;
96bd983f68STaylor Simpson     }
97b9f0326bSTaylor Simpson }
98b9f0326bSTaylor Simpson 
ctx_log_pred_read_new(DisasContext * ctx,int pnum)9976eaa971STaylor Simpson static inline void ctx_log_pred_read_new(DisasContext *ctx, int pnum)
10076eaa971STaylor Simpson {
10176eaa971STaylor Simpson     g_assert(test_bit(pnum, ctx->pregs_written));
10276eaa971STaylor Simpson }
10376eaa971STaylor Simpson 
ctx_log_reg_write(DisasContext * ctx,int rnum,bool is_predicated)10410849c26STaylor Simpson static inline void ctx_log_reg_write(DisasContext *ctx, int rnum,
10510849c26STaylor Simpson                                      bool is_predicated)
1068b453a2bSTaylor Simpson {
10710849c26STaylor Simpson     if (rnum == HEX_REG_P3_0_ALIASED) {
10810849c26STaylor Simpson         for (int i = 0; i < NUM_PREGS; i++) {
10910849c26STaylor Simpson             ctx_log_pred_write(ctx, i);
11010849c26STaylor Simpson         }
11110849c26STaylor Simpson     } else {
11210849c26STaylor Simpson         if (!test_bit(rnum, ctx->regs_written)) {
11310849c26STaylor Simpson             ctx->reg_log[ctx->reg_log_idx] = rnum;
11410849c26STaylor Simpson             ctx->reg_log_idx++;
11510849c26STaylor Simpson             set_bit(rnum, ctx->regs_written);
11610849c26STaylor Simpson         }
11710849c26STaylor Simpson         if (is_predicated) {
11810849c26STaylor Simpson             set_bit(rnum, ctx->predicated_regs);
11910849c26STaylor Simpson         }
12010849c26STaylor Simpson     }
12110849c26STaylor Simpson }
12210849c26STaylor Simpson 
ctx_log_reg_write_pair(DisasContext * ctx,int rnum,bool is_predicated)12310849c26STaylor Simpson static inline void ctx_log_reg_write_pair(DisasContext *ctx, int rnum,
12410849c26STaylor Simpson                                           bool is_predicated)
12510849c26STaylor Simpson {
12610849c26STaylor Simpson     ctx_log_reg_write(ctx, rnum, is_predicated);
12710849c26STaylor Simpson     ctx_log_reg_write(ctx, rnum + 1, is_predicated);
1288b453a2bSTaylor Simpson }
1298b453a2bSTaylor Simpson 
ctx_log_reg_read(DisasContext * ctx,int rnum)130b9f0326bSTaylor Simpson static inline void ctx_log_reg_read(DisasContext *ctx, int rnum)
131b9f0326bSTaylor Simpson {
132bd983f68STaylor Simpson     if (test_bit(rnum, ctx->regs_written)) {
133bd983f68STaylor Simpson         ctx->read_after_write = true;
134bd983f68STaylor Simpson     }
135b9f0326bSTaylor Simpson }
136b9f0326bSTaylor Simpson 
ctx_log_reg_read_new(DisasContext * ctx,int rnum)13776eaa971STaylor Simpson static inline void ctx_log_reg_read_new(DisasContext *ctx, int rnum)
13876eaa971STaylor Simpson {
13976eaa971STaylor Simpson     g_assert(test_bit(rnum, ctx->regs_written));
14076eaa971STaylor Simpson }
14176eaa971STaylor Simpson 
ctx_log_reg_read_pair(DisasContext * ctx,int rnum)142b9f0326bSTaylor Simpson static inline void ctx_log_reg_read_pair(DisasContext *ctx, int rnum)
143b9f0326bSTaylor Simpson {
144b9f0326bSTaylor Simpson     ctx_log_reg_read(ctx, rnum);
145b9f0326bSTaylor Simpson     ctx_log_reg_read(ctx, rnum + 1);
146b9f0326bSTaylor Simpson }
147b9f0326bSTaylor Simpson 
148a82dd548STaylor Simpson intptr_t ctx_future_vreg_off(DisasContext *ctx, int regnum,
149a82dd548STaylor Simpson                              int num, bool alloc_ok);
150a82dd548STaylor Simpson intptr_t ctx_tmp_vreg_off(DisasContext *ctx, int regnum,
151a82dd548STaylor Simpson                           int num, bool alloc_ok);
152a82dd548STaylor Simpson 
ctx_start_hvx_insn(DisasContext * ctx)153763d2ce7STaylor Simpson static inline void ctx_start_hvx_insn(DisasContext *ctx)
154763d2ce7STaylor Simpson {
155763d2ce7STaylor Simpson     bitmap_zero(ctx->insn_vregs_written, NUM_VREGS);
156763d2ce7STaylor Simpson     bitmap_zero(ctx->insn_vregs_read, NUM_VREGS);
157763d2ce7STaylor Simpson     bitmap_zero(ctx->insn_qregs_written, NUM_QREGS);
158763d2ce7STaylor Simpson     bitmap_zero(ctx->insn_qregs_read, NUM_QREGS);
159763d2ce7STaylor Simpson }
160763d2ce7STaylor Simpson 
ctx_log_vreg_write(DisasContext * ctx,int rnum,VRegWriteType type,bool is_predicated,bool has_helper)161a82dd548STaylor Simpson static inline void ctx_log_vreg_write(DisasContext *ctx,
162a82dd548STaylor Simpson                                       int rnum, VRegWriteType type,
163763d2ce7STaylor Simpson                                       bool is_predicated, bool has_helper)
164a82dd548STaylor Simpson {
165763d2ce7STaylor Simpson     if (has_helper) {
166763d2ce7STaylor Simpson         set_bit(rnum, ctx->insn_vregs_written);
167763d2ce7STaylor Simpson         if (test_bit(rnum, ctx->insn_vregs_read)) {
168763d2ce7STaylor Simpson             ctx->has_hvx_overlap = true;
169763d2ce7STaylor Simpson         }
170763d2ce7STaylor Simpson     }
171763d2ce7STaylor Simpson     set_bit(rnum, ctx->vregs_written);
172a82dd548STaylor Simpson     if (type != EXT_TMP) {
173c2b33d0bSTaylor Simpson         if (!test_bit(rnum, ctx->vregs_updated)) {
174a82dd548STaylor Simpson             ctx->vreg_log[ctx->vreg_log_idx] = rnum;
175a82dd548STaylor Simpson             ctx->vreg_log_idx++;
176c2b33d0bSTaylor Simpson             set_bit(rnum, ctx->vregs_updated);
177c2b33d0bSTaylor Simpson         }
178a82dd548STaylor Simpson 
179a82dd548STaylor Simpson         set_bit(rnum, ctx->vregs_updated);
1804d6f8420STaylor Simpson         if (is_predicated) {
1814d6f8420STaylor Simpson             set_bit(rnum, ctx->predicated_future_vregs);
1824d6f8420STaylor Simpson         }
183a82dd548STaylor Simpson     }
184a82dd548STaylor Simpson     if (type == EXT_NEW) {
185a82dd548STaylor Simpson         set_bit(rnum, ctx->vregs_select);
186a82dd548STaylor Simpson     }
187a82dd548STaylor Simpson     if (type == EXT_TMP) {
188a82dd548STaylor Simpson         set_bit(rnum, ctx->vregs_updated_tmp);
1894d6f8420STaylor Simpson         if (is_predicated) {
1904d6f8420STaylor Simpson             set_bit(rnum, ctx->predicated_tmp_vregs);
1914d6f8420STaylor Simpson         }
192a82dd548STaylor Simpson     }
193a82dd548STaylor Simpson }
194a82dd548STaylor Simpson 
ctx_log_vreg_write_pair(DisasContext * ctx,int rnum,VRegWriteType type,bool is_predicated,bool has_helper)195a82dd548STaylor Simpson static inline void ctx_log_vreg_write_pair(DisasContext *ctx,
196a82dd548STaylor Simpson                                            int rnum, VRegWriteType type,
197763d2ce7STaylor Simpson                                            bool is_predicated, bool has_helper)
198a82dd548STaylor Simpson {
199763d2ce7STaylor Simpson     ctx_log_vreg_write(ctx, rnum ^ 0, type, is_predicated, has_helper);
200763d2ce7STaylor Simpson     ctx_log_vreg_write(ctx, rnum ^ 1, type, is_predicated, has_helper);
201a82dd548STaylor Simpson }
202a82dd548STaylor Simpson 
ctx_log_vreg_read(DisasContext * ctx,int rnum,bool has_helper)203763d2ce7STaylor Simpson static inline void ctx_log_vreg_read(DisasContext *ctx, int rnum,
204763d2ce7STaylor Simpson                                      bool has_helper)
205b9f0326bSTaylor Simpson {
206763d2ce7STaylor Simpson     if (has_helper) {
207763d2ce7STaylor Simpson         set_bit(rnum, ctx->insn_vregs_read);
208763d2ce7STaylor Simpson         if (test_bit(rnum, ctx->insn_vregs_written)) {
209763d2ce7STaylor Simpson             ctx->has_hvx_overlap = true;
210763d2ce7STaylor Simpson         }
211763d2ce7STaylor Simpson     }
212763d2ce7STaylor Simpson     if (test_bit(rnum, ctx->vregs_written)) {
213763d2ce7STaylor Simpson         ctx->read_after_write = true;
214763d2ce7STaylor Simpson     }
215b9f0326bSTaylor Simpson }
216b9f0326bSTaylor Simpson 
ctx_log_vreg_read_new(DisasContext * ctx,int rnum,bool has_helper)217763d2ce7STaylor Simpson static inline void ctx_log_vreg_read_new(DisasContext *ctx, int rnum,
218763d2ce7STaylor Simpson                                          bool has_helper)
21976eaa971STaylor Simpson {
22076eaa971STaylor Simpson     g_assert(is_gather_store_insn(ctx) ||
22176eaa971STaylor Simpson              test_bit(rnum, ctx->vregs_updated) ||
22276eaa971STaylor Simpson              test_bit(rnum, ctx->vregs_select) ||
22376eaa971STaylor Simpson              test_bit(rnum, ctx->vregs_updated_tmp));
224763d2ce7STaylor Simpson     if (has_helper) {
225763d2ce7STaylor Simpson         set_bit(rnum, ctx->insn_vregs_read);
226763d2ce7STaylor Simpson         if (test_bit(rnum, ctx->insn_vregs_written)) {
227763d2ce7STaylor Simpson             ctx->has_hvx_overlap = true;
228763d2ce7STaylor Simpson         }
229763d2ce7STaylor Simpson     }
230763d2ce7STaylor Simpson     if (is_gather_store_insn(ctx)) {
231763d2ce7STaylor Simpson         ctx->read_after_write = true;
232763d2ce7STaylor Simpson     }
23376eaa971STaylor Simpson }
23476eaa971STaylor Simpson 
ctx_log_vreg_read_pair(DisasContext * ctx,int rnum,bool has_helper)235763d2ce7STaylor Simpson static inline void ctx_log_vreg_read_pair(DisasContext *ctx, int rnum,
236763d2ce7STaylor Simpson                                           bool has_helper)
237b9f0326bSTaylor Simpson {
238763d2ce7STaylor Simpson     ctx_log_vreg_read(ctx, rnum ^ 0, has_helper);
239763d2ce7STaylor Simpson     ctx_log_vreg_read(ctx, rnum ^ 1, has_helper);
240b9f0326bSTaylor Simpson }
241b9f0326bSTaylor Simpson 
ctx_log_qreg_write(DisasContext * ctx,int rnum,bool has_helper)242a82dd548STaylor Simpson static inline void ctx_log_qreg_write(DisasContext *ctx,
243763d2ce7STaylor Simpson                                       int rnum, bool has_helper)
244a82dd548STaylor Simpson {
245763d2ce7STaylor Simpson     if (has_helper) {
246763d2ce7STaylor Simpson         set_bit(rnum, ctx->insn_qregs_written);
247763d2ce7STaylor Simpson         if (test_bit(rnum, ctx->insn_qregs_read)) {
248763d2ce7STaylor Simpson             ctx->has_hvx_overlap = true;
249763d2ce7STaylor Simpson         }
250763d2ce7STaylor Simpson     }
251763d2ce7STaylor Simpson     set_bit(rnum, ctx->qregs_written);
252a82dd548STaylor Simpson     ctx->qreg_log[ctx->qreg_log_idx] = rnum;
253a82dd548STaylor Simpson     ctx->qreg_log_idx++;
254a82dd548STaylor Simpson }
255a82dd548STaylor Simpson 
ctx_log_qreg_read(DisasContext * ctx,int qnum,bool has_helper)256763d2ce7STaylor Simpson static inline void ctx_log_qreg_read(DisasContext *ctx,
257763d2ce7STaylor Simpson                                      int qnum, bool has_helper)
258b9f0326bSTaylor Simpson {
259763d2ce7STaylor Simpson     if (has_helper) {
260763d2ce7STaylor Simpson         set_bit(qnum, ctx->insn_qregs_read);
261763d2ce7STaylor Simpson         if (test_bit(qnum, ctx->insn_qregs_written)) {
262763d2ce7STaylor Simpson             ctx->has_hvx_overlap = true;
263763d2ce7STaylor Simpson         }
264763d2ce7STaylor Simpson     }
265763d2ce7STaylor Simpson     if (test_bit(qnum, ctx->qregs_written)) {
266763d2ce7STaylor Simpson         ctx->read_after_write = true;
267763d2ce7STaylor Simpson     }
268b9f0326bSTaylor Simpson }
269b9f0326bSTaylor Simpson 
2708b453a2bSTaylor Simpson extern TCGv hex_gpr[TOTAL_PER_THREAD_REGS];
2718b453a2bSTaylor Simpson extern TCGv hex_pred[NUM_PREGS];
2728b453a2bSTaylor Simpson extern TCGv hex_slot_cancelled;
2736aa4f1d1STaylor Simpson extern TCGv hex_new_value_usr;
2748b453a2bSTaylor Simpson extern TCGv hex_reg_written[TOTAL_PER_THREAD_REGS];
2758b453a2bSTaylor Simpson extern TCGv hex_store_addr[STORES_MAX];
2768b453a2bSTaylor Simpson extern TCGv hex_store_width[STORES_MAX];
2778b453a2bSTaylor Simpson extern TCGv hex_store_val32[STORES_MAX];
2788b453a2bSTaylor Simpson extern TCGv_i64 hex_store_val64[STORES_MAX];
2798b453a2bSTaylor Simpson extern TCGv hex_llsc_addr;
2808b453a2bSTaylor Simpson extern TCGv hex_llsc_val;
2818b453a2bSTaylor Simpson extern TCGv_i64 hex_llsc_val_i64;
282a82dd548STaylor Simpson extern TCGv hex_vstore_addr[VSTORES_MAX];
283a82dd548STaylor Simpson extern TCGv hex_vstore_size[VSTORES_MAX];
284a82dd548STaylor Simpson extern TCGv hex_vstore_pending[VSTORES_MAX];
2858b453a2bSTaylor Simpson 
2861e536334STaylor Simpson void process_store(DisasContext *ctx, int slot_num);
2877b84fd04STaylor Simpson 
2887b84fd04STaylor Simpson FIELD(PROBE_PKT_SCALAR_STORE_S0, MMU_IDX,       0, 2)
2897b84fd04STaylor Simpson FIELD(PROBE_PKT_SCALAR_STORE_S0, IS_PREDICATED, 2, 1)
2907b84fd04STaylor Simpson 
2917b84fd04STaylor Simpson FIELD(PROBE_PKT_SCALAR_HVX_STORES, HAS_ST0,        0, 1)
2927b84fd04STaylor Simpson FIELD(PROBE_PKT_SCALAR_HVX_STORES, HAS_ST1,        1, 1)
2937b84fd04STaylor Simpson FIELD(PROBE_PKT_SCALAR_HVX_STORES, HAS_HVX_STORES, 2, 1)
2947b84fd04STaylor Simpson FIELD(PROBE_PKT_SCALAR_HVX_STORES, S0_IS_PRED,     3, 1)
2957b84fd04STaylor Simpson FIELD(PROBE_PKT_SCALAR_HVX_STORES, S1_IS_PRED,     4, 1)
2962bda44e8STaylor Simpson FIELD(PROBE_PKT_SCALAR_HVX_STORES, MMU_IDX,        5, 2)
2977b84fd04STaylor Simpson 
2988b453a2bSTaylor Simpson #endif
299