OpenASIP  2.0
LEDataSection.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 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 DataSection.cc
26  *
27  * Non-inline definitions of DataSection class.
28  *
29  * @author Heikki Kultala 2014(hkultala-no.spam-cs.tut.fi)
30  * @author Pekka Jääskeläinen 2006 (pjaaskel-no.spam-cs.tut.fi)
31  *
32  * @note rating: yellow
33  */
34 
35 #include <cmath>
36 
37 #include "LEDataSection.hh"
38 #include "Application.hh"
39 #include "Swapper.hh"
40 #include "MathTools.hh"
41 
42 namespace TPEF {
43 
44 LEDataSection LEDataSection::proto_(true);
45 
46 /**
47  * Constructor.
48  *
49  * @param init true if registeration is wanted
50  */
52 
53  if (init) {
55  }
56 
57  unsetFlagVLen();
59 }
60 
61 /**
62  * Destructor.
63  */
65 }
66 
67 /**
68  * Returns section's type.
69  *
70  * @return Type of section.
71  */
74  return ST_LEDATA;
75 }
76 
77 /**
78  * Creates an instance of DataSection.
79  *
80  * @return Newly created section.
81  */
82 Section*
84 
85  return new LEDataSection(false);
86 }
87 
88 
89 /**
90  * Writes unsigned value to data section.
91  *
92  * Value is aligned to field as normal big endian value
93  * least significant bit is stored to last bit of last MAU.
94  *
95  * If we call writeValue(0, 4, 3) and MAU is 2bit
96  * start of data section will be 00 00 00 11.
97  *
98  * However the MAUs are stored in data section like this:
99  * 00000000|000000000|00000000|00000011 (one MAU per byte)
100  * MAU1 | MAU2 | MAU3 | MAU4
101  *
102  * @param index MAU offset to section where to we write value.
103  * @param numOfMAUs Number of MAUs that we use for storing value.
104  * @param value Value to write.
105  */
106 void
107 LEDataSection::writeValue(Word index, Word numOfMAUs, unsigned long value) {
108 
109  int mauInBytes = MAUsToBytes(1);
110 
111  MinimumAddressableUnit mauMask =
112  static_cast<unsigned int>(-1) >>
113  (sizeof(mauMask)*BYTE_BITWIDTH - aSpace()->MAU());
114 
115  int shiftCount = 0;
116  // start writing from beginning of area..
117  for (unsigned int i = 0; i < numOfMAUs; i++) {
118  int byteOffset = MAUsToBytes(index + i);
119 
120  MinimumAddressableUnit currentMAU = 0;
121 
122  if (shiftCount < static_cast<int>(sizeof(value)*BYTE_BITWIDTH)) {
123  // I tried math tools... system tests went broken :(
124  // ssooo... if it's not broken....
125  currentMAU = (value >> shiftCount) & mauMask;
126  }
127 
128  shiftCount += aSpace()->MAU();
129 
130  // write current MAU :)
131  for (int j = mauInBytes-1; j >= 0; j--) {
132  Byte currentByte = static_cast<Byte>(currentMAU);
133  setByte(byteOffset + j, currentByte);
134  currentMAU = currentMAU >> BYTE_BITWIDTH;
135  }
136  }
137 }
138 
139 /**
140  * Writes signed value to data section.
141  *
142  * For example, when we call writeValue(0, 4, -3) and MAU is 2bit
143  * start of data section will be 11 11 11 01.
144  *
145  * MAUs are stored in data section like this:
146  * 00000011 000000011 00000011 00000001 (one MAU per byte)
147  *
148  * If we call writeValue(0, 4, -3) and MAU is 10bit
149  * start of data section will be 1111111111 1111111111 1111111111 1111111101.
150  *
151  * However the MAUs are stored in data section like this:
152  *
153  * 00000011 11111111|00000011 11111111|00000011 11111111|00000011 11111101|
154  * MAU1 | MAU2 | MAU3 | MAU4 |
155  *
156  * @param index MAU offset to section where to we write value.
157  * @param numOfMAUs Number of MAUs that we use for storing value.
158  * @param value Value to write.
159  */
160 void
161 LEDataSection::writeValue(Word index, Word numOfMAUs, signed long value) {
162 
163  int mauInBytes = MAUsToBytes(1);
164 
165  MinimumAddressableUnit mauMask =
166  static_cast<unsigned int>(-1) >>
167  (sizeof(mauMask)*BYTE_BITWIDTH - aSpace()->MAU());
168 
169  int shiftCount = 0;
170  // start writing from beginning of area..
171  for (unsigned int i = 0; i < numOfMAUs; i++) {
172  int byteOffset = MAUsToBytes(index + i);
173 
174  MinimumAddressableUnit currentMAU =
175  static_cast<MinimumAddressableUnit>(~0);
176 
177  if (shiftCount < static_cast<int>(sizeof(value)*BYTE_BITWIDTH)) {
178  // I tried math tools... system tests went broken :(
179  // ssooo... if it's not broken....
180  currentMAU = (value >> shiftCount) & mauMask;
181  shiftCount += aSpace()->MAU();
182  }
183 
184  // write current MAU :)
185  for (int j = mauInBytes-1; j >= 0; j--) {
186  Byte currentByte = static_cast<Byte>(currentMAU);
187  setByte(byteOffset + j,currentByte);
188  currentMAU = currentMAU >> BYTE_BITWIDTH;
189  }
190  }
191 }
192 
193 }
LEDataSection.hh
TPEF::Section::aSpace
ASpaceElement * aSpace() const
TPEF::Section::unsetFlagVLen
void unsetFlagVLen()
TPEF::DataSection::setByte
virtual void setByte(Word offset, Byte aByte)
Definition: DataSection.cc:86
TPEF::LEDataSection::writeValue
virtual void writeValue(Word index, Word numOfMAUs, unsigned long value)
Definition: LEDataSection.cc:107
TPEF::LEDataSection::clone
virtual Section * clone() const
Definition: LEDataSection.cc:83
TPEF::DataSection
Definition: DataSection.hh:52
TPEF::ASpaceElement::MAU
Byte MAU() const
Byte
unsigned char Byte
Definition: BaseType.hh:116
TPEF::RawSection::MAUsToBytes
virtual Word MAUsToBytes(Word mauCount) const
Definition: Section.cc:320
TPEF::Section
Definition: Section.hh:64
TPEF::LEDataSection::proto_
static LEDataSection proto_
Prototype instance of section.
Definition: LEDataSection.hh:66
TPEF::Section::ST_LEDATA
@ ST_LEDATA
Initialized little endian data section.
Definition: Section.hh:82
TPEF::LEDataSection::~LEDataSection
virtual ~LEDataSection()
Definition: LEDataSection.cc:64
MinimumAddressableUnit
Word MinimumAddressableUnit
Type for storing a MAU (must be unsigned type!). This limits the maximum size of the simulated minimu...
Definition: BaseType.hh:184
Application.hh
TPEF::Section::unsetFlagNoBits
void unsetFlagNoBits()
TPEF::Section::registerSection
static void registerSection(const Section *section)
Definition: Section.cc:114
Swapper.hh
BYTE_BITWIDTH
const Byte BYTE_BITWIDTH
Definition: BaseType.hh:136
false
find Finds info of the inner loops in the false
Definition: InnerLoopFinder.cc:81
TPEF::LEDataSection::type
virtual SectionType type() const
Definition: LEDataSection.cc:73
TPEF::Section::SectionType
SectionType
Definition: Section.hh:69
MathTools.hh
TPEF::LEDataSection::LEDataSection
LEDataSection(bool init)
Definition: LEDataSection.cc:51
TPEF
Definition: Assembler.hh:43