2 * Copyright (c) 2012-2013 ARM Limited
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
14 * Copyright (c) 2006 The Regents of The University of Michigan
15 * All rights reserved.
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 #include "cpu/o3/fu_pool.hh"
47 #include "cpu/func_unit.hh"
51 ////////////////////////////////////////////////////////////////////////////
53 // A pool of function units
57 FUPool::FUIdxQueue::addFU(int fu_idx
)
59 funcUnitsIdx
.push_back(fu_idx
);
64 FUPool::FUIdxQueue::getFU()
66 int retval
= funcUnitsIdx
[idx
++];
76 fuListIterator i
= funcUnits
.begin();
77 fuListIterator end
= funcUnits
.end();
84 FUPool::FUPool(const Params
*p
)
91 maxOpLatencies
.fill(Cycles(0));
95 // Iterate through the list of FUDescData structures
97 const vector
<FUDesc
*> ¶mList
= p
->FUList
;
98 for (FUDDiterator i
= paramList
.begin(); i
!= paramList
.end(); ++i
) {
101 // Don't bother with this if we're not going to create any FU's
105 // Create the FuncUnit object from this structure
106 // - add the capabilities listed in the FU's operation
109 // We create the first unit, then duplicate it as needed
111 FuncUnit
*fu
= new FuncUnit
;
113 OPDDiterator j
= (*i
)->opDescList
.begin();
114 OPDDiterator end
= (*i
)->opDescList
.end();
115 for (; j
!= end
; ++j
) {
116 // indicate that this pool has this capability
117 capabilityList
.set((*j
)->opClass
);
119 // Add each of the FU's that will have this capability to the
120 // appropriate queue.
121 for (int k
= 0; k
< (*i
)->number
; ++k
)
122 fuPerCapList
[(*j
)->opClass
].addFU(numFU
+ k
);
124 // indicate that this FU has the capability
125 fu
->addCapability((*j
)->opClass
, (*j
)->opLat
, (*j
)->pipelined
);
127 if ((*j
)->opLat
> maxOpLatencies
[(*j
)->opClass
])
128 maxOpLatencies
[(*j
)->opClass
] = (*j
)->opLat
;
130 if (!(*j
)->pipelined
)
131 pipelined
[(*j
)->opClass
] = false;
136 // Add the appropriate number of copies of this FU to the list
137 fu
->name
= (*i
)->name() + "(0)";
138 funcUnits
.push_back(fu
);
140 for (int c
= 1; c
< (*i
)->number
; ++c
) {
143 FuncUnit
*fu2
= new FuncUnit(*fu
);
145 s
<< (*i
)->name() << "(" << c
<< ")";
147 funcUnits
.push_back(fu2
);
152 unitBusy
.resize(numFU
);
154 for (int i
= 0; i
< numFU
; i
++) {
160 FUPool::getUnit(OpClass capability
)
162 // If this pool doesn't have the specified capability,
163 // return this information to the caller
164 if (!capabilityList
[capability
])
167 int fu_idx
= fuPerCapList
[capability
].getFU();
168 int start_idx
= fu_idx
;
170 // Iterate through the circular queue if needed, stopping if we've reached
171 // the first element again.
172 while (unitBusy
[fu_idx
]) {
173 fu_idx
= fuPerCapList
[capability
].getFU();
174 if (fu_idx
== start_idx
) {
180 assert(fu_idx
< numFU
);
182 unitBusy
[fu_idx
] = true;
188 FUPool::freeUnitNextCycle(int fu_idx
)
190 assert(unitBusy
[fu_idx
]);
191 unitsToBeFreed
.push_back(fu_idx
);
195 FUPool::processFreeUnits()
197 while (!unitsToBeFreed
.empty()) {
198 int fu_idx
= unitsToBeFreed
.back();
199 unitsToBeFreed
.pop_back();
201 assert(unitBusy
[fu_idx
]);
203 unitBusy
[fu_idx
] = false;
210 cout
<< "Function Unit Pool (" << name() << ")\n";
211 cout
<< "======================================\n";
212 cout
<< "Free List:\n";
214 for (int i
= 0; i
< numFU
; ++i
) {
219 cout
<< " [" << i
<< "] : ";
221 cout
<< funcUnits
[i
]->name
<< " ";
226 cout
<< "======================================\n";
227 cout
<< "Busy List:\n";
228 for (int i
= 0; i
< numFU
; ++i
) {
233 cout
<< " [" << i
<< "] : ";
235 cout
<< funcUnits
[i
]->name
<< " ";
242 FUPool::isDrained() const
244 bool is_drained
= true;
245 for (int i
= 0; i
< numFU
; i
++)
246 is_drained
= is_drained
&& !unitBusy
[i
];
253 ////////////////////////////////////////////////////////////////////////////
255 // The SimObjects we use to get the FU information into the simulator
257 ////////////////////////////////////////////////////////////////////////////
260 // FUPool - Contails a list of FUDesc objects to make available
267 FUPoolParams::create()
269 return new FUPool(this);