summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.target/sparc/vec-init-2.inc
blob: 13685a1006e06586b585dcc31cb15acfcc5a205f (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
typedef short __v2hi __attribute__ ((__vector_size__ (4)));
typedef short __v4hi __attribute__ ((__vector_size__ (8)));

extern void abort (void);

static void
compare64 (int n, void *p, unsigned long long val)
{
  unsigned long long *x = (unsigned long long *) p;

  if (*x != val)
    abort();
}

static void
compare32 (int n, void *p, unsigned int val)
{
  unsigned int *x = (unsigned int *) p;
  if (*x != val)
    abort();
}

#define V2HI_TEST(N, elt0, elt1) \
static void \
test_v2hi_##N (unsigned short x, unsigned short y) \
{ \
  __v2hi v = { (elt0), (elt1) }; \
  compare32(N, &v, ((int)(elt0) << 16) | (elt1)); \
}

V2HI_TEST(1, x, y)
V2HI_TEST(2, y, x)
V2HI_TEST(3, x, x)
V2HI_TEST(4, x, 0)
V2HI_TEST(5, 0, x)
V2HI_TEST(6, y, 1)
V2HI_TEST(7, 1, y)
V2HI_TEST(8, 2, 3)
V2HI_TEST(9, 0x400, x)
V2HI_TEST(10, y, 0x8000)

#define V4HI_TEST(N, elt0, elt1, elt2, elt3)	\
static void \
test_v4hi_##N (unsigned short a, unsigned short b, unsigned short c, unsigned short d) \
{ \
  __v4hi v = { (elt0), (elt1), (elt2), (elt3) }; \
  compare64(N, &v, \
            ((long long)(elt0) << 48) | \
	    ((long long)(elt1) << 32) | \
            ((long long)(elt2) << 16) | \
            ((long long)(elt3))); \
}

V4HI_TEST(1, a, a, a, a)
V4HI_TEST(2, a, b, c, d)
V4HI_TEST(3, a, a, b, b)
V4HI_TEST(4, d, c, b, a)
V4HI_TEST(5, a, 0, 0, 0)
V4HI_TEST(6, a, 0, b, 0)
V4HI_TEST(7, c, 5, 5, 5)
V4HI_TEST(8, d, 6, a, 6)
V4HI_TEST(9, 0x200, 0x300, 0x500, 0x8800)
V4HI_TEST(10, 0x600, a, a, a)

unsigned short a16 = 0x3344;
unsigned short b16 = 0x5566;
unsigned short c16 = 0x7788;
unsigned short d16 = 0x9911;

int main(void)
{
  test_v2hi_1 (a16, b16);
  test_v2hi_2 (a16, b16);
  test_v2hi_3 (a16, b16);
  test_v2hi_4 (a16, b16);
  test_v2hi_5 (a16, b16);
  test_v2hi_6 (a16, b16);
  test_v2hi_7 (a16, b16);
  test_v2hi_8 (a16, b16);
  test_v2hi_9 (a16, b16);
  test_v2hi_10 (a16, b16);

  test_v4hi_1 (a16, b16, c16, d16);
  test_v4hi_2 (a16, b16, c16, d16);
  test_v4hi_3 (a16, b16, c16, d16);
  test_v4hi_4 (a16, b16, c16, d16);
  test_v4hi_5 (a16, b16, c16, d16);
  test_v4hi_6 (a16, b16, c16, d16);
  test_v4hi_7 (a16, b16, c16, d16);
  test_v4hi_8 (a16, b16, c16, d16);
  test_v4hi_9 (a16, b16, c16, d16);
  test_v4hi_10 (a16, b16, c16, d16);
  return 0;
}