46 #ifndef __CPU_MINOR_BUFFERS_HH__ 47 #define __CPU_MINOR_BUFFERS_HH__ 82 virtual bool isBubble()
const = 0;
91 template <
typename ElemType>
97 { elem.reportData(os); }
102 template <
typename PtrType>
108 { elem->reportData(os); }
116 template <
typename ElemType>
120 static bool isBubble(
const ElemType &) {
return false; }
124 panic(
"bubble called but no bubble interface");
129 template <
typename ElemType>
134 {
return elem.isBubble(); }
136 static ElemType
bubble() {
return ElemType::bubble(); }
140 template <
typename PtrType,
typename ElemType>
145 {
return elem->isBubble(); }
147 static PtrType
bubble() {
return ElemType::bubble(); }
151 template <
typename ElemType,
165 const std::string &data_name,
166 int num_past,
int num_future,
167 int report_left = -1,
int report_right = -1) :
169 reportLeft(report_left), reportRight(report_right),
180 for (
int i = -this->past;
i <= this->future;
i++) {
181 if (!BubbleTraits::isBubble((*
this)[
i]))
195 std::ostringstream
data;
197 int step = (reportLeft > reportRight ? -1 : 1);
198 int end = reportRight + step;
202 const ElemType &datum = (*this)[
i];
204 ReportTraits::reportData(data, datum);
216 template <
typename Data>
233 const std::string &data_name,
235 bool report_backwards =
false) :
237 buffer(name, data_name, delay_, 0, (report_backwards ? -delay_ : 0),
238 (report_backwards ? 0 : -delay_))
253 Input(
typename Buffer::wire input_wire) :
254 inputWire(input_wire)
264 Output(
typename Buffer::wire output_wire) :
265 outputWire(output_wire)
286 template <
typename ElemType,
287 typename ReportTraits,
306 const std::string &data_name,
309 (name, data_name, depth, 0, -1, -depth),
310 pushWire(this->getWire(0)),
311 popWire(this->getWire(-depth)),
319 for (
unsigned i = 0;
i <= depth;
i++)
320 (*
this)[-
i] = BubbleTraits::bubble();
330 assert(!alreadyPushed());
332 if (!BubbleTraits::isBubble(elem))
337 ElemType &
front() {
return *popWire; }
339 const ElemType &
front()
const {
return *popWire; }
345 bool isPopable() {
return !BubbleTraits::isBubble(front()); }
353 bool data_at_end = isPopable();
362 stalled = isPopable();
366 ElemType bubble = BubbleTraits::bubble();
377 virtual bool canReserve()
const = 0;
380 virtual void reserve() = 0;
383 virtual void freeReservation() = 0;
396 template <
typename ElemType,
415 Queue(
const std::string &
name,
const std::string &data_name,
416 unsigned int capacity_) :
430 if (!BubbleTraits::isBubble(data)) {
432 queue.push_back(data);
434 if (queue.size() > capacity) {
435 warn(
"%s: No space to push data into queue of capacity" 436 " %u, pushing anyway\n",
name(), capacity);
448 if (numReservedSlots != 0)
459 if (unreservedRemainingSpace() == 0)
460 warn(
"%s: No space is reservable in queue",
name());
465 bool canReserve()
const {
return unreservedRemainingSpace() != 0; }
481 int ret = capacity - queue.size();
483 return (ret < 0 ? 0 : ret);
490 int ret = capacity - (queue.size() + numReservedSlots);
492 return (ret < 0 ? 0 : ret);
496 ElemType &
front() {
return queue.front(); }
498 const ElemType &
front()
const {
return queue.front(); }
501 void pop() { queue.pop_front(); }
504 bool empty()
const {
return queue.empty(); }
509 std::ostringstream
data;
512 unsigned int num_total = (occupiedSpace() > totalSpace() ?
513 occupiedSpace() : totalSpace());
515 unsigned int num_reserved = reservedSpace();
516 unsigned int num_occupied = occupiedSpace();
520 while (num_printed <= num_occupied) {
521 ReportTraits::reportData(data, queue[num_printed - 1]);
524 if (num_printed <= num_total)
528 int num_printed_reserved = 1;
530 while (num_printed_reserved <= num_reserved &&
531 num_printed <= num_total)
534 num_printed_reserved++;
537 if (num_printed <= num_total)
542 while (num_printed <= num_total) {
545 if (num_printed <= num_total)
564 template <
typename ElemType,
578 unsigned int capacity_) :
579 queue(name, data_name, capacity_),
591 if (!BubbleTraits::isBubble(new_element)) {
593 elementPtr = &new_element;
595 queue.
push(new_element);
604 {
return (elementPtr ? *elementPtr : queue.
front()); }
607 {
return (elementPtr ? *elementPtr : queue.
front()); }
630 queue.
push(*elementPtr);
...ReportTraits are trait classes with the same functionality as ReportIF, but with elements explicit...
#define panic(...)
This implements a cprintf based panic() function.
Cycles is a wrapper class for representing cycle counts, i.e.
void pop()
Pop the head item.
static bool isBubble(const ElemType &)
unsigned int numReservedSlots
Number of slots currently reserved for future (reservation respecting) pushes.
const std::string & name()
MinorBuffer(const std::string &name, const std::string &data_name, int num_past, int num_future, int report_left=-1, int report_right=-1)
const ElemType & front() const
bool canReserve() const
Can a slot be reserved?
Output(typename Buffer::wire output_wire)
MinorBuffer< Data > Buffer
bool empty() const
Is the queue empty?
unsigned int unreservedRemainingSpace() const
Like remainingSpace but does not count reserved spaces.
const ElemType & front() const
unsigned int occupiedSpace() const
Number of slots already occupied in this buffer.
ElemType & front()
Peek at the end element of the pipe.
Interface class for data with 'bubble' values.
std::string dataName
Name to use for the data in a MinorTrace line.
Minor contains all the definitions within the MinorCPU apart from the CPU class itself.
Wrapper for a queue type to act as a pipeline stage input queue.
unsigned int totalSpace() const
Number of slots available in an empty buffer.
This file contains miscellaneous classes and functions for formatting general trace information and a...
Queue(const std::string &name, const std::string &data_name, unsigned int capacity_)
void reserve()
Reserve space in the queue for future pushes.
void advance()
Try to advance the pipeline.
TimeBuffer< ElemType >::wire popWire
Wire at the output end of the pipeline (for convenience)
std::string dataName
Name to use for the data in MinorTrace.
unsigned int capacity
Need this here as queues usually don't have a limited capacity.
void freeReservation()
Clear a single reserved slot.
A similar adaptor but for elements held by pointer ElemType should implement ReportIF.
TimeBuffer with MinorTrace and Named interfaces.
Base class for space reservation requestable objects.
Pass on call to the element where the element is a pointer.
std::deque< ElemType > queue
unsigned int reservedSpace() const
Number of slots which are reserved.
static bool isBubble(const PtrType &elem)
ElemType & front()
Head value.
static void reportData(std::ostream &os, const PtrType &elem)
unsigned int occupancy
The number of slots with non-bubbles in them.
virtual void reportData(std::ostream &os) const =0
Print the data in a format suitable to be the value in "name=value" trace lines.
unsigned int remainingSpace() const
Number of slots yet to fill in this buffer.
Pass on call to the element.
bool alreadyPushed()
Have we already pushed onto this pipe without advancing.
Cycles delay
Delays, in cycles, writing data into the latch and seeing it on the latched wires.
Output output()
An interface to just the output of the buffer.
void clearReservedSpace()
Clear all allocated space.
static bool isBubble(const ElemType &elem)
A pipeline simulating class that will stall (not advance when advance() is called) if a non-bubble va...
void push(ElemType &data)
Push an element into the buffer if it isn't a bubble.
#define MINORTRACE(...)
DPRINTFN for MinorTrace reporting.
SelfStallingPipeline(const std::string &name, const std::string &data_name, unsigned depth)
Interface class for data with reporting/tracing facilities.
Wraps a MinorBuffer with Input/Output interfaces to ensure that units within the model can only see t...
static void reportData(std::ostream &os, const ElemType &elem)
void minorTrace() const
Report buffer states from 'slot' 'from' to 'to'.
void push(ElemType &elem)
Write an element to the back of the pipeline.
TimeBuffer< ElemType >::wire pushWire
Wire at the input end of the pipeline (for convenience)
bool stalled
If true, advance will not advance the pipeline.
bool isPopable()
There's data (not a bubble) at the end of the pipe.
Latch(const std::string &name, const std::string &data_name, Cycles delay_=Cycles(1), bool report_backwards=false)
forward/backwardDelay specify the delay from input to output in each direction.
Input input()
An interface to just the input of the buffer.