#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) {
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