OpenASIP 2.2
Loading...
Searching...
No Matches
BlocksALU.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 BlocksALU.cc
26 *
27 * This class resembles a single output in the Blocks CGRA architecture.
28 *
29 * @author Maarten Molendijk 2020 (m.j.molendijk@tue.nl)
30 * @author Kanishkan Vadivel 2021 (k.vadivel@tue.nl)
31 */
32
33#include "BlocksALU.hh"
34
35#include "ExecutionPipeline.hh"
36
37using namespace TTAMachine;
38/**
39 * Create BlocksALU with default instructions
40 *
41 * @param mach The TTA machine where the ALU needs to be added.
42 * @param name The name of the ALU.
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 alu = this->fu;
54
55 // HW ops
56 ops.push_back(CreateHWOp("add", 3));
57 ops.push_back(CreateHWOp("and", 3));
58 ops.push_back(CreateHWOp("eq", 3));
59 ops.push_back(CreateHWOp("ge", 3));
60 ops.push_back(CreateHWOp("geu", 3));
61 ops.push_back(CreateHWOp("gt", 3));
62 ops.push_back(CreateHWOp("gtu", 3));
63 ops.push_back(CreateHWOp("ior", 3));
64 ops.push_back(CreateHWOp("lt", 3));
65 ops.push_back(CreateHWOp("ltu", 3));
66 ops.push_back(CreateHWOp("ne", 3));
67 ops.push_back(CreateHWOp("not", 2));
68 ops.push_back(CreateHWOp("shl1_32", 2));
69 ops.push_back(CreateHWOp("shl4_32", 2));
70 ops.push_back(CreateHWOp("shr1_32", 2));
71 ops.push_back(CreateHWOp("shr4_32", 2));
72 ops.push_back(CreateHWOp("shru1_32", 2));
73 ops.push_back(CreateHWOp("shru4_32", 2));
74 ops.push_back(CreateHWOp("sub", 3));
75 ops.push_back(CreateHWOp("xor", 3));
76 ops.push_back(CreateHWOp("copy", 2));
77}
78
79/**
80 * Emulates second output port with copy of FU with input port sharing
81 *
82 * @param mach The TTA machine where the ALU pair needs to be added.
83 * @param name The name of the ALU pair.
84 * @param sources A list of sources that are attached to this unit's input.
85 * @param usesOut0 A boolean that indicates whether output port 0 of the FU is
86 * used in the CGRA.
87 * @param usesOut1 A boolean that indicates whether output port 1 of the FU is
88 * used in the CGRA.
89 */
91 TTAMachine::Machine& mach, const std::string& name,
92 std::list<std::string> sources, bool usesOut0, bool usesOut1)
93 : sources(sources) {
94 in1sock = std::make_shared<TTAMachine::Socket>(name + "_in1t");
95 in2sock = std::make_shared<TTAMachine::Socket>(name + "_in2");
96 mach.addSocket(*(in1sock.get()));
97 mach.addSocket(*(in2sock.get()));
98 if (usesOut0)
99 alu0.reset(
100 new BlocksALU(mach, name + "_out0", sources, in1sock, in2sock));
101 if (usesOut1)
102 alu1.reset(
103 new BlocksALU(mach, name + "_out1", sources, in1sock, in2sock));
104}
105
106/**
107 * Creates a hardware operation.
108 *
109 * @param name The name of the hardware operation. This needs to exactly match
110 * the name in OSEd.
111 * @param numOfOperands The number of operands that this hardware operation
112 * requires.
113 */
115BlocksALU::CreateHWOp(const std::string& name, int numOfOperands) {
116 HWOperation* op = new HWOperation(name, *alu);
117 BindPorts(op, numOfOperands);
118 ConfigurePipeline(op->pipeline(), numOfOperands);
119 return op;
120}
121
122/**
123 * Bind the operation's operands to FU ports.
124 *
125 * @param hwOp A pointer to the hardware operation of which the operands need
126 * to be binded to FU ports.
127 * @param numOfOperands The number of operands of the given hwOp.
128 */
129void
130BlocksALU::BindPorts(HWOperation* hwOp, int numOfOperands) {
131 if (numOfOperands == 2) {
132 hwOp->bindPort(1, *in1);
133 hwOp->bindPort(2, *out);
134 } else if (numOfOperands == 3) {
135 hwOp->bindPort(1, *in1);
136 hwOp->bindPort(2, *in2);
137 hwOp->bindPort(3, *out);
138 } else {
139 // Currently no operation known that uses a different numbers of
140 // operands.
141 assert(
142 false &&
143 "Trying to add an ALU operation with a different number of "
144 "operands than 2 or 3.");
145 }
146}
147
148/**
149 * Configure the operation pipeline.
150 *
151 * @param pipeline A pointer to the execution pipeline of the operation of
152 * which the pipeline needs to be configured.
153 * @param numOfOperands The number of operands of the given hwOp.
154 */
155void
156BlocksALU::ConfigurePipeline(ExecutionPipeline* pipeline, int numOfOperands) {
157 if (numOfOperands < 3) {
158 pipeline->addPortRead(1, 0, 1);
159 pipeline->addPortWrite(2, 0, 1);
160 } else {
161 pipeline->addPortRead(1, 0, 1);
162 pipeline->addPortRead(2, 0, 1);
163 pipeline->addPortWrite(3, 0, 1);
164 }
165}
#define assert(condition)
std::list< std::string > sources
Definition BlocksALU.hh:69
std::shared_ptr< TTAMachine::Socket > in2sock
Definition BlocksALU.hh:68
std::unique_ptr< BlocksALU > alu1
Definition BlocksALU.hh:66
BlocksALUPair(TTAMachine::Machine &mach, const std::string &name, std::list< std::string > sources, bool usesOut0, bool usesOut1)
Definition BlocksALU.cc:90
std::unique_ptr< BlocksALU > alu0
Definition BlocksALU.hh:65
std::shared_ptr< TTAMachine::Socket > in1sock
Definition BlocksALU.hh:67
BlocksALU(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 BlocksALU.cc:47
void ConfigurePipeline(TTAMachine::ExecutionPipeline *pipeline, int numOfOperands)
Definition BlocksALU.cc:156
TTAMachine::FunctionUnit * alu
Definition BlocksALU.hh:41
TTAMachine::HWOperation * CreateHWOp(const std::string &name, int numOfOperands)
Definition BlocksALU.cc:115
void BindPorts(TTAMachine::HWOperation *hwOp, int numOfOperands)
Definition BlocksALU.cc:130
TTAMachine::FUPort * out
Definition BlocksFU.hh:63
TTAMachine::FUPort * in1
Definition BlocksFU.hh:61
TTAMachine::FunctionUnit * fu
Definition BlocksFU.hh:60
std::string name
Definition BlocksFU.hh:68
std::vector< TTAMachine::HWOperation * > ops
Definition BlocksFU.hh:59
TTAMachine::FUPort * in2
Definition BlocksFU.hh:62
void addPortRead(int operand, int start, int duration)
void addPortWrite(int operand, int start, int duration)
ExecutionPipeline * pipeline() const
virtual void bindPort(int operand, const FUPort &port)
virtual void addSocket(Socket &socket)
Definition Machine.cc:157