forked from darealshinji/vectorclass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vectormath_lib.h
2116 lines (1840 loc) · 70.1 KB
/
vectormath_lib.h
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
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**************************** vectormath_lib.h *****************************
* Author: Agner Fog
* Date created: 2012-05-30
* Last modified: 2016-04-26
* Version: 1.22
* Project: vector classes
* Description:
* Header file defining mathematical functions on floating point vectors
* May use Intel SVML library or AMD LIBM library
*
* Instructions:
* Define VECTORMATH to one of the following values:
* 0: Use ordinary math library (slow)
* 1: Use AMD LIBM library
* 2: Use Intel SVML library with any compiler
* 3: Use Intel SVML library with Intel compiler
*
* For detailed instructions, see VectorClass.pdf
*
* (c) Copyright 2012-2016 GNU General Public License http://www.gnu.org/licenses
\*****************************************************************************/
// check combination of header files
#ifndef VECTORMATH_LIB_H
#define VECTORMATH_LIB_H
#include "vectorf128.h"
#ifndef VECTORMATH
#ifdef __INTEL_COMPILER
#define VECTORMATH 3
#else
#define VECTORMATH 0
#endif // __INTEL_COMPILER
#endif // VECTORMATH
#include <math.h>
#ifdef VCL_NAMESPACE
namespace VCL_NAMESPACE {
#endif
/*****************************************************************************
*
* VECTORMATH = 0. Use ordinary library (scalar)
*
*****************************************************************************/
#if VECTORMATH == 0
#ifndef VECTORMATH_COMMON_H
// exponential and power functions
static inline Vec4f exp (Vec4f const & x) {
float xx[4];
x.store(xx);
return Vec4f(expf(xx[0]), expf(xx[1]), expf(xx[2]), expf(xx[3]));
}
static inline Vec2d exp (Vec2d const & x) {
double xx[4];
x.store(xx);
return Vec2d(::exp(xx[0]), ::exp(xx[1]));
}
// There is no certain way to know which functions are available, but at least some (Gnu)
// compilers have defines to specify this
#ifdef HAVE_EXPM1
static inline Vec4f expm1 (Vec4f const & x) {
float xx[4];
x.store(xx);
return Vec4f(expm1(xx[0]), expm1(xx[1]), expm1(xx[2]), expm1(xx[3]));
}
static inline Vec2d expm1 (Vec2d const & x) {
double xx[4];
x.store(xx);
return Vec2d(expm1(xx[0]), expm1(xx[1]));
}
#endif
#ifdef HAVE_EXP2
static inline Vec4f exp2 (Vec4f const & x) {
float xx[4];
x.store(xx);
return Vec4f(exp2(xx[0]), exp2(xx[1]), exp2(xx[2]), exp2(xx[3]));
}
static inline Vec2d exp2 (Vec2d const & x) {
double xx[4];
x.store(xx);
return Vec2d(exp2(xx[0]), exp2(xx[1]));
}
#else
static inline Vec4f exp2 (Vec4f const & x) {
return exp(x*Vec4f(0.693147180559945309417f /* log(2) */));
}
static inline Vec2d exp2 (Vec2d const & x) {
return exp(x*Vec2d(0.693147180559945309417 /* log(2) */));
}
#endif
static inline Vec4f exp10 (Vec4f const & x) {
return exp(x*Vec4f(2.30258509299404568402f /* log(10) */));
}
static inline Vec2d exp10 (Vec2d const & x) {
return exp(x*Vec2d(2.30258509299404568402 /* log(10) */));
}
static inline Vec4f pow (Vec4f const & a, Vec4f const & b) {
float aa[4], bb[4];
a.store(aa); b.store(bb);
return Vec4f(powf(aa[0],bb[0]), powf(aa[1],bb[1]), powf(aa[2],bb[2]), powf(aa[3],bb[3]));
}
static inline Vec2d pow (Vec2d const & a, Vec2d const & b) {
double aa[4], bb[4];
a.store(aa); b.store(bb);
return Vec2d(::pow(aa[0],bb[0]), ::pow(aa[1],bb[1]));
}
static inline Vec4f log (Vec4f const & x) {
float xx[4];
x.store(xx);
return Vec4f(logf(xx[0]), logf(xx[1]), logf(xx[2]), logf(xx[3]));
}
static inline Vec2d log (Vec2d const & x) {
double xx[4];
x.store(xx);
return Vec2d(::log(xx[0]), ::log(xx[1]));
}
#ifdef HAVE_LOG1P
static inline Vec4f log1p (Vec4f const & x) {
float xx[4];
x.store(xx);
return Vec4f(::log1p(xx[0]), ::log1p(xx[1]), ::log1p(xx[2]), ::log1p(xx[3]));
}
static inline Vec2d log1p (Vec2d const & x) {
double xx[4];
x.store(xx);
return Vec2d(::log1p(xx[0]), ::log1p(xx[1]));
}
#endif
static inline Vec4f log2 (Vec4f const & x) { // logarithm base 2
return log(x)*Vec4f(1.44269504088896340736f/* log2(e) */);
}
static inline Vec2d log2 (Vec2d const & x) { // logarithm base 2
return log(x)*Vec2d(1.44269504088896340736 /* log2(e) */);
}
static inline Vec4f log10 (Vec4f const & x) { // logarithm base 10
float xx[4];
x.store(xx);
return Vec4f(log10f(xx[0]), log10f(xx[1]), log10f(xx[2]), log10f(xx[3]));
}
static inline Vec2d log10 (Vec2d const & x) { // logarithm base 10
double xx[4];
x.store(xx);
return Vec2d(::log10(xx[0]), ::log10(xx[1]));
}
// trigonometric functions
static inline Vec4f sin(Vec4f const & x) {
float xx[4];
x.store(xx);
return Vec4f(sinf(xx[0]), sinf(xx[1]), sinf(xx[2]), sinf(xx[3]));
}
static inline Vec2d sin (Vec2d const & x) {
double xx[4];
x.store(xx);
return Vec2d(::sin(xx[0]), ::sin(xx[1]));
}
static inline Vec4f cos(Vec4f const & x) {
float xx[4];
x.store(xx);
return Vec4f(cosf(xx[0]), cosf(xx[1]), cosf(xx[2]), cosf(xx[3]));
}
static inline Vec2d cos (Vec2d const & x) {
double xx[4];
x.store(xx);
return Vec2d(::cos(xx[0]), ::cos(xx[1]));
}
static inline Vec4f sincos (Vec4f * pcos, Vec4f const & x) { // sine and cosine. sin(x) returned, cos(x) in pcos
*pcos = cos(x);
return sin(x);
}
static inline Vec2d sincos (Vec2d * pcos, Vec2d const & x) { // sine and cosine. sin(x) returned, cos(x) in pcos
*pcos = cos(x);
return sin(x);
}
static inline Vec4f tan(Vec4f const & x) {
float xx[4];
x.store(xx);
return Vec4f(tanf(xx[0]), tanf(xx[1]), tanf(xx[2]), tanf(xx[3]));
}
static inline Vec2d tan (Vec2d const & x) {
double xx[4];
x.store(xx);
return Vec2d(::tan(xx[0]), ::tan(xx[1]));
}
// inverse trigonometric functions
static inline Vec4f asin(Vec4f const & x) {
float xx[4];
x.store(xx);
return Vec4f(asinf(xx[0]), asinf(xx[1]), asinf(xx[2]), asinf(xx[3]));
}
static inline Vec2d asin (Vec2d const & x) {
double xx[4];
x.store(xx);
return Vec2d(::asin(xx[0]), ::asin(xx[1]));
}
static inline Vec4f acos(Vec4f const & x) {
float xx[4];
x.store(xx);
return Vec4f(acosf(xx[0]), acosf(xx[1]), acosf(xx[2]), acosf(xx[3]));
}
static inline Vec2d acos (Vec2d const & x) {
double xx[4];
x.store(xx);
return Vec2d(::acos(xx[0]), ::acos(xx[1]));
}
static inline Vec4f atan(Vec4f const & x) {
float xx[4];
x.store(xx);
return Vec4f(atanf(xx[0]), atanf(xx[1]), atanf(xx[2]), atanf(xx[3]));
}
static inline Vec2d atan (Vec2d const & x) {
double xx[4];
x.store(xx);
return Vec2d(::atan(xx[0]), ::atan(xx[1]));
}
static inline Vec4f atan2 (Vec4f const & a, Vec4f const & b) { // inverse tangent of a/b
float aa[4], bb[4];
a.store(aa); b.store(bb);
return Vec4f(atan2f(aa[0],bb[0]), atan2f(aa[1],bb[1]), atan2f(aa[2],bb[2]), atan2f(aa[3],bb[3]));
}
static inline Vec2d atan2 (Vec2d const & a, Vec2d const & b) { // inverse tangent of a/b
double aa[4], bb[4];
a.store(aa); b.store(bb);
return Vec2d(::atan2(aa[0],bb[0]), ::atan2(aa[1],bb[1]));
}
#endif // VECTORMATH_COMMON_H
// hyperbolic functions
static inline Vec4f sinh(Vec4f const & x) { // hyperbolic sine
float xx[4];
x.store(xx);
return Vec4f(sinhf(xx[0]), sinhf(xx[1]), sinhf(xx[2]), sinhf(xx[3]));
}
static inline Vec2d sinh (Vec2d const & x) {
double xx[4];
x.store(xx);
return Vec2d(::sinh(xx[0]), ::sinh(xx[1]));
}
static inline Vec4f cosh(Vec4f const & x) { // hyperbolic cosine
float xx[4];
x.store(xx);
return Vec4f(coshf(xx[0]), coshf(xx[1]), coshf(xx[2]), coshf(xx[3]));
}
static inline Vec2d cosh (Vec2d const & x) {
double xx[4];
x.store(xx);
return Vec2d(::cosh(xx[0]), ::cosh(xx[1]));
}
static inline Vec4f tanh(Vec4f const & x) { // hyperbolic tangent
float xx[4];
x.store(xx);
return Vec4f(tanhf(xx[0]), tanhf(xx[1]), tanhf(xx[2]), tanhf(xx[3]));
}
static inline Vec2d tanh (Vec2d const & x) {
double xx[4];
x.store(xx);
return Vec2d(::tanh(xx[0]), ::tanh(xx[1]));
}
// error function
#ifdef HAVE_ERF
static inline Vec4f erf(Vec4f const & x) {
float xx[4];
x.store(xx);
return Vec4f(::erf(xx[0]), ::erf(xx[1]), ::erf(xx[2]), ::erf(xx[3]));
}
static inline Vec2d erf (Vec2d const & x) {
double xx[4];
x.store(xx);
return Vec2d(::erf(xx[0]), ::erf(xx[1]));
}
#endif
#ifdef HAVE_ERFC
static inline Vec4f erfc(Vec4f const & x) {
float xx[4];
x.store(xx);
return Vec4f(::erfc(xx[0]), ::erfc(xx[1]), ::erfc(xx[2]), ::erfc(xx[3]));
}
static inline Vec2d erfc (Vec2d const & x) {
double xx[4];
x.store(xx);
return Vec2d(::erfc(xx[0]), ::erfc(xx[1]));
}
#endif
// complex exponential function (real part in even numbered elements, imaginary part in odd numbered elements)
static inline Vec4f cexp (Vec4f const & x) { // complex exponential function
float xx[4], ee[2];
x.store(xx);
Vec4f z(cosf(xx[1]),sinf(xx[1]),cosf(xx[3]),sinf(xx[3]));
ee[0] = expf(xx[0]); ee[1] = expf(xx[2]);
return z * Vec4f(ee[0],ee[0],ee[1],ee[1]);
}
static inline Vec2d cexp (Vec2d const & x) { // complex exponential function
double xx[2];
x.store(xx);
Vec2d z(::cos(xx[1]), ::sin(xx[1]));
return z * ::exp(xx[0]);
}
#if defined (VECTORF256_H) // 256 bit vectors defined
#ifndef VECTORMATH_COMMON_H
// exponential and power functions
static inline Vec8f exp (Vec8f const & x) { // exponential function
return Vec8f(exp(x.get_low()), exp(x.get_high()));
}
static inline Vec4d exp (Vec4d const & x) { // exponential function
return Vec4d(exp(x.get_low()), exp(x.get_high()));
}
#ifdef HAVE_EXPM1
static inline Vec8f expm1 (Vec8f const & x) { // exp(x)-1
return Vec8f(expm1(x.get_low()), expm1(x.get_high()));
}
static inline Vec4d expm1 (Vec4d const & x) { // exp(x)-1
return Vec4d(expm1(x.get_low()), expm1(x.get_high()));
}
#endif
static inline Vec8f exp2 (Vec8f const & x) { // pow(2,x)
return Vec8f(exp2(x.get_low()), exp2(x.get_high()));
}
static inline Vec4d exp2 (Vec4d const & x) { // pow(2,x)
return Vec4d(exp2(x.get_low()), exp2(x.get_high()));
}
static inline Vec8f exp10 (Vec8f const & x) { // pow(10,x)
return Vec8f(exp10(x.get_low()), exp10(x.get_high()));
}
static inline Vec4d exp10 (Vec4d const & x) { // pow(10,x)
return Vec4d(exp10(x.get_low()), exp10(x.get_high()));
}
static inline Vec8f pow (Vec8f const & a, Vec8f const & b) { // pow(a,b) = a to the power of b
return Vec8f(pow(a.get_low(),b.get_low()), pow(a.get_high(),b.get_high()));
}
static inline Vec4d pow (Vec4d const & a, Vec4d const & b) { // pow(a,b) = a to the power of b
return Vec4d(pow(a.get_low(),b.get_low()), pow(a.get_high(),b.get_high()));
}
// logarithms
static inline Vec8f log (Vec8f const & x) { // natural logarithm
return Vec8f(log(x.get_low()), log(x.get_high()));
}
static inline Vec4d log (Vec4d const & x) { // natural logarithm
return Vec4d(log(x.get_low()), log(x.get_high()));
}
#ifdef HAVE_LOG1P
static inline Vec8f log1p (Vec8f const & x) { // log(1+x). Avoids loss of precision if 1+x is close to 1
return Vec8f(log1p(x.get_low()), log1p(x.get_high()));
}
static inline Vec4d log1p (Vec4d const & x) { // log(1+x). Avoids loss of precision if 1+x is close to 1
return Vec4d(log1p(x.get_low()), log1p(x.get_high()));
}
#endif
static inline Vec8f log2 (Vec8f const & x) { // logarithm base 2
return Vec8f(log2(x.get_low()), log2(x.get_high()));
}
static inline Vec4d log2 (Vec4d const & x) { // logarithm base 2
return Vec4d(log2(x.get_low()), log2(x.get_high()));
}
static inline Vec8f log10 (Vec8f const & x) { // logarithm base 10
return Vec8f(log10(x.get_low()), log10(x.get_high()));
}
static inline Vec4d log10 (Vec4d const & x) { // logarithm base 10
return Vec4d(log10(x.get_low()), log10(x.get_high()));
}
// trigonometric functions (angles in radians)
static inline Vec8f sin (Vec8f const & x) { // sine
return Vec8f(sin(x.get_low()), sin(x.get_high()));
}
static inline Vec4d sin (Vec4d const & x) { // sine
return Vec4d(sin(x.get_low()), sin(x.get_high()));
}
static inline Vec8f cos (Vec8f const & x) { // cosine
return Vec8f(cos(x.get_low()), cos(x.get_high()));
}
static inline Vec4d cos (Vec4d const & x) { // cosine
return Vec4d(cos(x.get_low()), cos(x.get_high()));
}
static inline Vec8f sincos (Vec8f * pcos, Vec8f const & x) { // sine and cosine. sin(x) returned, cos(x) in pcos
*pcos = Vec8f(cos(x.get_low()), cos(x.get_high()));
return Vec8f(sin(x.get_low()), sin(x.get_high()));
}
static inline Vec4d sincos (Vec4d * pcos, Vec4d const & x) { // sine and cosine. sin(x) returned, cos(x) in pcos
*pcos = Vec4d(cos(x.get_low()), cos(x.get_high()));
return Vec4d(sin(x.get_low()), sin(x.get_high()));
}
static inline Vec8f tan (Vec8f const & x) { // tangent
return Vec8f(tan(x.get_low()), tan(x.get_high()));
}
static inline Vec4d tan (Vec4d const & x) { // tangent
return Vec4d(tan(x.get_low()), tan(x.get_high()));
}
// inverse trigonometric functions
static inline Vec8f asin (Vec8f const & x) { // inverse sine
return Vec8f(asin(x.get_low()), asin(x.get_high()));
}
static inline Vec4d asin (Vec4d const & x) { // inverse sine
return Vec4d(asin(x.get_low()), asin(x.get_high()));
}
static inline Vec8f acos (Vec8f const & x) { // inverse cosine
return Vec8f(acos(x.get_low()), acos(x.get_high()));
}
static inline Vec4d acos (Vec4d const & x) { // inverse cosine
return Vec4d(acos(x.get_low()), acos(x.get_high()));
}
static inline Vec8f atan (Vec8f const & x) { // inverse tangent
return Vec8f(atan(x.get_low()), atan(x.get_high()));
}
static inline Vec4d atan (Vec4d const & x) { // inverse tangent
return Vec4d(atan(x.get_low()), atan(x.get_high()));
}
static inline Vec8f atan2 (Vec8f const & a, Vec8f const & b) { // inverse tangent of a/b
return Vec8f(atan2(a.get_low(),b.get_low()), atan2(a.get_high(),b.get_high()));
}
static inline Vec4d atan2 (Vec4d const & a, Vec4d const & b) { // inverse tangent of a/b
return Vec4d(atan2(a.get_low(),b.get_low()), atan2(a.get_high(),b.get_high()));
}
#endif // VECTORMATH_COMMON_H
// hyperbolic functions and inverse hyperbolic functions
static inline Vec8f sinh (Vec8f const & x) { // hyperbolic sine
return Vec8f(sinh(x.get_low()), sinh(x.get_high()));
}
static inline Vec4d sinh (Vec4d const & x) { // hyperbolic sine
return Vec4d(sinh(x.get_low()), sinh(x.get_high()));
}
static inline Vec8f cosh (Vec8f const & x) { // hyperbolic cosine
return Vec8f(cosh(x.get_low()), cosh(x.get_high()));
}
static inline Vec4d cosh (Vec4d const & x) { // hyperbolic cosine
return Vec4d(cosh(x.get_low()), cosh(x.get_high()));
}
static inline Vec8f tanh (Vec8f const & x) { // hyperbolic tangent
return Vec8f(tanh(x.get_low()), tanh(x.get_high()));
}
static inline Vec4d tanh (Vec4d const & x) { // hyperbolic tangent
return Vec4d(tanh(x.get_low()), tanh(x.get_high()));
}
// error function
#ifdef HAVE_ERF
static inline Vec8f erf (Vec8f const & x) { // error function
return Vec8f(erf(x.get_low()), erf(x.get_high()));
}
static inline Vec4d erf (Vec4d const & x) { // error function
return Vec4d(erf(x.get_low()), erf(x.get_high()));
}
#endif
#ifdef HAVE_ERFC
static inline Vec8f erfc (Vec8f const & x) { // error function complement
return Vec8f(erfc(x.get_low()), erfc(x.get_high()));
}
static inline Vec4d erfc (Vec4d const & x) { // error function complement
return Vec4d(erfc(x.get_low()), erfc(x.get_high()));
}
#endif
// complex exponential function (real part in even numbered elements, imaginary part in odd numbered elements)
static inline Vec8f cexp (Vec8f const & x) { // complex exponential function
return Vec8f(cexp(x.get_low()), cexp(x.get_high()));
}
static inline Vec4d cexp (Vec4d const & x) { // complex exponential function
return Vec4d(cexp(x.get_low()), cexp(x.get_high()));
}
#endif // VECTORF256_H == 1
/*****************************************************************************
*
* VECTORMATH = 1. Use AMD LIBM library
*
*****************************************************************************/
#elif VECTORMATH == 1
//#include <amdlibm.h>
#include "amdlibm.h" // if header file is in current directory
#ifndef VECTORMATH_COMMON_H
// exponential and power functions
static inline Vec4f exp (Vec4f const & x) { // exponential function
return amd_vrs4_expf(x);
}
static inline Vec2d exp (Vec2d const & x) { // exponential function
return amd_vrd2_exp(x);
}
static inline Vec4f expm1 (Vec4f const & x) { // exp(x)-1. Avoids loss of precision if x is close to 1
return amd_vrs4_expm1f(x);
}
static inline Vec2d expm1 (Vec2d const & x) { // exp(x)-1. Avoids loss of precision if x is close to 1
return amd_vrd2_expm1(x);
}
static inline Vec4f exp2 (Vec4f const & x) { // pow(2,x)
return amd_vrs4_exp2f(x);
}
static inline Vec2d exp2 (Vec2d const & x) { // pow(2,x)
return amd_vrd2_exp2(x);
}
static inline Vec4f exp10 (Vec4f const & x) { // pow(10,x)
return amd_vrs4_exp10f(x);
}
static inline Vec2d exp10 (Vec2d const & x) { // pow(10,x)
return amd_vrd2_exp10(x);
}
static inline Vec4f pow (Vec4f const & a, Vec4f const & b) { // pow(a,b) = a to the power of b
return amd_vrs4_powf(a,b);
}
static inline Vec2d pow (Vec2d const & a, Vec2d const & b) { // pow(a,b) = a to the power of b
return amd_vrd2_pow(a,b);
}
static inline Vec4f cbrt (Vec4f const & x) { // pow(x,1/3)
return amd_vrs4_cbrtf(x);
}
static inline Vec2d cbrt (Vec2d const & x) { // pow(x,1/3)
return amd_vrd2_cbrt(x);
}
// logarithms
static inline Vec4f log (Vec4f const & x) { // natural logarithm
return amd_vrs4_logf(x);
}
static inline Vec2d log (Vec2d const & x) { // natural logarithm
return amd_vrd2_log(x);
}
static inline Vec4f log1p (Vec4f const & x) { // log(1+x). Avoids loss of precision if 1+x is close to 1
return amd_vrs4_log1pf(x);
}
static inline Vec2d log1p (Vec2d const & x) { // log(1+x). Avoids loss of precision if 1+x is close to 1
return amd_vrd2_log1p(x);
}
static inline Vec4f log2 (Vec4f const & x) { // logarithm base 2
return amd_vrs4_log2f(x);
}
static inline Vec2d log2 (Vec2d const & x) { // logarithm base 2
return amd_vrd2_log2(x);
}
static inline Vec4f log10 (Vec4f const & x) { // logarithm base 10
return amd_vrs4_log10f(x);
}
static inline Vec2d log10 (Vec2d const & x) { // logarithm base 10
return amd_vrd2_log10(x);
}
// trigonometric functions (angles in radians)
static inline Vec4f sin (Vec4f const & x) { // sine
return amd_vrs4_sinf(x);
}
static inline Vec2d sin (Vec2d const & x) { // sine
return amd_vrd2_sin(x);
}
static inline Vec4f cos (Vec4f const & x) { // cosine
return amd_vrs4_cosf(x);
}
static inline Vec2d cos (Vec2d const & x) { // cosine
return amd_vrd2_cos(x);
}
static inline Vec4f sincos (Vec4f * pcos, Vec4f const & x) { // sine and cosine. sin(x) returned, cos(x) in pcos
__m128 r_sin;
amd_vrs4_sincosf(x, &r_sin, (__m128*)pcos);
return r_sin;
}
static inline Vec2d sincos (Vec2d * pcos, Vec2d const & x) { // sine and cosine. sin(x) returned, cos(x) in pcos
__m128d r_sin;
amd_vrd2_sincos(x, &r_sin, (__m128d*)pcos);
return r_sin;
}
static inline Vec4f tan (Vec4f const & x) { // tangent
return amd_vrs4_tanf(x);
}
static inline Vec2d tan (Vec2d const & x) { // tangent
return amd_vrd2_tan(x);
}
// inverse trigonometric functions not supported
#endif // VECTORMATH_COMMON_H
// hyperbolic functions and inverse hyperbolic functions not supported
// error function not supported
// complex exponential function not supported
#ifdef VECTORF256_H
// Emulate 256 bit vector functions with two 128-bit vectors
#ifndef VECTORMATH_COMMON_H
// exponential and power functions
static inline Vec8f exp (Vec8f const & x) { // exponential function
return Vec8f(exp(x.get_low()), exp(x.get_high()));
}
static inline Vec4d exp (Vec4d const & x) { // exponential function
return Vec4d(exp(x.get_low()), exp(x.get_high()));
}
static inline Vec8f expm1 (Vec8f const & x) { // exp(x)-1. Avoids loss of precision if x is close to 1
return Vec8f(expm1(x.get_low()), expm1(x.get_high()));
}
static inline Vec4d expm1 (Vec4d const & x) { // exp(x)-1. Avoids loss of precision if x is close to 1
return Vec4d(expm1(x.get_low()), expm1(x.get_high()));
}
static inline Vec8f exp2 (Vec8f const & x) { // pow(2,x)
return Vec8f(exp2(x.get_low()), exp2(x.get_high()));
}
static inline Vec4d exp2 (Vec4d const & x) { // pow(2,x)
return Vec4d(exp2(x.get_low()), exp2(x.get_high()));
}
static inline Vec8f exp10 (Vec8f const & x) { // pow(10,x)
return Vec8f(exp10(x.get_low()), exp10(x.get_high()));
}
static inline Vec4d exp10 (Vec4d const & x) { // pow(10,x)
return Vec4d(exp10(x.get_low()), exp10(x.get_high()));
}
static inline Vec8f pow (Vec8f const & a, Vec8f const & b) { // pow(a,b) = a to the power of b
return Vec8f(pow(a.get_low(),b.get_low()), pow(a.get_high(),b.get_high()));
}
static inline Vec4d pow (Vec4d const & a, Vec4d const & b) { // pow(a,b) = a to the power of b
return Vec4d(pow(a.get_low(),b.get_low()), pow(a.get_high(),b.get_high()));
}
static inline Vec8f cbrt (Vec8f const & x) { // pow(x,1/3)
return Vec8f(cbrt(x.get_low()), cbrt(x.get_high()));
}
static inline Vec4d cbrt (Vec4d const & x) { // pow(x,1/3)
return Vec4d(cbrt(x.get_low()), cbrt(x.get_high()));
}
// logarithms
static inline Vec8f log (Vec8f const & x) { // natural logarithm
return Vec8f(log(x.get_low()), log(x.get_high()));
}
static inline Vec4d log (Vec4d const & x) { // natural logarithm
return Vec4d(log(x.get_low()), log(x.get_high()));
}
static inline Vec8f log1p (Vec8f const & x) { // log(1+x). Avoids loss of precision if 1+x is close to 1
return Vec8f(log1p(x.get_low()), log1p(x.get_high()));
}
static inline Vec4d log1p (Vec4d const & x) { // log(1+x). Avoids loss of precision if 1+x is close to 1
return Vec4d(log1p(x.get_low()), log1p(x.get_high()));
}
static inline Vec8f log2 (Vec8f const & x) { // logarithm base 2
return Vec8f(log2(x.get_low()), log2(x.get_high()));
}
static inline Vec4d log2 (Vec4d const & x) { // logarithm base 2
return Vec4d(log2(x.get_low()), log2(x.get_high()));
}
static inline Vec8f log10 (Vec8f const & x) { // logarithm base 10
return Vec8f(log10(x.get_low()), log10(x.get_high()));
}
static inline Vec4d log10 (Vec4d const & x) { // logarithm base 10
return Vec4d(log10(x.get_low()), log10(x.get_high()));
}
// trigonometric functions (angles in radians)
static inline Vec8f sin (Vec8f const & x) { // sine
return Vec8f(sin(x.get_low()), sin(x.get_high()));
}
static inline Vec4d sin (Vec4d const & x) { // sine
return Vec4d(sin(x.get_low()), sin(x.get_high()));
}
static inline Vec8f cos (Vec8f const & x) { // cosine
return Vec8f(cos(x.get_low()), cos(x.get_high()));
}
static inline Vec4d cos (Vec4d const & x) { // cosine
return Vec4d(cos(x.get_low()), cos(x.get_high()));
}
static inline Vec8f sincos (Vec8f * pcos, Vec8f const & x) { // sine and cosine. sin(x) returned, cos(x) in pcos
Vec4f r_sin0, r_sin1, r_cos0, r_cos1;
r_sin0 = sincos(&r_cos0, x.get_low());
r_sin1 = sincos(&r_cos1, x.get_high());
*pcos = Vec8f(r_cos0, r_cos1);
return Vec8f(r_sin0, r_sin1);
}
static inline Vec4d sincos (Vec4d * pcos, Vec4d const & x) { // sine and cosine. sin(x) returned, cos(x) in pcos
Vec2d r_sin0, r_sin1, r_cos0, r_cos1;
r_sin0 = sincos(&r_cos0, x.get_low());
r_sin1 = sincos(&r_cos1, x.get_high());
*pcos = Vec4d(r_cos0, r_cos1);
return Vec4d(r_sin0, r_sin1);
}
static inline Vec8f tan (Vec8f const & x) { // tangent
return Vec8f(tan(x.get_low()), tan(x.get_high()));
}
static inline Vec4d tan (Vec4d const & x) { // tangent
return Vec4d(tan(x.get_low()), tan(x.get_high()));
}
#endif // VECTORMATH_COMMON_H
#endif // VECTORF256_H == 1
/*****************************************************************************
*
* VECTORMATH = 2. Use Intel SVML library with any compiler
*
*****************************************************************************/
#elif VECTORMATH == 2
extern "C" {
extern __m128 __svml_expf4 (__m128);
extern __m128d __svml_exp2 (__m128d);
extern __m128 __svml_expm1f4 (__m128);
extern __m128d __svml_expm12 (__m128d);
extern __m128 __svml_exp2f4 (__m128);
extern __m128d __svml_exp22 (__m128d);
extern __m128 __svml_exp10f4 (__m128);
extern __m128d __svml_exp102 (__m128d);
extern __m128 __svml_powf4 (__m128, __m128);
extern __m128d __svml_pow2 (__m128d, __m128d);
extern __m128 __svml_cbrtf4 (__m128);
extern __m128d __svml_cbrt2 (__m128d);
extern __m128 __svml_invsqrtf4 (__m128);
extern __m128d __svml_invsqrt2 (__m128d);
extern __m128 __svml_logf4 (__m128);
extern __m128d __svml_log2 (__m128d);
extern __m128 __svml_log1pf4 (__m128);
extern __m128d __svml_log1p2 (__m128d);
extern __m128 __svml_log2f4 (__m128);
extern __m128d __svml_log22 (__m128d);
extern __m128 __svml_log10f4 (__m128);
extern __m128d __svml_log102 (__m128d);
extern __m128 __svml_sinf4 (__m128);
extern __m128d __svml_sin2 (__m128d);
extern __m128 __svml_cosf4 (__m128);
extern __m128d __svml_cos2 (__m128d);
extern __m128 __svml_sincosf4 (__m128); // cos returned in xmm1
extern __m128d __svml_sincos2 (__m128d); // cos returned in xmm1
extern __m128 __svml_tanf4 (__m128);
extern __m128d __svml_tan2 (__m128d);
extern __m128 __svml_asinf4 (__m128);
extern __m128d __svml_asin2 (__m128d);
extern __m128 __svml_acosf4 (__m128);
extern __m128d __svml_acos2 (__m128d);
extern __m128 __svml_atanf4 (__m128);
extern __m128d __svml_atan2 (__m128d);
extern __m128 __svml_atan2f4 (__m128, __m128);
extern __m128d __svml_atan22 (__m128d, __m128d);
extern __m128 __svml_sinhf4 (__m128);
extern __m128d __svml_sinh2 (__m128d);
extern __m128 __svml_coshf4 (__m128);
extern __m128d __svml_cosh2 (__m128d);
extern __m128 __svml_tanhf4 (__m128);
extern __m128d __svml_tanh2 (__m128d);
extern __m128 __svml_asinhf4 (__m128);
extern __m128d __svml_asinh2 (__m128d);
extern __m128 __svml_acoshf4 (__m128);
extern __m128d __svml_acosh2 (__m128d);
extern __m128 __svml_atanhf4 (__m128);
extern __m128d __svml_atanh2 (__m128d);
extern __m128 __svml_erff4 (__m128);
extern __m128d __svml_erf2 (__m128d);
extern __m128 __svml_erfcf4 (__m128);
extern __m128d __svml_erfc2 (__m128d);
extern __m128 __svml_erfinvf4 (__m128);
extern __m128d __svml_erfinv2 (__m128d);
extern __m128 __svml_cdfnorminvf4(__m128);
extern __m128d __svml_cdfnorminv2 (__m128d);
extern __m128 __svml_cdfnormf4 (__m128);
extern __m128d __svml_cdfnorm2 (__m128d);
extern __m128 __svml_cexpf4 (__m128);
extern __m128d __svml_cexp2 (__m128d);
}
#ifndef VECTORMATH_COMMON_H
// exponential and power functions
static inline Vec4f exp (Vec4f const & x) { // exponential function
return __svml_expf4(x);
}
static inline Vec2d exp (Vec2d const & x) { // exponential function
return __svml_exp2(x);
}
static inline Vec4f expm1 (Vec4f const & x) { // exp(x)-1. Avoids loss of precision if x is close to 1
return __svml_expm1f4(x);
}
static inline Vec2d expm1 (Vec2d const & x) { // exp(x)-1. Avoids loss of precision if x is close to 1
return __svml_expm12(x);
}
static inline Vec4f exp2 (Vec4f const & x) { // pow(2,x)
return __svml_exp2f4(x);
}
static inline Vec2d exp2 (Vec2d const & x) { // pow(2,x)
return __svml_exp22(x);
}
static inline Vec4f exp10 (Vec4f const & x) { // pow(10,x)
return __svml_exp10f4(x);
}
static inline Vec2d exp10 (Vec2d const & x) { // pow(10,x)
return __svml_exp102(x);
}
static inline Vec4f pow (Vec4f const & a, Vec4f const & b) { // pow(a,b) = a to the power of b
return __svml_powf4(a,b);
}
static inline Vec2d pow (Vec2d const & a, Vec2d const & b) { // pow(a,b) = a to the power of b
return __svml_pow2(a,b);
}
static inline Vec4f cbrt (Vec4f const & x) { // pow(x,1/3)
return __svml_cbrtf4(x);
}
static inline Vec2d cbrt (Vec2d const & x) { // pow(x,1/3)
return __svml_cbrt2(x);
}
// logarithms
static inline Vec4f log (Vec4f const & x) { // natural logarithm
return __svml_logf4(x);
}
static inline Vec2d log (Vec2d const & x) { // natural logarithm
return __svml_log2(x);
}
static inline Vec4f log1p (Vec4f const & x) { // log(1+x). Avoids loss of precision if 1+x is close to 1
return __svml_log1pf4(x);
}
static inline Vec2d log1p (Vec2d const & x) { // log(1+x). Avoids loss of precision if 1+x is close to 1
return __svml_log1p2(x);
}
static inline Vec4f log2 (Vec4f const & x) { // logarithm base 2
return __svml_log2f4(x);
}
static inline Vec2d log2 (Vec2d const & x) { // logarithm base 2
return __svml_log22(x);
}
static inline Vec4f log10 (Vec4f const & x) { // logarithm base 10
return __svml_log10f4(x);
}
static inline Vec2d log10 (Vec2d const & x) { // logarithm base 10
return __svml_log102(x);
}
// trigonometric functions (angles in radians)
static inline Vec4f sin (Vec4f const & x) { // sine
return __svml_sinf4(x);
}
static inline Vec2d sin (Vec2d const & x) { // sine
return __svml_sin2(x);
}
static inline Vec4f cos (Vec4f const & x) { // cosine
return __svml_cosf4(x);
}
static inline Vec2d cos (Vec2d const & x) { // cosine
return __svml_cos2(x);
}
#if defined(__unix__) || defined(__INTEL_COMPILER) || !defined(__x86_64__) || !defined(_MSC_VER)
// no inline assembly in 64 bit MS compiler
static inline Vec4f sincos (Vec4f * pcos, Vec4f const & x) { // sine and cosine. sin(x) returned, cos(x) in pcos
__m128 r_sin, r_cos;
r_sin = __svml_sincosf4(x);
#if defined(__unix__) || defined(__GNUC__)
// __asm__ ( "call __svml_sincosf4 \n movaps %%xmm0, %0 \n movaps %%xmm1, %1" : "=m"(r_sin), "=m"(r_cos) : "xmm0"(x) );
__asm__ __volatile__ ( "movaps %%xmm1, %0":"=m"(r_cos));
#else // Windows
_asm movaps r_cos, xmm1;
#endif
*pcos = r_cos;
return r_sin;
}
static inline Vec2d sincos (Vec2d * pcos, Vec2d const & x) { // sine and cosine. sin(x) returned, cos(x) in pcos
__m128d r_sin, r_cos;
r_sin = __svml_sincos2(x);
#if defined(__unix__) || defined(__GNUC__)
__asm__ __volatile__ ( "movaps %%xmm1, %0":"=m"(r_cos));
#else // Windows
_asm movapd r_cos, xmm1;
#endif
*pcos = r_cos;
return r_sin;
}
#endif // inline assembly available
static inline Vec4f tan (Vec4f const & x) { // tangent
return __svml_tanf4(x);
}
static inline Vec2d tan (Vec2d const & x) { // tangent
return __svml_tan2(x);
}
// inverse trigonometric functions
static inline Vec4f asin (Vec4f const & x) { // inverse sine
return __svml_asinf4(x);
}
static inline Vec2d asin (Vec2d const & x) { // inverse sine
return __svml_asin2(x);
}
static inline Vec4f acos (Vec4f const & x) { // inverse cosine
return __svml_acosf4(x);
}
static inline Vec2d acos (Vec2d const & x) { // inverse cosine
return __svml_acos2(x);
}
static inline Vec4f atan (Vec4f const & x) { // inverse tangent
return __svml_atanf4(x);
}
static inline Vec2d atan (Vec2d const & x) { // inverse tangent
return __svml_atan2(x);
}
static inline Vec4f atan2 (Vec4f const & a, Vec4f const & b) { // inverse tangent of a/b
return __svml_atan2f4(a,b);
}
static inline Vec2d atan2 (Vec2d const & a, Vec2d const & b) { // inverse tangent of a/b
return __svml_atan22(a,b);
}
#endif // VECTORMATH_COMMON_H
// hyperbolic functions and inverse hyperbolic functions
static inline Vec4f sinh (Vec4f const & x) { // hyperbolic sine
return __svml_sinhf4(x);
}
static inline Vec2d sinh (Vec2d const & x) { // hyperbolic sine
return __svml_sinh2(x);
}
static inline Vec4f cosh (Vec4f const & x) { // hyperbolic cosine
return __svml_coshf4(x);
}
static inline Vec2d cosh (Vec2d const & x) { // hyperbolic cosine
return __svml_cosh2(x);
}
static inline Vec4f tanh (Vec4f const & x) { // hyperbolic tangent
return __svml_tanhf4(x);
}
static inline Vec2d tanh (Vec2d const & x) { // hyperbolic tangent
return __svml_tanh2(x);
}