byteman  1.3 (Build #225)
Bitstream relocation and manipulation tool
inlineFAR.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 XCAP_IncrementFAR_BlockType0_new(int slrID, int &blockType, int &globalRowAddress, int &columnAddress, int &minorAddress)
18 {
19  uint8_t resourceLetter = (uint8_t)resourceString[globalRowAddress][columnAddress];
20  minorAddress++;
21  if(minorAddress == LUT_numberOfFramesForResourceLetter[resourceLetter]){
22  minorAddress = 0;
23  columnAddress++;
24  if(columnAddress == numberOfCols[0]){
25  columnAddress = 0;
26  if(globalRowAddress == SLRinfo[slrID].toRow){
27  globalRowAddress = SLRinfo[slrID].fromRow;
28  blockType++;
29  } else {
30  globalRowAddress++;
31  }
32  }
33  }
34 }
35 
36 inline void XCAP_IncrementFAR_BlockType0_old(int slrID, int &blockType, int &globalRowAddress, int &columnAddress, int &minorAddress)
37 {
38  uint8_t resourceLetter = (uint8_t)resourceString[globalRowAddress][columnAddress];
39  minorAddress++;
40  if(minorAddress == LUT_numberOfFramesForResourceLetter[resourceLetter]){
41  minorAddress = 0;
42  columnAddress++;
43  if(columnAddress == numberOfCols[globalRowAddress]){
44  columnAddress = 0;
45  bool isInTopHalf = (globalRowAddress >= (SLRinfo[slrID].fromRow + SLRinfo[slrID].rowsInBottomHalf));
46  if(isInTopHalf){
47  bool isAtTheTopTop = (globalRowAddress == (SLRinfo[slrID].toRow));
48  if(isAtTheTopTop){
49  bool hasNoBottomHalf = (SLRinfo[slrID].rowsInBottomHalf == 0);
50  if(hasNoBottomHalf){ // go to blockram contents
51  globalRowAddress = SLRinfo[slrID].fromRow;
52  blockType++;
53  } else { //go to bottom half
54  globalRowAddress = SLRinfo[slrID].fromRow + SLRinfo[slrID].rowsInBottomHalf - 1;
55  }
56  } else {
57  globalRowAddress++;
58  }
59  } else { //is in bottom half
60  bool isAtTheBottomBottom = (globalRowAddress == (SLRinfo[slrID].fromRow));
61  if(isAtTheBottomBottom){
62  globalRowAddress = SLRinfo[slrID].fromRow + SLRinfo[slrID].rowsInBottomHalf;
63  blockType++;
64  } else {
65  globalRowAddress--;
66  }
67  }
68  }
69  }
70 }
71 
72 inline void XCAP_IncrementFAR_BlockType0(int slrID, int &blockType, int &globalRowAddress, int &columnAddress, int &minorAddress)
73 {
74  if(FAR_ENABLE_TOP_BOTTOM_BIT == 0){// US and newer devices
75  XCAP_IncrementFAR_BlockType0_new(slrID, blockType, globalRowAddress, columnAddress, minorAddress);
76  } else {// Series 7 and older devices
77  XCAP_IncrementFAR_BlockType0_old(slrID, blockType, globalRowAddress, columnAddress, minorAddress);
78  }
79 }
80 
81 inline void XCAP_IncrementFAR_BlockType1_new(int slrID, int &blockType, int &globalRowAddress, int &columnAddress, int &minorAddress)
82 {
83  minorAddress++;
84  if((columnAddress == numberOfBRAMCols[0])?(minorAddress == EXTRA_FRAMES_PER_ROW):(minorAddress == FRAMES_PER_BRAM_CONTENT_COLUMN)){
85  minorAddress = 0;
86  columnAddress++;
87  if(columnAddress == (numberOfBRAMCols[0] + 1)){
88  columnAddress = 0;
89  if(globalRowAddress == SLRinfo[slrID].toRow){
90  globalRowAddress = SLRinfo[slrID].fromRow;
91  blockType++;
92  } else {
93  globalRowAddress++;
94  }
95  }
96  }
97 }
98 
99 inline void XCAP_IncrementFAR_BlockType1_old(int slrID, int &blockType, int &globalRowAddress, int &columnAddress, int &minorAddress)
100 {
101  minorAddress++;
102  if((columnAddress == numberOfBRAMCols[globalRowAddress])?(minorAddress == EXTRA_FRAMES_PER_ROW):(minorAddress == FRAMES_PER_BRAM_CONTENT_COLUMN)){
103  minorAddress = 0;
104  columnAddress++;
105  if(columnAddress == (numberOfBRAMCols[globalRowAddress] + 1)){
106  columnAddress = 0;
107 
108  bool isInTopHalf = (globalRowAddress >= (SLRinfo[slrID].fromRow + SLRinfo[slrID].rowsInBottomHalf));
109  if(isInTopHalf){
110  bool isAtTheTopTop = (globalRowAddress == (SLRinfo[slrID].toRow));
111  if(isAtTheTopTop){
112  bool hasNoBottomHalf = (SLRinfo[slrID].rowsInBottomHalf == 0);
113  if(hasNoBottomHalf){ // go to next blocktype
114  globalRowAddress = SLRinfo[slrID].fromRow;
115  blockType++;
116  } else { //go to bottom half
117  globalRowAddress = SLRinfo[slrID].fromRow + SLRinfo[slrID].rowsInBottomHalf - 1;
118  }
119  } else {
120  globalRowAddress++;
121  }
122  } else { //is in bottom half
123  bool isAtTheBottomBottom = (globalRowAddress == (SLRinfo[slrID].fromRow));
124  if(isAtTheBottomBottom){
125  globalRowAddress = SLRinfo[slrID].fromRow + SLRinfo[slrID].rowsInBottomHalf;
126  blockType++;
127  } else {
128  globalRowAddress--;
129  }
130  }
131  }
132  }
133 }
134 
135 inline void XCAP_IncrementFAR_BlockType1(int slrID, int &blockType, int &globalRowAddress, int &columnAddress, int &minorAddress)
136 {
137  if(FAR_ENABLE_TOP_BOTTOM_BIT == 0){// US and newer devices
138  XCAP_IncrementFAR_BlockType1_new(slrID, blockType, globalRowAddress, columnAddress, minorAddress);
139  } else {// Series 7 and older devices
140  XCAP_IncrementFAR_BlockType1_old(slrID, blockType, globalRowAddress, columnAddress, minorAddress);
141  }
142 }
143 
144 inline void XCAP_IncrementFAR(int slrID, int &blockType, int &globalRowAddress, int &columnAddress, int &minorAddress)
145 {
146  if(BLOCKTYPE_LOGIC == blockType){
147  XCAP_IncrementFAR_BlockType0(slrID, blockType, globalRowAddress, columnAddress, minorAddress);
148  } else if(BLOCKTYPE_BLOCKRAM == blockType){
149  XCAP_IncrementFAR_BlockType1(slrID, blockType, globalRowAddress, columnAddress, minorAddress);
150  }
151 }
152 
153 inline void XCAP_parseFAR(int farValue, int slr, int &blockType, int &globalRowAddress, int &columnAddress, int &minorAddress)
154 {
155  blockType = (farValue >> FAR_BLOCKTYPE_SHIFT) & FAR_BLOCKTYPE_MASK;
156  if(FAR_ENABLE_TOP_BOTTOM_BIT == 0){// US and newer devices
157  globalRowAddress = SLRinfo[slr].fromRow;
158  globalRowAddress += (farValue >> FAR_ROWADDRESS_SHIFT) & FAR_ROWADDRESS_MASK;
159  } else {//Series 7 and older devices
160  int bottomAndNotTop = (farValue >> FAR_TOP_BOTTOM_BIT_SHIFT) & 0x1;
161  globalRowAddress = SLRinfo[slr].fromRow;
162  globalRowAddress += SLRinfo[slr].rowsInBottomHalf;
163  int rowAddress = (farValue >> FAR_ROWADDRESS_SHIFT) & FAR_ROWADDRESS_MASK;
164  if(bottomAndNotTop){ //bottom
165  globalRowAddress -= (1 + rowAddress);
166  } else { //top
167  globalRowAddress += rowAddress;
168  }
169  }
170  columnAddress = (farValue >> FAR_COLUMNADDRESS_SHIFT) & FAR_COLUMNADDRESS_MASK;
171  minorAddress = (farValue >> FAR_MINORADDRESS_SHIFT) & FAR_MINORADDRESS_MASK;
172 }
173 
174 inline uint32_t XCAP_getFAR(int slr, int blockType, int globalRowAddress, int columnAddress, int minorAddress)
175 {
176  if(FAR_ENABLE_TOP_BOTTOM_BIT == 0){// US and newer devices
177  int rowAddress = (globalRowAddress - SLRinfo[slr].fromRow);
178  return (((blockType & FAR_BLOCKTYPE_MASK) << FAR_BLOCKTYPE_SHIFT) | ((rowAddress & FAR_ROWADDRESS_MASK) << FAR_ROWADDRESS_SHIFT) | ((columnAddress & FAR_COLUMNADDRESS_MASK) << FAR_COLUMNADDRESS_SHIFT) | ((minorAddress & FAR_MINORADDRESS_MASK) << FAR_MINORADDRESS_SHIFT));
179  }
180  //else Series 7 and older devices
181  int rowAddress = (globalRowAddress - SLRinfo[slr].fromRow);
182  int bottomAndNotTop;
183  if(rowAddress < SLRinfo[slr].rowsInBottomHalf) {
184  rowAddress = SLRinfo[slr].rowsInBottomHalf - 1 - rowAddress;
185  bottomAndNotTop = 1; // bottom
186  } else {
187  rowAddress -= SLRinfo[slr].rowsInBottomHalf;
188  bottomAndNotTop = 0; //top
189  }
190  return (((blockType & FAR_BLOCKTYPE_MASK) << FAR_BLOCKTYPE_SHIFT) | ((bottomAndNotTop & 0x1) << FAR_TOP_BOTTOM_BIT_SHIFT) | ((rowAddress & FAR_ROWADDRESS_MASK) << FAR_ROWADDRESS_SHIFT) | ((columnAddress & FAR_COLUMNADDRESS_MASK) << FAR_COLUMNADDRESS_SHIFT) | ((minorAddress & FAR_MINORADDRESS_MASK) << FAR_MINORADDRESS_SHIFT));
191 }
192 
194 inline uint32_t XCAP_getFarFarInstruction()
195 {
196  return XCAP_getFAR(0, 7, 63, 0, 0);
197 }
void XCAP_IncrementFAR_BlockType1(int slrID, int &blockType, int &globalRowAddress, int &columnAddress, int &minorAddress)
Definition: inlineFAR.h:135
void XCAP_IncrementFAR_BlockType0(int slrID, int &blockType, int &globalRowAddress, int &columnAddress, int &minorAddress)
Definition: inlineFAR.h:72
uint32_t XCAP_getFAR(int slr, int blockType, int globalRowAddress, int columnAddress, int minorAddress)
Definition: inlineFAR.h:174
uint32_t XCAP_getFarFarInstruction()
Generate and return the encoding for a Far FAR instruction.
Definition: inlineFAR.h:194
void XCAP_IncrementFAR_BlockType0_old(int slrID, int &blockType, int &globalRowAddress, int &columnAddress, int &minorAddress)
Definition: inlineFAR.h:36
void XCAP_IncrementFAR_BlockType1_new(int slrID, int &blockType, int &globalRowAddress, int &columnAddress, int &minorAddress)
Definition: inlineFAR.h:81
void XCAP_parseFAR(int farValue, int slr, int &blockType, int &globalRowAddress, int &columnAddress, int &minorAddress)
Definition: inlineFAR.h:153
void XCAP_IncrementFAR(int slrID, int &blockType, int &globalRowAddress, int &columnAddress, int &minorAddress)
Definition: inlineFAR.h:144
void XCAP_IncrementFAR_BlockType0_new(int slrID, int &blockType, int &globalRowAddress, int &columnAddress, int &minorAddress)
Definition: inlineFAR.h:17
void XCAP_IncrementFAR_BlockType1_old(int slrID, int &blockType, int &globalRowAddress, int &columnAddress, int &minorAddress)
Definition: inlineFAR.h:99