1 | ;; @file
|
---|
2 | ; innotek Portable Runtime - ASMBitFirstClear().
|
---|
3 | ;
|
---|
4 |
|
---|
5 | ;
|
---|
6 | ; Copyright (C) 2006-2007 innotek GmbH
|
---|
7 | ;
|
---|
8 | ; This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | ; available from http://www.virtualbox.org. This file is free software;
|
---|
10 | ; you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | ; General Public License as published by the Free Software Foundation,
|
---|
12 | ; in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
13 | ; distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
14 | ; be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 |
|
---|
16 |
|
---|
17 | ;*******************************************************************************
|
---|
18 | ;* Header Files *
|
---|
19 | ;*******************************************************************************
|
---|
20 | %include "iprt/asmdefs.mac"
|
---|
21 |
|
---|
22 | BEGINCODE
|
---|
23 |
|
---|
24 | ;;
|
---|
25 | ; Finds the first clear bit in a bitmap.
|
---|
26 | ;
|
---|
27 | ; @returns eax Index of the first zero bit.
|
---|
28 | ; @returns eax -1 if no clear bit was found.
|
---|
29 | ; @param rcx pvBitmap Pointer to the bitmap.
|
---|
30 | ; @param edx cBits The number of bits in the bitmap. Multiple of 32.
|
---|
31 | ;
|
---|
32 | BEGINPROC_EXPORTED ASMBitFirstClear
|
---|
33 |
|
---|
34 | ;if (cBits)
|
---|
35 | or edx, edx
|
---|
36 | jz short @failed
|
---|
37 | ;{
|
---|
38 | push rdi
|
---|
39 |
|
---|
40 | ; asm {...}
|
---|
41 | mov rdi, rcx ; rdi = start of scasd
|
---|
42 | mov ecx, edx
|
---|
43 | add ecx, 31 ; 32 bit aligned
|
---|
44 | shr ecx, 5 ; number of dwords to scan.
|
---|
45 | mov rdx, rdi ; rdx = saved pvBitmap
|
---|
46 | mov eax, 0ffffffffh
|
---|
47 | repe scasd ; Scan for the first dword with any clear bit.
|
---|
48 | je @failed_restore
|
---|
49 |
|
---|
50 | ; find the bit in question
|
---|
51 | lea rdi, [rdi - 4] ; one step back.
|
---|
52 | xor eax, [rdi] ; eax = NOT [rdi]
|
---|
53 | sub rdi, rdx
|
---|
54 | shl edi, 3 ; calc bit offset.
|
---|
55 |
|
---|
56 | mov ecx, 0ffffffffh
|
---|
57 | bsf ecx, eax
|
---|
58 | add ecx, edi
|
---|
59 | mov eax, ecx
|
---|
60 |
|
---|
61 | ; return success
|
---|
62 | pop rdi
|
---|
63 | ret
|
---|
64 |
|
---|
65 | ; failure
|
---|
66 | ;}
|
---|
67 | ;return -1;
|
---|
68 | @failed_restore:
|
---|
69 | pop rdi
|
---|
70 | ret
|
---|
71 | @failed:
|
---|
72 | mov eax, 0ffffffffh
|
---|
73 | ret
|
---|
74 | ENDPROC ASMBitFirstClear
|
---|
75 |
|
---|