2 * Copyright (c) 2007 MIPS Technologies, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * Authors: Korey Sewell
32 #include "cpu/inorder/pipeline_traits.hh"
33 #include "cpu/inorder/inorder_dyn_inst.hh"
34 #include "cpu/inorder/resources/resource_list.hh"
38 namespace ThePipeline
{
40 //@TODO: create my own Instruction Schedule Class
41 //that operates as a Priority QUEUE
42 int getNextPriority(DynInstPtr
&inst
, int stage_num
)
47 std::priority_queue<ScheduleEntry*, std::vector<ScheduleEntry*>,
48 entryCompare>::iterator sked_it = inst->resSched.begin();
50 std::priority_queue<ScheduleEntry*, std::vector<ScheduleEntry*>,
51 entryCompare>::iterator sked_end = inst->resSched.end();
53 while (sked_it != sked_end) {
55 if (sked_it.top()->stageNum == stage_num) {
56 cur_pri = sked_it.top()->priority;
66 void createFrontEndSchedule(DynInstPtr
&inst
)
68 InstStage
*I
= inst
->addStage();
69 InstStage
*E
= inst
->addStage();
71 I
->needs(FetchSeq
, FetchSeqUnit::AssignNextPC
);
72 I
->needs(ITLB
, TLBUnit::FetchLookup
);
73 I
->needs(ICache
, CacheUnit::InitiateFetch
);
75 E
->needs(ICache
, CacheUnit::CompleteFetch
);
76 E
->needs(Decode
, DecodeUnit::DecodeInst
);
77 E
->needs(BPred
, BranchPredictor::PredictBranch
);
78 E
->needs(FetchSeq
, FetchSeqUnit::UpdateTargetPC
);
81 bool createBackEndSchedule(DynInstPtr
&inst
)
83 if (!inst
->staticInst
) {
87 InstStage
*E
= inst
->currentStage();
88 InstStage
*M
= inst
->addStage();
89 InstStage
*A
= inst
->addStage();
90 InstStage
*W
= inst
->addStage();
92 for (int idx
=0; idx
< inst
->numSrcRegs(); idx
++) {
93 if (!idx
|| !inst
->isStore()) {
94 E
->needs(RegManager
, UseDefUnit::ReadSrcReg
, idx
);
99 if ( inst
->isNonSpeculative() ) {
100 // skip execution of non speculative insts until later
101 } else if ( inst
->isMemRef() ) {
102 if ( inst
->isLoad() ) {
103 E
->needs(AGEN
, AGENUnit::GenerateAddr
);
104 E
->needs(DTLB
, TLBUnit::DataLookup
);
105 E
->needs(DCache
, CacheUnit::InitiateReadData
);
107 } else if (inst
->opClass() == IntMultOp
|| inst
->opClass() == IntDivOp
) {
108 E
->needs(MDU
, MultDivUnit::StartMultDiv
);
110 // ZERO-LATENCY Multiply:
111 // E->needs(MDU, MultDivUnit::MultDiv);
113 E
->needs(ExecUnit
, ExecutionUnit::ExecuteInst
);
116 if (inst
->opClass() == IntMultOp
|| inst
->opClass() == IntDivOp
) {
117 M
->needs(MDU
, MultDivUnit::EndMultDiv
);
120 if ( inst
->isLoad() ) {
121 M
->needs(DCache
, CacheUnit::CompleteReadData
);
122 } else if ( inst
->isStore() ) {
123 M
->needs(RegManager
, UseDefUnit::ReadSrcReg
, 1);
124 M
->needs(AGEN
, AGENUnit::GenerateAddr
);
125 M
->needs(DTLB
, TLBUnit::DataLookup
);
126 M
->needs(DCache
, CacheUnit::InitiateWriteData
);
129 if ( inst
->isStore() ) {
130 A
->needs(DCache
, CacheUnit::CompleteWriteData
);
133 if ( inst
->isNonSpeculative() ) {
134 if ( inst
->isMemRef() ) fatal("Non-Speculative Memory Instruction");
135 W
->needs(ExecUnit
, ExecutionUnit::ExecuteInst
);
138 for (int idx
=0; idx
< inst
->numDestRegs(); idx
++) {
139 W
->needs(RegManager
, UseDefUnit::WriteDestReg
, idx
);
142 W
->needs(Grad
, GraduationUnit::GraduateInst
);
147 InstStage::InstStage(DynInstPtr inst
, int stage_num
)
149 stageNum
= stage_num
;
150 nextTaskPriority
= 0;
151 instSched
= &inst
->resSched
;