VirtualBox

source: vbox/trunk/src/VBox/Runtime/win64/ASMBitFirstClear.asm@ 1

Last change on this file since 1 was 1, checked in by vboxsync, 55 years ago

import

File size: 2.5 KB
Line 
1;; @file
2; InnoTek Portable Runtime - ASMBitFirstClear().
3;
4
5;
6; Copyright (C) 2006 InnoTek Systemberatung 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; If you received this file as part of a commercial VirtualBox
17; distribution, then only the terms of your commercial VirtualBox
18; license agreement apply instead of the previous paragraph.
19;
20
21
22;*******************************************************************************
23;* Header Files *
24;*******************************************************************************
25%include "iprt/asmdefs.mac"
26
27BEGINCODE
28
29;;
30; Finds the first clear bit in a bitmap.
31;
32; @returns eax Index of the first zero bit.
33; @returns eax -1 if no clear bit was found.
34; @param rcx pvBitmap Pointer to the bitmap.
35; @param edx cBits The number of bits in the bitmap. Multiple of 32.
36;
37BEGINPROC_EXPORTED ASMBitFirstClear
38
39 ;if (cBits)
40 or edx, edx
41 jz short @failed
42 ;{
43 push rdi
44
45 ; asm {...}
46 mov rdi, rcx ; rdi = start of scasd
47 mov ecx, edx
48 add ecx, 31 ; 32 bit aligned
49 shr ecx, 5 ; number of dwords to scan.
50 mov rdx, rdi ; rdx = saved pvBitmap
51 mov eax, 0ffffffffh
52 repe scasd ; Scan for the first dword with any clear bit.
53 je @failed_restore
54
55 ; find the bit in question
56 lea rdi, [rdi - 4] ; one step back.
57 xor eax, [rdi] ; eax = NOT [rdi]
58 sub rdi, rdx
59 shl edi, 3 ; calc bit offset.
60
61 mov ecx, 0ffffffffh
62 bsf ecx, eax
63 add ecx, edi
64 mov eax, ecx
65
66 ; return success
67 pop rdi
68 ret
69
70 ; failure
71 ;}
72 ;return -1;
73@failed_restore:
74 pop rdi
75 ret
76@failed:
77 mov eax, 0ffffffffh
78 ret
79ENDPROC ASMBitFirstClear
80
Note: See TracBrowser for help on using the repository browser.

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