OpenASIP 2.2
Loading...
Searching...
No Matches
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
InstructionDictionary Class Reference
Inheritance diagram for InstructionDictionary:
Inheritance graph
Collaboration diagram for InstructionDictionary:
Collaboration graph

Public Member Functions

 InstructionDictionary ()
 
virtual InstructionBitVectorcompress (const std::string &programName)
 
virtual void generateDecompressor (std::ostream &stream, TCEString entityStr)
 
virtual void printDescription (std::ostream &stream)
 
- Public Member Functions inherited from CodeCompressorPlugin
virtual ~CodeCompressorPlugin ()
 
void setParameters (ParameterTable parameters)
 
void setPrograms (std::map< std::string, TPEF::Binary * > &programs)
 
void setMachine (const TTAMachine::Machine &machine)
 
void setBEM (const BinaryEncoding &bem)
 
const BinaryEncodingbinaryEncoding () const
 
const TTAMachine::Machinemachine () const
 
unsigned int memoryAddress (const TTAProgram::Instruction &instruction) const
 
TTAProgram::ProgramcurrentProgram () const
 
int imemMauWidth () const
 
InstructionBitVectorbemInstructionBits (const TTAProgram::Instruction &)
 

Private Types

typedef std::map< BitVector, unsigned int > Dictionary
 Map type for dictionary.
 

Private Member Functions

void createDictionary ()
 
void addToDictionary (const BitVector &instructionBits)
 
void updateDictionary (const Program &program)
 
void addInstructions ()
 

Private Attributes

Dictionary dictionary_
 The dictionary.
 
bool compatibilityProgDone_
 Indicates whether the compatibility program is in dictionary.
 
bool dictionaryCreated_
 Indicates whether the whole dictionary has been created.
 

Additional Inherited Members

- Public Types inherited from CodeCompressorPlugin
typedef std::vector< ParameterParameterTable
 Table for passing plugin parameters.
 
- Protected Types inherited from CodeCompressorPlugin
typedef std::map< std::string, TPEF::Binary * > TPEFMap
 Map type for handling programs.
 
- Protected Member Functions inherited from CodeCompressorPlugin
 CodeCompressorPlugin ()
 
InstructionBitVectorbemBits (const TTAProgram::Program &program)
 
int moveSlotCount () const
 
int moveSlotWidth (int index) const
 
int firstMoveSlotIndex () const
 
void startNewProgram (const std::string &programName)
 
void addInstruction (const TTAProgram::Instruction &instruction, InstructionBitVector *bits)
 
void setInstructionToStartAtBeginningOfMAU (const TTAProgram::Instruction &instruction)
 
void setAllInstructionsToStartAtBeginningOfMAU ()
 
InstructionBitVectorprogramBits () const
 
bool hasParameter (const std::string &paramName) const
 
std::string parameterValue (const std::string &paramName) const
 
void setImemWidth (int mau, int widthInMaus=1)
 
int numberOfPrograms () const
 
TPEFMap::const_iterator programElement (int index) const
 
std::string indentation (int level)
 

Detailed Description

Implements a simple instruction based dictionary compression scheme.

Definition at line 78 of file InstructionDictionary.cc.

Member Typedef Documentation

◆ Dictionary

typedef std::map<BitVector, unsigned int> InstructionDictionary::Dictionary
private

Map type for dictionary.

Definition at line 251 of file InstructionDictionary.cc.

Constructor & Destructor Documentation

◆ InstructionDictionary()

InstructionDictionary::InstructionDictionary ( )
inline

The constructor.

Definition at line 84 of file InstructionDictionary.cc.

84 :
86 dictionaryCreated_(false) {
87 }
bool dictionaryCreated_
Indicates whether the whole dictionary has been created.
bool compatibilityProgDone_
Indicates whether the compatibility program is in dictionary.

Member Function Documentation

◆ addInstructions()

void InstructionDictionary::addInstructions ( )
inlineprivate

Adds the compressed instructions to the program.

Definition at line 315 of file InstructionDictionary.cc.

315 {
316 Instruction* instruction = &currentProgram().firstInstruction();
317 while (instruction != &NullInstruction::instance()) {
319 unsigned int code = MapTools::valueForKey<unsigned int>(
321 InstructionBitVector* compressedInstruction =
323 static_cast<BitVector*>(compressedInstruction)->pushBack(
324 code, static_cast<int>(
326 addInstruction(*instruction, compressedInstruction);
327 instruction = &currentProgram().nextInstruction(*instruction);
328
329 }
330 }
InstructionBitVector * bemBits(const TTAProgram::Program &program)
void addInstruction(const TTAProgram::Instruction &instruction, InstructionBitVector *bits)
TTAProgram::Program & currentProgram() const
InstructionBitVector * bemInstructionBits(const TTAProgram::Instruction &)
Dictionary dictionary_
The dictionary.
static KeyType keyForValue(const MapType &aMap, const ValueType &aValue)
static int requiredBits(unsigned long int number)
static NullInstruction & instance()
Instruction & nextInstruction(const Instruction &) const
Definition Program.cc:403
Instruction & firstInstruction() const
Definition Program.cc:353

References CodeCompressorPlugin::addInstruction(), CodeCompressorPlugin::bemBits(), CodeCompressorPlugin::bemInstructionBits(), CodeCompressorPlugin::currentProgram(), dictionary_, TTAProgram::Program::firstInstruction(), TTAProgram::NullInstruction::instance(), MapTools::keyForValue(), TTAProgram::Program::nextInstruction(), and MathTools::requiredBits().

Referenced by compress().

Here is the call graph for this function:

◆ addToDictionary()

void InstructionDictionary::addToDictionary ( const BitVector instructionBits)
inlineprivate

Adds the given instruction bits to the dictionary.

Parameters
instructionBitsThe instruction bits to add.

Definition at line 287 of file InstructionDictionary.cc.

287 {
288 if (!MapTools::containsKey(dictionary_, instructionBits)) {
289 unsigned int code = dictionary_.size();
290 dictionary_.insert(
291 std::pair<BitVector, unsigned int>(instructionBits, code));
292 }
293 }
static bool containsKey(const MapType &aMap, const KeyType &aKey)

References MapTools::containsKey(), and dictionary_.

Referenced by updateDictionary().

Here is the call graph for this function:

◆ compress()

virtual InstructionBitVector * InstructionDictionary::compress ( const std::string &  programName)
inlinevirtual

Creates the compressed code and returns the bit vector of it.

Implements CodeCompressorPlugin.

Definition at line 94 of file InstructionDictionary.cc.

94 {
95 try {
101 Binary* compatibilityBin = validator.profile(results);
102 TPEFProgramFactory factory(*compatibilityBin, machine());
103 Program* compatibilityProg = factory.build();
104 updateDictionary(*compatibilityProg);
105 delete compatibilityBin;
106 delete compatibilityProg;
108 }
109 } catch (const Exception& e) {
110 string errorMsg = "Unable to ensure programmability: " +
111 e.errorMessage();
112 throw InvalidData(
113 __FILE__, __LINE__, __func__, errorMsg);
114 }
115 if (!dictionaryCreated_) {
117
118 unsigned int compressedImemWidth =
120 assert(compressedImemWidth <= sizeof(long long unsigned int)*8
121 && "Compressed instruction width is too big");
122
123 // fix imem width (mau == instruction width)
124 setImemWidth(compressedImemWidth);
125 }
126 startNewProgram(programName);
129 return programBits();
130 }
#define __func__
#define assert(condition)
const string ENSURE_PROGRAMMABILITY
const string YES
void setImemWidth(int mau, int widthInMaus=1)
void startNewProgram(const std::string &programName)
const TTAMachine::Machine & machine() const
std::string parameterValue(const std::string &paramName) const
bool hasParameter(const std::string &paramName) const
InstructionBitVector * programBits() const
std::string errorMessage() const
Definition Exception.cc:123
void updateDictionary(const Program &program)

References __func__, addInstructions(), assert, TTAProgram::TPEFProgramFactory::build(), compatibilityProgDone_, createDictionary(), dictionary_, dictionaryCreated_, ENSURE_PROGRAMMABILITY, Exception::errorMessage(), CodeCompressorPlugin::hasParameter(), CodeCompressorPlugin::machine(), CodeCompressorPlugin::parameterValue(), ProgrammabilityValidator::profile(), CodeCompressorPlugin::programBits(), MathTools::requiredBits(), CodeCompressorPlugin::setAllInstructionsToStartAtBeginningOfMAU(), CodeCompressorPlugin::setImemWidth(), CodeCompressorPlugin::startNewProgram(), updateDictionary(), and YES.

Here is the call graph for this function:

◆ createDictionary()

void InstructionDictionary::createDictionary ( )
inlineprivate

Creates the whole dictionary

Definition at line 258 of file InstructionDictionary.cc.

258 {
259 for (int i = 0; i < numberOfPrograms(); i++) {
260 TPEFMap::const_iterator iter = programElement(i);
261 string name = iter->first;
262 startNewProgram(name);
265 }
266 dictionaryCreated_ = true;
267 if (Application::verboseLevel() > 0 && dictionary_.size() > 0) {
268 std::size_t keyWidth =
270 std::size_t entrySize = binaryEncoding().width();
271 std::size_t entries = dictionary_.size();
273 << (boost::format(
274 "dictionary width: %d bits, entries: %d, "
275 "total size: %d bits (%d bytes)\n" )
276 % keyWidth % entries % (entries * entrySize)
277 % std::size_t(std::ceil(entries * entrySize / 8.0))).str();
278 }
279 }
static int verboseLevel()
static std::ostream & logStream()
virtual int width(const TCEString &templateName) const
TPEFMap::const_iterator programElement(int index) const
const BinaryEncoding & binaryEncoding() const

References CodeCompressorPlugin::binaryEncoding(), CodeCompressorPlugin::currentProgram(), dictionary_, dictionaryCreated_, Application::logStream(), CodeCompressorPlugin::numberOfPrograms(), CodeCompressorPlugin::programElement(), MathTools::requiredBits(), CodeCompressorPlugin::setAllInstructionsToStartAtBeginningOfMAU(), CodeCompressorPlugin::startNewProgram(), updateDictionary(), Application::verboseLevel(), and BinaryEncoding::width().

Referenced by compress().

Here is the call graph for this function:

◆ generateDecompressor()

virtual void InstructionDictionary::generateDecompressor ( std::ostream &  stream,
TCEString  entityStr 
)
inlinevirtual

Generates the decompressor in VHDL.

Note! The programs must be compressed by compress method before calling this method.

Parameters
streamThe stream to write.

Implements CodeCompressorPlugin.

Definition at line 141 of file InstructionDictionary.cc.

141 {
142
143 stream << "library ieee;" << endl;
144 stream << "use ieee.std_logic_1164.all;" << endl;
145 stream << "use ieee.std_logic_arith.all;" << endl << endl;
146
147 stream << "package " << entityStr << "_dict_init is" << endl << endl;
148 stream << indentation(1)
149 << "type std_logic_dict_matrix is array (natural range <>) "
150 << "of std_logic_vector(" << binaryEncoding().width() - 1
151 << " downto 0);" << endl << endl;
152
153 // write the dictionary contents
154 stream << indentation(1)
155 << "constant dict_init : std_logic_dict_matrix := (" << endl;
156 for (unsigned int i = 0; i < dictionary_.size(); i++) {
158 dictionary_, i);
159 AsciiImageWriter writer(instr, instr.size());
160 stream << indentation(2) << "\"";
161 writer.writeImage(stream);
162 stream << "\"";
163 if (i+1 < dictionary_.size()) {
164 stream << "," << endl;
165 } else {
166 stream << ");" << endl;
167 }
168 }
169 stream << "end " << entityStr << "_dict_init;" << endl << endl;
170
171 stream << "library ieee;" << endl;
172 stream << "use ieee.std_logic_1164.all;" << endl;
173 stream << "use ieee.std_logic_arith.all;" << endl;
174 stream << "use work." << entityStr << "_globals.all;" << endl;
175 stream << "use work." << entityStr << "_dict_init.all;" << endl;
176 stream << "use work." << entityStr << "_imem_mau.all;" << endl << endl;
177
178 // write the decompressor entity
179 stream << "entity " << entityStr << "_decompressor is" << endl;
180 stream << indentation(1) << "port (" << endl;
181 stream << indentation(2) << "fetch_en : out std_logic;" << endl;
182 stream << indentation(2) << "lock : in std_logic;" << endl;
183 stream << indentation(2)
184 << "fetchblock : in std_logic_vector("
185 << "IMEMWIDTHINMAUS*IMEMMAUWIDTH-1 downto 0);" << endl;
186 stream << indentation(2)
187 << "instructionword : out std_logic_vector("
188 << "INSTRUCTIONWIDTH-1 downto 0);" << endl;
189 stream << indentation(2) << "glock : out std_logic;" << endl;
190 stream << indentation(2) << "lock_r : in std_logic;" << endl;
191 stream << indentation(2) << "clk : in std_logic;" << endl;
192 stream << indentation(2) << "rstx : in std_logic);" << endl << endl;
193 stream << "end " << entityStr << "_decompressor;" << endl << endl;
194
195 stream << "architecture simple_dict of " << entityStr
196 << "_decompressor is" << endl << endl;
197
198 stream << indentation(1)
199 << "subtype dict_index is integer range 0 to "
200 << "dict_init'length-1;" << endl;
201 stream << indentation(1) << "signal dict_line : dict_index;" << endl;
202 stream << indentation(1)
203 << "constant dict : std_logic_dict_matrix("
204 << "0 to dict_init'length-1) := dict_init;" << endl << endl;
205
206 stream << "begin" << endl << endl;
207 stream << indentation(1) << "glock <= lock;" << endl;
208 stream << indentation(1) << "fetch_en <= not lock_r;" << endl;
209 stream << indentation(1)
210 << "dict_line <= conv_integer(unsigned(fetchblock("
211 << "fetchblock'length-1 downto fetchblock'length-"
213 << ")));" << endl << endl;
214
215 stream << indentation(1) << "process (dict_line)" << endl;
216 stream << indentation(1) << "begin" << endl;
217 stream << indentation(2) << "instructionword <= dict(dict_line);"
218 << endl;
219 stream << indentation(1) << "end process;" << endl << endl;
220 stream << "end simple_dict;" << endl;
221 }
std::string indentation(int level)

References CodeCompressorPlugin::binaryEncoding(), dictionary_, CodeCompressorPlugin::indentation(), MapTools::keyForValue(), MathTools::requiredBits(), BinaryEncoding::width(), and AsciiImageWriter::writeImage().

Here is the call graph for this function:

◆ printDescription()

virtual void InstructionDictionary::printDescription ( std::ostream &  stream)
inlinevirtual

Prints the description of the plugin to the given stream.

Parameters
streamThe stream.

Implements CodeCompressorPlugin.

Definition at line 230 of file InstructionDictionary.cc.

230 {
231 stream << "Generates the program image using instruction-based "
232 << "dictionary compression." << endl << endl
233 << "Warning! This compressor works correctly only when "
234 << "there is one instruction per MAU in the final program "
235 << "image. That is, the minimum addressable unit of the "
236 << "address space should be "
237 << "the same as the width of the compressed instructions or "
238 << "wider. Otherwise jump and call addresses are invalid in "
239 << "the code. This compressor creates the dictionary on the "
240 << "level of whole instruction." << endl << endl
241 << "Parameters accepted:" << endl
242 << "----------------------" << endl
243 << "ensure_programmability" << endl
244 << "If the value is 'yes', instructions that ensure "
245 << "programmability of the processor are added to the "
246 << "dictionary automatically." << endl;
247 }

◆ updateDictionary()

void InstructionDictionary::updateDictionary ( const Program program)
inlineprivate

Creates the dictionary.

Definition at line 300 of file InstructionDictionary.cc.

300 {
301 Instruction* instruction = &program.firstInstruction();
302 while (instruction != &NullInstruction::instance()) {
303 InstructionBitVector* instructionBits = bemInstructionBits(
304 *instruction);
305 addToDictionary(*instructionBits);
306 instruction = &program.nextInstruction(*instruction);
307 }
308 }
find Finds info of the inner loops in the program
void addToDictionary(const BitVector &instructionBits)

References addToDictionary(), CodeCompressorPlugin::bemInstructionBits(), TTAProgram::NullInstruction::instance(), and program.

Referenced by compress(), and createDictionary().

Here is the call graph for this function:

Member Data Documentation

◆ compatibilityProgDone_

bool InstructionDictionary::compatibilityProgDone_
private

Indicates whether the compatibility program is in dictionary.

Definition at line 337 of file InstructionDictionary.cc.

Referenced by compress().

◆ dictionary_

Dictionary InstructionDictionary::dictionary_
private

The dictionary.

Definition at line 335 of file InstructionDictionary.cc.

Referenced by addInstructions(), addToDictionary(), compress(), createDictionary(), and generateDecompressor().

◆ dictionaryCreated_

bool InstructionDictionary::dictionaryCreated_
private

Indicates whether the whole dictionary has been created.

Definition at line 339 of file InstructionDictionary.cc.

Referenced by compress(), and createDictionary().


The documentation for this class was generated from the following file: