1 /* { dg-do run } */
2 /* { dg-require-effective-target sse3 } */
3 /* { dg-options "-O2 -msse3 -mfpmath=sse" } */
4 
5 #ifndef CHECK_H
6 #define CHECK_H "sse3-check.h"
7 #endif
8 
9 #ifndef TEST
10 #define TEST sse3_test
11 #endif
12 
13 #include CHECK_H
14 #include <pmmintrin.h>
15 
16 static void
sse3_test_hsubpd(double * i1,double * i2,double * r)17 sse3_test_hsubpd (double *i1, double *i2, double *r)
18 {
19   __m128d t1 = _mm_loadu_pd (i1);
20   __m128d t2 = _mm_loadu_pd (i2);
21 
22   t1 = _mm_hsub_pd (t1, t2);
23 
24   _mm_storeu_pd (r, t1);
25 }
26 
27 static void
sse3_test_hsubpd_subsume(double * i1,double * i2,double * r)28 sse3_test_hsubpd_subsume (double *i1, double *i2, double *r)
29 {
30   __m128d t1 = _mm_load_pd (i1);
31   __m128d t2 = _mm_load_pd (i2);
32 
33   t1 = _mm_hsub_pd (t1, t2);
34 
35   _mm_storeu_pd (r, t1);
36 }
37 
38 static int
chk_pd(double * v1,double * v2)39 chk_pd (double *v1, double *v2)
40 {
41   int i;
42   int n_fails = 0;
43 
44   for (i = 0; i < 2; i++)
45     if (v1[i] != v2[i])
46       n_fails += 1;
47 
48   return n_fails;
49 }
50 
51 static double p1[2] __attribute__ ((aligned(16)));
52 static double p2[2] __attribute__ ((aligned(16)));
53 static double p3[2];
54 static double ck[2];
55 
56 static double vals[80] =
57   {
58     100.0,  200.0, 300.0, 400.0, 5.0, -1.0, .345, -21.5,
59     1100.0, 0.235, 321.3, 53.40, 0.3, 10.0, 42.0, 32.52,
60     32.6,   123.3, 1.234, 2.156, 0.1, 3.25, 4.75, 32.44,
61     12.16,  52.34, 64.12, 71.13, -.1, 2.30, 5.12, 3.785,
62     541.3,  321.4, 231.4, 531.4, 71., 321., 231., -531.,
63     23.45,  23.45, 23.45, 23.45, 23.45, 23.45, 23.45, 23.45,
64     23.45,  -1.43, -6.74, 6.345, -20.1, -20.1, -40.1, -40.1,
65     1.234,  2.345, 3.456, 4.567, 5.678, 6.789, 7.891, 8.912,
66     -9.32,  -8.41, -7.50, -6.59, -5.68, -4.77, -3.86, -2.95,
67     9.32,  8.41, 7.50, 6.59, -5.68, -4.77, -3.86, -2.95
68   };
69 
70 static void
TEST(void)71 TEST (void)
72 {
73   int i;
74   int fail = 0;
75 
76   for (i = 0; i < 80; i += 4)
77     {
78       p1[0] = vals[i+0];
79       p1[1] = vals[i+1];
80 
81       p2[0] = vals[i+2];
82       p2[1] = vals[i+3];
83 
84       ck[0] = p1[0] - p1[1];
85       ck[1] = p2[0] - p2[1];
86 
87       sse3_test_hsubpd (p1, p2, p3);
88 
89       fail += chk_pd (ck, p3);
90 
91       sse3_test_hsubpd_subsume (p1, p2, p3);
92 
93       fail += chk_pd (ck, p3);
94     }
95 
96   if (fail != 0)
97     abort ();
98 }
99