OpenCores
URL https://opencores.org/ocsvn/pipelined_fixed_point_elementary_functions/pipelined_fixed_point_elementary_functions/trunk

Subversion Repositories pipelined_fixed_point_elementary_functions

[/] [pipelined_fixed_point_elementary_functions/] [trunk/] [math_pipelined/] [sqrt_pipelined.sv] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 leshabiruk
 
2
 
3
 
4
 
5
module sqrt_pipelined(
6
        input clk,
7
        input [UP:0] x,
8
        output [UP:0] osqrt,
9
        output [UP:0] odebug
10
        );
11
 
12
parameter BITS= 32;
13
//      Производные константы, не переопределять.
14
 
15
//      разрядность аргумента
16
parameter UP= BITS-1;
17
 
18
reg [UP:0] cr [UP:0];
19
reg [UP:0] crr [UP:0];
20
reg [UP:0] _crr [UP:0];
21
 
22
reg [UP:0] cx [UP:0];
23
 
24
`define BOUT (UP)       //      Чтобы мониторить промежуточные стадии при отладке
25
 
26
assign osqrt= cr[`BOUT];
27
assign odebug= crr[`BOUT];
28
 
29
always @( posedge clk )
30
begin
31
        integer ind;
32
 
33
 
34
        //      приводим аргумент к беззнаковому виду
35
        cx[0]<= x;
36
//      cr[0]<=  32'h00800000;
37
//      crr[0]<= 32'h40000000;
38
`define MEDI  (64'h0000000000000001<<(BITS-1) )
39
`define MEDI2 (64'h0000000000000001<<(BITS-1))
40
        cr[0]<=  `MEDI;
41
        crr[0]<= `MEDI2;
42
 
43
 
44
        for (ind=0; ind< UP; ind=ind+1)
45
        begin
46
                if ( cx[ind]>crr[ind] )
47
                begin
48
                        cr [ind+1]<= cr [ind] + (`MEDI>>(ind+1));
49
//                      _crr [ind+1]<= (cr [ind] + (`MEDI>>(ind+1)) )*(cr [ind] + (`MEDI>>(ind+1)) );
50
                        crr[ind+1]<= crr [ind] + (`MEDI2>>(2*(ind+1))) + ( (cr[ind])>>(ind) );
51
                end
52
                else
53
                begin
54
                        cr [ind+1]<= cr [ind] - (`MEDI>>(ind+1));
55
//                      _crr [ind+1]<= (cr [ind] - (`MEDI>>(ind+1)) )*(cr [ind] - (`MEDI>>(ind+1)) );
56
                        crr[ind+1]<= crr [ind] + (`MEDI2>>(2*(ind+1))) - ( (cr[ind])>>(ind) );
57
                end
58
                cx [ind+1]<= cx [ind];
59
        end
60
end
61
 
62
endmodule
63
 
64
 
65
 
66
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.