From: VMware, Inc <> Date: Wed, 18 Sep 2013 03:26:30 +0000 (-0700) Subject: Changes in shared code that don't affect open-vm-tools functionality. X-Git-Tag: 2013.09.16-1328054~69 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cbfdc1a390497f46bc15d1bff0dd91f9775a3780;p=thirdparty%2Fopen-vm-tools.git Changes in shared code that don't affect open-vm-tools functionality. Signed-off-by: Dmitry Torokhov --- diff --git a/open-vm-tools/lib/include/util.h b/open-vm-tools/lib/include/util.h index 276ddd55f..d28054d57 100644 --- a/open-vm-tools/lib/include/util.h +++ b/open-vm-tools/lib/include/util.h @@ -1,5 +1,5 @@ /********************************************************* - * Copyright (C) 1998-2012 VMware, Inc. All rights reserved. + * Copyright (C) 1998-2013 VMware, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published @@ -636,4 +636,45 @@ Util_IsFileDescriptorOpen(int fd) // IN } #endif /* !_WIN32 */ + +/* + *----------------------------------------------------------------------------- + * + * Util_Memcpy32 -- + * + * Special purpose version of memcpy that requires nbytes be a + * multiple of 4. This assumption lets us have a very small, + * inlineable implementation. + * + * Results: + * dst + * + * Side effects: + * See above. + * + *----------------------------------------------------------------------------- + */ + +static INLINE void * +Util_Memcpy32(void *dst, const void *src, size_t nbytes) +{ + ASSERT((nbytes % 4) == 0); +#if defined __GNUC__ && (defined(__i386__) || defined(__x86_64__)) + do { + int dummy0, dummy1, dummy2; + __asm__ __volatile__( + "cld \n\t" + "rep ; movsl" "\n\t" + : "=&c" (dummy0), "=&D" (dummy1), "=&S" (dummy2) + : "0" (nbytes / 4), "1" ((long) dst), "2" ((long) src) + : "memory", "cc" + ); + return dst; + } while (0); +#else + return memcpy(dst, src, nbytes); +#endif +} + + #endif /* UTIL_H */ diff --git a/open-vm-tools/lib/include/vm_basic_math.h b/open-vm-tools/lib/include/vm_basic_math.h index 164921da3..4811f0a71 100644 --- a/open-vm-tools/lib/include/vm_basic_math.h +++ b/open-vm-tools/lib/include/vm_basic_math.h @@ -70,4 +70,15 @@ IsPowerOfTwo(uint32 x) return !(x & (x - 1)); } +static INLINE uint32 +GetPowerOfTwo(uint32 x) +{ + /* Returns next-greatest power-of-two. */ + uint32 power2 = 1; + while (x > power2) { + power2 = power2 << 1; + } + return power2; +} + #endif // ifndef _VM_BASIC_MATH_H_