[testsuite] require sqrt_insn effective target where needed
[official-gcc.git] / gcc / testsuite / gcc.target / powerpc / direct-move.h
blob80874adcea1ae7cd09d5c2d3cc31e091d0b21c47
1 /* Test functions for direct move support. */
3 #include <math.h>
4 #include <string.h>
5 #include <stdlib.h>
6 extern void abort (void);
8 #ifndef VSX_REG_ATTR
9 #define VSX_REG_ATTR "wa"
10 #endif
12 void __attribute__((__noinline__))
13 copy (TYPE *a, TYPE *b)
15 *b = *a;
18 #ifndef NO_GPR
19 void __attribute__((__noinline__))
20 load_gpr (TYPE *a, TYPE *b)
22 TYPE c = *a;
23 __asm__ ("# gpr, reg = %0" : "+b" (c));
24 *b = c;
26 #endif
28 #ifndef NO_FPR
29 void __attribute__((__noinline__))
30 load_fpr (TYPE *a, TYPE *b)
32 TYPE c = *a;
33 __asm__ ("# fpr, reg = %0" : "+d" (c));
34 *b = c;
36 #endif
38 #ifndef NO_ALTIVEC
39 void __attribute__((__noinline__))
40 load_altivec (TYPE *a, TYPE *b)
42 TYPE c = *a;
43 __asm__ ("# altivec, reg = %0" : "+v" (c));
44 *b = c;
46 #endif
48 #ifndef NO_VSX
49 void __attribute__((__noinline__))
50 load_vsx (TYPE *a, TYPE *b)
52 TYPE c = *a;
53 __asm__ ("# vsx, reg = %x0" : "+" VSX_REG_ATTR (c));
54 *b = c;
56 #endif
58 #ifndef NO_GPR_TO_VSX
59 void __attribute__((__noinline__))
60 load_gpr_to_vsx (TYPE *a, TYPE *b)
62 TYPE c = *a;
63 TYPE d;
64 __asm__ ("# gpr, reg = %0" : "+b" (c));
65 d = c;
66 __asm__ ("# vsx, reg = %x0" : "+" VSX_REG_ATTR (d));
67 *b = d;
69 #endif
71 #ifndef NO_VSX_TO_GPR
72 void __attribute__((__noinline__))
73 load_vsx_to_gpr (TYPE *a, TYPE *b)
75 TYPE c = *a;
76 TYPE d;
77 __asm__ ("# vsx, reg = %x0" : "+" VSX_REG_ATTR (c));
78 d = c;
79 __asm__ ("# gpr, reg = %0" : "+b" (d));
80 *b = d;
82 #endif
84 #ifdef DO_MAIN
85 typedef void (fn_type (TYPE *, TYPE *));
87 struct test_struct {
88 fn_type *func;
89 const char *name;
92 const struct test_struct test_functions[] = {
93 { copy, "copy" },
94 #ifndef NO_GPR
95 { load_gpr, "load_gpr" },
96 #endif
97 #ifndef NO_FPR
98 { load_fpr, "load_fpr" },
99 #endif
100 #ifndef NO_ALTIVEC
101 { load_altivec, "load_altivec" },
102 #endif
103 #ifndef NO_VSX
104 { load_vsx, "load_vsx" },
105 #endif
106 #ifndef NO_GPR_TO_VSX
107 { load_gpr_to_vsx, "load_gpr_to_vsx" },
108 #endif
109 #ifndef NO_VSX_TO_GPR
110 { load_vsx_to_gpr, "load_vsx_to_gpr" },
111 #endif
114 /* Test a given value for each of the functions. */
115 void __attribute__((__noinline__))
116 test_value (TYPE a)
118 long i;
120 for (i = 0; i < sizeof (test_functions) / sizeof (test_functions[0]); i++)
122 TYPE b;
124 test_functions[i].func (&a, &b);
125 if (memcmp ((void *)&a, (void *)&b, sizeof (TYPE)) != 0)
126 abort ();
130 /* Main program. */
132 main (void)
134 long i,j;
135 union {
136 TYPE value;
137 unsigned char bytes[sizeof (TYPE)];
138 } u;
140 #if IS_INT
141 TYPE value = (TYPE)-5;
142 for (i = 0; i < 12; i++)
144 test_value (value);
145 value++;
148 for (i = 0; i < 8*sizeof (TYPE); i++)
149 test_value (((TYPE)1) << i);
151 #elif IS_UNS
152 TYPE value = (TYPE)0;
153 for (i = 0; i < 10; i++)
155 test_value (value);
156 test_value (~ value);
157 value++;
160 for (i = 0; i < 8*sizeof (TYPE); i++)
161 test_value (((TYPE)1) << i);
163 #elif IS_FLOAT
164 TYPE value = (TYPE)-5;
165 for (i = 0; i < 12; i++)
167 test_value (value);
168 value++;
171 test_value ((TYPE)3.1415926535);
172 test_value ((TYPE)1.23456);
173 test_value ((TYPE)(-0.0));
174 test_value ((TYPE)NAN);
175 test_value ((TYPE)+INFINITY);
176 test_value ((TYPE)-INFINITY);
177 #else
179 for (j = 0; j < 10; j++)
181 for (i = 0; i < sizeof (TYPE); i++)
182 u.bytes[i] = (unsigned char) (rand () >> 4);
184 test_value (u.value);
186 #endif
188 return 0;
190 #endif