aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/gcc.target/i386/xop-hadduX.c
blob: 9c7ea9a2a6017f84ca221c345b8f986e3136dec3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/* { dg-do run } */
/* { dg-require-effective-target xop } */
/* { dg-options "-O2 -mxop" } */

#include "xop-check.h"

#include <x86intrin.h>
#include <string.h>

#define NUM 10

union
{
  __m128i x[NUM];
  unsigned char  ssi[NUM * 16];
  unsigned short si[NUM * 8];
  unsigned int li[NUM * 4];
  unsigned long long  lli[NUM * 2];
} dst, res, src1;

static void
init_byte ()
{
  int i;
  for (i=0; i < NUM * 16; i++)
    src1.ssi[i] = i;
}

static void
init_word ()
{
  int i;
  for (i=0; i < NUM * 8; i++)
    src1.si[i] = i;
}


static void
init_dword ()
{
  int i;
  for (i=0; i < NUM * 4; i++)
    src1.li[i] = i;
}

static int 
check_byte2word ()
{
  int i, j, s, t, check_fails = 0;
  for (i = 0; i < NUM * 16; i = i + 16)
    {
      for (j = 0; j < 8; j++)
	{
	  t = i + (2 * j);
	  s = (i / 2) + j;
	  res.si[s] = src1.ssi[t] + src1.ssi[t + 1] ;
	  if (res.si[s] != dst.si[s]) 
	    check_fails++;	
	}
    }
}

static int 
check_byte2dword ()
{
  int i, j, s, t, check_fails = 0;
  for (i = 0; i < NUM * 16; i = i + 16)
    {
      for (j = 0; j < 4; j++)
	{
	  t = i + (4 * j);
	  s = (i / 4) + j;
	  res.li[s] = (src1.ssi[t] + src1.ssi[t + 1]) + (src1.ssi[t + 2]
	              + src1.ssi[t + 3]); 
	  if (res.li[s] != dst.li[s]) 
	    check_fails++;
	}
    }
  return check_fails++;
}

static int
check_byte2qword ()
{
  int i, j, s, t, check_fails = 0;
  for (i = 0; i < NUM * 16; i = i + 16)
    {
      for (j = 0; j < 2; j++)
	{
	  t = i + (8 * j);
	  s = (i / 8) + j;
	  res.lli[s] = ((src1.ssi[t] + src1.ssi[t + 1]) + (src1.ssi[t + 2] 
		       + src1.ssi[t + 3])) + ((src1.ssi[t + 4] + src1.ssi[t +5])
	               + (src1.ssi[t + 6] + src1.ssi[t + 7])); 
	  if (res.lli[s] != dst.lli[s]) 
	    check_fails++;
	}
    }
  return check_fails++;
}

static int
check_word2dword ()
{
  int i, j, s, t, check_fails = 0;
  for (i = 0; i < (NUM * 8); i = i + 8)
    {
      for (j = 0; j < 4; j++)
	{
	  t = i + (2 * j);
	  s = (i / 2) + j;
	  res.li[s] = src1.si[t] + src1.si[t + 1] ;
	  if (res.li[s] != dst.li[s]) 
	    check_fails++;	
	}
    }
}

static int 
check_word2qword ()
{
  int i, j, s, t, check_fails = 0;
  for (i = 0; i < NUM * 8; i = i + 8)
    {
      for (j = 0; j < 2; j++)
	{
	  t = i + (4 * j);
	  s = (i / 4) + j;
	  res.lli[s] = (src1.si[t] + src1.si[t + 1]) + (src1.si[t + 2]
	               + src1.si[t + 3]); 
	  if (res.lli[s] != dst.lli[s]) 
	    check_fails++;
	}
    }
  return check_fails++;
}

static int
check_dword2qword ()
{
  int i, j, s, t, check_fails = 0;
  for (i = 0; i < (NUM * 4); i = i + 4)
    {
      for (j = 0; j < 2; j++)
	{
	  t = i + (2 * j);
	  s = (i / 2) + j;
	  res.lli[s] = src1.li[t] + src1.li[t + 1] ;
	  if (res.lli[s] != dst.lli[s]) 
	    check_fails++;	
	}
    }
}

static void
xop_test (void)
{
  int i;
  
  /* Check haddubw */
  init_byte ();
  
  for (i = 0; i < NUM; i++)
    dst.x[i] = _mm_haddw_epu8 (src1.x[i]);
  
  if (check_byte2word())
  abort ();
  
  /* Check haddubd */
  for (i = 0; i < (NUM ); i++)
    dst.x[i] = _mm_haddd_epu8 (src1.x[i]);
  
  if (check_byte2dword())
    abort (); 
  
  /* Check haddubq */
  for (i = 0; i < NUM; i++)
    dst.x[i] = _mm_haddq_epu8 (src1.x[i]);
  
  if (check_byte2qword())
    abort ();

  /* Check hadduwd */
  init_word ();

  for (i = 0; i < (NUM ); i++)
    dst.x[i] = _mm_haddd_epu16 (src1.x[i]);
  
  if (check_word2dword())
    abort (); 
   
  /* Check haddbuwq */
 
  for (i = 0; i < NUM; i++)
    dst.x[i] = _mm_haddq_epu16 (src1.x[i]);
  
  if (check_word2qword())
    abort ();
 
  /* Check hadudq */
  init_dword ();
    for (i = 0; i < NUM; i++)
    dst.x[i] = _mm_haddq_epu32 (src1.x[i]);
  
  if (check_dword2qword())
    abort ();
}