aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/gcc.target/powerpc/direct-move.h
blob: 6a5b7ba18061a6d87fd163bba2a4368c9055ff61 (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
/* Test functions for direct move support.  */

#include <math.h>
extern void abort (void);

#ifndef VSX_REG_ATTR
#define VSX_REG_ATTR "wa"
#endif

void __attribute__((__noinline__))
copy (TYPE *a, TYPE *b)
{
  *b = *a;
}

#ifndef NO_GPR
void __attribute__((__noinline__))
load_gpr (TYPE *a, TYPE *b)
{
  TYPE c = *a;
  __asm__ ("# gpr, reg = %0" : "+b" (c));
  *b = c;
}
#endif

#ifndef NO_FPR
void __attribute__((__noinline__))
load_fpr (TYPE *a, TYPE *b)
{
  TYPE c = *a;
  __asm__ ("# fpr, reg = %0" : "+d" (c));
  *b = c;
}
#endif

#ifndef NO_ALTIVEC
void __attribute__((__noinline__))
load_altivec (TYPE *a, TYPE *b)
{
  TYPE c = *a;
  __asm__ ("# altivec, reg = %0" : "+v" (c));
  *b = c;
}
#endif

#ifndef NO_VSX
void __attribute__((__noinline__))
load_vsx (TYPE *a, TYPE *b)
{
  TYPE c = *a;
  __asm__ ("# vsx, reg = %x0" : "+" VSX_REG_ATTR (c));
  *b = c;
}
#endif

#ifndef NO_GPR_TO_VSX
void __attribute__((__noinline__))
load_gpr_to_vsx (TYPE *a, TYPE *b)
{
  TYPE c = *a;
  TYPE d;
  __asm__ ("# gpr, reg = %0" : "+b" (c));
  d = c;
  __asm__ ("# vsx, reg = %x0" : "+" VSX_REG_ATTR (d));
  *b = d;
}
#endif

#ifndef NO_VSX_TO_GPR
void __attribute__((__noinline__))
load_vsx_to_gpr (TYPE *a, TYPE *b)
{
  TYPE c = *a;
  TYPE d;
  __asm__ ("# vsx, reg = %x0" : "+" VSX_REG_ATTR (c));
  d = c;
  __asm__ ("# gpr, reg = %0" : "+b" (d));
  *b = d;
}
#endif

#ifdef DO_MAIN
typedef void (fn_type (TYPE *, TYPE *));

struct test_struct {
  fn_type *func;
  const char *name;
};

const struct test_struct test_functions[] = {
  { copy,		"copy"		  },
#ifndef NO_GPR
  { load_gpr,		"load_gpr"	  },
#endif
#ifndef NO_FPR
  { load_fpr,		"load_fpr"	  },
#endif
#ifndef NO_ALTIVEC
  { load_altivec,	"load_altivec"	  },
#endif
#ifndef NO_VSX
  { load_vsx,		"load_vsx"	  },
#endif
#ifndef NO_GPR_TO_VSX
  { load_gpr_to_vsx,	"load_gpr_to_vsx" },
#endif
#ifndef NO_VSX_TO_GPR
  { load_vsx_to_gpr,	"load_vsx_to_gpr" },
#endif
};

/* Test a given value for each of the functions.  */
void __attribute__((__noinline__))
test_value (TYPE a)
{
  long i;

  for (i = 0; i < sizeof (test_functions) / sizeof (test_functions[0]); i++)
    {
      TYPE b;

      test_functions[i].func (&a, &b);
      if (memcmp ((void *)&a, (void *)&b, sizeof (TYPE)) != 0)
	abort ();
    }
}

/* Main program.  */
int
main (void)
{
  long i,j;
  union {
    TYPE value;
    unsigned char bytes[sizeof (TYPE)];
  } u;

#if IS_INT
  TYPE value = (TYPE)-5;
  for (i = 0; i < 12; i++)
    {
      test_value (value);
      value++;
    }

  for (i = 0; i < 8*sizeof (TYPE); i++)
    test_value (((TYPE)1) << i);

#elif IS_UNS
  TYPE value = (TYPE)0;
  for (i = 0; i < 10; i++)
    {
      test_value (value);
      test_value (~ value);
      value++;
    }

  for (i = 0; i < 8*sizeof (TYPE); i++)
    test_value (((TYPE)1) << i);

#elif IS_FLOAT
  TYPE value = (TYPE)-5;
  for (i = 0; i < 12; i++)
    {
      test_value (value);
      value++;
    }

  test_value ((TYPE)3.1415926535);
  test_value ((TYPE)1.23456);
  test_value ((TYPE)(-0.0));
  test_value ((TYPE)NAN);
  test_value ((TYPE)+INFINITY);
  test_value ((TYPE)-INFINITY);
#else

  for (j = 0; j < 10; j++)
    {
      for (i = 0; i < sizeof (TYPE); i++)
	u.bytes[i] = (unsigned char) (random () >> 4);

      test_value (u.value);
    }
#endif

  return 0;
}
#endif