Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(440)

Side by Side Diff: src/core/SkCordic.cpp

Issue 19773006: Add bench to test float to fixed conversion (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « include/core/SkFixed.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkCordic.h" 8 #include "SkCordic.h"
9 #include "SkMathPriv.h" 9 #include "SkMathPriv.h"
10 #include "Sk64.h" 10 #include "Sk64.h"
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 #ifdef SK_DEBUG 196 #ifdef SK_DEBUG
197 197
198 #include "SkFloatingPoint.h" 198 #include "SkFloatingPoint.h"
199 199
200 void SkCordic_UnitTest() 200 void SkCordic_UnitTest()
201 { 201 {
202 #if defined(SK_SUPPORT_UNITTEST) 202 #if defined(SK_SUPPORT_UNITTEST)
203 float val; 203 float val;
204 for (float angle = -720; angle < 720; angle += 30) { 204 for (float angle = -720; angle < 720; angle += 30) {
205 float radian = angle * 3.1415925358f / 180.0f; 205 float radian = angle * 3.1415925358f / 180.0f;
206 SkFixed f_angle = (int) (radian * 65536.0f); 206 SkFixed f_angle = SkFloatToFixed(radian);
207 // sincos 207 // sincos
208 float sine = sinf(radian); 208 float sine = sinf(radian);
209 float cosine = cosf(radian); 209 float cosine = cosf(radian);
210 SkFixed f_cosine; 210 SkFixed f_cosine;
211 SkFixed f_sine = SkCordicSinCos(f_angle, &f_cosine); 211 SkFixed f_sine = SkCordicSinCos(f_angle, &f_cosine);
212 float sine2 = (float) f_sine / 65536.0f; 212 float sine2 = (float) f_sine / 65536.0f;
213 float cosine2 = (float) f_cosine / 65536.0f; 213 float cosine2 = (float) f_cosine / 65536.0f;
214 float error = fabsf(sine - sine2); 214 float error = fabsf(sine - sine2);
215 if (error > 0.001) 215 if (error > 0.001)
216 SkDebugf("sin error : angle = %g ; sin = %g ; cordic = %g\n", angle, sine, sine2); 216 SkDebugf("sin error : angle = %g ; sin = %g ; cordic = %g\n", angle, sine, sine2);
217 error = fabsf(cosine - cosine2); 217 error = fabsf(cosine - cosine2);
218 if (error > 0.001) 218 if (error > 0.001)
219 SkDebugf("cos error : angle = %g ; cos = %g ; cordic = %g\n", angle, cosine, cosine2); 219 SkDebugf("cos error : angle = %g ; cos = %g ; cordic = %g\n", angle, cosine, cosine2);
220 // tan 220 // tan
221 float _tan = tanf(radian); 221 float _tan = tanf(radian);
222 SkFixed f_tan = SkCordicTan(f_angle); 222 SkFixed f_tan = SkCordicTan(f_angle);
223 float tan2 = (float) f_tan / 65536.0f; 223 float tan2 = (float) f_tan / 65536.0f;
224 error = fabsf(_tan - tan2); 224 error = fabsf(_tan - tan2);
225 if (error > 0.05 && fabsf(_tan) < 1e6) 225 if (error > 0.05 && fabsf(_tan) < 1e6)
226 SkDebugf("tan error : angle = %g ; tan = %g ; cordic = %g\n", angle, _tan, tan2); 226 SkDebugf("tan error : angle = %g ; tan = %g ; cordic = %g\n", angle, _tan, tan2);
227 } 227 }
228 for (val = -1; val <= 1; val += .1f) { 228 for (val = -1; val <= 1; val += .1f) {
229 SkFixed f_val = (int) (val * 65536.0f); 229 SkFixed f_val = SkFloatToFixed(val);
230 // asin 230 // asin
231 float arcsine = asinf(val); 231 float arcsine = asinf(val);
232 SkFixed f_arcsine = SkCordicASin(f_val); 232 SkFixed f_arcsine = SkCordicASin(f_val);
233 float arcsine2 = (float) f_arcsine / 65536.0f; 233 float arcsine2 = (float) f_arcsine / 65536.0f;
234 float error = fabsf(arcsine - arcsine2); 234 float error = fabsf(arcsine - arcsine2);
235 if (error > 0.001) 235 if (error > 0.001)
236 SkDebugf("asin error : val = %g ; asin = %g ; cordic = %g\n", val, a rcsine, arcsine2); 236 SkDebugf("asin error : val = %g ; asin = %g ; cordic = %g\n", val, a rcsine, arcsine2);
237 } 237 }
238 #if 1 238 #if 1
239 for (val = -1; val <= 1; val += .1f) { 239 for (val = -1; val <= 1; val += .1f) {
240 #else 240 #else
241 val = .5; { 241 val = .5; {
242 #endif 242 #endif
243 SkFixed f_val = (int) (val * 65536.0f); 243 SkFixed f_val = SkFloatToFixed(val);
244 // acos 244 // acos
245 float arccos = acosf(val); 245 float arccos = acosf(val);
246 SkFixed f_arccos = SkCordicACos(f_val); 246 SkFixed f_arccos = SkCordicACos(f_val);
247 float arccos2 = (float) f_arccos / 65536.0f; 247 float arccos2 = (float) f_arccos / 65536.0f;
248 float error = fabsf(arccos - arccos2); 248 float error = fabsf(arccos - arccos2);
249 if (error > 0.001) 249 if (error > 0.001)
250 SkDebugf("acos error : val = %g ; acos = %g ; cordic = %g\n", val, a rccos, arccos2); 250 SkDebugf("acos error : val = %g ; acos = %g ; cordic = %g\n", val, a rccos, arccos2);
251 } 251 }
252 // atan2 252 // atan2
253 #if 1 253 #if 1
254 for (val = -1000; val <= 1000; val += 500.f) { 254 for (val = -1000; val <= 1000; val += 500.f) {
255 for (float val2 = -1000; val2 <= 1000; val2 += 500.f) { 255 for (float val2 = -1000; val2 <= 1000; val2 += 500.f) {
256 #else 256 #else
257 val = 0; { 257 val = 0; {
258 float val2 = -1000; { 258 float val2 = -1000; {
259 #endif 259 #endif
260 SkFixed f_val = (int) (val * 65536.0f); 260 SkFixed f_val = SkFloatToFixed(val);
261 SkFixed f_val2 = (int) (val2 * 65536.0f); 261 SkFixed f_val2 = SkFloatToFixed(val2);
262 float arctan = atan2f(val, val2); 262 float arctan = atan2f(val, val2);
263 SkFixed f_arctan = SkCordicATan2(f_val, f_val2); 263 SkFixed f_arctan = SkCordicATan2(f_val, f_val2);
264 float arctan2 = (float) f_arctan / 65536.0f; 264 float arctan2 = (float) f_arctan / 65536.0f;
265 float error = fabsf(arctan - arctan2); 265 float error = fabsf(arctan - arctan2);
266 if (error > 0.001) 266 if (error > 0.001)
267 SkDebugf("atan2 error : val = %g ; val2 = %g ; atan2 = %g ; cord ic = %g\n", val, val2, arctan, arctan2); 267 SkDebugf("atan2 error : val = %g ; val2 = %g ; atan2 = %g ; cord ic = %g\n", val, val2, arctan, arctan2);
268 } 268 }
269 } 269 }
270 // log 270 // log
271 #if 1 271 #if 1
272 for (val = 0.125f; val <= 8.f; val *= 2.0f) { 272 for (val = 0.125f; val <= 8.f; val *= 2.0f) {
273 #else 273 #else
274 val = .5; { 274 val = .5; {
275 #endif 275 #endif
276 SkFixed f_val = (int) (val * 65536.0f); 276 SkFixed f_val = SkFloatToFixed(val);
277 // acos 277 // acos
278 float log = logf(val); 278 float log = logf(val);
279 SkFixed f_log = SkCordicLog(f_val); 279 SkFixed f_log = SkCordicLog(f_val);
280 float log2 = (float) f_log / 65536.0f; 280 float log2 = (float) f_log / 65536.0f;
281 float error = fabsf(log - log2); 281 float error = fabsf(log - log2);
282 if (error > 0.001) 282 if (error > 0.001)
283 SkDebugf("log error : val = %g ; log = %g ; cordic = %g\n", val, log , log2); 283 SkDebugf("log error : val = %g ; log = %g ; cordic = %g\n", val, log , log2);
284 } 284 }
285 // exp 285 // exp
286 #endif 286 #endif
287 } 287 }
288 288
289 #endif 289 #endif
OLDNEW
« no previous file with comments | « include/core/SkFixed.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698