--- linuxsampler/trunk/src/common/RTMath.h 2005/05/19 19:25:14 554 +++ linuxsampler/trunk/src/common/RTMath.h 2005/12/22 19:35:42 818 @@ -36,6 +36,11 @@ ASM_X86_MMX_SSE }; +/** @brief Real Time Math Base Class + * + * Math functions for real time operation. This base class contains all + * non-template methods. + */ class RTMathBase { public: /** @@ -77,9 +82,12 @@ static float* InitCentsToFreqTable(); }; -/** Real Time Math +/** @brief Real Time Math * - * Math functions for real time operation. + * This is a template which provides customized methods for the desired low + * level implementation. The ASM_X86_MMX_SSE implementation of each method + * for example doesn't use 387 FPU instruction. This is needed for MMX + * algorithms which do not allow mixed MMX and 387 instructions. */ template class __RTMath : public RTMathBase { @@ -87,10 +95,7 @@ // conversion using truncate inline static int Int(const float a) { switch (IMPL) { - case CPP: { - return (int) a; - } - #if ARCH_X86 + #if CONFIG_ASM && ARCH_X86 case ASM_X86_MMX_SSE: { int ret; asm ( @@ -100,7 +105,10 @@ ); return ret; } - #endif // ARCH_X86 + #endif // CONFIG_ASM && ARCH_X86 + default: { + return (int) a; + } } } @@ -111,10 +119,7 @@ inline static float Float(const int a) { switch (IMPL) { - case CPP: { - return (float) a; - } - #if ARCH_X86 + #if CONFIG_ASM && ARCH_X86 case ASM_X86_MMX_SSE: { float ret; asm ( @@ -125,7 +130,10 @@ ); return ret; } - #endif // ARCH_X86 + #endif // CONFIG_ASM && ARCH_X86 + default: { + return (float) a; + } } } @@ -138,10 +146,7 @@ inline static float Sum(const float& a, const float& b) { switch (IMPL) { - case CPP: { - return (a + b); - } - #if ARCH_X86 + #if CONFIG_ASM && ARCH_X86 case ASM_X86_MMX_SSE: { float ret; asm ( @@ -153,7 +158,10 @@ ); return ret; } - #endif // ARCH_X86 + #endif // CONFIG_ASM && ARCH_X86 + default: { + return (a + b); + } } } @@ -163,10 +171,7 @@ inline static float Sub(const float& a, const float& b) { switch (IMPL) { - case CPP: { - return (a - b); - } - #if ARCH_X86 + #if CONFIG_ASM && ARCH_X86 case ASM_X86_MMX_SSE: { float ret; asm ( @@ -178,7 +183,10 @@ ); return ret; } - #endif // ARCH_X86 + #endif // CONFIG_ASM && ARCH_X86 + default: { + return (a - b); + } } } @@ -188,10 +196,7 @@ inline static float Mul(const float a, const float b) { switch (IMPL) { - case CPP: { - return (a * b); - } - #if ARCH_X86 + #if CONFIG_ASM && ARCH_X86 case ASM_X86_MMX_SSE: { float ret; asm ( @@ -203,7 +208,10 @@ ); return ret; } - #endif // ARCH_X86 + #endif // CONFIG_ASM && ARCH_X86 + default: { + return (a * b); + } } } @@ -213,10 +221,7 @@ inline static float Div(const float a, const float b) { switch (IMPL) { - case CPP: { - return (a / b); - } - #if ARCH_X86 + #if CONFIG_ASM && ARCH_X86 case ASM_X86_MMX_SSE: { float ret; asm ( @@ -228,7 +233,10 @@ ); return ret; } - #endif // ARCH_X86 + #endif // CONFIG_ASM && ARCH_X86 + default: { + return (a / b); + } } } @@ -238,10 +246,7 @@ inline static float Min(const float a, const float b) { switch (IMPL) { - case CPP: { - return (b < a) ? b : a; - } - #if ARCH_X86 + #if CONFIG_ASM && ARCH_X86 case ASM_X86_MMX_SSE: { float ret; asm ( @@ -253,7 +258,10 @@ ); return ret; } - #endif // ARCH_X86 + #endif // CONFIG_ASM && ARCH_X86 + default: { + return std::min(a, b); + } } } @@ -263,10 +271,7 @@ inline static float Max(const float a, const float b) { switch (IMPL) { - case CPP: { - return (b > a) ? b : a; - } - #if ARCH_X86 + #if CONFIG_ASM && ARCH_X86 case ASM_X86_MMX_SSE: { float ret; asm ( @@ -278,7 +283,10 @@ ); return ret; } - #endif // ARCH_X86 + #endif // CONFIG_ASM && ARCH_X86 + default: { + return std::max(a, b); + } } } @@ -288,10 +296,7 @@ inline static float Fmodf(const float &a, const float &b) { switch (IMPL) { - case CPP: { - return fmodf(a, b); - } - #if ARCH_X86 + #if CONFIG_ASM && ARCH_X86 case ASM_X86_MMX_SSE: { float ret; asm ( @@ -310,7 +315,10 @@ ); return ret; } - #endif // ARCH_X86 + #endif // CONFIG_ASM && ARCH_X86 + default: { + return fmodf(a, b); + } } } };