OpenASIP  2.0
BlocksGCU.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2021 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  * @file BlocksGCU.cc
26  *
27  * Implementation of BlocksGCU Class.
28  * This class describes the GCU unit of the Blocks (ABU of the TTA).
29  *
30  * @author Maarten Molendijk 2020 (m.j.molendijk@tue.nl)
31  * @author Kanishkan Vadivel 2021 (k.vadivel@tue.nl)
32  */
33 
34 #include "BlocksGCU.hh"
35 
36 using namespace TTAMachine;
37 /**
38  * BlocksGCU with default instructions
39  *
40  * @param mach The TTA machine where the GCU(ABU) needs to be added.
41  * @param name The name of the GCU.
42  * @param asInstr The address space containing the program instructions.
43  */
45  Machine& mach, const std::string& name, AddressSpace& asInstr) {
46  int delaySlots = 2;
47  int globalGuardLatency = 1;
48  gcu = new ControlUnit(name, delaySlots, globalGuardLatency);
49  mach.setGlobalControl(*gcu);
50  gcu->setAddressSpace(&asInstr);
51 
52  // TODO(mm): add check if there is not already a GCU present
53  pc = new FUPort("pc", 32, *gcu, true, true, true);
54  val = new FUPort("value", 32, *gcu, false, false, true);
55  ra = new SpecialRegisterPort("ra", 32, *gcu);
56 
57  // Create in and ouput sockets for 'special RA port'
58  raIn = new Socket("raIn");
59  raOut = new Socket("abu_out0");
60  valIn = new Socket("value");
61  pcIn = new Socket("pc");
62  mach.addSocket(*raIn);
63  mach.addSocket(*raOut);
64  mach.addSocket(*valIn);
65  mach.addSocket(*pcIn);
66  ra->attachSocket(*raIn);
67  ra->attachSocket(*raOut);
68  pc->attachSocket(*pcIn);
69  val->attachSocket(*valIn);
70 
71  // Connect in and out socket to bus
72  const int busWidth = 32;
73  const int immWidth = 0;
74  Machine::Extension busExt = Machine::Extension::ZERO;
75  Bus* raBus = new Bus("ra_out_to_ra_in", busWidth, immWidth, busExt);
76  mach.addBus(*raBus);
77  new UnconditionalGuard(false, *raBus);
78  new Segment("seg1", *raBus);
79  raIn->attachBus(*raBus);
80  raOut->attachBus(*raBus);
81  pcIn->attachBus(*raBus);
82  raOut->setDirection(Socket::Direction::OUTPUT);
83 
84  // set RA port
85  gcu->setReturnAddressPort(*ra);
86 
87  // Add HWops
88  ops.push_back(CreateHWOp("bnz", 2));
89  ops.push_back(CreateHWOp("bz", 2));
90  ops.push_back(CreateHWOp("call", 1));
91  ops.push_back(CreateHWOp("jump", 1));
92 }
93 
94 /**
95  * Configure the operation pipeline.
96  *
97  * @param pipeline A pointer to the execution pipeline of the operation of
98  * which the pipeline needs to be configured.
99  * @param numOfOperands The number of operands of the given hwOp.
100  */
101 void
103  TTAMachine::ExecutionPipeline* pipeline, int numOfOperands) {
104  if (numOfOperands == 1) {
105  pipeline->addPortRead(1, 0, 1);
106  } else if (numOfOperands == 2) {
107  pipeline->addPortRead(1, 0, 1);
108  pipeline->addPortRead(2, 0, 1);
109  } else {
110  // Currently no operation known that uses a different numbers of
111  // operands.
112  assert(
113  false &&
114  "Trying to add a GCU operation with a different number of "
115  "operands than 1 or 2.");
116  }
117 }
118 
119 /**
120  * Bind the operation's operands to GCU ports.
121  *
122  * @param hwOp A pointer to the hardware operation of which the operands need
123  * to be binded to GCU ports.
124  * @param numOfOperands The number of operands of the given hwOp.
125  */
126 void
128  if (numOfOperands < 2) {
129  hwOp->bindPort(1, *pc);
130  } else {
131  hwOp->bindPort(2, *pc); // Program counter is operand 2, therfore
132  // port binding is switched.
133  hwOp->bindPort(1, *val);
134  }
135 }
136 
137 /**
138  * Creates a hardware operation.
139  *
140  * @param name The name of the hardware operation. This needs to exactly match
141  * the name in OSEd.
142  * @param numOfOperands The number of operands that this hardware operation
143  * requires.
144  */
146 BlocksGCU::CreateHWOp(const std::string& name, int numOfOperands) {
147  HWOperation* op = new HWOperation(name, *gcu);
148  BindPorts(op, numOfOperands);
149  ConfigurePipeline(op->pipeline(), numOfOperands);
150  return op;
151 }
TTAMachine::HWOperation
Definition: HWOperation.hh:52
TTAMachine::AddressSpace
Definition: AddressSpace.hh:51
TTAMachine::HWOperation::bindPort
virtual void bindPort(int operand, const FUPort &port)
Definition: HWOperation.cc:269
TTAMachine::Segment
Definition: Segment.hh:54
TTAMachine::Bus
Definition: Bus.hh:53
BlocksGCU::BlocksGCU
BlocksGCU(TTAMachine::Machine &mach, const std::string &name, TTAMachine::AddressSpace &asInstr)
Definition: BlocksGCU.cc:44
BlocksGCU.hh
BlocksGCU::ConfigurePipeline
void ConfigurePipeline(TTAMachine::ExecutionPipeline *pipeline, int numOfOperands)
Definition: BlocksGCU.cc:102
assert
#define assert(condition)
Definition: Application.hh:86
TTAMachine::UnconditionalGuard
Definition: Guard.hh:180
TTAMachine::FUPort
Definition: FUPort.hh:46
TTAMachine::SpecialRegisterPort
Definition: SpecialRegisterPort.hh:48
TTAMachine::ControlUnit
Definition: ControlUnit.hh:50
TTAMachine::ExecutionPipeline::addPortRead
void addPortRead(int operand, int start, int duration)
Definition: ExecutionPipeline.cc:141
TTAMachine::Socket
Definition: Socket.hh:53
TTAMachine::Machine::addBus
virtual void addBus(Bus &bus)
Definition: Machine.cc:139
TTAMachine::Machine::setGlobalControl
virtual void setGlobalControl(ControlUnit &unit)
Definition: Machine.cc:317
TTAMachine::HWOperation::pipeline
ExecutionPipeline * pipeline() const
Definition: HWOperation.cc:201
TTAMachine::ExecutionPipeline
Definition: ExecutionPipeline.hh:55
TTAMachine::Machine::Extension
Extension
Definition: Machine.hh:80
TTAMachine
Definition: Assembler.hh:48
BlocksGCU::BindPorts
void BindPorts(TTAMachine::HWOperation *hwOp, int numOfOperands)
Definition: BlocksGCU.cc:127
BlocksGCU::CreateHWOp
TTAMachine::HWOperation * CreateHWOp(const std::string &name, int numOfOperands)
Definition: BlocksGCU.cc:146
TTAMachine::Machine::addSocket
virtual void addSocket(Socket &socket)
Definition: Machine.cc:157
TTAMachine::Machine
Definition: Machine.hh:73