From: VMware, Inc <> Date: Thu, 17 Jun 2010 21:20:34 +0000 (-0700) Subject: Consistent, unambiguous, non-colliding bit function names X-Git-Tag: 2010.06.16-268169~141 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=221f45e1f7e4eaef989c5226ea0419775b76d954;p=thirdparty%2Fopen-vm-tools.git Consistent, unambiguous, non-colliding bit function names We don't have complete set of find most/least significant bit set functions available throughout the source base. Create them. I created these functions by taking the monitor's complete set of functions, moving them to vm_basic_asm.h and renaming them such that they have consistent, unambiguous names that don't collide with ANSI, Linux or MacOS functions or differ in data types. The immediately problematic functions were ffs, fls, ffsl, flsl and fls64. Here is a table to assist with reviewing the change: NAME FUNCTION BITS ON ZERO MONITOR NAME ----- -------- ---- ------- ------------ lssb32 LSB set (uint32) 1..32 0 ffs lssb32_0 LSB set (uint32) 0..31 -1 ffs0 lssb64 LSB set (uint64) 1..64 0 ffs64 lssb64_0 LSB set (uint64) 0..63 -1 lssbPtr LSB set (uintptr_t) 1..32|64 0 ffsl lssbPtr_0 LSB set (uintptr_t) 0..31|63 -1 ffs0l mssb32 MSB set (uint32) 1..32 0 fls mssb32_0 MSB set (uint32) 0..31 -1 fls0 mssb64 MSB set (uint64) 1..64 0 fls64 mssb64_0 MSB set (uint64) 0..63 -1 mssbPtr MSB set (uintptr_t) 1..32|64 0 flsl mssbPtr_0 MSB set (uintptr_t) 0..31|63 -1 fls0l This change is the first of several. It establishes the functions and make one use of them in an obvious, easy place. I'll start converting the source base to use these functions in pieces. The monitor will be the last piece touched and there I'll demonstrate no size or performance changes - and correctness too. In the end the entire source base will be using the one consistent set of bit functions. Signed-off-by: Marcelo Vanzin --- diff --git a/open-vm-tools/lib/include/vm_basic_asm.h b/open-vm-tools/lib/include/vm_basic_asm.h index 9e1984344..08af6813a 100644 --- a/open-vm-tools/lib/include/vm_basic_asm.h +++ b/open-vm-tools/lib/include/vm_basic_asm.h @@ -60,7 +60,6 @@ #include "vm_basic_asm_x86.h" #endif - /* * x86-64 windows doesn't support inline asm so we have to use these * intrinsic functions defined in the compiler. Not all of these are well @@ -101,20 +100,20 @@ void _ReadWriteBarrier(void); * intrinsic functions only supported by x86-64 windows as of 2k3sp1 */ unsigned __int64 __rdtsc(void); -void __stosw(unsigned short*, unsigned short, size_t); -void __stosd(unsigned long*, unsigned long, size_t); -#pragma intrinsic(__rdtsc, __stosw, __stosd) - -/* - * intrinsic functions supported by x86-64 windows and newer x86 - * compilers (13.01.2035 for _BitScanForward). - */ -unsigned char _BitScanForward(unsigned long*, unsigned long); -unsigned char _BitScanReverse(unsigned long*, unsigned long); -void _mm_pause(void); -#pragma intrinsic(_BitScanForward, _BitScanReverse, _mm_pause) +void __stosw(unsigned short *, unsigned short, size_t); +void __stosd(unsigned long *, unsigned long, size_t); +void _mm_pause(void); +#pragma intrinsic(__rdtsc, __stosw, __stosd, _mm_pause) + +unsigned char _BitScanForward64(unsigned long *, unsigned __int64); +unsigned char _BitScanReverse64(unsigned long *, unsigned __int64); +#pragma intrinsic(_BitScanForward64, _BitScanReverse64) #endif /* VM_X86_64 */ +unsigned char _BitScanForward(unsigned long *, unsigned long); +unsigned char _BitScanReverse(unsigned long *, unsigned long); +#pragma intrinsic(_BitScanForward, _BitScanReverse) + #ifdef __cplusplus } #endif @@ -232,39 +231,248 @@ OUT32(uint16 port, uint32 value) __GET_EAX_FROM_CPUID(1), \ __GET_MSR(MSR_BIOS_SIGN_ID)) -#ifdef _MSC_VER +/* + * Locate most and least significant bit set functions. Use our own name + * space to avoid namespace collisions. The new names follow a pattern, + *