-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmm_math.c
95 lines (95 loc) · 2.07 KB
/
mm_math.c
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
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <immintrin.h>
#include <utils.h>
#include "dSFMT.h"
#include "mm_math.h"
extern dsfmt_t dsfmt;
void boundary(__m128d *r,__m128d box){
__m128d t=_mm_div_pd(*r,box);
t=_mm_round_pd(t,0x1);
t=_mm_mul_pd(t,box);
*r=_mm_sub_pd(*r,t);
}
__m128d _mm_dist(__m128d p,__m128d q,__m128d b){
__m128d x,y;
y=_mm_sub_pd(p,q);
x=_mm_div_pd(y,b);
x=_mm_round_pd(x,0x0);
x=_mm_mul_pd(x,b);
x=_mm_sub_pd(x,y);
return x;
}
double dist(__m128d p,__m128d q,__m128d b){
__m128d x,y;
y=_mm_sub_pd(p,q);
x=_mm_div_pd(y,b);
x=_mm_round_pd(x,0x0);
x=_mm_mul_pd(x,b);
x=_mm_sub_pd(x,y);
x=_mm_dp_pd(x,x,0xFF);
return _mm_cvtsd_f64(x);
}
__m128d _mm_dist_uy(__m128d p,__m128d q,__m128d b,double uy){
__m128d x,y;
y=_mm_sub_pd(p,q);
x=_mm_div_pd(y,b);
x=_mm_round_pd(x,0x0);
x=_mm_mul_pd(x,b);
x=_mm_sub_pd(x,y);
x[0]+=x[1]*uy;
return x;
}
double dist_uy(__m128d p,__m128d q,__m128d b,double uy){
__m128d x,y;
y=_mm_sub_pd(p,q);
x=_mm_div_pd(y,b);
x=_mm_round_pd(x,0x0);
x=_mm_mul_pd(x,b);
x=_mm_sub_pd(x,y);
x=_mm_dp_pd(x,x,0xFF);
x[0]+=x[1]*uy;
return _mm_cvtsd_f64(x);
}
double length2(__m128d x){
x=_mm_dp_pd(x,x,0xFF);
return _mm_cvtsd_f64(x);
}
double length(__m128d x){
x=_mm_dp_pd(x,x,0xFF);
return sqrt(_mm_cvtsd_f64(x));
}
double dot(__m128d a,__m128d b){
__m128d c=_mm_dp_pd(a,b,0x31);
return _mm_cvtsd_f64(c);
}
__m128d normalize(__m128d a){
double n=length(a);
return a/n;
}
double *init_dexp(double e){
int i,j;
double *dexp=alloc(2*NDEXP*sizeof(double));
for(i=-NDEXP,j=0;i<NDEXP;i++,j++)*(dexp+j)=exp(i*e);
return dexp;
}
__m128d rnd11(){
__m128d b={dsfmt_genrand_open_open(&dsfmt),dsfmt_genrand_open_open(&dsfmt)};
return b;
}
__m128d sincosa(double a){
__m128d b={sin(a),cos(a)};
return b;
}
__m128d rot22(__m128d a,__m128d b01){
__m128d b10={-b01[1],b01[0]};
return _mm_set1_pd(a[1])*b01-_mm_set1_pd(a[0])*b10;
}
__m128d rot2w(__m128d a,double w){
__m128d b={-sin(w),cos(w)};
return normalize(rot22(a,b));
}
unsigned int rndn(unsigned int n){
return (unsigned)(dsfmt_genrand_open_open(&dsfmt)*n);
}