mrDarker
2025-08-06 2379434200219132ee252f12d47a1e5efd160f42
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
 
.data
SprShift    equ        4
SprMulti    equ        16
 
 
.code
 
 
 
StartSpr        equ        rcx
EndSpr            equ        rdx
pData            equ        r8
wBuffer            equ        r9
 
;4 Param        rbp+ [10h, 18h, 20h, 28h]
 
InspLeft        equ        qword ptr[rbp+ 30h]
InspTop            equ        qword ptr[rbp+ 38h]
InspRight        equ        qword ptr[rbp+ 40h]
InspBottom        equ        qword ptr[rbp+ 48h]
 
DPC_SUPP        equ        qword ptr[rbp+ 50h]
 
iy            equ        r10
rrImgAddr    equ        r11
rrPitch        equ        r12
rrPitch2    equ        r13
 
rrSSpr        equ        r14
rrESpr        equ        r15
 
xxSupp2        equ        xmm3
xxSrc        equ        xmm4
xxSrc2        equ        xmm5
xxCmp        equ        xmm6
xxCmp2        equ        xmm7
xxSpr        equ        xmm8
xxOne        equ        xmm9
xxfSpr        equ        xmm10
xxsSpr        equ        xmm11
xxMinus        equ        xmm12
xxMinus2    equ        xmm13
xxRslt        equ        xmm14
 
 
 
CheckPitchAsmFast        PROC
    local    Result64[2]    :qword
    local    ImgAddrLine    : qword
    local    ImgLineEnd        : qword
    local    ImgLineLength    : qword
    
    local    iPitch            : qword
    local    SPR                : qword
    local    fSpr            : qword
 
    push    rbp
    mov        rbp, rsp
    push    r10
    push    r11
    push    r12
    push    r13
    push    r14
    push    r15
    push    rdi
    push    rsi
    push    rbx
    ADD        rbp, 030h
 
    mov        rrPitch, iPitch
    mov        rrPitch2, rrPitch
    add        rrPitch2, 1h
    
 
    mov        rax, 1
    movd        xxOne, rax        ; 1·Î Ã¤¿î´Ù.(word)
    movdqa        xmm0, xxOne
    punpcklwd    xmm0, xxOne
    pshufd        xxOne, xmm0, 0
    
    mov        rax, SPR
    movd        xxSpr, rax
    movdqa        xmm0, xxSpr
    punpcklwd    xmm0, xxSpr
    pshufd        xxSpr, xmm0, 0
 
    mov        rax, fSpr
    movd        xxfSpr, rax
    movdqa        xmm0, xxfSpr
    punpcklwd    xmm0, xxfSpr
    pshufd        xxfSpr, xmm0, 0
    
    movdqa    xxsSpr, xxSpr
    psubw    xxsSpr, xxfSpr
 
    mov        rax, 32 ; 2Çȼ¿*16spr= 32
    mul        DPC_SUPP
 
    movd        xxSupp2, rax
    movdqa        xmm0, xxSupp2
    punpcklwd    xmm0, xxSupp2
    pshufd        xxSupp2, xmm0, 0
 
; À̹ÌÁö ÁÖ¼Ò ¸¸µé±â
    mov        rrImgAddr, pData
    mov        rax, wBuffer    ; ImgAddr= ImgAddr+ BuffWidth*InspTop + InspLeft;
    mul        InspTop
    add        rax, InspLeft
    add        rrImgAddr, rax
    mov        ImgAddrLine, rrImgAddr
    
    mov        rax, InspRight
    sub        rax, InspLeft
    mov        ImgLineLength, rax
    
    add        rax, rrImgAddr
    mov        ImgLineEnd, rax
 
    mov        iy, InspTop
    pxor    xxRslt, xxRslt
    pxor    xmm0, xmm0
 
Cmp_16:
                                        ; 1. Src Buffer
    movdqu    xxSrc, [rrImgAddr]            ; Load
    movdqa    xxSrc2, xxSrc    
    punpcklbw    xxSrc, xmm0                ; Unpack
    punpckhbw    xxSrc2, xmm0    
 
    movdqu    xxMinus, [rrImgAddr+ 1]            ; Load
    movdqa    xxMinus2, xxMinus    
    punpcklbw    xxMinus, xmm0                ; Unpack
    punpckhbw    xxMinus2, xmm0    
    paddw    xxSrc, xxMinus
    paddw    xxSrc2, xxMinus2
 
 
    pmullw    xxSrc, xxSpr                ; SPR
    pmullw    xxSrc2, xxSpr
 
 
                                        ;    2. Compare Buffer
    movdqu    xxCmp, [rrImgAddr+ rrPitch]    ; Load
    movdqa    xxCmp2, xxCmp
    punpcklbw    xxCmp, xmm0                ; Unpack
    punpckhbw    xxCmp2, xmm0
    pmullw    xxCmp, xxfSpr                ; fSpr
    pmullw    xxCmp2, xxfSpr
 
    psubw    xxSrc, xxCmp                ; SPR - fSpr
    psubw    xxSrc2, xxCmp2
 
    movdqu    xxCmp, [rrImgAddr+ rrPitch2]
    movdqa    xxCmp2, xxCmp
    punpcklbw    xxCmp, xmm0
    punpckhbw    xxCmp2, xmm0
    pmullw    xxCmp, xxSpr
    pmullw    xxCmp2, xxSpr
 
    psubw    xxSrc, xxCmp
    psubw    xxSrc2, xxCmp2
 
 
    movdqu    xxCmp, [rrImgAddr+ rrPitch2+ 1]        ; Load
    movdqa    xxCmp2, xxCmp
    punpcklbw    xxCmp, xmm0                ; Unpack
    punpckhbw    xxCmp2, xmm0
    pmullw    xxCmp, xxsSpr                ; sSpr
    pmullw    xxCmp2, xxsSpr
 
    psubw    xxSrc, xxCmp                ; (SPR- fSpr) - sSpr
    psubw    xxSrc2, xxCmp2
 
 
    pabsw    xxSrc, xxSrc                ; Àý´ë°ª
    psubusw    xxSrc, xxSupp2
    pmaddwd    xxSrc, xxOne                ; multiply and add ( 16 -> 32)
    pabsw    xxSrc2, xxSrc2                ; Àý´ë°ª
    psubusw    xxSrc2, xxSupp2
    pmaddwd    xxSrc2, xxOne                ; multiply and add ( 16 -> 32)
 
    movdqa    xxCmp, xxSrc
    punpckldq    xxCmp, xmm0                ; unpack 32 -> 64
    punpckhdq    xxSrc, xmm0
    
    paddq    xxRslt, xxSrc                ; add to Result(64)
    paddq    xxRslt, xxCmp                ; add to Result(64)
 
    movdqa    xxCmp, xxSrc2
    punpckldq    xxCmp, xmm0                ; unpack 32 -> 64
    punpckhdq    xxSrc2, xmm0
 
    paddq    xxRslt, xxSrc2                ; add to Result(64)
    paddq    xxRslt, xxCmp                ; add to Result(64)
 
 
    add    rrImgAddr, 10h
    cmp    rrImgAddr, ImgLineEnd
    jl    Cmp_16
    
    inc    iy
    cmp    iy, InspBottom
    jge    End_Buff
 
 
    mov    rax, ImgAddrLine
    add    rax, wBuffer
    mov    ImgAddrLine, rax
    mov    rrImgAddr, rax
    
    add    rax, ImgLineLength
    mov    ImgLineEnd, rax
    
    jmp    Cmp_16
 
 
End_Buff:
 
    lea        rcx, Result64
    movdqu    [rcx], xxRslt
    mov        rax, [rcx]
    add        rax, [rcx+8h]
    
    
    
    pop    rbx
    pop    rsi
    pop    rdi
    pop    r15
    pop    r14
    pop    r13
    pop    r12
    pop    r11
    pop    r10
    pop        rbp
 
RET
 
CheckPitchAsmFast    ENDP
 
 
 
 
 
 
 
 
 
ix            equ        rsi
iy            equ        rdi
rrBW        equ        r9
rrImgAddr    equ        r10
rrNoise    equ        r11        ; Noise Value at Current Pitch
rrLeast    equ        r12        ; Least Noise Value
rrPitch    equ        r13        ; Pitch at Least Noise Value
 
 
xxTemp        equ        xmm1
xxOne        equ        xmm11
xxSrc        equ        xmm2
xxSrc2        equ        xmm3
xxCmp        equ        xmm4
xxRef0        equ        xmm5
xxRef1        equ        xmm6
xxRef2        equ        xmm7
xxRef3        equ        xmm8
 
xxZeroBack    equ        xmm10
xxNoise    equ        xmm15
 
 
 
 
 
end