OSDN Git Service

Support AVX for cmpss/cmpsd.
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.target / i386 / sse-7.c
1 /* { dg-do run } */
2 /* { dg-options "-O2 -msse" } */
3
4 #include "sse-check.h"
5
6 #include <xmmintrin.h>
7 #include <string.h>
8
9 #define SHIFT (4)
10
11 typedef union {
12   __m64 v;
13   unsigned char c[8];
14   unsigned short int s[4];
15   unsigned long long t;
16   unsigned int u[2];
17 }vecInWord;
18
19 void sse_tests (void) __attribute__((noinline));
20 void dump64_16 (char *, char *, vecInWord);
21 int check (const char *, const char *[]);
22
23 char buf[8000];
24 char comparison[8000];
25 static int errors = 0;
26
27 vecInWord c64, e64;
28 __m64 m64_64;
29
30 const char *reference_sse[] = {
31   "_mm_shuffle_pi16 0123 4567 89ab cdef \n",
32   ""
33 };
34
35 static void
36 sse_test (void)
37 {
38   e64.t  = 0x0123456789abcdefULL;
39
40   m64_64 = e64.v;
41
42   sse_tests();
43   check (buf, reference_sse);
44 #ifdef DEBUG
45   printf ("sse testing:\n");
46   printf (buf);
47   printf ("\ncomparison:\n");
48   printf (comparison);
49 #endif
50   buf[0] = '\0';
51
52   if (errors != 0)
53     abort ();
54 }
55
56 void __attribute__((noinline))
57 sse_tests (void)
58 {
59   /* pshufw */
60   c64.v = _mm_shuffle_pi16 (m64_64, 0x1b);
61   dump64_16 (buf, "_mm_shuffle_pi16", c64);
62 }
63
64 void
65 dump64_16 (char *buf, char *name, vecInWord x)
66 {
67   int i;
68   char *p = buf + strlen (buf);
69
70   sprintf (p, "%s ", name);
71   p += strlen (p);
72
73   for (i=0; i<4; i++)
74     {
75       sprintf (p, "%4.4x ", x.s[i]);
76       p += strlen (p);
77     }
78   strcat (p, "\n");
79 }
80
81 int
82 check (const char *input, const char *reference[])
83 {
84   int broken, i, j, len;
85   const char *p_input;
86   char *p_comparison;
87   int new_errors = 0;
88
89   p_comparison = &comparison[0];
90   p_input = input;
91
92   for (i = 0; *reference[i] != '\0'; i++)
93     {
94       broken = 0;
95       len = strlen (reference[i]);
96       for (j = 0; j < len; j++)
97         {
98           /* Ignore the terminating NUL characters at the end of every string in 'reference[]'.  */
99           if (!broken && *p_input != reference[i][j])
100             {
101               *p_comparison = '\0';
102               strcat (p_comparison, " >>> ");
103               p_comparison += strlen (p_comparison);
104               new_errors++;
105               broken = 1;
106             }
107           *p_comparison = *p_input;
108           p_comparison++;
109           p_input++;
110         }
111       if (broken)
112         {
113           *p_comparison = '\0';
114           strcat (p_comparison, "expected:\n");
115           strcat (p_comparison, reference[i]);
116           p_comparison += strlen (p_comparison);
117         }
118     }
119   *p_comparison = '\0';
120   strcat (p_comparison, new_errors ? "failure\n\n" : "O.K.\n\n") ;
121   errors += new_errors;
122   return 0;
123 }