blob: 803bd39429325183ed2892c63d4b82c2dea888a8 [file] [log] [blame]
Paul Greenwooddc47e0a2019-11-01 16:22:57 -05001#include <hei_chip.hpp>
2#include <hei_includes.hpp>
3#include <register/hei_hardware_register.hpp>
4#include <register/hei_operator_register.hpp>
5#include <register/hei_register.hpp>
6
7#include <iomanip>
8#include <iostream>
9
10#define BITSTRING_BIT_WIDTH 16
11#define CONSTANT1 0x1458 // 1458
12#define CONSTANT2 0x5368 // 5468
13
14using namespace std;
15using namespace libhei;
16
17int main()
18{
19
20 Chip my_chip;
21 size_t constant1 = CONSTANT1;
22 size_t constant2 = CONSTANT2;
23
24 // Initializing two registers
25
26 cout << "\n\n\nInitializing two constant registers ";
27 cout << "(leftside & rightside):\n\n";
28
29 cout << "\nCreating BitString \"bsa\".\n";
30 BitStringBuffer bsa{BITSTRING_BIT_WIDTH};
31 cout << "Setting BitString \"bsa\" to: ";
32 cout << "0x" << setfill('0') << setw(BITSTRING_BIT_WIDTH / 4) << hex
33 << uppercase << constant1 << "\n";
34 bsa.setFieldRight(0, BITSTRING_BIT_WIDTH, constant1);
35
36 cout << "\nCreating BitString \"bsb\".\n";
37 BitStringBuffer bsb{BITSTRING_BIT_WIDTH};
38 cout << "Setting BitString \"bsb\" to: ";
39 cout << "0x" << setfill('0') << setw(BITSTRING_BIT_WIDTH / 4) << hex
40 << uppercase << constant2 << "\n\n";
41 bsb.setFieldRight(0, BITSTRING_BIT_WIDTH, constant2);
42
43 cout << "Creating \"leftside\" register from bsa.\n";
44 ConstantRegister leftside(bsa);
45 cout << "Creating \"rightside\" register from bsb.\n";
46 ConstantRegister rightside(bsb);
47
48 cout << "Leftside: ";
49 cout << "0x" << setfill('0') << setw(BITSTRING_BIT_WIDTH / 4) << hex
50 << leftside.getBitString(my_chip)->getFieldRight(0,
51 BITSTRING_BIT_WIDTH);
52
53 cout << " Rightside: ";
54 cout << "0x" << setfill('0') << setw(BITSTRING_BIT_WIDTH / 4) << hex
55 << rightside.getBitString(my_chip)->getFieldRight(0,
56 BITSTRING_BIT_WIDTH);
57 cout << "\n\n";
58
59 // Basic functional tests:
60 // AND
61 cout << "Instantiating my_and_register passing in two registers:\n";
62 cout << "AndRegister my_and_register(leftside, rightside);\n";
63 AndRegister my_and_register(leftside, rightside);
64 cout << "AND result: ";
65 cout << "0x" << setfill('0') << setw(BITSTRING_BIT_WIDTH / 4) << hex
66 << my_and_register.getBitString(my_chip)->getFieldRight(
67 0, BITSTRING_BIT_WIDTH)
68 << "\n\n";
69
70 // NOT
71 cout << "Instantiating my_not_register passing in my_and_register "
72 << "from above:\n";
73 cout << "NotRegister my_not_register(my_and_register);\n";
74 NotRegister my_not_register(my_and_register);
75 cout << "NOT result: ";
76 cout << "0x" << setfill('0') << setw(BITSTRING_BIT_WIDTH / 4) << hex
77 << my_not_register.getBitString(my_chip)->getFieldRight(
78 0, BITSTRING_BIT_WIDTH)
79 << "\n\n";
80
81 // Left Shift
82 cout << "Instantiating my_leftshift_register passing "
83 << "in my_not_register from above and a 4 directing i"
84 << "a left shift of 4 bits:\n";
85 cout << "LeftShiftRegister my_leftshift_register(my_not_register, 4);\n";
86 LeftShiftRegister my_leftshift_register(my_not_register, 4);
87 cout << "LeftShift result: ";
88 cout << "0x" << setfill('0') << setw(BITSTRING_BIT_WIDTH / 4) << hex
89 << my_leftshift_register.getBitString(my_chip)->getFieldRight(
90 0, BITSTRING_BIT_WIDTH)
91 << "\n\n";
92
93 // Right Shift
94 cout << "Instantiating my_rightshift_register passing in "
95 << "my_leftshift_register from above and a 4 directing "
96 << "a right shift of 4 bits:\n";
97 cout << "RightShiftRegister my_rightshift_register("
98 << "my_leftshift_register, 4);\n";
99 RightShiftRegister my_rightshift_register(my_leftshift_register, 4);
100 cout << "Right Shift result: ";
101 cout << "0x" << setfill('0') << setw(BITSTRING_BIT_WIDTH / 4) << hex
102 << my_rightshift_register.getBitString(my_chip)->getFieldRight(
103 0, BITSTRING_BIT_WIDTH)
104 << "\n\n";
105
106 // OR
107 cout << "Instantiating my_or_register passing in my_leftshift_register"
108 << " and my_rightshift_register from above:\n";
109 cout << "OrRegister my_or_register(my_leftshift_register,"
110 << "my_rightshift_register);\n";
111 OrRegister my_or_register(my_leftshift_register, my_rightshift_register);
112 cout << "OR result: ";
113 cout << "0x" << setfill('0') << setw(BITSTRING_BIT_WIDTH / 4) << hex
114 << my_or_register.getBitString(my_chip)->getFieldRight(
115 0, BITSTRING_BIT_WIDTH)
116 << "\n\n";
117
118 // = operator
119
120 // ConstantRegister
121 cout << "\nExercising operator \"=\" (assignment):\n\n";
122
123 cout << "Assigning leftside register to constreg1 register. (";
124 ConstantRegister constreg1 = leftside;
125 cout << "0x" << setfill('0') << setw(BITSTRING_BIT_WIDTH / 4) << hex
126 << constreg1.getBitString(my_chip)->getFieldRight(0,
127 BITSTRING_BIT_WIDTH)
128 << ")\n";
129 cout << "ConstantRegister constreg1 = leftside;\n";
130
131 cout << "Assigning rightside register to constreg2 register. (";
132 ConstantRegister constreg2 = rightside;
133 cout << "0x" << setfill('0') << setw(BITSTRING_BIT_WIDTH / 4) << hex
134 << constreg2.getBitString(my_chip)->getFieldRight(0,
135 BITSTRING_BIT_WIDTH)
136 << ")\n";
137 cout << "ConstantRegister constreg2 = rightside;\n";
138
139 // AndRegister
140 cout << "\nCreating and_register1 with leftside & rightside registers.\n";
141 cout << "AndRegister and_register1(leftside,rightside);\n";
142 AndRegister and_register1(leftside, rightside);
143 cout << "Creating and_register2 with the assignment operator (=).\n";
144 cout << "AndRegister and_register2 = and_register1;\n";
145 AndRegister and_register2 = and_register1;
146 cout << "and_register2 = ";
147 cout << "0x" << setfill('0') << setw(BITSTRING_BIT_WIDTH / 4) << hex
148 << and_register2.getBitString(my_chip)->getFieldRight(
149 0, BITSTRING_BIT_WIDTH)
150 << "\n";
151
152 // NotRegister
153 cout << "\nCreating not_register1 with leftside register.\n";
154 cout << "NotRegister not_register1(leftside);\n";
155 NotRegister not_register1(leftside);
156 cout << "Creating not_register2 with the assignment operator (=).\n";
157 cout << "NotRegister not_register2 = not_register1;\n";
158 NotRegister not_register2 = not_register1;
159 cout << "not_register2 = ";
160 cout << "0x" << setfill('0') << setw(BITSTRING_BIT_WIDTH / 4) << hex
161 << not_register2.getBitString(my_chip)->getFieldRight(
162 0, BITSTRING_BIT_WIDTH)
163 << "\n";
164
165 // LeftShiftRegister
166 cout << "\nCreating leftshift_register1 with leftside register.\n";
167 cout << "LeftShiftRegister leftshift_register1(leftside,4);\n";
168 LeftShiftRegister leftshift_register1(leftside, 4);
169 cout << "Creating leftshift_register2 with the assignment operator (=).\n";
170 cout << "LeftShiftRegister leftshift_register2 = leftshift_register1;\n";
171 LeftShiftRegister leftshift_register2 = leftshift_register1;
172 cout << "leftshift_register2 = ";
173 cout << "0x" << setfill('0') << setw(BITSTRING_BIT_WIDTH / 4) << hex
174 << leftshift_register2.getBitString(my_chip)->getFieldRight(
175 0, BITSTRING_BIT_WIDTH)
176 << "\n";
177
178 // RightShiftRegister
179 cout << "\nCreating rightshift_register1 with leftside register.\n";
180 cout << "RightShiftRegister rightshift_register1(leftside,4);\n";
181 RightShiftRegister rightshift_register1(leftside, 4);
182 cout << "Creating rightshift_register2 with the assignment operator (=).\n";
183 cout << "RightShiftRegister rightshift_register2 = rightshift_register1;\n";
184 RightShiftRegister rightshift_register2 = rightshift_register1;
185 cout << "rightshift_register2 = ";
186 cout << "0x" << setfill('0') << setw(BITSTRING_BIT_WIDTH / 4) << hex
187 << rightshift_register2.getBitString(my_chip)->getFieldRight(
188 0, BITSTRING_BIT_WIDTH)
189 << "\n";
190
191 // OrRegister
192 cout << "\nCreating or_register1 with leftside & rightside registers.\n";
193 cout << "OrRegister or_register1(leftside,rightside);\n";
194 OrRegister or_register1(leftside, rightside);
195 cout << "or_register1 = ";
196 cout << "0x" << setfill('0') << setw(BITSTRING_BIT_WIDTH / 4) << hex
197 << or_register1.getBitString(my_chip)->getFieldRight(
198 0, BITSTRING_BIT_WIDTH)
199 << "\n";
200 cout << "Creating or_register2 with the assignment operator (=).\n";
201 cout << "OrRegister or_register2 = or_register1;\n";
202 OrRegister or_register2 = or_register1;
203 cout << "or_register2 = ";
204 cout << "0x" << setfill('0') << setw(BITSTRING_BIT_WIDTH / 4) << hex
205 << or_register2.getBitString(my_chip)->getFieldRight(
206 0, BITSTRING_BIT_WIDTH)
207 << "\n";
208
209 //***** == operator *****
210 cout << "\nOperator \"==\" (equality)\n\n";
211 cout << "Operation Register1 = Register2 Equality\n";
212
213 // Constant Register
214 ConstantRegister cr1(leftside);
215 ConstantRegister cr2(rightside);
216 cout << " Constant 0x" << setfill('0') << setw(BITSTRING_BIT_WIDTH / 4)
217 << hex
218 << cr1.getBitString(my_chip)->getFieldRight(0, BITSTRING_BIT_WIDTH);
219 cout << " 0x" << setfill('0') << setw(BITSTRING_BIT_WIDTH / 4) << hex
220 << cr2.getBitString(my_chip)->getFieldRight(0, BITSTRING_BIT_WIDTH);
221 if (cr1 == cr2)
222 cout << " Equal\n";
223 else
224 cout << " Not Equal\n";
225
226 // And Register
227 AndRegister and1(leftside, rightside);
228 AndRegister and2(leftside, rightside);
229
230 cout << " And 0x" << setfill('0') << setw(BITSTRING_BIT_WIDTH / 4)
231 << hex
232 << and1.getBitString(my_chip)->getFieldRight(0, BITSTRING_BIT_WIDTH);
233 cout << " 0x" << setfill('0') << setw(BITSTRING_BIT_WIDTH / 4) << hex
234 << and2.getBitString(my_chip)->getFieldRight(0, BITSTRING_BIT_WIDTH);
235 if (and1 == and2)
236 cout << " Equal\n";
237 else
238 cout << " Not Equal\n";
239
240 // Not Register
241 NotRegister nr1(leftside);
242 NotRegister nr2(rightside);
243 cout << " Not 0x" << setfill('0') << setw(BITSTRING_BIT_WIDTH / 4)
244 << hex
245 << nr1.getBitString(my_chip)->getFieldRight(0, BITSTRING_BIT_WIDTH);
246 cout << " 0x" << setfill('0') << setw(BITSTRING_BIT_WIDTH / 4) << hex
247 << nr2.getBitString(my_chip)->getFieldRight(0, BITSTRING_BIT_WIDTH);
248 if (nr1 == nr2)
249 cout << " Equal\n";
250 else
251 cout << " Not Equal\n";
252
253 // Left Shift Register
254 LeftShiftRegister lsr1(leftside, 4);
255 LeftShiftRegister lsr2(rightside, 4);
256 cout << " Left Shift 0x" << setfill('0') << setw(BITSTRING_BIT_WIDTH / 4)
257 << hex
258 << lsr1.getBitString(my_chip)->getFieldRight(0, BITSTRING_BIT_WIDTH);
259 cout << " 0x" << setfill('0') << setw(BITSTRING_BIT_WIDTH / 4) << hex
260 << lsr2.getBitString(my_chip)->getFieldRight(0, BITSTRING_BIT_WIDTH);
261 if (lsr1 == lsr2)
262 cout << " Equal\n";
263 else
264 cout << " Not Equal\n";
265
266 // Right Shift Register
267 RightShiftRegister rsr1(leftside, 6);
268 RightShiftRegister rsr2(rightside, 6);
269 cout << " Right Shift 0x" << setfill('0') << setw(BITSTRING_BIT_WIDTH / 4)
270 << hex
271 << rsr1.getBitString(my_chip)->getFieldRight(0, BITSTRING_BIT_WIDTH);
272 cout << " 0x" << setfill('0') << setw(BITSTRING_BIT_WIDTH / 4) << hex
273 << rsr2.getBitString(my_chip)->getFieldRight(0, BITSTRING_BIT_WIDTH);
274 if (rsr1 == rsr2)
275 cout << " Equal\n";
276 else
277 cout << " Not Equal\n";
278
279 // Or Register
280 OrRegister or1(leftside, rightside);
281 OrRegister or2(leftside, rightside);
282 cout << " OR 0x" << setfill('0') << setw(BITSTRING_BIT_WIDTH / 4)
283 << hex
284 << or1.getBitString(my_chip)->getFieldRight(0, BITSTRING_BIT_WIDTH);
285 cout << " 0x" << setfill('0') << setw(BITSTRING_BIT_WIDTH / 4) << hex
286 << or2.getBitString(my_chip)->getFieldRight(0, BITSTRING_BIT_WIDTH);
287 if (or1 == or2)
288 cout << " Equal\n";
289 else
290 cout << " Not Equal\n";
291
292 //***** < operator *****
293 cout << "\nOperator \"<\" (equality)\n\n";
294 cout << "Operation Register1 < Register2 Equal/Less Than\n";
295
296 // Constant Register
297 ConstantRegister cr1a(leftside);
298 ConstantRegister cr2a(rightside);
299 cout << " Constant 0x" << setfill('0') << setw(BITSTRING_BIT_WIDTH / 4)
300 << hex
301 << cr1a.getBitString(my_chip)->getFieldRight(0, BITSTRING_BIT_WIDTH);
302 cout << " 0x" << setfill('0') << setw(BITSTRING_BIT_WIDTH / 4) << hex
303 << cr2a.getBitString(my_chip)->getFieldRight(0, BITSTRING_BIT_WIDTH);
304 // if (cr1a < cr2a)
305 if (cr1a.getBitString(my_chip)->getFieldRight(0, BITSTRING_BIT_WIDTH) <
306 cr2a.getBitString(my_chip)->getFieldRight(0, BITSTRING_BIT_WIDTH))
307 cout << " Less Than\n";
308 else
309 cout << " Not Less Than\n";
310
311 // And Register
312 AndRegister and1a(leftside, rightside);
313 AndRegister and2a(leftside, rightside);
314 cout << " And 0x" << setfill('0') << setw(BITSTRING_BIT_WIDTH / 4)
315 << hex
316 << and1a.getBitString(my_chip)->getFieldRight(0, BITSTRING_BIT_WIDTH);
317 cout << " 0x" << setfill('0') << setw(BITSTRING_BIT_WIDTH / 4) << hex
318 << and2a.getBitString(my_chip)->getFieldRight(0, BITSTRING_BIT_WIDTH);
319 // if (and2a < and1a)
320 if (and1a.getBitString(my_chip)->getFieldRight(0, BITSTRING_BIT_WIDTH) <
321 and2a.getBitString(my_chip)->getFieldRight(0, BITSTRING_BIT_WIDTH))
322 cout << " Less Than\n";
323 else
324 cout << " Not Less Than\n";
325
326 // Not Register
327 NotRegister nr1a(leftside);
328 NotRegister nr2a(rightside);
329 cout << " Not 0x" << setfill('0') << setw(BITSTRING_BIT_WIDTH / 4)
330 << hex
331 << nr1a.getBitString(my_chip)->getFieldRight(0, BITSTRING_BIT_WIDTH);
332 cout << " 0x" << setfill('0') << setw(BITSTRING_BIT_WIDTH / 4) << hex
333 << nr2a.getBitString(my_chip)->getFieldRight(0, BITSTRING_BIT_WIDTH);
334 // if (nr1a < nr2a) Paul
335 if (nr1a.getBitString(my_chip)->getFieldRight(0, BITSTRING_BIT_WIDTH) <
336 nr2a.getBitString(my_chip)->getFieldRight(0, BITSTRING_BIT_WIDTH))
337 cout << " Less Than\n";
338 else
339 cout << " Not Less Than\n";
340
341 // Left Shift Register
342 LeftShiftRegister lsr1a(leftside, 4);
343 LeftShiftRegister lsr2a(leftside, 4);
344 cout << " Left Shift 0x" << setfill('0') << setw(BITSTRING_BIT_WIDTH / 4)
345 << hex
346 << lsr1a.getBitString(my_chip)->getFieldRight(0, BITSTRING_BIT_WIDTH);
347 cout << " 0x" << setfill('0') << setw(BITSTRING_BIT_WIDTH / 4) << hex
348 << lsr2a.getBitString(my_chip)->getFieldRight(0, BITSTRING_BIT_WIDTH);
349 // if (lsr1a < lsr2a)
350 if (lsr1a.getBitString(my_chip)->getFieldRight(0, BITSTRING_BIT_WIDTH) <
351 lsr2a.getBitString(my_chip)->getFieldRight(0, BITSTRING_BIT_WIDTH))
352 cout << " Less Than\n";
353 else
354 cout << " Not Less Than\n";
355
356 // Right Shift Register
357 RightShiftRegister rsr1a(leftside, 4);
358 RightShiftRegister rsr2a(leftside, 4);
359 cout << " Right Shift 0x" << setfill('0') << setw(BITSTRING_BIT_WIDTH / 4)
360 << hex
361 << rsr1a.getBitString(my_chip)->getFieldRight(0, BITSTRING_BIT_WIDTH);
362 cout << " 0x" << setfill('0') << setw(BITSTRING_BIT_WIDTH / 4) << hex
363 << rsr2a.getBitString(my_chip)->getFieldRight(0, BITSTRING_BIT_WIDTH);
364 // if (rsr1a < rsr2a)
365 if (rsr1a.getBitString(my_chip)->getFieldRight(0, BITSTRING_BIT_WIDTH) <
366 rsr2a.getBitString(my_chip)->getFieldRight(0, BITSTRING_BIT_WIDTH))
367 cout << " Less Than\n";
368 else
369 cout << " Not Less Than\n";
370
371 // Or Register
372 OrRegister or1a(leftside, rightside);
373 OrRegister or2a(leftside, rightside);
374 cout << " Or 0x" << setfill('0') << setw(BITSTRING_BIT_WIDTH / 4)
375 << hex
376 << or1a.getBitString(my_chip)->getFieldRight(0, BITSTRING_BIT_WIDTH);
377 cout << " 0x" << setfill('0') << setw(BITSTRING_BIT_WIDTH / 4) << hex
378 << or2a.getBitString(my_chip)->getFieldRight(0, BITSTRING_BIT_WIDTH);
379 // if (or1a < or2a)
380 if (or1a.getBitString(my_chip)->getFieldRight(0, BITSTRING_BIT_WIDTH) <
381 or2a.getBitString(my_chip)->getFieldRight(0, BITSTRING_BIT_WIDTH))
382 cout << " Less Than\n";
383 else
384 cout << " Not Less Than\n";
385
386 return (0);
387}