VirtualBox

source: vbox/trunk/src/VBox/Runtime/win/amd64/ASMBitFirstSet.asm@ 5490

Last change on this file since 5490 was 4071, checked in by vboxsync, 17 years ago

Biggest check-in ever. New source code headers for all (C) innotek files.

File size: 2.3 KB
Line 
1;; @file
2; innotek Portable Runtime - ASMBitFirstSet().
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
22BEGINCODE
23
24;;
25; Finds the first set bit in a bitmap.
26;
27; @returns eax Index of the first set 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;
32BEGINPROC_EXPORTED ASMBitFirstSet
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 xor eax, eax
47 repe scasd ; Scan for the first dword with any set bit.
48 je @failed_restore
49
50 ; find the bit in question
51 lea rdi, [rdi - 4] ; one step back.
52 mov eax, [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@failed:
71 mov eax, 0ffffffffh
72 ret
73ENDPROC ASMBitFirstSet
74
75
76
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