Ticket #5965: freesurround-imath.patch

File freesurround-imath.patch, 6.4 KB (added by foobum@…, 15 years ago)
  • mythtv/libs/libmythfreesurround/el_processor.cpp

    diff --git a/mythtv/libs/libmythfreesurround/el_processor.cpp b/mythtv/libs/libmythfreesurround/el_processor.cpp
    index 1cf0dc8..7073d6d 100644
    a b along with this program; if not, write to the Free Software 
    1616Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    1717*/
    1818
     19#include "../libmyth/mythconfig.h"
    1920#include "el_processor.h"
    2021#include <cstdlib>
    2122#include <cstring>
    extern "C" { 
    3132typedef FFTSample FFTComplexArray[2];
    3233#endif
    3334
     35// use inline asm trig on x86_32/64
     36#ifdef ARCH_X86
     37#include "imath.h"
     38#define SQRT isqrtf
     39#define SIN isin
     40#define COS icos
     41#define TAN itan
     42#define ASIN iasin
     43#define ATAN2 iatan2f
     44#else
     45#define SQRT sqrt
     46#define SIN sin
     47#define COS cos
     48#define TAN tan
     49#define ASIN asin
     50#define ATAN2 atan2
     51#endif
    3452
    3553#ifdef USE_FFTW3
    3654#pragma comment (lib,"libfftw3f-3.lib")
    typedef std::complex<float> cfloat; 
    4058
    4159const float PI = 3.141592654;
    4260const float epsilon = 0.000001;
    43 const float center_level = 0.5*sqrt(0.5);
     61const float center_level = 0.5*SQRT(0.5);
    4462
    4563// private implementation of the surround decoder
    4664class decoder_impl {
    public: 
    177195        unsigned int cutoff = (30*N)/srate;
    178196        for (unsigned f=0;f<=halfN;f++) {           
    179197            if (f<cutoff)
    180                 filter[5][f] = 0.5*sqrt(0.5);
     198                filter[5][f] = 0.5*SQRT(0.5);
    181199            else
    182200                filter[5][f] = 0.0;
    183201        }
    public: 
    214232
    215233private:
    216234    // polar <-> cartesian coodinates conversion
    217     static inline float amplitude(const float cf[2]) { return sqrt(cf[0]*cf[0] + cf[1]*cf[1]); }
    218     static inline float phase(const float cf[2]) { return atan2(cf[1],cf[0]); }
     235    static inline float amplitude(const float cf[2]) { return SQRT(cf[0]*cf[0] + cf[1]*cf[1]); }
     236    static inline float phase(const float cf[2]) { return ATAN2(cf[1],cf[0]); }
     237#ifdef ARCH_X86
     238    static inline cfloat polar(float a, float p) {
     239        float sc[2];
     240        isincosf(p, sc);
     241        return cfloat(a*sc[0],a*sc[1]);
     242    }
     243#else
    219244    static inline cfloat polar(float a, float p) { return cfloat(a*cos(p),a*sin(p)); }
     245#endif
    220246    static inline float sqr(float x) { return x*x; }
    221247    // the dreaded min/max
    222248    static inline float min(float a, float b) { return a<b?a:b; }
    private: 
    377403    inline double get_yfs(double ampDiff, double phaseDiff) {
    378404        double x = 1-(((1-sqr(ampDiff))*phaseDiff)/PI*2);
    379405#ifdef FASTER_CALC
    380         double tanX = tan(x);
     406        double tanX = TAN(x);
    381407        return 0.16468622925824683 + 0.5009268347818189*x - 0.06462757726992101*x*x
    382408            + 0.09170680403453149*x*x*x + 0.2617754892323973*tanX - 0.04180413533856156*sqr(tanX);
    383409#else
    private: 
    390416    inline double get_xfs(double ampDiff, double yfs) {
    391417        double x=ampDiff,y=yfs;
    392418#ifdef FASTER_CALC
    393         double tanX = tan(x);
    394         double tanY = tan(y);
    395         double asinX = asin(x);
    396         double sinX = sin(x);
    397         double sinY = sin(y);
     419        double tanX = TAN(x);
     420        double tanY = TAN(y);
     421        double asinX = ASIN(x);
     422        double sinX = SIN(x);
     423        double sinY = SIN(y);
    398424        double x3 = x*x*x;
    399425        double y2 = y*y;
    400426        double y3 = y*y2;
  • new file mythtv/libs/libmythfreesurround/imath.h

    diff --git a/mythtv/libs/libmythfreesurround/imath.h b/mythtv/libs/libmythfreesurround/imath.h
    new file mode 100644
    index 0000000..86f04c6
    - +  
     1static inline double icos(double x)
     2{
     3    double y;
     4    asm (
     5        "fldl   %1\n\t"
     6        "fcos   \n\t"
     7        :"=&t"(y):"m"(x)
     8    );
     9    return y;
     10}
     11
     12static inline float icosf(float x)
     13{
     14    float y;
     15    asm (
     16        "flds   %1\n\t"
     17        "fcos   \n\t"
     18        :"=&t"(y):"m"(x)
     19    );
     20    return y;
     21}
     22
     23static inline double isin(double x)
     24{
     25    double y;
     26    asm (
     27        "fldl   %1\n\t"
     28        "fsin   \n\t"
     29        :"=&t"(y):"m"(x)
     30    );
     31    return y;
     32}
     33
     34static inline float isinf(float x)
     35{
     36    float y;
     37    asm (
     38        "flds   %1\n\t"
     39        "fsin   \n\t"
     40        :"=&t"(y):"m"(x)
     41    );
     42    return y;
     43}
     44
     45static inline double itan(double x)
     46{
     47    double y;
     48    asm (
     49        "fldl   %1\n\t"
     50        "fptan   \n\t"
     51        "fstp   %%st(0)\n\t"
     52        :"=&t"(y):"m"(x)
     53    );
     54    return y;
     55}
     56
     57static inline float itanf(float x)
     58{
     59    float y;
     60    asm (
     61        "flds   %1\n\t"
     62        "fptan   \n\t"
     63        :"=&t"(y):"m"(x)
     64    );
     65    return y;
     66}
     67
     68static inline double *isincos(double x, double *ptr)
     69{
     70    double *ptr2 = ptr + 1;
     71    asm (
     72        "fldl   %2\n\t"
     73        "fsincos \n\t"
     74        "fstpl  %0\n\t"
     75        "fstpl  %1\n\t"
     76        :"=m"(*ptr),"=m"(*ptr2):"m"(x)
     77    );
     78    return ptr;
     79}
     80
     81static inline float *isincosf(float x, float *ptr)
     82{
     83    float *ptr2 = ptr + 1;
     84    asm (
     85        "flds   %2\n\t"
     86        "fsincos \n\t"
     87        "fstps  %0\n\t"
     88        "fstps  %1\n\t"
     89        :"=m"(*ptr),"=m"(*ptr2):"m"(x)
     90    );
     91    return ptr;
     92}
     93
     94static inline double iasin(double x)
     95{
     96    double y;
     97    asm (
     98        "fldl   %1\n\t"
     99        "fld    %%st\n\t"
     100        "fmul   %%st(0)\n\t"
     101        "fld1   \n\t"
     102        "fsubp  \n\t"
     103        "fsqrt  \n\t"
     104        "fpatan \n\t"
     105        :"=&t"(y):"m"(x)
     106    );
     107    return y;
     108}
     109
     110static inline float iasinf(float x)
     111{
     112    float y;
     113    asm (
     114        "flds   %1\n\t"
     115        "fld    %%st\n\t"
     116        "fmul   %%st(0)\n\t"
     117        "fld1   \n\t"
     118        "fsubp  \n\t"
     119        "fsqrt  \n\t"
     120        "fpatan \n\t"
     121        :"=&t"(y):"m"(x)
     122    );
     123    return y;
     124}
     125
     126static inline double iatan2(double x, double y)
     127{
     128    double z;
     129    asm (
     130        "fldl   %1\n\t"
     131        "fldl   %2\n\t"
     132        "fpatan \n\t"
     133        :"=&t"(z):"m"(x),"m"(y)
     134    );
     135    return z;
     136}
     137
     138static inline float iatan2f(float x, float y)
     139{
     140    float z;
     141    asm (
     142        "flds   %1\n\t"
     143        "flds   %2\n\t"
     144        "fpatan \n\t"
     145        :"=&t"(z):"m"(x),"m"(y)
     146    );
     147    return z;
     148}
     149
     150static inline double isqrt(double x)
     151{
     152    double y;
     153    asm (
     154        "fldl   %1\n\t"
     155        "fsqrt  \n\t"
     156        :"=&t"(y):"m"(x)
     157    );
     158    return y;
     159}
     160
     161static inline float isqrtf(float x)
     162{
     163    float y;
     164    asm (
     165        "flds   %1\n\t"
     166        "fsqrt  \n\t"
     167        :"=&t"(y):"m"(x)
     168    );
     169    return y;
     170}