Skip to content

Commit 8131106

Browse files
committed
xrCDB: minor cleanup using C++11
1 parent fdd7908 commit 8131106

File tree

2 files changed

+16
-26
lines changed

2 files changed

+16
-26
lines changed

src/xrCDB/ISpatial_q_ray.cpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,18 @@
77
#include <xmmintrin.h>
88
#pragma warning(pop)
99

10-
// can you say "barebone"?
11-
#ifndef _MM_ALIGN16
12-
#define _MM_ALIGN16 __declspec(align(16))
13-
#endif // _MM_ALIGN16
14-
15-
struct _MM_ALIGN16 vec_t : public Fvector3
10+
struct alignas(16) vec_t : public Fvector3
1611
{
1712
float pad;
1813
};
1914
// 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; }
2015

21-
struct _MM_ALIGN16 aabb_t
16+
struct alignas(16) aabb_t
2217
{
2318
vec_t min;
2419
vec_t max;
2520
};
26-
struct _MM_ALIGN16 ray_t
21+
struct alignas(16) ray_t
2722
{
2823
vec_t pos;
2924
vec_t inv_dir;
@@ -148,16 +143,16 @@ ICF BOOL isect_fpu(const Fvector& min, const Fvector& max, const ray_t& ray, Fve
148143
#define rotatelps(ps) _mm_shuffle_ps((ps), (ps), 0x39) // a,b,c,d -> b,c,d,a
149144
#define muxhps(low, high) _mm_movehl_ps((low), (high)) // low{a,b,c,d}|high{e,f,g,h} = {c,d,g,h}
150145

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

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

160-
// use whatever's apropriate to load.
155+
// use whatever's appropriate to load.
161156
const __m128 box_min = loadps(&box.min), box_max = loadps(&box.max), pos = loadps(&ray.pos),
162157
inv_dir = loadps(&ray.inv_dir);
163158

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

202197
template <bool b_use_sse, bool b_first, bool b_nearest>
203-
class _MM_ALIGN16 walker
198+
class alignas(16) walker
204199
{
205200
public:
206201
ray_t ray;

src/xrCDB/xrCDB_ray.cpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,18 @@
1111
using namespace CDB;
1212
using namespace Opcode;
1313

14-
// can you say "barebone"?
15-
#ifndef _MM_ALIGN16
16-
#define _MM_ALIGN16 __declspec(align(16))
17-
#endif // _MM_ALIGN16
18-
19-
struct _MM_ALIGN16 vec_t : public Fvector3
14+
struct alignas(16) vec_t : public Fvector3
2015
{
2116
float pad;
2217
};
2318
// 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; }
2419

25-
struct _MM_ALIGN16 aabb_t
20+
struct alignas(16) aabb_t
2621
{
2722
vec_t min;
2823
vec_t max;
2924
};
30-
struct _MM_ALIGN16 ray_t
25+
struct alignas(16) ray_t
3126
{
3227
vec_t pos;
3328
vec_t inv_dir;
@@ -152,16 +147,16 @@ ICF BOOL isect_fpu(const Fvector& min, const Fvector& max, const ray_t& ray, Fve
152147
#define rotatelps(ps) _mm_shuffle_ps((ps), (ps), 0x39) // a,b,c,d -> b,c,d,a
153148
#define muxhps(low, high) _mm_movehl_ps((low), (high)) // low{a,b,c,d}|high{e,f,g,h} = {c,d,g,h}
154149

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

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

164-
// use whatever's apropriate to load.
159+
// use whatever's appropriate to load.
165160
const __m128 box_min = loadps(&box.min), box_max = loadps(&box.max), pos = loadps(&ray.pos),
166161
inv_dir = loadps(&ray.inv_dir);
167162

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

204199
template <bool bUseSSE, bool bCull, bool bFirst, bool bNearest>
205-
class _MM_ALIGN16 ray_collider
200+
class alignas(16) ray_collider
206201
{
207202
public:
208203
COLLIDER* dest;

0 commit comments

Comments
 (0)