Skip to content

Commit

Permalink
added foundation::M128Fields to avoid relying on a Microsoft extension.
Browse files Browse the repository at this point in the history
  • Loading branch information
dictoon committed Apr 2, 2015
1 parent fd39ef4 commit fd0eb82
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/appleseed/foundation/math/scalar.h
Expand Up @@ -560,25 +560,33 @@ inline T fast_ceil(const T x)
template <>
inline float fast_floor(const float x)
{
return _mm_floor_ss(_mm_set1_ps(x), _mm_set1_ps(x)).m128_f32[0];
M128Fields f;
f.m128 = _mm_floor_ss(_mm_set1_ps(x), _mm_set1_ps(x));
return f.f32[0];
}

template <>
inline double fast_floor(const double x)
{
return _mm_floor_sd(_mm_set1_pd(x), _mm_set1_pd(x)).m128d_f64[0];
M128Fields f;
f.m128d = _mm_floor_sd(_mm_set1_pd(x), _mm_set1_pd(x));
return f.f64[0];
}

template <>
inline float fast_ceil(const float x)
{
return _mm_ceil_ss(_mm_set1_ps(x), _mm_set1_ps(x)).m128_f32[0];
M128Fields f;
f.m128 = _mm_ceil_ss(_mm_set1_ps(x), _mm_set1_ps(x));
return f.f32[0];
}

template <>
inline double fast_ceil(const double x)
{
return _mm_ceil_sd(_mm_set1_pd(x), _mm_set1_pd(x)).m128d_f64[0];
M128Fields f;
f.m128d = _mm_ceil_sd(_mm_set1_pd(x), _mm_set1_pd(x));
return f.f64[0];
}

#endif
Expand Down
30 changes: 30 additions & 0 deletions src/appleseed/foundation/platform/sse.h
Expand Up @@ -34,9 +34,39 @@
#error SSE support not enabled.
#endif

// appleseed.foundation headers.
#include "foundation/platform/types.h"

// Platform headers.
#include <xmmintrin.h> // SSE1 intrinsics
#include <emmintrin.h> // SSE2 intrinsics
#include <smmintrin.h> // SSE4 intrinsics

namespace foundation
{

struct M128Fields
{
union
{
__m128 m128;
__m128d m128d;
__m128i m128i;

float f32[4];
double f64[2];

int8 i8[16];
int16 i16[8];
int32 i32[4];
int64 i64[2];
uint8 u8[16];
uint16 u16[8];
uint32 u32[4];
uint64 u64[2];
};
};

}

#endif // !APPLESEED_FOUNDATION_PLATFORM_SSE_H

0 comments on commit fd0eb82

Please sign in to comment.