zeus/include/Global.hpp

56 lines
1.8 KiB
C++
Raw Normal View History

2015-04-19 20:39:16 +00:00
#ifndef ZEUS_GLOBAL_HPP
#define ZEUS_GLOBAL_HPP
#if _M_IX86_FP >= 1 || _M_X64
# define __SSE__ 1
#endif
#if __SSE__
# include <immintrin.h>
2015-10-25 19:31:41 +00:00
# ifndef _MSC_VER
2015-04-19 20:39:16 +00:00
# include <mm_malloc.h>
# endif
# define zeAlloc(sz, align) _mm_malloc(sz, align)
# define zeFree(ptr) _mm_free(ptr)
2015-10-25 19:31:41 +00:00
#elif GEKKO
# include <ps_intrins.h>
# define zeAlloc(sz, align) _ps_malloc(sz, align)
# define zeFree(ptr) _ps_free(ptr)
2015-04-19 20:39:16 +00:00
#endif
2015-10-25 19:31:41 +00:00
#if __SSE__ || __GEKKO_PS__
2015-04-19 20:39:16 +00:00
# define ZE_DECLARE_ALIGNED_ALLOCATOR() \
inline void* operator new(size_t sizeInBytes) { return zeAlloc(sizeInBytes,16); } \
inline void operator delete(void* ptr) { zeFree(ptr); } \
inline void* operator new(size_t, void* ptr) { return ptr; } \
inline void operator delete(void*, void*) { } \
inline void* operator new[](size_t sizeInBytes) { return zeAlloc(sizeInBytes,16); } \
inline void operator delete[](void* ptr) { zeFree(ptr); } \
inline void* operator new[](size_t, void* ptr) { return ptr; } \
2015-08-25 06:56:05 +00:00
inline void operator delete[](void*, void*) { } \
void __unused__()
2015-04-19 20:39:16 +00:00
#else
2015-08-25 06:56:05 +00:00
# define ZE_DECLARE_ALIGNED_ALLOCATOR() void __unused__()
2015-04-19 20:39:16 +00:00
#endif
#if __SSE__
# define ZE_SHUFFLE(x,y,z,w) ((w)<<6 | (z)<<4 | (y)<<2 | (x))
# define ze_pshufd_ps( _a, _mask ) _mm_shuffle_ps((_a), (_a), (_mask) )
# define ze_splat3_ps( _a, _i ) ze_pshufd_ps((_a), ZE_SHUFFLE(_i,_i,_i, 3) )
# define ze_splat_ps( _a, _i ) ze_pshufd_ps((_a), ZE_SHUFFLE(_i,_i,_i,_i) )
# if _WIN32
# define zeCastiTo128f(a) (_mm_castsi128_ps(a))
# else
# define zeCastiTo128f(a) ((__m128) (a))
# endif
2015-10-25 19:31:41 +00:00
#elif __GEKKO_PS__
2015-04-19 20:39:16 +00:00
#endif
2015-10-12 00:33:42 +00:00
inline int rotr(int x, int n) { return ((x >> n) | (x << (32 - n))); }
inline int rotl(int x, int n) { return ((x << n) | (x >> (32 - n))); }
2015-04-19 20:39:16 +00:00
#endif //ZEUS_GLOBAL_HPP