Skip to content

Commit 29f57b0

Browse files
authored
Add files via upload
1 parent 6e2a654 commit 29f57b0

File tree

5 files changed

+239
-0
lines changed

5 files changed

+239
-0
lines changed

MAC/adder/buffer2.v

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
`timescale 1ns / 1ps
2+
//////////////////////////////////////////////////////////////////////////////////
3+
// Company:
4+
// Engineer:
5+
//
6+
// Create Date: 29.11.2018 11:45:41
7+
// Design Name:
8+
// Module Name: buffer2
9+
// Project Name:
10+
// Target Devices:
11+
// Tool Versions:
12+
// Description:
13+
//
14+
// Dependencies:
15+
//
16+
// Revision:
17+
// Revision 0.01 - File Created
18+
// Additional Comments:
19+
//
20+
//////////////////////////////////////////////////////////////////////////////////
21+
22+
module buffer2(mxy1,s3,sr1,ex,sn3,sn4,clk,mxy2,ex3,sn5,sn6,s4,sr2);
23+
input [24:0]mxy1;
24+
input s3,clk,sr1,sn3,sn4;
25+
input [7:0]ex;
26+
output reg[24:0]mxy2;
27+
output reg[7:0]ex3;
28+
output reg s4,sn5,sn6,sr2;
29+
always@(posedge clk)
30+
begin
31+
sr2=sr1;
32+
sn5=sn3;
33+
sn6=sn4;
34+
ex3=ex;
35+
mxy2=mxy1;
36+
s4=s3;
37+
end
38+
endmodule

MAC/adder/compshift.v

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
`timescale 1ns / 1ps
2+
//////////////////////////////////////////////////////////////////////////////////
3+
// Company:
4+
// Engineer:
5+
//
6+
// Create Date: 29.11.2018 11:49:07
7+
// Design Name:
8+
// Module Name: compshift
9+
// Project Name:
10+
// Target Devices:
11+
// Tool Versions:
12+
// Description:
13+
//
14+
// Dependencies:
15+
//
16+
// Revision:
17+
// Revision 0.01 - File Created
18+
// Additional Comments:
19+
//
20+
//////////////////////////////////////////////////////////////////////////////////
21+
22+
module cmpshift(e1,e2,s1,s2,m1,m2,clk,ex,ey,mx,my,s,sx1,sy1); //module for copare &shift
23+
input [7:0]e1,e2;
24+
input [23:0]m1,m2;
25+
input clk,s1,s2;
26+
output reg[7:0]ex,ey;
27+
output reg[23:0]mx,my;
28+
output reg s,sx1,sy1;
29+
reg [7:0]diff;
30+
always@(posedge clk)
31+
begin
32+
sx1=s1;
33+
sy1=s2;
34+
if(e1==e2)
35+
begin
36+
ex=e1+8'b1;
37+
ey=e2+8'b1;
38+
mx=m1;
39+
my=m2;
40+
s=1'b1;
41+
end
42+
else if(e1>e2)
43+
begin
44+
diff=e1-e2;
45+
ex=e1+8'b1;
46+
ey=e1+8'b1;
47+
mx=m1;
48+
my=m2>>diff;
49+
s=1'b1;
50+
end
51+
else
52+
begin
53+
diff=e2-e1;
54+
ex=e2+8'b1;
55+
ey=e2+8'b1;
56+
mx=m2;
57+
my=m1>>diff;
58+
s=1'b0;
59+
end
60+
end
61+
endmodule

MAC/adder/faddsub.v

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
`timescale 1ns / 1ps
2+
//////////////////////////////////////////////////////////////////////////////////
3+
// Company:
4+
// Engineer:
5+
//
6+
// Create Date: 29.11.2018 11:48:07
7+
// Design Name:
8+
// Module Name: faddsub
9+
// Project Name:
10+
// Target Devices:
11+
// Tool Versions:
12+
// Description:
13+
//
14+
// Dependencies:
15+
//
16+
// Revision:
17+
// Revision 0.01 - File Created
18+
// Additional Comments:
19+
//
20+
//////////////////////////////////////////////////////////////////////////////////
21+
22+
module faddsub(a,b,s1,s2,sn,ex1,clk,out,ex2,sn3,sn4,s,sr1); //submodule for addition or subtraction
23+
input [23:0]a,b;
24+
input[7:0]ex1;
25+
input s1,s2,clk,sn;
26+
output reg [23:0]ex2;
27+
output reg[24:0]out;
28+
output reg s,sn3,sn4,sr1;
29+
always@(posedge clk)
30+
begin
31+
ex2=ex1;
32+
sr1=sn;
33+
sn3=s1;
34+
sn4=s2;
35+
s=s1^s2;
36+
if(s)
37+
begin
38+
out=a-b;
39+
end
40+
else
41+
begin
42+
out=a+b;
43+
end
44+
end
45+
endmodule

MAC/adder/fpadd.v

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
`timescale 1ns / 1ps
2+
//////////////////////////////////////////////////////////////////////////////////
3+
// Company:
4+
// Engineer:
5+
//
6+
// Create Date: 16.11.2018 11:53:54
7+
// Design Name:
8+
// Module Name: add
9+
// Project Name:
10+
// Target Devices:
11+
// Tool Versions:
12+
// Description:
13+
//
14+
// Dependencies:
15+
//
16+
// Revision:
17+
// Revision 0.01 - File Created
18+
// Additional Comments:
19+
//
20+
//////////////////////////////////////////////////////////////////////////////////
21+
22+
module fpadd(a,b,clk,out);
23+
input[31:0]a,b;
24+
input clk;
25+
output [31:0]out;
26+
wire [7:0]e1,e2,ex,ey,exy,ex1,ey1,ex2,ex3;
27+
wire s1,s2,s,s3,sr,sn,s4,sx1,sy1,sn1,sn2,sn3,sn4,sr1,sr2,sn5,sn6;
28+
wire [23:0]m1,m2,mx,my,mxy,mx1,my1;
29+
wire [24:0]mxy1,mxy2;
30+
assign s1=a[31];
31+
assign s2=b[31];
32+
assign e1=a[30:23];
33+
assign e2=b[30:23];
34+
assign m1[23]=1'b1;
35+
assign m2[23]=1'b1;
36+
assign m1[22:0]=a[22:0];
37+
assign m2[22:0]=b[22:0];
38+
//submodule for compare and shfit
39+
cmpshift as(e1[7:0],e2[7:0],s1,s2,m1[23:0],m2[23:0],clk,ex,ey,mx,my,s,sx1,sy1);
40+
//buffer1 buff1(ex,ey,sx1,sy1,mx,my,s,clk,ex1,ey1,mx1,my1,sn,sn1,sn2);
41+
//sub module for mantissa addition snd subtraction
42+
faddsub as1(mx,my,sx1,sy1,s,ex,clk,mxy1,ex2,sn3,sn4,s3,sr1);
43+
//faddsub as1(mx1,my1,sn1,sn2,sn,ex1,clk,mxy1,ex2,sn3,sn4,s3,sr1);
44+
buffer2 buff2(mxy1,s3,sr1,ex2,sn3,sn4,clk,mxy2,ex3,sn5,sn6,s4,sr2);
45+
//sub module for normalization
46+
//normalized as2(mxy1,sr1,sn3,sn4,s3,clk,ex3,sr,exy,mxy);
47+
normalized as2(mxy2,sr2,sn5,sn6,s4,clk,ex3,sr,exy,mxy);
48+
assign out={sr,exy,mxy[22:0]};
49+
endmodule
50+

MAC/adder/normalized.v

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
`timescale 1ns / 1ps
2+
//////////////////////////////////////////////////////////////////////////////////
3+
// Company:
4+
// Engineer:
5+
//
6+
// Create Date: 29.11.2018 11:46:33
7+
// Design Name:
8+
// Module Name: normalise
9+
// Project Name:
10+
// Target Devices:
11+
// Tool Versions:
12+
// Description:
13+
//
14+
// Dependencies:
15+
//
16+
// Revision:
17+
// Revision 0.01 - File Created
18+
// Additional Comments:
19+
//
20+
//////////////////////////////////////////////////////////////////////////////////
21+
22+
module normalized(mxy1,s,s1,s2,s3,clk,ex,sr,exy,mxy);
23+
input[24:0]mxy1;
24+
input s,s1,s2,s3,clk;
25+
input[7:0]ex;
26+
output reg sr;
27+
output reg[7:0]exy;
28+
output reg[23:0]mxy;
29+
reg [24:0]mxy2;
30+
always@(posedge clk)
31+
begin
32+
sr=s?s1^(mxy1[24]&s3):s2^(mxy1[24]&s3);
33+
mxy2=(mxy1[24]&s3)?~mxy1+25'b1:mxy1;
34+
mxy=mxy2[24:1];
35+
exy=ex;
36+
repeat(24)
37+
begin
38+
if(mxy[23]==1'b0)
39+
begin
40+
mxy=mxy<<1'b1;
41+
exy=exy-8'b1;
42+
end
43+
end
44+
end
45+
endmodule

0 commit comments

Comments
 (0)