Changeset 656 for libcaca


Ignore:
Timestamp:
Mar 21, 2006, 12:05:56 PM (15 years ago)
Author:
Sam Hocevar
Message:
  • Tried to do something with cucul_powf. It currently sucks.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/cucul/math.c

    r568 r656  
    7171}
    7272
    73 
    7473/**
    7574 * \brief powf substitute (x^y)
    7675 * \param x The value to be raised
    77  * \param y The power to raise x of.
     76 * \param y The power to raise x to (only works with integers)
    7877 * \return \p x raised to the power of \p y
    7978 */
    80 
    8179float cucul_powf(float x, float y)
    8280{
    83     int i=((int)y);
    84     float r=x;
     81#ifdef __i386__
     82    /* FIXME: this can be optimised by directly calling fyl2x for x and y */
     83    register double logx;
     84    register long double v, e;
    8585
    86     if(((int)y)==1 || ((int)x)==1)
    87         return x;
     86    asm volatile("fldln2; fxch; fyl2x"
     87                 : "=t" (logx) : "0" (x) : "st(1)");
    8888
    89     i--;
    90     while(i--)
    91     {
    92         r*=x;
    93     }
    94     return r;
     89    asm volatile("fldl2e\n\t"
     90                 "fmul %%st(1)\n\t"
     91                 "fst %%st(1)\n\t"
     92                 "frndint\n\t"
     93                 "fxch\n\t"
     94                 "fsub %%st(1)\n\t"
     95                 "f2xm1\n\t"
     96                 : "=t" (v), "=u" (e) : "0" (y * logx));
     97    v += 1.0;
     98    asm volatile("fscale"
     99                 : "=t" (v) : "0" (v), "u" (e));
     100
     101    return v;
     102#else
     103    return x; /* HAHAHA VIEUX PORC */
     104#endif
    95105}
Note: See TracChangeset for help on using the changeset viewer.