1 /* { dg-do run { target i?86-*-* x86_64-*-* } } */
2 /* { dg-options "-O2 -mmmx" } */
7 #include "../../gcc.dg/i386-cpuid.h"
10 #define NOINLINE __attribute__ ((noinline))
18 unsigned short int s
[4];
23 void mmx_tests (void) NOINLINE
;
24 void dump64_16 (char *, char *, vecInWord
);
25 void dump64_32 (char *, char *, vecInWord
);
26 void dump64_64 (char *, char *, vecInWord
);
27 int check (const char *, const char *[]);
30 char comparison
[8000];
31 static int errors
= 0;
33 vecInWord a64
, b64
, c64
, d64
, e64
;
34 __m64 m64_16
, s64
, m64_32
, m64_64
;
36 const char *reference_mmx
[] = {
37 "_mm_srai_pi16 0012 0012 0012 0012 \n",
38 "_mm_sra_pi16 0012 0012 0012 0012 \n",
39 "_mm_srai_pi32 00123456 00123456 \n",
40 "_mm_sra_pi32 00123456 00123456 \n",
41 "_mm_srli_pi16 0012 0012 0012 0012 \n",
42 "_mm_srl_pi16 0012 0012 0012 0012 \n",
43 "_mm_srli_pi32 00123456 00123456 \n",
44 "_mm_srl_pi32 00123456 00123456 \n",
45 "_mm_srli_si64 00123456789abcde\n",
46 "_mm_srl_si64 00123456789abcde\n",
47 "_mm_slli_pi16 1230 1230 1230 1230 \n",
48 "_mm_sll_pi16 1230 1230 1230 1230 \n",
49 "_mm_slli_pi32 12345670 12345670 \n",
50 "_mm_sll_pi32 12345670 12345670 \n",
51 "_mm_slli_si64 123456789abcdef0\n",
52 "_mm_sll_si64 123456789abcdef0\n",
58 unsigned long cpu_facilities
;
60 cpu_facilities
= i386_cpuid ();
62 if ((cpu_facilities
& bit_MMX
) == 0)
65 d64
.u
[0] = 0x01234567;
66 d64
.u
[1] = 0x01234567;
70 e64
.t
= 0x0123456789abcdefULL
;
88 if (cpu_facilities
& bit_MMX
)
91 check (buf
, reference_mmx
);
93 printf ("mmx testing:\n");
95 printf ("\ncomparison:\n");
110 c64
.v
= _mm_srai_pi16 (m64_16
, SHIFT
);
111 dump64_16 (buf
, "_mm_srai_pi16", c64
);
112 c64
.v
= _mm_sra_pi16 (m64_16
, s64
);
113 dump64_16 (buf
, "_mm_sra_pi16", c64
);
116 c64
.v
= _mm_srai_pi32 (m64_32
, SHIFT
);
117 dump64_32 (buf
, "_mm_srai_pi32", c64
);
118 c64
.v
= _mm_sra_pi32 (m64_32
, s64
);
119 dump64_32 (buf
, "_mm_sra_pi32", c64
);
122 c64
.v
= _mm_srli_pi16 (m64_16
, SHIFT
);
123 dump64_16 (buf
, "_mm_srli_pi16", c64
);
124 c64
.v
= _mm_srl_pi16 (m64_16
, s64
);
125 dump64_16 (buf
, "_mm_srl_pi16", c64
);
128 c64
.v
= _mm_srli_pi32 (m64_32
, SHIFT
);
129 dump64_32 (buf
, "_mm_srli_pi32", c64
);
130 c64
.v
= _mm_srl_pi32 (m64_32
, s64
);
131 dump64_32 (buf
, "_mm_srl_pi32", c64
);
134 c64
.v
= _mm_srli_si64 (m64_64
, SHIFT
);
135 dump64_64 (buf
, "_mm_srli_si64", c64
);
136 c64
.v
= _mm_srl_si64 (m64_64
, s64
);
137 dump64_64 (buf
, "_mm_srl_si64", c64
);
140 c64
.v
= _mm_slli_pi16 (m64_16
, SHIFT
);
141 dump64_16 (buf
, "_mm_slli_pi16", c64
);
142 c64
.v
= _mm_sll_pi16 (m64_16
, s64
);
143 dump64_16 (buf
, "_mm_sll_pi16", c64
);
146 c64
.v
= _mm_slli_pi32 (m64_32
, SHIFT
);
147 dump64_32 (buf
, "_mm_slli_pi32", c64
);
148 c64
.v
= _mm_sll_pi32 (m64_32
, s64
);
149 dump64_32 (buf
, "_mm_sll_pi32", c64
);
152 c64
.v
= _mm_slli_si64 (m64_64
, SHIFT
);
153 dump64_64 (buf
, "_mm_slli_si64", c64
);
154 c64
.v
= _mm_sll_si64 (m64_64
, s64
);
155 dump64_64 (buf
, "_mm_sll_si64", c64
);
159 dump64_16 (char *buf
, char *name
, vecInWord x
)
162 char *p
= buf
+ strlen (buf
);
164 sprintf (p
, "%s ", name
);
169 sprintf (p
, "%4.4x ", x
.s
[i
]);
176 dump64_32 (char *buf
, char *name
, vecInWord x
)
179 char *p
= buf
+ strlen (buf
);
181 sprintf (p
, "%s ", name
);
186 sprintf (p
, "%8.8x ", x
.u
[i
]);
193 dump64_64 (char *buf
, char *name
, vecInWord x
)
195 char *p
= buf
+ strlen (buf
);
197 sprintf (p
, "%s ", name
);
200 sprintf (p
, "%16.16llx\n", x
.t
);
204 check (const char *input
, const char *reference
[])
206 int broken
, i
, j
, len
;
211 p_comparison
= &comparison
[0];
214 for (i
= 0; *reference
[i
] != '\0'; i
++)
217 len
= strlen (reference
[i
]);
218 for (j
= 0; j
< len
; j
++)
220 /* Ignore the terminating NUL characters at the end of every string in 'reference[]'. */
221 if (!broken
&& *p_input
!= reference
[i
][j
])
223 *p_comparison
= '\0';
224 strcat (p_comparison
, " >>> ");
225 p_comparison
+= strlen (p_comparison
);
229 *p_comparison
= *p_input
;
235 *p_comparison
= '\0';
236 strcat (p_comparison
, "expected:\n");
237 strcat (p_comparison
, reference
[i
]);
238 p_comparison
+= strlen (p_comparison
);
241 *p_comparison
= '\0';
242 strcat (p_comparison
, new_errors
? "failure\n\n" : "O.K.\n\n") ;
243 errors
+= new_errors
;