26static const f32x4
_id_x = set_f32x4(1.0f, 0.0f, 0.0f, 0.0f);
27static const f32x4
_id_y = set_f32x4(0.0f, 1.0f, 0.0f, 0.0f);
28static const f32x4
_id_z = set_f32x4(0.0f, 0.0f, 1.0f, 0.0f);
29static const f32x4
_id_w = set_f32x4(0.0f, 0.0f, 0.0f, 1.0f);
30static const f32x4
_minus1 = set_f32x4(-1.0f, -1.0f, -1.0f, -1.0f);
31static const f32x4
_plus1 = set_f32x4(1.0f, 1.0f, 1.0f, 1.0f);
32static const f32x4
_zero = set_f32x4(0.0f, 0.0f, 0.0f, 0.0f);
33static const i32x4
_sign = set_i32x4(0x80000000, 0x80000000, 0x80000000, 0x80000000);
34static const f32x4
_mask_xyz = cast_i32x4_to_f32x4(set_i32x4( 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0 ));
70 void load(
const scalar* ptr);
72 void loadu(
const scalar* ptr);
74 void store(scalar* ptr)
const;
76 void storeu(scalar* ptr)
const;
78 void stream(scalar* ptr)
const;
81 void set(scalar
x, scalar
y, scalar
z);
106 this->
vec = set_f32x4(
x,
y,
z, 0);
115 this->
vec = _mm_setr_ps(f3.
x, f3.
y, f3.
z, 0);
124 this->
vec = set_f32x4(
v,
v,
v, 0.0f);
133 this->
vec = set_last_f32x4(rhs, 0);
142 this->
vec = set_last_f32x4(rhs, 0);
151 return (((_mm_movemask_ps(_mm_cmpeq_ps(this->
vec, rhs.
vec)) & 7) == 7) != 0);
160 return !(((_mm_movemask_ps(_mm_cmpeq_ps(this->
vec, rhs.
vec)) & 7) == 7) != 0);
170 this->
vec = load_aligned_f32x3(ptr);
180 this->
vec = load_unaligned_f32x3(ptr);
190 store_f32x3(this->
vec, ptr);
200 store_f32x3(this->
vec, ptr);
218 return vec3(flip_sign_f32x4(lhs.
vec));
228 f32x4 temp = _mm_set1_ps(t);
229 return mul_f32x4(lhs.
vec, temp);
239 return mul_f32x4(lhs.
vec, rhs.
vec);
249 __m128 temp = _mm_set1_ps(t);
250 return _mm_div_ps(lhs.
vec, temp);
259 this->
vec = mul_f32x4(this->
vec, rhs.
vec);
268 this->
vec = div_f32x4(this->
vec, rhs.
vec);
277 this->
vec = add_f32x4(this->
vec, rhs.
vec);
286 this->
vec = sub_f32x4(this->
vec, rhs.
vec);
295 f32x4 temp = splat_f32x4(s);
296 this->
vec = mul_f32x4(this->
vec, temp);
305 return add_f32x4(lhs.
vec, rhs.
vec);
314 return sub_f32x4(lhs.
vec, rhs.
vec);
323 this->
vec = set_f32x4(
x,
y,
z, 0);
333 return this->
v[index];
343 return this->
v[index];
362 return dot_f32x3(v.
vec, v.
vec);
380 return rcp_f32x4(v.
vec);
389 return mul_f32x4(v0.
vec, v1.
vec);
398 return fma_f32x4(v0.
vec, v1.
vec, v2.
vec);
407 return div_f32x4(v0.
vec, v1.
vec);
416 return abs_f32x4(v.
vec);
425 f32x4 tmp0, tmp1, tmp2, tmp3, result;
426 tmp0 = shuffle_f32x4( v0.
vec, v0.
vec, 3,0,2,1 );
427 tmp1 = shuffle_f32x4( v1.
vec, v1.
vec, 3,1,0,2 );
428 tmp2 = shuffle_f32x4( v0.
vec, v0.
vec, 3,1,0,2 );
429 tmp3 = shuffle_f32x4( v1.
vec, v1.
vec, 3,0,2,1 );
430 result = mul_f32x4( tmp0, tmp1 );
431 result = sub_f32x4( result, mul_f32x4( tmp2, tmp3 ) );
441 return dot_f32x3(v0.
vec, v1.
vec);
451 f32x4 R1 = sub_f32x4(v1.
vec,v0.
vec);
452 f32x4 SF = splat_f32x4(f);
453 f32x4 R2 = sub_f32x4(v2.
vec,v0.
vec);
454 f32x4 SG = splat_f32x4(g);
455 R1 = mul_f32x4(R1,SF);
456 R2 = mul_f32x4(R2,SG);
457 R1 = add_f32x4(R1,v0.
vec);
458 R1 = add_f32x4(R1,R2);
471 f32x4 P0 = splat_f32x4((-s3 + 2.0f * s2 - s) * 0.5f);
472 f32x4 P1 = splat_f32x4((3.0f * s3 - 5.0f * s2 + 2.0f) * 0.5f);
473 f32x4 P2 = splat_f32x4((-3.0f * s3 + 4.0f * s2 + s) * 0.5f);
474 f32x4 P3 = splat_f32x4((s3 - s2) * 0.5f);
476 P0 = mul_f32x4(P0, v0.
vec);
477 P1 = mul_f32x4(P1, v1.
vec);
478 P2 = mul_f32x4(P2, v2.
vec);
479 P3 = mul_f32x4(P3, v3.
vec);
480 P0 = add_f32x4(P0,P1);
481 P2 = add_f32x4(P2,P3);
482 P0 = add_f32x4(P0,P2);
495 f32x4 P0 = splat_f32x4(2.0f * s3 - 3.0f * s2 + 1.0f);
496 f32x4 T0 = splat_f32x4(s3 - 2.0f * s2 + s);
497 f32x4 P1 = splat_f32x4(-2.0f * s3 + 3.0f * s2);
498 f32x4 T1 = splat_f32x4(s3 - s2);
500 f32x4 vResult = mul_f32x4(P0, v1.
vec);
501 f32x4 vTemp = mul_f32x4(T0, t1.
vec);
502 vResult = add_f32x4(vResult,vTemp);
503 vTemp = mul_f32x4(P1, v2.
vec);
504 vResult = add_f32x4(vResult,vTemp);
505 vTemp = mul_f32x4(T1, t2.
vec);
506 vResult = add_f32x4(vResult,vTemp);
516 f32x4 l0 = mul_f32x4(v0.
vec, v0.
vec);
517 l0 = add_f32x4(shuffle_f32x4(l0, l0, 0, 0, 0, 0),
518 add_f32x4(shuffle_f32x4(l0, l0, 1, 1, 1, 1), shuffle_f32x4(l0, l0, 2, 2, 2, 2)));
520 f32x4 l1 = mul_f32x4(v1.
vec, v1.
vec);
521 l1 = add_f32x4(shuffle_f32x4(l1, l1, 0, 0, 0, 0),
522 add_f32x4(shuffle_f32x4(l1, l1, 1, 1, 1, 1), shuffle_f32x4(l1, l1, 2, 2, 2, 2)));
524 f32x4 l = shuffle_f32x4(l0, l1, 0, 0, 0, 0);
526 l = mul_first_f32x4(shuffle_f32x4(l, l, 0, 0, 0, 0), shuffle_f32x4(l, l, 1, 1, 1, 1));
530 dot = add_f32x4(shuffle_f32x4(
dot,
dot, 0, 0, 0, 0),
531 add_f32x4(shuffle_f32x4(
dot,
dot, 1, 1, 1, 1),
532 add_f32x4(shuffle_f32x4(
dot,
dot, 2, 2, 2, 2), shuffle_f32x4(
dot,
dot, 3, 3, 3, 3))));
534 dot = mul_first_f32x4(
dot, l);
540 store_f32(
dot, &cangle);
550 return fma_f32x4(sub_f32x4(v1.
vec, v0.
vec), splat_f32x4(s), v0.
vec);
559 return max_f32x4(v0.
vec, v1.
vec);
568 return min_f32x4(v0.
vec, v1.
vec);
577 f32x4 temp = max_f32x4(
min.vec,
clamp.vec);
578 temp = min_f32x4(temp,
max.vec);
588 if (v ==
vec3(0))
return v;
590 f32x4 t = div_f32x4(v.
vec, splat_f32x4(
sqrt(dot_f32x3(v.
vec, v.
vec))));
600 if (v ==
vec3(0))
return v;
601 f32x4 t = splat_f32x4(1.0f /
sqrt(dot_f32x3(v.
vec, v.
vec)));
602 return mul_f32x4(v.
vec, set_last_f32x4(t, 0));
611 f32x4 res = mul_f32x4(incident.
vec, normal.
vec);
612 res = add_f32x4(shuffle_f32x4(res, res, 0, 0, 0, 0),
613 add_f32x4(shuffle_f32x4(res, res, 1, 1, 1, 1), shuffle_f32x4(res, res, 2, 2, 2, 2)));
614 res = add_f32x4(res, res);
615 res = mul_f32x4(res, normal.
vec);
616 res = sub_f32x4(incident.
vec,res);
626 __m128 vTemp = _mm_cmpge_ps(v0.
vec, v1.
vec);
627 int res = _mm_movemask_ps(vTemp) & 0x7;
637 __m128 vTemp = _mm_cmpge_ps(v0.
vec, v1.
vec);
638 int res = _mm_movemask_ps(vTemp) & 0x7;
648 __m128 vTemp = _mm_cmpgt_ps(v0.
vec, v1.
vec);
649 int res = _mm_movemask_ps(vTemp) & 7;
659 __m128 vTemp = _mm_cmpgt_ps(v0.
vec, v1.
vec);
660 int res = _mm_movemask_ps(vTemp) & 0x7;
670 __m128 vTemp = _mm_cmpgt_ps(v0.
vec, v1.
vec);
671 int res = _mm_movemask_ps(vTemp) & 0x7;
681 __m128 vTemp = _mm_cmpgt_ps(v0.
vec, v1.
vec);
682 int res = _mm_movemask_ps(vTemp) & 0x7;
692 __m128 vTemp = _mm_cmpge_ps(v0.
vec, v1.
vec);
693 int res = _mm_movemask_ps(vTemp) & 0x7;
703 __m128 vTemp = _mm_cmpge_ps(v0.
vec, v1.
vec);
704 int res = _mm_movemask_ps(vTemp) & 0x7;
714 __m128 vTemp = _mm_cmpeq_ps(v0.
vec, v1.
vec);
715 int res = _mm_movemask_ps(vTemp) & 0x7;
725 __m128 eps = _mm_setr_ps(epsilon, epsilon, epsilon, 0);
726 __m128 delta = _mm_sub_ps(v0.
vec, v1.
vec);
727 __m128 temp = _mm_setzero_ps();
728 temp = _mm_sub_ps(temp, delta);
729 temp = _mm_max_ps(temp, delta);
730 temp = _mm_cmple_ps(temp, eps);
731 return (_mm_movemask_ps(temp) & 0x7) != 0;
740 __m128 delta = _mm_sub_ps(v0.
vec, v1.
vec);
741 __m128 temp = _mm_setzero_ps();
742 temp = _mm_sub_ps(temp, delta);
743 temp = _mm_max_ps(temp, delta);
744 temp = _mm_cmple_ps(temp, epsilon.
vec);
745 auto foo = _mm_movemask_ps(temp) & 0x7;
746 return (_mm_movemask_ps(temp) & 0x7) == 0x7;
755 return _mm_min_ps(_mm_cmplt_ps(v0.
vec, v1.
vec),
_plus1);
764 return _mm_min_ps(_mm_cmpgt_ps(v0.
vec, v1.
vec),
_plus1);
773 return _mm_min_ps(_mm_cmpeq_ps(v0.
vec, v1.
vec),
_plus1);
782 n_assert(element < 3 && element >= 0);
788 res = shuffle_f32x4(v.
vec, v.
vec, 0, 0, 0, 0);
791 res = shuffle_f32x4(v.
vec, v.
vec, 1, 1, 1, 1);
794 res = shuffle_f32x4(v.
vec, v.
vec, 2, 2, 2, 2);
797 return set_last_f32x4(res, 0);
806 f32x4 res = shuffle_f32x4(v.
vec, v.
vec, 0, 0, 0, 0);
807 return set_last_f32x4(res, 0);
816 f32x4 res = shuffle_f32x4(v.
vec, v.
vec, 1, 1, 1, 1);
817 return set_last_f32x4(res, 0);
826 f32x4 res = shuffle_f32x4(v.
vec, v.
vec, 2, 2, 2, 2);
827 return set_last_f32x4(res, 0);
834permute(
const vec3& v0,
const vec3& v1,
unsigned int i0,
unsigned int i1,
unsigned int i2)
836 static i32x4 three = _mm_set_epi32(3,3,3,3);
839 i32x4 vControl = _mm_load_si128(
reinterpret_cast<const __m128i*
>(&elem[0]));
841 i32x4 vSelect = _mm_cmpgt_epi32(vControl, three);
842 vControl = _mm_and_si128(vControl, three);
844 f32x4 shuffled1 = _mm_permutevar_ps(v0.
vec, vControl);
845 f32x4 shuffled2 = _mm_permutevar_ps(v1.
vec, vControl);
847 f32x4 masked1 = _mm_andnot_ps(_mm_castsi128_ps(vSelect), shuffled1);
848 f32x4 masked2 = _mm_and_ps(_mm_castsi128_ps(vSelect), shuffled2);
850 return _mm_or_ps(masked1, masked2);
860 return permute(v0, v1, i0, i1, i2);
869 f32x4 v0masked = _mm_andnot_ps(control.
vec, v0.
vec);
870 f32x4 v1masked = _mm_and_ps(v1.
vec, control.
vec);
871 return _mm_or_ps(v0masked, v1masked);
880 return _mm_floor_ps(v.
vec);
889 return _mm_ceil_ps(v.
vec);
#define n_assert(exp)
Definition debug.h:50
Different curves.
Definition angularpfeedbackloop.h:17
__forceinline point less(const point &v0, const point &v1)
Definition point.h:501
static const f32x4 _zero
Definition vec3.h:32
static const f32x4 _plus1
Definition vec3.h:31
__forceinline vec3 cross(const vec3 &v0, const vec3 &v1)
Definition vec3.h:423
__forceinline point maximize(const point &v0, const point &v1)
Definition point.h:368
static const f32x4 _id_w
Definition vec3.h:29
__forceinline quat barycentric(const quat &q0, const quat &q1, const quat &q2, scalar f, scalar g)
Definition quat.h:296
__forceinline bool equal_any(const point &v0, const point &v1)
Definition point.h:474
__forceinline bool greaterequal_any(const point &v0, const point &v1)
Definition point.h:452
__forceinline vec3 ceiling(const vec3 &v)
Definition vec3.h:887
__forceinline vec3 splat_z(const vec3 &v)
Definition vec3.h:824
__forceinline vec3 hermite(const vec3 &v1, const vec3 &t1, const vec3 &v2, const vec3 &t2, scalar s)
Definition vec3.h:490
__forceinline scalar sqrt(scalar x)
Definition scalar.h:236
__forceinline point equal(const point &v0, const point &v1)
Definition point.h:519
__forceinline vec3 splat_x(const vec3 &v)
Definition vec3.h:804
__forceinline vec3 splat(const vec3 &v, uint element)
Definition vec3.h:780
mat4 reflect(const vec4 &p)
based on this http://www.opengl.org/discussion_boards/showthread.php/169605-reflection-matrix-how-to-...
Definition mat4.cc:22
__forceinline vec3 multiply(const vec3 &v0, const vec3 &v1)
Definition vec3.h:387
__forceinline scalar angle(const vec3 &v0, const vec3 &v1)
Definition vec3.h:514
__forceinline vec3 divide(const vec3 &v0, const vec3 &v1)
Definition vec3.h:405
__forceinline vec3 reciprocal(const vec3 &v)
Definition vec3.h:369
__forceinline scalar length(const quat &q)
Definition quat.h:260
half operator/(half one, half two)
Definition half.h:132
__forceinline scalar lengthsq(const quat &q)
Definition quat.h:269
__forceinline scalar dot(const plane &p, const vec4 &v1)
Definition plane.h:252
__forceinline vec3 permute(const vec3 &v0, const vec3 &v1, unsigned int i0, unsigned int i1, unsigned int i2)
Definition vec3.h:834
__forceinline plane normalize(const plane &p)
Definition plane.h:261
__forceinline bool greaterequal_all(const point &v0, const point &v1)
Definition point.h:463
__forceinline bool greater_any(const point &v0, const point &v1)
Definition point.h:430
__forceinline float lerp(float x, float y, float l)
Linearly interpolate between 2 values: ret = x + l * (y - x)
Definition scalar.h:616
static const f32x4 _id_y
Definition vec3.h:27
__forceinline float clamp(float val, float minVal, float maxVal)
Float clamping.
Definition scalar.h:506
static const f32x4 _id_z
Definition vec3.h:28
half operator-(half one, half two)
Definition half.h:114
__forceinline bool less_any(const point &v0, const point &v1)
Definition point.h:386
__forceinline vec3 catmullrom(const vec3 &v0, const vec3 &v1, const vec3 &v2, const vec3 &v3, scalar s)
Definition vec3.h:466
__forceinline TYPE min(TYPE a, TYPE b)
Definition scalar.h:399
__forceinline bool less_all(const point &v0, const point &v1)
Definition point.h:397
__forceinline bool lessequal_all(const point &v0, const point &v1)
Definition point.h:419
__forceinline vec3 select(const vec3 &v0, const vec3 &v1, const uint i0, const uint i1, const uint i2)
Definition vec3.h:857
__forceinline vec3 splat_y(const vec3 &v)
Definition vec3.h:814
__forceinline point minimize(const point &v0, const point &v1)
Definition point.h:377
float scalar
Definition scalar.h:45
__forceinline point greater(const point &v0, const point &v1)
Definition point.h:510
half operator+(half one, half two)
Definition half.h:105
static const i32x4 _sign
Definition vec3.h:33
half operator*(half one, half two)
Definition half.h:123
__forceinline TYPE max(TYPE a, TYPE b)
Definition scalar.h:368
__forceinline scalar abs(scalar a)
Definition scalar.h:451
static const f32x4 _mask_xyz
Definition vec3.h:34
__forceinline vec3 multiplyadd(const vec3 &v0, const vec3 &v1, const vec3 &v2)
Definition vec3.h:396
static const f32x4 _minus1
Definition vec3.h:30
__forceinline scalar acos(scalar x)
Definition scalar.h:218
__forceinline bool greater_all(const point &v0, const point &v1)
Definition point.h:441
__forceinline bool nearequal(const point &v0, const point &v1, float epsilon)
Definition point.h:485
__forceinline bool lessequal_any(const point &v0, const point &v1)
Definition point.h:408
static const f32x4 _id_x
Definition vec3.h:26
__forceinline float floor(float val)
Floating point flooring.
Definition scalar.h:552
__forceinline vec3 normalizeapprox(const vec3 &v)
Definition vec3.h:598
__forceinline vec3 reciprocalapprox(const vec3 &v)
Definition vec3.h:378
Nebula's scalar datatype.
Maps generic SIMD-like types and intrinsics to either SSE4+AVX or NEON.
vec3()=default
default constructor, NOTE: does NOT setup components!
scalar x
Definition scalar.h:70
scalar y
Definition scalar.h:70
scalar z
Definition scalar.h:70
A 4x4 single point precision float matrix.
Definition mat4.h:49
A 3D vector.
Definition vec3.h:37
void loadu(const scalar *ptr)
load content from unaligned memory
Definition vec3.h:178
void stream(scalar *ptr) const
stream content to 16-byte-aligned memory circumventing the write-cache
Definition vec3.h:207
float v[3]
Definition vec3.h:96
bool operator==(const vec3 &rhs) const
equality operator
Definition vec3.h:149
void storeu(scalar *ptr) const
write content to unaligned memory through the write cache
Definition vec3.h:198
vec3()=default
default constructor, NOTE: does NOT setup components!
void load(const scalar *ptr)
load content from 16-byte-aligned memory
Definition vec3.h:168
void operator*=(scalar s)
inplace scalar multiply
Definition vec3.h:293
void operator-=(const vec3 &rhs)
inplace sub
Definition vec3.h:284
void store(scalar *ptr) const
write content to 16-byte-aligned memory through the write cache
Definition vec3.h:188
float x
Definition vec3.h:93
float z
Definition vec3.h:93
void operator/=(const vec3 &rhs)
divide by a vector component-wise
Definition vec3.h:266
float __w
Definition vec3.h:93
f32x4 vec
Definition vec3.h:95
void operator+=(const vec3 &rhs)
inplace add
Definition vec3.h:275
scalar & operator[](const int index)
read-only access to indexed component
Definition vec3.h:330
bool operator!=(const vec3 &rhs) const
inequality operator
Definition vec3.h:158
void operator=(const f32x4 &rhs)
assign an vmVector4
Definition vec3.h:140
void set(scalar x, scalar y, scalar z)
set content
Definition vec3.h:321
vec3(const vec3 &rhs)=default
copy constructor
float y
Definition vec3.h:93
bool operator==(const TiXmlString &a, const TiXmlString &b)
Definition tinystr.h:272
bool operator!=(const TiXmlString &a, const TiXmlString &b)
Definition tinystr.h:282
#define NEBULA_ALIGN16
Definition types.h:143
unsigned int uint
Definition types.h:33