forked from gurnec/HashCheck
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GetHighMSB.h
73 lines (57 loc) · 1.72 KB
/
GetHighMSB.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* HashCheck Shell Extension
* Copyright (C) Kai Liu. All rights reserved.
*
* Please refer to readme.txt for information about this source code.
* Please refer to license.txt for details about distribution and modification.
**/
#ifndef __GETHIGHMSB_H__
#define __GETHIGHMSB_H__
#ifdef __cplusplus
extern "C" {
#endif
// -----------------------------------------------------------------------------
// LODWORD/HIDWORD helper macros
#define LODWORD(ull) ((DWORD)((ull) & 0xFFFFFFFF))
#define HIDWORD(ull) ((DWORD)((ull) >> 32))
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// GetHighMSB
// Gets the 1-based index of the most significant bit of the upper 32-bits of
// a 64-bit integer; this is the smallest number by which the integer could be
// shifted so that the upper 32-bits are unused.
#if _MSC_VER >= 1310
#ifndef __INTRIN_H_
unsigned char _BitScanReverse( unsigned long *, unsigned long );
#endif
#pragma intrinsic(_BitScanReverse)
__forceinline UINT GetHighMSB( PULARGE_INTEGER puli )
{
UINT uIndex;
if (_BitScanReverse(&uIndex, puli->HighPart))
return(uIndex + 1);
else
return(0);
}
#elif defined(_M_IX86)
#pragma warning(push)
#pragma warning(disable: 4035) // returns for inline asm functions
__forceinline UINT GetHighMSB( PULARGE_INTEGER puli )
{
DWORD dwHigh = puli->HighPart;
__asm
{
bsr eax,dwHigh
jnz done
or eax,-1
done:
inc eax
}
}
#pragma warning(pop)
#endif
// -----------------------------------------------------------------------------
#ifdef __cplusplus
}
#endif
#endif