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/resources/graduation_unit.hh"
34 using namespace ThePipeline
;
36 GraduationUnit::GraduationUnit(std::string res_name
, int res_id
, int res_width
,
37 int res_latency
, InOrderCPU
*_cpu
,
38 ThePipeline::Params
*params
)
39 : Resource(res_name
, res_id
, res_width
, res_latency
, _cpu
),
42 for (ThreadID tid
= 0; tid
< ThePipeline::MaxThreads
; tid
++) {
43 nonSpecInstActive
[tid
] = &cpu
->nonSpecInstActive
[tid
];
44 nonSpecSeqNum
[tid
] = &cpu
->nonSpecSeqNum
[tid
];
49 GraduationUnit::execute(int slot_num
)
51 ResourceRequest
* grad_req
= reqs
[slot_num
];
52 DynInstPtr inst
= reqs
[slot_num
]->inst
;
53 ThreadID tid
= inst
->readTid();
54 int stage_num
= inst
->curSkedEntry
->stageNum
;
56 switch (grad_req
->cmd
)
60 if (lastNonSpecTick
== curTick()) {
61 DPRINTF(InOrderGraduation
, "Unable to graduate [sn:%i]. "
62 "Only 1 nonspec inst. per cycle can graduate.\n");
63 grad_req
->done(false);
67 // Handle Any Faults Before Graduating Instruction
68 if (inst
->fault
!= NoFault
) {
69 cpu
->trap(inst
->fault
, tid
, inst
);
70 grad_req
->setCompleted(false);
74 DPRINTF(InOrderGraduation
,
75 "[tid:%i] Graduating instruction [sn:%i].\n",
78 // Release Non-Speculative "Block" on instructions that could not
79 // execute because there was a non-speculative inst. active.
80 // @TODO: Fix this functionality. Probably too conservative.
81 if (inst
->isNonSpeculative()) {
82 *nonSpecInstActive
[tid
] = false;
83 DPRINTF(InOrderGraduation
,
84 "[tid:%i] Non-speculative inst [sn:%i] graduated\n",
86 lastNonSpecTick
= curTick();
89 if (inst
->traceData
) {
90 inst
->traceData
->setStageCycle(stage_num
, curTick());
93 // Tell CPU that instruction is finished processing
94 cpu
->instDone(inst
, tid
);
101 fatal("Unrecognized command to %s", resName
);