OSDN Git Service

amdfam10
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.target / i386 / sse4a-extract.c
1 /* { dg-do run { target i?86-*-* x86_64-*-* } } */
2 /* { dg-options "-O2 -msse4a" } */
3 #include <ammintrin.h>
4 #include <stdlib.h>
5 #include "../../gcc.dg/i386-cpuid.h"
6
7 static void sse4a_test (void);
8
9 typedef union
10 {
11   long long i[2];
12   __m128i vec;
13 } LI;
14
15 int
16 main ()
17 {  
18   unsigned long cpu_facilities;
19
20   cpu_facilities = i386_extended_cpuid_ecx ();
21
22   /* Run SSE4a test only if host has SSE4a support.  */
23   if ((cpu_facilities & bit_SSE4a))
24     sse4a_test ();
25
26   exit (0);
27 }
28
29 static long long 
30 sse4a_test_extrq (long long in)
31 {
32   __m128i v1, v2;
33   long long index_length, pad;
34   LI v_out;
35   index_length = 0x0000000000000810; 
36   pad = 0x0;
37   v1 = _mm_set_epi64x (pad, in);
38   v2 = _mm_set_epi64x (pad, index_length); 
39   v_out.vec = _mm_extract_si64 (v1, v2);
40   return (v_out.i[0]); 
41 }
42
43 static long long 
44 sse4a_test_extrqi (long long in)
45 {
46   __m128i v1;
47   long long pad =0x0;
48   LI v_out;
49   v1 = _mm_set_epi64x (pad, in);
50   v_out.vec = _mm_extracti_si64 (v1, (unsigned int) 0x10,(unsigned int) 0x08);
51   return (v_out.i[0]);
52 }
53
54 static chk (long long i1, long long i2)
55 {
56   int n_fails =0;
57   if (i1 != i2) 
58     n_fails +=1;
59   return n_fails;
60 }
61
62 long long vals_in[5] =
63   {
64     0x1234567887654321,
65     0x1456782093002490,
66     0x2340909123990390,
67     0x9595959599595999,
68     0x9099038798000029
69   };
70
71 long long vals_out[5] =
72   {
73     0x0000000000006543,
74     0x0000000000000024,
75     0x0000000000009903,
76     0x0000000000005959,
77     0x0000000000000000
78   };
79
80 static void
81 sse4a_test (void)
82 {
83   int i;
84   int fail = 0;
85   long long out;
86
87   for (i = 0; i < 5; i += 1)
88     {
89       out = sse4a_test_extrq (vals_in[i]);
90       fail += chk(out, vals_out[i]);
91
92       out = sse4a_test_extrqi (vals_in[i]);
93       fail += chk(out, vals_out[i]);
94     }
95
96   if (fail != 0)
97     abort ();
98
99   exit (0);
100 }