remove trailing whitespaces
[dpdk.git] / lib / librte_eal / common / include / rte_common.h
index 236f98a..921b91f 100644 (file)
@@ -1,13 +1,13 @@
 /*-
  *   BSD LICENSE
- * 
- *   Copyright(c) 2010-2013 Intel Corporation. All rights reserved.
+ *
+ *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
  *   All rights reserved.
- * 
+ *
  *   Redistribution and use in source and binary forms, with or without
  *   modification, are permitted provided that the following conditions
  *   are met:
- * 
+ *
  *     * Redistributions of source code must retain the above copyright
  *       notice, this list of conditions and the following disclaimer.
  *     * Redistributions in binary form must reproduce the above copyright
@@ -17,7 +17,7 @@
  *     * Neither the name of Intel Corporation nor the names of its
  *       contributors may be used to endorse or promote products derived
  *       from this software without specific prior written permission.
- * 
+ *
  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@@ -49,6 +49,7 @@ extern "C" {
 #include <stdlib.h>
 #include <ctype.h>
 #include <errno.h>
+#include <limits.h>
 
 /*********** Macros to eliminate unused variable warnings ********/
 
@@ -68,12 +69,12 @@ extern "C" {
 /**
  * add a byte-value offset from a pointer
  */
-#define RTE_PTR_ADD(ptr, x) ((typeof(ptr))((uintptr_t)ptr + (x)))
+#define RTE_PTR_ADD(ptr, x) ((void*)((uintptr_t)(ptr) + (x)))
 
 /**
  * subtract a byte-value offset from a pointer
  */
-#define RTE_PTR_SUB(ptr, x) ((typeof(ptr))((uintptr_t)ptr - (x)))
+#define RTE_PTR_SUB(ptr, x) ((void*)((uintptr_t)ptr - (x)))
 
 /**
  * get the difference between two pointer values, i.e. how far apart
@@ -129,7 +130,7 @@ rte_align_floor_int(uintptr_t ptr, uintptr_t align)
  * must be a power-of-two value.
  */
 #define RTE_PTR_ALIGN_CEIL(ptr, align) \
-       RTE_PTR_ALIGN_FLOOR(RTE_PTR_ADD(ptr, (align) - 1), align)
+       RTE_PTR_ALIGN_FLOOR((typeof(ptr))RTE_PTR_ADD(ptr, (align) - 1), align)
 
 /**
  * Macro to align a value to a given power-of-two. The resultant value
@@ -227,6 +228,29 @@ rte_align32pow2(uint32_t x)
        return x + 1;
 }
 
+/**
+ * Aligns 64b input parameter to the next power of 2
+ *
+ * @param x
+ *   The 64b value to algin
+ *
+ * @return
+ *   Input parameter aligned to the next power of 2
+ */
+static inline uint64_t
+rte_align64pow2(uint64_t v)
+{
+       v--;
+       v |= v >> 1;
+       v |= v >> 2;
+       v |= v >> 4;
+       v |= v >> 8;
+       v |= v >> 16;
+       v |= v >> 32;
+
+       return v + 1;
+}
+
 /*********** Macros for calculating min and max **********/
 
 /**
@@ -290,6 +314,13 @@ rte_bsf32(uint32_t v)
 /** Take a macro value and get a string version of it */
 #define RTE_STR(x) _RTE_STR(x)
 
+/** Mask value of type <tp> for the first <ln> bit set. */
+#define        RTE_LEN2MASK(ln, tp)    \
+       ((tp)((uint64_t)-1 >> (sizeof(uint64_t) * CHAR_BIT - (ln))))
+
+/** Number of elements in the array. */
+#define        RTE_DIM(a)      (sizeof (a) / sizeof ((a)[0]))
+
 /**
  * Converts a numeric string to the equivalent uint64_t value.
  * As well as straight number conversion, also recognises the suffixes