-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmini16_cpu.v
More file actions
803 lines (755 loc) · 19.9 KB
/
mini16_cpu.v
File metadata and controls
803 lines (755 loc) · 19.9 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
/*
Copyright (c) 2018, miya
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
module mini16_cpu
#(
parameter WIDTH_I = 16,
parameter WIDTH_D = 16,
parameter DEPTH_I = 8,
parameter DEPTH_D = 8,
parameter DEPTH_REG = 5,
parameter REGFILE_RAM_TYPE = "auto",
parameter ENABLE_MVIL = 1'b0,
parameter ENABLE_MUL = 1'b0,
parameter ENABLE_MULTI_BIT_SHIFT = 1'b0,
parameter ENABLE_MVC = 1'b0,
parameter ENABLE_WA = 1'b0,
parameter ENABLE_INT = 1'b0,
parameter FULL_PIPELINED_ALU = 1'b0
)
(
input clk,
input reset,
input soft_reset,
output reg [DEPTH_I-1:0] mem_i_r_addr,
input [WIDTH_I-1:0] mem_i_r_data,
output reg [DEPTH_D-1:0] mem_d_r_addr,
input [WIDTH_D-1:0] mem_d_r_data,
output reg [DEPTH_D-1:0] mem_d_w_addr,
output reg [WIDTH_D-1:0] mem_d_w_data,
output reg mem_d_we
);
localparam TRUE = 1'b1;
localparam FALSE = 1'b0;
localparam ONE = 1'd1;
localparam ZERO = 1'd0;
localparam FFFF = {WIDTH_D{1'b1}};
localparam SHIFT_BITS = $clog2(WIDTH_D);
localparam BL_OFFSET = 1'd1;
localparam DEPTH_OPERAND = 5;
// opcode
localparam I_NOP = 5'h00; // 5'b00000;
localparam I_ST = 5'h01; // 5'b00001;
localparam I_MVC = 5'h02; // 5'b00010;
localparam I_BA = 5'h04; // 5'b00100;
localparam I_BC = 5'h05; // 5'b00101;
localparam I_WA = 5'h06; // 5'b00110;
localparam I_BL = 5'h07; // 5'b00111;
localparam I_ADD = 5'h08; // 5'b01000;
localparam I_SUB = 5'h09; // 5'b01001;
localparam I_AND = 5'h0a; // 5'b01010;
localparam I_OR = 5'h0b; // 5'b01011;
localparam I_XOR = 5'h0c; // 5'b01100;
localparam I_MUL = 5'h0d; // 5'b01101;
localparam I_MV = 5'h10; // 5'b10000;
localparam I_MVIL = 5'h11; // 5'b10001;
localparam I_LD = 5'h17; // 5'b10111;
localparam I_SR = 5'h18; // 5'b11000;
localparam I_SL = 5'h19; // 5'b11001;
localparam I_SRA = 5'h1a; // 5'b11010;
localparam I_CNZ = 5'h1c; // 5'b11100;
localparam I_CNM = 5'h1d; // 5'b11101;
// special register
localparam SP_REG_CP = 0;
localparam SP_REG_MVIL = 1;
// debug
`ifdef DEBUG
reg [DEPTH_I-1:0] mem_i_r_addr_d1;
reg [DEPTH_I-1:0] mem_i_r_addr_s1;
always @(posedge clk)
begin
mem_i_r_addr_d1 <= mem_i_r_addr;
mem_i_r_addr_s1 <= mem_i_r_addr_d1;
end
`endif
// stage 1 fetch
reg [WIDTH_I-1:0] inst_s1;
wire [DEPTH_OPERAND-1:0] reg_d_s1;
wire [DEPTH_OPERAND-1:0] reg_a_s1;
wire [4:0] op_s1;
wire is_im_s1;
assign reg_d_s1 = inst_s1[15:11];
assign reg_a_s1 = inst_s1[10:6];
assign is_im_s1 = inst_s1[5];
assign op_s1 = inst_s1[4:0];
generate
if (ENABLE_WA == TRUE)
begin
always @(posedge clk)
begin
if (reset == TRUE)
begin
inst_s1 <= ZERO;
end
else
begin
if (wait_en_s2 == TRUE)
begin
inst_s1 <= ZERO;
end
else
begin
inst_s1 <= mem_i_r_data;
end
end
end
end
else
begin
always @(posedge clk)
begin
if (reset == TRUE)
begin
inst_s1 <= ZERO;
end
else
begin
inst_s1 <= mem_i_r_data;
end
end
end
endgenerate
// stage 2 wait counter
wire wait_en_s2;
reg [4:0] wait_count_m1;
reg [9:0] wait_counter_s2;
generate
if (ENABLE_WA == TRUE)
begin
assign wait_en_s2 = (wait_counter_s2 == ZERO) ? FALSE : TRUE;
always @(posedge clk)
begin
if (reset == TRUE)
begin
wait_counter_s2 <= ZERO;
wait_count_m1 <= ZERO;
end
else
begin
if (op_s1 == I_WA)
begin
wait_counter_s2 <= reg_a_s1;
wait_count_m1 <= reg_a_s1 - ONE;
end
else
begin
if (wait_en_s2 == TRUE)
begin
wait_counter_s2 <= wait_counter_s2 - ONE;
end
end
end
end
end
endgenerate
// stage 2 set reg read addr
reg [DEPTH_REG-1:0] reg_addr_a_s2;
reg [DEPTH_REG-1:0] reg_addr_b_s2;
generate
if (ENABLE_MVC == TRUE)
begin
always @(posedge clk)
begin
reg_addr_b_s2 <= reg_a_s1[DEPTH_REG-1:0];
if (op_s1 == I_MVC)
begin
reg_addr_a_s2 <= SP_REG_CP;
end
else
begin
reg_addr_a_s2 <= reg_d_s1[DEPTH_REG-1:0];
end
end
end
endgenerate
// stage 2 delay
reg [4:0] op_s2;
reg is_im_s2;
reg [DEPTH_OPERAND-1:0] reg_d_s2;
reg [DEPTH_OPERAND-1:0] reg_a_s2;
always @(posedge clk)
begin
op_s2 <= op_s1;
is_im_s2 <= is_im_s1;
reg_d_s2 <= reg_d_s1;
reg_a_s2 <= reg_a_s1;
end
// stage 3 set dest reg addr
reg [DEPTH_REG-1:0] reg_addr_d_s3;
always @(posedge clk)
begin
if (reset == TRUE)
begin
reg_addr_d_s3 <= ZERO;
end
else
begin
if ((ENABLE_MVIL == TRUE) && (op_s2 == I_MVIL))
begin
reg_addr_d_s3 <= SP_REG_MVIL;
end
else
begin
reg_addr_d_s3 <= reg_d_s2[DEPTH_REG-1:0];
end
end
end
// stage 3 delay
reg [4:0] op_s3;
reg is_im_s3;
reg [DEPTH_OPERAND-1:0] reg_a_s3;
always @(posedge clk)
begin
op_s3 <= op_s2;
is_im_s3 <= is_im_s2;
reg_a_s3 <= reg_a_s2;
end
reg [DEPTH_OPERAND-1:0] reg_d_s3;
generate
if (ENABLE_MVIL == TRUE)
begin
always @(posedge clk)
begin
reg_d_s3 <= reg_d_s2;
end
end
endgenerate
// stage 4 fetch reg_data
wire [WIDTH_D-1:0] reg_data_a_s_s3;
wire [WIDTH_D-1:0] reg_data_b_s_s3;
reg [WIDTH_D-1:0] reg_data_a_s4;
reg [WIDTH_D-1:0] reg_data_b_s4;
always @(posedge clk)
begin
reg_data_a_s4 <= reg_data_a_s_s3;
if (reset == TRUE)
begin
reg_data_b_s4 <= ZERO;
end
else
begin
if ((ENABLE_MVIL == TRUE) && (op_s3 == I_MVIL))
begin
reg_data_b_s4 <= {reg_d_s3, reg_a_s3, is_im_s3};
end
else if (is_im_s3 == TRUE)
begin
reg_data_b_s4 <= $signed(reg_a_s3);
end
else
begin
reg_data_b_s4 <= reg_data_b_s_s3;
end
end
end
// stage 4 load address
always @(posedge clk)
begin
if (reset == TRUE)
begin
mem_d_r_addr <= ZERO;
end
else
begin
if (op_s3 == I_LD)
begin
mem_d_r_addr <= reg_data_b_s_s3;
end
end
end
// stage 4 delay
reg [4:0] op_s4;
reg [DEPTH_REG-1:0] reg_addr_d_s4;
always @(posedge clk)
begin
op_s4 <= op_s3;
reg_addr_d_s4 <= reg_addr_d_s3;
end
// stage 5 execute store
always @(posedge clk)
begin
if (reset == TRUE)
begin
mem_d_w_addr <= ZERO;
mem_d_w_data <= ZERO;
mem_d_we <= FALSE;
end
else
begin
case (op_s4)
I_ST:
begin
mem_d_w_addr <= reg_data_a_s4;
mem_d_w_data <= reg_data_b_s4;
mem_d_we <= TRUE;
end
default:
begin
mem_d_w_addr <= ZERO;
mem_d_w_data <= ZERO;
mem_d_we <= FALSE;
end
endcase
end
end
// stage 5 calc BL address
reg [DEPTH_I-1:0] bl_addr_s5;
always @(posedge clk)
begin
bl_addr_s5 <= mem_i_r_addr + BL_OFFSET;
end
// stage 5 execute branch
wire cond_true_s4;
assign cond_true_s4 = (reg_data_a_s4 != ZERO) ? TRUE : FALSE;
always @(posedge clk)
begin
if (reset == TRUE)
begin
mem_i_r_addr <= ZERO;
end
else
begin
// branch
if ((ENABLE_INT == TRUE) && (soft_reset == TRUE))
begin
mem_i_r_addr <= ZERO;
end
else if ((op_s4 == I_BA) || (op_s4 == I_BL) || ((op_s4 == I_BC) && (cond_true_s4)))
begin
mem_i_r_addr <= reg_data_b_s4;
end
else if ((ENABLE_WA == TRUE) && (op_s4 == I_WA))
begin
mem_i_r_addr <= mem_i_r_addr - wait_count_m1;
end
else
begin
mem_i_r_addr <= mem_i_r_addr + ONE;
end
end
end
// stage 5 delay
reg [4:0] op_s5;
reg [DEPTH_REG-1:0] reg_addr_d_s5;
reg [WIDTH_D-1:0] reg_data_a_s5;
reg [WIDTH_D-1:0] reg_data_b_s5;
always @(posedge clk)
begin
op_s5 <= op_s4;
reg_addr_d_s5 <= reg_addr_d_s4;
reg_data_a_s5 <= reg_data_a_s4;
reg_data_b_s5 <= reg_data_b_s4;
end
reg cond_true_s5;
generate
if (ENABLE_MVC == TRUE)
begin
always @(posedge clk)
begin
cond_true_s5 <= cond_true_s4;
end
end
endgenerate
// stage 6 compare
reg flag_cnz_s6;
reg flag_cnm_s6;
always @(posedge clk)
begin
if (reg_data_b_s5 == ZERO)
begin
flag_cnz_s6 <= FALSE;
end
else
begin
flag_cnz_s6 <= TRUE;
end
if (reg_data_b_s5[WIDTH_D-1] == 1'b0)
begin
flag_cnm_s6 <= TRUE;
end
else
begin
flag_cnm_s6 <= FALSE;
end
end
// stage 6 reg we
reg reg_we_s6;
wire stage6_reg_we_cond;
generate
if (ENABLE_MVC == TRUE)
begin
assign stage6_reg_we_cond = ((op_s5[4:3] != 2'b00) || (op_s5 == I_BL) || ((op_s5 == I_MVC) && (cond_true_s5 == TRUE)));
end
else
begin
assign stage6_reg_we_cond = ((op_s5[4:3] != 2'b00) || (op_s5 == I_BL));
end
endgenerate
always @(posedge clk)
begin
if (stage6_reg_we_cond)
begin
reg_we_s6 <= TRUE;
end
else
begin
reg_we_s6 <= FALSE;
end
end
// stage 6 delay
reg [4:0] op_s6;
reg [DEPTH_REG-1:0] reg_addr_d_s6;
reg [WIDTH_D-1:0] reg_data_a_s6;
reg [WIDTH_D-1:0] reg_data_b_s6;
reg [DEPTH_I-1:0] bl_addr_s6;
always @(posedge clk)
begin
op_s6 <= op_s5;
reg_addr_d_s6 <= reg_addr_d_s5;
reg_data_a_s6 <= reg_data_a_s5;
reg_data_b_s6 <= reg_data_b_s5;
bl_addr_s6 <= bl_addr_s5;
end
// stage 6 pre-execute
reg [WIDTH_D-1:0] reg_data_add_s6;
reg [WIDTH_D-1:0] reg_data_sub_s6;
reg [WIDTH_D-1:0] reg_data_and_s6;
reg [WIDTH_D-1:0] reg_data_or_s6;
reg [WIDTH_D-1:0] reg_data_xor_s6;
generate
if (FULL_PIPELINED_ALU == TRUE)
begin
always @(posedge clk)
begin
reg_data_add_s6 <= reg_data_a_s5 + reg_data_b_s5;
reg_data_sub_s6 <= reg_data_a_s5 - reg_data_b_s5;
reg_data_and_s6 <= reg_data_a_s5 & reg_data_b_s5;
reg_data_or_s6 <= reg_data_a_s5 | reg_data_b_s5;
reg_data_xor_s6 <= reg_data_a_s5 ^ reg_data_b_s5;
end
end
endgenerate
// stage 7 execute
reg [WIDTH_D-1:0] reg_data_w_s7;
always @(posedge clk)
begin
case (op_s6)
I_ADD:
begin
if (FULL_PIPELINED_ALU == TRUE)
begin
reg_data_w_s7 <= reg_data_add_s6;
end
else
begin
reg_data_w_s7 <= reg_data_a_s6 + reg_data_b_s6;
end
end
I_SUB:
begin
if (FULL_PIPELINED_ALU == TRUE)
begin
reg_data_w_s7 <= reg_data_sub_s6;
end
else
begin
reg_data_w_s7 <= reg_data_a_s6 - reg_data_b_s6;
end
end
I_AND:
begin
if (FULL_PIPELINED_ALU == TRUE)
begin
reg_data_w_s7 <= reg_data_and_s6;
end
else
begin
reg_data_w_s7 <= reg_data_a_s6 & reg_data_b_s6;
end
end
I_OR:
begin
if (FULL_PIPELINED_ALU == TRUE)
begin
reg_data_w_s7 <= reg_data_or_s6;
end
else
begin
reg_data_w_s7 <= reg_data_a_s6 | reg_data_b_s6;
end
end
I_XOR:
begin
if (FULL_PIPELINED_ALU == TRUE)
begin
reg_data_w_s7 <= reg_data_xor_s6;
end
else
begin
reg_data_w_s7 <= reg_data_a_s6 ^ reg_data_b_s6;
end
end
I_SR:
begin
reg_data_w_s7 <= sr_result_s6;
end
I_SL:
begin
reg_data_w_s7 <= sl_result_s6;
end
I_SRA:
begin
reg_data_w_s7 <= sra_result_s6;
end
I_CNZ:
begin
reg_data_w_s7 <= {WIDTH_D{flag_cnz_s6}};
end
I_CNM:
begin
reg_data_w_s7 <= {WIDTH_D{flag_cnm_s6}};
end
I_BL:
begin
reg_data_w_s7 <= bl_addr_s6;
end
I_MUL:
begin
if (ENABLE_MUL == TRUE)
begin
reg_data_w_s7 <= mul_result_s6;
end
else
begin
reg_data_w_s7 <= reg_data_b_s6;
end
end
I_LD:
begin
reg_data_w_s7 <= mem_d_r_data;
end
// I_MV, I_MVIL
default:
begin
reg_data_w_s7 <= reg_data_b_s6;
end
endcase
end
// stage 7 delay
reg [DEPTH_REG-1:0] reg_addr_d_s7;
reg reg_we_s7;
always @(posedge clk)
begin
reg_addr_d_s7 <= reg_addr_d_s6;
reg_we_s7 <= reg_we_s6;
end
wire [DEPTH_REG-1:0] reg_file_addr_r_a;
wire [DEPTH_REG-1:0] reg_file_addr_r_b;
generate
if (ENABLE_MVC == TRUE)
begin
assign reg_file_addr_r_a = reg_addr_a_s2;
assign reg_file_addr_r_b = reg_addr_b_s2;
end
else
begin
assign reg_file_addr_r_a = reg_d_s2[DEPTH_REG-1:0];
assign reg_file_addr_r_b = reg_a_s2[DEPTH_REG-1:0];
end
endgenerate
r2w1_port_ram
#(
.DATA_WIDTH (WIDTH_D),
.ADDR_WIDTH (DEPTH_REG),
.RAM_TYPE (REGFILE_RAM_TYPE)
)
reg_file
(
.clk (clk),
.addr_r_a (reg_file_addr_r_a),
.addr_r_b (reg_file_addr_r_b),
.addr_w (reg_addr_d_s7),
.data_in (reg_data_w_s7),
.we (reg_we_s7),
.data_out_a (reg_data_a_s_s3),
.data_out_b (reg_data_b_s_s3)
);
wire [WIDTH_D-1:0] mul_result_s6;
generate
if (ENABLE_MUL == TRUE)
begin
wire signed [WIDTH_D-1:0] mul_a_s3;
wire signed [WIDTH_D-1:0] mul_b_s3;
assign mul_a_s3 = reg_data_a_s_s3;
assign mul_b_s3 = (is_im_s3 == TRUE) ? $signed(reg_a_s3) : reg_data_b_s_s3;
delayed_mul
#(
.WIDTH_D (WIDTH_D)
)
delayed_mul_0
(
.clk (clk),
.a (mul_a_s3),
.b (mul_b_s3),
.out (mul_result_s6)
);
end
endgenerate
wire [WIDTH_D-1:0] sr_result_s6;
wire [WIDTH_D-1:0] sl_result_s6;
wire [WIDTH_D-1:0] sra_result_s6;
reg [WIDTH_D-1:0] sr_result_s6_reg;
reg [WIDTH_D-1:0] sl_result_s6_reg;
reg [WIDTH_D-1:0] sra_result_s6_reg;
generate
if (ENABLE_MULTI_BIT_SHIFT == TRUE)
begin
delayed_sr
#(
.WIDTH_D (WIDTH_D),
.SHIFT_BITS (SHIFT_BITS)
)
delayed_sr_0
(
.clk (clk),
.a (reg_data_a_s4),
.b (reg_data_b_s4[SHIFT_BITS-1:0]),
.out (sr_result_s6)
);
delayed_sl
#(
.WIDTH_D (WIDTH_D),
.SHIFT_BITS (SHIFT_BITS)
)
delayed_sl_0
(
.clk (clk),
.a (reg_data_a_s4),
.b (reg_data_b_s4[SHIFT_BITS-1:0]),
.out (sl_result_s6)
);
delayed_sra
#(
.WIDTH_D (WIDTH_D),
.SHIFT_BITS (SHIFT_BITS)
)
delayed_sra_0
(
.clk (clk),
.a (reg_data_a_s4),
.b (reg_data_b_s4[SHIFT_BITS-1:0]),
.out (sra_result_s6)
);
end
else
begin
always @(posedge clk)
begin
sr_result_s6_reg <= {1'b0, reg_data_a_s5[WIDTH_D-1:1]};
sl_result_s6_reg <= {reg_data_a_s5[WIDTH_D-2:0], 1'b0};
sra_result_s6_reg <= {reg_data_a_s5[WIDTH_D-1], reg_data_a_s5[WIDTH_D-1:1]};
end
assign sr_result_s6 = sr_result_s6_reg;
assign sl_result_s6 = sl_result_s6_reg;
assign sra_result_s6 = sra_result_s6_reg;
end
endgenerate
endmodule
module delayed_mul
#(
parameter WIDTH_D = 16
)
(
input clk,
input signed [WIDTH_D-1:0] a,
input signed [WIDTH_D-1:0] b,
output reg signed [WIDTH_D-1:0] out
);
reg signed [WIDTH_D-1:0] sa;
reg signed [WIDTH_D-1:0] sb;
reg signed [WIDTH_D-1:0] out1;
always @(posedge clk)
begin
sa <= a;
sb <= b;
out1 <= sa * sb;
out <= out1;
end
endmodule
module delayed_sr
#(
parameter WIDTH_D = 16,
parameter SHIFT_BITS = 4
)
(
input clk,
input [WIDTH_D-1:0] a,
input [SHIFT_BITS-1:0] b,
output reg [WIDTH_D-1:0] out
);
reg [WIDTH_D-1:0] sa;
reg [SHIFT_BITS-1:0] sb;
always @(posedge clk)
begin
sa <= a;
sb <= b;
out <= sa >> sb;
end
endmodule
module delayed_sl
#(
parameter WIDTH_D = 16,
parameter SHIFT_BITS = 4
)
(
input clk,
input [WIDTH_D-1:0] a,
input [SHIFT_BITS-1:0] b,
output reg [WIDTH_D-1:0] out
);
reg [WIDTH_D-1:0] sa;
reg [SHIFT_BITS-1:0] sb;
always @(posedge clk)
begin
sa <= a;
sb <= b;
out <= sa << sb;
end
endmodule
module delayed_sra
#(
parameter WIDTH_D = 16,
parameter SHIFT_BITS = 4
)
(
input clk,
input [WIDTH_D-1:0] a,
input [SHIFT_BITS-1:0] b,
output reg [WIDTH_D-1:0] out
);
reg signed [WIDTH_D-1:0] sa;
reg [SHIFT_BITS-1:0] sb;
always @(posedge clk)
begin
sa <= a;
sb <= b;
out <= sa >>> sb;
end
endmodule