OpenASIP  2.0
AssignmentQueue.icc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
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:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
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.
23  */
24 
25 /**
26  * Adds a new delayed assignment to the queue
27  *
28  * @param assignValue value to be assigned
29  * @param assignTarget pointer to the target of the assignment
30  * @param latency how long to wait in the queue until assignment can be done
31  * @note if the latency is zero, the assignment is done immediately
32  */
33 void inline
34 AssignmentQueue::addAssignment(
35  const SimValue& assignValue, SimValue* assignTarget, int latency) {
36 
37  if (maxLatency_ == 0) { // ring buffer with a size of zero! do nothing.
38  return;
39  }
40 
41  assert(latency >= 0 && latency <= maxLatency_);
42 
43  if (latency == 0) {
44  (*assignTarget) = assignValue;
45  return;
46  }
47 
48  int location = (position_ + latency) % maxLatency_;
49  assignmentQueue_[location].push_back(
50  Assignment(assignValue, assignTarget));
51 }
52 
53 /**
54  * Advances the assign queue by one cycle.
55  *
56  * Reduces delayed assignments wait time by one
57  */
58 void inline
59 AssignmentQueue::advanceClock() {
60 
61  if (maxLatency_ == 0) { // ring buffer with a size of zero! do nothing.
62  return;
63  }
64 
65  // Move to the next position in the ring buffer
66  position_ = (position_ + 1) % maxLatency_;
67 
68  while (!assignmentQueue_[position_].empty()) {
69  // do the assignment and remove it
70  Assignment& a = assignmentQueue_[position_].front();
71  (*a.second) = a.first;
72  assignmentQueue_[position_].pop_front();
73  }
74 }
75