aboutsummaryrefslogtreecommitdiff
path: root/riscv/vector_unit.h
blob: b9f706c53aab413cee706d33de1957dc3d56b05e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// See LICENSE for license details.
#ifndef _RISCV_VECTOR_UNIT_H
#define _RISCV_VECTOR_UNIT_H

#include "decode.h"
#include "csrs.h"

class processor_t;

enum VRM{
  RNU = 0,
  RNE,
  RDN,
  ROD,
  INVALID_RM
};

template<uint64_t N>
struct type_usew_t;

template<>
struct type_usew_t<8>
{
  using type=uint8_t;
};

template<>
struct type_usew_t<16>
{
  using type=uint16_t;
};

template<>
struct type_usew_t<32>
{
  using type=uint32_t;
};

template<>
struct type_usew_t<64>
{
  using type=uint64_t;
};

template<uint64_t N>
struct type_sew_t;

template<>
struct type_sew_t<8>
{
  using type=int8_t;
};

template<>
struct type_sew_t<16>
{
  using type=int16_t;
};

template<>
struct type_sew_t<32>
{
  using type=int32_t;
};

template<>
struct type_sew_t<64>
{
  using type=int64_t;
};


class vectorUnit_t
{
public:
  processor_t* p;
  void *reg_file;
  char reg_referenced[NVPR];
  int setvl_count;
  reg_t vlmax;
  reg_t vlenb;
  csr_t_p vxsat;
  vector_csr_t_p vxrm, vstart, vl, vtype;
  reg_t vma, vta;
  reg_t vsew;
  float vflmul;
  reg_t ELEN, VLEN;
  bool vill;
  bool vstart_alu;

  // vector element for varies SEW
  template<class T> T& elt(reg_t vReg, reg_t n, bool is_write = false);

public:

  void reset();

  vectorUnit_t():
    p(0),
    reg_file(0),
    reg_referenced{0},
    setvl_count(0),
    vlmax(0),
    vlenb(0),
    vxsat(0),
    vxrm(0),
    vstart(0),
    vl(0),
    vtype(0),
    vma(0),
    vta(0),
    vsew(0),
    vflmul(0),
    ELEN(0),
    VLEN(0),
    vill(false),
    vstart_alu(false) {
  }

  ~vectorUnit_t() {
    free(reg_file);
    reg_file = 0;
  }

  reg_t set_vl(int rd, int rs1, reg_t reqVL, reg_t newType);

  reg_t get_vlen() { return VLEN; }
  reg_t get_elen() { return ELEN; }
  reg_t get_slen() { return VLEN; }

  VRM get_vround_mode() {
    return (VRM)(vxrm->read());
  }
};
#endif