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

📄 dbg.inc

📁 这是一个JPEG解码器,里面使用了MMX,SSE等汇编指令集
💻 INC
字号:
;// Debugging flag and macros

OPTION CASEMAP:NONE

;// debug flags
IF DEBUG
    DEBUG_FILE = 1
    DEBUG_WND = 0
    DEBUG_CHECKBS = 0
    DEBUG_IDCT_IN = 0
    DEBUG_IDCT_OUT = 0
    DEBUG_DECODE = 0
    DEBUG_EXTEND = 0
    DEBUG_MARKER = 0
    DEBUG_MEM = 0
    DEBUG_SOF = 1
    DEBUG_SOS = 1
    DEBUG_DRI = 0
    DEBUG_QTABLE = 0
    DEBUG_HTABLE = 0
    DEBUG_CPUID = 0
    DEBUG_PROFILE = 0
ELSE
    DEBUG_FILE = 0
    DEBUG_WND = 0
    DEBUG_CHECKBS = 0
    DEBUG_IDCT_IN = 0
    DEBUG_IDCT_OUT = 0
    DEBUG_DECODE = 0
    DEBUG_EXTEND = 0
    DEBUG_MARKER = 0
    DEBUG_MEM = 0
    DEBUG_SOF = 0
    DEBUG_SOS = 0
    DEBUG_DRI = 0
    DEBUG_QTABLE = 0
    DEBUG_HTABLE = 0
    DEBUG_CPUID = 0
    DEBUG_PROFILE = 0
ENDIF

;// debug proto
DBG_Start PROTO
DBG_Stop PROTO
DBG_Output PROTO
DBG_PrintMarker PROTO
DBG_DumpIdctIn PROTO
DBG_DumpIdctOut8x8 PROTO
DBG_DumpIdctOut16x16 PROTO
DBG_DumpIdctOut16x8 PROTO
DBG_DumpIdctOut8x16 PROTO
DBG_Jfif PROTO
DBG_Sof PROTO
DBG_Sos PROTO
DBG_Dri PROTO
DBG_Qtable PROTO
DBG_Htable PROTO
DBG_CheckBS PROTO
DBG_Dump8x8DWords PROTO
DBG_Dump8x8Words PROTO
DBG_DumpNxMFloats PROTO
DBG_Cpuid PROTO
DBG_ProfileIn PROTO
DBG_ProfileOut PROTO

;// profiling struct by mark_larson
IF DEBUG_PROFILE
    MAGIC_PROF = 'FORP'
    PROFILE STRUCT 1
        magic       dword ?
        curtime     qword ?
        totaltime   qword ?
        numcalls    dword ?
        funcname    dword ?
    PROFILE ENDS
ENDIF

;// use sprintf
IF DEBUG
    DEBUG_SPRINTF = 1
ELSE
    DEBUG_SPRINTF = 0
ENDIF        

;// segment containing profiling structures
IF DEBUG_PROFILE
    DEBUG_SPRINTF = 1
    ProfSeg$01 SEGMENT byte
    ProfSeg$01 ENDS
    ProfSeg TEXTEQU <ProfSeg$01>
ENDIF

;// global buffer used by printf
EXTERNDEF pDBG_Buffer:dword

;// start debugging
DBGSTART MACRO
IF DEBUG
        call        DBG_Start
ENDIF
ENDM

;// stop debugging
DBGSTOP MACRO
IF DEBUG 
        call        DBG_Stop
ENDIF 
ENDM

;// printf a message 
DBG MACRO fmt:REQ, vars:VARARG
LOCAL TxtName
IF DEBUG
        IF DEBUG_SPRINTF
            sprintf PROTO C :dword, :dword, :VARARG
            PRINTF EQU <sprintf>
        ELSE
            wsprintfA PROTO C :dword, :dword, :VARARG
            PRINTF EQU <wsprintfA>
        ENDIF  

        pushad
        pushfd

        .DATA
        TxtName byte fmt, 0
        .CODE
        IFB <&vars>
            INVOKE  PRINTF, pDBG_Buffer, OFFSET TxtName
        ELSE
            INVOKE  PRINTF, pDBG_Buffer, OFFSET TxtName, &vars
        ENDIF
        INVOKE  DBG_Output
        popfd
        popad
ENDIF
ENDM

;// int3 if cdt failed
ASSERT MACRO cdt:req
IF DEBUG
        .IF ( ! (&cdt) )
        int       3 
        .ENDIF
ENDIF
ENDM

;// dump idct input
DBG_IDCT_IN MACRO
IF DEBUG_IDCT_IN
        call        DBG_DumpIdctIn
ENDIF
ENDM

;// dump idct output (8x8)
DBG_IDCT_OUT_8x8 MACRO
IF DEBUG_IDCT_OUT
        call        DBG_DumpIdctOut8x8
ENDIF
ENDM

;// dump idct output (16x16)
DBG_IDCT_OUT_16x16 MACRO
IF DEBUG_IDCT_OUT
        call        DBG_DumpIdctOut16x16
ENDIF
ENDM

;// dump idct output (8x16)
DBG_IDCT_OUT_8x16 MACRO
IF DEBUG_IDCT_OUT
        call        DBG_DumpIdctOut8x16
ENDIF
ENDM

;// dump idct output (16x8)
DBG_IDCT_OUT_16x8 MACRO
IF DEBUG_IDCT_OUT
        call        DBG_DumpIdctOut16x8
ENDIF
ENDM

;// dump huffman decoded value
DBG_DECODE MACRO
IF DEBUG_DECODE
        DBG "<DECODE>"
        DBG "  %d", eax
        DBG "</DECODE>"
ENDIF
ENDM

;// dump bits read in ECS
DBG_EXTEND MACRO
IF DEBUG_EXTEND
        DBG "<EXTEND>"
        DBG "  %d", eax
        DBG "</EXTEND>"
ENDIF
ENDM

;// dump marker
DBG_MARKER MACRO
IF DEBUG_MARKER
        call        DBG_PrintMarker
ENDIF
ENDM

;// dump allocated size
DBG_MEMSIZE MACRO
IF DEBUG_MEM
        DBG "<MEM>"
        DBG "  siz : %d", eax
ENDIF
ENDM

;// dump allocated pointer
DBG_MEMPTR MACRO
IF DEBUG_MEM
        DBG "  ptr : 0x%x", eax
        DBG "</MEM>"
ENDIF
ENDM

;// dump memory release
DBG_MEMFREE MACRO
IF DEBUG_MEM
        DBG "<MEM>"
        DBG "  free : 0x%x", eax
        DBG "</MEM>"
ENDIF
ENDM

;// dump SOF marker
DBG_SOF MACRO
IF DEBUG_SOF
        call        DBG_Sof
ENDIF
ENDM

;// dump SOS marker
DBG_SOS MACRO
IF DEBUG_SOS
        call        DBG_Sos
ENDIF
ENDM

;// dump DRI marker
DBG_DRI MACRO
IF DEBUG_DRI
        call        DBG_Dri
ENDIF
ENDM

;// dump quantization table
DBG_QTABLE MACRO
IF DEBUG_QTABLE
        call        DBG_Qtable
ENDIF
ENDM

;// dump huffman table index
DBG_HTABLE MACRO
IF DEBUG_HTABLE
        call        DBG_Htable
ENDIF
ENDM

;// dump huffman table index
DBG_CHECKBS MACRO
IF DEBUG_CHECKBS
        call        DBG_CheckBS
ENDIF
ENDM

;// dump cpu features
DBG_CPUID MACRO
IF DEBUG_CPUID
        call        DBG_Cpuid
ENDIF
ENDM

;// Profile function entry
_DBG_PROFIN MACRO
LOCAL prof

ProfSeg SEGMENT byte
prof PROFILE <>
ProfSeg ENDS

        mov         DPTR [prof].PROFILE.magic, MAGIC_PROF
        push        eax
        push        edx
        pushfd
        rdtsc
        mov         DPTR [prof].PROFILE.curtime[4], edx
        mov         DPTR [prof].PROFILE.curtime[0], eax
        popfd
        pop         edx
        pop         eax

        EXITM <prof>

ENDM

;// Profile function exit
_DBG_PROFOUT MACRO prof:req, msg:req
        push        eax
        push        edx
        pushfd
        rdtsc
        sub         eax, DPTR [prof].PROFILE.curtime[0]
        sbb         edx, DPTR [prof].PROFILE.curtime[4]
        add         DPTR [prof].PROFILE.totaltime[0], eax
        adc         DPTR [prof].PROFILE.totaltime[4], edx
        inc         DPTR [prof].PROFILE.numcalls
        mov         DPTR [prof].PROFILE.funcname, OFFSET msg
        popfd
        pop         edx
        pop         eax
ENDM

;// start profiling
PROFILE_IN MACRO
IF DEBUG_PROFILE
        __t = _DBG_PROFIN()
ENDIF
ENDM

;// stop profiling with a msg
PROFILE_OUT MACRO msg:req,p
LOCAL s,p
IF DEBUG_PROFILE
        .DATA
        s byte msg, 0
        .CODE
        _DBG_PROFOUT __t, s
        IFNB <p>
            p = __t
        ENDIF
ENDIF
ENDM

⌨️ 快捷键说明

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