1 // { dg-do compile }
2 // { dg-additional-options "-ffast-math -fopenmp-simd" }
3 // { dg-additional-options "-msse2" { target x86_64-*-* i?86-*-* } }
4
my_alloc(__SIZE_TYPE__ bytes)5 inline void* my_alloc (__SIZE_TYPE__ bytes) {void *ptr; __builtin_posix_memalign (&ptr, bytes, 128); return 0; }
my_free(void * memory)6 inline void my_free (void* memory) {__builtin_free (memory);}
7
8 template <typename T>
9 class Vec
10 {
11 const int isize;
12 T* data;
13
14 public:
15
Vec(int n)16 Vec (int n) : isize (n) {data = (T*)my_alloc (isize*sizeof (T));}
~Vec()17 ~Vec () {my_free(data);}
18
operator =(const Vec & other)19 Vec& operator = (const Vec& other)
20 {
21 if (this != &other)
22 __builtin_memcpy (data, other.data, isize*sizeof (T));
23 return *this;
24 }
25
operator [](int i)26 T& operator [] (int i) {return data[i];}
operator [](int i) const27 const T& operator [] (int i) const {return data[i];}
at(int i)28 T& at (int i) {return data[i];}
at(int i) const29 const T& at (int i) const {return data[i];}
30
operator T*()31 operator T* () {return data;}
size() const32 int size () const {return isize;}
33 };
34
35 template <typename T>
36 class Cl
37 {
38 public:
39
40 Cl (int n, int m);
41 const int N, M;
42 Vec<T> v_x, v_y;
43 Vec<int> v_i;
44 Vec<float> v_z;
45 };
46
47 struct Ss
48 {
49 const int S_n, S_m;
50 Cl<float> v1;
51 float* C1;
52 float* C2;
SsSs53 Ss (int n1, int n2): S_n(n1), S_m(n2), v1(n1, n2)
54 {
55 C1 = new float[n1 * 3];
56 C2 = new float[n2 * 4];
57 }
58
~SsSs59 ~Ss () { delete C1; delete C2;}
60 void foo (float *in, float w);
61 };
foo(float * in,float w)62 void Ss::foo (float *in, float w)
63 {
64 #pragma omp simd
65 for (int i = 0; i < S_n; i++)
66 {
67 float w1 = C2[S_n + i] * w;
68 v1.v_i[i] += (int)w1;
69 C1[S_n + i] += w1;
70 }
71 }
72
73 // { dg-final { scan-tree-dump "LOOP VECTORIZED" "vect" { xfail *-*-* } } }
74