forked from vectorclass/version2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vectormath_lib.h
2211 lines (2058 loc) · 81.5 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: 2022-08-02
* Version: 2.02.00
* Project: vector class library
* Description:
* Header file defining mathematical functions on floating point vectors
* using Intel SVML (Short Vector Math Library)
*
* Include this file if you want to use SVML for math functions on vectors
* See vcl_manual.pdf for details on how to obtain the SVML library and link to it.
* Alternatively, use the inline math functions by including
* vectormath_exp.h for power and exponential functions,
* vectormath_trig.h for trigonometric functions,
* vectormath_hyp.h for hyperbolic functions
*
* For detailed instructions, see vcl_manual.pdf
*
* (c) Copyright 2012-2022 Agner Fog.
* Apache License version 2.0 or later.
\*****************************************************************************/
// check combination of header files
#ifndef VECTORMATH_LIB_H
#define VECTORMATH_LIB_H 202
#ifdef VECTORMATH_COMMON_H
#error conflicting header files. More than one implementation of mathematical functions included
#else
#include "vectorclass.h" // make sure vector classes are defined first
#ifdef VCL_NAMESPACE
namespace VCL_NAMESPACE { // optional name space
#endif
#if defined(__INTEL_COMPILER) || defined(__INTEL_LLVM_COMPILER)
#define USE_SVML_INTRINSICS // Intel compilers have intrinsic functions of access to SVML library
#endif
#if !(defined(USE_SVML_INTRINSICS))
// sinpi, cospi, and tanpi functions are included in SVML, but undocumented
// (The "Classic" version of Intel compiler accepts the intrinsics of these functions even though they are not in the header files)
#define TRIGPI_FUNCTIONS
#endif
#if defined(__clang__) || defined (__GNUC__)
#define SINCOS_ASM // sincos can be fixed with inline assembly
#else
// MS compiler does not support inline assembly. sincos not available
#endif
#ifdef USE_SVML_INTRINSICS
/*****************************************************************************
*
* 128-bit vector functions using Intel compiler intrinsic functions
*
*****************************************************************************/
// exponential and power functions
static inline Vec4f exp(Vec4f const x) { // exponential function
return _mm_exp_ps(x);
}
static inline Vec2d exp(Vec2d const x) { // exponential function
return _mm_exp_pd(x);
}
static inline Vec4f expm1(Vec4f const x) { // exp(x)-1. Avoids loss of precision if x is close to 1
return _mm_expm1_ps(x);
}
static inline Vec2d expm1(Vec2d const x) { // exp(x)-1. Avoids loss of precision if x is close to 1
return _mm_expm1_pd(x);
}
static inline Vec4f exp2(Vec4f const x) { // pow(2,x)
return _mm_exp2_ps(x);
}
static inline Vec2d exp2(Vec2d const x) { // pow(2,x)
return _mm_exp2_pd(x);
}
static inline Vec4f exp10(Vec4f const x) { // pow(10,x)
return _mm_exp10_ps(x);
}
static inline Vec2d exp10(Vec2d const x) { // pow(10,x)
return _mm_exp10_pd(x);
}
static inline Vec4f pow(Vec4f const a, Vec4f const b) { // pow(a,b) = a to the power of b
return _mm_pow_ps(a, b);
}
static inline Vec4f pow(Vec4f const a, float const b) { // pow(a,b) = a to the power of b
return _mm_pow_ps(a, Vec4f(b));
}
static inline Vec2d pow(Vec2d const a, Vec2d const b) { // pow(a,b) = a to the power of b
return _mm_pow_pd(a, b);
}
static inline Vec2d pow(Vec2d const a, double const b) { // pow(a,b) = a to the power of b
return _mm_pow_pd(a, Vec2d(b));
}
static inline Vec4f cbrt(Vec4f const x) { // pow(x,1/3)
return _mm_cbrt_ps(x);
}
static inline Vec2d cbrt(Vec2d const x) { // pow(x,1/3)
return _mm_cbrt_pd(x);
}
// logarithms
static inline Vec4f log(Vec4f const x) { // natural logarithm
return _mm_log_ps(x);
}
static inline Vec2d log(Vec2d const x) { // natural logarithm
return _mm_log_pd(x);
}
static inline Vec4f log1p(Vec4f const x) { // log(1+x). Avoids loss of precision if 1+x is close to 1
return _mm_log1p_ps(x);
}
static inline Vec2d log1p(Vec2d const x) { // log(1+x). Avoids loss of precision if 1+x is close to 1
return _mm_log1p_pd(x);
}
static inline Vec4f log2(Vec4f const x) { // logarithm base 2
return _mm_log2_ps(x);
}
static inline Vec2d log2(Vec2d const x) { // logarithm base 2
return _mm_log2_pd(x);
}
static inline Vec4f log10(Vec4f const x) { // logarithm base 10
return _mm_log10_ps(x);
}
static inline Vec2d log10(Vec2d const x) { // logarithm base 10
return _mm_log10_pd(x);
}
// trigonometric functions
static inline Vec4f sin(Vec4f const x) { // sine
return _mm_sin_ps(x);
}
static inline Vec2d sin(Vec2d const x) { // sine
return _mm_sin_pd(x);
}
static inline Vec4f cos(Vec4f const x) { // cosine
return _mm_cos_ps(x);
}
static inline Vec2d cos(Vec2d const x) { // cosine
return _mm_cos_pd(x);
}
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 = _mm_sincos_ps(&r_cos, x);
*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 = _mm_sincos_pd(&r_cos, x);
*pcos = r_cos;
return r_sin;
}
static inline Vec4f tan(Vec4f const x) { // tangent
return _mm_tan_ps(x);
}
static inline Vec2d tan(Vec2d const x) { // tangent
return _mm_tan_pd(x);
}
#ifdef TRIGPI_FUNCTIONS
static inline Vec4f sinpi(Vec4f const x) { // sine
return _mm_sinpi_ps(x);
}
static inline Vec2d sinpi(Vec2d const x) { // sine
return _mm_sinpi_pd(x);
}
static inline Vec4f cospi(Vec4f const x) { // cosine
return _mm_cospi_ps(x);
}
static inline Vec2d cospi(Vec2d const x) { // cosine
return _mm_cospi_pd(x);
}
static inline Vec4f tanpi(Vec4f const x) { // tangent
return _mm_tanpi_ps(x);
}
static inline Vec2d tanpi(Vec2d const x) { // tangent
return _mm_tanpi_pd(x);
}
#endif // TRIGPI_FUNCTIONS
// inverse trigonometric functions
static inline Vec4f asin(Vec4f const x) { // inverse sine
return _mm_asin_ps(x);
}
static inline Vec2d asin(Vec2d const x) { // inverse sine
return _mm_asin_pd(x);
}
static inline Vec4f acos(Vec4f const x) { // inverse cosine
return _mm_acos_ps(x);
}
static inline Vec2d acos(Vec2d const x) { // inverse cosine
return _mm_acos_pd(x);
}
static inline Vec4f atan(Vec4f const x) { // inverse tangent
return _mm_atan_ps(x);
}
static inline Vec2d atan(Vec2d const x) { // inverse tangent
return _mm_atan_pd(x);
}
static inline Vec4f atan2(Vec4f const a, Vec4f const b) { // inverse tangent of a/b
return _mm_atan2_ps(a, b);
}
static inline Vec2d atan2(Vec2d const a, Vec2d const b) { // inverse tangent of a/b
return _mm_atan2_pd(a, b);
}
// hyperbolic functions and inverse hyperbolic functions
static inline Vec4f sinh(Vec4f const x) { // hyperbolic sine
return _mm_sinh_ps(x);
}
static inline Vec2d sinh(Vec2d const x) { // hyperbolic sine
return _mm_sinh_pd(x);
}
static inline Vec4f cosh(Vec4f const x) { // hyperbolic cosine
return _mm_cosh_ps(x);
}
static inline Vec2d cosh(Vec2d const x) { // hyperbolic cosine
return _mm_cosh_pd(x);
}
static inline Vec4f tanh(Vec4f const x) { // hyperbolic tangent
return _mm_tanh_ps(x);
}
static inline Vec2d tanh(Vec2d const x) { // hyperbolic tangent
return _mm_tanh_pd(x);
}
static inline Vec4f asinh(Vec4f const x) { // inverse hyperbolic sine
return _mm_asinh_ps(x);
}
static inline Vec2d asinh(Vec2d const x) { // inverse hyperbolic sine
return _mm_asinh_pd(x);
}
static inline Vec4f acosh(Vec4f const x) { // inverse hyperbolic cosine
return _mm_acosh_ps(x);
}
static inline Vec2d acosh(Vec2d const x) { // inverse hyperbolic cosine
return _mm_acosh_pd(x);
}
static inline Vec4f atanh(Vec4f const x) { // inverse hyperbolic tangent
return _mm_atanh_ps(x);
}
static inline Vec2d atanh(Vec2d const x) { // inverse hyperbolic tangent
return _mm_atanh_pd(x);
}
// error function
static inline Vec4f erf(Vec4f const x) { // error function
return _mm_erf_ps(x);
}
static inline Vec2d erf(Vec2d const x) { // error function
return _mm_erf_pd(x);
}
static inline Vec4f erfc(Vec4f const x) { // error function complement
return _mm_erfc_ps(x);
}
static inline Vec2d erfc(Vec2d const x) { // error function complement
return _mm_erfc_pd(x);
}
static inline Vec4f erfinv(Vec4f const x) { // inverse error function
return _mm_erfinv_ps(x);
}
static inline Vec2d erfinv(Vec2d const x) { // inverse error function
return _mm_erfinv_pd(x);
}
static inline Vec4f cdfnorm(Vec4f const x) { // cumulative normal distribution function
return _mm_cdfnorm_ps(x);
}
static inline Vec2d cdfnorm(Vec2d const x) { // cumulative normal distribution function
return _mm_cdfnorm_pd(x);
}
static inline Vec4f cdfnorminv(Vec4f const x) { // inverse cumulative normal distribution function
return _mm_cdfnorminv_ps(x);
}
static inline Vec2d cdfnorminv(Vec2d const x) { // inverse cumulative normal distribution function
return _mm_cdfnorminv_pd(x);
}
#else
/*************************************************************************************
*
* 128-bit vector functions using other compiler than Intel C++ compiler "Classic"
*
*************************************************************************************/
#if (defined(_WIN64) && !defined(USE_SVML_INTRINSICS) )
// (call with one parameter may work without __vectorcall because the parameter happens to be in zmm0, but that would be unsafe)
#define V_VECTORCALL __vectorcall // fix calling convention, one parameter.
#define V_VECTORCALL2 __vectorcall // fix calling convention, two parameters or two returns
#else
#define V_VECTORCALL
#define V_VECTORCALL2
#endif
// External function prototypes for SVML library, 128-bit vectors
extern "C" {
extern __m128 V_VECTORCALL __svml_expf4 (__m128);
extern __m128d V_VECTORCALL __svml_exp2 (__m128d);
extern __m128 V_VECTORCALL __svml_expm1f4 (__m128);
extern __m128d V_VECTORCALL __svml_expm12 (__m128d);
extern __m128 V_VECTORCALL __svml_exp2f4 (__m128);
extern __m128d V_VECTORCALL __svml_exp22 (__m128d);
extern __m128 V_VECTORCALL __svml_exp10f4 (__m128);
extern __m128d V_VECTORCALL __svml_exp102 (__m128d);
extern __m128 V_VECTORCALL2 __svml_powf4 (__m128, __m128);
extern __m128d V_VECTORCALL2 __svml_pow2 (__m128d, __m128d);
extern __m128 V_VECTORCALL __svml_cbrtf4 (__m128);
extern __m128d V_VECTORCALL __svml_cbrt2 (__m128d);
extern __m128 V_VECTORCALL __svml_invsqrtf4 (__m128);
extern __m128d V_VECTORCALL __svml_invsqrt2 (__m128d);
extern __m128 V_VECTORCALL __svml_logf4 (__m128);
extern __m128d V_VECTORCALL __svml_log2 (__m128d);
extern __m128 V_VECTORCALL __svml_log1pf4 (__m128);
extern __m128d V_VECTORCALL __svml_log1p2 (__m128d);
extern __m128 V_VECTORCALL __svml_log2f4 (__m128);
extern __m128d V_VECTORCALL __svml_log22 (__m128d);
extern __m128 V_VECTORCALL __svml_log10f4 (__m128);
extern __m128d V_VECTORCALL __svml_log102 (__m128d);
extern __m128 V_VECTORCALL __svml_sinf4 (__m128);
extern __m128d V_VECTORCALL __svml_sin2 (__m128d);
extern __m128 V_VECTORCALL __svml_cosf4 (__m128);
extern __m128d V_VECTORCALL __svml_cos2 (__m128d);
extern __m128 V_VECTORCALL2 __svml_sincosf4 (__m128); // cos returned in xmm1
extern __m128d V_VECTORCALL2 __svml_sincos2 (__m128d); // cos returned in xmm1
extern __m128 V_VECTORCALL __svml_tanf4 (__m128);
extern __m128d V_VECTORCALL __svml_tan2 (__m128d);
extern __m128 V_VECTORCALL __svml_sinpif4 (__m128);
extern __m128d V_VECTORCALL __svml_sinpi2 (__m128d);
extern __m128 V_VECTORCALL __svml_cospif4 (__m128);
extern __m128d V_VECTORCALL __svml_cospi2 (__m128d);
//extern __m128 V_VECTORCALL2 __svml_sincospif4 (__m128); // not in library
//extern __m128d V_VECTORCALL2 __svml_sincospi2 (__m128d);// not in library
extern __m128 V_VECTORCALL __svml_tanpif4 (__m128);
extern __m128d V_VECTORCALL __svml_tanpi2 (__m128d);
extern __m128 V_VECTORCALL __svml_asinf4 (__m128);
extern __m128d V_VECTORCALL __svml_asin2 (__m128d);
extern __m128 V_VECTORCALL __svml_acosf4 (__m128);
extern __m128d V_VECTORCALL __svml_acos2 (__m128d);
extern __m128 V_VECTORCALL __svml_atanf4 (__m128);
extern __m128d V_VECTORCALL __svml_atan2 (__m128d);
extern __m128 V_VECTORCALL2 __svml_atan2f4 (__m128, __m128);
extern __m128d V_VECTORCALL2 __svml_atan22 (__m128d, __m128d);
extern __m128 V_VECTORCALL __svml_sinhf4 (__m128);
extern __m128d V_VECTORCALL __svml_sinh2 (__m128d);
extern __m128 V_VECTORCALL __svml_coshf4 (__m128);
extern __m128d V_VECTORCALL __svml_cosh2 (__m128d);
extern __m128 V_VECTORCALL __svml_tanhf4 (__m128);
extern __m128d V_VECTORCALL __svml_tanh2 (__m128d);
extern __m128 V_VECTORCALL __svml_asinhf4 (__m128);
extern __m128d V_VECTORCALL __svml_asinh2 (__m128d);
extern __m128 V_VECTORCALL __svml_acoshf4 (__m128);
extern __m128d V_VECTORCALL __svml_acosh2 (__m128d);
extern __m128 V_VECTORCALL __svml_atanhf4 (__m128);
extern __m128d V_VECTORCALL __svml_atanh2 (__m128d);
extern __m128 V_VECTORCALL __svml_erff4 (__m128);
extern __m128d V_VECTORCALL __svml_erf2 (__m128d);
extern __m128 V_VECTORCALL __svml_erfcf4 (__m128);
extern __m128d V_VECTORCALL __svml_erfc2 (__m128d);
extern __m128 V_VECTORCALL __svml_erfinvf4 (__m128);
extern __m128d V_VECTORCALL __svml_erfinv2 (__m128d);
extern __m128 V_VECTORCALL __svml_cdfnormf4 (__m128);
extern __m128d V_VECTORCALL __svml_cdfnorm2 (__m128d);
extern __m128 V_VECTORCALL __svml_cdfnorminvf4(__m128);
extern __m128d V_VECTORCALL __svml_cdfnorminv2 (__m128d);
extern __m128 V_VECTORCALL __svml_cexpf4 (__m128);
extern __m128d V_VECTORCALL __svml_cexp2 (__m128d);
}
/*****************************************************************************
*
* Function definitions
*
*****************************************************************************/
// 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
return __svml_expm1f4(x);
}
static inline Vec2d expm1 (Vec2d const x) { // exp(x)-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 Vec4f pow (Vec4f const a, float const b) { // pow(a,b)
return __svml_powf4(a,Vec4f(b));
}
static inline Vec2d pow (Vec2d const a, Vec2d const b) { // pow(a,b)
return __svml_pow2(a,b);
}
static inline Vec2d pow (Vec2d const a, double const b) { // pow(a,b)
return __svml_pow2(a,Vec2d(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)
return __svml_log1pf4(x);
}
static inline Vec2d log1p (Vec2d const x) { // log(1+x)
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);
}
// sincos function. sin(x) returned, cos(x) in pcos
#ifdef SINCOS_ASM // sincos can be fixed with inline assembly
static inline Vec4f sincos (Vec4f * pcos, Vec4f const x) {
__m128 r_sin, r_cos;
// __asm__ ( "call __svml_sincosf4 \n movaps %%xmm0, %0 \n movaps %%xmm1, %1" : "=m"(r_sin), "=m"(r_cos) : "xmm0"(x) );
r_sin = __svml_sincosf4(x); // fix calling convention in windows and linux using assembly
__asm__ __volatile__ ( "movaps %%xmm1, %0":"=m"(r_cos));
*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);
__asm__ __volatile__ ( "movaps %%xmm1, %0":"=m"(r_cos));
*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);
}
static inline Vec4f sinpi (Vec4f const x) { // sine
return __svml_sinpif4(x);
}
static inline Vec2d sinpi (Vec2d const x) { // sine
return __svml_sinpi2(x);
}
static inline Vec4f cospi (Vec4f const x) { // cosine
return __svml_cospif4(x);
}
static inline Vec2d cospi (Vec2d const x) { // cosine
return __svml_cospi2(x);
}
static inline Vec4f tanpi (Vec4f const x) { // tangent
return __svml_tanpif4(x);
}
static inline Vec2d tanpi (Vec2d const x) { // tangent
return __svml_tanpi2(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);
}
// 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);
}
static inline Vec4f asinh (Vec4f const x) { // inverse hyperbolic sine
return __svml_asinhf4(x);
}
static inline Vec2d asinh (Vec2d const x) { // inverse hyperbolic sine
return __svml_asinh2(x);
}
static inline Vec4f acosh (Vec4f const x) { // inverse hyperbolic cosine
return __svml_acoshf4(x);
}
static inline Vec2d acosh (Vec2d const x) { // inverse hyperbolic cosine
return __svml_acosh2(x);
}
static inline Vec4f atanh (Vec4f const x) { // inverse hyperbolic tangent
return __svml_atanhf4(x);
}
static inline Vec2d atanh (Vec2d const x) { // inverse hyperbolic tangent
return __svml_atanh2(x);
}
// error function
static inline Vec4f erf (Vec4f const x) { // error function
return __svml_erff4(x);
}
static inline Vec2d erf (Vec2d const x) { // error function
return __svml_erf2(x);
}
static inline Vec4f erfc (Vec4f const x) { // error function complement
return __svml_erfcf4(x);
}
static inline Vec2d erfc (Vec2d const x) { // error function complement
return __svml_erfc2(x);
}
static inline Vec4f erfinv (Vec4f const x) { // inverse error function
return __svml_erfinvf4(x);
}
static inline Vec2d erfinv (Vec2d const x) { // inverse error function
return __svml_erfinv2(x);
}
static inline Vec4f cdfnorm (Vec4f const x) { // cumulative normal distribution function
return __svml_cdfnormf4(x);
}
static inline Vec2d cdfnorm (Vec2d const x) { // cumulative normal distribution function
return __svml_cdfnorm2(x);
}
static inline Vec4f cdfnorminv (Vec4f const x) { // inverse cumulative normal distribution function
return __svml_cdfnorminvf4(x);
}
static inline Vec2d cdfnorminv (Vec2d const x) { // inverse cumulative normal distribution function
return __svml_cdfnorminv2(x);
}
#endif // USE_SVML_INTRINSICS
#if defined (MAX_VECTOR_SIZE) && MAX_VECTOR_SIZE >= 256 // 256 bit vectors
#if defined (VECTORF256_H) // 256-bit vector registers supported
#ifdef USE_SVML_INTRINSICS
/*****************************************************************************
*
* 256-bit vector functions using Intel compiler intrinsic functions
*
*****************************************************************************/
// exponential and power functions
static inline Vec8f exp(Vec8f const x) { // exponential function
return _mm256_exp_ps(x);
}
static inline Vec4d exp(Vec4d const x) { // exponential function
return _mm256_exp_pd(x);
}
static inline Vec8f expm1(Vec8f const x) { // exp(x)-1. Avoids loss of precision if x is close to 1
return _mm256_expm1_ps(x);
}
static inline Vec4d expm1(Vec4d const x) { // exp(x)-1. Avoids loss of precision if x is close to 1
return _mm256_expm1_pd(x);
}
static inline Vec8f exp2(Vec8f const x) { // pow(2,x)
return _mm256_exp2_ps(x);
}
static inline Vec4d exp2(Vec4d const x) { // pow(2,x)
return _mm256_exp2_pd(x);
}
static inline Vec8f exp10(Vec8f const x) { // pow(10,x)
return _mm256_exp10_ps(x);
}
static inline Vec4d exp10(Vec4d const x) { // pow(10,x)
return _mm256_exp10_pd(x);
}
static inline Vec8f pow(Vec8f const a, Vec8f const b) { // pow(a,b) = a to the power of b
return _mm256_pow_ps(a, b);
}
static inline Vec8f pow(Vec8f const a, float const b) { // pow(a,b) = a to the power of b
return _mm256_pow_ps(a, Vec8f(b));
}
static inline Vec4d pow(Vec4d const a, Vec4d const b) { // pow(a,b) = a to the power of b
return _mm256_pow_pd(a, b);
}
static inline Vec4d pow(Vec4d const a, double const b) { // pow(a,b) = a to the power of b
return _mm256_pow_pd(a, Vec4d(b));
}
static inline Vec8f cbrt(Vec8f const x) { // pow(x,1/3)
return _mm256_cbrt_ps(x);
}
static inline Vec4d cbrt(Vec4d const x) { // pow(x,1/3)
return _mm256_cbrt_pd(x);
}
// logarithms
static inline Vec8f log(Vec8f const x) { // natural logarithm
return _mm256_log_ps(x);
}
static inline Vec4d log(Vec4d const x) { // natural logarithm
return _mm256_log_pd(x);
}
static inline Vec8f log1p(Vec8f const x) { // log(1+x). Avoids loss of precision if 1+x is close to 1
return _mm256_log1p_ps(x);
}
static inline Vec4d log1p(Vec4d const x) { // log(1+x). Avoids loss of precision if 1+x is close to 1
return _mm256_log1p_pd(x);
}
static inline Vec8f log2(Vec8f const x) { // logarithm base 2
return _mm256_log2_ps(x);
}
static inline Vec4d log2(Vec4d const x) { // logarithm base 2
return _mm256_log2_pd(x);
}
static inline Vec8f log10(Vec8f const x) { // logarithm base 10
return _mm256_log10_ps(x);
}
static inline Vec4d log10(Vec4d const x) { // logarithm base 10
return _mm256_log10_pd(x);
}
// trigonometric functions
static inline Vec8f sin(Vec8f const x) { // sine
return _mm256_sin_ps(x);
}
static inline Vec4d sin(Vec4d const x) { // sine
return _mm256_sin_pd(x);
}
static inline Vec8f cos(Vec8f const x) { // cosine
return _mm256_cos_ps(x);
}
static inline Vec4d cos(Vec4d const x) { // cosine
return _mm256_cos_pd(x);
}
static inline Vec8f sincos(Vec8f * pcos, Vec8f const x) { // sine and cosine. sin(x) returned, cos(x) in pcos
__m256 r_sin, r_cos;
r_sin = _mm256_sincos_ps(&r_cos, x);
*pcos = r_cos;
return r_sin;
}
static inline Vec4d sincos(Vec4d * pcos, Vec4d const x) { // sine and cosine. sin(x) returned, cos(x) in pcos
__m256d r_sin, r_cos;
r_sin = _mm256_sincos_pd(&r_cos, x);
*pcos = r_cos;
return r_sin;
}
static inline Vec8f tan(Vec8f const x) { // tangent
return _mm256_tan_ps(x);
}
static inline Vec4d tan(Vec4d const x) { // tangent
return _mm256_tan_pd(x);
}
#ifdef TRIGPI_FUNCTIONS
static inline Vec8f sinpi(Vec8f const x) { // sine
return _mm256_sinpi_ps(x);
}
static inline Vec4d sinpi(Vec4d const x) { // sine
return _mm256_sinpi_pd(x);
}
static inline Vec8f cospi(Vec8f const x) { // cosine
return _mm256_cospi_ps(x);
}
static inline Vec4d cospi(Vec4d const x) { // cosine
return _mm256_cospi_pd(x);
}
static inline Vec8f tanpi(Vec8f const x) { // tangent
return _mm256_tanpi_ps(x);
}
static inline Vec4d tanpi(Vec4d const x) { // tangent
return _mm256_tanpi_pd(x);
}
#endif // TRIGPI_FUNCTIONS
// inverse trigonometric functions
static inline Vec8f asin(Vec8f const x) { // inverse sine
return _mm256_asin_ps(x);
}
static inline Vec4d asin(Vec4d const x) { // inverse sine
return _mm256_asin_pd(x);
}
static inline Vec8f acos(Vec8f const x) { // inverse cosine
return _mm256_acos_ps(x);
}
static inline Vec4d acos(Vec4d const x) { // inverse cosine
return _mm256_acos_pd(x);
}
static inline Vec8f atan(Vec8f const x) { // inverse tangent
return _mm256_atan_ps(x);
}
static inline Vec4d atan(Vec4d const x) { // inverse tangent
return _mm256_atan_pd(x);
}
static inline Vec8f atan2(Vec8f const a, Vec8f const b) { // inverse tangent of a/b
return _mm256_atan2_ps(a, b);
}
static inline Vec4d atan2(Vec4d const a, Vec4d const b) { // inverse tangent of a/b
return _mm256_atan2_pd(a, b);
}
// hyperbolic functions and inverse hyperbolic functions
static inline Vec8f sinh(Vec8f const x) { // hyperbolic sine
return _mm256_sinh_ps(x);
}
static inline Vec4d sinh(Vec4d const x) { // hyperbolic sine
return _mm256_sinh_pd(x);
}
static inline Vec8f cosh(Vec8f const x) { // hyperbolic cosine
return _mm256_cosh_ps(x);
}
static inline Vec4d cosh(Vec4d const x) { // hyperbolic cosine
return _mm256_cosh_pd(x);
}
static inline Vec8f tanh(Vec8f const x) { // hyperbolic tangent
return _mm256_tanh_ps(x);
}
static inline Vec4d tanh(Vec4d const x) { // hyperbolic tangent
return _mm256_tanh_pd(x);
}
static inline Vec8f asinh(Vec8f const x) { // inverse hyperbolic sine
return _mm256_asinh_ps(x);
}
static inline Vec4d asinh(Vec4d const x) { // inverse hyperbolic sine
return _mm256_asinh_pd(x);
}
static inline Vec8f acosh(Vec8f const x) { // inverse hyperbolic cosine
return _mm256_acosh_ps(x);
}
static inline Vec4d acosh(Vec4d const x) { // inverse hyperbolic cosine
return _mm256_acosh_pd(x);
}
static inline Vec8f atanh(Vec8f const x) { // inverse hyperbolic tangent
return _mm256_atanh_ps(x);
}
static inline Vec4d atanh(Vec4d const x) { // inverse hyperbolic tangent
return _mm256_atanh_pd(x);
}
// error function
static inline Vec8f erf(Vec8f const x) { // error function
return _mm256_erf_ps(x);
}
static inline Vec4d erf(Vec4d const x) { // error function
return _mm256_erf_pd(x);
}
static inline Vec8f erfc(Vec8f const x) { // error function complement
return _mm256_erfc_ps(x);
}
static inline Vec4d erfc(Vec4d const x) { // error function complement
return _mm256_erfc_pd(x);
}
static inline Vec8f erfinv(Vec8f const x) { // inverse error function
return _mm256_erfinv_ps(x);
}
static inline Vec4d erfinv(Vec4d const x) { // inverse error function
return _mm256_erfinv_pd(x);
}
static inline Vec8f cdfnorm(Vec8f const x) { // cumulative normal distribution function
return _mm256_cdfnorm_ps(x);
}
static inline Vec4d cdfnorm(Vec4d const x) { // cumulative normal distribution function
return _mm256_cdfnorm_pd(x);
}
static inline Vec8f cdfnorminv(Vec8f const x) {// inverse cumulative normal distribution function
return _mm256_cdfnorminv_ps(x);
}
static inline Vec4d cdfnorminv(Vec4d const x) {// inverse cumulative normal distribution function
return _mm256_cdfnorminv_pd(x);
}
#else // not USE_SVML_INTRINSICS
/*****************************************************************************
*
* 256-bit vector functions using other compiler than Intel
*
*****************************************************************************/
// External function prototypes for SVML library, 256-bit vectors
extern "C" {
extern __m256 V_VECTORCALL __svml_expf8 (__m256);
extern __m256d V_VECTORCALL __svml_exp4 (__m256d);
extern __m256 V_VECTORCALL __svml_expm1f8 (__m256);
extern __m256d V_VECTORCALL __svml_expm14 (__m256d);
extern __m256 V_VECTORCALL __svml_exp2f8 (__m256);
extern __m256d V_VECTORCALL __svml_exp24 (__m256d);
extern __m256 V_VECTORCALL __svml_exp10f8 (__m256);
extern __m256d V_VECTORCALL __svml_exp104 (__m256d);
extern __m256 V_VECTORCALL2 __svml_powf8 (__m256, __m256);
extern __m256d V_VECTORCALL2 __svml_pow4 (__m256d, __m256d);
extern __m256 V_VECTORCALL __svml_cbrtf8 (__m256);
extern __m256d V_VECTORCALL __svml_cbrt4 (__m256d);
extern __m256 V_VECTORCALL __svml_invsqrtf8 (__m256);
extern __m256d V_VECTORCALL __svml_invsqrt4 (__m256d);
extern __m256 V_VECTORCALL __svml_logf8 (__m256);
extern __m256d V_VECTORCALL __svml_log4 (__m256d);
extern __m256 V_VECTORCALL __svml_log1pf8 (__m256);
extern __m256d V_VECTORCALL __svml_log1p4 (__m256d);
extern __m256 V_VECTORCALL __svml_log2f8 (__m256);
extern __m256d V_VECTORCALL __svml_log24 (__m256d);
extern __m256 V_VECTORCALL __svml_log10f8 (__m256);
extern __m256d V_VECTORCALL __svml_log104 (__m256d);
extern __m256 V_VECTORCALL __svml_sinf8 (__m256);
extern __m256d V_VECTORCALL __svml_sin4 (__m256d);
extern __m256 V_VECTORCALL __svml_cosf8 (__m256);
extern __m256d V_VECTORCALL __svml_cos4 (__m256d);
extern __m256 V_VECTORCALL2 __svml_sincosf8 (__m256); // cos returned in ymm1
extern __m256d V_VECTORCALL2 __svml_sincos4 (__m256d); // cos returned in ymm1
extern __m256 V_VECTORCALL __svml_tanf8 (__m256);
extern __m256d V_VECTORCALL __svml_tan4 (__m256d);
extern __m256 V_VECTORCALL __svml_sinpif8 (__m256);
extern __m256d V_VECTORCALL __svml_sinpi4 (__m256d);
extern __m256 V_VECTORCALL __svml_cospif8 (__m256);
extern __m256d V_VECTORCALL __svml_cospi4 (__m256d);
extern __m256 V_VECTORCALL __svml_tanpif8 (__m256);
extern __m256d V_VECTORCALL __svml_tanpi4 (__m256d);
extern __m256 V_VECTORCALL __svml_asinf8 (__m256);
extern __m256d V_VECTORCALL __svml_asin4 (__m256d);
extern __m256 V_VECTORCALL __svml_acosf8 (__m256);
extern __m256d V_VECTORCALL __svml_acos4 (__m256d);
extern __m256 V_VECTORCALL __svml_atanf8 (__m256);
extern __m256d V_VECTORCALL __svml_atan4 (__m256d);
extern __m256 V_VECTORCALL2 __svml_atan2f8 (__m256, __m256);
extern __m256d V_VECTORCALL2 __svml_atan24 (__m256d, __m256d);
extern __m256 V_VECTORCALL __svml_sinhf8 (__m256);
extern __m256d V_VECTORCALL __svml_sinh4 (__m256d);
extern __m256 V_VECTORCALL __svml_coshf8 (__m256);
extern __m256d V_VECTORCALL __svml_cosh4 (__m256d);
extern __m256 V_VECTORCALL __svml_tanhf8 (__m256);
extern __m256d V_VECTORCALL __svml_tanh4 (__m256d);
extern __m256 V_VECTORCALL __svml_asinhf8 (__m256);
extern __m256d V_VECTORCALL __svml_asinh4 (__m256d);
extern __m256 V_VECTORCALL __svml_acoshf8 (__m256);
extern __m256d V_VECTORCALL __svml_acosh4 (__m256d);
extern __m256 V_VECTORCALL __svml_atanhf8 (__m256);
extern __m256d V_VECTORCALL __svml_atanh4 (__m256d);
extern __m256 V_VECTORCALL __svml_erff8 (__m256);
extern __m256d V_VECTORCALL __svml_erf4 (__m256d);
extern __m256 V_VECTORCALL __svml_erfcf8 (__m256);
extern __m256d V_VECTORCALL __svml_erfc4 (__m256d);
extern __m256 V_VECTORCALL __svml_erfinvf8 (__m256);
extern __m256d V_VECTORCALL __svml_erfinv4 (__m256d);
extern __m256 V_VECTORCALL __svml_cdfnorminvf8(__m256);
extern __m256d V_VECTORCALL __svml_cdfnorminv4 (__m256d);
extern __m256 V_VECTORCALL __svml_cdfnormf8 (__m256);
extern __m256d V_VECTORCALL __svml_cdfnorm4 (__m256d);
//extern __m256 V_VECTORCALL __svml_cexpf8 (__m256);
//extern __m256d V_VECTORCALL __svml_cexp4 (__m256d);
}
// exponential and power functions
static inline Vec8f exp (Vec8f const x) { // exponential function
return __svml_expf8(x);
}
static inline Vec4d exp (Vec4d const x) { // exponential function
return __svml_exp4(x);
}
static inline Vec8f expm1 (Vec8f const x) { // exp(x)-1
return __svml_expm1f8(x);
}
static inline Vec4d expm1 (Vec4d const x) { // exp(x)-1
return __svml_expm14(x);
}
static inline Vec8f exp2 (Vec8f const x) { // pow(2,x)
return __svml_exp2f8(x);
}
static inline Vec4d exp2 (Vec4d const x) { // pow(2,x)
return __svml_exp24(x);
}
static inline Vec8f exp10 (Vec8f const x) { // pow(10,x)
return __svml_exp10f8(x);
}
static inline Vec4d exp10 (Vec4d const x) { // pow(10,x)
return __svml_exp104(x);
}
static inline Vec8f pow (Vec8f const a, Vec8f const b) { // pow(a,b) = a to the power of b
return __svml_powf8(a,b);
}
static inline Vec8f pow (Vec8f const a, float const b) { // pow(a,b)
return __svml_powf8(a,Vec8f(b));
}
static inline Vec4d pow (Vec4d const a, Vec4d const b) { // pow(a,b)
return __svml_pow4(a,b);
}
static inline Vec4d pow (Vec4d const a, double const b) { // pow(a,b)
return __svml_pow4(a,Vec4d(b));
}
static inline Vec8f cbrt (Vec8f const x) { // pow(x,1/3)
return __svml_cbrtf8(x);
}
static inline Vec4d cbrt (Vec4d const x) { // pow(x,1/3)
return __svml_cbrt4(x);
}
// logarithms
static inline Vec8f log (Vec8f const x) { // natural logarithm
return __svml_logf8(x);
}
static inline Vec4d log (Vec4d const x) { // natural logarithm
return __svml_log4(x);