xref: /qemu/target/hexagon/translate.h (revision 2bda44e8)
18b453a2bSTaylor Simpson /*
210849c26STaylor Simpson  *  Copyright(c) 2019-2023 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;
53a82dd548STaylor Simpson     DECLARE_BITMAP(vregs_updated_tmp, NUM_VREGS);
54a82dd548STaylor Simpson     DECLARE_BITMAP(vregs_updated, NUM_VREGS);
55a82dd548STaylor Simpson     DECLARE_BITMAP(vregs_select, NUM_VREGS);
564d6f8420STaylor Simpson     DECLARE_BITMAP(predicated_future_vregs, NUM_VREGS);
574d6f8420STaylor Simpson     DECLARE_BITMAP(predicated_tmp_vregs, NUM_VREGS);
58a82dd548STaylor Simpson     int qreg_log[NUM_QREGS];
59a82dd548STaylor Simpson     int qreg_log_idx;
60a82dd548STaylor Simpson     bool pre_commit;
611b9a7f2aSTaylor Simpson     TCGCond branch_cond;
621b9a7f2aSTaylor Simpson     target_ulong branch_dest;
63564b2040STaylor Simpson     bool is_tight_loop;
644d13bb51STaylor Simpson     bool need_pkt_has_store_s1;
658b453a2bSTaylor Simpson } DisasContext;
668b453a2bSTaylor Simpson 
678b453a2bSTaylor Simpson static inline void ctx_log_pred_write(DisasContext *ctx, int pnum)
688b453a2bSTaylor Simpson {
6910849c26STaylor Simpson     if (!test_bit(pnum, ctx->pregs_written)) {
708b453a2bSTaylor Simpson         ctx->preg_log[ctx->preg_log_idx] = pnum;
718b453a2bSTaylor Simpson         ctx->preg_log_idx++;
726c677c60STaylor Simpson         set_bit(pnum, ctx->pregs_written);
738b453a2bSTaylor Simpson     }
7410849c26STaylor Simpson }
758b453a2bSTaylor Simpson 
7610849c26STaylor Simpson static inline void ctx_log_reg_write(DisasContext *ctx, int rnum,
7710849c26STaylor Simpson                                      bool is_predicated)
788b453a2bSTaylor Simpson {
7910849c26STaylor Simpson     if (rnum == HEX_REG_P3_0_ALIASED) {
8010849c26STaylor Simpson         for (int i = 0; i < NUM_PREGS; i++) {
8110849c26STaylor Simpson             ctx_log_pred_write(ctx, i);
8210849c26STaylor Simpson         }
8310849c26STaylor Simpson     } else {
8410849c26STaylor Simpson         if (!test_bit(rnum, ctx->regs_written)) {
8510849c26STaylor Simpson             ctx->reg_log[ctx->reg_log_idx] = rnum;
8610849c26STaylor Simpson             ctx->reg_log_idx++;
8710849c26STaylor Simpson             set_bit(rnum, ctx->regs_written);
8810849c26STaylor Simpson         }
8910849c26STaylor Simpson         if (is_predicated) {
9010849c26STaylor Simpson             set_bit(rnum, ctx->predicated_regs);
9110849c26STaylor Simpson         }
9210849c26STaylor Simpson     }
9310849c26STaylor Simpson }
9410849c26STaylor Simpson 
9510849c26STaylor Simpson static inline void ctx_log_reg_write_pair(DisasContext *ctx, int rnum,
9610849c26STaylor Simpson                                           bool is_predicated)
9710849c26STaylor Simpson {
9810849c26STaylor Simpson     ctx_log_reg_write(ctx, rnum, is_predicated);
9910849c26STaylor Simpson     ctx_log_reg_write(ctx, rnum + 1, is_predicated);
1008b453a2bSTaylor Simpson }
1018b453a2bSTaylor Simpson 
102a82dd548STaylor Simpson intptr_t ctx_future_vreg_off(DisasContext *ctx, int regnum,
103a82dd548STaylor Simpson                              int num, bool alloc_ok);
104a82dd548STaylor Simpson intptr_t ctx_tmp_vreg_off(DisasContext *ctx, int regnum,
105a82dd548STaylor Simpson                           int num, bool alloc_ok);
106a82dd548STaylor Simpson 
107a82dd548STaylor Simpson static inline void ctx_log_vreg_write(DisasContext *ctx,
108a82dd548STaylor Simpson                                       int rnum, VRegWriteType type,
109a82dd548STaylor Simpson                                       bool is_predicated)
110a82dd548STaylor Simpson {
111a82dd548STaylor Simpson     if (type != EXT_TMP) {
112c2b33d0bSTaylor Simpson         if (!test_bit(rnum, ctx->vregs_updated)) {
113a82dd548STaylor Simpson             ctx->vreg_log[ctx->vreg_log_idx] = rnum;
114a82dd548STaylor Simpson             ctx->vreg_log_idx++;
115c2b33d0bSTaylor Simpson             set_bit(rnum, ctx->vregs_updated);
116c2b33d0bSTaylor Simpson         }
117a82dd548STaylor Simpson 
118a82dd548STaylor Simpson         set_bit(rnum, ctx->vregs_updated);
1194d6f8420STaylor Simpson         if (is_predicated) {
1204d6f8420STaylor Simpson             set_bit(rnum, ctx->predicated_future_vregs);
1214d6f8420STaylor Simpson         }
122a82dd548STaylor Simpson     }
123a82dd548STaylor Simpson     if (type == EXT_NEW) {
124a82dd548STaylor Simpson         set_bit(rnum, ctx->vregs_select);
125a82dd548STaylor Simpson     }
126a82dd548STaylor Simpson     if (type == EXT_TMP) {
127a82dd548STaylor Simpson         set_bit(rnum, ctx->vregs_updated_tmp);
1284d6f8420STaylor Simpson         if (is_predicated) {
1294d6f8420STaylor Simpson             set_bit(rnum, ctx->predicated_tmp_vregs);
1304d6f8420STaylor Simpson         }
131a82dd548STaylor Simpson     }
132a82dd548STaylor Simpson }
133a82dd548STaylor Simpson 
134a82dd548STaylor Simpson static inline void ctx_log_vreg_write_pair(DisasContext *ctx,
135a82dd548STaylor Simpson                                            int rnum, VRegWriteType type,
136a82dd548STaylor Simpson                                            bool is_predicated)
137a82dd548STaylor Simpson {
138a82dd548STaylor Simpson     ctx_log_vreg_write(ctx, rnum ^ 0, type, is_predicated);
139a82dd548STaylor Simpson     ctx_log_vreg_write(ctx, rnum ^ 1, type, is_predicated);
140a82dd548STaylor Simpson }
141a82dd548STaylor Simpson 
142a82dd548STaylor Simpson static inline void ctx_log_qreg_write(DisasContext *ctx,
143c2b33d0bSTaylor Simpson                                       int rnum)
144a82dd548STaylor Simpson {
145a82dd548STaylor Simpson     ctx->qreg_log[ctx->qreg_log_idx] = rnum;
146a82dd548STaylor Simpson     ctx->qreg_log_idx++;
147a82dd548STaylor Simpson }
148a82dd548STaylor Simpson 
1498b453a2bSTaylor Simpson extern TCGv hex_gpr[TOTAL_PER_THREAD_REGS];
1508b453a2bSTaylor Simpson extern TCGv hex_pred[NUM_PREGS];
1518b453a2bSTaylor Simpson extern TCGv hex_this_PC;
1528b453a2bSTaylor Simpson extern TCGv hex_slot_cancelled;
1538b453a2bSTaylor Simpson extern TCGv hex_branch_taken;
1548b453a2bSTaylor Simpson extern TCGv hex_new_value[TOTAL_PER_THREAD_REGS];
1558b453a2bSTaylor Simpson extern TCGv hex_reg_written[TOTAL_PER_THREAD_REGS];
1568b453a2bSTaylor Simpson extern TCGv hex_new_pred_value[NUM_PREGS];
1578b453a2bSTaylor Simpson extern TCGv hex_pred_written;
1588b453a2bSTaylor Simpson extern TCGv hex_store_addr[STORES_MAX];
1598b453a2bSTaylor Simpson extern TCGv hex_store_width[STORES_MAX];
1608b453a2bSTaylor Simpson extern TCGv hex_store_val32[STORES_MAX];
1618b453a2bSTaylor Simpson extern TCGv_i64 hex_store_val64[STORES_MAX];
1628b453a2bSTaylor Simpson extern TCGv hex_dczero_addr;
1638b453a2bSTaylor Simpson extern TCGv hex_llsc_addr;
1648b453a2bSTaylor Simpson extern TCGv hex_llsc_val;
1658b453a2bSTaylor Simpson extern TCGv_i64 hex_llsc_val_i64;
166a82dd548STaylor Simpson extern TCGv hex_vstore_addr[VSTORES_MAX];
167a82dd548STaylor Simpson extern TCGv hex_vstore_size[VSTORES_MAX];
168a82dd548STaylor Simpson extern TCGv hex_vstore_pending[VSTORES_MAX];
1698b453a2bSTaylor Simpson 
1701e536334STaylor Simpson bool is_gather_store_insn(DisasContext *ctx);
1711e536334STaylor Simpson void process_store(DisasContext *ctx, int slot_num);
1727b84fd04STaylor Simpson 
1737b84fd04STaylor Simpson FIELD(PROBE_PKT_SCALAR_STORE_S0, MMU_IDX,       0, 2)
1747b84fd04STaylor Simpson FIELD(PROBE_PKT_SCALAR_STORE_S0, IS_PREDICATED, 2, 1)
1757b84fd04STaylor Simpson 
1767b84fd04STaylor Simpson FIELD(PROBE_PKT_SCALAR_HVX_STORES, HAS_ST0,        0, 1)
1777b84fd04STaylor Simpson FIELD(PROBE_PKT_SCALAR_HVX_STORES, HAS_ST1,        1, 1)
1787b84fd04STaylor Simpson FIELD(PROBE_PKT_SCALAR_HVX_STORES, HAS_HVX_STORES, 2, 1)
1797b84fd04STaylor Simpson FIELD(PROBE_PKT_SCALAR_HVX_STORES, S0_IS_PRED,     3, 1)
1807b84fd04STaylor Simpson FIELD(PROBE_PKT_SCALAR_HVX_STORES, S1_IS_PRED,     4, 1)
1812bda44e8STaylor Simpson FIELD(PROBE_PKT_SCALAR_HVX_STORES, MMU_IDX,        5, 2)
1827b84fd04STaylor Simpson 
1838b453a2bSTaylor Simpson #endif
184