-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIEEE64_design.sv
3207 lines (2590 loc) · 92.3 KB
/
IEEE64_design.sv
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
`timescale 1ps/1fs
module clk_div
#(parameter
THRESHOLD=24// divides i_clk by 24 to obtain ck_stb which is the divided clock signal
)
(i_clk, ck_stb);
input i_clk;
output reg ck_stb = 0;
reg [($clog2(THRESHOLD >> 1)-1):0] counter = 0;
reg counter_reset = 0;
//output reg ck_stb = 0;
always @(posedge i_clk)
counter_reset <= (counter == (THRESHOLD >> 1) - 1'b1);
always @(posedge i_clk)
begin
if(counter_reset)
counter <= 1;
else
counter <= counter + 1;
end
always @(posedge i_clk)
if(counter_reset)
ck_stb <= ~ck_stb;
endmodule
//Clock generator module
module clk_gen
#(
parameter THRESHOLD_FOR_CLOCK = 24
)
(clk_0_1ps,clk_out);
input clk_0_1ps;
output clk_out;
// reg clk_0_1ns;
wire clk_out;
clk_div #(.THRESHOLD(THRESHOLD_FOR_CLOCK)) cd (.i_clk(clk_0_1ps), .ck_stb(clk_out));
endmodule
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//File Name: Multiplication.v
//Created By: Sheetal Swaroop Burada
//Date: 62-04-2019
//Project Name: Design of 64 Bit Floating Point ALU Based on Standard IEEE-754 in Verilog and its implementation on FPGA.
//University: Dayalbagh Educational Institute
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
module Multiplication64(
input clk,
input [63:0] a_operand,
input [63:0] b_operand,
output reg Exception,Overflow,Underflow,
output reg [63:0] result
);
reg sign,product_round,normalised,zero;
reg [11:0] exponent,sum_exponent;
reg [51:0] product_mantissa;
reg [52:0] operand_a,operand_b;
reg [105:0] product,product_normalised;
wire sign1,product_round1,normalised1,zero1;////
wire [11:0] exponent1,sum_exponent1;//
wire [51:0] product_mantissa1;
wire [52:0] operand_a1,operand_b1;//
wire [105:0] product1,product_normalised1;//
wire Exception1,Overflow1,Underflow1;//
wire [63:0] result1;
reg [63:0] res1,res2,res3;
assign sign1 = a_operand[63] ^ b_operand[63];
//Exception flag sets 1 if either one of the exponent is 255.
assign Exception1 = (&a_operand[62:52]) | (&b_operand[62:52]);
//Assigining significand values according to Hidden Bit.
//If exponent is equal to zero then hidden bit will be 0 for that respective significand else it will be 1
assign operand_a1 = (|a_operand[62:52]) ? {1'b1,a_operand[51:0]} : {1'b0,a_operand[51:0]};
assign operand_b1 = (|b_operand[62:52]) ? {1'b1,b_operand[51:0]} : {1'b0,b_operand[51:0]};
assign product1 = operand_a * operand_b; //Calculating Product
assign product_round1 = |product_normalised[51:0]; //Ending 51 bits are OR'ed for rounding operation.
assign normalised1 = product[105] ? 1'b1 : 1'b0;
assign product_normalised1 = normalised ? product : product << 1; //Assigning Normalised value based on 48th bit
//Final Manitssa.
assign product_mantissa1 = product_normalised[104:53] + {50'b0,(product_normalised[52] & product_round)};
assign zero1 = Exception ? 1'b0 : (product_mantissa == 52'd0) ? 1'b1 : 1'b0;
assign sum_exponent1 = a_operand[62:52] + b_operand[62:52];
assign exponent1 = sum_exponent - 11'd1023 + normalised;
assign Overflow1 = ((exponent[11] & !exponent[10]) & !zero) ; //If overall exponent is greater than 2047 then Overflow condition.
//Exception Case when exponent reaches its maximu value that is 384.
//If sum of both exponents is less than 127 then Underflow condition.
assign Underflow1 = ((exponent[11] & exponent[10]) & !zero) ? 1'b1 : 1'b0;
assign result1 = Exception ? 64'd0 : zero ? {sign,63'd0} : Overflow ? {sign,11'b11111111111,52'd0} : Underflow ? {sign,63'd0} : {sign,exponent[10:0],product_mantissa};
always@(posedge clk)
begin
sign<=sign1;
Exception<=Exception1;
operand_a<=operand_a1;
operand_b<=operand_b1;
product<=product1;
product_round<=product_round1;
normalised<=normalised1;
product_normalised<=product_normalised1;
product_mantissa<=product_mantissa1;
zero<=zero1;
sum_exponent<=sum_exponent1;
exponent<=exponent1;
Overflow<=Overflow1;
Underflow<=Underflow1;
res1<=result1;
res2<=res1;
res3<=res2;
result<=res3;
end
endmodule
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//File Name: Iteration.v
//Created By: Sheetal Swaroop Burada
//Date: 62-04-2019
//Project Name: Design of 64 Bit Floating Point ALU Based on Standard IEEE-754 in Verilog and its implementation on FPGA.
//University: Dayalbagh Educational Institute
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
module Iteration64(
input clk,
input [63:0] operand_1,
input [63:0] operand_2,
output reg [63:0] solution
);
wire [63:0] Intermediate_Value11,Intermediate_Value2;
wire [63:0] solution1;
reg [63:0] Intermediate_Value1;
Multiplication64 M1(clk,operand_1,operand_2,,,,Intermediate_Value11);
//64'h4000_0000 -> 2.
Addition_Subtraction64 A1(clk,64'b0100000000000000000000000000000000000000000000000000000000000000,{1'b1,Intermediate_Value1[62:0]},1'b0,,Intermediate_Value2);
Multiplication64 M2(clk,operand_1,Intermediate_Value2,,,,solution1);
always@(posedge clk)
begin
Intermediate_Value1<=Intermediate_Value11;
solution<=solution1;
end
endmodule
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//File Name: Additon_Subtraction.v
//Created By: Sheetal Swaroop Burada
//Date: 62-04-2019
//Project Name: Design of 64 Bit Floating Point ALU Based on Standard IEEE-754 in Verilog and its implementation on FPGA.
//University: Dayalbagh Educational Institute
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
module Addition_Subtraction64(
input clk,
input [63:0] a_operand,b_operand, //Inputs in the format of IEEE-754 Representation.
input AddBar_Sub, //If Add_Sub is low then Addition else Subtraction.
output reg Exception,
output reg [63:0] result //Outputs in the format of IEEE-754 Representation.
);
reg operation_sub_addBar;
wire Comp_enable;
reg output_sign;
wire [63:0] operand_a,operand_b;
reg [52:0] significand_a,significand_b;
reg [10:0] exponent_diff;
reg [52:0] significand_b_add_sub;
reg [10:0] exponent_b_add_sub;
reg [53:0] significand_add;
wire [62:0] add_sum;
reg [52:0] significand_sub_complement;
reg [53:0] significand_sub;
wire [62:0] sub_diff;
reg [53:0] subtraction_diff;
reg [10:0] exponent_sub;
wire operation_sub_addBar1;
wire Comp_enable1;
wire output_sign1;
wire [63:0] operand_a1,operand_b1;
wire [52:0] significand_a1,significand_b1;
wire [10:0] exponent_diff1;
wire [52:0] significand_b_add_sub1;
wire [10:0] exponent_b_add_sub1;
wire [53:0] significand_add1;
wire [62:0] add_sum1;
wire [52:0] significand_sub_complement1;
wire [53:0] significand_sub1;
wire [62:0] sub_diff1;
wire [53:0] subtraction_diff1;
wire [10:0] exponent_sub1;
wire Exception1;
wire [63:0] result1;
wire perform;
wire [10:0] exp_a,exp_b;
//for operations always operand_a must not be less than b_operand
assign {Comp_enable,operand_a,operand_b} = (a_operand[62:0] < b_operand[62:0]) ? {1'b1,b_operand,a_operand} : {1'b0,a_operand,b_operand};
assign exp_a = operand_a[62:52];
assign exp_b = operand_b[62:52];
//Exception flag sets 1 if either one of the exponent is 255.
assign Exception1 = (&operand_a[62:52]) | (&operand_b[62:52]);
assign output_sign1 = AddBar_Sub ? Comp_enable ? !operand_a[63] : operand_a[63] : operand_a[63] ;
assign operation_sub_addBar1 = AddBar_Sub ? operand_a[63] ^ operand_b[63] : ~(operand_a[63] ^ operand_b[63]);
//Assigining significand values according to Hidden Bit.
//If exponent is equal to zero then hidden bit will be 0 for that respective significand else it will be 1
assign significand_a1 = (|operand_a[62:52]) ? {1'b1,operand_a[51:0]} : {1'b0,operand_a[51:0]};
assign significand_b1 = (|operand_b[62:52]) ? {1'b1,operand_b[51:0]} : {1'b0,operand_b[51:0]};
//Evaluating Exponent Difference
assign exponent_diff1 = operand_a[62:52] - operand_b[62:52];
//Shifting significand_b according to exponent_diff
assign significand_b_add_sub1 = significand_b >> exponent_diff;
assign exponent_b_add_sub1 = operand_b[62:52] + exponent_diff;
//Checking exponents are same or not
assign perform = (operand_a[62:52] == exponent_b_add_sub);
///////////////////////////////////////////////////////////////////////////////////////////////////////
//------------------------------------------------ADD BLOCK------------------------------------------//
assign significand_add1 = (perform & operation_sub_addBar) ? (significand_a + significand_b_add_sub) : 25'd0;
//Result will be equal to Most 52 bits if carry generates else it will be Least 51 bits.
assign add_sum[51:0] = significand_add[53] ? significand_add[52:1] : significand_add[51:0];
//If carry generates in sum value then exponent must be added with 1 else feed as it is.
assign add_sum[62:52] = significand_add[53] ? (1'b1 + operand_a[62:52]) : operand_a[62:52];
///////////////////////////////////////////////////////////////////////////////////////////////////////
//------------------------------------------------SUB BLOCK------------------------------------------//
assign significand_sub_complement1 = (perform & !operation_sub_addBar) ? ~(significand_b_add_sub) + 53'd1 : 53'd0 ;
assign significand_sub1 = perform ? (significand_a + significand_sub_complement) : 25'd0;
priority_encoder64 pe(significand_sub,operand_a[62:52],subtraction_diff,exponent_sub);
assign sub_diff[62:52] = exponent_sub;
assign sub_diff[51:0] = subtraction_diff[51:0];
///////////////////////////////////////////////////////////////////////////////////////////////////////
//-------------------------------------------------OUTPUT--------------------------------------------//
//If there is no exception and operation will evaluate
assign result1 = Exception ? 64'b0 : ((!operation_sub_addBar) ? {output_sign,sub_diff} : {output_sign,add_sum});
always@(posedge clk)
begin
Exception<=Exception1;
output_sign<=output_sign1;
operation_sub_addBar<=operation_sub_addBar1;
significand_a<=significand_a1;
significand_b<=significand_b1;
exponent_diff<=exponent_diff1;
significand_b_add_sub<=significand_b_add_sub1;
exponent_b_add_sub<=exponent_b_add_sub1;
significand_add<=significand_add1;
significand_sub_complement<=significand_sub_complement1;
significand_sub<=significand_sub1;
result<=result1;
end
endmodule
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//File Name: Priority Encoder.v
//Created By: Sheetal Swaroop Burada
//Date: 62-04-2019
//Project Name: Design of 64 Bit Floating Point ALU Based on Standard IEEE-754 in Verilog and its implementation on FPGA.
//University: Dayalbagh Educational Institute
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
module priority_encoder64(
input [53:0] significand,
input [10:0] Exponent_a,
output reg [53:0] Significand,
output [10:0] Exponent_sub
);
reg [5:0] shift;
always @(significand)
begin
casex (significand)
54'b1_1xxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_x : begin
Significand = significand;
shift = 5'd0;
end
54'b1_01xx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_x : begin
Significand = significand << 1;
shift = 5'd1;
end
54'b1_001x_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_x : begin
Significand = significand << 2;
shift = 5'd2;
end
54'b1_0001_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_x : begin
Significand = significand << 3;
shift = 5'd3;
end
54'b1_0000_1xxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_x : begin
Significand = significand << 4;
shift = 5'd4;
end
54'b1_0000_01xx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_x : begin
Significand = significand << 5;
shift = 5'd5;
end
54'b1_0000_001x_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_x : begin // 53'h020000
Significand = significand << 6;
shift = 5'd6;
end
54'b1_0000_0001_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_x : begin // 53'h010000
Significand = significand << 7;
shift = 5'd7;
end
54'b1_0000_0000_1xxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_x : begin // 53'h008000
Significand = significand << 8;
shift = 5'd8;
end
54'b1_0000_0000_01xx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_x : begin // 53'h004000
Significand = significand << 9;
shift = 5'd9;
end
54'b1_0000_0000_001x_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_x : begin // 53'h002000
Significand = significand << 10;
shift = 5'd10;
end
54'b1_0000_0000_0001_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_x : begin // 53'h001000
Significand = significand << 11;
shift = 5'd11;
end
54'b1_0000_0000_0000_1xxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_x : begin // 53'h000800
Significand = significand << 12;
shift = 5'd12;
end
54'b1_0000_0000_0000_01xx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_x : begin // 53'h000400
Significand = significand << 13;
shift = 5'd13;
end
54'b1_0000_0000_0000_001x_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_x : begin // 53'h000200
Significand = significand << 14;
shift = 5'd14;
end
54'b1_0000_0000_0000_0001_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_x : begin // 53'h000100
Significand = significand << 15;
shift = 5'd15;
end
54'b1_0000_0000_0000_0000_1xxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_x : begin // 53'h000080
Significand = significand << 16;
shift = 5'd16;
end
54'b1_0000_0000_0000_0000_01xx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_x : begin // 53'h000040
Significand = significand << 17;
shift = 5'd17;
end
54'b1_0000_0000_0000_0000_001x_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_x : begin // 53'h000020
Significand = significand << 18;
shift = 5'd18;
end
54'b1_0000_0000_0000_0000_0001_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_x : begin // 53'h000010
Significand = significand << 19;
shift = 5'd19;
end
54'b1_0000_0000_0000_0000_0000_1xxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_x : begin // 53'h000008
Significand = significand << 20;
shift = 5'd20;
end
54'b1_0000_0000_0000_0000_0000_01xx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_x : begin // 53'h000004
Significand = significand << 21;
shift = 5'd21;
end
54'b1_0000_0000_0000_0000_0000_001x_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_x : begin // 53'h000002
Significand = significand << 22;
shift = 5'd22;
end
54'b1_0000_0000_0000_0000_0000_0001_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_x : begin // 53'h000001
Significand = significand << 23;
shift = 5'd23;
end
54'b1_0000_0000_0000_0000_0000_0000_1xxx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_x : begin // 53'h000000
Significand = significand << 24;
shift = 5'd24;
end
54'b1_0000_0000_0000_0000_0000_0000_01xx_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_x : begin
Significand = significand << 25;
shift = 5'd25;
end
54'b1_0000_0000_0000_0000_0000_0000_001x_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_x : begin
Significand = significand << 26;
shift = 5'd26;
end
54'b1_0000_0000_0000_0000_0000_0000_0001_xxxx_xxxx_xxxx_xxxx_xxxx_xxxx_x : begin
Significand = significand << 27;
shift = 5'd27;
end
54'b1_0000_0000_0000_0000_0000_0000_0000_1xxx_xxxx_xxxx_xxxx_xxxx_xxxx_x : begin
Significand = significand << 28;
shift = 5'd28;
end
54'b1_0000_0000_0000_0000_0000_0000_0000_01xx_xxxx_xxxx_xxxx_xxxx_xxxx_x : begin
Significand = significand << 29;
shift = 5'd29;
end
54'b1_0000_0000_0000_0000_0000_0000_0000_001x_xxxx_xxxx_xxxx_xxxx_xxxx_x : begin
Significand = significand << 30;
shift = 5'd30;
end
54'b1_0000_0000_0000_0000_0000_0000_0000_0001_xxxx_xxxx_xxxx_xxxx_xxxx_x : begin // 53'h020000
Significand = significand << 31;
shift = 5'd31;
end
54'b1_0000_0000_0000_0000_0000_0000_0000_0000_1xxx_xxxx_xxxx_xxxx_xxxx_x : begin // 53'h010000
Significand = significand << 32;
shift = 5'd32;
end
54'b1_0000_0000_0000_0000_0000_0000_0000_0000_01xx_xxxx_xxxx_xxxx_xxxx_x : begin // 53'h008000
Significand = significand << 33;
shift = 5'd33;
end
54'b1_0000_0000_0000_0000_0000_0000_0000_0000_001x_xxxx_xxxx_xxxx_xxxx_x : begin // 53'h004000
Significand = significand <<34;
shift = 5'd34;
end
54'b1_0000_0000_0000_0000_0000_0000_0000_0000_0001_xxxx_xxxx_xxxx_xxxx_x : begin // 53'h002000
Significand = significand << 35;
shift = 5'd35;
end
54'b1_0000_0000_0000_0000_0000_0000_0000_0000_0000_1xxx_xxxx_xxxx_xxxx_x : begin // 53'h001000
Significand = significand << 36;
shift = 5'd36;
end
54'b1_0000_0000_0000_0000_0000_0000_0000_0000_0000_01xx_xxxx_xxxx_xxxx_x : begin // 53'h000800
Significand = significand << 37;
shift = 5'd37;
end
54'b1_0000_0000_0000_0000_0000_0000_0000_0000_0000_001x_xxxx_xxxx_xxxx_x : begin // 53'h000400
Significand = significand << 38;
shift = 5'd38;
end
54'b1_0000_0000_0000_0000_0000_0000_0000_0000_0000_0001_xxxx_xxxx_xxxx_x : begin // 53'h000200
Significand = significand << 39;
shift = 5'd39;
end
54'b1_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_1xxx_xxxx_xxxx_x : begin // 53'h000100
Significand = significand << 40;
shift = 5'd40;
end
54'b1_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_01xx_xxxx_xxxx_x : begin // 53'h000080
Significand = significand << 41;
shift = 5'd41;
end
54'b1_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_001x_xxxx_xxxx_x : begin // 53'h000040
Significand = significand << 42;
shift = 5'd42;
end
54'b1_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0001_xxxx_xxxx_x : begin // 53'h000020
Significand = significand << 43;
shift = 5'd43;
end
54'b1_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_1xxx_xxxx_x : begin // 53'h000010
Significand = significand << 44;
shift = 5'd44;
end
54'b1_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_01xx_xxxx_x : begin // 53'h000008
Significand = significand << 45;
shift = 5'd45;
end
54'b1_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_001x_xxxx_x : begin // 53'h000004
Significand = significand << 46;
shift = 5'd46;
end
54'b1_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0001_xxxx_x : begin // 53'h000002
Significand = significand << 47;
shift = 5'd47;
end
54'b1_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_1xxx_x : begin // 53'h000001
Significand = significand << 48;
shift = 5'd48;
end
54'b1_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_01xx_x : begin // 53'h000000
Significand = significand << 49;
shift = 5'd49;
end
54'b1_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_001x_x : begin // 53'h000000
Significand = significand << 50;
shift = 5'd50;
end
54'b1_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0001_x : begin // 53'h000000
Significand = significand << 51;
shift = 5'd51;
end
54'b1_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_1 : begin // 53'h000000
Significand = significand << 52;
shift = 5'd52;
end
54'b1_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0000_0 : begin // 53'h000000
Significand = significand << 53;
shift = 5'd53;
end
default : begin
Significand = (~significand) + 1'b1;
shift = 11'd0;
end
endcase
end
assign Exponent_sub = Exponent_a - shift;
endmodule
// Code your design here
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//File Name: Division.v
//Created By: Sheetal Swaroop Burada
//Date: 62-04-2019
//Project Name: Design of 64 Bit Floating Point ALU Based on Standard IEEE-754 in Verilog and its implementation on FPGA.
//University: Dayalbagh Educational Institute
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
module Division64(
input clk,
input [63:0] a_operand,
input [63:0] b_operand,
output Exception,
output [63:0] result
);
wire sign1;
wire [10:0] shift1;
wire [10:0] exponent_a1;
wire [63:0] divisor1;
wire [63:0] operand_a1;
wire [63:0] Intermediate_X01;
wire [63:0] Iteration_X01;
wire [63:0] Iteration_X11;
wire [63:0] Iteration_X21;
wire [63:0] Iteration_X31;
wire [63:0] solution1;
wire [63:0] denominator1;
wire [63:0] operand_a_change1;
reg sign;//
reg [10:0] shift;//
reg [10:0] exponent_a;//
reg [63:0] divisor;//
reg [63:0] operand_a;//
reg [63:0] Intermediate_X0;//
reg [63:0] Iteration_X0;//
reg [63:0] Iteration_X1;//
reg [63:0] Iteration_X2;//
reg [63:0] Iteration_X3;//
reg [63:0] solution;//
reg [63:0] denominator;//
reg [63:0] operand_a_change;//
assign Exception = (&a_operand[62:52]) | (&b_operand[62:52]);
assign sign1 = a_operand[63] ^ b_operand[63];
assign shift1 = 11'd1022 - b_operand[62:52];
assign divisor1 = {1'b0,11'd1022,b_operand[51:0]};
assign denominator1 = divisor;
assign exponent_a1 = a_operand[62:52] + shift;
assign operand_a1 = {a_operand[63],exponent_a,a_operand[51:0]};
assign operand_a_change1 = operand_a;
//64'hC00B_4B4B = (-37)/17
Multiplication64 x0(clk,64'b1100000000000001011010010110100101101001101001100000101111101101,divisor,,,,Intermediate_X01);
//64'h4034_B4B5 = 48/17
Addition_Subtraction64 X0(clk,Intermediate_X0,64'b0100000000000110100101101001011010010110010110011111010000010010,1'b0,,Iteration_X01);
Iteration64 X1(clk,Iteration_X0,divisor,Iteration_X11);
Iteration64 X2(clk,Iteration_X1,divisor,Iteration_X21);
Iteration64 X3(clk,Iteration_X2,divisor,Iteration_X31);
Multiplication64 END(clk,Iteration_X3,operand_a,,,,solution1);
always@(posedge clk)
begin
sign<=sign1;
shift<=shift1;
divisor<=divisor1;
denominator<=denominator1;
exponent_a<=exponent_a1;
operand_a<=operand_a1;
operand_a_change<=operand_a_change1;
Intermediate_X0<=Intermediate_X01;
Iteration_X0<=Iteration_X01;
Iteration_X1<=Iteration_X11;
Iteration_X2<=Iteration_X21;
Iteration_X3<=Iteration_X31;
solution<=solution1;
end
assign result = {sign,solution[62:0]};
endmodule
// Code your design here
/* Name: Suhas Sunil Raut SJSU ID: 011432980
Verilog Code For IEEE 754 Single Precision (32 bit) Floating Point Adder
This is a reduced complexity floating point adder.
NaN, overflow, underflow and infinity values not processed
Format for IEEE 754 SP FP:
S Exp Mantissa
31 30:23 22:0
Note: Number = 0 for exp=0 and mantissa=0
*/
module fpadd64( input reset, input [63:0]Number1, input [63:0]Number2,input clk, output [63:0]Result);
reg [63:0] Num_shift_80,Num_shift_pipe2_80;
reg [10:0] Larger_exp_80,Larger_exp_pipe1_80,Larger_exp_pipe2_80,Larger_exp_pipe3_80,Larger_exp_pipe4_80,Larger_exp_pipe5_80,Final_expo_80;
reg [51:0] Small_exp_mantissa_80,Small_exp_mantissa_pipe2_80,S_exp_mantissa_pipe2_80,S_exp_mantissa_pipe3_80,Small_exp_mantissa_pipe3_80;
reg [51:0] S_mantissa_80,L_mantissa_80;
reg [51:0] L1_mantissa_pipe2_80,L1_mantissa_pipe3_80,Large_mantissa_80,Final_mant_80;
reg [51:0] Large_mantissa_pipe2_80,Large_mantissa_pipe3_80,S_mantissa_pipe4_80,L_mantissa_pipe4_80;
reg [52:0] Add_mant_80,Add1_mant_80,Add_mant_pipe5_80;
reg [10:0] e1_80,e1_pipe1_80,e1_pipe2_80,e1_pipe3_80,e1_pipe4_80,e1_pipe5_80;
reg [10:0] e2_80,e2_pipe1_80,e2_pipe2_80,e2_pipe3_80,e2_pipe4_80,e2_pipe5_80;
reg [51:0] m1_80,m1_pipe1_80,m1_pipe2_80,m1_pipe3_80,m1_pipe4_80,m1_pipe5_80;
reg [51:0] m2_80,m2_pipe1_80,m2_pipe2_80,m2_pipe3_80,m2_pipe4_80,m2_pipe5_80;
reg s1_80,s2_80,Final_sign_80,s1_pipe1_80,s1_pipe2_80,s1_pipe3_80,s1_pipe4_80,s1_pipe5_80;
reg s2_pipe1_80,s2_pipe2_80,s2_pipe3_80,s2_pipe4_80,s2_pipe5_80;
reg [4:0] renorm_shift_80,renorm_shift_pipe5_80;
integer signed renorm_exp_80;
//:w
//reg [3:0] renorm_exp_80,renorm_exp_pipe5_80;
reg [63:0] Result_80;
assign Result = Result_80;
always @(*) begin
///////////////////////// Combinational stage1 ///////////////////////////
e1_80 = Number1[62:52];
e2_80 = Number2[62:52];
m1_80 = Number1[51:0];
m2_80 = Number2[51:0];
s1_80 = Number1[63];
s2_80 = Number2[63];
if (e1_80 > e2_80) begin
Num_shift_80 = e1_80 - e2_80; // determine number of mantissa shift
Larger_exp_80 = e1_80; // store higher exponent
Small_exp_mantissa_80 = m2_80;
Large_mantissa_80 = m1_80;
end
else begin
Num_shift_80 = e2_80 - e1_80;
Larger_exp_80 = e2_80;
Small_exp_mantissa_80 = m1_80;
Large_mantissa_80 = m2_80;
end
if (e1_80 == 0 | e2_80 ==0) begin
Num_shift_80 = 0;
end
else begin
Num_shift_80 = Num_shift_80;
end
///////////////////////// Combinational stage2 ///////////////////////////
//right shift mantissa of smaller exponent
if (e1_pipe2_80 != 0) begin
S_exp_mantissa_pipe2_80 = {1'b1,Small_exp_mantissa_pipe2_80[51:1]};
S_exp_mantissa_pipe2_80 = (S_exp_mantissa_pipe2_80 >> Num_shift_pipe2_80);
end
else begin
S_exp_mantissa_pipe2_80 = Small_exp_mantissa_pipe2_80;
end
if (e2_80!= 0) begin
L1_mantissa_pipe2_80 = {1'b1,Large_mantissa_pipe2_80[51:1]};
end
else begin
L1_mantissa_pipe2_80 = Large_mantissa_pipe2_80;
end
///////////////////////// Combinational stage3 ///////////////////////////
//compare which is smaller mantissa
if (S_exp_mantissa_pipe3_80 < L1_mantissa_pipe3_80) begin
S_mantissa_80 = S_exp_mantissa_pipe3_80;
L_mantissa_80 = L1_mantissa_pipe3_80;
end
else begin
S_mantissa_80 = L1_mantissa_pipe3_80;
L_mantissa_80 = S_exp_mantissa_pipe3_80;
end
///////////////////////// Combinational stage4 ///////////////////////////
//add the two mantissa's
if (e1_pipe4_80!=0 & e2_pipe4_80!=0) begin
if (s1_pipe4_80 == s2_pipe4_80) begin
Add_mant_80 = S_mantissa_pipe4_80 + L_mantissa_pipe4_80;
end else begin
Add_mant_80 = L_mantissa_pipe4_80 - S_mantissa_pipe4_80;
end
end
else begin
Add_mant_80 = L_mantissa_pipe4_80;
end
//determine shifts for renormalization for mantissa and exponent
if (Add_mant_80[52]) begin
renorm_shift_80 = 5'd1;
renorm_exp_80 = 5'd1;
end
else if (Add_mant_80[51])begin
renorm_shift_80 = 5'd2;
renorm_exp_80 = 0;
end
else if (Add_mant_80[50])begin
renorm_shift_80 = 5'd3;
renorm_exp_80 = -1;
end
else if (Add_mant_80[49])begin
renorm_shift_80 = 5'd4;
renorm_exp_80 = -2;
end
else if (Add_mant_80[48])begin
renorm_shift_80 = 5'd5;
renorm_exp_80 = -3;
end
else if (Add_mant_80[47])begin
renorm_shift_80 = 5'd6;
renorm_exp_80 = -4;
end
else if (Add_mant_80[46])begin
renorm_shift_80 = 5'd7;
renorm_exp_80 = -5;
end
else if (Add_mant_80[45])begin
renorm_shift_80 = 5'd8;
renorm_exp_80 = -6;
end
else if (Add_mant_80[44])begin
renorm_shift_80 = 5'd9;
renorm_exp_80 = -7;
end
else begin
renorm_exp_80 = 0;
end
///////////////////////// Combinational stage5 /////////////////////////////
//Shift the mantissa as required; re-normalize exp; determine sign
Final_expo_80 = Larger_exp_pipe5_80 + renorm_exp_80;
if (renorm_shift_pipe5_80 != 0) begin
Add1_mant_80 = Add_mant_pipe5_80 << renorm_shift_pipe5_80;
end
else begin
Add1_mant_80 = Add_mant_pipe5_80;
end
Final_mant_80 = Add1_mant_80[52:1];
if (s1_pipe5_80 == s2_pipe5_80) begin
Final_sign_80 = s1_pipe5_80;
end
if (e1_pipe5_80 > e2_pipe5_80) begin
Final_sign_80 = s1_pipe5_80;
end else if (e2_80 > e1_80) begin
Final_sign_80 = s2_pipe5_80;
end
else begin
if (m1_pipe5_80 > m2_pipe5_80) begin
Final_sign_80 = s1_pipe5_80;
end else begin
Final_sign_80 = s2_pipe5_80;
end
end
Result_80 = {Final_sign_80,Final_expo_80,Final_mant_80};
end
always @(posedge clk) begin
if(reset) begin //reset all reg at reset signal
s1_pipe2_80 <= 0;
s2_pipe2_80 <= 0;
e1_pipe2_80 <= 0;
e2_pipe2_80 <= 0;
m1_pipe2_80 <= 0;
m2_pipe2_80 <= 0;
Larger_exp_pipe2_80 <= 0;
//stage2
Small_exp_mantissa_pipe2_80 <= 0;
Large_mantissa_pipe2_80 <= 0;
Num_shift_pipe2_80 <= 0;
s1_pipe3_80 <= 0;
s2_pipe3_80 <= 0;
e1_pipe3_80 <= 0;
e2_pipe3_80 <= 0;
m1_pipe3_80 <= 0;
m2_pipe3_80 <= 0;
Larger_exp_pipe3_80 <= 0;
s1_pipe4_80 <= 0;
s2_pipe4_80 <= 0;
e1_pipe4_80 <= 0;
e2_pipe4_80 <= 0;
m1_pipe4_80 <= 0;
m2_pipe4_80 <= 0;
Larger_exp_pipe4_80 <= 0;
s1_pipe5_80 <= 0;
s2_pipe5_80 <= 0;
e1_pipe5_80 <= 0;
e2_pipe5_80 <= 0;
m1_pipe5_80 <= 0;
m2_pipe5_80 <= 0;
Larger_exp_pipe5_80 <= 0;
//stage3
S_exp_mantissa_pipe3_80 <= 0;
L1_mantissa_pipe3_80 <= 0;
//stage4
S_mantissa_pipe4_80 <= 0;
L_mantissa_pipe4_80 <= 0;
//stage5
Add_mant_pipe5_80 <= 0;
renorm_shift_pipe5_80 <= 0;
Result_80 <=0;
end
else begin
///////////////////////////////PIPELINE STAGES and VARIABLES/////////////////
//propogate pipelined variables to next stages
s1_pipe2_80 <= s1_80;
s2_pipe2_80 <= s2_80;
e1_pipe2_80 <= e1_80;
e2_pipe2_80 <= e2_80;
m1_pipe2_80 <= m1_80;
m2_pipe2_80 <= m2_80;
Larger_exp_pipe2_80 <= Larger_exp_80;
//stage2
Small_exp_mantissa_pipe2_80 <= Small_exp_mantissa_80;
Large_mantissa_pipe2_80 <= Large_mantissa_80;
Num_shift_pipe2_80 <= Num_shift_80;
s1_pipe3_80 <= s1_pipe2_80;
s2_pipe3_80 <= s2_pipe2_80;
e1_pipe3_80 <= e1_pipe2_80;
e2_pipe3_80 <= e2_pipe2_80;
m1_pipe3_80 <= m1_pipe2_80;
m2_pipe3_80 <= m2_pipe2_80;
Larger_exp_pipe3_80 <= Larger_exp_pipe2_80;
s1_pipe4_80 <= s1_pipe3_80;
s2_pipe4_80 <= s2_pipe3_80;
e1_pipe4_80 <= e1_pipe3_80;
e2_pipe4_80 <= e2_pipe3_80;
m1_pipe4_80 <= m1_pipe3_80;
m2_pipe4_80 <= m2_pipe3_80;
Larger_exp_pipe4_80 <= Larger_exp_pipe3_80;
s1_pipe5_80 <= s1_pipe4_80;
s2_pipe5_80 <= s2_pipe4_80;
e1_pipe5_80 <= e1_pipe4_80;
e2_pipe5_80 <= e2_pipe4_80;
m1_pipe5_80 <= m1_pipe4_80;
m2_pipe5_80 <= m2_pipe4_80;
Larger_exp_pipe5_80 <= Larger_exp_pipe4_80;
//stage3
S_exp_mantissa_pipe3_80 <= S_exp_mantissa_pipe2_80;
L1_mantissa_pipe3_80 <= L1_mantissa_pipe2_80;
//stage4
S_mantissa_pipe4_80 <= S_mantissa_80;
L_mantissa_pipe4_80 <= L_mantissa_80;
//stage5
Add_mant_pipe5_80 <= Add_mant_80;
renorm_shift_pipe5_80 <= renorm_shift_80;
//renorm_exp_pipe5_80 <= renorm_exp_80;
end
end
endmodule
module sign_bit(
output wire sign,
input wire[63:0] in1,
input wire[63:0] in2
);
xor(sign,in1[63],in2[63]);
endmodule
//1 bit Full Adder
module full_adder(
input wire clk,
output reg sum1,
output reg cout1,
input wire in1,
input wire in2,
input wire cin
);