-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathRounding.v
More file actions
43 lines (42 loc) · 988 Bytes
/
Rounding.v
File metadata and controls
43 lines (42 loc) · 988 Bytes
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
module Rounding(clk,res,shift,incre,
exp_result,fra_result,result,overflow);
input clk,res;
input [8:0] incre;
input [27:0] shift;
reg [24:0] fra;//Include "1" but not the two reserved places.
output reg overflow;
output reg [7:0] exp_result;
output reg [27:0] fra_result;
output reg [31:0] result;
always @(posedge clk) begin
if(shift)
begin
if(incre[8])//incase the second time exp is not overflow.
overflow = 1;
else
overflow = 0;//reset
fra [24] = 0;
fra[23:0] = shift[25:2];
if(shift[1])
fra = fra+1;
if(fra[24])
begin
fra_result[27] = shift[27];
fra_result[26:2] = fra[24:0];
fra_result[1:0] = 1;
exp_result = incre[7:0];
end
else
begin
result[31] = shift[27];
result[30:23] = incre[7:0];
result[22:0] = fra[22:0];
end
if(!res)
begin
fra_result = 0;
result = 0;
end
end
end
endmodule