2 Copyright (c) 2002-2009 Tampere University.
4 This file is part of TTA-Based Codesign Environment (TCE).
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
25 * @file CompiledSimulation.icc
27 * Inline definitions of CompiledSimulation class.
29 * @author Viljami Korhonen 2007 (viljami.korhonen-no.spam-tut.fi)
30 * @author Pekka Jääskeläinen 2009 (pekka.jaaskelainen-no.spam-tut.fi)
34 #include "Application.hh"
37 * Adds a SimValue to the FU's results list.
39 * Used to simulate the FU latency.
41 * @param results The FU results list
42 * @param cycleCount # of cycles at the time of the addition
43 * @param value value to be added
44 * @param latency Latency of the FU
47 CompiledSimulation::addFUResult(
48 FUResultType& results,
49 ClockCycleCount cycleCount,
50 const SimValue& value,
53 int oldResultIndex = -1;
55 // Find the next empty slot and put the result there
56 for (int i = 0; i < results.size; ++i) {
57 FUResultElementType& result = results.data[i];
59 // clear overwritten results to make room for the ringbuffer.
62 if (result.cycles <= cycleCount) {
64 if (oldResultIndex == -1) {
67 FUResultElementType& oldResult =
68 results.data[oldResultIndex];
69 if (oldResult.cycles < result.cycles) {
70 // use the space of the old result for the new one.
71 oldResult.cycles = cycleCount + latency;
72 oldResult.value = value;
73 oldResult.used = true;
77 results.numberOfElements--;
83 result.cycles = cycleCount + latency;
86 results.numberOfElements++;
90 assert(0 && "Ringbuffer full!");
94 * Adds a UIntWord value to the FU's results.
96 * Used to simulate the FU latency.
98 * @param results The FU results list
99 * @param cycleCount # of cycles at the time of the addition
100 * @param value value to be added
101 * @param latency Latency of the FU
104 CompiledSimulation::addFUResult(
105 FUResultType& results,
106 ClockCycleCount cycleCount,
107 const UIntWord& value,
110 int oldResultIndex = -1;
112 // Find the next empty slot and put the result there
113 for (int i = 0; i < results.size; ++i) {
114 FUResultElementType& result = results.data[i];
116 // clear overwritten results to make room for the ringbuffer.
119 if (result.cycles <= cycleCount) {
121 if (oldResultIndex == -1) {
124 FUResultElementType& oldResult =
125 results.data[oldResultIndex];
126 if (oldResult.cycles < result.cycles) {
127 // use the space of the old result for the new one.
128 oldResult.cycles = cycleCount + latency;
129 oldResult.value = value;
130 oldResult.used = true;
134 results.numberOfElements--;
141 result.cycles = cycleCount + latency;
142 result.value = value;
144 results.numberOfElements++;
148 assert(0 && "Ringbuffer full!");
153 * Grabs the current value from the FU results list.
155 * The current value is computed using the current cycle count,
156 * discarding "too old" (overwritten) results.
158 * @param target Target of the assignment.
159 * @param results The FU results to be checked for.
160 * @param cycles The current cyclecount.
163 CompiledSimulation::FUResult(
164 SimValue& target, FUResultType& results, ClockCycleCount cycles) {
166 int maxDiff = -2147483647;
168 for (int i = 0; results.numberOfElements != 0 && i < results.size; ++i) {
169 FUResultElementType& result = results.data[i];
175 int diff = static_cast<int>(result.cycles - cycles);
177 if (diff >= maxDiff) {
179 target = result.value;
182 results.numberOfElements--;
190 CompiledSimulation::clearFUResults(FUResultType& results) {
192 if (results.numberOfElements == 0) {
196 for (int i = 0; i < results.size; ++i) {
197 results.data[i].used = false;
199 results.numberOfElements = 0;