byteman  1.3 (Build #225)
Bitstream relocation and manipulation tool
inlineChange.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2022 Kristiyan Manev (University of Manchester)
3  *
4  * Licensed under the Apache License, Version 2.0(the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *****************************************************************************/
16 
17 inline void ensureSelectedEndianness(Endianness newEndianness){
18  ensureInitializedBitstreamArrays();//initialize bitstream arrays before modifications
19  Endianness endiannessConvertion = Endian::diff(loadedBitstreamEndianness, newEndianness);
20  if(endiannessConvertion == Endianness::NATIVE)// if there is no actual convertion needed
21  return;
22  int bitstreamSize = bitstreamEnd - bitstreamBegin;
23 
24  if(endiannessConvertion == Endianness::BE)
25  for( int i = 0 ; i < bitstreamSize ; i++)
26  bitstreamBegin[i] = Endian::NativeToBigEndian32(bitstreamBegin[i]);
27 
28  if(endiannessConvertion == Endianness::LE)
29  for( int i = 0 ; i < bitstreamSize ; i++)
30  bitstreamBegin[i] = Endian::NativeToLittleEndian32(bitstreamBegin[i]);
31 
32  if(endiannessConvertion == Endianness::BE_BS)
33  for( int i = 0 ; i < bitstreamSize ; i++)
34  bitstreamBegin[i] = Endian::BitSwap32(Endian::NativeToBigEndian32(bitstreamBegin[i]));
35 
36  if(endiannessConvertion == Endianness::LE_BS)
37  for( int i = 0 ; i < bitstreamSize ; i++)
38  bitstreamBegin[i] = Endian::BitSwap32(Endian::NativeToLittleEndian32(bitstreamBegin[i]));
39 
40  loadedBitstreamEndianness = newEndianness;
41 }
42 
43 inline void setBitstreamWord(std::string params){
44  ensureInitializedBitstreamArrays();//initialize bitstream arrays before modifications
45  uint32_t r, y, c, b, m, w, mask, newVal;
46  str::parse::multipleUints(params, y, c, b, m, w, mask, newVal);
47  mask = Endian::NativeToAnyEndianness32(mask, loadedBitstreamEndianness);
48  newVal = Endian::NativeToAnyEndianness32(newVal, loadedBitstreamEndianness);
49  r = y / CLB_PER_CLOCK_REGION;
50  if(b == BLOCKTYPE_LOGIC){
51  bitstreamCLB[r][c][m*WORDS_PER_FRAME + w] = (mask & newVal) | ((mask^0xFFFFFFFF) & bitstreamCLB[r][c][m*WORDS_PER_FRAME + w]);
52  } else if(b == BLOCKTYPE_BLOCKRAM){
53  bitstreamBRAM[r][numberOfBRAMsBeforeCol[r][c]][m*WORDS_PER_FRAME + w] = (mask & newVal) | ((mask^0xFFFFFFFF) & bitstreamBRAM[r][numberOfBRAMsBeforeCol[r][c]][m*WORDS_PER_FRAME + w]);
54  }
55  bitstreamHasValidData = true;
56 }
57 
Endianness
< Endianness in byteman is represented not only by big/little endian, but also by potential bit swapp...
Definition: Endianness.h:47
@ BE_BS
Big endian with bit swaps inside each byte.
@ LE_BS
Little endian with bit swaps inside each byte.
@ LE
Little endian ("LE" instead of full-er name, so it does not conflict with linux's reserved endianess ...
@ BE
Big endian ("BE" instead of full-er name, so it does not conflict with linux's reserved endianess wor...
@ NATIVE
System native will always be the fastest endianess to process.
void setBitstreamWord(std::string params)
Definition: inlineChange.h:43
void ensureSelectedEndianness(Endianness newEndianness)
Definition: inlineChange.h:17
uint32_t NativeToLittleEndian32(uint32_t x)
Definition: Endianness.h:169
uint32_t NativeToAnyEndianness32(uint32_t x, Endianness e)
Definition: Endianness.h:246
uint32_t NativeToBigEndian32(uint32_t x)
Definition: Endianness.h:152
uint32_t BitSwap32(uint32_t x)
Definition: Endianness.h:220
Endianness diff(Endianness e1, Endianness e2)
Definition: Endianness.h:117
bool multipleUints(std::stringstream &ss)
Definition: parse.h:229