VirtualBox

Ignore:
Timestamp:
Nov 18, 2015 6:04:10 PM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
104187
Message:

ASMBitFirstClear.asm: work in progress.

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/asm/ASMBitFirstClear.asm

    r58720 r58746  
     1; $Id: $
    12;; @file
    23; IPRT - ASMBitFirstClear().
     
    3536; Finds the first clear bit in a bitmap.
    3637;
    37 ; @returns eax  Index of the first zero bit.
    38 ; @returns eax  -1 if no clear bit was found.
    39 ; @param   rcx pvBitmap    Pointer to the bitmap.
    40 ; @param   edx cBits       The number of bits in the bitmap. Multiple of 32.
     38; @returns (32/64:eax, 16:ax+dx)   Index of the first zero bit.
     39; @returns (32/64:eax, 16:ax+dx)  -1 if no clear bit was found.
     40; @param   msc:rcx gcc:rdi pvBitmap    Pointer to the bitmap.
     41; @param   msc:edx gcc:rsi cBits       The number of bits in the bitmap. Multiple of 32.
    4142;
    4243BEGINPROC_EXPORTED ASMBitFirstClear
    43 
    44         ;if (cBits)
    45         or      edx, edx
     44        ;
     45        ; if (cBits)
     46        ; Put cBits in ecx first.
     47        ;
     48%if    ARCH_BITS == 64
     49 %ifdef ASM_CALL64_GCC
     50        mov     ecx, esi
     51 %else
     52        xchg    ecx, edx                ; rdx=pvDst, ecx=cBits
     53 %endif
     54%elif ARCH_BITS == 32
     55        mov     ecx, [esp + 4 + 4]
     56%elif ARCH_BITS == 16
     57        push    bp
     58        mov     bp, sp
     59        mov     ecx, [bp + 4 + 4]
     60%endif
     61        or      ecx, ecx
    4662        jz      short .failed
    4763        ;{
    48         push    rdi
     64        push    xDI
    4965
    5066        ;    asm {...}
    51         mov     rdi, rcx                ; rdi = start of scasd
    52         mov     ecx, edx
     67%if    ARCH_BITS == 64
     68 %ifdef ASM_CALL64_GCC
     69                                        ; rdi = start of scasd - already done
     70 %else
     71        mov     rdi, rdx                ; rdi = start of scasd (Note! xchg rdx,rcx above)
     72 %endif
     73%elif ARCH_BITS == 32
     74        mov     edi, [esp + 4]
     75%elif ARCH_BITS == 16
     76        mov     ax, [bp + 4 + 2]
     77        mov     di, [bp + 4]
     78        mov     es, ax                  ; es is volatile, no need to save.
     79%endif
    5380        add     ecx, 31                 ; 32 bit aligned
    5481        shr     ecx, 5                  ; number of dwords to scan.
    55         mov     rdx, rdi                ; rdx = saved pvBitmap
     82        mov     xDX, xDI                ; xDX = saved pvBitmap
    5683        mov     eax, 0ffffffffh
    57         repe    scasd                   ; Scan for the first dword with any clear bit.
     84        repe scasd                      ; Scan for the first dword with any clear bit.
    5885        je      .failed_restore
    5986
    6087        ; find the bit in question
    61         lea     rdi, [rdi - 4]          ; one step back.
    62         xor     eax, [rdi]              ; eax = NOT [rdi]
    63         sub     rdi, rdx
     88        sub     xDI, 4                  ; one step back.
     89%if ARCH_BITS == 16
     90        movzx   edi, di
     91        xor     eax, [es:xDI]           ; eax = NOT [rdi]
     92%else
     93        xor     eax, [edi]              ; eax = NOT [rdi]
     94%endif
     95        jz      .failed_restore         ; race paranoia
     96        sub     xDI, xDX
    6497        shl     edi, 3                  ; calc bit offset.
    6598
     
    70103
    71104        ; return success
    72         pop     rdi
     105        pop     xDI
     106%if ARCH_BITS == 16
     107        leave
     108%endif
    73109        ret
    74110
     
    77113        ;return -1;
    78114.failed_restore:
    79         pop     rdi
     115        pop     xDI
     116%if ARCH_BITS == 16
     117        mov     edx, eax
     118        shr     edx, 16
     119        leave
     120%endif
    80121        ret
     122
    81123.failed:
     124%if ARCH_BITS != 16
    82125        mov     eax, 0ffffffffh
     126%else
     127        mov     ax, 0ffffh
     128        mov     dx, ax
     129        leave
     130%endif
    83131        ret
    84132ENDPROC ASMBitFirstClear
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette