also arrange for id_regs.py to identify compressed instruction usage
[riscv-isa-sim.git] / riscv / sv_decode.h
1 // See LICENSE for license details.
2
3 #ifndef _RISCV_SV_DECODE_H
4 #define _RISCV_SV_DECODE_H
5
6 #include "sv.h"
7 #include "decode.h"
8 #include "processor.h"
9
10 #define REG_RD 0x1
11 #define REG_RS1 0x2
12 #define REG_RS2 0x4
13 #define REG_RS3 0x8
14 #define REG_RVC_RS1 0x10
15 #define REG_RVC_RS2 0x20
16 #define REG_RVC_RS1S 0x40
17 #define REG_RVC_RS2S 0x80
18
19
20 class sv_insn_t: public insn_t
21 {
22 public:
23 sv_insn_t(processor_t *pr, insn_bits_t bits, unsigned int f) :
24 insn_t(bits), p(pr), fimap(f),
25 cached_rd(0xff), cached_rs1(0xff),
26 cached_rs2(0xff), cached_rs3(0xff),
27 offs_rd(0), offs_rs1(0),
28 offs_rs2(0), offs_rs3(0) {}
29 uint64_t rd ()
30 { return _remap(insn_t::rd (), fimap & REG_RD , offs_rd , cached_rd); }
31 uint64_t rs1()
32 { return _remap(insn_t::rs1(), fimap & REG_RS1, offs_rs1, cached_rs1); }
33 uint64_t rs2()
34 { return _remap(insn_t::rs2(), fimap & REG_RS2, offs_rs2, cached_rs2); }
35 uint64_t rs3()
36 { return _remap(insn_t::rs3(), fimap & REG_RS3, offs_rs3, cached_rs3); }
37
38 void reset_caches(void)
39 {
40 cached_rd = 0xff;
41 cached_rs1 = 0xff;
42 cached_rs2 = 0xff;
43 cached_rs3 = 0xff;
44 }
45
46 bool sv_check_reg(bool intreg, uint64_t reg);
47 sv_reg_entry* get_regentry(uint64_t reg, bool isint);
48 sv_pred_entry* get_predentry(uint64_t reg, bool isint);
49 reg_t predicate(uint64_t reg, bool isint, bool &zeroing);
50
51 private:
52 processor_t *p;
53 unsigned int fimap;
54 uint64_t cached_rd;
55 uint64_t cached_rs1;
56 uint64_t cached_rs2;
57 uint64_t cached_rs3;
58 int offs_rd;
59 int offs_rs1;
60 int offs_rs2;
61 int offs_rs3;
62 // remaps the register through the lookup table.
63 // will need to take the current loop index/offset somehow
64 uint64_t remap(uint64_t reg, bool isint, int &offs);
65
66 // cached version of remap: if remap is called multiple times
67 // by an emulated instruction it would increment the loop offset
68 // before it's supposed to.
69 uint64_t _remap(uint64_t reg, bool isint, int &offs, uint64_t &cached)
70 {
71 if (cached == 0xff)
72 {
73 cached = remap(reg, isint, offs);
74 }
75 return cached;
76 }
77 };
78
79 #endif