46 #ifndef __CPU_MINOR_BUFFERS_HH__
47 #define __CPU_MINOR_BUFFERS_HH__
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; }
121 static ElemType
bubble() { assert(
false); }
125 template <
typename ElemType>
130 {
return elem.isBubble(); }
132 static ElemType
bubble() {
return ElemType::bubble(); }
136 template <
typename PtrType,
typename ElemType>
141 {
return elem->isBubble(); }
143 static PtrType
bubble() {
return ElemType::bubble(); }
147 template <
typename ElemType,
148 typename ReportTraits = ReportTraitsAdaptor<ElemType>,
149 typename BubbleTraits = BubbleTraitsAdaptor<ElemType> >
161 const std::string &data_name,
162 int num_past,
int num_future,
163 int report_left = -1,
int report_right = -1) :
177 if (!BubbleTraits::isBubble((*
this)[
i]))
191 std::ostringstream
data;
198 const ElemType &datum = (*this)[
i];
200 ReportTraits::reportData(data, datum);
212 template <
typename Data>
229 const std::string &data_name,
231 bool report_backwards =
false) :
233 buffer(name, data_name, delay_, 0, (report_backwards ? -delay_ : 0),
234 (report_backwards ? 0 : -delay_))
282 template <
typename ElemType,
283 typename ReportTraits,
284 typename BubbleTraits = BubbleTraitsAdaptor<ElemType> >
302 const std::string &data_name,
305 (name, data_name, depth, 0, -1, -depth),
315 for (
unsigned i = 0;
i <= depth;
i++)
316 (*
this)[-
i] = BubbleTraits::bubble();
328 if (!BubbleTraits::isBubble(elem))
362 ElemType bubble = BubbleTraits::bubble();
390 template <
typename ElemType,
409 Queue(
const std::string &
name,
const std::string &data_name,
410 unsigned int capacity_) :
426 if (!BubbleTraits::isBubble(data)) {
428 queue.push_back(data);
431 warn(
"%s: No space to push data into queue of capacity"
456 warn(
"%s: No space is reservable in queue",
name());
479 return (ret < 0 ? 0 : ret);
488 return (ret < 0 ? 0 : ret);
505 std::ostringstream
data;
516 while (num_printed <= num_occupied) {
517 ReportTraits::reportData(data,
queue[num_printed - 1]);
520 if (num_printed <= num_total)
524 int num_printed_reserved = 1;
526 while (num_printed_reserved <= num_reserved &&
527 num_printed <= num_total)
530 num_printed_reserved++;
533 if (num_printed <= num_total)
538 while (num_printed <= num_total) {
541 if (num_printed <= num_total)
560 template <
typename ElemType,
561 typename ReportTraits = ReportTraitsAdaptor<ElemType>,
562 typename BubbleTraits = BubbleTraitsAdaptor<ElemType> >
574 unsigned int capacity_) :
575 queue(name, data_name, capacity_),
587 if (!BubbleTraits::isBubble(new_element)) {
591 queue.push(new_element);
613 queue.freeReservation();
648 return queue.unreservedRemainingSpace();
...ReportTraits are trait classes with the same functionality as ReportIF, but with elements explicit...
const std::string & name() const
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)
Output(typename Buffer::wire output_wire)
MinorBuffer< Data > Buffer
virtual bool isBubble() const =0
int reportLeft
The range of elements that should appear in trace lines.
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.
unsigned int unreservedRemainingSpace() const
Like remainingSpace but does not count reserved spaces.
const ElemType & front() const
Wrapper for a queue type to act as a pipeline stage input queue.
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.
bool empty() const
Is the queue empty?
bool canReserve() const
Can a slot be reserved?
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
static bool isBubble(const PtrType &elem)
ElemType & front()
Head value.
const ElemType & front() const
static void reportData(std::ostream &os, const PtrType &elem)
virtual bool canReserve() const =0
Can a slot be reserved?
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.
virtual void freeReservation()=0
Free a reserved slot.
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.
unsigned int reservedSpace() const
Number of slots which are reserved.
Output output()
An interface to just the output of the buffer.
virtual void reserve()=0
Reserve a slot in whatever structure this is attached to.
void clearReservedSpace()
Clear all allocated space.
unsigned int totalSpace() const
Number of slots available in an empty buffer.
void minorTrace() const
Report buffer states from 'slot' 'from' to 'to'.
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 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)
unsigned int remainingSpace() const
Number of slots yet to fill in this buffer.
unsigned int occupiedSpace() const
Number of slots already occupied in this buffer.
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.