⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 text_idct_mmx.c

📁 mpeg4源代码
💻 C
📖 第 1 页 / 共 2 页
字号:

/**************************************************************************
 *                                                                        *
 * This code is developed by John Funnell.  This software is an           *
 * an implementation of a part of one or more MPEG-4 Video tools as       *
 * specified in ISO/IEC 14496-2 standard.  Those intending to use this    *
 * software module in hardware or software products are advised that its  *
 * use may infringe existing patents or copyrights, and any such use      *
 * would be at such party's own risk.  The original developer of this     *
 * software module and his/her company, and subsequent editors and their  *
 * companies (including Project Mayo), will have no liability for use of  *
 * this software or modifications or derivatives thereof.                 *
 *                                                                        *
 * Project Mayo gives users of the Codec a license to this software       *
 * module or modifications thereof for use in hardware or software        *
 * products claiming conformance to the MPEG-4 Video Standard as          *
 * described in the Open DivX license.                                    *
 *                                                                        *
 * The complete Open DivX license can be found at                         *
 * http://www.projectmayo.com/opendivx/license.php .                      *
 *                                                                        *
 **************************************************************************/

/**************************************************************************
 *
 *  text_idct_mmx.c
 *
 *  Copyright (C) 2001  Project Mayo
 *
 *  John Funnell
 *
 *  DivX Advance Research Center <darc@projectmayo.com>
 *
 **************************************************************************/

/* This file contains idct functions with MMX optimization.               */
/* Please see acknowledgement below.                                      */

/*
;
; MMX iDCT
;
; Originally provided by Intel at AP-922
; http://developer.intel.com/vtune/cbts/strmsimd/922down.htm
; (See more app notes at http://developer.intel.com/vtune/cbts/strmsimd/appnotes.htm)
; but in a limited edition.
; New macro implements a column part for precise iDCT
; The routine precision now satisfies IEEE standard 1180-1990. 
;
; Copyright (c) 2000-2001 Peter Gubanov <peter@elecard.net.ru>
; Rounding trick Copyright (c) 2000 Michel Lespinasse <walken@zoy.org>
;
; http://www.elecard.com/peter/idct.html
; http://www.linuxvideo.org/mpeg2dec/
;
; Conversion to MS-style inline C format (c) 2001 Project Mayo Inc. John Funnell
;
; Version v1.0.0 10 January 2001
;
*/


/*
 if you are not setting the name of you MMX idct function with compile flag MMX_IDCT_NAME,
 then you need to choose a name to insert in here:
*/
#define DEFAULT_FUNCTION_NAME       Fast_IDCT



#ifndef MMX_IDCT_NAME
#define MMX_IDCT_NAME DEFAULT_FUNCTION_NAME
#endif



/* some types */
#define int16_t short
#define int32_t int
#define uint64_t unsigned __int64

#define MPTR qword ptr 


/* some conversions from readable integer constants to qwords */
#define SHORT4_TO_QWORD(A, B, C, D)   ( \
    ( ( ((uint64_t)(A)) & ((uint64_t)(0xffff)) )  <<  0 ) | \
    ( ( ((uint64_t)(B)) & ((uint64_t)(0xffff)) )  << 16 ) | \
    ( ( ((uint64_t)(C)) & ((uint64_t)(0xffff)) )  << 32 ) | \
    ( ( ((uint64_t)(D)) & ((uint64_t)(0xffff)) )  << 48 ) ) 

#define INT2_TO_QWORD(A, B)    ( \
    ( ( ((uint64_t)(A)) & ((uint64_t)(0xffffffff)) )  <<  0 ) | \
    ( ( ((uint64_t)(B)) & ((uint64_t)(0xffffffff)) )  << 32 ) )




#define BITS_INV_ACC      5                             /* 4 or 5 for IEEE */
#define SHIFT_INV_ROW     (16 - BITS_INV_ACC)
#define SHIFT_INV_COL     (1 + BITS_INV_ACC)
#define RND_INV_ROW       (1024 * (6 - BITS_INV_ACC))   /* 1 << (SHIFT_INV_ROW-1) */
#define RND_INV_COL       (16 * (BITS_INV_ACC - 3))     /* 1 << (SHIFT_INV_COL-1) */
#define RND_INV_CORR      (RND_INV_COL - 1)             /* correction -1.0 and round */
#define BITS_FRW_ACC      3                             /* 2 or 3 for accuracy */
#define SHIFT_FRW_COL     BITS_FRW_ACC
#define SHIFT_FRW_ROW     (BITS_FRW_ACC + 17)
#define RND_FRW_ROW       (262144 * (BITS_FRW_ACC - 1)) /* 1 << (SHIFT_FRW_ROW-1) */






static const uint64_t   tg_1_16 = SHORT4_TO_QWORD( 13036,  13036,  13036,  13036 );
static const uint64_t   tg_2_16 = SHORT4_TO_QWORD( 27146,  27146,  27146,  27146 );
static const uint64_t   tg_3_16 = SHORT4_TO_QWORD(-21746, -21746, -21746, -21746 );
static const uint64_t ocos_4_16 = SHORT4_TO_QWORD( 23170,  23170,  23170,  23170 );




/* rounding value that is added before the row transform's rounding */


#if   SHIFT_INV_ROW == 12
static const uint64_t rounder[8] = {
	INT2_TO_QWORD( 65536, 65536), /* rounder_0 */       
	INT2_TO_QWORD(  7195,  7195), /* rounder_1 */ 
	INT2_TO_QWORD(  4520,  4520), /* rounder_2 */ 
	INT2_TO_QWORD(  2407,  2407), /* rounder_3 */ 
	INT2_TO_QWORD(     0,     0), /* rounder_4 */ 
	INT2_TO_QWORD(   240,   240), /* rounder_5 */
	INT2_TO_QWORD(  1024,  1024), /* rounder_6 */
	INT2_TO_QWORD(  1024,  1024)  /* rounder_7 */
};
#elif SHIFT_INV_ROW == 11
static const uint64_t rounder[2*8] = {
	INT2_TO_QWORD( 65536, 65536), /* rounder_0 */
	INT2_TO_QWORD(  3597,  3597), /* rounder_1 */
	INT2_TO_QWORD(  2260,  2260), /* rounder_2 */
	INT2_TO_QWORD(  1203,  1203), /* rounder_3 */
	INT2_TO_QWORD( 	 0,	  0), /* rounder_4 */
	INT2_TO_QWORD(   120,	120), /* rounder_5 */
	INT2_TO_QWORD(   512,	512), /* rounder_6 */
	INT2_TO_QWORD(   512,	512)  /* rounder_7 */
};
#endif



/*
;=============================================================================
;
; The first stage iDCT 8x8 - inverse DCTs of rows
;
;-----------------------------------------------------------------------------
; The 8-point inverse DCT direct algorithm
;-----------------------------------------------------------------------------
;
; static const short w[32] = {
; FIX(cos_4_16), FIX(cos_2_16), FIX(cos_4_16), FIX(cos_6_16),
; FIX(cos_4_16), FIX(cos_6_16), -FIX(cos_4_16), -FIX(cos_2_16),
; FIX(cos_4_16), -FIX(cos_6_16), -FIX(cos_4_16), FIX(cos_2_16),
; FIX(cos_4_16), -FIX(cos_2_16), FIX(cos_4_16), -FIX(cos_6_16),
; FIX(cos_1_16), FIX(cos_3_16), FIX(cos_5_16), FIX(cos_7_16),
; FIX(cos_3_16), -FIX(cos_7_16), -FIX(cos_1_16), -FIX(cos_5_16),
; FIX(cos_5_16), -FIX(cos_1_16), FIX(cos_7_16), FIX(cos_3_16),
; FIX(cos_7_16), -FIX(cos_5_16), FIX(cos_3_16), -FIX(cos_1_16) };
;
; #define DCT_8_INV_ROW(x, y)
;{
; int a0, a1, a2, a3, b0, b1, b2, b3;
;
; a0 =x[0]*w[0]+x[2]*w[1]+x[4]*w[2]+x[6]*w[3];
; a1 =x[0]*w[4]+x[2]*w[5]+x[4]*w[6]+x[6]*w[7];
; a2 = x[0] * w[ 8] + x[2] * w[ 9] + x[4] * w[10] + x[6] * w[11];
; a3 = x[0] * w[12] + x[2] * w[13] + x[4] * w[14] + x[6] * w[15];
; b0 = x[1] * w[16] + x[3] * w[17] + x[5] * w[18] + x[7] * w[19];
; b1 = x[1] * w[20] + x[3] * w[21] + x[5] * w[22] + x[7] * w[23];
; b2 = x[1] * w[24] + x[3] * w[25] + x[5] * w[26] + x[7] * w[27];
; b3 = x[1] * w[28] + x[3] * w[29] + x[5] * w[30] + x[7] * w[31];
;
; y[0] = SHIFT_ROUND ( a0 + b0 );
; y[1] = SHIFT_ROUND ( a1 + b1 );
; y[2] = SHIFT_ROUND ( a2 + b2 );
; y[3] = SHIFT_ROUND ( a3 + b3 );
; y[4] = SHIFT_ROUND ( a3 - b3 );
; y[5] = SHIFT_ROUND ( a2 - b2 );
; y[6] = SHIFT_ROUND ( a1 - b1 );
; y[7] = SHIFT_ROUND ( a0 - b0 );
;}
;
;-----------------------------------------------------------------------------
;
; In this implementation the outputs of the iDCT-1D are multiplied
; for rows 0,4 - by cos_4_16,
; for rows 1,7 - by cos_1_16,
; for rows 2,6 - by cos_2_16,
; for rows 3,5 - by cos_3_16
; and are shifted to the left for better accuracy
;
; For the constants used,
; FIX(float_const) = (short) (float_const * (1<<15) + 0.5)
;
;=============================================================================
*/


/*
;=============================================================================
; code for MMX
;=============================================================================
; Table for rows 0,4 - constants are multiplied by cos_4_16
*/
static const uint64_t tab_i_04[8*8] = {
/* Table for rows 0,4 - constants are multiplied by cos_4_16 */
 	SHORT4_TO_QWORD( 16384,  16384,  16384, -16384 ),   /* movq-> w06 w04 w02 w00 */
	SHORT4_TO_QWORD( 21407,   8867,   8867, -21407 ),   /*        w07 w05 w03 w01 */
	SHORT4_TO_QWORD( 16384, -16384,  16384,  16384 ),   /*        w14 w12 w10 w08 */
	SHORT4_TO_QWORD( -8867,  21407, -21407,  -8867 ),   /*        w15 w13 w11 w09 */
	SHORT4_TO_QWORD( 22725,  12873,  19266, -22725 ),   /*        w22 w20 w18 w16 */
	SHORT4_TO_QWORD( 19266,   4520,  -4520, -12873 ),   /*        w23 w21 w19 w17 */
	SHORT4_TO_QWORD( 12873,   4520,   4520,  19266 ),   /*        w30 w28 w26 w24 */
	SHORT4_TO_QWORD(-22725,  19266, -12873, -22725 ),   /*        w31 w29 w27 w25 */
/* Table for rows 1,7 - constants are multiplied by cos_1_16 */
	SHORT4_TO_QWORD( 22725,  22725,  22725, -22725 ),   /* movq-> w06 w04 w02 w00 */
	SHORT4_TO_QWORD( 29692,  12299,  12299, -29692 ),   /*        w07 w05 w03 w01 */
	SHORT4_TO_QWORD( 22725, -22725,  22725,  22725 ),   /*        w14 w12 w10 w08 */
	SHORT4_TO_QWORD(-12299,  29692, -29692, -12299 ),   /*        w15 w13 w11 w09 */
	SHORT4_TO_QWORD( 31521,  17855,  26722, -31521 ),   /*        w22 w20 w18 w16 */
	SHORT4_TO_QWORD( 26722,   6270,  -6270, -17855 ),   /*        w23 w21 w19 w17 */
	SHORT4_TO_QWORD( 17855,   6270,   6270,  26722 ),   /*        w30 w28 w26 w24 */
	SHORT4_TO_QWORD(-31521,  26722, -17855, -31521 ),   /*        w31 w29 w27 w25 */
/* Table for rows 2,6 - constants are multiplied by cos_2_16 */
	SHORT4_TO_QWORD( 21407,  21407,  21407, -21407 ),   /* movq-> w06 w04 w02 w00 */
	SHORT4_TO_QWORD( 27969,  11585,  11585, -27969 ),   /*        w07 w05 w03 w01 */
	SHORT4_TO_QWORD( 21407, -21407,  21407,  21407 ),   /*        w14 w12 w10 w08 */
	SHORT4_TO_QWORD(-11585,  27969, -27969, -11585 ),   /*        w15 w13 w11 w09 */
	SHORT4_TO_QWORD( 29692,  16819,  25172, -29692 ),   /*        w22 w20 w18 w16 */
	SHORT4_TO_QWORD( 25172,   5906,  -5906, -16819 ),   /*        w23 w21 w19 w17 */
	SHORT4_TO_QWORD( 16819,   5906,   5906,  25172 ),   /*        w30 w28 w26 w24 */
	SHORT4_TO_QWORD(-29692,  25172, -16819, -29692 ),   /*        w31 w29 w27 w25 */
/* Table for rows 3,5 - constants are multiplied by cos_3_16 */
	SHORT4_TO_QWORD( 19266,  19266,  19266, -19266 ),   /* movq-> w06 w04 w02 w00 */
	SHORT4_TO_QWORD( 25172,  10426,  10426, -25172 ),   /*        w07 w05 w03 w01 */
	SHORT4_TO_QWORD( 19266, -19266,  19266,  19266 ),   /*        w14 w12 w10 w08 */
	SHORT4_TO_QWORD(-10426,  25172, -25172, -10426 ),   /*        w15 w13 w11 w09 */
	SHORT4_TO_QWORD( 26722,  15137,  22654, -26722 ),   /*        w22 w20 w18 w16 */
	SHORT4_TO_QWORD( 22654,   5315,  -5315, -15137 ),   /*        w23 w21 w19 w17 */
	SHORT4_TO_QWORD( 15137,   5315,   5315,  22654 ),   /*        w30 w28 w26 w24 */
	SHORT4_TO_QWORD(-26722,  22654, -15137, -26722 ),   /*        w31 w29 w27 w25 */
/* Table for rows 0,4 - constants are multiplied by cos_4_16 */
 	SHORT4_TO_QWORD( 16384,  16384,  16384, -16384 ),   /* movq-> w06 w04 w02 w00 */
	SHORT4_TO_QWORD( 21407,   8867,   8867, -21407 ),   /*        w07 w05 w03 w01 */
	SHORT4_TO_QWORD( 16384, -16384,  16384,  16384 ),   /*        w14 w12 w10 w08 */
	SHORT4_TO_QWORD(-8867,  21407, -21407,  -8867  ),   /*        w15 w13 w11 w09 */
	SHORT4_TO_QWORD( 22725,  12873,  19266, -22725 ),   /*        w22 w20 w18 w16 */
	SHORT4_TO_QWORD( 19266,   4520,  -4520, -12873 ),   /*        w23 w21 w19 w17 */
	SHORT4_TO_QWORD( 12873,   4520,   4520,  19266 ),   /*        w30 w28 w26 w24 */
	SHORT4_TO_QWORD(-22725,  19266, -12873, -22725 ),   /*        w31 w29 w27 w25 */
/* Table for rows 3,5 - constants are multiplied by cos_3_16 */
	SHORT4_TO_QWORD( 19266,  19266,  19266, -19266 ),   /* movq-> w06 w04 w02 w00 */
	SHORT4_TO_QWORD( 25172,  10426,  10426, -25172 ),   /*        w07 w05 w03 w01 */
	SHORT4_TO_QWORD( 19266, -19266,  19266,  19266 ),   /*        w14 w12 w10 w08 */
	SHORT4_TO_QWORD(-10426,  25172, -25172, -10426 ),   /*        w15 w13 w11 w09 */
	SHORT4_TO_QWORD( 26722,  15137,  22654, -26722 ),   /*        w22 w20 w18 w16 */
	SHORT4_TO_QWORD( 22654,   5315,  -5315, -15137 ),   /*        w23 w21 w19 w17 */
	SHORT4_TO_QWORD( 15137,   5315,   5315,  22654 ),   /*        w30 w28 w26 w24 */
	SHORT4_TO_QWORD(-26722,  22654, -15137, -26722 ),   /*        w31 w29 w27 w25 */
/* Table for rows 2,6 - constants are multiplied by cos_2_16 */
	SHORT4_TO_QWORD( 21407,  21407,  21407, -21407 ),   /* movq-> w06 w04 w02 w00 */
	SHORT4_TO_QWORD( 27969,  11585,  11585, -27969 ),   /*        w07 w05 w03 w01 */
	SHORT4_TO_QWORD( 21407, -21407,  21407,  21407 ),   /*        w14 w12 w10 w08 */
	SHORT4_TO_QWORD(-11585,  27969, -27969, -11585 ),   /*        w15 w13 w11 w09 */
	SHORT4_TO_QWORD( 29692,  16819,  25172, -29692 ),   /*        w22 w20 w18 w16 */
	SHORT4_TO_QWORD( 25172,   5906,  -5906, -16819 ),   /*        w23 w21 w19 w17 */
	SHORT4_TO_QWORD( 16819,   5906,   5906,  25172 ),   /*        w30 w28 w26 w24 */
	SHORT4_TO_QWORD(-29692,  25172, -16819, -29692 ),   /*        w31 w29 w27 w25 */
/* Table for rows 1,7 - constants are multiplied by cos_1_16 */
	SHORT4_TO_QWORD( 22725,  22725,  22725, -22725 ),   /* movq-> w06 w04 w02 w00 */
	SHORT4_TO_QWORD( 29692,  12299,  12299, -29692 ),   /*        w07 w05 w03 w01 */
	SHORT4_TO_QWORD( 22725, -22725,  22725,  22725 ),   /*        w14 w12 w10 w08 */
	SHORT4_TO_QWORD(-12299,  29692, -29692, -12299 ),   /*        w15 w13 w11 w09 */
	SHORT4_TO_QWORD( 31521,  17855,  26722, -31521 ),   /*        w22 w20 w18 w16 */
	SHORT4_TO_QWORD( 26722,   6270,  -6270, -17855 ),   /*        w23 w21 w19 w17 */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -