Changeset 58746 in vbox for trunk/src/VBox/Runtime/common/asm
- Timestamp:
- Nov 18, 2015 6:04:10 PM (9 years ago)
- svn:sync-xref-src-repo-rev:
- 104187
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/asm/ASMBitFirstClear.asm
r58720 r58746 1 ; $Id: $ 1 2 ;; @file 2 3 ; IPRT - ASMBitFirstClear(). … … 35 36 ; Finds the first clear bit in a bitmap. 36 37 ; 37 ; @returns eaxIndex of the first zero bit.38 ; @returns eax-1 if no clear bit was found.39 ; @param rcxpvBitmap Pointer to the bitmap.40 ; @param edxcBits 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. 41 42 ; 42 43 BEGINPROC_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 46 62 jz short .failed 47 63 ;{ 48 push rdi64 push xDI 49 65 50 66 ; 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 53 80 add ecx, 31 ; 32 bit aligned 54 81 shr ecx, 5 ; number of dwords to scan. 55 mov rdx, rdi ; rdx= saved pvBitmap82 mov xDX, xDI ; xDX = saved pvBitmap 56 83 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. 58 85 je .failed_restore 59 86 60 87 ; 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 64 97 shl edi, 3 ; calc bit offset. 65 98 … … 70 103 71 104 ; return success 72 pop rdi 105 pop xDI 106 %if ARCH_BITS == 16 107 leave 108 %endif 73 109 ret 74 110 … … 77 113 ;return -1; 78 114 .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 80 121 ret 122 81 123 .failed: 124 %if ARCH_BITS != 16 82 125 mov eax, 0ffffffffh 126 %else 127 mov ax, 0ffffh 128 mov dx, ax 129 leave 130 %endif 83 131 ret 84 132 ENDPROC ASMBitFirstClear
Note:
See TracChangeset
for help on using the changeset viewer.