News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Advanced centering window proc

Started by jdoe, January 19, 2006, 06:06:15 PM

Previous topic - Next topic

Snouphruh

Quote from: Tedd on January 30, 2006, 10:48:08 AM
The reason for push-pop is to avoid messing up any registers. If you have a register to spare, then I would use it.
Or even better, if you have two..

    mov eax, rectDesktop.left
    mov ecx, rectDesktop.top
    mov rectParent.left, eax
    mov rectParent.top, ecx

    mov eax, rectDesktop.right
    mov ecx, rectDesktop.bottom
    mov rectParent.right, eax
    mov rectParent.bottom, ecx


Yeah, it's better!
But if we can use more than just 2 registers.
And some moments: let's rectDesktop has lower address location than rectParent does, i. e. rectParent follows rectDesktop. It will use L2 cache more efficient, therefore it will gain in speed of execution.

mov esi, offset rectDesktop ; the same as mov esi, offset rectDesktop.left
mov edi, offset rectParent ; the same as mov edi, offset rectParent.left

; ^^^^^
; these 2 instructions pair, i. e. they take 1 clock.

mov eax, [esi]
mov ecx, [esi + 4] ; the same as mov ecx, [esi + RECT.top]
mov edx, [esi + 8] ; the same as mov edx, [esi + RECT.right]
mov ebx, [esi + 12] ; the same as mov ebx, [esi + RECT.bottom]

;^^^^^ loading
; each element follows each other, i. e. the next element has the higher address location.
; these 4 instructions pair, i. e. they take 2 clocks.
; L2 line cache has 64 byte size (processor depended).
; it's no memory penalties here.

mov [edi], eax
mov [edi + 4], ecx ; the same as mov [edi + RECT.top], ecx
mov [edi + 8], edx ; the same as mov [edi + RECT.right], edx
mov [edi + 12], ebx ; the same as mov [edi + RECT.bottom], ebx

;^^^^^ storing
; look loading
; you can use ESI instead EDI here:
; mov [esi + 16], eax
; mov [edi + 20], ecx
; mov [edi + 24], edx
; mov [edi + 28], ebx


Some documentations say that using REP MOVSD is faster than using pairing.

mov esi, offset rectDektop
mov edi, offset rectParent
mov ecx, 4
rep movsd