summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2013-04-09 19:07:35 -0400
committerMichael Sevakis <jethead71@rockbox.org>2013-04-09 19:07:35 -0400
commitf5b7134f59fa20685a51d56d3a323044a2c441cf (patch)
tree2b0bb30c1eb8a748fdc00f9c6854381c6205005e
parent9a19a22d8510f96838d30f539a94ac8eec73a390 (diff)
downloadrockbox-f5b7134f59fa20685a51d56d3a323044a2c441cf.tar.gz
rockbox-f5b7134f59fa20685a51d56d3a323044a2c441cf.zip
Consolidate identical fixedpoint exp and ln functions.
grey_core.c and fixedpoint.c each had their own copies. grey_core.c can use the ones fixedpoint.c. fixedpoint.c gets the more complete and optimized version of fp_16exp from grey_core.c. Change-Id: I43ee3add60796b06ed12012fbbd91815d64675a6
-rw-r--r--apps/fixedpoint.c77
-rw-r--r--apps/plugins/lib/grey_core.c52
2 files changed, 38 insertions, 91 deletions
diff --git a/apps/fixedpoint.c b/apps/fixedpoint.c
index a8f606a5db..5051cc78e7 100644
--- a/apps/fixedpoint.c
+++ b/apps/fixedpoint.c
@@ -271,25 +271,26 @@ long fp14_cos(int val)
271 * values with 16 fractional bits, although intermediates are kept with 28 271 * values with 16 fractional bits, although intermediates are kept with 28
272 * bits of precision to avoid loss of accuracy during shifts." 272 * bits of precision to avoid loss of accuracy during shifts."
273 */ 273 */
274long fp16_log(int x)
275{
276 int t;
277 int y = 0xa65af;
278
279 if (x < 0x00008000) x <<=16, y -= 0xb1721;
280 if (x < 0x00800000) x <<= 8, y -= 0x58b91;
281 if (x < 0x08000000) x <<= 4, y -= 0x2c5c8;
282 if (x < 0x20000000) x <<= 2, y -= 0x162e4;
283 if (x < 0x40000000) x <<= 1, y -= 0x0b172;
284 t = x + (x >> 1); if ((t & 0x80000000) == 0) x = t, y -= 0x067cd;
285 t = x + (x >> 2); if ((t & 0x80000000) == 0) x = t, y -= 0x03920;
286 t = x + (x >> 3); if ((t & 0x80000000) == 0) x = t, y -= 0x01e27;
287 t = x + (x >> 4); if ((t & 0x80000000) == 0) x = t, y -= 0x00f85;
288 t = x + (x >> 5); if ((t & 0x80000000) == 0) x = t, y -= 0x007e1;
289 t = x + (x >> 6); if ((t & 0x80000000) == 0) x = t, y -= 0x003f8;
290 t = x + (x >> 7); if ((t & 0x80000000) == 0) x = t, y -= 0x001fe;
291 x = 0x80000000 - x;
292 y -= x >> 15;
274 293
275long fp16_log(int x) {
276 long t,y;
277
278 y=0xa65af;
279 if(x<0x00008000) x<<=16, y-=0xb1721;
280 if(x<0x00800000) x<<= 8, y-=0x58b91;
281 if(x<0x08000000) x<<= 4, y-=0x2c5c8;
282 if(x<0x20000000) x<<= 2, y-=0x162e4;
283 if(x<0x40000000) x<<= 1, y-=0x0b172;
284 t=x+(x>>1); if((t&0x80000000)==0) x=t,y-=0x067cd;
285 t=x+(x>>2); if((t&0x80000000)==0) x=t,y-=0x03920;
286 t=x+(x>>3); if((t&0x80000000)==0) x=t,y-=0x01e27;
287 t=x+(x>>4); if((t&0x80000000)==0) x=t,y-=0x00f85;
288 t=x+(x>>5); if((t&0x80000000)==0) x=t,y-=0x007e1;
289 t=x+(x>>6); if((t&0x80000000)==0) x=t,y-=0x003f8;
290 t=x+(x>>7); if((t&0x80000000)==0) x=t,y-=0x001fe;
291 x=0x80000000-x;
292 y-=x>>15;
293 return y; 294 return y;
294} 295}
295 296
@@ -305,29 +306,23 @@ long fp16_log(int x) {
305 */ 306 */
306long fp16_exp(int x) 307long fp16_exp(int x)
307{ 308{
308 int t,y; 309 int t;
309 310 int y = 0x00010000;
310 y=0x00010000; 311
311 t=x-0x58b91; if(t>=0) x=t,y<<=8; 312 if (x < 0) x += 0xb1721, y >>= 16;
312 t=x-0x2c5c8; if(t>=0) x=t,y<<=4; 313 t = x - 0x58b91; if (t >= 0) x = t, y <<= 8;
313 t=x-0x162e4; if(t>=0) x=t,y<<=2; 314 t = x - 0x2c5c8; if (t >= 0) x = t, y <<= 4;
314 t=x-0x0b172; if(t>=0) x=t,y<<=1; 315 t = x - 0x162e4; if (t >= 0) x = t, y <<= 2;
315 t=x-0x067cd; if(t>=0) x=t,y+=y>>1; 316 t = x - 0x0b172; if (t >= 0) x = t, y <<= 1;
316 t=x-0x03920; if(t>=0) x=t,y+=y>>2; 317 t = x - 0x067cd; if (t >= 0) x = t, y += y >> 1;
317 t=x-0x01e27; if(t>=0) x=t,y+=y>>3; 318 t = x - 0x03920; if (t >= 0) x = t, y += y >> 2;
318 t=x-0x00f85; if(t>=0) x=t,y+=y>>4; 319 t = x - 0x01e27; if (t >= 0) x = t, y += y >> 3;
319 t=x-0x007e1; if(t>=0) x=t,y+=y>>5; 320 t = x - 0x00f85; if (t >= 0) x = t, y += y >> 4;
320 t=x-0x003f8; if(t>=0) x=t,y+=y>>6; 321 t = x - 0x007e1; if (t >= 0) x = t, y += y >> 5;
321 t=x-0x001fe; if(t>=0) x=t,y+=y>>7; 322 t = x - 0x003f8; if (t >= 0) x = t, y += y >> 6;
322 if(x&0x100) y+=y>>8; 323 t = x - 0x001fe; if (t >= 0) x = t, y += y >> 7;
323 if(x&0x080) y+=y>>9; 324 y += ((y >> 8) * x) >> 8;
324 if(x&0x040) y+=y>>10; 325
325 if(x&0x020) y+=y>>11;
326 if(x&0x010) y+=y>>12;
327 if(x&0x008) y+=y>>13;
328 if(x&0x004) y+=y>>14;
329 if(x&0x002) y+=y>>15;
330 if(x&0x001) y+=y>>16;
331 return y; 326 return y;
332} 327}
333#endif /* PLUGIN */ 328#endif /* PLUGIN */
diff --git a/apps/plugins/lib/grey_core.c b/apps/plugins/lib/grey_core.c
index 047e4cc160..bb6823522d 100644
--- a/apps/plugins/lib/grey_core.c
+++ b/apps/plugins/lib/grey_core.c
@@ -27,6 +27,7 @@
27 27
28#include "plugin.h" 28#include "plugin.h"
29#include "grey.h" 29#include "grey.h"
30#include "fixedpoint.h"
30 31
31#if defined(HAVE_ADJUSTABLE_CPU_FREQ) && \ 32#if defined(HAVE_ADJUSTABLE_CPU_FREQ) && \
32 (defined(CPU_PP) || (CONFIG_LCD == LCD_TL0350A)) 33 (defined(CPU_PP) || (CONFIG_LCD == LCD_TL0350A))
@@ -368,8 +369,6 @@ static const unsigned char lcdlinear[256] = {
368 369
369/* Prototypes */ 370/* Prototypes */
370static inline void _deferred_update(void) __attribute__ ((always_inline)); 371static inline void _deferred_update(void) __attribute__ ((always_inline));
371static int exp_s16p16(int x);
372static int log_s16p16(int x);
373static void grey_screendump_hook(int fd); 372static void grey_screendump_hook(int fd);
374static void fill_gvalues(void); 373static void fill_gvalues(void);
375#ifdef SIMULATOR 374#ifdef SIMULATOR
@@ -501,53 +500,6 @@ static void _timer_isr(void)
501 500
502#endif /* !SIMULATOR */ 501#endif /* !SIMULATOR */
503 502
504/* fixed point exp() */
505static int exp_s16p16(int x)
506{
507 int t;
508 int y = 0x00010000;
509
510 if (x < 0) x += 0xb1721, y >>= 16;
511 t = x - 0x58b91; if (t >= 0) x = t, y <<= 8;
512 t = x - 0x2c5c8; if (t >= 0) x = t, y <<= 4;
513 t = x - 0x162e4; if (t >= 0) x = t, y <<= 2;
514 t = x - 0x0b172; if (t >= 0) x = t, y <<= 1;
515 t = x - 0x067cd; if (t >= 0) x = t, y += y >> 1;
516 t = x - 0x03920; if (t >= 0) x = t, y += y >> 2;
517 t = x - 0x01e27; if (t >= 0) x = t, y += y >> 3;
518 t = x - 0x00f85; if (t >= 0) x = t, y += y >> 4;
519 t = x - 0x007e1; if (t >= 0) x = t, y += y >> 5;
520 t = x - 0x003f8; if (t >= 0) x = t, y += y >> 6;
521 t = x - 0x001fe; if (t >= 0) x = t, y += y >> 7;
522 y += ((y >> 8) * x) >> 8;
523
524 return y;
525}
526
527/* fixed point log() */
528static int log_s16p16(int x)
529{
530 int t;
531 int y = 0xa65af;
532
533 if (x < 0x00008000) x <<=16, y -= 0xb1721;
534 if (x < 0x00800000) x <<= 8, y -= 0x58b91;
535 if (x < 0x08000000) x <<= 4, y -= 0x2c5c8;
536 if (x < 0x20000000) x <<= 2, y -= 0x162e4;
537 if (x < 0x40000000) x <<= 1, y -= 0x0b172;
538 t = x + (x >> 1); if ((t & 0x80000000) == 0) x = t, y -= 0x067cd;
539 t = x + (x >> 2); if ((t & 0x80000000) == 0) x = t, y -= 0x03920;
540 t = x + (x >> 3); if ((t & 0x80000000) == 0) x = t, y -= 0x01e27;
541 t = x + (x >> 4); if ((t & 0x80000000) == 0) x = t, y -= 0x00f85;
542 t = x + (x >> 5); if ((t & 0x80000000) == 0) x = t, y -= 0x007e1;
543 t = x + (x >> 6); if ((t & 0x80000000) == 0) x = t, y -= 0x003f8;
544 t = x + (x >> 7); if ((t & 0x80000000) == 0) x = t, y -= 0x001fe;
545 x = 0x80000000 - x;
546 y -= x >> 15;
547
548 return y;
549}
550
551static void fill_gvalues(void) 503static void fill_gvalues(void)
552{ 504{
553 int i; 505 int i;
@@ -560,7 +512,7 @@ static void fill_gvalues(void)
560#endif 512#endif
561 for (i = 0; i < 256; i++) 513 for (i = 0; i < 256; i++)
562 { 514 {
563 data = exp_s16p16((_GREY_GAMMA * log_s16p16(i * 257 + 1)) >> 8) + 128; 515 data = fp16_exp((_GREY_GAMMA * fp16_log(i * 257 + 1)) >> 8) + 128;
564 data = (data - (data >> 8)) >> 8; /* approx. data /= 257 */ 516 data = (data - (data >> 8)) >> 8; /* approx. data /= 257 */
565 data = ((lcdlinear[data ^ imask] ^ imask) << 7) + 127; 517 data = ((lcdlinear[data ^ imask] ^ imask) << 7) + 127;
566 _grey_info.gvalue[i] = (data + (data >> 8)) >> 8; 518 _grey_info.gvalue[i] = (data + (data >> 8)) >> 8;