aboutsummaryrefslogtreecommitdiff
path: root/riscv/vector_unit.h
blob: a057c62fbe5d2ecf4a517848897bec51c6aadcd4 (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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// See LICENSE for license details.
#ifndef _RISCV_VECTOR_UNIT_H
#define _RISCV_VECTOR_UNIT_H

#include <array>
#include <cstdint>

#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;
};

// Element Group of 4 32 bits elements (128b total).
using EGU32x4_t = std::array<uint32_t, 4>;

// Element Group of 8 32 bits elements (256b total).
using EGU32x8_t = std::array<uint32_t, 8>;

// Element Group of 4 64 bits elements (256b total).
using EGU64x4_t = std::array<uint64_t, 4>;

// Element Group of 16 8 bits elements (128b total).
using EGU8x16_t = std::array<uint8_t, 16>;

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 various SEW
  template<class T> T& elt(reg_t vReg, reg_t n, bool is_write = false);
  // vector element group access, where EG is a std::array<T, N>.
  template<typename EG> EG&
  elt_group(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