summaryrefslogtreecommitdiff
path: root/include/gal/opengl/glm/gtx/simd_vec4.inl
blob: 0b22115dc1a705832bcb3d0872f4e2c999887b1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Mathematics Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2009-05-07
// Updated : 2009-05-07
// Licence : This source is under MIT License
// File    : glm/gtx/simd_vec4.inl
///////////////////////////////////////////////////////////////////////////////////////////////////

namespace glm{
namespace detail{

template <int Value>
struct mask
{
	enum{value = Value};
};

//////////////////////////////////////
// Implicit basic constructors

GLM_FUNC_QUALIFIER fvec4SIMD::fvec4SIMD()
#ifdef GLM_SIMD_ENABLE_DEFAULT_INIT
    : Data(_mm_set_ps(0.0f, 0.0f, 0.0f, 0.0f))
#endif
{}

GLM_FUNC_QUALIFIER fvec4SIMD::fvec4SIMD(__m128 const & Data) :
	Data(Data)
{}

GLM_FUNC_QUALIFIER fvec4SIMD::fvec4SIMD(fvec4SIMD const & v) :
	Data(v.Data)
{}

GLM_FUNC_QUALIFIER fvec4SIMD::fvec4SIMD(tvec4<float> const & v) :
	Data(_mm_set_ps(v.w, v.z, v.y, v.x))
{}

//////////////////////////////////////
// Explicit basic constructors

GLM_FUNC_QUALIFIER fvec4SIMD::fvec4SIMD(float const & s) :
	Data(_mm_set1_ps(s))
{}

GLM_FUNC_QUALIFIER fvec4SIMD::fvec4SIMD(float const & x, float const & y, float const & z, float const & w) :
//		Data(_mm_setr_ps(x, y, z, w))
	Data(_mm_set_ps(w, z, y, x))
{}
/*
GLM_FUNC_QUALIFIER fvec4SIMD::fvec4SIMD(float const v[4]) :
	Data(_mm_load_ps(v))
{}
*/
//////////////////////////////////////
// Swizzle constructors

//fvec4SIMD(ref4<float> const & r);

//////////////////////////////////////
// Convertion vector constructors

GLM_FUNC_QUALIFIER fvec4SIMD::fvec4SIMD(vec2 const & v, float const & s1, float const & s2) :
	Data(_mm_set_ps(s2, s1, v.y, v.x))
{}

GLM_FUNC_QUALIFIER fvec4SIMD::fvec4SIMD(float const & s1, vec2 const & v, float const & s2) :
	Data(_mm_set_ps(s2, v.y, v.x, s1))
{}

GLM_FUNC_QUALIFIER fvec4SIMD::fvec4SIMD(float const & s1, float const & s2, vec2 const & v) :
	Data(_mm_set_ps(v.y, v.x, s2, s1))
{}

GLM_FUNC_QUALIFIER fvec4SIMD::fvec4SIMD(vec3 const & v, float const & s) :
	Data(_mm_set_ps(s, v.z, v.y, v.x))
{}

GLM_FUNC_QUALIFIER fvec4SIMD::fvec4SIMD(float const & s, vec3 const & v) :
	Data(_mm_set_ps(v.z, v.y, v.x, s))
{}

GLM_FUNC_QUALIFIER fvec4SIMD::fvec4SIMD(vec2 const & v1, vec2 const & v2) :
	Data(_mm_set_ps(v2.y, v2.x, v1.y, v1.x))
{}

//GLM_FUNC_QUALIFIER fvec4SIMD::fvec4SIMD(ivec4SIMD const & v) :
//	Data(_mm_cvtepi32_ps(v.Data))
//{}

//////////////////////////////////////
// Unary arithmetic operators

GLM_FUNC_QUALIFIER fvec4SIMD& fvec4SIMD::operator=(fvec4SIMD const & v)
{
	this->Data = v.Data;
	return *this;
}

GLM_FUNC_QUALIFIER fvec4SIMD& fvec4SIMD::operator+=(float const & s)
{
	this->Data = _mm_add_ps(Data, _mm_set_ps1(s));
	return *this;
}

GLM_FUNC_QUALIFIER fvec4SIMD& fvec4SIMD::operator+=(fvec4SIMD const & v)
{
	this->Data = _mm_add_ps(this->Data , v.Data);
	return *this;
}

GLM_FUNC_QUALIFIER fvec4SIMD& fvec4SIMD::operator-=(float const & s)
{
	this->Data = _mm_sub_ps(Data, _mm_set_ps1(s));
	return *this;
}

GLM_FUNC_QUALIFIER fvec4SIMD& fvec4SIMD::operator-=(fvec4SIMD const & v)
{
	this->Data = _mm_sub_ps(this->Data , v.Data);
	return *this;
}

GLM_FUNC_QUALIFIER fvec4SIMD& fvec4SIMD::operator*=(float const & s)
{
	this->Data = _mm_mul_ps(this->Data, _mm_set_ps1(s));
	return *this;
}

GLM_FUNC_QUALIFIER fvec4SIMD& fvec4SIMD::operator*=(fvec4SIMD const & v)
{
	this->Data = _mm_mul_ps(this->Data , v.Data);
	return *this;
}

GLM_FUNC_QUALIFIER fvec4SIMD& fvec4SIMD::operator/=(float const & s)
{
	this->Data = _mm_div_ps(Data, _mm_set1_ps(s));
	return *this;
}

GLM_FUNC_QUALIFIER fvec4SIMD& fvec4SIMD::operator/=(fvec4SIMD const & v)
{
	this->Data = _mm_div_ps(this->Data , v.Data);
	return *this;
}

GLM_FUNC_QUALIFIER fvec4SIMD& fvec4SIMD::operator++()
{
	this->Data = _mm_add_ps(this->Data , glm::detail::one);
	return *this;
}

GLM_FUNC_QUALIFIER fvec4SIMD& fvec4SIMD::operator--()
{
	this->Data = _mm_sub_ps(this->Data, glm::detail::one);
	return *this;
}

//////////////////////////////////////
// Swizzle operators

template <comp X, comp Y, comp Z, comp W>
GLM_FUNC_QUALIFIER fvec4SIMD fvec4SIMD::swizzle() const
{
	__m128 Data = _mm_shuffle_ps(
		this->Data, this->Data, 
		mask<(W << 6) | (Z << 4) | (Y << 2) | (X << 0)>::value);
	return fvec4SIMD(Data);
}

template <comp X, comp Y, comp Z, comp W>
GLM_FUNC_QUALIFIER fvec4SIMD& fvec4SIMD::swizzle()
{
	this->Data = _mm_shuffle_ps(
		this->Data, this->Data, 
		mask<(W << 6) | (Z << 4) | (Y << 2) | (X << 0)>::value);
	return *this;
}

// operator+
GLM_FUNC_QUALIFIER fvec4SIMD operator+ (fvec4SIMD const & v, float s)
{
	return fvec4SIMD(_mm_add_ps(v.Data, _mm_set1_ps(s)));
}

GLM_FUNC_QUALIFIER fvec4SIMD operator+ (float s, fvec4SIMD const & v)
{
	return fvec4SIMD(_mm_add_ps(_mm_set1_ps(s), v.Data));
}

GLM_FUNC_QUALIFIER fvec4SIMD operator+ (fvec4SIMD const & v1, fvec4SIMD const & v2)
{
	return fvec4SIMD(_mm_add_ps(v1.Data, v2.Data));
}

//operator-
GLM_FUNC_QUALIFIER fvec4SIMD operator- (fvec4SIMD const & v, float s)
{
	return fvec4SIMD(_mm_sub_ps(v.Data, _mm_set1_ps(s)));
}

GLM_FUNC_QUALIFIER fvec4SIMD operator- (float s, fvec4SIMD const & v)
{
	return fvec4SIMD(_mm_sub_ps(_mm_set1_ps(s), v.Data));
}

GLM_FUNC_QUALIFIER fvec4SIMD operator- (fvec4SIMD const & v1, fvec4SIMD const & v2)
{
	return fvec4SIMD(_mm_sub_ps(v1.Data, v2.Data));
}

//operator*
GLM_FUNC_QUALIFIER fvec4SIMD operator* (fvec4SIMD const & v, float s)
{
	__m128 par0 = v.Data;
	__m128 par1 = _mm_set1_ps(s);
	return fvec4SIMD(_mm_mul_ps(par0, par1));
}

GLM_FUNC_QUALIFIER fvec4SIMD operator* (float s, fvec4SIMD const & v)
{
	__m128 par0 = _mm_set1_ps(s);
	__m128 par1 = v.Data;
	return fvec4SIMD(_mm_mul_ps(par0, par1));
}

GLM_FUNC_QUALIFIER fvec4SIMD operator* (fvec4SIMD const & v1, fvec4SIMD const & v2)
{
	return fvec4SIMD(_mm_mul_ps(v1.Data, v2.Data));
}

//operator/
GLM_FUNC_QUALIFIER fvec4SIMD operator/ (fvec4SIMD const & v, float s)
{
	__m128 par0 = v.Data;
	__m128 par1 = _mm_set1_ps(s);
	return fvec4SIMD(_mm_div_ps(par0, par1));
}

GLM_FUNC_QUALIFIER fvec4SIMD operator/ (float s, fvec4SIMD const & v)
{
	__m128 par0 = _mm_set1_ps(s);
	__m128 par1 = v.Data;
	return fvec4SIMD(_mm_div_ps(par0, par1));
}

GLM_FUNC_QUALIFIER fvec4SIMD operator/ (fvec4SIMD const & v1, fvec4SIMD const & v2)
{
	return fvec4SIMD(_mm_div_ps(v1.Data, v2.Data));
}

// Unary constant operators
GLM_FUNC_QUALIFIER fvec4SIMD operator- (fvec4SIMD const & v)
{
	return fvec4SIMD(_mm_sub_ps(_mm_setzero_ps(), v.Data));
}

GLM_FUNC_QUALIFIER fvec4SIMD operator++ (fvec4SIMD const & v, int)
{
	return fvec4SIMD(_mm_add_ps(v.Data, glm::detail::one));
}

GLM_FUNC_QUALIFIER fvec4SIMD operator-- (fvec4SIMD const & v, int)
{
	return fvec4SIMD(_mm_sub_ps(v.Data, glm::detail::one));
}

}//namespace detail

GLM_FUNC_QUALIFIER detail::tvec4<float> vec4_cast
(
	detail::fvec4SIMD const & x
)
{
	GLM_ALIGN(16) detail::tvec4<float> Result;
	_mm_store_ps(&Result[0], x.Data);
	return Result;
}

// Other possible implementation
//float abs(float a)
//{
//  return max(-a, a);
//}
GLM_FUNC_QUALIFIER detail::fvec4SIMD abs
(
	detail::fvec4SIMD const & x
)
{
	return detail::sse_abs_ps(x.Data);
}

GLM_FUNC_QUALIFIER detail::fvec4SIMD sign
(
	detail::fvec4SIMD const & x
)
{
	return detail::sse_sgn_ps(x.Data);
}

GLM_FUNC_QUALIFIER detail::fvec4SIMD floor
(
	detail::fvec4SIMD const & x
)
{
	return detail::sse_flr_ps(x.Data);
}

GLM_FUNC_QUALIFIER detail::fvec4SIMD trunc
(
	detail::fvec4SIMD const & x
)
{
    //return x < 0 ? -floor(-x) : floor(x);

	__m128 Flr0 = detail::sse_flr_ps(_mm_sub_ps(_mm_setzero_ps(), x.Data));
	__m128 Sub0 = _mm_sub_ps(Flr0, x.Data);
	__m128 Flr1 = detail::sse_flr_ps(x.Data);

	__m128 Cmp0 = _mm_cmplt_ps(x.Data, glm::detail::zero);
	__m128 Cmp1 = _mm_cmpnlt_ps(x.Data, glm::detail::zero);

	__m128 And0 = _mm_and_ps(Sub0, Cmp0);
	__m128 And1 = _mm_and_ps(Flr1, Cmp1);

	return _mm_or_ps(And0, And1);
}

GLM_FUNC_QUALIFIER detail::fvec4SIMD round
(
	detail::fvec4SIMD const & x
)
{
	return detail::sse_rnd_ps(x.Data);
}

//GLM_FUNC_QUALIFIER detail::fvec4SIMD roundEven
//(
//	detail::fvec4SIMD const & x
//)
//{

//}

GLM_FUNC_QUALIFIER detail::fvec4SIMD ceil
(
	detail::fvec4SIMD const & x
)
{
	return detail::sse_ceil_ps(x.Data);
}

GLM_FUNC_QUALIFIER detail::fvec4SIMD fract
(
	detail::fvec4SIMD const & x
)
{
	return detail::sse_frc_ps(x.Data);
}

GLM_FUNC_QUALIFIER detail::fvec4SIMD mod
(
	detail::fvec4SIMD const & x, 
	detail::fvec4SIMD const & y
)
{
	return detail::sse_mod_ps(x.Data, y.Data);
}

GLM_FUNC_QUALIFIER detail::fvec4SIMD mod
(
	detail::fvec4SIMD const & x, 
	float const & y
)
{
	return detail::sse_mod_ps(x.Data, _mm_set1_ps(y));
}

//GLM_FUNC_QUALIFIER detail::fvec4SIMD modf
//(
//	detail::fvec4SIMD const & x, 
//	detail::fvec4SIMD & i
//)
//{

//}

GLM_FUNC_QUALIFIER detail::fvec4SIMD min
(
	detail::fvec4SIMD const & x, 
	detail::fvec4SIMD const & y
)
{
	return _mm_min_ps(x.Data, y.Data);
}

GLM_FUNC_QUALIFIER detail::fvec4SIMD min
(
	detail::fvec4SIMD const & x, 
	float const & y
)
{
	return _mm_min_ps(x.Data, _mm_set1_ps(y));
}

GLM_FUNC_QUALIFIER detail::fvec4SIMD max
(
	detail::fvec4SIMD const & x, 
	detail::fvec4SIMD const & y
)
{
	return _mm_max_ps(x.Data, y.Data);
}

GLM_FUNC_QUALIFIER detail::fvec4SIMD max
(
	detail::fvec4SIMD const & x, 
	float const & y
)
{
	return _mm_max_ps(x.Data, _mm_set1_ps(y));
}

GLM_FUNC_QUALIFIER detail::fvec4SIMD clamp
(
	detail::fvec4SIMD const & x, 
	detail::fvec4SIMD const & minVal, 
	detail::fvec4SIMD const & maxVal
)
{
	return detail::sse_clp_ps(x.Data, minVal.Data, maxVal.Data);
}

GLM_FUNC_QUALIFIER detail::fvec4SIMD clamp
(
	detail::fvec4SIMD const & x, 
	float const & minVal, 
	float const & maxVal
) 
{
	return detail::sse_clp_ps(x.Data, _mm_set1_ps(minVal), _mm_set1_ps(maxVal));
}

GLM_FUNC_QUALIFIER detail::fvec4SIMD mix
(
	detail::fvec4SIMD const & x, 
	detail::fvec4SIMD const & y, 
	detail::fvec4SIMD const & a
)
{
	__m128 Sub0 = _mm_sub_ps(y.Data, x.Data);
	__m128 Mul0 = _mm_mul_ps(a.Data, Sub0);
	return _mm_add_ps(x.Data, Mul0);
}

GLM_FUNC_QUALIFIER detail::fvec4SIMD step
(
	detail::fvec4SIMD const & edge, 
	detail::fvec4SIMD const & x
)
{
	__m128 cmp0 = _mm_cmpngt_ps(x.Data, edge.Data);
	return _mm_max_ps(_mm_min_ps(cmp0, _mm_setzero_ps()), detail::one);
}

GLM_FUNC_QUALIFIER detail::fvec4SIMD step
(
	float const & edge, 
	detail::fvec4SIMD const & x
)
{
	__m128 cmp0 = _mm_cmpngt_ps(x.Data, _mm_set1_ps(edge));
	return _mm_max_ps(_mm_min_ps(cmp0, _mm_setzero_ps()), detail::one);
}

GLM_FUNC_QUALIFIER detail::fvec4SIMD smoothstep
(
	detail::fvec4SIMD const & edge0, 
	detail::fvec4SIMD const & edge1, 
	detail::fvec4SIMD const & x
)
{
	return detail::sse_ssp_ps(edge0.Data, edge1.Data, x.Data);
}

GLM_FUNC_QUALIFIER detail::fvec4SIMD smoothstep
(
	float const & edge0, 
	float const & edge1, 
	detail::fvec4SIMD const & x
)
{
	return detail::sse_ssp_ps(_mm_set1_ps(edge0), _mm_set1_ps(edge1), x.Data);
}

//GLM_FUNC_QUALIFIER bvec4 isnan(detail::fvec4SIMD const & x)
//{

//}

//GLM_FUNC_QUALIFIER bvec4 isinf(detail::fvec4SIMD const & x)
//{

//}

//GLM_FUNC_QUALIFIER detail::ivec4SIMD floatBitsToInt
//(
//	detail::fvec4SIMD const & value
//)
//{

//}

//GLM_FUNC_QUALIFIER detail::fvec4SIMD intBitsToFloat
//(
//	detail::ivec4SIMD const & value
//)
//{

//}

GLM_FUNC_QUALIFIER detail::fvec4SIMD fma
(
	detail::fvec4SIMD const & a, 
	detail::fvec4SIMD const & b, 
	detail::fvec4SIMD const & c
)
{
	return _mm_add_ps(_mm_mul_ps(a.Data, b.Data), c.Data);
}

GLM_FUNC_QUALIFIER float length
(
	detail::fvec4SIMD const & x
)
{
	detail::fvec4SIMD dot0 = detail::sse_dot_ss(x.Data, x.Data);
	detail::fvec4SIMD sqt0 = sqrt(dot0);
	float Result = 0;
	_mm_store_ss(&Result, sqt0.Data);
	return Result;
}

GLM_FUNC_QUALIFIER float fastLength
(
	detail::fvec4SIMD const & x
)
{
	detail::fvec4SIMD dot0 = detail::sse_dot_ss(x.Data, x.Data);
	detail::fvec4SIMD sqt0 = fastSqrt(dot0);
	float Result = 0;
	_mm_store_ss(&Result, sqt0.Data);
	return Result;
}

GLM_FUNC_QUALIFIER float niceLength
(
	detail::fvec4SIMD const & x
)
{
	detail::fvec4SIMD dot0 = detail::sse_dot_ss(x.Data, x.Data);
	detail::fvec4SIMD sqt0 = niceSqrt(dot0);
	float Result = 0;
	_mm_store_ss(&Result, sqt0.Data);
	return Result;
}

GLM_FUNC_QUALIFIER detail::fvec4SIMD length4
(
	detail::fvec4SIMD const & x
)
{
	return sqrt(dot4(x, x));
}

GLM_FUNC_QUALIFIER detail::fvec4SIMD fastLength4
(
	detail::fvec4SIMD const & x
)
{
	return fastSqrt(dot4(x, x));
}

GLM_FUNC_QUALIFIER detail::fvec4SIMD niceLength4
(
	detail::fvec4SIMD const & x
)
{
	return niceSqrt(dot4(x, x));
}

GLM_FUNC_QUALIFIER float distance
(
	detail::fvec4SIMD const & p0,
	detail::fvec4SIMD const & p1
)
{
	float Result = 0;
	_mm_store_ss(&Result, detail::sse_dst_ps(p0.Data, p1.Data));
	return Result;
}

GLM_FUNC_QUALIFIER detail::fvec4SIMD distance4
(
	detail::fvec4SIMD const & p0,
	detail::fvec4SIMD const & p1
)
{
	return detail::sse_dst_ps(p0.Data, p1.Data);
}

GLM_FUNC_QUALIFIER float dot
(
	detail::fvec4SIMD const & x,
	detail::fvec4SIMD const & y
)
{
	float Result = 0;
	_mm_store_ss(&Result, detail::sse_dot_ss(x.Data, y.Data));
	return Result;
}

GLM_FUNC_QUALIFIER detail::fvec4SIMD dot4
(
	detail::fvec4SIMD const & x,
	detail::fvec4SIMD const & y
)
{
	return detail::sse_dot_ps(x.Data, y.Data);
}

GLM_FUNC_QUALIFIER detail::fvec4SIMD cross
(
	detail::fvec4SIMD const & x,
	detail::fvec4SIMD const & y
)
{
	return detail::sse_xpd_ps(x.Data, y.Data);
}

GLM_FUNC_QUALIFIER detail::fvec4SIMD normalize
(
	detail::fvec4SIMD const & x
)
{
	__m128 dot0 = detail::sse_dot_ps(x.Data, x.Data);
	__m128 isr0 = inversesqrt(detail::fvec4SIMD(dot0)).Data;
	__m128 mul0 = _mm_mul_ps(x.Data, isr0);
	return mul0;
}

GLM_FUNC_QUALIFIER detail::fvec4SIMD fastNormalize
(
	detail::fvec4SIMD const & x
)
{
	__m128 dot0 = detail::sse_dot_ps(x.Data, x.Data);
	__m128 isr0 = fastInversesqrt(dot0).Data;
	__m128 mul0 = _mm_mul_ps(x.Data, isr0);
	return mul0;
}

GLM_FUNC_QUALIFIER detail::fvec4SIMD faceforward
(
	detail::fvec4SIMD const & N,
	detail::fvec4SIMD const & I,
	detail::fvec4SIMD const & Nref
)
{
	return detail::sse_ffd_ps(N.Data, I.Data, Nref.Data);
}

GLM_FUNC_QUALIFIER detail::fvec4SIMD reflect
(
	detail::fvec4SIMD const & I,
	detail::fvec4SIMD const & N
)
{
	return detail::sse_rfe_ps(I.Data, N.Data);
}

GLM_FUNC_QUALIFIER detail::fvec4SIMD refract
(
	detail::fvec4SIMD const & I,
	detail::fvec4SIMD const & N,
	float const & eta
)
{
	return detail::sse_rfa_ps(I.Data, N.Data, _mm_set1_ps(eta));
}

GLM_FUNC_QUALIFIER detail::fvec4SIMD sqrt(detail::fvec4SIMD const & x)
{
	return _mm_mul_ps(inversesqrt(x).Data, x.Data);
}

GLM_FUNC_QUALIFIER detail::fvec4SIMD niceSqrt(detail::fvec4SIMD const & x)
{
	return _mm_sqrt_ps(x.Data);
}

GLM_FUNC_QUALIFIER detail::fvec4SIMD fastSqrt(detail::fvec4SIMD const & x)
{
	return _mm_mul_ps(fastInversesqrt(x.Data).Data, x.Data);
}

// SSE scalar reciprocal sqrt using rsqrt op, plus one Newton-Rhaphson iteration
// By Elan Ruskin, http://assemblyrequired.crashworks.org/
GLM_FUNC_QUALIFIER detail::fvec4SIMD inversesqrt(detail::fvec4SIMD const & x)
{
	GLM_ALIGN(4) static const __m128 three = {3, 3, 3, 3}; // aligned consts for fast load
	GLM_ALIGN(4) static const __m128 half = {0.5,0.5,0.5,0.5};

	__m128 recip = _mm_rsqrt_ps(x.Data);  // "estimate" opcode
	__m128 halfrecip = _mm_mul_ps(half, recip);
	__m128 threeminus_xrr = _mm_sub_ps(three, _mm_mul_ps(x.Data, _mm_mul_ps(recip, recip)));
	return _mm_mul_ps(halfrecip, threeminus_xrr);
}

GLM_FUNC_QUALIFIER detail::fvec4SIMD fastInversesqrt(detail::fvec4SIMD const & x)
{
	return _mm_rsqrt_ps(x.Data);
}

}//namespace glm