uoptsystemdependant.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. /****************************************************************************
  2. *
  3. * Module Title : SystemDependant.c
  4. *
  5. * Description : Miscellaneous system dependant functions
  6. *
  7. * AUTHOR : Paul Wilkins
  8. *
  9. *****************************************************************************
  10. * Revision History
  11. *
  12. * 1.20 YWX 06-Nov-02 Added forward DCT function optimized for Pentium 4
  13. * 1.19 YWX 15-Jun-01 added function pointer setups for new deblocking filter
  14. * 1.18 YWX 26-Apr-01 Fixed the cpu frequency detection bug caused by Sleep()
  15. * 1.17 JBX 22-Mar-01 Merged with new vp4-mapca bitstream
  16. * 1.16 JBB 26-Jan-01 Cleaned out unused function
  17. * 1.15 YWX 08-dec-00 Added WMT PostProcessor and
  18. * moved function declarations into _head files
  19. * 1.14 JBB 30 NOV 00 Version number changes
  20. * 1.13 YWX 03-Nov-00 Optimized postprocessor filters
  21. * 1.12 YWX 02-Nov-00 Added new loopfilter function pointers
  22. * 1.11 YWX 19-Oct-00 Added 1-2 Scaling functions pointers
  23. * 1.10 jbb 16 oct 00 added ifdefs to insure version code
  24. * 1.09 YWX 04-Oct-00 Added function pointers for scaling
  25. * 1.08 YWX 06 Sep 00 Added function pointers for new deringing filter
  26. * using frag baseed Q Value.
  27. * 1.07 JBB 21 Aug 00 New More Blurry in high variance area deringer
  28. * 1.06 YWX 2 Aug 00 Added function pointers for postprocess
  29. * 1.05 YWX 15/05/00 Added functions to check processor frequency
  30. * and more function pointers for postprocessor
  31. * 1.04 YWX 08/05/00 Added function pointers setup for postprocess
  32. * 1.03 SJL 20/04/00 Added ability to enable the new dequant code.
  33. * 1.02 SJL 22/03/00 Function pointers for the loop filter.
  34. * 1.01 JBB 21/03/00 More Function Pointers for optimized playback
  35. * 1.00 PGW 12/10/99 Configuration baseline
  36. *
  37. *****************************************************************************
  38. */
  39. /****************************************************************************
  40. * Header Files
  41. *****************************************************************************
  42. */
  43. #include "codec_common.h"
  44. #include "vputil_if.h"
  45. #include "cpuidlib.h"
  46. //global debugging aid's!
  47. int fastIDCTDisabled = 0;
  48. int forceCPUID = 0;
  49. int CPUID = 0;
  50. extern void GetProcessorFlags(INT32 *MmxEnabled, INT32 *XmmEnabled, INT32 *WmtEnabled);
  51. // Scalar (no mmx) reconstruction functions
  52. extern void ClearSysState_C(void);
  53. extern void IDctSlow( INT16 * InputData, INT16 *QuantMatrix, INT16 * OutputData );
  54. extern void IDct10( INT16 * InputData, INT16 *QuantMatrix, INT16 * OutputData );
  55. extern void IDct1( INT16 * InputData, INT16 *QuantMatrix, INT16 * OutputData );
  56. extern void ScalarReconIntra( INT16 *TmpDataBuffer, UINT8 * ReconPtr, UINT16 * ChangePtr, UINT32 LineStep );
  57. extern void ScalarReconInter( INT16 *TmpDataBuffer, UINT8 * ReconPtr, UINT8 * RefPtr, INT16 * ChangePtr, UINT32 LineStep );
  58. extern void ScalarReconInterHalfPixel2( INT16 *TmpDataBuffer, UINT8 * ReconPtr,UINT8 * RefPtr1, UINT8 * RefPtr2, INT16 * ChangePtr, UINT32 LineStep );
  59. extern void ReconBlock_C(INT16 *SrcBlock,INT16 *ReconRefPtr, UINT8 *DestBlock, UINT32 LineStep);
  60. extern void SubtractBlock_C( UINT8 *SrcBlock, INT16 *DestPtr, UINT32 LineStep );
  61. extern void UnpackBlock_C( UINT8 *ReconPtr, INT16 *ReconRefPtr, UINT32 ReconPixelsPerLine);
  62. extern void AverageBlock_C( UINT8 *ReconPtr1, UINT8 *ReconPtr2, UINT16 *ReconRefPtr, UINT32 ReconPixelsPerLine);
  63. extern void CopyBlock_C(unsigned char *src, unsigned char *dest, unsigned int srcstride);
  64. extern void Copy12x12_C(const unsigned char *src, unsigned char *dest, unsigned int srcstride, unsigned int deststride);
  65. extern void fdct_short_C ( INT16 * InputData, INT16 * OutputData );
  66. extern void FilterBlockBil_8_C( UINT8 *ReconPtr1, UINT8 *ReconPtr2, UINT8 *ReconRefPtr, UINT32 ReconPixelsPerLine, INT32 ModX, INT32 ModY );
  67. extern void FilterBlock_C( UINT8 *ReconPtr1, UINT8 *ReconPtr2, UINT16 *ReconRefPtr, UINT32 PixelsPerLine, INT32 ModX, INT32 ModY, BOOL UseBicubic, UINT8 BicubicAlpha );
  68. // MMx versions
  69. extern void fdct_MMX ( INT16 * InputData, INT16 * OutputData );
  70. extern void ClearMmx(void);
  71. extern void MMXReconIntra( INT16 *TmpDataBuffer, UINT8 * ReconPtr, UINT16 * ChangePtr, UINT32 LineStep );
  72. extern void MmxReconInter( INT16 *TmpDataBuffer, UINT8 * ReconPtr, UINT8 * RefPtr, INT16 * ChangePtr, UINT32 LineStep );
  73. extern void MmxReconInterHalfPixel2( INT16 *TmpDataBuffer, UINT8 * ReconPtr, UINT8 * RefPtr1, UINT8 * RefPtr2, INT16 * ChangePtr, UINT32 LineStep );
  74. extern void MMX_idct( Q_LIST_ENTRY * InputData, INT16 *QuantMatrix, INT16 * OutputData );
  75. extern void MMX_idct10( Q_LIST_ENTRY * InputData, INT16 *QuantMatrix, INT16 * OutputData );
  76. extern void MMX_idct1( Q_LIST_ENTRY * InputData, INT16 *QuantMatrix, INT16 * OutputData );
  77. extern void MMX_idct_DX( Q_LIST_ENTRY * InputData, INT16 *QuantMatrix, INT16 * OutputData );
  78. extern void MMX_idct10_DX( Q_LIST_ENTRY * InputData, INT16 *QuantMatrix, INT16 * OutputData );
  79. extern void ReconBlock_MMX(INT16 *SrcBlock,INT16 *ReconRefPtr, UINT8 *DestBlock, UINT32 LineStep);
  80. extern void SubtractBlock_MMX( UINT8 *SrcBlock, INT16 *DestPtr, UINT32 LineStep );
  81. extern void UnpackBlock_MMX( UINT8 *ReconPtr, INT16 *ReconRefPtr, UINT32 ReconPixelsPerLine);
  82. extern void AverageBlock_MMX( UINT8 *ReconPtr1, UINT8 *ReconPtr2, UINT16 *ReconRefPtr, UINT32 ReconPixelsPerLine);
  83. extern void CopyBlockMMX(unsigned char *src, unsigned char *dest, unsigned int srcstride);
  84. extern void Copy12x12_MMX(const unsigned char *src, unsigned char *dest, unsigned int srcstride, unsigned int deststride);
  85. extern void FilterBlockBil_8_mmx( UINT8 *ReconPtr1, UINT8 *ReconPtr2, UINT8 *ReconRefPtr, UINT32 ReconPixelsPerLine, INT32 ModX, INT32 ModY );
  86. extern void FilterBlock_mmx( UINT8 *ReconPtr1, UINT8 *ReconPtr2, UINT16 *ReconRefPtr, UINT32 PixelsPerLine, INT32 ModX, INT32 ModY, BOOL UseBicubic, UINT8 BicubicAlpha );
  87. // WMT versions
  88. extern void WmtReconIntra( INT16 *TmpDataBuffer, UINT8 * ReconPtr, UINT16 * ChangePtr, UINT32 LineStep );
  89. extern void WmtReconInter( INT16 *TmpDataBuffer, UINT8 * ReconPtr, UINT8 * RefPtr, INT16 * ChangePtr, UINT32 LineStep );
  90. extern void WmtReconInterHalfPixel2( INT16 *TmpDataBuffer, UINT8 * ReconPtr, UINT8 * RefPtr1, UINT8 * RefPtr2, INT16 * ChangePtr, UINT32 LineStep );
  91. extern void Wmt_idct1( Q_LIST_ENTRY * InputData, INT16 *QuantMatrix, INT16 * OutputData );
  92. extern void Wmt_IDct_Dx( Q_LIST_ENTRY * InputData, INT16 *QuantMatrix, INT16 * OutputData );
  93. extern void Wmt_IDct10_Dx( Q_LIST_ENTRY * InputData, INT16 *QuantMatrix, INT16 * OutputData );
  94. extern void fdct_WMT(short *InputData, short *OutputData);
  95. extern void FilterBlockBil_8_wmt( UINT8 *ReconPtr1, UINT8 *ReconPtr2, UINT8 *ReconRefPtr, UINT32 ReconPixelsPerLine, INT32 ModX, INT32 ModY );
  96. extern void FilterBlock_wmt( UINT8 *ReconPtr1, UINT8 *ReconPtr2, UINT16 *ReconRefPtr, UINT32 PixelsPerLine, INT32 ModX, INT32 ModY, BOOL UseBicubic, UINT8 BicubicAlpha );
  97. #define IdctAdjustBeforeShift 8
  98. extern UINT16 idctconstants[(4+7+1) * 4];
  99. extern UINT16 idctcosTbl[ 7];
  100. void fillidctconstants(void)
  101. {
  102. int j = 16;
  103. UINT16 * p;
  104. do
  105. {
  106. idctconstants[ --j] = 0;
  107. }
  108. while( j);
  109. idctconstants[0] = idctconstants[5] = idctconstants[10] = idctconstants[15] = 65535;
  110. j = 1;
  111. do
  112. {
  113. p = idctconstants + ( (j+3) << 2);
  114. p[0] = p[1] = p[2] = p[3] = idctcosTbl[ j - 1];
  115. }
  116. while( ++j <= 7);
  117. idctconstants[44] = idctconstants[45] = idctconstants[46] = idctconstants[47] = IdctAdjustBeforeShift;
  118. }
  119. /****************************************************************************
  120. *
  121. * ROUTINE : Get Processor Flags
  122. *
  123. * INPUTS : None
  124. *
  125. * OUTPUTS : None
  126. *
  127. * RETURNS : None
  128. *
  129. * FUNCTION : Checks for machine specifc features such as MMX support
  130. * sets approipriate flags and function pointers.
  131. *
  132. * SPECIAL NOTES : None.
  133. *
  134. *
  135. * ERRORS : None.
  136. *
  137. ****************************************************************************/
  138. void GetProcessorFlags
  139. (
  140. INT32 *MmxEnabled,
  141. INT32 *XmmEnabled,
  142. INT32 *WmtEnabled
  143. )
  144. {
  145. PROCTYPE CPUType = findCPUId();
  146. if(forceCPUID)
  147. CPUType = CPUID;
  148. switch(CPUType)
  149. {
  150. case X86 :
  151. case PPRO :
  152. case C6X86 :
  153. case C6X86MX:
  154. case AMDK5 :
  155. case MACG3 :
  156. case MAC68K :
  157. *MmxEnabled = FALSE;
  158. *XmmEnabled = FALSE;
  159. *WmtEnabled = FALSE;
  160. break;
  161. case PII :
  162. case AMDK63D:
  163. case AMDK6 :
  164. case PMMX :
  165. *MmxEnabled = TRUE;
  166. *XmmEnabled = FALSE;
  167. *WmtEnabled = FALSE;
  168. break;
  169. case XMM :
  170. *MmxEnabled = TRUE;
  171. *XmmEnabled = TRUE;
  172. *WmtEnabled = FALSE;
  173. break;
  174. case WMT :
  175. *MmxEnabled = TRUE;
  176. *XmmEnabled = TRUE;
  177. *WmtEnabled = TRUE;
  178. break;
  179. }
  180. }
  181. /****************************************************************************
  182. *
  183. * ROUTINE : MachineSpecificConfig
  184. *
  185. * INPUTS : None
  186. *
  187. * OUTPUTS : None
  188. *
  189. * RETURNS : None
  190. *
  191. * FUNCTION : Checks for machine specifc features such as MMX support
  192. * sets approipriate flags and function pointers.
  193. *
  194. * SPECIAL NOTES : None.
  195. *
  196. *
  197. * ERRORS : None.
  198. *
  199. ****************************************************************************/
  200. void UtilMachineSpecificConfig
  201. (
  202. void
  203. )
  204. {
  205. UINT32 i;
  206. INT32 MmxEnabled;
  207. INT32 XmmEnabled;
  208. INT32 WmtEnabled;
  209. GetProcessorFlags( &MmxEnabled,&XmmEnabled,&WmtEnabled);
  210. if(WmtEnabled) //Willamette
  211. {
  212. for(i=0;i<=64;i++)
  213. {
  214. if(fastIDCTDisabled)
  215. idct[i]=Wmt_IDct_Dx;
  216. else
  217. {
  218. if(i<=1)idct[i]=Wmt_idct1;
  219. else if(i<=10)idct[i]=Wmt_IDct10_Dx;
  220. else idct[i]=Wmt_IDct_Dx;
  221. }
  222. }
  223. for(i=0;i<=64;i++)
  224. {
  225. if(fastIDCTDisabled)
  226. idctc[i]=MMX_idct;
  227. else
  228. {
  229. if(i<=1)idctc[i]=Wmt_idct1;
  230. else if(i<=10)idctc[i]=MMX_idct10;
  231. else idctc[i]=MMX_idct;
  232. }
  233. }
  234. fdct_short=fdct_WMT;
  235. ReconIntra = WmtReconIntra;
  236. ReconInter = WmtReconInter;
  237. ReconInterHalfPixel2 = WmtReconInterHalfPixel2;
  238. ClearSysState = ClearMmx;
  239. AverageBlock = AverageBlock_MMX;
  240. UnpackBlock = UnpackBlock_MMX;
  241. ReconBlock = ReconBlock_MMX;
  242. SubtractBlock = SubtractBlock_MMX;
  243. CopyBlock = CopyBlockMMX;
  244. Copy12x12 = Copy12x12_MMX;
  245. FilterBlockBil_8 = FilterBlockBil_8_wmt;
  246. FilterBlock=FilterBlock_wmt;
  247. //FilterBlock=FilterBlock_C;
  248. }
  249. else if ( MmxEnabled )
  250. {
  251. for(i=0;i<=64;i++)
  252. {
  253. if(fastIDCTDisabled)
  254. idctc[i]=MMX_idct_DX;
  255. else
  256. {
  257. if(i<=1)idctc[i]=MMX_idct1;
  258. else if(i<=10)idctc[i]=MMX_idct10;
  259. else idctc[i]=MMX_idct;
  260. }
  261. }
  262. fdct_short=fdct_MMX;
  263. for(i=0;i<=64;i++)
  264. {
  265. if(fastIDCTDisabled)
  266. idct[i]=MMX_idct_DX;
  267. else
  268. {
  269. if(i<=1)idct[i]=MMX_idct1;
  270. else if(i<=10)idct[i]=MMX_idct10_DX;
  271. else idct[i]=MMX_idct_DX;
  272. }
  273. }
  274. ReconIntra = MMXReconIntra;
  275. ReconInter = MmxReconInter;
  276. ReconInterHalfPixel2 = MmxReconInterHalfPixel2;
  277. ClearSysState = ClearMmx;
  278. AverageBlock = AverageBlock_MMX;
  279. UnpackBlock = UnpackBlock_MMX;
  280. ReconBlock = ReconBlock_MMX;
  281. SubtractBlock = SubtractBlock_MMX;
  282. CopyBlock = CopyBlockMMX;
  283. Copy12x12 = Copy12x12_MMX;
  284. FilterBlockBil_8 = FilterBlockBil_8_mmx;
  285. FilterBlock=FilterBlock_mmx;
  286. //FilterBlock=FilterBlock_C;
  287. }
  288. else
  289. {
  290. int i;
  291. for(i=0;i<=64;i++)
  292. {
  293. if(fastIDCTDisabled)
  294. idctc[i]=IDctSlow;
  295. else
  296. {
  297. if(i<=1)idctc[i]=IDct1;
  298. else if(i<=10)idctc[i]=IDct10;
  299. else idctc[i]=IDctSlow;
  300. }
  301. }
  302. fdct_short=fdct_short_C ;
  303. for(i=0;i<=64;i++)
  304. {
  305. if(fastIDCTDisabled)
  306. idct[i]=IDctSlow;
  307. else
  308. {
  309. if(i<=1)idct[i]=IDct1;
  310. else if(i<=10)idct[i]=IDct10;
  311. else idct[i]=IDctSlow;
  312. }
  313. }
  314. ClearSysState = ClearSysState_C;
  315. ReconIntra = ScalarReconIntra;
  316. ReconInter = ScalarReconInter;
  317. ReconInterHalfPixel2 = ScalarReconInterHalfPixel2;
  318. AverageBlock = AverageBlock_C;
  319. UnpackBlock = UnpackBlock_C;
  320. ReconBlock = ReconBlock_C;
  321. SubtractBlock = SubtractBlock_C;
  322. CopyBlock = CopyBlock_C;
  323. Copy12x12 = Copy12x12_MMX;
  324. FilterBlockBil_8 = FilterBlockBil_8_C;
  325. FilterBlock=FilterBlock_C;
  326. }
  327. //FilterBlock=FilterBlock_C;
  328. }