Skip to content

Commit b3f96e2

Browse files
committed
+ support for ZICOND RISC-V extension
+ RTL decode refactoring
1 parent 8d97d2c commit b3f96e2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1060
-999
lines changed

ci/trace_csv.py

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/usr/bin/env python3
22

33
# Copyright © 2019-2023
4-
#
4+
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.
77
# You may obtain a copy of the License at
88
# http://www.apache.org/licenses/LICENSE-2.0
9-
#
9+
#
1010
# Unless required by applicable law or agreed to in writing, software
1111
# distributed under the License is distributed on an "AS IS" BASIS,
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,15 +17,15 @@
1717
import argparse
1818
import csv
1919
import re
20-
20+
2121
def parse_args():
2222
parser = argparse.ArgumentParser(description='CPU trace log to CSV format converter.')
2323
parser.add_argument('-t', '--type', default='simx', help='log type (rtlsim or simx)')
2424
parser.add_argument('-o', '--csv', default='trace.csv', help='Output CSV file')
2525
parser.add_argument('log', help='Input log file')
2626
return parser.parse_args()
2727

28-
def parse_simx(log_filename):
28+
def parse_simx(log_filename):
2929
pc_pattern = r"PC=(0x[0-9a-fA-F]+)"
3030
instr_pattern = r"Instr (0x[0-9a-fA-F]+):"
3131
opcode_pattern = r"Instr 0x[0-9a-fA-F]+: ([0-9a-zA-Z_\.]+)"
@@ -42,12 +42,12 @@ def parse_simx(log_filename):
4242
if line.startswith("DEBUG Fetch:"):
4343
if instr_data:
4444
entries.append(instr_data)
45-
instr_data = {}
45+
instr_data = {}
4646
instr_data["lineno"] = lineno
4747
instr_data["PC"] = re.search(pc_pattern, line).group(1)
4848
instr_data["core_id"] = re.search(core_id_pattern, line).group(1)
4949
instr_data["warp_id"] = re.search(warp_id_pattern, line).group(1)
50-
instr_data["tmask"] = re.search(tmask_pattern, line).group(1)
50+
instr_data["tmask"] = re.search(tmask_pattern, line).group(1)
5151
instr_data["uuid"] = re.search(uuid_pattern, line).group(1)
5252
elif line.startswith("DEBUG Instr"):
5353
instr_data["instr"] = re.search(instr_pattern, line).group(1)
@@ -60,13 +60,13 @@ def parse_simx(log_filename):
6060
if instr_data:
6161
entries.append(instr_data)
6262
return entries
63-
63+
6464
def reverse_binary(bin_str):
6565
return bin_str[::-1]
6666

6767
def bin_to_array(bin_str):
6868
return [int(bit) for bit in bin_str]
69-
69+
7070
def append_reg(text, value, sep):
7171
if sep:
7272
text += ", "
@@ -77,14 +77,7 @@ def append_reg(text, value, sep):
7777
text += "x" + value
7878
sep = True
7979
return text, sep
80-
81-
def append_imm(text, value, sep):
82-
if sep:
83-
text += ", "
84-
text += value
85-
sep = True
86-
return text, sep
87-
80+
8881
def append_value(text, reg, value, tmask_arr, sep):
8982
text, sep = append_reg(text, reg, sep)
9083
text += "={"
@@ -97,8 +90,8 @@ def append_value(text, reg, value, tmask_arr, sep):
9790
text +="-"
9891
text += "}"
9992
return text, sep
100-
101-
def parse_rtlsim(log_filename):
93+
94+
def parse_rtlsim(log_filename):
10295
line_pattern = r"\d+: core(\d+)-(decode|issue|commit)"
10396
pc_pattern = r"PC=(0x[0-9a-fA-F]+)"
10497
instr_pattern = r"instr=(0x[0-9a-fA-F]+)"
@@ -108,8 +101,6 @@ def parse_rtlsim(log_filename):
108101
tmask_pattern = r"tmask=(\d+)"
109102
wb_pattern = r"wb=(\d)"
110103
opds_pattern = r"opds=(\d+)"
111-
use_imm_pattern = r"use_imm=(\d)"
112-
imm_pattern = r"imm=(0x[0-9a-fA-F]+)"
113104
rd_pattern = r"rd=(\d+)"
114105
rs1_pattern = r"rs1=(\d+)"
115106
rs2_pattern = r"rs2=(\d+)"
@@ -120,24 +111,24 @@ def parse_rtlsim(log_filename):
120111
rd_data_pattern = r"data=\{(.+?)\}"
121112
eop_pattern = r"eop=(\d)"
122113
uuid_pattern = r"#(\d+)"
123-
entries = []
114+
entries = []
124115
with open(log_filename, 'r') as log_file:
125116
instr_data = {}
126117
for lineno, line in enumerate(log_file, start=1):
127118
line_match = re.search(line_pattern, line)
128119
if line_match:
129120
PC = re.search(pc_pattern, line).group(1)
130-
warp_id = re.search(warp_id_pattern, line).group(1)
121+
warp_id = re.search(warp_id_pattern, line).group(1)
131122
tmask = re.search(tmask_pattern, line).group(1)
132-
uuid = re.search(uuid_pattern, line).group(1)
123+
uuid = re.search(uuid_pattern, line).group(1)
133124
core_id = line_match.group(1)
134125
stage = line_match.group(2)
135-
if stage == "decode":
126+
if stage == "decode":
136127
trace = {}
137128
trace["uuid"] = uuid
138-
trace["PC"] = PC
129+
trace["PC"] = PC
139130
trace["core_id"] = core_id
140-
trace["warp_id"] = warp_id
131+
trace["warp_id"] = warp_id
141132
trace["tmask"] = reverse_binary(tmask)
142133
trace["instr"] = re.search(instr_pattern, line).group(1)
143134
trace["opcode"] = re.search(op_pattern, line).group(1)
@@ -146,8 +137,6 @@ def parse_rtlsim(log_filename):
146137
trace["rs1"] = re.search(rs1_pattern, line).group(1)
147138
trace["rs2"] = re.search(rs2_pattern, line).group(1)
148139
trace["rs3"] = re.search(rs3_pattern, line).group(1)
149-
trace["use_imm"] = re.search(use_imm_pattern, line).group(1) == "1"
150-
trace["imm"] = re.search(imm_pattern, line).group(1)
151140
instr_data[uuid] = trace
152141
elif stage == "issue":
153142
if uuid in instr_data:
@@ -162,7 +151,7 @@ def parse_rtlsim(log_filename):
162151
trace["rs3_data"] = re.search(rs3_data_pattern, line).group(1).split(', ')[::-1]
163152
trace["issued"] = True
164153
instr_data[uuid] = trace
165-
elif stage == "commit":
154+
elif stage == "commit":
166155
if uuid in instr_data:
167156
trace = instr_data[uuid]
168157
if "issued" in trace:
@@ -205,16 +194,14 @@ def parse_rtlsim(log_filename):
205194
del trace["rs1"]
206195
del trace["rs2"]
207196
del trace["rs3"]
208-
del trace["use_imm"]
209-
del trace["imm"]
210-
del trace["issued"]
197+
del trace["issued"]
211198
del instr_data[uuid]
212199
entries.append(trace)
213-
return entries
200+
return entries
214201

215202
def write_csv(log_filename, csv_filename, log_type):
216203
entries = None
217-
204+
218205
# parse log file
219206
if log_type == "rtlsim":
220207
entries = parse_rtlsim(log_filename)
@@ -223,19 +210,19 @@ def write_csv(log_filename, csv_filename, log_type):
223210
else:
224211
print('Error: invalid log type')
225212
sys.exit()
226-
213+
227214
# sort entries by uuid
228215
entries.sort(key=lambda x: (int(x['uuid'])))
229216
for entry in entries:
230217
del entry['lineno']
231-
218+
232219
# write to CSV
233220
with open(csv_filename, 'w', newline='') as csv_file:
234221
fieldnames = ["uuid", "PC", "opcode", "instr", "core_id", "warp_id", "tmask", "operands", "destination"]
235222
writer = csv.DictWriter(csv_file, fieldnames=fieldnames)
236223
writer.writeheader()
237224
for entry in entries:
238-
writer.writerow(entry)
225+
writer.writerow(entry)
239226

240227
def main():
241228
args = parse_args()

hw/rtl/VX_config.vh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
`define EXT_F_ENABLE
4141
`endif
4242

43+
`ifndef EXT_ZICOND_ENABLE
44+
`define EXT_ZICOND_ENABLE
45+
`endif
46+
4347
`ifndef XLEN_32
4448
`ifndef XLEN_64
4549
`define XLEN_32
@@ -637,6 +641,12 @@
637641
`define EXT_M_ENABLED 0
638642
`endif
639643

644+
`ifdef EXT_ZICOND_ENABLE
645+
`define EXT_ZICOND_ENABLED 1
646+
`else
647+
`define EXT_ZICOND_ENABLED 0
648+
`endif
649+
640650
`define ISA_STD_A 0
641651
`define ISA_STD_C 2
642652
`define ISA_STD_D 3
@@ -654,12 +664,14 @@
654664
`define ISA_EXT_L2CACHE 2
655665
`define ISA_EXT_L3CACHE 3
656666
`define ISA_EXT_LMEM 4
667+
`define ISA_EXT_ZICOND 5
657668

658669
`define MISA_EXT (`ICACHE_ENABLED << `ISA_EXT_ICACHE) \
659670
| (`DCACHE_ENABLED << `ISA_EXT_DCACHE) \
660671
| (`L2_ENABLED << `ISA_EXT_L2CACHE) \
661672
| (`L3_ENABLED << `ISA_EXT_L3CACHE) \
662-
| (`LMEM_ENABLED << `ISA_EXT_LMEM)
673+
| (`LMEM_ENABLED << `ISA_EXT_LMEM) \
674+
| (`EXT_ZICOND_ENABLED << `ISA_EXT_ZICOND)
663675

664676
`define MISA_STD (`EXT_A_ENABLED << 0) /* A - Atomic Instructions extension */ \
665677
| (0 << 1) /* B - Tentatively reserved for Bit operations extension */ \

hw/rtl/VX_define.vh

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@
5555
`define UUID_WIDTH 1
5656
`endif
5757

58+
`define PC_BITS (`XLEN-1)
59+
`define OFFSET_BITS 12
60+
`define IMM_BITS `XLEN
61+
5862
///////////////////////////////////////////////////////////////////////////////
5963

6064
`define EX_ALU 0
@@ -105,6 +109,10 @@
105109
`define INST_EXT3 7'b1011011 // 0x5B
106110
`define INST_EXT4 7'b1111011 // 0x7B
107111

112+
// Opcode extensions
113+
`define INST_R_F7_MUL 7'b0000001
114+
`define INST_R_F7_ZICOND 7'b0000111
115+
108116
///////////////////////////////////////////////////////////////////////////////
109117

110118
`define INST_FRM_RNE 3'b000 // round to nearest even
@@ -118,7 +126,7 @@
118126
///////////////////////////////////////////////////////////////////////////////
119127

120128
`define INST_OP_BITS 4
121-
`define INST_MOD_BITS 3
129+
`define INST_MOD_BITS $bits(op_mod_t)
122130
`define INST_FMT_BITS 2
123131

124132
///////////////////////////////////////////////////////////////////////////////
@@ -135,14 +143,23 @@
135143
`define INST_ALU_OR 4'b1101
136144
`define INST_ALU_XOR 4'b1110
137145
`define INST_ALU_SLL 4'b1111
138-
`define INST_ALU_OTHER 4'b0111
146+
`define INST_ALU_CZEQ 4'b1010
147+
`define INST_ALU_CZNE 4'b1011
148+
//`define INST_ALU_UNUSED 4'b0001
149+
//`define INST_ALU_UNUSED 4'b0110
150+
151+
152+
`define ALU_TYPE_BITS 2
153+
`define ALU_TYPE_ARITH 0
154+
`define ALU_TYPE_BRANCH 1
155+
`define ALU_TYPE_MULDIV 2
156+
`define ALU_TYPE_OTHER 3
157+
139158
`define INST_ALU_BITS 4
140159
`define INST_ALU_CLASS(op) op[3:2]
141160
`define INST_ALU_SIGNED(op) op[0]
142161
`define INST_ALU_IS_SUB(op) op[1]
143-
`define INST_ALU_IS_BR(mod) mod[0]
144-
`define INST_ALU_IS_M(mod) mod[1]
145-
`define INST_ALU_IS_W(mod) mod[2]
162+
`define INST_ALU_IS_CZERO(op) (op[3:1] == 3'b101)
146163

147164
`define INST_BR_EQ 4'b0000
148165
`define INST_BR_NE 4'b0010
@@ -225,9 +242,8 @@
225242
`define INST_FPU_NMSUB 4'b1110
226243
`define INST_FPU_NMADD 4'b1111
227244
`define INST_FPU_BITS 4
228-
`define INST_FPU_IS_W(mod) (mod[4])
229-
`define INST_FPU_IS_CLASS(op, mod) (op == `INST_FPU_MISC && mod == 3)
230-
`define INST_FPU_IS_MVXW(op, mod) (op == `INST_FPU_MISC && mod == 4)
245+
`define INST_FPU_IS_CLASS(op, frm) (op == `INST_FPU_MISC && frm == 3)
246+
`define INST_FPU_IS_MVXW(op, frm) (op == `INST_FPU_MISC && frm == 4)
231247

232248
`define INST_SFU_TMC 4'h0
233249
`define INST_SFU_WSPAWN 4'h1
@@ -238,7 +254,6 @@
238254
`define INST_SFU_CSRRW 4'h6
239255
`define INST_SFU_CSRRS 4'h7
240256
`define INST_SFU_CSRRC 4'h8
241-
`define INST_SFU_CMOV 4'h9
242257
`define INST_SFU_BITS 4
243258
`define INST_SFU_CSR(f3) (4'h6 + 4'(f3) - 4'h1)
244259
`define INST_SFU_IS_WCTL(op) (op <= 5)
@@ -414,13 +429,10 @@
414429
data.uuid, \
415430
data.wis, \
416431
data.tmask, \
432+
data.PC, \
417433
data.op_type, \
418434
data.op_mod, \
419435
data.wb, \
420-
data.use_PC, \
421-
data.use_imm, \
422-
data.PC, \
423-
data.imm, \
424436
data.rd, \
425437
tid, \
426438
data.rs1_data, \

hw/rtl/VX_gpu_pkg.sv

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ package VX_gpu_pkg;
2626
typedef struct packed {
2727
logic valid;
2828
logic [`NUM_WARPS-1:0] wmask;
29-
logic [`XLEN-1:0] pc;
29+
logic [`PC_BITS-1:0] pc;
3030
} wspawn_t;
3131

3232
typedef struct packed {
3333
logic valid;
3434
logic is_dvg;
3535
logic [`NUM_THREADS-1:0] then_tmask;
3636
logic [`NUM_THREADS-1:0] else_tmask;
37-
logic [`XLEN-1:0] next_pc;
37+
logic [`PC_BITS-1:0] next_pc;
3838
} split_t;
3939

4040
typedef struct packed {
@@ -55,9 +55,9 @@ package VX_gpu_pkg;
5555
} barrier_t;
5656

5757
typedef struct packed {
58-
logic [`XLEN-1:0] startup_addr;
59-
logic [`XLEN-1:0] startup_arg;
60-
logic [7:0] mpm_class;
58+
logic [`XLEN-1:0] startup_addr;
59+
logic [`XLEN-1:0] startup_arg;
60+
logic [7:0] mpm_class;
6161
} base_dcrs_t;
6262

6363
typedef struct packed {
@@ -77,6 +77,42 @@ package VX_gpu_pkg;
7777
logic [`PERF_CTR_BITS-1:0] latency;
7878
} mem_perf_t;
7979

80+
typedef struct packed {
81+
logic use_PC;
82+
logic use_imm;
83+
logic is_w;
84+
logic [`ALU_TYPE_BITS-1:0] xtype;
85+
logic [`IMM_BITS-1:0] imm;
86+
} alu_mod_t;
87+
88+
typedef struct packed {
89+
logic [`INST_FRM_BITS-1:0] frm;
90+
logic [`INST_FMT_BITS-1:0] fmt;
91+
} fpu_mod_t;
92+
93+
typedef struct packed {
94+
logic is_float;
95+
logic [`OFFSET_BITS-1:0] offset;
96+
} lsu_mod_t;
97+
98+
typedef struct packed {
99+
logic use_imm;
100+
logic [`VX_CSR_ADDR_BITS-1:0] addr;
101+
logic [4:0] imm;
102+
} csr_mod_t;
103+
104+
typedef struct packed {
105+
logic is_neg;
106+
} wctl_mod_t;
107+
108+
typedef union packed {
109+
alu_mod_t alu;
110+
fpu_mod_t fpu;
111+
lsu_mod_t lsu;
112+
csr_mod_t csr;
113+
wctl_mod_t wctl;
114+
} op_mod_t;
115+
80116
/* verilator lint_off UNUSED */
81117

82118
///////////////////////// LSU memory Parameters ///////////////////////////

0 commit comments

Comments
 (0)