2014-04-15 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / gcc.target / i386 / sse-7.c
blob30e2c13ba04544ede4b6ef707b81602fac896b68
1 /* { dg-do run } */
2 /* { dg-options "-O2 -msse" } */
3 /* { dg-require-effective-target sse } */
5 #include "sse-check.h"
7 #include <xmmintrin.h>
8 #include <string.h>
10 #define SHIFT (4)
12 typedef union {
13 __m64 v;
14 unsigned char c[8];
15 unsigned short int s[4];
16 unsigned long long t;
17 unsigned int u[2];
18 }vecInWord;
20 void sse_tests (void) __attribute__((noinline));
21 void dump64_16 (char *, char *, vecInWord);
22 int check (const char *, const char *[]);
24 char buf[8000];
25 char comparison[8000];
26 static int errors = 0;
28 vecInWord c64, e64;
29 __m64 m64_64;
31 const char *reference_sse[] = {
32 "_mm_shuffle_pi16 0123 4567 89ab cdef \n",
36 static void
37 sse_test (void)
39 e64.t = 0x0123456789abcdefULL;
41 m64_64 = e64.v;
43 sse_tests();
44 check (buf, reference_sse);
45 #ifdef DEBUG
46 printf ("sse testing:\n");
47 printf (buf);
48 printf ("\ncomparison:\n");
49 printf (comparison);
50 #endif
51 buf[0] = '\0';
53 if (errors != 0)
54 abort ();
57 void __attribute__((noinline))
58 sse_tests (void)
60 /* pshufw */
61 c64.v = _mm_shuffle_pi16 (m64_64, 0x1b);
62 dump64_16 (buf, "_mm_shuffle_pi16", c64);
65 void
66 dump64_16 (char *buf, char *name, vecInWord x)
68 int i;
69 char *p = buf + strlen (buf);
71 sprintf (p, "%s ", name);
72 p += strlen (p);
74 for (i=0; i<4; i++)
76 sprintf (p, "%4.4x ", x.s[i]);
77 p += strlen (p);
79 strcat (p, "\n");
82 int
83 check (const char *input, const char *reference[])
85 int broken, i, j, len;
86 const char *p_input;
87 char *p_comparison;
88 int new_errors = 0;
90 p_comparison = &comparison[0];
91 p_input = input;
93 for (i = 0; *reference[i] != '\0'; i++)
95 broken = 0;
96 len = strlen (reference[i]);
97 for (j = 0; j < len; j++)
99 /* Ignore the terminating NUL characters at the end of every string in 'reference[]'. */
100 if (!broken && *p_input != reference[i][j])
102 *p_comparison = '\0';
103 strcat (p_comparison, " >>> ");
104 p_comparison += strlen (p_comparison);
105 new_errors++;
106 broken = 1;
108 *p_comparison = *p_input;
109 p_comparison++;
110 p_input++;
112 if (broken)
114 *p_comparison = '\0';
115 strcat (p_comparison, "expected:\n");
116 strcat (p_comparison, reference[i]);
117 p_comparison += strlen (p_comparison);
120 *p_comparison = '\0';
121 strcat (p_comparison, new_errors ? "failure\n\n" : "O.K.\n\n") ;
122 errors += new_errors;
123 return 0;