summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/torture/pr44900.C
blob: ad150d7fb96eed7f54294719523fcb5f58899b17 (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
/* { dg-do run { target i?86-*-* x86_64-*-* } } */
/* { dg-options "-msse" } */
/* { dg-require-effective-target sse_runtime } */

typedef float __m128 __attribute__ ((__vector_size__ (16), __may_alias__));
typedef float __v4sf __attribute__ ((__vector_size__ (16)));

extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__,
__artificial__))
_mm_set_ps (const float __Z, const float __Y, const float __X, const float __W)
{
  return __extension__ (__m128)(__v4sf){ __W, __X, __Y, __Z };
}

struct vec
{
        union {
                __m128 v;
                float  e[4];
        };

        static const vec & zero()
        {
                static const vec v = _mm_set_ps(0, 0, 0, 0);
                return v;
        }

        vec() {}
        vec(const __m128 & a) : v(a) {}

        operator const __m128&() const { return v; }
};

struct vec2
{
        vec _v1;
        vec _v2;

        vec2() {}
        vec2(const vec & a, const vec & b) : _v1(a), _v2(b) {}

        static vec2 load(const float * a)
        {
                return vec2(
                        __builtin_ia32_loadups(&a[0]),
                        __builtin_ia32_loadups(&a[4]));
        }

        const vec & v1() const { return _v1; }
        const vec & v2() const { return _v2; }
};

extern "C" void abort(void);


inline bool operator==(const vec & a, const vec & b)
{ return 0xf == __builtin_ia32_movmskps(__builtin_ia32_cmpeqps(a, b)); }

int main( int argc, char * argv[] )
{
        __attribute__((aligned(16))) float data[] =
        { 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5 };

        float * p = &data[2];
        vec2 a;

        a = vec2::load(p);

        vec v1 = a.v1();
        vec v2 = a.v2();

	if (v2.e[3] != 7.0)
	  abort();

        return 0;
}