10#define NOINLINE __attribute__((noinline))
12NOINLINE
int sum5(
int a,
int b,
int c,
int d,
int e) {
return a + 2 * b + 3 * c + 4 * d + 5 * e; }
13NOINLINE
int sum6(
int a,
int b,
int c,
int d,
int e,
int f) {
return a + 2 * b + 3 * c + 4 * d + 5 * e + 6 * f; }
14NOINLINE
int sum2(
int a,
int b) {
return a * 10 + b; }
15NOINLINE
int twice(
int x) {
return x * 2; }
17NOINLINE
int fwd5(
int a,
int b,
int c,
int d,
int e) {
return sum5(a, b, c, d, e); }
18NOINLINE
int fwd5_rev(
int a,
int b,
int c,
int d,
int e) {
return sum5(e, d, c, b, a); }
19NOINLINE
int fwd6(
int a,
int b,
int c,
int d,
int e,
int f) {
return sum6(a, b, c, d, e, f); }
20NOINLINE
int fwd6_rot(
int a,
int b,
int c,
int d,
int e,
int f) {
return sum6(f, a, b, c, d, e); }
21NOINLINE
int grow3(
int a,
int b,
int c) {
return sum5(a, b, c, 7, 9); }
22NOINLINE
int shrink(
int a,
int b,
int c,
int d,
int e) {
return sum2(a + e, b + d); }
23NOINLINE
int after_call(
int x) {
int y = twice(x);
return sum2(y + 1, x); }
25static int (*
volatile fp5)(int, int, int, int, int) = sum5;
26static int (*
volatile fp2)(int, int) = sum2;
27NOINLINE
int via_ptr5(
int a,
int b,
int c,
int d,
int e) {
return fp5(a, b, c, d, e); }
28NOINLINE
int via_ptr2(
int a,
int b) {
return fp2(b, a); }
30NOINLINE
int chain(
int a) {
return after_call(twice(a)); }
33#define CHECK(expr, want) do { int got = (expr); if (got != (want)) { bad++; printf("tc: %s = %d, want %d\n", #expr, got, (int)(want)); } } while (0)
35int _start(
int argc,
char *argv[])
40 CHECK(fwd5(1, 2, 3, 4, 5), 1 + 4 + 9 + 16 + 25);
41 CHECK(fwd5_rev(1, 2, 3, 4, 5), 5 + 8 + 9 + 8 + 5);
42 CHECK(fwd6(1, 2, 3, 4, 5, 6), 1 + 4 + 9 + 16 + 25 + 36);
43 CHECK(fwd6_rot(1, 2, 3, 4, 5, 6), 6 + 2 + 6 + 12 + 20 + 30);
44 CHECK(grow3(1, 2, 3), 1 + 4 + 9 + 28 + 45);
45 CHECK(shrink(1, 2, 3, 4, 5), (1 + 5) * 10 + (2 + 4));
46 CHECK(after_call(3), 7 * 10 + 3);
47 CHECK(via_ptr5(5, 4, 3, 2, 1), 5 + 8 + 9 + 8 + 5);
48 CHECK(via_ptr2(3, 4), 40 + 3);
49 CHECK(chain(2), (8 + 1) * 10 + 4);
51 printf(
"tc: %s\n", bad ?
"mismatch" :
"ok");