-
Notifications
You must be signed in to change notification settings - Fork 39
/
VexRiscv_Linux.v
7789 lines (7575 loc) · 311 KB
/
VexRiscv_Linux.v
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
// Generator : SpinalHDL v1.3.5 git head : f0505d24810c8661a24530409359554b7cfa271a
// Date : 09/06/2019, 12:35:00
// Component : VexRiscv
`define EnvCtrlEnum_defaultEncoding_type [1:0]
`define EnvCtrlEnum_defaultEncoding_NONE 2'b00
`define EnvCtrlEnum_defaultEncoding_XRET 2'b01
`define EnvCtrlEnum_defaultEncoding_WFI 2'b10
`define EnvCtrlEnum_defaultEncoding_ECALL 2'b11
`define AluBitwiseCtrlEnum_defaultEncoding_type [1:0]
`define AluBitwiseCtrlEnum_defaultEncoding_XOR_1 2'b00
`define AluBitwiseCtrlEnum_defaultEncoding_OR_1 2'b01
`define AluBitwiseCtrlEnum_defaultEncoding_AND_1 2'b10
`define Src1CtrlEnum_defaultEncoding_type [1:0]
`define Src1CtrlEnum_defaultEncoding_RS 2'b00
`define Src1CtrlEnum_defaultEncoding_IMU 2'b01
`define Src1CtrlEnum_defaultEncoding_PC_INCREMENT 2'b10
`define Src1CtrlEnum_defaultEncoding_URS1 2'b11
`define Src2CtrlEnum_defaultEncoding_type [1:0]
`define Src2CtrlEnum_defaultEncoding_RS 2'b00
`define Src2CtrlEnum_defaultEncoding_IMI 2'b01
`define Src2CtrlEnum_defaultEncoding_IMS 2'b10
`define Src2CtrlEnum_defaultEncoding_PC 2'b11
`define ShiftCtrlEnum_defaultEncoding_type [1:0]
`define ShiftCtrlEnum_defaultEncoding_DISABLE_1 2'b00
`define ShiftCtrlEnum_defaultEncoding_SLL_1 2'b01
`define ShiftCtrlEnum_defaultEncoding_SRL_1 2'b10
`define ShiftCtrlEnum_defaultEncoding_SRA_1 2'b11
`define BranchCtrlEnum_defaultEncoding_type [1:0]
`define BranchCtrlEnum_defaultEncoding_INC 2'b00
`define BranchCtrlEnum_defaultEncoding_B 2'b01
`define BranchCtrlEnum_defaultEncoding_JAL 2'b10
`define BranchCtrlEnum_defaultEncoding_JALR 2'b11
`define AluCtrlEnum_defaultEncoding_type [1:0]
`define AluCtrlEnum_defaultEncoding_ADD_SUB 2'b00
`define AluCtrlEnum_defaultEncoding_SLT_SLTU 2'b01
`define AluCtrlEnum_defaultEncoding_BITWISE 2'b10
`define MmuPlugin_shared_State_defaultEncoding_type [2:0]
`define MmuPlugin_shared_State_defaultEncoding_IDLE 3'b000
`define MmuPlugin_shared_State_defaultEncoding_L1_CMD 3'b001
`define MmuPlugin_shared_State_defaultEncoding_L1_RSP 3'b010
`define MmuPlugin_shared_State_defaultEncoding_L0_CMD 3'b011
`define MmuPlugin_shared_State_defaultEncoding_L0_RSP 3'b100
module InstructionCache (
input io_flush,
input io_cpu_prefetch_isValid,
output reg io_cpu_prefetch_haltIt,
input [31:0] io_cpu_prefetch_pc,
input io_cpu_fetch_isValid,
input io_cpu_fetch_isStuck,
input io_cpu_fetch_isRemoved,
input [31:0] io_cpu_fetch_pc,
output [31:0] io_cpu_fetch_data,
input io_cpu_fetch_dataBypassValid,
input [31:0] io_cpu_fetch_dataBypass,
output io_cpu_fetch_mmuBus_cmd_isValid,
output [31:0] io_cpu_fetch_mmuBus_cmd_virtualAddress,
output io_cpu_fetch_mmuBus_cmd_bypassTranslation,
input [31:0] io_cpu_fetch_mmuBus_rsp_physicalAddress,
input io_cpu_fetch_mmuBus_rsp_isIoAccess,
input io_cpu_fetch_mmuBus_rsp_allowRead,
input io_cpu_fetch_mmuBus_rsp_allowWrite,
input io_cpu_fetch_mmuBus_rsp_allowExecute,
input io_cpu_fetch_mmuBus_rsp_exception,
input io_cpu_fetch_mmuBus_rsp_refilling,
output io_cpu_fetch_mmuBus_end,
input io_cpu_fetch_mmuBus_busy,
output [31:0] io_cpu_fetch_physicalAddress,
output io_cpu_fetch_haltIt,
input io_cpu_decode_isValid,
input io_cpu_decode_isStuck,
input [31:0] io_cpu_decode_pc,
output [31:0] io_cpu_decode_physicalAddress,
output [31:0] io_cpu_decode_data,
output io_cpu_decode_cacheMiss,
output io_cpu_decode_error,
output io_cpu_decode_mmuRefilling,
output io_cpu_decode_mmuException,
input io_cpu_decode_isUser,
input io_cpu_fill_valid,
input [31:0] io_cpu_fill_payload,
output io_mem_cmd_valid,
input io_mem_cmd_ready,
output [31:0] io_mem_cmd_payload_address,
output [2:0] io_mem_cmd_payload_size,
input io_mem_rsp_valid,
input [31:0] io_mem_rsp_payload_data,
input io_mem_rsp_payload_error,
input clk,
input reset);
reg [21:0] _zz_10_;
reg [31:0] _zz_11_;
wire _zz_12_;
wire _zz_13_;
wire [0:0] _zz_14_;
wire [0:0] _zz_15_;
wire [21:0] _zz_16_;
reg _zz_1_;
reg _zz_2_;
reg lineLoader_fire;
reg lineLoader_valid;
reg [31:0] lineLoader_address;
reg lineLoader_hadError;
reg lineLoader_flushPending;
reg [7:0] lineLoader_flushCounter;
reg _zz_3_;
reg lineLoader_cmdSent;
reg lineLoader_wayToAllocate_willIncrement;
wire lineLoader_wayToAllocate_willClear;
wire lineLoader_wayToAllocate_willOverflowIfInc;
wire lineLoader_wayToAllocate_willOverflow;
reg [2:0] lineLoader_wordIndex;
wire lineLoader_write_tag_0_valid;
wire [6:0] lineLoader_write_tag_0_payload_address;
wire lineLoader_write_tag_0_payload_data_valid;
wire lineLoader_write_tag_0_payload_data_error;
wire [19:0] lineLoader_write_tag_0_payload_data_address;
wire lineLoader_write_data_0_valid;
wire [9:0] lineLoader_write_data_0_payload_address;
wire [31:0] lineLoader_write_data_0_payload_data;
wire _zz_4_;
wire [6:0] _zz_5_;
wire _zz_6_;
wire fetchStage_read_waysValues_0_tag_valid;
wire fetchStage_read_waysValues_0_tag_error;
wire [19:0] fetchStage_read_waysValues_0_tag_address;
wire [21:0] _zz_7_;
wire [9:0] _zz_8_;
wire _zz_9_;
wire [31:0] fetchStage_read_waysValues_0_data;
wire fetchStage_hit_hits_0;
wire fetchStage_hit_valid;
wire fetchStage_hit_error;
wire [31:0] fetchStage_hit_data;
wire [31:0] fetchStage_hit_word;
reg [31:0] io_cpu_fetch_data_regNextWhen;
reg [31:0] decodeStage_mmuRsp_physicalAddress;
reg decodeStage_mmuRsp_isIoAccess;
reg decodeStage_mmuRsp_allowRead;
reg decodeStage_mmuRsp_allowWrite;
reg decodeStage_mmuRsp_allowExecute;
reg decodeStage_mmuRsp_exception;
reg decodeStage_mmuRsp_refilling;
reg decodeStage_hit_valid;
reg decodeStage_hit_error;
(* ram_style = "block" *) reg [21:0] ways_0_tags [0:127];
(* ram_style = "block" *) reg [31:0] ways_0_datas [0:1023];
assign _zz_12_ = (! lineLoader_flushCounter[7]);
assign _zz_13_ = (lineLoader_flushPending && (! (lineLoader_valid || io_cpu_fetch_isValid)));
assign _zz_14_ = _zz_7_[0 : 0];
assign _zz_15_ = _zz_7_[1 : 1];
assign _zz_16_ = {lineLoader_write_tag_0_payload_data_address,{lineLoader_write_tag_0_payload_data_error,lineLoader_write_tag_0_payload_data_valid}};
always @ (posedge clk) begin
if(_zz_2_) begin
ways_0_tags[lineLoader_write_tag_0_payload_address] <= _zz_16_;
end
end
always @ (posedge clk) begin
if(_zz_6_) begin
_zz_10_ <= ways_0_tags[_zz_5_];
end
end
always @ (posedge clk) begin
if(_zz_1_) begin
ways_0_datas[lineLoader_write_data_0_payload_address] <= lineLoader_write_data_0_payload_data;
end
end
always @ (posedge clk) begin
if(_zz_9_) begin
_zz_11_ <= ways_0_datas[_zz_8_];
end
end
always @ (*) begin
_zz_1_ = 1'b0;
if(lineLoader_write_data_0_valid)begin
_zz_1_ = 1'b1;
end
end
always @ (*) begin
_zz_2_ = 1'b0;
if(lineLoader_write_tag_0_valid)begin
_zz_2_ = 1'b1;
end
end
assign io_cpu_fetch_haltIt = io_cpu_fetch_mmuBus_busy;
always @ (*) begin
lineLoader_fire = 1'b0;
if(io_mem_rsp_valid)begin
if((lineLoader_wordIndex == (3'b111)))begin
lineLoader_fire = 1'b1;
end
end
end
always @ (*) begin
io_cpu_prefetch_haltIt = (lineLoader_valid || lineLoader_flushPending);
if(_zz_12_)begin
io_cpu_prefetch_haltIt = 1'b1;
end
if((! _zz_3_))begin
io_cpu_prefetch_haltIt = 1'b1;
end
if(io_flush)begin
io_cpu_prefetch_haltIt = 1'b1;
end
end
assign io_mem_cmd_valid = (lineLoader_valid && (! lineLoader_cmdSent));
assign io_mem_cmd_payload_address = {lineLoader_address[31 : 5],(5'b00000)};
assign io_mem_cmd_payload_size = (3'b101);
always @ (*) begin
lineLoader_wayToAllocate_willIncrement = 1'b0;
if(lineLoader_fire)begin
lineLoader_wayToAllocate_willIncrement = 1'b1;
end
end
assign lineLoader_wayToAllocate_willClear = 1'b0;
assign lineLoader_wayToAllocate_willOverflowIfInc = 1'b1;
assign lineLoader_wayToAllocate_willOverflow = (lineLoader_wayToAllocate_willOverflowIfInc && lineLoader_wayToAllocate_willIncrement);
assign _zz_4_ = 1'b1;
assign lineLoader_write_tag_0_valid = ((_zz_4_ && lineLoader_fire) || (! lineLoader_flushCounter[7]));
assign lineLoader_write_tag_0_payload_address = (lineLoader_flushCounter[7] ? lineLoader_address[11 : 5] : lineLoader_flushCounter[6 : 0]);
assign lineLoader_write_tag_0_payload_data_valid = lineLoader_flushCounter[7];
assign lineLoader_write_tag_0_payload_data_error = (lineLoader_hadError || io_mem_rsp_payload_error);
assign lineLoader_write_tag_0_payload_data_address = lineLoader_address[31 : 12];
assign lineLoader_write_data_0_valid = (io_mem_rsp_valid && _zz_4_);
assign lineLoader_write_data_0_payload_address = {lineLoader_address[11 : 5],lineLoader_wordIndex};
assign lineLoader_write_data_0_payload_data = io_mem_rsp_payload_data;
assign _zz_5_ = io_cpu_prefetch_pc[11 : 5];
assign _zz_6_ = (! io_cpu_fetch_isStuck);
assign _zz_7_ = _zz_10_;
assign fetchStage_read_waysValues_0_tag_valid = _zz_14_[0];
assign fetchStage_read_waysValues_0_tag_error = _zz_15_[0];
assign fetchStage_read_waysValues_0_tag_address = _zz_7_[21 : 2];
assign _zz_8_ = io_cpu_prefetch_pc[11 : 2];
assign _zz_9_ = (! io_cpu_fetch_isStuck);
assign fetchStage_read_waysValues_0_data = _zz_11_;
assign fetchStage_hit_hits_0 = (fetchStage_read_waysValues_0_tag_valid && (fetchStage_read_waysValues_0_tag_address == io_cpu_fetch_mmuBus_rsp_physicalAddress[31 : 12]));
assign fetchStage_hit_valid = (fetchStage_hit_hits_0 != (1'b0));
assign fetchStage_hit_error = fetchStage_read_waysValues_0_tag_error;
assign fetchStage_hit_data = fetchStage_read_waysValues_0_data;
assign fetchStage_hit_word = fetchStage_hit_data[31 : 0];
assign io_cpu_fetch_data = (io_cpu_fetch_dataBypassValid ? io_cpu_fetch_dataBypass : fetchStage_hit_word);
assign io_cpu_decode_data = io_cpu_fetch_data_regNextWhen;
assign io_cpu_fetch_mmuBus_cmd_isValid = io_cpu_fetch_isValid;
assign io_cpu_fetch_mmuBus_cmd_virtualAddress = io_cpu_fetch_pc;
assign io_cpu_fetch_mmuBus_cmd_bypassTranslation = 1'b0;
assign io_cpu_fetch_mmuBus_end = ((! io_cpu_fetch_isStuck) || io_cpu_fetch_isRemoved);
assign io_cpu_fetch_physicalAddress = io_cpu_fetch_mmuBus_rsp_physicalAddress;
assign io_cpu_decode_cacheMiss = (! decodeStage_hit_valid);
assign io_cpu_decode_error = decodeStage_hit_error;
assign io_cpu_decode_mmuRefilling = decodeStage_mmuRsp_refilling;
assign io_cpu_decode_mmuException = ((! decodeStage_mmuRsp_refilling) && (decodeStage_mmuRsp_exception || (! decodeStage_mmuRsp_allowExecute)));
assign io_cpu_decode_physicalAddress = decodeStage_mmuRsp_physicalAddress;
always @ (posedge clk) begin
if(reset) begin
lineLoader_valid <= 1'b0;
lineLoader_hadError <= 1'b0;
lineLoader_flushPending <= 1'b1;
lineLoader_cmdSent <= 1'b0;
lineLoader_wordIndex <= (3'b000);
end else begin
if(lineLoader_fire)begin
lineLoader_valid <= 1'b0;
end
if(lineLoader_fire)begin
lineLoader_hadError <= 1'b0;
end
if(io_cpu_fill_valid)begin
lineLoader_valid <= 1'b1;
end
if(io_flush)begin
lineLoader_flushPending <= 1'b1;
end
if(_zz_13_)begin
lineLoader_flushPending <= 1'b0;
end
if((io_mem_cmd_valid && io_mem_cmd_ready))begin
lineLoader_cmdSent <= 1'b1;
end
if(lineLoader_fire)begin
lineLoader_cmdSent <= 1'b0;
end
if(io_mem_rsp_valid)begin
lineLoader_wordIndex <= (lineLoader_wordIndex + (3'b001));
if(io_mem_rsp_payload_error)begin
lineLoader_hadError <= 1'b1;
end
end
end
end
always @ (posedge clk) begin
if(io_cpu_fill_valid)begin
lineLoader_address <= io_cpu_fill_payload;
end
if(_zz_12_)begin
lineLoader_flushCounter <= (lineLoader_flushCounter + (8'b00000001));
end
_zz_3_ <= lineLoader_flushCounter[7];
if(_zz_13_)begin
lineLoader_flushCounter <= (8'b00000000);
end
if((! io_cpu_decode_isStuck))begin
io_cpu_fetch_data_regNextWhen <= io_cpu_fetch_data;
end
if((! io_cpu_decode_isStuck))begin
decodeStage_mmuRsp_physicalAddress <= io_cpu_fetch_mmuBus_rsp_physicalAddress;
decodeStage_mmuRsp_isIoAccess <= io_cpu_fetch_mmuBus_rsp_isIoAccess;
decodeStage_mmuRsp_allowRead <= io_cpu_fetch_mmuBus_rsp_allowRead;
decodeStage_mmuRsp_allowWrite <= io_cpu_fetch_mmuBus_rsp_allowWrite;
decodeStage_mmuRsp_allowExecute <= io_cpu_fetch_mmuBus_rsp_allowExecute;
decodeStage_mmuRsp_exception <= io_cpu_fetch_mmuBus_rsp_exception;
decodeStage_mmuRsp_refilling <= io_cpu_fetch_mmuBus_rsp_refilling;
end
if((! io_cpu_decode_isStuck))begin
decodeStage_hit_valid <= fetchStage_hit_valid;
end
if((! io_cpu_decode_isStuck))begin
decodeStage_hit_error <= fetchStage_hit_error;
end
end
endmodule
module DataCache (
input io_cpu_execute_isValid,
input [31:0] io_cpu_execute_address,
input io_cpu_execute_args_wr,
input [31:0] io_cpu_execute_args_data,
input [1:0] io_cpu_execute_args_size,
input io_cpu_execute_args_isLrsc,
input io_cpu_execute_args_isAmo,
input io_cpu_execute_args_amoCtrl_swap,
input [2:0] io_cpu_execute_args_amoCtrl_alu,
input io_cpu_memory_isValid,
input io_cpu_memory_isStuck,
input io_cpu_memory_isRemoved,
output io_cpu_memory_isWrite,
input [31:0] io_cpu_memory_address,
output io_cpu_memory_mmuBus_cmd_isValid,
output [31:0] io_cpu_memory_mmuBus_cmd_virtualAddress,
output io_cpu_memory_mmuBus_cmd_bypassTranslation,
input [31:0] io_cpu_memory_mmuBus_rsp_physicalAddress,
input io_cpu_memory_mmuBus_rsp_isIoAccess,
input io_cpu_memory_mmuBus_rsp_allowRead,
input io_cpu_memory_mmuBus_rsp_allowWrite,
input io_cpu_memory_mmuBus_rsp_allowExecute,
input io_cpu_memory_mmuBus_rsp_exception,
input io_cpu_memory_mmuBus_rsp_refilling,
output io_cpu_memory_mmuBus_end,
input io_cpu_memory_mmuBus_busy,
input io_cpu_writeBack_isValid,
input io_cpu_writeBack_isStuck,
input io_cpu_writeBack_isUser,
output reg io_cpu_writeBack_haltIt,
output io_cpu_writeBack_isWrite,
output reg [31:0] io_cpu_writeBack_data,
input [31:0] io_cpu_writeBack_address,
output io_cpu_writeBack_mmuException,
output io_cpu_writeBack_unalignedAccess,
output reg io_cpu_writeBack_accessError,
input io_cpu_writeBack_clearLrsc,
output reg io_cpu_redo,
input io_cpu_flush_valid,
output reg io_cpu_flush_ready,
output reg io_mem_cmd_valid,
input io_mem_cmd_ready,
output reg io_mem_cmd_payload_wr,
output reg [31:0] io_mem_cmd_payload_address,
output [31:0] io_mem_cmd_payload_data,
output [3:0] io_mem_cmd_payload_mask,
output reg [2:0] io_mem_cmd_payload_length,
output reg io_mem_cmd_payload_last,
input io_mem_rsp_valid,
input [31:0] io_mem_rsp_payload_data,
input io_mem_rsp_payload_error,
input clk,
input reset);
reg [21:0] _zz_10_;
reg [31:0] _zz_11_;
wire _zz_12_;
wire _zz_13_;
wire _zz_14_;
wire _zz_15_;
wire _zz_16_;
wire _zz_17_;
wire _zz_18_;
wire _zz_19_;
wire _zz_20_;
wire _zz_21_;
wire [2:0] _zz_22_;
wire [0:0] _zz_23_;
wire [0:0] _zz_24_;
wire [31:0] _zz_25_;
wire [31:0] _zz_26_;
wire [31:0] _zz_27_;
wire [31:0] _zz_28_;
wire [1:0] _zz_29_;
wire [31:0] _zz_30_;
wire [1:0] _zz_31_;
wire [1:0] _zz_32_;
wire [0:0] _zz_33_;
wire [0:0] _zz_34_;
wire [2:0] _zz_35_;
wire [1:0] _zz_36_;
wire [21:0] _zz_37_;
reg _zz_1_;
reg _zz_2_;
wire haltCpu;
reg tagsReadCmd_valid;
reg [6:0] tagsReadCmd_payload;
reg tagsWriteCmd_valid;
reg [0:0] tagsWriteCmd_payload_way;
reg [6:0] tagsWriteCmd_payload_address;
reg tagsWriteCmd_payload_data_valid;
reg tagsWriteCmd_payload_data_error;
reg [19:0] tagsWriteCmd_payload_data_address;
reg tagsWriteLastCmd_valid;
reg [0:0] tagsWriteLastCmd_payload_way;
reg [6:0] tagsWriteLastCmd_payload_address;
reg tagsWriteLastCmd_payload_data_valid;
reg tagsWriteLastCmd_payload_data_error;
reg [19:0] tagsWriteLastCmd_payload_data_address;
reg dataReadCmd_valid;
reg [9:0] dataReadCmd_payload;
reg dataWriteCmd_valid;
reg [0:0] dataWriteCmd_payload_way;
reg [9:0] dataWriteCmd_payload_address;
reg [31:0] dataWriteCmd_payload_data;
reg [3:0] dataWriteCmd_payload_mask;
wire _zz_3_;
wire ways_0_tagsReadRsp_valid;
wire ways_0_tagsReadRsp_error;
wire [19:0] ways_0_tagsReadRsp_address;
wire [21:0] _zz_4_;
wire _zz_5_;
wire [31:0] ways_0_dataReadRsp;
reg [3:0] _zz_6_;
wire [3:0] stage0_mask;
wire [0:0] stage0_colisions;
reg stageA_request_wr;
reg [31:0] stageA_request_data;
reg [1:0] stageA_request_size;
reg stageA_request_isLrsc;
reg stageA_request_isAmo;
reg stageA_request_amoCtrl_swap;
reg [2:0] stageA_request_amoCtrl_alu;
reg [3:0] stageA_mask;
wire stageA_wayHits_0;
reg [0:0] stage0_colisions_regNextWhen;
wire [0:0] _zz_7_;
wire [0:0] stageA_colisions;
reg stageB_request_wr;
reg [31:0] stageB_request_data;
reg [1:0] stageB_request_size;
reg stageB_request_isLrsc;
reg stageB_isAmo;
reg stageB_request_amoCtrl_swap;
reg [2:0] stageB_request_amoCtrl_alu;
reg stageB_mmuRspFreeze;
reg [31:0] stageB_mmuRsp_physicalAddress;
reg stageB_mmuRsp_isIoAccess;
reg stageB_mmuRsp_allowRead;
reg stageB_mmuRsp_allowWrite;
reg stageB_mmuRsp_allowExecute;
reg stageB_mmuRsp_exception;
reg stageB_mmuRsp_refilling;
reg stageB_tagsReadRsp_0_valid;
reg stageB_tagsReadRsp_0_error;
reg [19:0] stageB_tagsReadRsp_0_address;
reg [31:0] stageB_dataReadRsp_0;
wire [0:0] _zz_8_;
reg [0:0] stageB_waysHits;
wire stageB_waysHit;
wire [31:0] stageB_dataMux;
reg [3:0] stageB_mask;
reg [0:0] stageB_colisions;
reg stageB_loaderValid;
reg stageB_flusher_valid;
reg stageB_lrsc_reserved;
reg [31:0] stageB_requestDataBypass;
wire stageB_amo_compare;
wire stageB_amo_unsigned;
wire [31:0] stageB_amo_addSub;
wire stageB_amo_less;
wire stageB_amo_selectRf;
reg [31:0] stageB_amo_result;
reg stageB_amo_resultRegValid;
reg [31:0] stageB_amo_resultReg;
reg stageB_memCmdSent;
wire [0:0] _zz_9_;
reg loader_valid;
reg loader_counter_willIncrement;
wire loader_counter_willClear;
reg [2:0] loader_counter_valueNext;
reg [2:0] loader_counter_value;
wire loader_counter_willOverflowIfInc;
wire loader_counter_willOverflow;
reg [0:0] loader_waysAllocator;
reg loader_error;
(* ram_style = "block" *) reg [21:0] ways_0_tags [0:127];
(* ram_style = "block" *) reg [7:0] ways_0_data_symbol0 [0:1023];
(* ram_style = "block" *) reg [7:0] ways_0_data_symbol1 [0:1023];
(* ram_style = "block" *) reg [7:0] ways_0_data_symbol2 [0:1023];
(* ram_style = "block" *) reg [7:0] ways_0_data_symbol3 [0:1023];
reg [7:0] _zz_38_;
reg [7:0] _zz_39_;
reg [7:0] _zz_40_;
reg [7:0] _zz_41_;
assign _zz_12_ = (io_cpu_execute_isValid && (! io_cpu_memory_isStuck));
assign _zz_13_ = (((stageB_mmuRsp_refilling || io_cpu_writeBack_accessError) || io_cpu_writeBack_mmuException) || io_cpu_writeBack_unalignedAccess);
assign _zz_14_ = (stageB_waysHit || (stageB_request_wr && (! stageB_isAmo)));
assign _zz_15_ = (! stageB_amo_resultRegValid);
assign _zz_16_ = (stageB_request_isLrsc && (! stageB_lrsc_reserved));
assign _zz_17_ = (loader_valid && io_mem_rsp_valid);
assign _zz_18_ = (stageB_request_isLrsc && (! stageB_lrsc_reserved));
assign _zz_19_ = ((((io_cpu_flush_valid && (! io_cpu_execute_isValid)) && (! io_cpu_memory_isValid)) && (! io_cpu_writeBack_isValid)) && (! io_cpu_redo));
assign _zz_20_ = (((! stageB_request_wr) || stageB_isAmo) && ((stageB_colisions & stageB_waysHits) != (1'b0)));
assign _zz_21_ = ((! io_cpu_writeBack_isStuck) && (! stageB_mmuRspFreeze));
assign _zz_22_ = (stageB_request_amoCtrl_alu | {stageB_request_amoCtrl_swap,(2'b00)});
assign _zz_23_ = _zz_4_[0 : 0];
assign _zz_24_ = _zz_4_[1 : 1];
assign _zz_25_ = ($signed(_zz_26_) + $signed(_zz_30_));
assign _zz_26_ = ($signed(_zz_27_) + $signed(_zz_28_));
assign _zz_27_ = stageB_request_data;
assign _zz_28_ = (stageB_amo_compare ? (~ stageB_dataMux) : stageB_dataMux);
assign _zz_29_ = (stageB_amo_compare ? _zz_31_ : _zz_32_);
assign _zz_30_ = {{30{_zz_29_[1]}}, _zz_29_};
assign _zz_31_ = (2'b01);
assign _zz_32_ = (2'b00);
assign _zz_33_ = (! stageB_lrsc_reserved);
assign _zz_34_ = loader_counter_willIncrement;
assign _zz_35_ = {2'd0, _zz_34_};
assign _zz_36_ = {loader_waysAllocator,loader_waysAllocator[0]};
assign _zz_37_ = {tagsWriteCmd_payload_data_address,{tagsWriteCmd_payload_data_error,tagsWriteCmd_payload_data_valid}};
always @ (posedge clk) begin
if(_zz_2_) begin
ways_0_tags[tagsWriteCmd_payload_address] <= _zz_37_;
end
end
always @ (posedge clk) begin
if(_zz_3_) begin
_zz_10_ <= ways_0_tags[tagsReadCmd_payload];
end
end
always @ (*) begin
_zz_11_ = {_zz_41_, _zz_40_, _zz_39_, _zz_38_};
end
always @ (posedge clk) begin
if(dataWriteCmd_payload_mask[0] && _zz_1_) begin
ways_0_data_symbol0[dataWriteCmd_payload_address] <= dataWriteCmd_payload_data[7 : 0];
end
if(dataWriteCmd_payload_mask[1] && _zz_1_) begin
ways_0_data_symbol1[dataWriteCmd_payload_address] <= dataWriteCmd_payload_data[15 : 8];
end
if(dataWriteCmd_payload_mask[2] && _zz_1_) begin
ways_0_data_symbol2[dataWriteCmd_payload_address] <= dataWriteCmd_payload_data[23 : 16];
end
if(dataWriteCmd_payload_mask[3] && _zz_1_) begin
ways_0_data_symbol3[dataWriteCmd_payload_address] <= dataWriteCmd_payload_data[31 : 24];
end
end
always @ (posedge clk) begin
if(_zz_5_) begin
_zz_38_ <= ways_0_data_symbol0[dataReadCmd_payload];
_zz_39_ <= ways_0_data_symbol1[dataReadCmd_payload];
_zz_40_ <= ways_0_data_symbol2[dataReadCmd_payload];
_zz_41_ <= ways_0_data_symbol3[dataReadCmd_payload];
end
end
always @ (*) begin
_zz_1_ = 1'b0;
if((dataWriteCmd_valid && dataWriteCmd_payload_way[0]))begin
_zz_1_ = 1'b1;
end
end
always @ (*) begin
_zz_2_ = 1'b0;
if((tagsWriteCmd_valid && tagsWriteCmd_payload_way[0]))begin
_zz_2_ = 1'b1;
end
end
assign haltCpu = 1'b0;
assign _zz_3_ = (tagsReadCmd_valid && (! io_cpu_memory_isStuck));
assign _zz_4_ = _zz_10_;
assign ways_0_tagsReadRsp_valid = _zz_23_[0];
assign ways_0_tagsReadRsp_error = _zz_24_[0];
assign ways_0_tagsReadRsp_address = _zz_4_[21 : 2];
assign _zz_5_ = (dataReadCmd_valid && (! io_cpu_memory_isStuck));
assign ways_0_dataReadRsp = _zz_11_;
always @ (*) begin
tagsReadCmd_valid = 1'b0;
if(_zz_12_)begin
tagsReadCmd_valid = 1'b1;
end
end
always @ (*) begin
tagsReadCmd_payload = (7'bxxxxxxx);
if(_zz_12_)begin
tagsReadCmd_payload = io_cpu_execute_address[11 : 5];
end
end
always @ (*) begin
dataReadCmd_valid = 1'b0;
if(_zz_12_)begin
dataReadCmd_valid = 1'b1;
end
end
always @ (*) begin
dataReadCmd_payload = (10'bxxxxxxxxxx);
if(_zz_12_)begin
dataReadCmd_payload = io_cpu_execute_address[11 : 2];
end
end
always @ (*) begin
tagsWriteCmd_valid = 1'b0;
if(stageB_flusher_valid)begin
tagsWriteCmd_valid = stageB_flusher_valid;
end
if(_zz_13_)begin
tagsWriteCmd_valid = 1'b0;
end
if(loader_counter_willOverflow)begin
tagsWriteCmd_valid = 1'b1;
end
end
always @ (*) begin
tagsWriteCmd_payload_way = (1'bx);
if(stageB_flusher_valid)begin
tagsWriteCmd_payload_way = (1'b1);
end
if(loader_counter_willOverflow)begin
tagsWriteCmd_payload_way = loader_waysAllocator;
end
end
always @ (*) begin
tagsWriteCmd_payload_address = (7'bxxxxxxx);
if(stageB_flusher_valid)begin
tagsWriteCmd_payload_address = stageB_mmuRsp_physicalAddress[11 : 5];
end
if(loader_counter_willOverflow)begin
tagsWriteCmd_payload_address = stageB_mmuRsp_physicalAddress[11 : 5];
end
end
always @ (*) begin
tagsWriteCmd_payload_data_valid = 1'bx;
if(stageB_flusher_valid)begin
tagsWriteCmd_payload_data_valid = 1'b0;
end
if(loader_counter_willOverflow)begin
tagsWriteCmd_payload_data_valid = 1'b1;
end
end
always @ (*) begin
tagsWriteCmd_payload_data_error = 1'bx;
if(loader_counter_willOverflow)begin
tagsWriteCmd_payload_data_error = (loader_error || io_mem_rsp_payload_error);
end
end
always @ (*) begin
tagsWriteCmd_payload_data_address = (20'bxxxxxxxxxxxxxxxxxxxx);
if(loader_counter_willOverflow)begin
tagsWriteCmd_payload_data_address = stageB_mmuRsp_physicalAddress[31 : 12];
end
end
always @ (*) begin
dataWriteCmd_valid = 1'b0;
if(io_cpu_writeBack_isValid)begin
if(! stageB_mmuRsp_isIoAccess) begin
if(_zz_14_)begin
if((stageB_request_wr && stageB_waysHit))begin
dataWriteCmd_valid = 1'b1;
end
if(stageB_isAmo)begin
if(_zz_15_)begin
dataWriteCmd_valid = 1'b0;
end
end
if(_zz_16_)begin
dataWriteCmd_valid = 1'b0;
end
end
end
end
if(_zz_13_)begin
dataWriteCmd_valid = 1'b0;
end
if(_zz_17_)begin
dataWriteCmd_valid = 1'b1;
end
end
always @ (*) begin
dataWriteCmd_payload_way = (1'bx);
if(io_cpu_writeBack_isValid)begin
if(! stageB_mmuRsp_isIoAccess) begin
if(_zz_14_)begin
dataWriteCmd_payload_way = stageB_waysHits;
end
end
end
if(_zz_17_)begin
dataWriteCmd_payload_way = loader_waysAllocator;
end
end
always @ (*) begin
dataWriteCmd_payload_address = (10'bxxxxxxxxxx);
if(io_cpu_writeBack_isValid)begin
if(! stageB_mmuRsp_isIoAccess) begin
if(_zz_14_)begin
dataWriteCmd_payload_address = stageB_mmuRsp_physicalAddress[11 : 2];
end
end
end
if(_zz_17_)begin
dataWriteCmd_payload_address = {stageB_mmuRsp_physicalAddress[11 : 5],loader_counter_value};
end
end
always @ (*) begin
dataWriteCmd_payload_data = (32'bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx);
if(io_cpu_writeBack_isValid)begin
if(! stageB_mmuRsp_isIoAccess) begin
if(_zz_14_)begin
dataWriteCmd_payload_data = stageB_requestDataBypass;
end
end
end
if(_zz_17_)begin
dataWriteCmd_payload_data = io_mem_rsp_payload_data;
end
end
always @ (*) begin
dataWriteCmd_payload_mask = (4'bxxxx);
if(io_cpu_writeBack_isValid)begin
if(! stageB_mmuRsp_isIoAccess) begin
if(_zz_14_)begin
dataWriteCmd_payload_mask = stageB_mask;
end
end
end
if(_zz_17_)begin
dataWriteCmd_payload_mask = (4'b1111);
end
end
always @ (*) begin
case(io_cpu_execute_args_size)
2'b00 : begin
_zz_6_ = (4'b0001);
end
2'b01 : begin
_zz_6_ = (4'b0011);
end
default : begin
_zz_6_ = (4'b1111);
end
endcase
end
assign stage0_mask = (_zz_6_ <<< io_cpu_execute_address[1 : 0]);
assign stage0_colisions[0] = (((dataWriteCmd_valid && dataWriteCmd_payload_way[0]) && (dataWriteCmd_payload_address == io_cpu_execute_address[11 : 2])) && ((stage0_mask & dataWriteCmd_payload_mask) != (4'b0000)));
assign io_cpu_memory_mmuBus_cmd_isValid = io_cpu_memory_isValid;
assign io_cpu_memory_mmuBus_cmd_virtualAddress = io_cpu_memory_address;
assign io_cpu_memory_mmuBus_cmd_bypassTranslation = 1'b0;
assign io_cpu_memory_mmuBus_end = ((! io_cpu_memory_isStuck) || io_cpu_memory_isRemoved);
assign io_cpu_memory_isWrite = stageA_request_wr;
assign stageA_wayHits_0 = ((io_cpu_memory_mmuBus_rsp_physicalAddress[31 : 12] == ways_0_tagsReadRsp_address) && ways_0_tagsReadRsp_valid);
assign _zz_7_[0] = (((dataWriteCmd_valid && dataWriteCmd_payload_way[0]) && (dataWriteCmd_payload_address == io_cpu_memory_address[11 : 2])) && ((stageA_mask & dataWriteCmd_payload_mask) != (4'b0000)));
assign stageA_colisions = (stage0_colisions_regNextWhen | _zz_7_);
always @ (*) begin
stageB_mmuRspFreeze = 1'b0;
if((stageB_loaderValid || loader_valid))begin
stageB_mmuRspFreeze = 1'b1;
end
end
assign _zz_8_[0] = stageA_wayHits_0;
assign stageB_waysHit = (stageB_waysHits != (1'b0));
assign stageB_dataMux = stageB_dataReadRsp_0;
always @ (*) begin
stageB_loaderValid = 1'b0;
if(io_cpu_writeBack_isValid)begin
if(! stageB_mmuRsp_isIoAccess) begin
if(! _zz_14_) begin
if(io_mem_cmd_ready)begin
stageB_loaderValid = 1'b1;
end
end
end
end
if(_zz_13_)begin
stageB_loaderValid = 1'b0;
end
end
always @ (*) begin
io_cpu_writeBack_haltIt = io_cpu_writeBack_isValid;
if(stageB_flusher_valid)begin
io_cpu_writeBack_haltIt = 1'b1;
end
if(io_cpu_writeBack_isValid)begin
if(stageB_mmuRsp_isIoAccess)begin
if((stageB_request_wr ? io_mem_cmd_ready : io_mem_rsp_valid))begin
io_cpu_writeBack_haltIt = 1'b0;
end
if(_zz_18_)begin
io_cpu_writeBack_haltIt = 1'b0;
end
end else begin
if(_zz_14_)begin
if(((! stageB_request_wr) || io_mem_cmd_ready))begin
io_cpu_writeBack_haltIt = 1'b0;
end
if(stageB_isAmo)begin
if(_zz_15_)begin
io_cpu_writeBack_haltIt = 1'b1;
end
end
if(_zz_16_)begin
io_cpu_writeBack_haltIt = 1'b0;
end
end
end
end
if(_zz_13_)begin
io_cpu_writeBack_haltIt = 1'b0;
end
end
always @ (*) begin
io_cpu_flush_ready = 1'b0;
if(_zz_19_)begin
io_cpu_flush_ready = 1'b1;
end
end
always @ (*) begin
stageB_requestDataBypass = stageB_request_data;
if(stageB_isAmo)begin
stageB_requestDataBypass = stageB_amo_resultReg;
end
end
assign stageB_amo_compare = stageB_request_amoCtrl_alu[2];
assign stageB_amo_unsigned = (stageB_request_amoCtrl_alu[2 : 1] == (2'b11));
assign stageB_amo_addSub = _zz_25_;
assign stageB_amo_less = ((stageB_request_data[31] == stageB_dataMux[31]) ? stageB_amo_addSub[31] : (stageB_amo_unsigned ? stageB_dataMux[31] : stageB_request_data[31]));
assign stageB_amo_selectRf = (stageB_request_amoCtrl_swap ? 1'b1 : (stageB_request_amoCtrl_alu[0] ^ stageB_amo_less));
always @ (*) begin
case(_zz_22_)
3'b000 : begin
stageB_amo_result = stageB_amo_addSub;
end
3'b001 : begin
stageB_amo_result = (stageB_request_data ^ stageB_dataMux);
end
3'b010 : begin
stageB_amo_result = (stageB_request_data | stageB_dataMux);
end
3'b011 : begin
stageB_amo_result = (stageB_request_data & stageB_dataMux);
end
default : begin
stageB_amo_result = (stageB_amo_selectRf ? stageB_request_data : stageB_dataMux);
end
endcase
end
always @ (*) begin
io_cpu_redo = 1'b0;
if(io_cpu_writeBack_isValid)begin
if(! stageB_mmuRsp_isIoAccess) begin
if(_zz_14_)begin
if(_zz_20_)begin
io_cpu_redo = 1'b1;
end
end
end
end
if((io_cpu_writeBack_isValid && stageB_mmuRsp_refilling))begin
io_cpu_redo = 1'b1;
end
if(loader_valid)begin
io_cpu_redo = 1'b1;
end
end
always @ (*) begin
io_cpu_writeBack_accessError = 1'b0;
if(stageB_mmuRsp_isIoAccess)begin
io_cpu_writeBack_accessError = (io_mem_rsp_valid && io_mem_rsp_payload_error);
end else begin
io_cpu_writeBack_accessError = ((stageB_waysHits & _zz_9_) != (1'b0));
end
end
assign io_cpu_writeBack_mmuException = (io_cpu_writeBack_isValid && ((stageB_mmuRsp_exception || ((! stageB_mmuRsp_allowWrite) && stageB_request_wr)) || ((! stageB_mmuRsp_allowRead) && ((! stageB_request_wr) || stageB_isAmo))));
assign io_cpu_writeBack_unalignedAccess = (io_cpu_writeBack_isValid && (((stageB_request_size == (2'b10)) && (stageB_mmuRsp_physicalAddress[1 : 0] != (2'b00))) || ((stageB_request_size == (2'b01)) && (stageB_mmuRsp_physicalAddress[0 : 0] != (1'b0)))));
assign io_cpu_writeBack_isWrite = stageB_request_wr;
always @ (*) begin
io_mem_cmd_valid = 1'b0;
if(io_cpu_writeBack_isValid)begin
if(stageB_mmuRsp_isIoAccess)begin
io_mem_cmd_valid = (! stageB_memCmdSent);
if(_zz_18_)begin
io_mem_cmd_valid = 1'b0;
end
end else begin
if(_zz_14_)begin
if(stageB_request_wr)begin
io_mem_cmd_valid = 1'b1;
end
if(stageB_isAmo)begin
if(_zz_15_)begin
io_mem_cmd_valid = 1'b0;
end
end
if(_zz_20_)begin
io_mem_cmd_valid = 1'b0;
end
if(_zz_16_)begin
io_mem_cmd_valid = 1'b0;
end
end else begin
if((! stageB_memCmdSent))begin
io_mem_cmd_valid = 1'b1;
end
end
end
end
if(_zz_13_)begin
io_mem_cmd_valid = 1'b0;
end
end
always @ (*) begin
io_mem_cmd_payload_address = (32'bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx);
if(io_cpu_writeBack_isValid)begin
if(stageB_mmuRsp_isIoAccess)begin
io_mem_cmd_payload_address = {stageB_mmuRsp_physicalAddress[31 : 2],(2'b00)};
end else begin
if(_zz_14_)begin
io_mem_cmd_payload_address = {stageB_mmuRsp_physicalAddress[31 : 2],(2'b00)};
end else begin
io_mem_cmd_payload_address = {stageB_mmuRsp_physicalAddress[31 : 5],(5'b00000)};
end
end
end
end
always @ (*) begin
io_mem_cmd_payload_length = (3'bxxx);
if(io_cpu_writeBack_isValid)begin
if(stageB_mmuRsp_isIoAccess)begin
io_mem_cmd_payload_length = (3'b000);
end else begin
if(_zz_14_)begin
io_mem_cmd_payload_length = (3'b000);
end else begin
io_mem_cmd_payload_length = (3'b111);
end
end
end
end