2 Copyright (c) 2013, IIT Madras
5 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9 * Neither the name of IIT Madras nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
11 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
12 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
15 import defined_types::*;
16 `include "core_parameters.bsv"
18 interface Ifc_prf_new;
19 method ActionValue#(RFType#(`Reg_width)) read_rs1 (Bit#(5) addr, Operand_type rs1type, Bit#(`Reg_width) data);
20 method ActionValue#(RFType#(`Reg_width)) read_rs2 (Bit#(5) addr, Operand_type rs2type, Bit#(`Reg_width) data);
21 method ActionValue#(RFType#(`Reg_width)) read_rs3 (Bit#(5) addr, Operand_type rs3type, Bit#(`Reg_width) data);
22 method ActionValue#(Tuple2#(Bit#(TLog#(`PRFDEPTH)),Bit#(4))) get_index_pid(Bit#(5) addr, Operand_type rdtype);
23 method Action update_rd (Bit#(TLog#(`PRFDEPTH)) index, Bit#(4) pid);
24 method Action fwd_from_execution (Bit#(`Reg_width) data, Bit#(TLog#(`PRFDEPTH)) index, Bit#(4) pid);
25 method Action fwd_from_memory (Bit#(`Reg_width) data, Bit#(TLog#(`PRFDEPTH)) index, Bit#(4) pid);
26 method Action flush_all;
28 (*conflict_free="fwd_from_execution,fwd_from_memory"*)
29 (*conflict_free="fwd_from_execution,update_rd"*)
30 (*conflict_free="update_rd,fwd_from_memory"*)
32 module mkprf_new(Ifc_prf_new);
33 Reg#(RFType#(`Reg_width)) physical_rf [`PRFDEPTH];
34 Reg#(Bit#(4)) pid_rf [`PRFDEPTH];
35 Vector#(`PRFDEPTH,Reg#(Tuple2#(Bit#(5),Operand_type))) rd_rf<-replicateM(mkReg(tuple2(0,IntegerRF)));
36 Reg#(Bit#(4)) rg_pid_counter<-mkReg(0);
37 Reg#(Bit#(TLog#(`PRFDEPTH))) rg_prf_index<-mkReg(0);
38 Wire#(Bool) wr_flush<-mkDWire(False);
39 for(Integer i=0;i<`PRFDEPTH;i=i+1)begin
40 physical_rf[i]<-mkReg(tagged Absent 0);
43 rule flush_all_mapping(wr_flush);
44 for(Integer i=0;i<`PRFDEPTH;i=i+1)begin
45 physical_rf[i]<=tagged Absent 0;
47 rd_rf[i]<=tuple2(0,IntegerRF);
50 method ActionValue#(RFType#(`Reg_width)) read_rs1 (Bit#(5) addr, Operand_type rs1type, Bit#(`Reg_width) data);
51 if(rs1type==IntegerRF && addr==0)
52 return tagged Present 0;
53 else if(rs1type==IntegerRF `ifdef spfpu || rs1type==FloatingRF `endif ) begin
54 let array_rd=readVReg(rd_rf); // convert the reg-vector to bit#(5)-vector
55 let index=findElem(tuple2(addr,rs1type),array_rd); // find the index of match
56 if(index matches tagged Valid .idx)begin // if match exists
57 `ifdef verbose $display($time,"\tPRF: READ_RS1: valid index: %d",idx); `endif
58 return physical_rf[idx];
60 else // there is no instruction in pipe updating this reg.
61 return tagged Present data;
63 else // there is no instruction in pipe updating this reg.
64 return tagged Present data;
66 method ActionValue#(RFType#(`Reg_width)) read_rs2 (Bit#(5) addr, Operand_type rs2type, Bit#(`Reg_width) data);
67 if(rs2type==IntegerRF && addr==0)
68 return tagged Present 0;
69 else if(rs2type==IntegerRF `ifdef spfpu || rs2type==FloatingRF `endif ) begin
70 let array_rd=readVReg(rd_rf); // convert the reg-vector to bit#(5)-vector
71 let index=findElem(tuple2(addr,rs2type),array_rd); // find the index of match
72 if(index matches tagged Valid .idx)begin // if match exists
73 `ifdef verbose $display($time,"\tPRF: READ_RS2: valid index: %d",idx); `endif
74 return physical_rf[idx];
76 else // there is no instruction in pipe updating this reg.
77 return tagged Present data;
79 else // there is no instruction in pipe updating this reg.
80 return tagged Present data;
82 method ActionValue#(RFType#(`Reg_width)) read_rs3 (Bit#(5) addr, Operand_type rs3type, Bit#(`Reg_width) data);
83 if(rs3type==IntegerRF && addr==0)
84 return tagged Present 0;
85 else if(rs3type==IntegerRF `ifdef spfpu || rs3type==FloatingRF `endif ) begin
86 let array_rd=readVReg(rd_rf); // convert the reg-vector to bit#(5)-vector
87 let index=findElem(tuple2(addr,rs3type),array_rd); // find the index of match
88 if(index matches tagged Valid .idx)begin // if match exists
89 return physical_rf[idx];
91 else // there is no instruction in pipe updating this reg.
92 return tagged Present data;
94 else // there is no instruction in pipe updating this reg.
95 return tagged Present data;
97 method ActionValue#(Tuple2#(Bit#(TLog#(`PRFDEPTH)),Bit#(4))) get_index_pid(Bit#(5) addr, Operand_type rdtype);
98 let array_rd=readVReg(rd_rf);
99 let index=findElem(tuple2(addr,rdtype),array_rd); // find the index of match
100 rg_pid_counter<=rg_pid_counter+1;
101 if(rg_prf_index==`PRFDEPTH-1)
104 rg_prf_index<=rg_prf_index+1;
105 rd_rf[rg_prf_index]<=tuple2(addr,rdtype);
106 if(index matches tagged Valid .idx)begin
107 if(pack(idx)!=rg_prf_index)
108 rd_rf[idx]<=tuple2(0,IntegerRF);
109 `ifdef verbose $display($time,"\tPRF: Removing previously alotted index: %d",idx); `endif
111 `ifdef verbose $display($time,"\tPRF: Giving Index: %d PID: %d",rg_prf_index, rg_pid_counter); `endif
112 return tuple2(rg_prf_index,rg_pid_counter);
114 method Action update_rd (Bit#(TLog#(`PRFDEPTH)) index, Bit#(4) pid);
115 physical_rf[index]<=tagged Absent pid;
118 method Action fwd_from_execution (Bit#(`Reg_width) data, Bit#(TLog#(`PRFDEPTH)) index, Bit#(4) pid);
119 `ifdef verbose $display($time,"\tPRF: FWD from EXE Data: %h index: %d pid: %d",data,index,pid); `endif
120 physical_rf[index]<=tagged Present data;
122 method Action fwd_from_memory (Bit#(`Reg_width) data, Bit#(TLog#(`PRFDEPTH)) index, Bit#(4) pid);
123 `ifdef verbose $display($time,"\tPRF: FWD from MEM Data: %h index: %d pid: %d",data,index,pid); `endif
124 physical_rf[index]<=tagged Present data;
126 method Action flush_all;