The Sparta Modeling Framework
Loading...
Searching...
No Matches
Rename.cpp
Go to the documentation of this file.
1
8#include <algorithm>
9#include "Rename.hpp"
12
13namespace core_example
14{
15 const char Rename::name[] = "rename";
16
18 const RenameParameterSet * p) :
19 sparta::Unit(node),
20 uop_queue_("rename_uop_queue", p->rename_queue_depth,
21 node->getClock(), getStatisticSet()),
22 num_to_rename_per_cycle_(p->num_to_rename)
23 {
24 uop_queue_.enableCollection(node);
25
26 // The path into the Rename block
27 // - Instructions are received on the Uop Queue Append port
28 // - Credits arrive on the dispatch queue credits port
29 in_uop_queue_append_.
30 registerConsumerHandler(CREATE_SPARTA_HANDLER_WITH_DATA(Rename, decodedInstructions_, InstGroup));
31 in_dispatch_queue_credits_.
32 registerConsumerHandler(CREATE_SPARTA_HANDLER_WITH_DATA(Rename, creditsDispatchQueue_, uint32_t));
33 in_reorder_flush_.
34 registerConsumerHandler(CREATE_SPARTA_HANDLER_WITH_DATA(Rename, handleFlush_, FlushManager::FlushingCriteria));
35 sparta::StartupEvent(node, CREATE_SPARTA_HANDLER(Rename, sendInitialCredits_));
36 }
37
38 // Send the initial credit count
39 void Rename::sendInitialCredits_()
40 {
41 out_uop_queue_credits_.send(uop_queue_.capacity());
42 }
43
44 void Rename::creditsDispatchQueue_(const uint32_t & credits)
45 {
46 sparta_assert(in_dispatch_queue_credits_.dataReceived());
47
48 credits_dispatch_ += credits;
49 if (uop_queue_.size() > 0) {
50 ev_rename_insts_.schedule();
51 }
52 }
53
54 // Handle incoming flush
55 void Rename::handleFlush_(const FlushManager::FlushingCriteria & criteria)
56 {
58 info_logger_ << "Got a flush call for " << criteria;
59 }
60 out_uop_queue_credits_.send(uop_queue_.size());
61 uop_queue_.clear();
62 }
63
64 void Rename::decodedInstructions_(const InstGroup & insts)
65 {
66 sparta_assert(in_uop_queue_append_.dataReceived());
67
68 for(auto & i : insts) {
69 uop_queue_.push(i);
70 }
71
72 // If we have credits from dispatch, schedule a rename session
73 // this cycle
74 if (credits_dispatch_ > 0) {
75 ev_rename_insts_.schedule();
76 }
77 }
78
79 void Rename::renameInstructions_()
80 {
81
82 uint32_t num_rename = std::min(uop_queue_.size(), num_to_rename_per_cycle_);
83 num_rename = std::min(credits_dispatch_, num_rename);
84
85 if(num_rename > 0)
86 {
87
88 InstGroup insts;
89 for(uint32_t i = 0; i < num_rename; ++i) {
90 insts.emplace_back(uop_queue_.read(0));
92 info_logger_ << ": sending inst to dispatch: " << uop_queue_.read(0);
93 }
94 uop_queue_.pop();
95 }
96 out_dispatch_queue_write_.send(insts);
97 credits_dispatch_ -= num_rename;
98
99 // Replenish credits in the Decode unit
100 out_uop_queue_credits_.send(num_rename);
101 }
102
103 if (credits_dispatch_ > 0 && (uop_queue_.size() > 0)) {
104 ev_rename_insts_.schedule(1);
105 }
106 }
107
108}
#define sparta_assert(...)
Simple variadic assertion that will throw a sparta_exception if the condition fails.
#define SPARTA_EXPECT_FALSE(x)
A macro for hinting to the compiler a particular condition should be considered most likely false.
#define CREATE_SPARTA_HANDLER_WITH_DATA(clname, meth, dataT)
#define CREATE_SPARTA_HANDLER(clname, meth)
File that defines the StartupEvent class.
Parameters for Rename model.
Definition Rename.hpp:33
static const char name[]
Name of this resource. Required by sparta::UnitFactory.
Definition Rename.hpp:53
Rename(sparta::TreeNode *node, const RenameParameterSet *p)
Constructor for Rename.
Definition Rename.cpp:17
bool dataReceived() const
Has this port received data (not timed)
void send(const DataT &dat, sparta::Clock::Cycle rel_time=0)
Send data to bound receivers.
Definition DataPort.hpp:145
size_type size() const
Return the number of valid entries.
Definition Queue.hpp:552
uint32_t capacity() const
Return the fixed size of this queue.
Definition Queue.hpp:544
const value_type & read(uint32_t idx) const
Read and return the data at the given index, const reference.
Definition Queue.hpp:503
iterator push(const value_type &dat)
push data to the Queue.
Definition Queue.hpp:615
void enableCollection(TreeNode *parent)
Request that this queue begin collecting its contents for pipeline collection.
Definition Queue.hpp:603
void clear()
Empty the queue.
Definition Queue.hpp:580
void pop()
Pops the data at the front of the structure (oldest element) After pop iterator always points to the ...
Definition Queue.hpp:636
StartupEvent is a simple class for scheduling a starting event on the Scheduler. It does not support ...
Node in a composite tree representing a sparta Tree item.
Definition TreeNode.hpp:205
void schedule()
Schedule this event with its pre-set delay using the pre-set Clock.
log::MessageSource info_logger_
Default info logger.
Definition Unit.hpp:161
Macros for handling exponential backoff.