1 /* Test functions for direct move support.  */
2 
3 #include <math.h>
4 #include <string.h>
5 #include <stdlib.h>
6 extern void abort (void);
7 
8 #ifndef VSX_REG_ATTR
9 #define VSX_REG_ATTR "wa"
10 #endif
11 
12 void __attribute__((__noinline__))
copy(TYPE * a,TYPE * b)13 copy (TYPE *a, TYPE *b)
14 {
15   *b = *a;
16 }
17 
18 #ifndef NO_GPR
19 void __attribute__((__noinline__))
load_gpr(TYPE * a,TYPE * b)20 load_gpr (TYPE *a, TYPE *b)
21 {
22   TYPE c = *a;
23   __asm__ ("# gpr, reg = %0" : "+b" (c));
24   *b = c;
25 }
26 #endif
27 
28 #ifndef NO_FPR
29 void __attribute__((__noinline__))
load_fpr(TYPE * a,TYPE * b)30 load_fpr (TYPE *a, TYPE *b)
31 {
32   TYPE c = *a;
33   __asm__ ("# fpr, reg = %0" : "+d" (c));
34   *b = c;
35 }
36 #endif
37 
38 #ifndef NO_ALTIVEC
39 void __attribute__((__noinline__))
load_altivec(TYPE * a,TYPE * b)40 load_altivec (TYPE *a, TYPE *b)
41 {
42   TYPE c = *a;
43   __asm__ ("# altivec, reg = %0" : "+v" (c));
44   *b = c;
45 }
46 #endif
47 
48 #ifndef NO_VSX
49 void __attribute__((__noinline__))
load_vsx(TYPE * a,TYPE * b)50 load_vsx (TYPE *a, TYPE *b)
51 {
52   TYPE c = *a;
53   __asm__ ("# vsx, reg = %x0" : "+" VSX_REG_ATTR (c));
54   *b = c;
55 }
56 #endif
57 
58 #ifndef NO_GPR_TO_VSX
59 void __attribute__((__noinline__))
load_gpr_to_vsx(TYPE * a,TYPE * b)60 load_gpr_to_vsx (TYPE *a, TYPE *b)
61 {
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;
68 }
69 #endif
70 
71 #ifndef NO_VSX_TO_GPR
72 void __attribute__((__noinline__))
load_vsx_to_gpr(TYPE * a,TYPE * b)73 load_vsx_to_gpr (TYPE *a, TYPE *b)
74 {
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;
81 }
82 #endif
83 
84 #ifdef DO_MAIN
85 typedef void (fn_type (TYPE *, TYPE *));
86 
87 struct test_struct {
88   fn_type *func;
89   const char *name;
90 };
91 
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
112 };
113 
114 /* Test a given value for each of the functions.  */
115 void __attribute__((__noinline__))
test_value(TYPE a)116 test_value (TYPE a)
117 {
118   long i;
119 
120   for (i = 0; i < sizeof (test_functions) / sizeof (test_functions[0]); i++)
121     {
122       TYPE b;
123 
124       test_functions[i].func (&a, &b);
125       if (memcmp ((void *)&a, (void *)&b, sizeof (TYPE)) != 0)
126 	abort ();
127     }
128 }
129 
130 /* Main program.  */
131 int
main(void)132 main (void)
133 {
134   long i,j;
135   union {
136     TYPE value;
137     unsigned char bytes[sizeof (TYPE)];
138   } u;
139 
140 #if IS_INT
141   TYPE value = (TYPE)-5;
142   for (i = 0; i < 12; i++)
143     {
144       test_value (value);
145       value++;
146     }
147 
148   for (i = 0; i < 8*sizeof (TYPE); i++)
149     test_value (((TYPE)1) << i);
150 
151 #elif IS_UNS
152   TYPE value = (TYPE)0;
153   for (i = 0; i < 10; i++)
154     {
155       test_value (value);
156       test_value (~ value);
157       value++;
158     }
159 
160   for (i = 0; i < 8*sizeof (TYPE); i++)
161     test_value (((TYPE)1) << i);
162 
163 #elif IS_FLOAT
164   TYPE value = (TYPE)-5;
165   for (i = 0; i < 12; i++)
166     {
167       test_value (value);
168       value++;
169     }
170 
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
178 
179   for (j = 0; j < 10; j++)
180     {
181       for (i = 0; i < sizeof (TYPE); i++)
182 	u.bytes[i] = (unsigned char) (random () >> 4);
183 
184       test_value (u.value);
185     }
186 #endif
187 
188   return 0;
189 }
190 #endif
191