Skip to content

Commit

Permalink
xrCDB: minor cleanup using C++11
Browse files Browse the repository at this point in the history
  • Loading branch information
Xottab-DUTY committed Apr 25, 2018
1 parent fdd7908 commit 8131106
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 26 deletions.
21 changes: 8 additions & 13 deletions src/xrCDB/ISpatial_q_ray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,18 @@
#include <xmmintrin.h>
#pragma warning(pop)

// can you say "barebone"?
#ifndef _MM_ALIGN16
#define _MM_ALIGN16 __declspec(align(16))
#endif // _MM_ALIGN16

struct _MM_ALIGN16 vec_t : public Fvector3
struct alignas(16) vec_t : public Fvector3
{
float pad;
};
// static vec_t vec_c ( float _x, float _y, float _z) { vec_t v; v.x=_x;v.y=_y;v.z=_z;v.pad=0; return v; }

struct _MM_ALIGN16 aabb_t
struct alignas(16) aabb_t
{
vec_t min;
vec_t max;
};
struct _MM_ALIGN16 ray_t
struct alignas(16) ray_t
{
vec_t pos;
vec_t inv_dir;
Expand Down Expand Up @@ -148,16 +143,16 @@ ICF BOOL isect_fpu(const Fvector& min, const Fvector& max, const ray_t& ray, Fve
#define rotatelps(ps) _mm_shuffle_ps((ps), (ps), 0x39) // a,b,c,d -> b,c,d,a
#define muxhps(low, high) _mm_movehl_ps((low), (high)) // low{a,b,c,d}|high{e,f,g,h} = {c,d,g,h}

static const float flt_plus_inf = -logf(0); // let's keep C and C++ compilers happy.
static const float _MM_ALIGN16 ps_cst_plus_inf[4] = {flt_plus_inf, flt_plus_inf, flt_plus_inf, flt_plus_inf},
ps_cst_minus_inf[4] = {-flt_plus_inf, -flt_plus_inf, -flt_plus_inf, -flt_plus_inf};
static constexpr auto flt_plus_inf = std::numeric_limits<float>::infinity();
alignas(16) static constexpr float ps_cst_plus_inf[4] = { flt_plus_inf, flt_plus_inf, flt_plus_inf, flt_plus_inf },
ps_cst_minus_inf[4] = { -flt_plus_inf, -flt_plus_inf, -flt_plus_inf, -flt_plus_inf };

ICF BOOL isect_sse(const aabb_t& box, const ray_t& ray, float& dist)
{
// you may already have those values hanging around somewhere
const __m128 plus_inf = loadps(ps_cst_plus_inf), minus_inf = loadps(ps_cst_minus_inf);

// use whatever's apropriate to load.
// use whatever's appropriate to load.
const __m128 box_min = loadps(&box.min), box_max = loadps(&box.max), pos = loadps(&ray.pos),
inv_dir = loadps(&ray.inv_dir);

Expand Down Expand Up @@ -200,7 +195,7 @@ ICF BOOL isect_sse(const aabb_t& box, const ray_t& ray, float& dist)
extern Fvector c_spatial_offset[8];

template <bool b_use_sse, bool b_first, bool b_nearest>
class _MM_ALIGN16 walker
class alignas(16) walker
{
public:
ray_t ray;
Expand Down
21 changes: 8 additions & 13 deletions src/xrCDB/xrCDB_ray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,18 @@
using namespace CDB;
using namespace Opcode;

// can you say "barebone"?
#ifndef _MM_ALIGN16
#define _MM_ALIGN16 __declspec(align(16))
#endif // _MM_ALIGN16

struct _MM_ALIGN16 vec_t : public Fvector3
struct alignas(16) vec_t : public Fvector3
{
float pad;
};
// static vec_t vec_c ( float _x, float _y, float _z) { vec_t v; v.x=_x;v.y=_y;v.z=_z;v.pad=0; return v; }

struct _MM_ALIGN16 aabb_t
struct alignas(16) aabb_t
{
vec_t min;
vec_t max;
};
struct _MM_ALIGN16 ray_t
struct alignas(16) ray_t
{
vec_t pos;
vec_t inv_dir;
Expand Down Expand Up @@ -152,16 +147,16 @@ ICF BOOL isect_fpu(const Fvector& min, const Fvector& max, const ray_t& ray, Fve
#define rotatelps(ps) _mm_shuffle_ps((ps), (ps), 0x39) // a,b,c,d -> b,c,d,a
#define muxhps(low, high) _mm_movehl_ps((low), (high)) // low{a,b,c,d}|high{e,f,g,h} = {c,d,g,h}

static const float flt_plus_inf = -logf(0); // let's keep C and C++ compilers happy.
static const float _MM_ALIGN16 ps_cst_plus_inf[4] = {flt_plus_inf, flt_plus_inf, flt_plus_inf, flt_plus_inf},
ps_cst_minus_inf[4] = {-flt_plus_inf, -flt_plus_inf, -flt_plus_inf, -flt_plus_inf};
static constexpr float flt_plus_inf = std::numeric_limits<float>::infinity();
alignas(16) static constexpr float ps_cst_plus_inf[4] = { flt_plus_inf, flt_plus_inf, flt_plus_inf, flt_plus_inf },
ps_cst_minus_inf[4] = { -flt_plus_inf, -flt_plus_inf, -flt_plus_inf, -flt_plus_inf };

ICF BOOL isect_sse(const aabb_t& box, const ray_t& ray, float& dist)
{
// you may already have those values hanging around somewhere
const __m128 plus_inf = loadps(ps_cst_plus_inf), minus_inf = loadps(ps_cst_minus_inf);

// use whatever's apropriate to load.
// use whatever's appropriate to load.
const __m128 box_min = loadps(&box.min), box_max = loadps(&box.max), pos = loadps(&ray.pos),
inv_dir = loadps(&ray.inv_dir);

Expand Down Expand Up @@ -202,7 +197,7 @@ ICF BOOL isect_sse(const aabb_t& box, const ray_t& ray, float& dist)
}

template <bool bUseSSE, bool bCull, bool bFirst, bool bNearest>
class _MM_ALIGN16 ray_collider
class alignas(16) ray_collider
{
public:
COLLIDER* dest;
Expand Down

0 comments on commit 8131106

Please sign in to comment.