aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.target/powerpc/vec-splati-runnable.c
blob: 6c01666b6257b897e8a8480c4c76694977e5061a (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
/* { dg-do run { target { power10_hw } } } */
/* { dg-do link { target { ! power10_hw } } } */
/* { dg-require-effective-target power10_ok } */
/* { dg-options "-mdejagnu-cpu=power10 -save-temps -O2" } */
#include <altivec.h>

#define DEBUG 0

#if DEBUG
#include <stdio.h>
#endif

extern void abort (void);

volatile vector double vresult_d_undefined;

int
main (int argc, char *argv [])
{
  int i;
  vector int vsrc_a_int;
  vector int vresult_int;
  vector int expected_vresult_int;
  int src_a_int = 13;

  vector unsigned int vsrc_a_uint;
  vector unsigned int vresult_uint;
  vector unsigned int expected_vresult_uint;
  unsigned int src_a_uint = 7;

  vector float vresult_f;
  vector float expected_vresult_f;
  vector float vsrc_a_f;
  float src_a_f = 23.0;

  vector double vsrc_a_d;
  vector double vresult_d;
  vector double expected_vresult_d;
 
  /* Vector splati word */
  vresult_int = (vector signed int) { 1, 2, 3, 4 };
  expected_vresult_int = (vector signed int) { -13, -13, -13, -13 }; 
						 
  vresult_int = vec_splati ( -13 );

  if (!vec_all_eq (vresult_int,  expected_vresult_int)) {
#if DEBUG
    printf("ERROR, vec_splati (src_a_int)\n");
    for(i = 0; i < 4; i++)
      printf(" vresult_int[%d] = %d, expected_vresult_int[%d] = %d\n",
	     i, vresult_int[i], i, expected_vresult_int[i]);
#else
    abort();
#endif
  }

  vresult_f = (vector float) { 1.0, 2.0, 3.0, 4.0 };
  expected_vresult_f = (vector float) { 23.0, 23.0, 23.0, 23.0 };
						 
  vresult_f = vec_splati (23.0f);

  if (!vec_all_eq (vresult_f,  expected_vresult_f)) {
#if DEBUG
    printf("ERROR, vec_splati (src_a_f)\n");
    for(i = 0; i < 4; i++)
      printf(" vresult_f[%d] = %f, expected_vresult_f[%d] = %f\n",
	     i, vresult_f[i], i, expected_vresult_f[i]);
#else
    abort();
#endif
  }

  /* Vector splati double */
  vresult_d = (vector double) { 2.0, 3.0 };
  expected_vresult_d = (vector double) { -31.0, -31.0 };
						 
  vresult_d = vec_splatid (-31.0f);

  if (!vec_all_eq (vresult_d,  expected_vresult_d)) {
#if DEBUG
    printf("ERROR, vec_splati (-31.0f)\n");
    for(i = 0; i < 2; i++)
      printf(" vresult_d[%i] = %f, expected_vresult_d[%i] = %f\n",
	     i, vresult_d[i], i, expected_vresult_d[i]);
#else
    abort();
#endif
  }

  /* This test will generate a "note" to the user that the argument is
     subnormal.  It is not an error, but results are not defined.  Because this
     is undefined, we cannot check that any value is correct.  Just store it in
     a volatile variable so the XXSPLTIDP instruction gets generated and the
     warning message printed. */
  vresult_d_undefined = vec_splatid (6.6E-42f);

  /* Vector splat immediate */
  vsrc_a_int = (vector int) { 2, 3, 4, 5 };
  vresult_int = (vector int) { 1, 1, 1, 1 };
  expected_vresult_int = (vector int) { 2, 20, 4, 20 };
						 
  vresult_int = vec_splati_ins (vsrc_a_int, 1, 20);

  if (!vec_all_eq (vresult_int,  expected_vresult_int)) {
#if DEBUG
    printf("ERROR, vec_splati_ins (vsrc_a_int, 1, 20)\n");
    for(i = 0; i < 4; i++)
      printf(" vresult_int[%i] = %d, expected_vresult_int[%i] = %d\n",
	     i, vresult_int[i], i, expected_vresult_int[i]);
#else
    abort();
#endif
  }
  
  vsrc_a_uint = (vector unsigned int) { 4, 5, 6, 7 };
  vresult_uint = (vector unsigned int) { 1, 1, 1, 1 };
  expected_vresult_uint = (vector unsigned int) { 4, 40, 6, 40 };
						 
  vresult_uint = vec_splati_ins (vsrc_a_uint, 1, 40);

  if (!vec_all_eq (vresult_uint,  expected_vresult_uint)) {
#if DEBUG
    printf("ERROR, vec_splati_ins (vsrc_a_uint, 1, 40)\n");
    for(i = 0; i < 4; i++)
      printf(" vresult_uint[%i] = %d, expected_vresult_uint[%i] = %d\n",
	     i, vresult_uint[i], i, expected_vresult_uint[i]);
#else
    abort();
#endif
  }
  
  vsrc_a_f = (vector float) { 2.0, 3.0, 4.0, 5.0 };
  vresult_f = (vector float) { 1.0, 1.0, 1.0, 1.0 };
  expected_vresult_f = (vector float) { 2.0, 20.1, 4.0, 20.1 };
						 
  vresult_f = vec_splati_ins (vsrc_a_f, 1, 20.1f);

  if (!vec_all_eq (vresult_f,  expected_vresult_f)) {
#if DEBUG
    printf("ERROR, vec_splati_ins (vsrc_a_f, 1, 20.1)\n");
    for(i = 0; i < 4; i++)
      printf(" vresult_f[%i] = %f, expected_vresult_f[%i] = %f\n",
	     i, vresult_f[i], i, expected_vresult_f[i]);
#else
    abort();
#endif
  }

  return 0;
}

/* { dg-final { scan-assembler-times {\mxxspltiw\M} 3 } } */
/* { dg-final { scan-assembler-times {\mxxspltidp\M} 3 } } */
/* { dg-final { scan-assembler-times {\mxxsplti32dx\M} 3 } } */