The Sparta Modeling Framework
Loading...
Searching...
No Matches
Decode.cpp
1// <Decode.cpp> -*- C++ -*-
2
3
4#include <algorithm>
5
6#include "Decode.hpp"
8
9namespace core_example
10{
12 const DecodeParameterSet * p) :
13 sparta::Unit(node),
14 fetch_queue_("FetchQueue", p->fetch_queue_size, node->getClock(), &unit_stat_set_),
15 num_to_decode_(p->num_to_decode)
16 {
17 fetch_queue_.enableCollection(node);
18
19 fetch_queue_write_in_.
20 registerConsumerHandler(CREATE_SPARTA_HANDLER_WITH_DATA(Decode, fetchBufferAppended_, InstGroup));
21 uop_queue_credits_in_.
22 registerConsumerHandler(CREATE_SPARTA_HANDLER_WITH_DATA(Decode, receiveUopQueueCredits_, uint32_t));
23 in_reorder_flush_.
24 registerConsumerHandler(CREATE_SPARTA_HANDLER_WITH_DATA(Decode, handleFlush_, FlushManager::FlushingCriteria));
25
26 sparta::StartupEvent(node, CREATE_SPARTA_HANDLER(Decode, sendInitialCredits_));
27 }
28
29 // Send fetch the initial credit count
30 void Decode::sendInitialCredits_()
31 {
32 fetch_queue_credits_outp_.send(fetch_queue_.capacity());
33 }
34
35 // Receive Uop credits from Dispatch
36 void Decode::receiveUopQueueCredits_(const uint32_t & credits) {
37 uop_queue_credits_ += credits;
38 if (fetch_queue_.size() > 0) {
39 ev_decode_insts_event_.schedule(sparta::Clock::Cycle(0));
40 }
41
43 info_logger_ << "Received credits: " << uop_queue_credits_in_;
44 }
45 }
46
47 // Called when the fetch buffer was appended by Fetch. If decode
48 // has the credits, then schedule a decode session. Otherwise, go
49 // to sleep
50 void Decode::fetchBufferAppended_(const InstGroup & insts)
51 {
52 // Cache the instructions in the instruction queue if we can't decode this cycle
53 for(auto & i : insts)
54 {
55 fetch_queue_.push(i);
56
58 info_logger_ << "Got inst: " << i;
59 }
60 }
61 if (uop_queue_credits_ > 0) {
62 ev_decode_insts_event_.schedule(sparta::Clock::Cycle(0));
63 }
64 }
65
66 // Handle incoming flush
67 void Decode::handleFlush_(const FlushManager::FlushingCriteria & criteria)
68 {
70 info_logger_ << "Got a flush call for " << criteria;
71 }
72 fetch_queue_credits_outp_.send(fetch_queue_.size());
73 fetch_queue_.clear();
74 }
75
76 // Decode instructions
77 void Decode::decodeInsts_()
78 {
79 uint32_t num_decode = std::min(uop_queue_credits_, fetch_queue_.size());
80 num_decode = std::min(num_decode, num_to_decode_);
81
82 if(num_decode > 0)
83 {
84 InstGroup insts;
85 // Send instructions on their way to rename
86 for(uint32_t i = 0; i < num_decode; ++i) {
87 insts.emplace_back(fetch_queue_.read(0));
88
90 info_logger_ << "Decoded inst: " << fetch_queue_.read(0);
91 }
92
93 fetch_queue_.pop();
94 }
95
96 // Send decoded instructions to rename
97 uop_queue_outp_.send(insts);
98
99 // Decrement internal Uop Queue credits
100 uop_queue_credits_ -= num_decode;
101
102 // Send credits back to Fetch to get more instructions
103 fetch_queue_credits_outp_.send(num_decode);
104 }
105
106 // If we still have credits to send instructions as well as
107 // instructions in the queue, schedule another decode session
108 if(uop_queue_credits_ > 0 && fetch_queue_.size() > 0) {
109 ev_decode_insts_event_.schedule(1);
110 }
111 }
112}
#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 Decode model.
Definition Decode.hpp:32
Decode(sparta::TreeNode *node, const DecodeParameterSet *p)
Constructor for Decode.
Definition Decode.cpp:11
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.