7 /* Program that checks all numbers of args (0 through 12) work for
8 wrapping. Also calls originals which trash all the iregs in an
9 attempt to shake out any problems caused by insufficient saving of
10 caller-save registers around the hidden call instruction. */
12 typedef unsigned int UInt
;
14 #define ROL(_x,n) (((_x) << n) | ((UInt)(_x)) >> ((8*sizeof(UInt)-n)))
16 #define TRASH_IREGS(_rlval, _vec) \
18 register UInt* vec = (_vec); \
19 /* x86 spills for v > 4, amd64 for v > 12. Getting ppc */ \
20 /* to spill is quite difficult, requiring v > 28 or so. */ \
21 register UInt i, sum = 0; \
22 register UInt v1 = vec[1-1]; \
23 register UInt v2 = vec[2-1]; \
24 register UInt v3 = vec[3-1]; \
25 register UInt v4 = vec[4-1]; \
26 register UInt v5 = vec[5-1]; \
27 register UInt v6 = vec[6-1]; \
28 register UInt v7 = vec[7-1]; \
29 register UInt v8 = vec[8-1]; \
30 register UInt v9 = vec[9-1]; \
31 register UInt v10 = vec[10-1]; \
32 register UInt v11 = vec[11-1]; \
33 register UInt v12 = vec[12-1]; \
34 register UInt v13 = vec[13-1]; \
35 register UInt v14 = vec[14-1]; \
36 register UInt v15 = vec[15-1]; \
37 register UInt v16 = vec[16-1]; \
38 register UInt v17 = vec[17-1]; \
39 register UInt v18 = vec[18-1]; \
40 register UInt v19 = vec[19-1]; \
41 register UInt v20 = vec[20-1]; \
42 register UInt v21 = vec[21-1]; \
43 register UInt v22 = vec[22-1]; \
44 register UInt v23 = vec[23-1]; \
45 register UInt v24 = vec[24-1]; \
46 register UInt v25 = vec[25-1]; \
47 register UInt v26 = vec[26-1]; \
48 register UInt v27 = vec[27-1]; \
49 register UInt v28 = vec[28-1]; \
50 register UInt v29 = vec[29-1]; \
51 for (i = 0; i < 50; i++) { \
81 sum ^= ((0xFFF & v1) * i); \
115 /* Returns one, in a way that gcc probably can't constant fold out */
117 volatile int one_actual_return_value
= 0; /* the value one() returns */
119 __attribute__((noinline
))
123 for (i
= 0; i
< 7; i
++)
125 a
[3] = 3+one_actual_return_value
;
127 for (i
= 7-1; i
>= 0; i
--)
132 #define LOOPS_START \
133 { register int len = one(); \
134 register int x0; for (x0 = 0x1000; x0 < 0x1000+len; x0++) { \
135 register int x1; for (x1 = 0x1100; x1 < 0x1100+len; x1++) { \
136 register int x2; for (x2 = 0x1200; x2 < 0x1200+len; x2++) { \
137 register int x3; for (x3 = 0x1300; x3 < 0x1300+len; x3++) { \
138 register int x4; for (x4 = 0x1400; x4 < 0x1400+len; x4++) { \
139 register int x5; for (x5 = 0x1500; x5 < 0x1500+len; x5++) { \
140 register int x6; for (x6 = 0x1600; x6 < 0x1600+len; x6++) { \
141 register int x7; for (x7 = 0x1700; x7 < 0x1700+len; x7++) { \
142 register int x8; for (x8 = 0x1800; x8 < 0x1800+len; x8++) { \
143 register int x9; for (x9 = 0x1900; x9 < 0x1900+len; x9++) { \
144 register int xA; for (xA = 0x1A00; xA < 0x1A00+len; xA++) { \
145 register int xB; for (xB = 0x1B00; xB < 0x1B00+len; xB++) { \
146 register int xC; for (xC = 0x1C00; xC < 0x1C00+len; xC++) { \
147 register int xD; for (xD = 0x1D00; xD < 0x1D00+len; xD++) { \
148 register int xE; for (xE = 0x1E00; xE < 0x1E00+len; xE++) { \
149 register int xF; for (xF = 0x1F00; xF < 0x1F00+len; xF++) { \
153 assert(xF >= 0x1F00 && xF <= 0x1F00+len); } \
154 assert(xE >= 0x1E00 && xE <= 0x1E00+len); } \
155 assert(xD >= 0x1D00 && xD <= 0x1D00+len); } \
156 assert(xC >= 0x1C00 && xC <= 0x1C00+len); } \
157 assert(xB >= 0x1B00 && xB <= 0x1B00+len); } \
158 assert(xA >= 0x1A00 && xA <= 0x1A00+len); } \
159 assert(x9 >= 0x1900 && x9 <= 0x1900+len); } \
160 assert(x8 >= 0x1800 && x8 <= 0x1800+len); } \
161 assert(x7 >= 0x1700 && x7 <= 0x1700+len); } \
162 assert(x6 >= 0x1600 && x6 <= 0x1600+len); } \
163 assert(x5 >= 0x1500 && x5 <= 0x1500+len); } \
164 assert(x4 >= 0x1400 && x4 <= 0x1400+len); } \
165 assert(x3 >= 0x1300 && x3 <= 0x1300+len); } \
166 assert(x2 >= 0x1200 && x2 <= 0x1200+len); } \
167 assert(x1 >= 0x1100 && x1 <= 0x1100+len); } \
168 assert(x0 >= 0x1000 && x0 <= 0x1000+len); } \
171 /* General idea is for the wrappers to use LOOPS_START / LOOPS_END to
172 soak up lots of int registers. And the orig fn uses TRASH_IREGS to
173 do the same. If there is insufficient saving of caller-saves regs
174 by the CALL_FN_* macros, then hopefully the assertions in LOOPS_END
177 /* --------------- 0 --------------- */
182 UInt
* words
= calloc(200, sizeof(UInt
));
183 TRASH_IREGS(r
, words
);
188 UInt
I_WRAP_SONAME_FNNAME_ZU(NONE
,fn_0
) ( UInt a1
)
192 VALGRIND_GET_ORIG_FN(fn
);
194 printf("fn_0 wrapper pre ()\n");
196 printf("fn_0 wrapper post1 = %d\n", (int)r
);
198 printf("fn_0 wrapper post2 = %d\n", (int)r
);
203 /* --------------- 1 --------------- */
205 UInt
fn_1 ( UInt a1
)
208 UInt
* words
= calloc(200, sizeof(UInt
));
210 TRASH_IREGS(r
, words
);
215 UInt
I_WRAP_SONAME_FNNAME_ZU(NONE
,fn_1
) ( UInt a1
)
219 VALGRIND_GET_ORIG_FN(fn
);
221 printf("fn_1 wrapper pre ( %d )\n", (int)a1
);
222 CALL_FN_W_W(r
, fn
, a1
);
223 printf("fn_1 wrapper post1 = %d\n", (int)r
);
225 printf("fn_1 wrapper post2 = %d\n", (int)r
);
230 /* --------------- 2 --------------- */
232 UInt
fn_2 ( UInt a1
, UInt a2
)
235 UInt
* words
= calloc(200, sizeof(UInt
));
238 TRASH_IREGS(r
, words
);
243 UInt
I_WRAP_SONAME_FNNAME_ZU(NONE
,fn_2
) ( UInt a1
, UInt a2
)
247 VALGRIND_GET_ORIG_FN(fn
);
249 printf("fn_2 wrapper pre ( %d, %d )\n", (int)a1
, (int)a2
);
250 CALL_FN_W_WW(r
, fn
, a1
, a2
);
251 printf("fn_2 wrapper post1 = %d\n", (int)r
);
252 CALL_FN_v_WW(fn
, a1
, a2
);
253 printf("fn_2 wrapper post2 = %d\n", (int)r
);
258 /* --------------- 3 --------------- */
260 UInt
fn_3 ( UInt a1
, UInt a2
, UInt a3
)
263 UInt
* words
= calloc(200, sizeof(UInt
));
267 TRASH_IREGS(r
, words
);
272 UInt
I_WRAP_SONAME_FNNAME_ZU(NONE
,fn_3
) ( UInt a1
, UInt a2
, UInt a3
)
276 VALGRIND_GET_ORIG_FN(fn
);
278 printf("fn_3 wrapper pre ( %d, %d, %d )\n", (int)a1
, (int)a2
, (int)a3
);
279 CALL_FN_W_WWW(r
, fn
, a1
, a2
, a3
);
280 printf("fn_3 wrapper post1 = %d\n", (int)r
);
281 CALL_FN_v_WWW(fn
, a1
, a2
, a3
);
282 printf("fn_3 wrapper post2 = %d\n", (int)r
);
287 /* --------------- 4 --------------- */
289 UInt
fn_4 ( UInt a1
, UInt a2
, UInt a3
, UInt a4
)
292 UInt
* words
= calloc(200, sizeof(UInt
));
297 TRASH_IREGS(r
, words
);
302 UInt
I_WRAP_SONAME_FNNAME_ZU(NONE
,fn_4
)
303 ( UInt a1
, UInt a2
, UInt a3
, UInt a4
)
307 VALGRIND_GET_ORIG_FN(fn
);
309 printf("fn_4 wrapper pre ( %d, %d, %d, %d )\n",
310 (int)a1
, (int)a2
, (int)a3
, (int)a4
);
311 CALL_FN_W_WWWW(r
, fn
, a1
, a2
, a3
, a4
);
312 printf("fn_4 wrapper post1 = %d\n", (int)r
);
317 /* --------------- 5 --------------- */
319 UInt
fn_5 ( UInt a1
, UInt a2
, UInt a3
, UInt a4
, UInt a5
)
322 UInt
* words
= calloc(200, sizeof(UInt
));
328 TRASH_IREGS(r
, words
);
333 UInt
I_WRAP_SONAME_FNNAME_ZU(NONE
,fn_5
)
334 ( UInt a1
, UInt a2
, UInt a3
, UInt a4
, UInt a5
)
338 VALGRIND_GET_ORIG_FN(fn
);
340 printf("fn_5 wrapper pre ( %d, %d, %d, %d, %d )\n",
341 (int)a1
, (int)a2
, (int)a3
, (int)a4
, (int)a5
);
342 CALL_FN_W_5W(r
, fn
, a1
, a2
, a3
, a4
, a5
);
343 printf("fn_5 wrapper post1 = %d\n", (int)r
);
348 /* --------------- 6 --------------- */
350 UInt
fn_6 ( UInt a1
, UInt a2
, UInt a3
, UInt a4
, UInt a5
, UInt a6
)
353 UInt
* words
= calloc(200, sizeof(UInt
));
360 TRASH_IREGS(r
, words
);
365 UInt
I_WRAP_SONAME_FNNAME_ZU(NONE
,fn_6
)
366 ( UInt a1
, UInt a2
, UInt a3
, UInt a4
, UInt a5
, UInt a6
)
370 VALGRIND_GET_ORIG_FN(fn
);
372 printf("fn_6 wrapper pre ( %d, %d, %d, %d, %d, %d )\n",
373 (int)a1
, (int)a2
, (int)a3
, (int)a4
, (int)a5
, (int)a6
);
374 CALL_FN_W_6W(r
, fn
, a1
, a2
, a3
, a4
, a5
, a6
);
375 printf("fn_6 wrapper post1 = %d\n", (int)r
);
380 /* --------------- 7 --------------- */
382 UInt
fn_7 ( UInt a1
, UInt a2
, UInt a3
, UInt a4
, UInt a5
, UInt a6
,
386 UInt
* words
= calloc(200, sizeof(UInt
));
394 TRASH_IREGS(r
, words
);
399 UInt
I_WRAP_SONAME_FNNAME_ZU(NONE
,fn_7
)
400 ( UInt a1
, UInt a2
, UInt a3
, UInt a4
, UInt a5
, UInt a6
,
405 VALGRIND_GET_ORIG_FN(fn
);
407 printf("fn_7 wrapper pre ( %d, %d, %d, %d, %d, %d, %d )\n",
408 (int)a1
, (int)a2
, (int)a3
, (int)a4
, (int)a5
, (int)a6
,
410 CALL_FN_W_7W(r
, fn
, a1
, a2
, a3
, a4
, a5
, a6
, a7
);
411 printf("fn_7 wrapper post1 = %d\n", (int)r
);
416 /* --------------- 8 --------------- */
418 UInt
fn_8 ( UInt a1
, UInt a2
, UInt a3
, UInt a4
, UInt a5
, UInt a6
,
422 UInt
* words
= calloc(200, sizeof(UInt
));
431 TRASH_IREGS(r
, words
);
436 UInt
I_WRAP_SONAME_FNNAME_ZU(NONE
,fn_8
)
437 ( UInt a1
, UInt a2
, UInt a3
, UInt a4
, UInt a5
, UInt a6
,
442 VALGRIND_GET_ORIG_FN(fn
);
444 printf("fn_8 wrapper pre ( %d, %d, %d, %d, %d, %d, %d, %d )\n",
445 (int)a1
, (int)a2
, (int)a3
, (int)a4
, (int)a5
, (int)a6
,
447 CALL_FN_W_8W(r
, fn
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
);
448 printf("fn_8 wrapper post1 = %d\n", (int)r
);
453 /* --------------- 9 --------------- */
455 UInt
fn_9 ( UInt a1
, UInt a2
, UInt a3
, UInt a4
, UInt a5
, UInt a6
,
456 UInt a7
, UInt a8
, UInt a9
)
459 UInt
* words
= calloc(200, sizeof(UInt
));
469 TRASH_IREGS(r
, words
);
474 UInt
I_WRAP_SONAME_FNNAME_ZU(NONE
,fn_9
)
475 ( UInt a1
, UInt a2
, UInt a3
, UInt a4
, UInt a5
, UInt a6
,
476 UInt a7
, UInt a8
, UInt a9
)
480 VALGRIND_GET_ORIG_FN(fn
);
482 printf("fn_9 wrapper pre ( %d, %d, %d, %d, %d, %d, %d, %d, %d )\n",
483 (int)a1
, (int)a2
, (int)a3
, (int)a4
, (int)a5
, (int)a6
,
484 (int)a7
, (int)a8
, (int)a9
);
485 CALL_FN_W_9W(r
, fn
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
);
486 printf("fn_9 wrapper post1 = %d\n", (int)r
);
491 /* --------------- 10 --------------- */
493 UInt
fn_10 ( UInt a1
, UInt a2
, UInt a3
, UInt a4
, UInt a5
, UInt a6
,
494 UInt a7
, UInt a8
, UInt a9
, UInt a10
)
497 UInt
* words
= calloc(200, sizeof(UInt
));
508 TRASH_IREGS(r
, words
);
513 UInt
I_WRAP_SONAME_FNNAME_ZU(NONE
,fn_10
)
514 ( UInt a1
, UInt a2
, UInt a3
, UInt a4
, UInt a5
, UInt a6
,
515 UInt a7
, UInt a8
, UInt a9
, UInt a10
)
519 VALGRIND_GET_ORIG_FN(fn
);
521 printf("fn_10 wrapper pre ( %d, %d, %d, %d, %d, %d, %d, %d, %d, %d )\n",
522 (int)a1
, (int)a2
, (int)a3
, (int)a4
, (int)a5
, (int)a6
,
523 (int)a7
, (int)a8
, (int)a9
, (int)a10
);
524 CALL_FN_W_10W(r
, fn
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
, a10
);
525 printf("fn_10 wrapper post1 = %d\n", (int)r
);
530 /* --------------- 11 --------------- */
532 UInt
fn_11 ( UInt a1
, UInt a2
, UInt a3
, UInt a4
, UInt a5
, UInt a6
,
533 UInt a7
, UInt a8
, UInt a9
, UInt a10
, UInt a11
)
536 UInt
* words
= calloc(200, sizeof(UInt
));
548 TRASH_IREGS(r
, words
);
553 UInt
I_WRAP_SONAME_FNNAME_ZU(NONE
,fn_11
)
554 ( UInt a1
, UInt a2
, UInt a3
, UInt a4
, UInt a5
, UInt a6
,
555 UInt a7
, UInt a8
, UInt a9
, UInt a10
, UInt a11
)
559 VALGRIND_GET_ORIG_FN(fn
);
561 printf("fn_11 wrapper pre ( %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d )\n",
562 (int)a1
, (int)a2
, (int)a3
, (int)a4
, (int)a5
, (int)a6
,
563 (int)a7
, (int)a8
, (int)a9
, (int)a10
, (int)a11
);
564 CALL_FN_W_11W(r
, fn
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
, a10
, a11
);
565 printf("fn_11 wrapper post1 = %d\n", (int)r
);
570 /* --------------- 12 --------------- */
572 UInt
fn_12 ( UInt a1
, UInt a2
, UInt a3
, UInt a4
, UInt a5
, UInt a6
,
573 UInt a7
, UInt a8
, UInt a9
, UInt a10
, UInt a11
, UInt a12
)
576 UInt
* words
= calloc(200, sizeof(UInt
));
589 TRASH_IREGS(r
, words
);
594 UInt
I_WRAP_SONAME_FNNAME_ZU(NONE
,fn_12
)
595 ( UInt a1
, UInt a2
, UInt a3
, UInt a4
, UInt a5
, UInt a6
,
596 UInt a7
, UInt a8
, UInt a9
, UInt a10
, UInt a11
, UInt a12
)
600 VALGRIND_GET_ORIG_FN(fn
);
602 printf("fn_12 wrapper pre ( %d, %d, %d, %d, %d, %d, "
603 "%d, %d, %d, %d, %d, %d )\n",
604 (int)a1
, (int)a2
, (int)a3
, (int)a4
, (int)a5
, (int)a6
,
605 (int)a7
, (int)a8
, (int)a9
, (int)a10
, (int)a11
, (int)a12
);
606 CALL_FN_W_12W(r
, fn
, a1
, a2
, a3
, a4
, a5
, a6
, a7
, a8
, a9
, a10
, a11
, a12
);
607 printf("fn_12 wrapper post1 = %d\n", (int)r
);
612 /* --------------- main --------------- */
618 one_actual_return_value
= 1;
620 printf("fn_0 ...\n");
622 printf(" ... %d\n\n", (int)w
);
624 printf("fn_1 ...\n");
626 printf(" ... %d\n\n", (int)w
);
628 printf("fn_2 ...\n");
630 printf(" ... %d\n\n", (int)w
);
632 printf("fn_3 ...\n");
634 printf(" ... %d\n\n", (int)w
);
636 printf("fn_4 ...\n");
637 w
= fn_4(42,43,44,45);
638 printf(" ... %d\n\n", (int)w
);
640 printf("fn_5 ...\n");
641 w
= fn_5(42,43,44,45,46);
642 printf(" ... %d\n\n", (int)w
);
644 printf("fn_6 ...\n");
645 w
= fn_6(42,43,44,45,46,47);
646 printf(" ... %d\n\n", (int)w
);
648 printf("fn_7 ...\n");
649 w
= fn_7(42,43,44,45,46,47,48);
650 printf(" ... %d\n\n", (int)w
);
652 printf("fn_8 ...\n");
653 w
= fn_8(42,43,44,45,46,47,48,49);
654 printf(" ... %d\n\n", (int)w
);
656 printf("fn_9 ...\n");
657 w
= fn_9(42,43,44,45,46,47,48,49,50);
658 printf(" ... %d\n\n", (int)w
);
660 printf("fn_10 ...\n");
661 w
= fn_10(42,43,44,45,46,47,48,49,50,51);
662 printf(" ... %d\n\n", (int)w
);
664 printf("fn_11 ...\n");
665 w
= fn_11(42,43,44,45,46,47,48,49,50,51,52);
666 printf(" ... %d\n\n", (int)w
);
668 printf("fn_12 ...\n");
669 w
= fn_12(42,43,44,45,46,47,48,49,50,51,52,53);
670 printf(" ... %d\n\n", (int)w
);