stats: Fix all stats usages to deal with template fixes
[gem5.git] / src / cpu / inorder / resources / mult_div_unit.hh
1 /*
2 * Copyright (c) 2007 MIPS Technologies, Inc.
3 * All rights reserved.
4 *
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.
15 *
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.
27 *
28 * Authors: Korey Sewell
29 *
30 */
31
32 #ifndef __CPU_INORDER_MULT_DIV_UNIT_HH__
33 #define __CPU_INORDER_MULT_DIV_UNIT_HH__
34
35 #include <vector>
36 #include <list>
37 #include <string>
38
39 #include "cpu/func_unit.hh"
40 #include "cpu/op_class.hh"
41 #include "cpu/inorder/first_stage.hh"
42 #include "cpu/inorder/resource.hh"
43 #include "cpu/inorder/inorder_dyn_inst.hh"
44
45 class MDUEvent;
46
47 class MultDivUnit : public Resource {
48 public:
49 typedef ThePipeline::DynInstPtr DynInstPtr;
50
51 enum Command {
52 StartMultDiv,
53 EndMultDiv,
54 MultDiv
55 };
56
57 public:
58 MultDivUnit(std::string res_name, int res_id, int res_width,
59 int res_latency, InOrderCPU *_cpu, ThePipeline::Params *params);
60 virtual ~MultDivUnit() {}
61
62 public:
63 /** Override default Resource getSlot(). Will only getSlot if
64 * valid mult/div sequence is being maintained
65 */
66 virtual int getSlot(DynInstPtr inst);
67
68 virtual int findSlot(DynInstPtr inst);
69
70 virtual void freeSlot(int slot_idx);
71
72 virtual void init();
73
74 /** Get Operand Size For A Division Operation */
75 int getDivOpSize(DynInstPtr inst);
76
77 /** Override default Resource execute */
78 virtual void execute(int slot_num);
79
80 void exeMulDiv(int slot_num);
81
82 /** Register extra resource stats */
83 virtual void regStats();
84
85 protected:
86 /** Latency & Repeat Rate for Multiply Insts */
87 unsigned multRepeatRate;
88 unsigned multLatency;
89
90 /** Latency & Repeat Rate for 8-bit Divide Insts */
91 unsigned div8RepeatRate;
92 unsigned div8Latency;
93
94 /** Latency & Repeat Rate for 16-bit Divide Insts */
95 unsigned div16RepeatRate;
96 unsigned div16Latency;
97
98 /** Latency & Repeat Rate for 24-bit Divide Insts */
99 unsigned div24RepeatRate;
100 unsigned div24Latency;
101
102 /** Latency & Repeat Rate for 32-bit Divide Insts */
103 unsigned div32RepeatRate;
104 unsigned div32Latency;
105
106 /** Last cycle that MDU was used */
107 Tick lastMDUCycle;
108
109 /** Last type of instruction MDU started processing */
110 OpClass lastOpType;
111
112 /** Last Division Operand of instruction MDU was processing */
113 uint32_t lastDivSize;
114
115 /** Last instruction name the MDU used */
116 std::string lastInstName;
117
118 /** Number of Instruction Requests the Resource Processes */
119 Stats::Scalar multInstReqsProcessed;
120
121 /** Number of Instruction Requests the Resource Processes */
122 Stats::Scalar divInstReqsProcessed;
123
124 MDUEvent *mduEvent;
125 };
126
127 class MDUEvent : public ResourceEvent
128 {
129 public:
130 MDUEvent();
131 virtual ~MDUEvent() { }
132
133
134 virtual void process();
135 };
136
137
138 #endif //__CPU_INORDER_MULT_DIV_UNIT_HH__