Changeset 3592


Ignore:
Timestamp:
Sep 23, 2007, 9:50:24 AM (18 years ago)
Author:
bird
Message:

Made it work on 64-bit progs too.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kStuff/kProfiler2/prfamd64msc.asm

    r3586 r3592  
    8383        push    r10
    8484        push    r11
    85         sub     rsp, 30h                ; rsp is aligned at this point (7 pushes).
     85        sub     rsp, 28h                ; rsp is unaligned at this point (8 pushes).
    8686                                        ; reserve 20h for spill, and 8 bytes for ts.
    8787
     
    9191        or      r8, rax                 ; param 3 - the timestamp
    9292        mov     [rsp + 20h], r8         ; save the tsc for later use.
    93         lea     rdx, [rsp + 7*8 + 30h]  ; Param 2 - frame pointer (pointer to the return address of the function calling us)
     93        lea     rdx, [rsp + 8*8 + 28h]  ; Param 2 - frame pointer (pointer to the return address of the function calling us)
    9494        mov     rcx, [rdx]              ; Param 1 - The function address
    9595        call    KPRF_ENTER
     
    127127        push    r10
    128128        push    r11
    129         sub     rsp, 30h                ; rsp is aligned at this point (7 pushes).
     129        sub     rsp, 28h                ; rsp is unaligned at this point (8 pushes).
    130130                                        ; reserve 20h for spill, and 8 bytes for ts.
    131131
    132         ; setting up the leave call frame.
     132        ; setting up the enter call frame
    133133        mov     r8d, edx
    134134        shl     r8, 32
    135135        or      r8, rax                 ; param 3 - the timestamp
    136136        mov     [rsp + 20h], r8         ; save the tsc for later use.
    137         lea     rdx, [rsp + 7*8 + 30h]  ; Param 2 - frame pointer (pointer to the return address of the function calling us)
     137        lea     rdx, [rsp + 8*8 + 28h]  ; Param 2 - frame pointer (pointer to the return address of the function calling us)
    138138        mov     rcx, [rdx]              ; Param 1 - The function address
    139139        call    KPRF_LEAVE
     
    148148common_return_path:
    149149        ; Update overhead
    150         test    eax, eax
     150        test    rax, rax
    151151        jz      common_no_overhead
    152152        cmp     byte [g_fCalibrated wrt rip], 0
     
    166166
    167167        ; restore volatile registers.
    168         add     rsp, 30h
     168        add     rsp, 28h
    169169        pop     r11
    170170        pop     r10
     
    180180; Data rsi points to while we're calibrating.
    181181struc CALIBDATA
    182     .OverheadLo resd 1
    183     .OverheadHi resd 1
    184     .ProfiledLo resd 1
    185     .ProfiledHi resd 1
    186     .EnterTSLo  resd 1
    187     .EnterTSHi  resd 1
    188     .MinLo      resd 1
    189     .MinHi      resd 1
     182    .Overhead   resq 1
     183    .Profiled   resq 1
     184    .EnterTS    resq 1
     185    .Min        resq 1
    190186endstruc
    191187
     
    219215        mov     rsi, rsp                ; rsi points to the CALIBDATA
    220216
    221         and     rsp, -15
     217        and     rsp, -16
    222218
    223219        ;
     
    238234        ;
    239235        mov     ecx, 200h
    240         mov     dword [rsi + CALIBDATA.MinLo], 0ffffffffh
    241         mov     dword [rsi + CALIBDATA.MinHi], 07fffffffh
     236        mov     dword [rsi + CALIBDATA.Min], 0ffffffffh
     237        mov     dword [rsi + CALIBDATA.Min + 4], 07fffffffh
    242238calib_inner_loop:
    243239
    244240        ; zero the overhead and profiled times.
    245241        xor     eax, eax
    246         mov     [rsi + CALIBDATA.OverheadLo], rax
    247         mov     [rsi + CALIBDATA.ProfiledLo], rax
     242        mov     [rsi + CALIBDATA.Overhead], rax
     243        mov     [rsi + CALIBDATA.Profiled], rax
    248244        call    calib_nullproc
    249245
    250246        ; subtract the overhead
    251         mov     rax, [rsi + CALIBDATA.ProfiledLo]
    252         sub     rax, [rsi + CALIBDATA.OverheadLo]
     247        mov     rax, [rsi + CALIBDATA.Profiled]
     248        sub     rax, [rsi + CALIBDATA.Overhead]
    253249
    254250        ; update the minimum value.
    255251        bt      rax, 63
    256252        jc near calib_outer_dec        ; if negative, just simplify and shortcut
    257         cmp     rax, [rsi + CALIBDATA.MinHi]
     253        cmp     rax, [rsi + CALIBDATA.Min]
    258254        jge     calib_inner_next
    259255calib_inner_update_minimum:
    260         mov     [rsi + CALIBDATA.MinLo], rax
     256        mov     [rsi + CALIBDATA.Min], rax
    261257calib_inner_next:
    262258        loop    calib_inner_loop
    263259
    264260        ; Is the minimum value acceptable?
    265         test    dword [rsi + CALIBDATA.MinLo + 4], 80000000h
     261        test    dword [rsi + CALIBDATA.Min + 4], 80000000h
    266262        jnz     calib_outer_dec         ; simplify if negative.
    267         cmp     dword [rsi + CALIBDATA.MinHi + 4], 0
     263        cmp     dword [rsi + CALIBDATA.Min + 4], 0
    268264        jnz     calib_outer_inc         ; this shouldn't be possible
    269         cmp     dword [rsi + CALIBDATA.MinLo], 1fh
     265        cmp     dword [rsi + CALIBDATA.Min], 1fh
    270266        jbe     calib_outer_dec         ; too low - 2 ticks per pair is the minimum!
    271         cmp     dword [rsi + CALIBDATA.MinLo], 30h
    272         jbe     calib_done              ; this is fine!
     267        ;cmp     dword [rsi + CALIBDATA.Min], 30h
     268        ;jbe     calib_done              ; this is fine!
     269        cmp     dword [rsi + CALIBDATA.Min], 70h ; - a bit weird...
     270        jbe     calib_outer_next         ; do the full 200h*200h iteration
    273271calib_outer_inc:
    274272        inc     dword [g_OverheadAdj wrt rip]
     
    284282
    285283        ; epilog - restore it all.
    286         leave
     284        mov     rsp, rbp
    287285        pop     r15
    288286        pop     r14
     
    300298        pop     rax
    301299        popfq
     300        pop     rbp
    302301        ret
    303302
     
    319318        push    r10
    320319        push    r11
    321         sub     rsp, 30h                ; rsp is aligned at this point (7 pushes).
     320        sub     rsp, 28h                ; rsp is unaligned at this point (8 pushes).
    322321                                        ; reserve 20h for spill, and 8 bytes for ts.
    323322
     
    328327        mov     [rsp + 20h], r8
    329328
    330         mov     [rsi + CALIBDATA.EnterTSLo], r8
    331 
    332         lea     rax, [rsi + CALIBDATA.OverheadLo]
     329        mov     [rsi + CALIBDATA.EnterTS], r8
     330
     331        lea     rax, [rsi + CALIBDATA.Overhead]
    333332        jmp     common_overhead
    334333
     
    348347        push    r10
    349348        push    r11
    350         sub     rsp, 30h                ; rsp is aligned at this point (7 pushes).
     349        sub     rsp, 28h                ; rsp is unaligned at this point (8 pushes).
    351350                                        ; reserve 20h for spill, and 8 bytes for ts.
    352351
     
    357356        mov     [rsp + 20h], r8
    358357
    359         sub     r8, [rsi + CALIBDATA.EnterTSLo]
    360         add     [rsi + CALIBDATA.ProfiledLo], r8
    361 
    362         lea     rax, [rsi + CALIBDATA.EnterTSLo]
     358        sub     r8, [rsi + CALIBDATA.EnterTS]
     359        add     [rsi + CALIBDATA.Profiled], r8
     360
     361        lea     rax, [rsi + CALIBDATA.EnterTS]
    363362        jmp     common_overhead
    364363
Note: See TracChangeset for help on using the changeset viewer.