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.
41 #include "cpu/o3/fu_pool.hh"
45 #include "cpu/func_unit.hh"
49 ////////////////////////////////////////////////////////////////////////////
51 // A pool of function units
55 FUPool::FUIdxQueue::addFU(int fu_idx
)
57 funcUnitsIdx
.push_back(fu_idx
);
62 FUPool::FUIdxQueue::getFU()
64 int retval
= funcUnitsIdx
[idx
++];
74 fuListIterator i
= funcUnits
.begin();
75 fuListIterator end
= funcUnits
.end();
82 FUPool::FUPool(const Params
&p
)
89 maxOpLatencies
.fill(Cycles(0));
93 // Iterate through the list of FUDescData structures
95 const vector
<FUDesc
*> ¶mList
= p
.FUList
;
96 for (FUDDiterator i
= paramList
.begin(); i
!= paramList
.end(); ++i
) {
99 // Don't bother with this if we're not going to create any FU's
103 // Create the FuncUnit object from this structure
104 // - add the capabilities listed in the FU's operation
107 // We create the first unit, then duplicate it as needed
109 FuncUnit
*fu
= new FuncUnit
;
111 OPDDiterator j
= (*i
)->opDescList
.begin();
112 OPDDiterator end
= (*i
)->opDescList
.end();
113 for (; j
!= end
; ++j
) {
114 // indicate that this pool has this capability
115 capabilityList
.set((*j
)->opClass
);
117 // Add each of the FU's that will have this capability to the
118 // appropriate queue.
119 for (int k
= 0; k
< (*i
)->number
; ++k
)
120 fuPerCapList
[(*j
)->opClass
].addFU(numFU
+ k
);
122 // indicate that this FU has the capability
123 fu
->addCapability((*j
)->opClass
, (*j
)->opLat
, (*j
)->pipelined
);
125 if ((*j
)->opLat
> maxOpLatencies
[(*j
)->opClass
])
126 maxOpLatencies
[(*j
)->opClass
] = (*j
)->opLat
;
128 if (!(*j
)->pipelined
)
129 pipelined
[(*j
)->opClass
] = false;
134 // Add the appropriate number of copies of this FU to the list
135 fu
->name
= (*i
)->name() + "(0)";
136 funcUnits
.push_back(fu
);
138 for (int c
= 1; c
< (*i
)->number
; ++c
) {
141 FuncUnit
*fu2
= new FuncUnit(*fu
);
143 s
<< (*i
)->name() << "(" << c
<< ")";
145 funcUnits
.push_back(fu2
);
150 unitBusy
.resize(numFU
);
152 for (int i
= 0; i
< numFU
; i
++) {
158 FUPool::getUnit(OpClass capability
)
160 // If this pool doesn't have the specified capability,
161 // return this information to the caller
162 if (!capabilityList
[capability
])
165 int fu_idx
= fuPerCapList
[capability
].getFU();
166 int start_idx
= fu_idx
;
168 // Iterate through the circular queue if needed, stopping if we've reached
169 // the first element again.
170 while (unitBusy
[fu_idx
]) {
171 fu_idx
= fuPerCapList
[capability
].getFU();
172 if (fu_idx
== start_idx
) {
178 assert(fu_idx
< numFU
);
180 unitBusy
[fu_idx
] = true;
186 FUPool::freeUnitNextCycle(int fu_idx
)
188 assert(unitBusy
[fu_idx
]);
189 unitsToBeFreed
.push_back(fu_idx
);
193 FUPool::processFreeUnits()
195 while (!unitsToBeFreed
.empty()) {
196 int fu_idx
= unitsToBeFreed
.back();
197 unitsToBeFreed
.pop_back();
199 assert(unitBusy
[fu_idx
]);
201 unitBusy
[fu_idx
] = false;
208 cout
<< "Function Unit Pool (" << name() << ")\n";
209 cout
<< "======================================\n";
210 cout
<< "Free List:\n";
212 for (int i
= 0; i
< numFU
; ++i
) {
217 cout
<< " [" << i
<< "] : ";
219 cout
<< funcUnits
[i
]->name
<< " ";
224 cout
<< "======================================\n";
225 cout
<< "Busy List:\n";
226 for (int i
= 0; i
< numFU
; ++i
) {
231 cout
<< " [" << i
<< "] : ";
233 cout
<< funcUnits
[i
]->name
<< " ";
240 FUPool::isDrained() const
242 bool is_drained
= true;
243 for (int i
= 0; i
< numFU
; i
++)
244 is_drained
= is_drained
&& !unitBusy
[i
];
251 ////////////////////////////////////////////////////////////////////////////
253 // The SimObjects we use to get the FU information into the simulator
255 ////////////////////////////////////////////////////////////////////////////
258 // FUPool - Contails a list of FUDesc objects to make available
265 FUPoolParams::create() const
267 return new FUPool(*this);