]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Changes in shared code that don't affect open-vm-tools functionality.
authorVMware, Inc <>
Wed, 18 Sep 2013 03:26:30 +0000 (20:26 -0700)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Mon, 23 Sep 2013 05:06:59 +0000 (22:06 -0700)
Signed-off-by: Dmitry Torokhov <dtor@vmware.com>
open-vm-tools/lib/include/util.h
open-vm-tools/lib/include/vm_basic_math.h

index 276ddd55f391a49468ecdb3ba74ef0a79d454b34..d28054d57d199a3a9277f60ac0ac27de80bd7c1c 100644 (file)
@@ -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 */
index 164921da313b02bb5543c4431f4887a524ef8c1d..4811f0a712a843d6e45e02acf5e7373df9e0b13c 100644 (file)
@@ -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_