00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __UT_CommonMMXFuncs_h__
00018 #define __UT_CommonMMXFuncs_h__
00019
00020 #include "UT_API.h"
00021 #include <SYS/SYS_Types.h>
00022 #include "UT_Floor.h"
00023
00024 #ifdef LINUX
00025 #if !defined(IA64) && !defined(AMD64) && !defined(PPC)
00026 #define UT_USE_ASM_ACCEL
00027 #endif
00028 #endif
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 UT_API void UTconvertFPto8(unsigned char *dest,
00041 const fpreal32 *source,
00042 int length,
00043 int useprocext = 0);
00044
00045 UT_API void UTconvertFPto8BW(unsigned char *dest,
00046 const fpreal32 *source,
00047 int length,
00048 unsigned int black,
00049 unsigned int white,
00050 int useprocext = 0);
00051
00052
00053 UT_API void UTconvert8toFP(fpreal32 *dest,
00054 const unsigned char *source,
00055 int length,
00056 bool usesse = true);
00057
00058 UT_API void UTconvert8BWtoFP(fpreal32 *dest,
00059 const unsigned char*source,
00060 int length,
00061 unsigned int black,
00062 unsigned int white,
00063 bool usesse = true);
00064
00065
00066 UT_API void UTconvertFPto16(unsigned short *dest,
00067 const fpreal32 *source,
00068 int length,
00069 int procext = 0);
00070
00071 UT_API void UTconvertFPto16BW(unsigned short *dest,
00072 const fpreal32 *source,
00073 int length,
00074 unsigned int black,
00075 unsigned int white,
00076 bool usesse = true);
00077
00078
00079 UT_API void UTconvert16toFP(fpreal32 *dest,
00080 const unsigned short*source,
00081 int length,
00082 bool usesse = true);
00083
00084 UT_API void UTconvert16BWtoFP(fpreal32 *dest,
00085 const unsigned short *source,
00086 int length,
00087 unsigned int black,
00088 unsigned int white,
00089 bool usesse = true);
00090
00091
00092 UT_API inline unsigned char UTconvertFPto8(fpreal32 fval)
00093 {
00094 unsigned char val;
00095
00096 #ifdef UT_USE_ASM_ACCEL
00097 const fpreal32 f255[1] = { 255.0f };
00098 const fpreal32 *fptr = &fval;
00099 int ival = 0;
00100
00101 __asm__ __volatile (
00102 "movss (%%edi), %%xmm0 \n"
00103 "movss (%%ebx), %%xmm1 \n"
00104 "mov $255, %%ecx \n"
00105 "mulss %%xmm1, %%xmm0 \n"
00106 "mov $0, %%ebx \n"
00107 "cvtss2si %%xmm0, %%eax \n"
00108 "cmp %%eax, %%ecx \n"
00109 "cmovl %%ecx, %%eax \n"
00110 "cmp %%eax, %%ebx \n"
00111 "cmovg %%ebx, %%eax \n"
00112 : "=a" (ival)
00113 : "D" (fptr),
00114 "b" (f255) : "%ecx");
00115
00116 val = (unsigned char) ival;
00117 #else
00118 int t = (int) UTfloorIL(fval * 255.0f +0.5F);
00119
00120 if(t < 0)
00121 val = 0;
00122 else if(t > 255)
00123 val = 255;
00124 else
00125 val = (unsigned char) t;
00126 #endif
00127 return val;
00128 }
00129
00130 UT_API inline unsigned short UTconvertFPto16(fpreal32 fval)
00131 {
00132 unsigned short val;
00133
00134 #ifdef UT_USE_ASM_ACCEL
00135 const fpreal32 f65535[1] = { 65535.0f };
00136 const fpreal32 *fptr = &fval;
00137 int ival = 0;
00138
00139 __asm__ __volatile (
00140 "movss (%%edi), %%xmm0 \n"
00141 "movss (%%ebx), %%xmm1 \n"
00142 "mov $65535, %%ecx \n"
00143 "mulss %%xmm1, %%xmm0 \n"
00144 "mov $0, %%ebx \n"
00145 "cvtss2si %%xmm0, %%eax \n"
00146 "cmp %%eax, %%ecx \n"
00147 "cmovl %%ecx, %%eax \n"
00148 "cmp %%eax, %%ebx \n"
00149 "cmovg %%ebx, %%eax \n"
00150 : "=a" (ival)
00151 : "D" (fptr),
00152 "b" (f65535) : "%ecx");
00153
00154 val = (unsigned short) ival;
00155 #else
00156 int t = (int) UTfloorIL(fval * 65535.0f +0.5F);
00157 if(t < 0)
00158 val = 0;
00159 else if(t > 65535)
00160 val = 65535;
00161 else
00162 val = (unsigned short) t;
00163 #endif
00164 return val;
00165 }
00166
00167 #endif