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

📄 tables.asm

📁 这是一个JPEG解码器,里面使用了MMX,SSE等汇编指令集
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;// Tables

.686P
.MODEL FLAT, STDCALL
OPTION CASEMAP:NONE
OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE
.MMX

INCLUDE jpeg.inc

.CONST

data_start = $

;// Decoder machine state

;// Macro to define a state
stateno = 0
STATE MACRO s
  LOCAL statename,ad
  ad = $
  s = stateno
  stateno = stateno + 1
  EXITM <@CatStr(TBL_Trans_,s)>
ENDM

;// Macro to define transition
TRANS MACRO marker, new_state, func
  EXITM <dword marker OR new_state SHL 8 OR func SHL 16>
ENDM

;// Macro to define a transition function
funcno = 1
TFUNC MACRO func_id, func
  IF funcno EQ 256
    .ERR <Funcno too big>
  ENDIF
  func_id = funcno
  func PROTO
  funcno = funcno + 1
  EXITM <dword func>
ENDM

ALIGN 4
;// Transition functions
TBL_TransFunc TFUNC(TRANS_SOF,    JPG_SOF)
              TFUNC(TRANS_SOS,    JPG_SOS)
              TFUNC(TRANS_DQT,    JPG_DQT)
              TFUNC(TRANS_DHT,    JPG_DHT)
              TFUNC(TRANS_DRI,    JPG_DRI)
              TFUNC(TRANS_RST,    JPG_RST)
              TFUNC(TRANS_EOI,    JPG_EOI)
              TFUNC(TRANS_ECS,    JPG_ECS)
              TFUNC(TRANS_SOI,    JPG_SOI)
              TFUNC(TRANS_SKIP,   JPG_SKIP)
              TFUNC(TRANS_UNSUPP, JPG_UNSUPP)

;// State transition
;// marker, new state, transition function
STATE(DEAD)   TRANS(mSOI, SOI,    TRANS_SOI)
              TRANS(0FFh, DEAD,   TRANS_UNSUPP)

STATE(SOI)    TRANS(mSOS,  ECS,   TRANS_SOS)
              TRANS(mSOF0, SOI,   TRANS_SOF)
              TRANS(mSOF1, SOI,   TRANS_SOF)
              TRANS(mDQT,  SOI,   TRANS_DQT)
              TRANS(mDHT,  SOI,   TRANS_DHT)
              TRANS(mDRI,  SOI,   TRANS_DRI)
              TRANS(mAPPs, SOI,   TRANS_SKIP)
              TRANS(0FFh,  DEAD,  TRANS_UNSUPP)

STATE(ECS)    TRANS(mEOI,  DEAD,  TRANS_EOI)
              TRANS(mRST,  ECS,   TRANS_RST)
              TRANS(0FFh,  DEAD,  TRANS_UNSUPP)

TBL_TransList dword TBL_Trans_DEAD
              dword TBL_Trans_SOI
              dword TBL_Trans_ECS

;// Table[i] = 64 - i
ALIGN 8
TBL_64 qword  64, 63, 62, 61, 60, 59, 58, 57
       qword  56, 55, 54, 53, 52, 51, 50, 49
       qword  48, 47, 46, 45, 44, 43, 42, 41
       qword  40, 39, 38, 37, 36, 35, 34, 33
       qword  32, 31, 30, 29, 28, 27, 26, 25
       qword  24, 23, 22, 21, 20, 19, 18, 17
       qword  16, 15, 14, 13, 12, 11, 10, 9
       qword  8, 7, 6, 5, 4, 3, 2, 1, 0

;// convert zig-zag index to array index (from IJG code by Thomas Lane)
TBL_jpeg_natural_order byte   0,  1,  8, 16,  9,  2,  3, 10
                       byte   17, 24, 32, 25, 18, 11,  4,  5
                       byte   12, 19, 26, 33, 40, 48, 41, 34
                       byte   27, 20, 13,  6,  7, 14, 21, 28
                       byte   35, 42, 49, 56, 57, 50, 43, 36
                       byte   29, 22, 15, 23, 30, 37, 44, 51
                       byte   58, 59, 52, 45, 38, 31, 39, 46
                       byte   53, 60, 61, 54, 47, 55, 62, 63
                       byte   63, 63, 63, 63, 63, 63, 63, 63
                       byte   63, 63, 63, 63, 63, 63, 63, 63

;// IDCT functions
TBL_IDCT_SSE2 dword IDCT_8x16_SSE2, IDCT_16x8_SSE2, IDCT_16x16_SSE2, IDCT_8x8_SSE2
TBL_IDCT_SSE  dword IDCT_8x16_SSE, IDCT_16x8_SSE, IDCT_16x16_SSE, IDCT_8x8_SSE
TBL_IDCT      dword TBL_IDCT_SSE, TBL_IDCT_SSE2, TBL_IDCT_SSE2

;// IDCT constants
ALIGN 16
TBL_tg1_16    real4 4 dup (0.1989123674)    ;// tan(1*Pi/16)
TBL_tg2_16    real4 4 dup (0.4142135625)    ;// tan(2*Pi/16)
TBL_tg3_16    real4 4 dup (0.6681786380)    ;// tan(3*Pi/16)
TBL_tg1_32    real4 4 dup (0.9849140272e-1) ;// tan(1*Pi/32)
TBL_tg3_32    real4 4 dup (0.3033466831)    ;// tan(3*Pi/32)
TBL_tg5_32    real4 4 dup (0.5345111356)    ;// tan(5*Pi/32)
TBL_tg7_32    real4 4 dup (0.8206787908)    ;// tan(7*Pi/32)
TBL_cos2_16   real4 4 dup (0.9238795325)    ;// cos(2*Pi/16)
TBL_cos4_16   real4 4 dup (0.7071067810)    ;// cos(4*Pi/16)

;// 8-point IDCT

;// tbl[i] = multiplier for row i
TBL_MultRow8x8 dword TBL_8x8_04, TBL_8x8_17, TBL_8x8_26, TBL_8x8_35
               dword TBL_8x8_04, TBL_8x8_35, TBL_8x8_26, TBL_8x8_17

ALIGN 16

;// rows 0,4
;// w = (cos(4*Pi/16)/4)*transpose(M8)*transpose(P8)
TBL_8x8_04  real4 0.1250000000, 0.1250000000, 0.1250000000, 0.1250000000          ;// movaps->w12 w08 w04 w00
            real4 0.1633203706, 0.6764951250e-1, -0.6764951250e-1, -0.1633203706  ;// w13 w09 w05 w01
            real4 0.1250000000, -0.1250000000, -0.1250000000, 0.1250000000        ;// w14 w10 w06 w02
            real4 0.6764951250e-1, -0.1633203706, 0.1633203706, -0.6764951250e-1  ;// w15 w11 w07 w03
            real4 0.1733799806, 0.1469844502, 0.9821186980e-1, 0.3448742240e-1    ;// w28 w24 w20 w16
            real4 0.1469844502, -0.3448742240e-1, -0.1733799806, -0.9821186980e-1 ;// w29 w25 w21 w17
            real4 0.9821186980e-1, -0.1733799806, 0.3448742240e-1, 0.1469844502   ;// w30 w26 w22 w18
            real4 0.3448742240e-1, -0.9821186980e-1, 0.1469844502, -0.1733799806  ;// w31 w27 w23 w19

;// rows 1,7
;// w = (cos(1*Pi/16)/4)*transpose(M8)*transpose(P8)
TBL_8x8_17  real4 0.1733799806, 0.1733799806, 0.1733799806, 0.1733799806
            real4 0.2265318616, 0.9383256940e-1, -0.9383256940e-1, -0.2265318616
            real4 0.1733799806, -0.1733799806, -0.1733799806, 0.1733799806
            real4 0.9383256940e-1, -0.2265318616, 0.2265318616, -0.9383256940e-1
            real4 0.2404849416, 0.2038732892, 0.1362237767, 0.4783542905e-1
            real4 0.2038732892, -0.4783542905e-1, -0.2404849416, -0.1362237767
            real4 0.1362237767, -0.2404849416, 0.4783542905e-1, 0.2038732892
            real4 0.4783542905e-1, -0.1362237767, 0.2038732892, -0.2404849416     

;// rows 2,6
;// w = (cos(2*Pi/16)/4)*transpose(M8)*transpose(P8)
TBL_8x8_26  real4 0.1633203706, 0.1633203706, 0.1633203706, 0.1633203706
            real4 0.2133883476, 0.8838834765e-1, -0.8838834765e-1, -0.2133883476
            real4 0.1633203706, -0.1633203706, -0.1633203706, 0.1633203706
            real4 0.8838834770e-1, -0.2133883476, 0.2133883476, -0.8838834765e-1
            real4 0.2265318616, 0.1920444392, 0.1283199918, 0.4505998888e-1
            real4 0.1920444392, -0.4505998888e-1, -0.2265318616, -0.1283199918
            real4 0.1283199918, -0.2265318616, 0.4505998888e-1, 0.1920444392
            real4 0.4505998888e-1, -0.1283199918, 0.1920444392, -0.2265318616    

;// rows 3,5
;// w = (cos(3*Pi/16)/4)*transpose(M8)*transpose(P8)
TBL_8x8_35  real4 0.1469844502, 0.1469844502, 0.1469844502, 0.1469844502
            real4 0.1920444392, 0.7954741130e-1, -0.7954741130e-1, -0.1920444392
            real4 0.1469844502, -0.1469844502, -0.1469844502, 0.1469844502
            real4 0.7954741130e-1, -0.1920444392, 0.1920444392, -0.7954741130e-1
            real4 0.2038732892, 0.1728354290, 0.1154849416, 0.4055291860e-1
            real4 0.1728354290, -0.4055291860e-1, -0.2038732892, -0.1154849416
            real4 0.1154849416, -0.2038732892, 0.4055291860e-1, 0.1728354290
            real4 0.4055291860e-1, -0.1154849416, 0.1728354290, -0.2038732892    

;// 16-point IDCT

TBL_MultRow16x16  dword TBL_16x16_08, TBL_16x16_1F, TBL_16x16_2E, TBL_16x16_3D
                  dword TBL_16x16_4C, TBL_16x16_5B, TBL_16x16_6A, TBL_16x16_79

ALIGN 16

;// rows 0,8
;// w = (cos(8*Pi/32)/8)*transpose(M16)*transpose(P16)
TBL_16x16_08    real4 0.1250000000, 0.1250000000, 0.1250000000, 0.1250000000
                real4 0.1733799806, 0.1469844502, 0.9821186975e-1, 0.3448742240e-1
                real4 0.1633203706, 0.6764951252e-1, -0.6764951252e-1, -0.1633203706

⌨️ 快捷键说明

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