OpenASIP  2.0
BlocksMUL.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 BlocksMUL.cc
26  *
27  * Implementation of BlocksMUL Class.
28  * This class resembles a single output in the Blocks architecture.
29  *
30  * @author Maarten Molendijk 2020 (m.j.molendijk@tue.nl)
31  * @author Kanishkan Vadivel 2021 (k.vadivel@tue.nl)
32  */
33 
34 #include "BlocksMUL.hh"
35 
36 using namespace TTAMachine;
37 
38 /**
39  * Constructor BlocksMUL
40  *
41  * @param mach The TTA machine where the MUL needs to be added.
42  * @param name The name of the MUL.
43  * @param sources A list of sources that are attached to this unit's input.
44  * @param in1sock (shared) pointer to the TTA socket for in1 input port.
45  * @param in2sock (shared) pointer to the TTA socket for in2 input port.
46  */
48  Machine& mach, const std::string& name, std::list<std::string> sources,
49  std::shared_ptr<TTAMachine::Socket> in1sock,
50  std::shared_ptr<TTAMachine::Socket> in2sock)
51  : BlocksFU::BlocksFU(mach, name, sources, in1sock, in2sock) {
52  // Function unit and ports
53  mul = this->fu;
54 
55  // HW ops
56  HWOperation* mulOp = CreateHWOp("mul", 3);
57  ops.push_back(mulOp);
58  HWOperation* copyOp = CreateHWOp("copy", 2);
59  ops.push_back(copyOp);
60 }
61 
62 /**
63  * Constructor BlocksMULPair
64  *
65  * @param mach The TTA machine where the MUL pair needs to be added.
66  * @param name The name of the MUL pair.
67  * @param sources A list of sources that are attached to this unit's input.
68  * @param usesOut0 A boolean that indicates whether output port 0 of the FU is
69  * used in the Blocks.
70  * @param usesOut1 A boolean that indicates whether output port 1 of the FU is
71  * used in the Blocks.
72  */
74  TTAMachine::Machine& mach, const std::string& name,
75  std::list<std::string> sources, bool usesOut0, bool usesOut1)
76  : sources(sources) {
77  in1sock = std::make_shared<TTAMachine::Socket>(name + "_in1t");
78  in2sock = std::make_shared<TTAMachine::Socket>(name + "_in2");
79  mach.addSocket(*(in1sock.get()));
80  mach.addSocket(*(in2sock.get()));
81  if (usesOut0)
82  mul0.reset(
83  new BlocksMUL(mach, name + "_out0", sources, in1sock, in2sock));
84  if (usesOut1)
85  mul1.reset(
86  new BlocksMUL(mach, name + "_out1", sources, in1sock, in2sock));
87 }
88 
89 /**
90  * Creates a hardware operation.
91  *
92  * @param name The name of the hardware operation. This needs to exactly match
93  * the name in OSEd.
94  * @param numOfOperands The number of operands that this hardware operation
95  * requires.
96  */
98 BlocksMUL::CreateHWOp(const std::string& name, int numOfOperands) {
99  HWOperation* op = new HWOperation(name, *mul);
100  BindPorts(op, numOfOperands);
101  ConfigurePipeline(op->pipeline(), numOfOperands);
102  return op;
103 }
104 
105 /**
106  * Bind the operation's operands to FU ports.
107  *
108  * @param hwOp A pointer to the hardware operation of which the operands need
109  * to be binded to FU ports.
110  * @param numOfOperands The number of operands of the given hwOp.
111  */
112 void
113 BlocksMUL::BindPorts(HWOperation* hwOp, int numOfOperands) {
114  if (numOfOperands == 2) {
115  hwOp->bindPort(1, *in1);
116  hwOp->bindPort(2, *out);
117  } else if (numOfOperands == 3) {
118  hwOp->bindPort(1, *in1);
119  hwOp->bindPort(2, *in2);
120  hwOp->bindPort(3, *out);
121  } else {
122  // Currently no operation known that uses a different numbers of
123  // operands.
124  assert(
125  false &&
126  "Trying to add an MUL operation with a different number of "
127  "operands than 2 or 3.");
128  }
129 }
130 
131 /**
132  * Configure the operation pipeline.
133  *
134  * @param pipeline A pointer to the execution pipeline of the operation of
135  * which the pipeline needs to be configured.
136  * @param numOfOperands The number of operands of the given hwOp.
137  */
138 void
139 BlocksMUL::ConfigurePipeline(ExecutionPipeline* pipeline, int numOfOperands) {
140  if (numOfOperands < 3) {
141  pipeline->addPortRead(1, 0, 1);
142  pipeline->addPortWrite(2, 0, 1);
143  } else {
144  pipeline->addPortRead(1, 0, 1);
145  pipeline->addPortRead(2, 0, 1);
146  pipeline->addPortWrite(3, 0, 1);
147  }
148 }
BlocksFU::ops
std::vector< TTAMachine::HWOperation * > ops
Definition: BlocksFU.hh:59
BlocksMUL
Definition: BlocksMUL.hh:39
BlocksFU::in1
TTAMachine::FUPort * in1
Definition: BlocksFU.hh:61
BlocksMULPair::BlocksMULPair
BlocksMULPair(TTAMachine::Machine &mach, const std::string &name, std::list< std::string > sources, bool usesOut0, bool usesOut1)
Definition: BlocksMUL.cc:73
TTAMachine::HWOperation
Definition: HWOperation.hh:52
TTAMachine::HWOperation::bindPort
virtual void bindPort(int operand, const FUPort &port)
Definition: HWOperation.cc:269
BlocksFU::fu
TTAMachine::FunctionUnit * fu
Definition: BlocksFU.hh:60
BlocksMUL::BindPorts
void BindPorts(TTAMachine::HWOperation *hwOp, int numOfOperands)
Definition: BlocksMUL.cc:113
BlocksMUL::CreateHWOp
TTAMachine::HWOperation * CreateHWOp(const std::string &name, int numOfOperands)
Definition: BlocksMUL.cc:98
assert
#define assert(condition)
Definition: Application.hh:86
BlocksMUL::mul
TTAMachine::FunctionUnit * mul
Definition: BlocksMUL.hh:41
BlocksMULPair::mul0
std::unique_ptr< BlocksMUL > mul0
Definition: BlocksMUL.hh:70
BlocksMUL::ConfigurePipeline
void ConfigurePipeline(TTAMachine::ExecutionPipeline *pipeline, int numOfOperands)
Definition: BlocksMUL.cc:139
BlocksFU::out
TTAMachine::FUPort * out
Definition: BlocksFU.hh:63
BlocksMUL.hh
BlocksMULPair::mul1
std::unique_ptr< BlocksMUL > mul1
Definition: BlocksMUL.hh:71
TTAMachine::ExecutionPipeline::addPortRead
void addPortRead(int operand, int start, int duration)
Definition: ExecutionPipeline.cc:141
BlocksMULPair::in2sock
std::shared_ptr< TTAMachine::Socket > in2sock
Definition: BlocksMUL.hh:73
BlocksMUL::BlocksMUL
BlocksMUL(TTAMachine::Machine &mach, const std::string &name, std::list< std::string > sources, std::shared_ptr< TTAMachine::Socket > in1sock, std::shared_ptr< TTAMachine::Socket > in2sock)
Definition: BlocksMUL.cc:47
BlocksFU
Definition: BlocksFU.hh:43
BlocksFU::name
std::string name
Definition: BlocksFU.hh:68
TTAMachine::HWOperation::pipeline
ExecutionPipeline * pipeline() const
Definition: HWOperation.cc:201
TTAMachine::ExecutionPipeline
Definition: ExecutionPipeline.hh:55
TTAMachine::ExecutionPipeline::addPortWrite
void addPortWrite(int operand, int start, int duration)
Definition: ExecutionPipeline.cc:167
BlocksFU::in2
TTAMachine::FUPort * in2
Definition: BlocksFU.hh:62
TTAMachine
Definition: Assembler.hh:48
BlocksMULPair::in1sock
std::shared_ptr< TTAMachine::Socket > in1sock
Definition: BlocksMUL.hh:72
BlocksMULPair::sources
std::list< std::string > sources
Definition: BlocksMUL.hh:74
TTAMachine::Machine::addSocket
virtual void addSocket(Socket &socket)
Definition: Machine.cc:157
TTAMachine::Machine
Definition: Machine.hh:73