Bug 497723 - forgot to restore callgrind output cleanup
[valgrind.git] / none / tests / ppc64 / test_mod_instructions.c
blobff5d55285f0ebb1292b0a6899f4770f473cf3c9b
1 #include <stdio.h>
3 #ifdef HAS_ISA_3_00
4 long test_modsd( long srcA, long srcB)
6 long dst;
7 __asm__ __volatile__ ("modsd %0,%1,%2" : "=r" (dst): "r" (srcA), "r" (srcB));
9 return dst;
12 unsigned long test_modud( unsigned long srcA, unsigned long srcB)
14 unsigned long dst;
15 __asm__ __volatile__ ("modud %0,%1,%2" : "=r" (dst): "r" (srcA), "r" (srcB));
17 return dst;
20 int test_modsw( int srcA, int srcB)
22 int dst;
23 __asm__ __volatile__ ("modsw %0,%1,%2" : "=r" (dst): "r" (srcA), "r" (srcB));
25 return dst;
28 unsigned test_moduw( unsigned srcA, unsigned srcB)
30 unsigned dst;
31 __asm__ __volatile__ ("moduw %0,%1,%2" : "=r" (dst): "r" (srcA), "r" (srcB));
33 return dst;
35 #endif
37 int main()
39 #ifdef HAS_ISA_3_00
40 int srcA_si, srcB_si, dst_si;
41 unsigned int srcA_ui, srcB_ui, dst_ui;
42 long srcA_sl, srcB_sl, dst_sl;
43 unsigned long srcA_ul, srcB_ul, dst_ul;
44 int i_si, j_si;
45 long int i_sl, j_sl;
46 int i_ui, j_ui;
47 long int i_ul, j_ul;
49 #define SI_NEGATIVE_START 0x80000000
50 #define SI_NEGATIVE_STOP 0x80000008
51 #define SI_POSITIVE_START 0x7FFFFFF8
52 #define SI_POSITIVE_STOP 0x7FFFFFFF
53 #define SI_ZERO_START -5
54 #define SI_ZERO_STOP 5
56 #define DI_NEGATIVE_START 0x8000000000000000LL
57 #define DI_NEGATIVE_STOP 0x8000000000000008LL
58 #define DI_POSITIVE_START 0x7FFFFFFFFFFFFFF8LL
59 #define DI_POSITIVE_STOP 0x7FFFFFFFFFFFFFFFLL
60 #define DI_ZERO_START -5
61 #define DI_ZERO_STOP 5
63 #define UI_START 0xFFFFFFF8
64 #define UI_STOP 0xFFFFFFFF
65 #define UI_ZERO_START 0
66 #define UI_ZERO_STOP 10
68 #define UL_START 0xFFFFFFFFFFFFFFF8ULL
69 #define UL_STOP 0xFFFFFFFFFFFFFFFFULL
70 #define UL_ZERO_START 0
71 #define UL_ZERO_STOP 10
73 /* Signed tests need to check the most negative values,
74 the most positive values and values around zero. */
76 /* Signed integer tests */
77 for (i_si = SI_NEGATIVE_START; i_si < SI_NEGATIVE_STOP; i_si++)
78 for (j_si = SI_NEGATIVE_START; j_si < SI_NEGATIVE_STOP; j_si++)
80 srcA_si = i_si;
81 srcB_si = j_si;
83 dst_si = test_modsw( srcA_si, srcB_si);
84 #ifdef debug
85 printf("srcA_si = %d \n", srcA_si);
86 printf("srcB_si = %d \n", srcB_si);
87 printf ("modsw result = %d\n\n", dst_si);
88 #else
89 printf ("modsw result = %d\n", dst_si);
90 #endif
93 for (i_si = SI_ZERO_START; i_si < SI_ZERO_STOP; i_si++)
94 for (j_si = SI_ZERO_START; j_si < SI_ZERO_STOP; j_si++)
96 srcA_si = i_si;
97 srcB_si = j_si;
99 dst_si = test_modsw( srcA_si, srcB_si);
101 #ifdef debug
102 printf("srcA_si = %d \n", srcA_si);
103 printf("srcB_si = %d \n", srcB_si);
104 printf ("modsw result = %d\n\n", dst_si);
105 #else
106 printf ("modsw result = %d\n", dst_si);
107 #endif
110 for (i_si = SI_POSITIVE_START; i_si < SI_POSITIVE_STOP; i_si++)
111 for (j_si = SI_POSITIVE_START; j_si < SI_POSITIVE_STOP; j_si++)
113 srcA_si = i_si;
114 srcB_si = j_si;
116 dst_si = test_modsw( srcA_si, srcB_si);
118 #ifdef debug
119 printf("srcA_si = %d \n", srcA_si);
120 printf("srcB_si = %d \n", srcB_si);
121 printf ("modsw result = %d\n\n", dst_si);
122 #else
123 printf ("modsw result = %d\n", dst_si);
124 #endif
127 /* Signed long integer tests */
128 for (i_sl = DI_NEGATIVE_START; i_sl < DI_NEGATIVE_STOP; i_sl++)
129 for (j_sl = DI_NEGATIVE_START; j_sl < DI_NEGATIVE_STOP; j_sl++)
131 srcA_sl = i_sl;
132 srcB_sl = j_sl;
134 dst_sl = test_modsd( srcA_sl, srcB_sl);
136 #ifdef debug
137 printf("srcA_sl = %ld \n", srcA_sl);
138 printf("srcB_sl = %ld \n", srcB_sl);
139 printf ("modsd result = %ld\n\n", dst_sl);
140 #else
141 printf ("modsd result = %ld\n", dst_sl);
142 #endif
145 for (i_sl = DI_ZERO_START; i_sl < DI_ZERO_STOP; i_sl++)
146 for (j_sl = DI_ZERO_START; j_sl < DI_ZERO_STOP; j_sl++)
148 srcA_sl = i_sl;
149 srcB_sl = j_sl;
151 dst_sl = test_modsd( srcA_sl, srcB_sl);
153 #ifdef debug
154 printf("srcA_sl = %ld \n", srcA_sl);
155 printf("srcB_sl = %ld \n", srcB_sl);
156 printf ("modsd result = %ld\n\n", dst_sl);
157 #else
158 printf ("modsd result = %ld\n", dst_sl);
159 #endif
162 for (i_sl = DI_POSITIVE_START; i_sl < DI_POSITIVE_STOP; i_sl++)
163 for (j_sl = DI_POSITIVE_START; j_sl < DI_POSITIVE_STOP; j_sl++)
165 srcA_sl = i_sl;
166 srcB_sl = j_sl;
168 dst_sl = test_modsd( srcA_sl, srcB_sl);
170 #ifdef debug
171 printf("srcA_sl = %ld \n", srcA_sl);
172 printf("srcB_sl = %ld \n", srcB_sl);
173 printf ("modsd result = %ld\n\n", dst_sl);
174 #else
175 printf ("modsd result = %ld\n", dst_sl);
176 #endif
179 /* Unsigned tests need to check the most positive values
180 and the values around zero. */
182 /* Unsigned integer tests */
183 for (i_ui = UI_START; i_ui < UI_STOP; i_ui++)
184 for (j_ui = UI_START; j_ui < UI_STOP; j_ui++)
186 srcA_ui = i_ui;
187 srcB_ui = j_ui;
189 dst_ui = test_moduw( srcA_ui, srcB_ui);
191 #ifdef debug
192 printf("srcA_ui = %u \n", srcA_ui);
193 printf("srcB_ui = %u \n", srcB_ui);
194 printf ("moduw result = %u\n\n", dst_ui);
195 #else
196 printf ("moduw result = %u\n", dst_ui);
197 #endif
200 for (i_ui = SI_ZERO_START; i_ui < SI_ZERO_STOP; i_ui++)
201 for (j_ui = SI_ZERO_START; j_ui < SI_ZERO_STOP; j_ui++)
203 srcA_ui = i_ui;
204 srcB_ui = j_ui;
206 dst_ui = test_moduw( srcA_ui, srcB_ui);
208 #ifdef debug
209 printf("srcA_ui = %u \n", srcA_ui);
210 printf("srcB_ui = %u \n", srcB_ui);
211 printf ("moduw result = %u\n", dst_ui);
212 #else
213 printf ("moduw result = %u\n\n", dst_ui);
214 #endif
217 /* Unsigned long integer tests */
218 for (i_ul = UL_START; i_ul < UL_STOP; i_ul++)
219 for (j_ul = UL_START; j_ul < UL_STOP; j_ul++)
221 srcA_ul = i_ul;
222 srcB_ul = j_ul;
224 dst_ul = test_modud( srcA_ul, srcB_ul);
226 #ifdef debug
227 printf("srcA_ul = %lu \n", srcA_ul);
228 printf("srcB_ul = %lu \n", srcB_ul);
229 printf ("modud result = %lu\n\n", dst_ul);
230 #else
231 printf ("modud result = %lu\n", dst_ul);
232 #endif
235 for (i_ul = UL_ZERO_START; i_ul < UL_ZERO_STOP; i_ul++)
236 for (j_ul = UL_ZERO_START; j_ul < UL_ZERO_STOP; j_ul++)
238 srcA_ul = i_ul;
239 srcB_ul = j_ul;
241 dst_ul = test_modud( srcA_ul, srcB_ul);
243 #ifdef debug
244 printf("srcA_ul = %lu \n", srcA_ul);
245 printf("srcB_ul = %lu \n", srcB_ul);
246 printf ("modud result = %lu\n\n", dst_ul);
247 #else
248 printf ("modud result = %lu\n", dst_ul);
249 #endif
251 #else
252 printf("HAS_ISA_3_00 not detected.\n");
253 #endif // HAS_ISA_3_0
254 return 0;