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

Subversion Repositories theia_gpu

[/] [theia_gpu/] [branches/] [icarus_version/] [rtl/] [Module_FixedPointSquareRoot.v] - Blame information for rev 194

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

Line No. Rev Author Line
1 158 diegovalve
`timescale 1ns / 1ps
2
`include "aDefinitions.v"
3
 
4
 
5
//LUT contains LUT for numbers up to 100 in FIXED point scale 17
6
module SQUAREROOT_LUT
7
(
8
        input  wire[`WIDTH-1:0]                  I,
9
        output reg [`WIDTH-1:0]          O
10
);
11
 
12
 
13
always @( I )
14
begin
15
        case (I)
16 184 diegovalve
        32'h0: O = 32'h0;
17
32'h20000: O = 32'h20000;
18
32'h40000: O = 32'h2d413;
19
32'h60000: O = 32'h376cf;
20
32'h80000: O = 32'h40000;
21
32'ha0000: O = 32'h478dd;
22
32'hc0000: O = 32'h4e623;
23
32'he0000: O = 32'h54a9f;
24
32'h100000: O = 32'h5a827;
25
32'h120000: O = 32'h60000;
26
32'h140000: O = 32'h65316;
27
32'h160000: O = 32'h6a21c;
28
32'h180000: O = 32'h6ed9e;
29
32'h1a0000: O = 32'h7360a;
30
32'h1c0000: O = 32'h77bba;
31
32'h1e0000: O = 32'h7bef7;
32
32'h200000: O = 32'h80000;
33
32'h220000: O = 32'h83f07;
34
32'h240000: O = 32'h87c3b;
35
32'h260000: O = 32'h8b7c1;
36
32'h280000: O = 32'h8f1bb;
37
32'h2a0000: O = 32'h92a47;
38
32'h2c0000: O = 32'h9617e;
39
32'h2e0000: O = 32'h99777;
40
32'h300000: O = 32'h9cc47;
41
32'h320000: O = 32'ha0000;
42
32'h340000: O = 32'ha32b2;
43
32'h360000: O = 32'ha646e;
44
32'h380000: O = 32'ha953f;
45
32'h3a0000: O = 32'hac534;
46
32'h3c0000: O = 32'haf456;
47
32'h3e0000: O = 32'hb22b2;
48
32'h400000: O = 32'hb504f;
49
32'h420000: O = 32'hb7d37;
50
32'h440000: O = 32'hba972;
51
32'h460000: O = 32'hbd508;
52
32'h480000: O = 32'hc0000;
53
32'h4a0000: O = 32'hc2a5f;
54
32'h4c0000: O = 32'hc542e;
55
32'h4e0000: O = 32'hc7d70;
56
32'h500000: O = 32'hca62c;
57
32'h520000: O = 32'hcce66;
58
32'h540000: O = 32'hcf623;
59
32'h560000: O = 32'hd1d68;
60
32'h580000: O = 32'hd4439;
61
32'h5a0000: O = 32'hd6a99;
62
32'h5c0000: O = 32'hd908d;
63
32'h5e0000: O = 32'hdb618;
64
32'h600000: O = 32'hddb3d;
65
32'h620000: O = 32'he0000;
66
32'h640000: O = 32'he2463;
67
32'h660000: O = 32'he4869;
68
32'h680000: O = 32'he6c15;
69
32'h6a0000: O = 32'he8f6a;
70
32'h6c0000: O = 32'heb26a;
71
32'h6e0000: O = 32'hed517;
72
32'h700000: O = 32'hef775;
73
32'h720000: O = 32'hf1983;
74
32'h740000: O = 32'hf3b46;
75
32'h760000: O = 32'hf5cbf;
76
32'h780000: O = 32'hf7def;
77
32'h7a0000: O = 32'hf9ed9;
78
32'h7c0000: O = 32'hfbf7d;
79
32'h7e0000: O = 32'hfdfdf;
80
32'h800000: O = 32'h100000;
81
32'h820000: O = 32'h101fe0;
82
32'h840000: O = 32'h103f81;
83
32'h860000: O = 32'h105ee6;
84
32'h880000: O = 32'h107e0f;
85
32'h8a0000: O = 32'h109cfd;
86
32'h8c0000: O = 32'h10bbb3;
87
32'h8e0000: O = 32'h10da30;
88
32'h900000: O = 32'h10f876;
89
32'h920000: O = 32'h111687;
90
32'h940000: O = 32'h113463;
91
32'h960000: O = 32'h11520c;
92
32'h980000: O = 32'h116f83;
93
32'h9a0000: O = 32'h118cc8;
94
32'h9c0000: O = 32'h11a9dc;
95
32'h9e0000: O = 32'h11c6c1;
96
32'ha00000: O = 32'h11e377;
97
32'ha20000: O = 32'h120000;
98
32'ha40000: O = 32'h121c5b;
99
32'ha60000: O = 32'h12388a;
100
32'ha80000: O = 32'h12548e;
101
32'haa0000: O = 32'h127068;
102
32'hac0000: O = 32'h128c17;
103
32'hae0000: O = 32'h12a79e;
104
32'hb00000: O = 32'h12c2fc;
105
32'hb20000: O = 32'h12de32;
106
32'hb40000: O = 32'h12f942;
107
32'hb60000: O = 32'h13142b;
108
32'hb80000: O = 32'h132eee;
109
32'hba0000: O = 32'h13498c;
110
32'hbc0000: O = 32'h136406;
111
32'hbe0000: O = 32'h137e5b;
112
32'hc00000: O = 32'h13988e;
113
32'hc20000: O = 32'h13b29d;
114
32'hc40000: O = 32'h13cc8a;
115
32'hc60000: O = 32'h13e655;
116
32'hc80000: O = 32'h140000;
117
32'hca0000: O = 32'h141989;
118
32'hcc0000: O = 32'h1432f2;
119
32'hce0000: O = 32'h144c3b;
120
32'hd00000: O = 32'h146565;
121
32'hd20000: O = 32'h147e70;
122
32'hd40000: O = 32'h14975c;
123
32'hd60000: O = 32'h14b02b;
124
32'hd80000: O = 32'h14c8dc;
125
32'hda0000: O = 32'h14e16f;
126
32'hdc0000: O = 32'h14f9e6;
127
32'hde0000: O = 32'h151241;
128
32'he00000: O = 32'h152a7f;
129
32'he20000: O = 32'h1542a2;
130
32'he40000: O = 32'h155aaa;
131
32'he60000: O = 32'h157296;
132
32'he80000: O = 32'h158a68;
133
32'hea0000: O = 32'h15a220;
134
32'hec0000: O = 32'h15b9be;
135
32'hee0000: O = 32'h15d142;
136
32'hf00000: O = 32'h15e8ad;
137
32'hf20000: O = 32'h160000;
138
32'hf40000: O = 32'h161739;
139
32'hf60000: O = 32'h162e5a;
140
32'hf80000: O = 32'h164564;
141
32'hfa0000: O = 32'h165c55;
142
32'hfc0000: O = 32'h16732f;
143 183 diegovalve
32'hfe0000: O = 32'h1689f2; //127 -> 1111111,00000000000000000 
144 158 diegovalve
 
145
default:
146
begin
147 183 diegovalve
//$display("Shit, got %d\n",I << `SCALE);
148
 O = 32'h00caca;
149 158 diegovalve
end
150
        endcase
151
 
152
end //always    
153
endmodule
154
 
155
module FixedPointSquareRoot
156
(
157
        input wire                                                      Clock,
158
        input wire                                                      Reset,
159
        input wire[`LONG_WIDTH-1:0]      Operand,
160
        input wire                                                      iInputReady,
161
        output  wire                                            OutputReady,
162
        output  wire [`WIDTH-1:0]                Result
163
);
164
 
165
 
166 183 diegovalve
FFD_POSEDGE_SYNCRONOUS_RESET # (1) FFDelay1
167
(
168
        .Clock( Clock ),
169
        .Reset( Reset ),
170
        .Enable(1'b1 ),
171
        .D( iInputReady ),
172
        .Q( OutputReady )
173
);
174
 
175
//LUT only has values from 0 to 127, lets see if the value is bigger than that
176
wire wNotInLUT;
177
assign wNotInLUT = Operand[7+`SCALE];
178 184 diegovalve
//If the value is not on the LUT then divide by 64, so SQRT(x) = SQRT(64*x/64)
179 183 diegovalve
//=16*SQRT(x/64)
180
 
181
wire[`WIDTH-1:0] wScaledOperand;
182
 
183
assign wScaledOperand = (wNotInLUT == 1'b0 ) ?
184
   {Operand[`WIDTH-1:`SCALE],{`SCALE{1'b0}}} :     //Aproximate the Square root to an integer value
185
        {6'b0,Operand[`WIDTH-1:`SCALE+6],{`SCALE{1'b0}}};  //Shift right two bits (divide by 4)
186
 
187
wire [`WIDTH-1:0] wResult,wScaleResult;
188
SQUAREROOT_LUT SQRT
189
(
190
.I(wScaledOperand),
191
.O(wScaleResult)
192
 
193
);
194
 
195
 
196
 
197
assign wResult = (wNotInLUT == 1'b0 ) ? wScaleResult : {wScaleResult[`WIDTH-3:0],1'b0};
198
 
199
 
200
FFD_POSEDGE_SYNCRONOUS_RESET # (`WIDTH) FFRESULT
201
(
202
        .Clock( Clock ),
203
        .Reset( Reset ),
204
        .Enable(1'b1 ),
205
        .D( wResult ),
206
        .Q( Result )
207
);
208
 
209 184 diegovalve
 
210 183 diegovalve
//--------------------------------------------------------------------------------
211 158 diegovalve
endmodule
212 184 diegovalve
 

powered by: WebSVN 2.1.0

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