summaryrefslogtreecommitdiff
path: root/apps/fixedpoint.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/fixedpoint.c')
-rw-r--r--apps/fixedpoint.c77
1 files changed, 36 insertions, 41 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 */