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

Subversion Repositories jart

[/] [jart/] [branches/] [ver0branch/] [sqrt.vhd] - Blame information for rev 68

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 68 jguarin200
 
2
-- A 1 clock x 4 stage pipe square root.
3
 
4
 
5
library ieee;
6
use ieee.std_logic_1164.all;
7
use ieee.std_logic_arith.all;
8
use work.powerGrid.all;
9
 
10
entity sqrt is
11
 
12
        generic (
13
                W2 : integer := 64
14
 
15
        );
16
        port
17
        (
18
                clk,rst,ena : in std_logic;
19
 
20
                radical         : in std_logic_vector (W2-1 downto 0);
21
                sho                     : out std_logic;
22
                a,b,x,y         : out std_logic_vector ((W2/2)-1 downto 0);
23
                decoder         : out integer range 0 to (W2/2)-1
24
        );
25
end entity;
26
 
27
 
28
architecture rtl of sqrt is
29
 
30
        constant WP                             : integer:= W2/2;
31
        constant WP_2                   : integer:= WP/2;
32
 
33
 
34
        signal sa0,sb0,sx0,sy0,sb0_1            : std_logic_vector (WP-1 downto 0);
35
        signal sa1,sb1,sx1,sy1,sb1_1,muxs1      : std_logic_vector (WP-1 downto 0);
36
        signal sa2,sb2,sx2,sy2                          : std_logic_vector (WP-1 downto 0);
37
        signal localenc1                                        : integer range 0 to WP-1;
38
        signal localenc2                                        : integer range 0 to WP-1;
39
 
40
 
41
        begin
42
 
43
        -- Logic function signals ...... if some day there's a paper of how this logic circuit works, it will be easier to comprehend this block of code
44
        sb0_1<=sa0(WP-2 downto 0) & '0';
45
        signalization : for i in 0 to WP-1 generate
46
 
47
                -- Stage 0. Functions for A,B,X and preliminar Y.
48
                sb0(i)<=radical(i*2);
49
                sa0(i)<=radical(i*2+1);
50
                sx0(i)<=sb0(i) or sa0(i);
51
                sy0(i)<=sb0(i) and sa0(i);
52
 
53
                -- Stage 1 : Function for signal Y.
54
                muxs1(i) <= sy1(i) or (not(sx1(i)) and sb1_1(i));
55
 
56
 
57
        end generate signalization;
58
 
59
 
60
 
61
 
62
        stages: process (rst,clk,ena,sx0,sx1,localenc2)
63
                variable localenc0 : integer range 0 to WP-1;
64
 
65
        begin
66
 
67
                -- Highest signifcant pair enconder : look for the bit pair with the most significant bit.
68
                localenc0 := WP-1;
69
                stg0henc: while localenc0>0 loop
70
 
71
                        exit when (sx0(localenc0)='1');
72
                        localenc0:=localenc0-1;
73
                end loop;
74
 
75
 
76
 
77
 
78
                -- Clocking process;
79
                if rst='0' then
80
                        -- Stage 1
81
                        sa1<=(others => '0');
82
                        sb1<=(others => '0');
83
                        sx1<=(others => '0');
84
                        sy1<=(others => '0');
85
                        sb1_1<=(others => '0');
86
 
87
 
88
                        -- Stage 2
89
                        sx2<=(others => '0');
90
                        sa2<=(others => '0');
91
                        sb2<=(others => '0');
92
                        sy2<=(others => '0');
93
 
94
 
95
                        --Stage 3
96
                        x<=(others => '0');
97
                        y<=(others => '0');
98
                        a<=(others => '0');
99
                        b<=(others => '0');
100
 
101
 
102
 
103
                elsif rising_edge(clk) and ena='1' then
104
 
105
                        -- Stage01 
106
                        sa1<=sa0;
107
                        sb1<=sb0;
108
                        sx1<=sx0;
109
                        sy1<=sy0;
110
                        sb1_1<=sb0_1;
111
                        localenc1<=localenc0;
112
 
113
 
114
                        -- Stage12
115
                        sx2<=sx1;
116
                        sa2<=sa1;
117
                        sb2<=sb1;
118
                        sy2<= muxs1;
119
                        localenc2<=localenc1;
120
 
121
                        -- Stage 23 Shift 1 bit to right if the high bit in the highest significant pair is set.
122
                        if sa2(localenc2)='1' then
123
                                -- Shift Right
124
                                a <= '0' & sb2(WP-1 downto 1);
125
                                b <= sa2;
126
                                x <= '0' & sy2(WP-1 downto 1);
127
                                y <= sx2;
128
 
129
                        else
130
                                -- Leave me alone
131
                                x <= sx2;
132
                                y <= sy2;
133
                                a <= sa2;
134
                                b <= sb2;
135
                        end if;
136
 
137
                        decoder<=localenc2;
138
                        sho<=sa2(localenc2);
139
 
140
                        stage34
141
 
142
                end if;
143
 
144
 
145
        end process stages;
146
 
147
 
148
 
149
end rtl;
150
 

powered by: WebSVN 2.1.0

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