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

Subversion Repositories ft816float

[/] [ft816float/] [trunk/] [rtl/] [verilog2/] [fpSincos64.sv] - Blame information for rev 90

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 90 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2023  Robert Finch, Waterloo
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch@finitron.ca
6
//       ||
7
//
8
//
9
// BSD 3-Clause License
10
// Redistribution and use in source and binary forms, with or without
11
// modification, are permitted provided that the following conditions are met:
12
//
13
// 1. Redistributions of source code must retain the above copyright notice, this
14
//    list of conditions and the following disclaimer.
15
//
16
// 2. Redistributions in binary form must reproduce the above copyright notice,
17
//    this list of conditions and the following disclaimer in the documentation
18
//    and/or other materials provided with the distribution.
19
//
20
// 3. Neither the name of the copyright holder nor the names of its
21
//    contributors may be used to endorse or promote products derived from
22
//    this software without specific prior written permission.
23
//
24
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
//
35
// ============================================================================
36
 
37
import fp64Pkg::*;
38
 
39
module fpSincos64(rst, clk, rm, ld, a, sin, cos);
40
input rst;
41
input clk;
42
input [2:0] rm;
43
input ld;
44
input FP64 a;
45
output FP64 sin;
46
output FP64 cos;
47
 
48
FP64 aa;
49
FP64X sinx, cosx;
50
wire FP64N fpn_sin, fpn_cos;
51
reg [59:0] phase_i;
52
wire [EMSB:0] exp;
53
reg [EMSB:0] exp1,exp2,exp3,exp4;
54
wire [FMSB+1:0] fract;
55
reg [FMSB+10:0] fract1,fract2,fract3,fract4;
56
wire [53:0] xval, yval;
57
wire [59:0] phase;
58
wire nan;
59
wire cdone;
60
wire vz;
61
reg ld1, ld2, ld3, ld4, ld5;
62
 
63
fpDecomp64Reg u4
64
(
65
        .clk(clk),
66
        .ce(1'b1),
67
        .i(aa),
68
        .o(),
69
        .sgn(sgn),
70
        .exp(exp),
71
        .man(),
72
        .fract(fract),
73
        .xz(),
74
        .mz(),
75
        .vz(vz),
76
        .inf(),
77
        .xinf(),
78
        .qnan(),
79
        .snan(),
80
        .nan(nan)
81
);
82
 
83
wire signed [11:0] expdif = 11'h3ff - exp;
84
 
85
always_ff @(posedge clk)
86
if (rst) begin
87
        fract1 <= 'd0;
88
        fract2 <= 'd0;
89
        ld1 <= 'd0;
90
        ld2 <= 'd0;
91
        ld3 <= 'd0;
92
        ld4 <= 'd0;
93
        ld5 <= 'd0;
94
        aa <= 'd0;
95
end
96
else begin
97
        if (ld)
98
                aa <= a;
99
        ld1 <= ld;
100
        ld2 <= ld1;
101
        ld3 <= ld2;
102
        ld4 <= ld3;
103
        ld5 <= ld4;
104
        if (vz) begin
105
                fract1 <= 'd0;
106
                exp1 <= 'd0;
107
        end
108
        else if (expdif[11]) begin      // expdif < 0?
109
                fract1 <= {fract,7'b0} << -expdif;
110
                exp1 <= exp + expdif;
111
        end
112
        else if (expdif > 13'd53) begin
113
                fract1 <= 'd0;
114
                exp1 <= exp + 6'd53;
115
        end
116
        else if (expdif > 0) begin// negative?
117
                fract1 <= {fract,7'b0} >> expdif[5:0];
118
                exp1 <= exp + expdif;
119
        end
120
        else if (expdif=='d0) begin
121
                fract1 <= {fract,7'b0};
122
                exp1 <= exp;
123
        end
124
        exp2 <= exp1;
125
        exp3 <= exp2;
126
        exp4 <= exp3;
127
        fract2 <= ({61'd0,fract1} * 61'h517cc1b727220c0) >> 8'd61;
128
        fract3 <= fract2;
129
        fract4 <= fract3;
130
end
131
 
132
wire [6:0] ylz, xlz;
133
cntlz64 uclzy(
134
        .i({yval[53] ? -yval[52:0] : yval[52:0],11'd0}),
135
        .o(ylz)
136
);
137
cntlz64 uclzx (
138
        .i({xval[53] ? -xval[52:0] : xval[52:0],11'd0}),
139
        .o(xlz)
140
);
141
 
142
always_ff @(posedge clk)
143
if (rst) begin
144
        sinx <= 'd0;
145
        cosx <= 'd0;
146
end
147
else begin
148
        if (cdone) begin
149
                if (nan) begin
150
                        sinx.sign <= a.sign;
151
                        sinx.exp <= a.exp;
152
                        sinx.sig <= {a.sig,a.sig};
153
                        cosx.sign <= a.sign;
154
                        cosx.exp <= a.exp;
155
                        cosx.sig <= {a.sig,a.sig};
156
                end
157
                else begin
158
                        sinx.sign <= yval[53];
159
                        sinx.exp <= exp4 - 2'd1 - ylz;  // 2^1
160
                        if (yval[53])
161
                                sinx.sig <= {-yval[51:0],54'd0} << ylz;
162
                        else
163
                                sinx.sig <= {yval[51:0],54'd0} << ylz;
164
                        cosx.sign <= xval[53];
165
                        cosx.exp <= exp4 - 2'd1 - xlz;
166
                        if (xval[53]) begin
167
                                cosx.sig <= {-xval[51:0],54'd0} << xlz;
168
                        end
169
                        else
170
                                cosx.sig <= {xval[51:0],54'd0} << xlz;
171
                end
172
        end
173
end
174
 
175
fpCordic u1
176
(
177
        .rst(rst),
178
        .clk(clk),
179
        .arctan(1'b0),
180
        .ld(ld5),
181
        .phase_i({fract4[FMSB+8:0],1'b0}),
182
        .xval_i(54'h10000000000000),
183
        .yval_i(54'h00000000000000),
184
        .xval_o(xval),
185
        .yval_o(yval),
186
        .phase_o(phase),
187
        .done(cdone)
188
);
189
 
190
fpNormalize64 u2
191
(
192
        .clk(clk),
193
        .ce(1'b1),
194
        .under_i(1'b0),
195
        .i(sinx),
196
        .o(fpn_sin)
197
);
198
 
199
fpRound64 u3
200
(
201
        .clk(clk),
202
        .ce(1'b1),
203
        .rm(rm),
204
        .i(fpn_sin),
205
        .o(sin)
206
);
207
 
208
fpNormalize64 u5
209
(
210
        .clk(clk),
211
        .ce(1'b1),
212
        .under_i(1'b0),
213
        .i(cosx),
214
        .o(fpn_cos)
215
);
216
 
217
fpRound64 u6
218
(
219
        .clk(clk),
220
        .ce(1'b1),
221
        .rm(rm),
222
        .i(fpn_cos),
223
        .o(cos)
224
);
225
 
226
vtdl #(.WID(1), .DEP(16)) u7
227
(
228
        .clk(clk),
229
        .ce(1'b1),
230
        .a(4'd11),
231
        .d(cdone),
232
        .q(done)
233
);
234
 
235
endmodule

powered by: WebSVN 2.1.0

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