-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsst_core.cpp
More file actions
1246 lines (1084 loc) · 29.8 KB
/
Copy pathsst_core.cpp
File metadata and controls
1246 lines (1084 loc) · 29.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <sst/core/sst_config.h>
#include <sst_core/sst_core.hpp>
#include <sstream>
#include <sst/core/interfaces/simpleMem.h>
#include <sst/core/interfaces/stringEvent.h>
#include <sst/core/simulation.h>
#include <cstdlib>
#include <math.h>
#include <fstream>
#define print_request(req_to_print) \
{\
std::cout<<\
(req_to_print->cmd==Interfaces::SimpleMem::Request::Command::Write?"Write":\
(req_to_print->cmd==Interfaces::SimpleMem::Request::Command::Read?"Read":\
(req_to_print->cmd==Interfaces::SimpleMem::Request::Command::ReadResp?"ReadResp":\
(req_to_print->cmd==Interfaces::SimpleMem::Request::Command::WriteResp?"WriteResp":"Some flush"\
))))<<std::endl<<\
"\tTo Address "<<req_to_print->addr<<std::endl<<\
"\tSize "<<req_to_print->size<<std::endl<<\
"\tId "<<req_to_print->id<<std::endl;\
}
namespace XSim
{
namespace SST
{
int in_mul = 0;
int in_div = 0;
int in_ls = 0;
int in_int = 0;
struct node{
int remaining_cycles;
int memloc;
int iready;
int jready;
int executing;
int complete;
int destreg;
int read;
int operation;
node *ires;
node *jres;
node *next;
node *prev;
};
typedef struct node *nodep;
nodep beginning_of_int;
nodep end_of_int;
nodep reg_file[8];
int int_empty = 1;
int using_int = 0;
nodep beginning_of_div;
nodep end_of_div;
int div_empty = 1;
int using_div = 0;
nodep beginning_of_mul;
nodep end_of_mul;
int mul_empty = 1;
int using_mul = 0;
nodep beginning_of_ls;
int ls_empty = 1;
int using_ls = 0;
int to_dec_ls = 0;
int16_t *int_arr;
int16_t *mul_arr;
int16_t *div_arr;
int16_t ls_arr = 0;
int regread = 0;
nodep *int_used_arr;
nodep *mul_used_arr;
nodep *div_used_arr;
int stalls = 0;
core::core(ComponentId_t id, Params& params):
Component(id)
{
//***********************************************************************************************
//* Some of the parameters may not be avaiable here, e.g. if --run-mode is "init" *
//* As a consequence, this section shall not throw any errors. Instead use setup section *
//***********************************************************************************************
// verbose is one of the configuration options for this component
verbose = (uint32_t) params.find<uint32_t>("verbose", verbose);
// clock_frequency is one of the configuration options for this component
clock_frequency=params.find<std::string>("clock_frequency",clock_frequency);
n_read_requests=params.find<uarch_t>("n_read_requests",n_read_requests);
n_write_requests=params.find<uarch_t>("n_write_requests",n_write_requests);
int_num=params.find<uint16_t>("integernum",int_num);
int_res=params.find<uint16_t>("integerres",int_res);
int_lat=params.find<uint16_t>("integerlat",int_lat);
div_num=params.find<uint16_t>("dividernum",div_num);
div_res=params.find<uint16_t>("dividerres",div_res);
div_lat=params.find<uint16_t>("dividerlat",div_lat);
mul_num=params.find<uint16_t>("multipliernum",mul_num);
mul_res=params.find<uint16_t>("multiplierres",mul_res);
mul_lat=params.find<uint16_t>("multiplierlat",mul_lat);
ls_res=params.find<uint16_t>("lsres",ls_res);
ls_num=params.find<uint16_t>("lsnum",ls_num);
ls_lat=params.find<uint16_t>("lslat",ls_lat);
program_file=params.find<std::string>("program",program_file);
output_file=params.find<std::string>("output",output_file);
// Create the SST output with the required verbosity level
output = new Output("mips_core[@t:@l]: ", verbose, 0, Output::STDOUT);
bool success;
output->verbose(CALL_INFO, 1, 0, "Configuring cache connection...\n");
//
// The following code creates the SST interface that will connect to the memory hierarchy
//
data_memory_link = dynamic_cast<SimpleMem*>(Super::loadModuleWithComponent("memHierarchy.memInterface", this, params));
SimpleMem::Handler<core> *data_handler=
new SimpleMem::Handler<core>(this,&core::memory_callback);
if(!data_memory_link)
{
output->fatal(CALL_INFO, -1, "Error loading memory interface module.\n");
}
else
{
output->verbose(CALL_INFO, 1, 0, "Loaded memory interface successfully.\n");
}
success=data_memory_link->initialize("data_memory_link", data_handler );
if(success)
{
output->verbose(CALL_INFO, 1, 0, "Loaded memory initialize routine returned successfully.\n");
}
else
{
output->fatal(CALL_INFO, -1, "Failed to initialize interface: %s\n", "memHierarchy.memInterface");
}
output->verbose(CALL_INFO, 1, 0, "Configuration of memory interface completed.\n");
// tell the simulator not to end without us
registerAsPrimaryComponent();
primaryComponentDoNotEndSim();
}
void core::setup()
{
output->output("Setting up.\n");
Super::registerExit();
// Create a tick function with the frequency specified
Super::registerClock( clock_frequency, new Clock::Handler<core>(this, &core::tick ) );
// Memory latency is used to make write/read requests to the SST simulated memory
// Simple wrapper to register callbacks
memory_latency = new SSTMemory(data_memory_link);
core::loadProgram();
cycles=0;
instructions=0;
}
void core::init(unsigned int phase)
{
output->output("Initializing.\n");
//Nothing to do here
}
void core::loadProgram(){
printf("%d\n",ls_res );
printf("%d\n",ls_lat );
programArray = (uint16_t*)malloc(65536*sizeof(uint16_t));
data_memory = (int16_t*)malloc(65536*sizeof(int16_t));
int_arr = (int16_t*)malloc(int_num*sizeof(int16_t));
for(int i=0;i<int_num;i++)
int_arr[i]=0;
div_arr = (int16_t*)malloc(div_num*sizeof(int16_t));
for(int i=0;i<div_num;i++)
div_arr[i]=0;
mul_arr = (int16_t*)malloc(mul_num*sizeof(int16_t));
for(int i=0;i<mul_num;i++)
mul_arr[i]=0;
int_used_arr = (nodep*)malloc(int_num*sizeof(nodep));
for(int i=0;i<int_num;i++)
int_used_arr[i]=NULL;
div_used_arr = (nodep*)malloc(div_num*sizeof(nodep));
for(int i=0;i<div_num;i++)
div_used_arr[i]=NULL;
mul_used_arr = (nodep*)malloc(mul_num*sizeof(nodep));
for(int i=0;i<mul_num;i++)
mul_used_arr[i]=NULL;
for(int i=0;i<8;i++)
reg_file[i]=NULL;
std::ifstream file(program_file);
std::string str;
while (std::getline(file, str))
{
if(str.front() != '#'){
if(str.length() > 5){
programArray[instr_count] = (int)strtol(str.substr(0,4).c_str(), NULL, 16);
//printf("%d\n",programArray[instr_count]);
data_memory[instr_count++] = (int)strtol(str.substr(5,8).c_str(), NULL, 16);
//printf("%d\n",data_memory[instr_count-1]);
}
else
programArray[instr_count++] = (int)strtol(str.c_str(), NULL, 16);
}
}
}
void core::finish()
{
FILE * pFile;
pFile = fopen (output_file.c_str(),"w");
fprintf(pFile,"{\"cycles\":%d,\n",cycles);
fprintf(pFile,"\"integer\":[");
for(int i=0;i<int_num;i++){
fprintf(pFile,"{ \"id\" : %d, \"instructions\" : %d}",i,int_arr[i]);
if(i+1<int_num)
fprintf(pFile,",");
else
fprintf(pFile,"],\n");
}
fprintf(pFile,"\"multiplier\":[");
for(int i=0;i<mul_num;i++){
fprintf(pFile,"{ \"id\" : %d, \"instructions\" : %d}",i,mul_arr[i]);
if(i+1<mul_num)
fprintf(pFile,",");
else
fprintf(pFile,"],\n");
}
fprintf(pFile,"\"divider\":[");
for(int i=0;i<div_num;i++){
fprintf(pFile,"{ \"id\" : %d, \"instructions\" : %d}",i,div_arr[i]);
if(i+1<div_num)
fprintf(pFile,",");
else
fprintf(pFile,"],\n");
}
fprintf(pFile,"\"ls\":[");
for(int i=0;i<ls_num;i++){
fprintf(pFile,"{ \"id\" : %d, \"instructions\" : %d}",i,ls_arr);
if(i+1<ls_num)
fprintf(pFile,",");
else
fprintf(pFile,"],\n");
}
fprintf(pFile,"\"reg reads\" : %d,\n",regread);
fprintf(pFile,"\"stalls\" : %d}",stalls);
fclose(pFile);
}
bool core::tick(Cycle_t cycle)
{
printf("\n\nTick %d:\n", cycles);
//***********************************************************************************************
//* What you need to do is to change the logic in this function with instruction execution *
//***********************************************************************************************
//std::cout<<"core::tick"<<std::endl;
cycles++;
std::function<void(uarch_t, uarch_t)> callback_function = [this](uarch_t request_id, uarch_t addr)
{
nodep current = beginning_of_ls;
//Broadcast first to allow those waiting to immediately read
current->complete = 1;
to_dec_ls++;
if(current->destreg > -1 && reg_file[current->destreg] == current)
reg_file[current->destreg] = NULL;
if(current->next != NULL)
beginning_of_ls = current->next;
else{
beginning_of_ls = NULL;
ls_empty = 1;
}
printf("Ls broadcasted\n");
nodep current2 = beginning_of_int;
while(current2 != NULL){
if(current2->iready == 0){
if(current2->ires->complete == 1){
current2->iready = 1;
current2->ires = NULL;
}
}
if(current2->jready == 0){
if(current2->jres->complete == 1){
current2->jready = 1;
current2->jres = NULL;
}
}
if(current2->iready == 1 && current->jready == 1 && current2->executing == 0 && current2->read == 0){
current2->read = 1;
printf("Int Read instructions\n");
}
current2 = current2->next;
}
current2 = beginning_of_mul;
while(current2 != NULL){
if(current2->iready == 0){
if(current2->ires->complete == 1){
current2->iready = 1;
current2->ires = NULL;
}
}
if(current2->jready == 0){
if(current2->jres->complete == 1){
current2->jready = 1;
current2->jres = NULL;
}
}
if(current2->iready == 1 && current->jready == 1 && current2->executing == 0 && current2->read == 0){
current2->read = 1;
printf("Mul Read instructions\n");
}
current2 = current2->next;
}
current2 = beginning_of_div;
while(current2 != NULL){
if(current2->iready == 0){
if(current2->ires->complete == 1){
current2->iready = 1;
current2->ires = NULL;
}
}
if(current2->jready == 0){
if(current2->jres->complete == 1){
current2->jready = 1;
current2->jres = NULL;
}
}
if(current2->iready == 1 && current->jready == 1 && current2->executing == 0 && current2->read == 0){
current2->read = 1;
printf("Div Read instructions\n");
}
current2 = current2->next;
}
delete(current);
if((instr_run == instr_count) && (int_empty == 1 || beginning_of_int == NULL) && (div_empty == 1 || beginning_of_div == NULL) && (mul_empty == 1 || beginning_of_mul == NULL) && (ls_empty == 1 || beginning_of_ls == NULL)){
primaryComponentOKToEndSim();
unregisterExit();
return true;
}
};
nodep current = beginning_of_int;
nodep oldint = NULL;
nodep oldintlast = NULL;
int to_dec_int = 0;
//Broadcast first to allow those waiting to immediately read
while(current != NULL){
nodep togo = current->next;
if(current->remaining_cycles == 0 && current->executing == 1){
current->complete = 1;
to_dec_int++;
if(current->destreg > -1 && reg_file[current->destreg] == current)
reg_file[current->destreg] = NULL;
if(current->prev != NULL && current->next != NULL){
current->prev->next = current->next;
current->next->prev = current->prev;
}
else if(current->prev == NULL && current-> next != NULL){
beginning_of_int = current->next;
beginning_of_int->prev = NULL;
}
else if(current->prev != NULL && current-> next == NULL){
current->prev->next = NULL;
end_of_int = current->prev;
}
else if(current->prev == NULL && current-> next == NULL){
beginning_of_int = NULL;
end_of_int = NULL;
int_empty = 1;
}
if(oldint == NULL){
oldint = current;
oldintlast = current;
current->next = NULL;
}
else{
oldintlast->next = current;
oldintlast = current;
current->next = NULL;
}
printf("int broadcasted\n");
}
if(togo == NULL)
break;
else
current = togo;
}
current = beginning_of_div;
nodep olddiv = NULL;
nodep olddivlast = NULL;
int to_dec_div = 0;
//Broadcast first to allow those waiting to immediately read
while(current != NULL){
nodep togo = current->next;
if(current->remaining_cycles == 0 && current->executing == 1){
current->complete = 1;
to_dec_div++;
if(current->destreg > -1 && reg_file[current->destreg] == current)
reg_file[current->destreg] = NULL;
if(current->prev != NULL && current->next != NULL){
current->prev->next = current->next;
current->next->prev = current->prev;
}
else if(current->prev == NULL && current-> next != NULL){
beginning_of_div = current->next;
beginning_of_div->prev = NULL;
}
else if(current->prev != NULL && current-> next == NULL){
current->prev->next = NULL;
end_of_div = current->prev;
}
else if(current->prev == NULL && current-> next == NULL){
beginning_of_div = NULL;
end_of_div = NULL;
div_empty = 1;
}
if(olddiv == NULL){
olddiv = current;
olddivlast = current;
current->next = NULL;
}
else{
olddivlast->next = current;
olddivlast = current;
current->next = NULL;
}
printf("div broadcasted\n");
}
if(togo == NULL)
break;
else
current = togo;
}
current = beginning_of_mul;
nodep oldmul = NULL;
nodep oldmullast = NULL;
int to_dec_mul = 0;
//Broadcast first to allow those waiting to immediately read
while(current != NULL){
nodep togo = current->next;
if(current->remaining_cycles == 0 && current->executing == 1){
current->complete = 1;
to_dec_mul++;
if(current->destreg > -1 && reg_file[current->destreg] == current)
reg_file[current->destreg] = NULL;
if(current->prev != NULL && current->next != NULL){
current->prev->next = current->next;
current->next->prev = current->prev;
}
else if(current->prev == NULL && current-> next != NULL){
beginning_of_mul = current->next;
beginning_of_mul->prev = NULL;
}
else if(current->prev != NULL && current-> next == NULL){
current->prev->next = NULL;
end_of_mul = current->prev;
}
else if(current->prev == NULL && current-> next == NULL){
beginning_of_mul = NULL;
end_of_mul = NULL;
mul_empty = 1;
}
if(oldmul == NULL){
oldmul = current;
oldmullast = current;
current->next = NULL;
}
else{
oldmullast->next = current;
oldmullast = current;
current->next = NULL;
}
printf("mul broadcasted\n");
}
if(togo == NULL)
break;
else
current = togo;
}
current = beginning_of_int;
while(current != NULL){
if(current->iready == 0){
if(current->ires->complete == 1){
current->iready = 1;
current->ires = NULL;
}
}
if(current->jready == 0){
if(current->jres->complete == 1){
current->jready = 1;
current->jres = NULL;
}
}
if(current->iready == 1 && current->jready == 1 && current->executing == 0 ){
if(current->read == 1 && using_int < int_num){
for(int i=0;i<int_num;i++){
if(int_used_arr[i] == NULL){
int_used_arr[i]=current;
int_arr[i]++;
break;
}
}
current->executing = 1;
printf("int executed 1st cycle\n");
current->remaining_cycles-=1;
using_int++;
}
else if(current->read == 0){
current->read = 1;
printf("int Read instructions\n");
}
}
else if(current->executing == 1){
current->remaining_cycles-=1;
printf("int executed one cycle\n");
}
if(current->next == NULL)
break;
else
current = current->next;
}
current = beginning_of_div;
while(current != NULL){
if(current->iready == 0){
if(current->ires->complete == 1){
current->iready = 1;
current->ires = NULL;
}
}
if(current->jready == 0){
if(current->jres->complete == 1){
current->jready = 1;
current->jres = NULL;
}
}
if(current->iready == 1 && current->jready == 1 && current->executing == 0 ){
if(current->read == 1 && using_div < div_num){
for(int i=0;i<div_num;i++){
int found = 0;
if(div_used_arr[i] == NULL){
div_used_arr[i]=current;
div_arr[i]++;
found = 1;
break;
}
if(found == 0)
printf("NOT FOUND\n");
}
current->executing = 1;
printf("div executed one cycle\n");
current->remaining_cycles-=1;
using_div++;
}
else if(current->read == 0){
current->read = 1;
printf("div Read instructions\n");
}
}
else if(current->executing == 1){
current->remaining_cycles-=1;
printf("div executed one cycle\n");
}
if(current->next == NULL)
break;
else
current = current->next;
}
current = beginning_of_mul;
while(current != NULL){
if(current->iready == 0){
if(current->ires->complete == 1){
current->iready = 1;
current->ires = NULL;
}
}
if(current->jready == 0){
if(current->jres->complete == 1){
current->jready = 1;
current->jres = NULL;
}
}
if(current->iready == 1 && current->jready == 1 && current->executing == 0 ){
if(current->read == 1 && using_mul < mul_num){
for(int i=0;i<mul_num;i++){
if(mul_used_arr[i] == NULL){
mul_used_arr[i]=current;
mul_arr[i]++;
break;
}
}
current->executing = 1;
printf("mul executed one cycle\n");
current->remaining_cycles-=1;
using_mul++;
}
else if(current->read == 0){
current->read = 1;
printf("mul Read instructions\n");
}
}
else if(current->executing == 1){
current->remaining_cycles-=1;
printf("mul executed one cycle\n");
}
if(current->next == NULL)
break;
else
current = current->next;
}
current = beginning_of_ls;
while(current != NULL){
if(current->iready == 0){
if(current->ires->complete == 1){
current->iready = 1;
current->ires = NULL;
}
}
if(current->jready == 0){
if(current->jres->complete == 1){
current->jready = 1;
current->jres = NULL;
}
}
if(current->iready == 1 && current->jready == 1 && current->executing == 0){
if(current->read == 1 && using_ls < ls_num && current == beginning_of_ls){
ls_arr++;
current->executing = 1;
printf("ls executed one cycle\n");
current->remaining_cycles-=1;
using_ls++;
}
else if(current->read == 0){
current->read = 1;
printf("ls Read instructions\n");
}
}
else if(current->remaining_cycles == 0){
if(current->operation == 0)
memory_latency->read(current->memloc, callback_function);
else
memory_latency->write(current->memloc, callback_function);
current->executing = 0;
}
else if(current->executing == 1){
current->remaining_cycles-=1;
printf("ls executed one cycle\n");
}
if(current->next == NULL)
break;
else
current = current->next;
}
if((instr_run == instr_count) && (int_empty == 1 || beginning_of_int == NULL) && (div_empty == 1 || beginning_of_div == NULL) && (mul_empty == 1 || beginning_of_mul == NULL) && (ls_empty == 1 || beginning_of_ls == NULL)){
primaryComponentOKToEndSim();
unregisterExit();
return true;
}
if(instr_run<instr_count){
uint16_t instr = programArray[instr_run++];
//add/sub/and/nor
if((instr & 0xF800) == 0x0000 || (instr & 0xF800) == 0x0800 || (instr & 0xF800) == 0x1000 || (instr & 0xF800) == 0x1800){
if(in_int < int_res){
nodep next = new node;
if(beginning_of_int == NULL){
beginning_of_int = next;
end_of_int = next;
next->next = NULL;
next->prev = NULL;
}
else{
end_of_int->next = next;
next->prev = end_of_int;
next->next = NULL;
end_of_int = next;
}
if(reg_file[instr>>5 & 0x0007] != NULL){
next->ires = reg_file[instr>>5 & 0x0007];
next->iready = 0;
}
else{
next->iready = 1;
regread++;
}
if(reg_file[instr>>2 & 0x0007] != NULL){
next->jres = reg_file[instr>>2 & 0x0007];
next->jready = 0;
}
else{
regread++;
next->jready = 1;
}
reg_file[instr>>8 & 0x0007] = next;
next->remaining_cycles = int_lat;
next->executing=0;
next->complete=0;
next->read = 0;
next->destreg = (instr>>8 & 0x0007);
int_empty = 0;
in_int++;
printf("Add/sub/and/nor issued\n");
}
else{
instr_run--;
stalls++;
}
}
//Liz,lis,lui
else if((instr & 0xF800) == 0x8000 || (instr & 0xF800) == 0x8800){
if(in_int < int_res){
nodep next = new node;
if(beginning_of_int == NULL){
beginning_of_int = next;
end_of_int = next;
next->next = NULL;
next->prev = NULL;
}
else{
end_of_int->next = next;
next->prev = end_of_int;
next->next = NULL;
end_of_int = next;
}
next->iready = 1;
next->jready = 1;
reg_file[instr>>8 & 0x0007] = next;
next->remaining_cycles = int_lat;
next->executing=0;
next->complete=0;
next->read = 0;
next->destreg = (instr>>8 & 0x0007);
int_empty = 0;
in_int++;
printf("Lis/liz/lui issued\n");
}
else{
instr_run--;
stalls++;
}
}
//lui
else if((instr & 0xF800) == 0x9000){
if(in_int < int_res){
nodep next = new node;
if(beginning_of_int == NULL){
beginning_of_int = next;
end_of_int = next;
next->next = NULL;
next->prev = NULL;
}
else{
end_of_int->next = next;
next->prev = end_of_int;
next->next = NULL;
end_of_int = next;
}
if(reg_file[instr>>8 & 0x0007] != NULL){
next->ires = reg_file[instr>>8 & 0x0007];
next->iready = 0;
}
else{
next->iready = 1;
regread++;
}
next->jready = 1;
reg_file[instr>>8 & 0x0007] = next;
next->remaining_cycles = int_lat;
next->executing=0;
next->complete=0;
next->read = 0;
next->destreg = (instr>>8 & 0x0007);
int_empty = 0;
in_int++;
printf("Lis/liz/lui issued\n");
}
else{
instr_run--;
stalls++;
}
}
//Halt
else if((instr & 0xF800) == 0x6800){
if(in_int < int_res){
nodep next = new node;
if(beginning_of_int == NULL){
beginning_of_int = next;
end_of_int = next;
next->next = NULL;
next->prev = NULL;
}
else{
end_of_int->next = next;
next->prev = end_of_int;
next->next = NULL;
end_of_int = next;
}
next->iready = 1;
next->jready = 1;
next->remaining_cycles = int_lat;
next->executing=0;
next->complete=0;
next->read = 0;
next->destreg = -1;
int_empty = 0;
in_int++;
printf("Halt issued\n");
}
else{
instr_run--;
stalls++;
}
}
//Put
else if((instr & 0xF800) == 0x7000){
if(in_int < int_res){
nodep next = new node;
if(beginning_of_int == NULL){
beginning_of_int = next;
end_of_int = next;
next->next = NULL;
next->prev = NULL;
}
else{
end_of_int->next = next;
next->prev = end_of_int;
next->next = NULL;
end_of_int = next;
}
if(reg_file[instr>>5 & 0x0007] != NULL){
next->ires = reg_file[instr>>5 & 0x0007];
next->iready = 0;
}
else{
next->iready = 1;
regread++;
}
next->jready = 1;
next->remaining_cycles = int_lat;
next->executing=0;
next->complete=0;
next->read = 0;
next->destreg = -1;
int_empty = 0;
in_int++;
printf("put issued\n");
}
else{
instr_run--;
stalls++;
}
}
//Div/mod/exp instr
else if((instr & 0xF800) == 0x2000 || (instr & 0xF800) == 0x3800 || (instr & 0xF800) == 0x3000){
if(in_div < div_res){
nodep next = new node;
if(beginning_of_div == NULL){
beginning_of_div = next;
end_of_div = next;
next->next = NULL;
next->prev = NULL;
}
else{
end_of_div->next = next;
next->prev = end_of_div;
next->next = NULL;
end_of_div = next;
}
if(reg_file[instr>>5 & 0x0007] != NULL){
next->ires = reg_file[instr>>5 & 0x0007];
next->iready = 0;
}
else{
next->iready = 1;
regread++;
}
if(reg_file[instr>>2 & 0x0007] != NULL){
next->jres = reg_file[instr>>2 & 0x0007];
next->jready = 0;
}
else{
next->jready = 1;
regread++;
}
reg_file[instr>>8 & 0x0007] = next;
next->remaining_cycles = div_lat;
next->executing=0;
next->complete=0;
next->read = 0;
next->destreg = (instr>>8 & 0x0007);
div_empty = 0;
in_div++;
printf("div/mod/exp issued\n");