OSDN Git Service

2007-05-24 H.J. Lu <hongjiu.lu@intel.com>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.target / i386 / sse4a-insert.c
1 /* { dg-do run { target i?86-*-* x86_64-*-* } } */
2 /* { dg-require-effective-target sse4a } */
3 /* { dg-options "-O2 -msse4a" } */
4 #include <ammintrin.h>
5 #include <stdlib.h>
6 #include "../../gcc.dg/i386-cpuid.h"
7
8 static void sse4a_test (void);
9
10 typedef union
11 {
12   long long i[2];
13   __m128i vec;
14 } LI;
15
16 int
17 main ()
18 {  
19   unsigned long cpu_facilities;
20
21   cpu_facilities = i386_extended_cpuid_ecx ();
22
23   /* Run SSE4a test only if host has SSE4a support.  */
24   if ((cpu_facilities & bit_SSE4a))
25     sse4a_test ();
26
27   exit (0);
28 }
29
30 static long long
31 sse4a_test_insert (long long in1, long long in2)
32 {
33   __m128i v1,v2;
34   long long index_length, pad;
35   LI v_out;
36   index_length = 0x0000000000000810LL;
37   pad = 0x0;
38   v1 = _mm_set_epi64x (pad, in1);
39   v2 = _mm_set_epi64x (index_length, in2); 
40   v_out.vec = _mm_insert_si64 (v1, v2);
41   return (v_out.i[0]);
42 }
43
44 static long long
45 sse4a_test_inserti (long long in1, long long in2)
46 {
47   __m128i v1,v2;
48   long long pad = 0x0;
49   LI v_out;
50   v1 = _mm_set_epi64x (pad, in1);
51   v2 = _mm_set_epi64x (pad, in2); 
52   v_out.vec = _mm_inserti_si64 (v1, v2, (unsigned int) 0x10, (unsigned int) 0x08);
53   return (v_out.i[0]);  
54 }
55
56 static chk (long long i1, long long i2)
57 {
58   int n_fails =0;
59   if (i1 != i2) 
60     n_fails +=1;
61   return n_fails;
62 }
63
64 long long vals_in1[5] =
65   {
66     0x1234567887654321LL,
67     0x1456782093002490LL,
68     0x2340909123990390LL,
69     0x9595959599595999LL,
70     0x9099038798000029LL
71   };
72
73 long long vals_in2[5] =
74   {
75     0x9ABCDEF00FEDCBA9LL,
76     0x234567097289672ALL,
77     0x45476453097BD342LL,
78     0x23569012AE586FF0LL,
79     0x432567ABCDEF765DLL
80   };
81
82 long long vals_out[5] =
83   {
84     0x1234567887CBA921LL,
85     0x1456782093672A90LL,
86     0x2340909123D34290LL,
87     0x95959595996FF099LL,
88     0x9099038798765D29LL
89   };
90
91 static void
92 sse4a_test (void)
93 {
94   int i;
95   int fail = 0;
96   long long out;
97
98   for (i = 0; i < 5; i += 1)
99     {
100       out = sse4a_test_insert (vals_in1[i], vals_in2[i]);
101       fail += chk(out, vals_out[i]);
102
103       out = sse4a_test_inserti (vals_in1[i], vals_in2[i]);
104       fail += chk(out, vals_out[i]);
105     }
106
107   if (fail != 0)
108     abort ();
109
110   exit (0);
111 }