OSDN Git Service

PR rtl-optimization/323
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.target / i386 / sse4_1-phminposuw.c
1 /* { dg-do run } */
2 /* { dg-require-effective-target sse4 } */
3 /* { dg-options "-O2 -msse4.1" } */
4
5 #ifndef CHECK_H
6 #define CHECK_H "sse4_1-check.h"
7 #endif
8
9 #ifndef TEST
10 #define TEST sse4_1_test
11 #endif
12
13 #include CHECK_H
14
15 #include <smmintrin.h>
16
17 #define NUM 64
18
19 static void
20 TEST (void)
21 {
22   union
23     {
24       __m128i x[NUM/8];
25       unsigned short s[NUM];
26     } src;
27   unsigned short minVal[NUM/8];
28   int minInd[NUM/8];
29   unsigned short minValScalar, minIndScalar;
30   int i, j, res;
31
32   for (i = 0; i < NUM; i++)
33     src.s[i] = i * i / (i + i / 3.14 + 1.0);
34
35   for (i = 0, j = 0; i < NUM; i += 8, j++)
36     {
37       res = _mm_cvtsi128_si32 (_mm_minpos_epu16 (src.x [i/8]));
38       minVal[j] = res & 0xffff;
39       minInd[j] = (res >> 16) & 0x3;
40     }
41
42   for (i = 0; i < NUM; i += 8)
43     {
44       minValScalar = src.s[i];
45       minIndScalar = 0;
46
47       for (j = i + 1; j < i + 8; j++)
48         if (minValScalar > src.s[j])
49           {
50             minValScalar = src.s[j];
51             minIndScalar = j - i;
52           }
53
54       if (minValScalar != minVal[i/8] && minIndScalar != minInd[i/8])
55         abort ();
56     }
57 }