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/] [math_pipelined.sv] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 leshabiruk
 
2
module mull_pipelined(
3
        input clk,
4
        input [7:0] x,
5
        input [7:0] y,
6
        output [15:0] z
7
        );
8
 
9
reg [7:0] cx [7:0];
10
reg [7:0] cy [7:0];
11
reg [15:0] cz [15:0];
12
assign z= cz[7];
13
 
14
 
15
always @( posedge clk )
16
begin : multblk
17
        integer ind;
18
        cx[0]<= x;
19
        cy[0]<= y;
20
        cz[0]<= y[0]? x : 0;
21
        for (ind=0; ind<6; ind=ind+1)
22
        begin
23
                cy[ind+1]<= cy[ind];
24
                cx[ind+1]<= cx[ind];
25
                cz[ind+1]<= cz[ind] + (cy[ind][ind+1]? (cx[ind]<<(ind+1)) : 0);
26
        end
27
        cz[7]<= cz[6] + (cy[6][7]? cx[6] : 0);
28
end
29
endmodule
30
 
31
 
32
//module div_pipelined(
33
//      input clk,
34
//      input [15:0] x,
35
//      input [7:0] y,
36
//      output [7:0] z
37
//      );
38
//
39
//parameter BITS= 8;
40
//
41
//reg [15:0] cx [15:0];
42
//reg [7:0] cy [7:0];
43
//reg [7:0] cz [7:0];
44
//assign z= cz[7];
45
//
46
//wire [15:0] candidate [7:0];
47
//
48
//assign candidate[0]= x- (y<<7);
49
//
50
//`define MY_EXPR(ind) assign candidate[(ind+1)]= cx[(ind)]- (cy[(ind)]<<(6-ind))
51
//
52
//`MY_EXPR( 0 );
53
//`MY_EXPR( 1 );
54
//`MY_EXPR( 2 );
55
//`MY_EXPR( 3 );
56
//`MY_EXPR( 4 );
57
//`MY_EXPR( 5 );
58
//`MY_EXPR( 6 );
59
//
60
//always @( posedge clk )
61
//begin : multblk
62
//      integer ind;
63
//      integer j;
64
//      cx[0]<= candidate[0][15] ? x : candidate[0];
65
//      cy[0]<= y;
66
//      cz[0][7]<= candidate[0][15] ? 0 : 1;
67
//      for (ind=0; ind<6; ind=ind+1)
68
//      begin
69
//              cy[ind+1]<= cy[ind];
70
//              cx[ind+1]<= candidate[ind+1][15] ? cx[ind] : candidate[ind+1];
71
//              cz[ind+1][6-ind]<= candidate[ind+1][15] ? 0 : 1;
72
//              for (j=7; j>6-ind; j=j-1)
73
//              begin
74
//                      cz[ind+1][j]<= cz[ind][j];
75
//              end
76
//      end
77
//      cz[7][0]<= candidate[7][15] ? 0 : 1;
78
//      cz[7][7:1]<=cz[6][7:1];
79
//end
80
//endmodule
81
 
82
 
83
 
84
 
85
 
86
 
87
 
88
 
89
 
90
 
91
 
92
 
93
 
94
 
95
 
96
 
97
 
98
 
99
module div_pipelined(
100
        input clk,
101
        input [D_UP:0] x,
102
        input [UP:0] y,
103
        output [UP:0] z
104
        );
105
 
106
parameter BITS= 48;
107
//      ���������� ���������, �� ��������������.
108
parameter UP= BITS-1;
109
parameter D_UP= 2*BITS-1;
110
 
111
reg [D_UP:0] cx [UP:0];
112
reg [UP:0] cy [UP:0];
113
reg [UP:0] cz [UP:0];
114
reg csign [UP:0];
115
 
116
assign z= (csign[UP] ? -cz[UP]:cz[UP]);
117
 
118
wire [D_UP:0] candidate [UP:0];
119
 
120
wire [D_UP:0] ux= ( (x[D_UP]) ? (-x):x );
121
wire [UP:0] uy= ( (y[UP]) ? (-y):y );
122
wire [D_UP:0] _uy= uy;
123
 
124
wire [D_UP:0] _cy [UP:0];
125
 
126
always @*
127
begin
128
        integer ind;
129
        candidate[0]<= ux- (_uy<
130
        for (ind=0; ind< BITS-2 ; ind=ind+1)
131
        begin
132
                _cy <= cy;
133
                candidate[ind+1]<= cx[ind]- (_cy[ind]<<(BITS-2-ind));
134
        end
135
end
136
 
137
 
138
always @( posedge clk )
139
begin : multblk
140
        integer ind;
141
        integer j;
142
        csign[0]= x[D_UP]^y[UP];
143
        cx[0]<= candidate[0][D_UP] ? ux : candidate[0];
144
        cy[0]<= uy;
145
        cz[0][UP]<= ~candidate[0][D_UP];        //      !!! sign bit?
146
        for (ind=0; ind< BITS-1 ; ind=ind+1)
147
        begin
148
                cy[ind+1]<= cy[ind];
149
                cx[ind+1]<= candidate[ind+1][D_UP] ? cx[ind] : candidate[ind+1];
150
                cz[ind+1][ BITS-2 -ind]<= ~candidate[ind+1][D_UP];
151
                csign[ind+1]<= csign[ind];
152
                for (j=UP; j> BITS-2 -ind; j=j-1)
153
                begin
154
                        cz[ind+1][j]<= cz[ind][j];
155
                end
156
        end
157
//      cz[UP][0]<= ~candidate[UP][D_UP];
158
//      cz[UP][UP:1]<=cz[ BITS-2 ][UP:1];
159
//      csign[UP]<= csign[UP-1];
160
end
161
endmodule
162
 
163
 
164
module id_pipelined(
165
        input clk,
166
        input [UP:0] i,
167
        output [UP:0] o
168
        );
169
 
170
parameter BITS= 32;
171
parameter DELAY= 32;
172
//      ���������� ���������, �� ��������������.
173
parameter UP= BITS-1;
174
 
175
reg [UP:0] cx [DELAY];
176
 
177
assign o= cx[DELAY-1];
178
 
179
always @( posedge clk )
180
begin : blk
181
        integer ind;
182
        cx[0]<= i;
183
        for (ind=0; ind< DELAY-1 ; ind=ind+1)
184
        begin
185
                cx[ind+1]<= cx[ind];
186
        end
187
end
188
endmodule
189
 
190
 
191
 
192
 

powered by: WebSVN 2.1.0

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