]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - Vc/include/Vc/scalar/helperimpl.tcc
update to Vc 0.7.3-dev
[u/mrichter/AliRoot.git] / Vc / include / Vc / scalar / helperimpl.tcc
index 82c74a0be3539dd682035595f084a3566bd08e0a..4c01efed6daae1db37bd8f7e74c47eb6956e6aaf 100644 (file)
 #include <malloc.h>
 #endif
 
+namespace AliRoot {
 namespace Vc
 {
 namespace Internal
 {
 
 template<size_t X>
-static inline size_t nextMultipleOf(size_t value)
+static _VC_CONSTEXPR size_t nextMultipleOf(size_t value)
 {
-    const size_t offset = value % X;
-    if ( offset > 0 ) {
-        return value + X - offset;
-    }
-    return value;
+    return (value % X) > 0 ? value + X - (value % X) : value;
 }
 
 template<Vc::MallocAlignment A>
-inline void *HelperImpl<ScalarImpl>::malloc(size_t n)
+Vc_ALWAYS_INLINE void *HelperImpl<ScalarImpl>::malloc(size_t n)
 {
     void *ptr = 0;
     switch (A) {
@@ -49,36 +46,41 @@ inline void *HelperImpl<ScalarImpl>::malloc(size_t n)
             return std::malloc(n);
         case Vc::AlignOnCacheline:
             // TODO: hardcoding 64 is not such a great idea
-#if defined _WIN32 || defined _WIN64
-            ptr = _aligned_malloc(nextMultipleOf<64>(n), 64);
-            return ptr;
+#ifdef _WIN32
+#ifdef __GNUC__
+#define _VC_ALIGNED_MALLOC __mingw_aligned_malloc
+#else
+#define _VC_ALIGNED_MALLOC _aligned_malloc
+#endif
+            ptr = _VC_ALIGNED_MALLOC(nextMultipleOf<64>(n), 64);
 #else
             if (0 == posix_memalign(&ptr, 64, nextMultipleOf<64>(n))) {
                 return ptr;
             }
-            break;
 #endif
+            break;
         case Vc::AlignOnPage:
             // TODO: hardcoding 4096 is not such a great idea
-#if defined _WIN32 || defined _WIN64
-            ptr = _aligned_malloc(nextMultipleOf<4096>(n), 4096);
-            return ptr;
+#ifdef _WIN32
+            ptr = _VC_ALIGNED_MALLOC(nextMultipleOf<4096>(n), 4096);
+#undef _VC_ALIGNED_MALLOC
 #else
             if (0 == posix_memalign(&ptr, 4096, nextMultipleOf<4096>(n))) {
                 return ptr;
             }
-            break;
 #endif
+            break;
     }
-    return 0;
+    return ptr;
 }
 
-inline void HelperImpl<ScalarImpl>::free(void *p)
+Vc_ALWAYS_INLINE void HelperImpl<ScalarImpl>::free(void *p)
 {
     std::free(p);
 }
 
 } // namespace Internal
 } // namespace Vc
+} // namespace AliRoot
 
 #endif // VC_SCALAR_HELPERIMPL_TCC