-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathroot.v
62 lines (61 loc) · 1.78 KB
/
root.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
`timescale 1ns / 1ps
module root(
input clk_i,
input rst_i,
input start_i,
input [7:0] x_bi,
output reg [3:0] y_bo,
output busy_o
);
localparam IDLE = 2'h0;
localparam FIRST_WORK = 2'h1;
localparam SECOND_WORK = 2'h2;
reg [7:0] x;
reg [7:0] part_result;
reg [7:0] b;
reg [6:0] m;
reg [1:0] state;
wire end_step;
wire x_above_b;
assign end_step = (m == 0);
assign x_above_b = (x >= b);
assign busy_o = (state != IDLE);
always @(posedge clk_i)
if (rst_i) begin
y_bo <= 0;
b <= 0;
state <= IDLE;
end else begin
case (state)
IDLE:
begin
if (start_i) begin
state <= FIRST_WORK;
part_result <= 0;
x <= x_bi;
m <= 7'b1000000;
end
end
FIRST_WORK:
begin
if (!end_step) begin
b <= part_result | m;
part_result <= part_result >> 1;
state <= SECOND_WORK;
end else begin
y_bo <= part_result[3:0];
state <= IDLE;
end
end
SECOND_WORK:
begin
if(x_above_b) begin
x <= x - b;
part_result = part_result | m;
end
m <= m >> 2;
state <= FIRST_WORK;
end
endcase
end
endmodule