#include #include volatile unsigned int scratchpad = 0; void __attribute__((noinline)) leaf1(unsigned long long count) { while (count--) { scratchpad ^= 0x1; } } void __attribute__((noinline)) leaf2(unsigned long long count) { while (count--) { scratchpad ^= 0x2; } } void __attribute__((noinline)) leaf3(unsigned long long count) { while (count--) { scratchpad ^= 0x4; } } void __attribute__((noinline)) leaf4(unsigned long long count) { while (count--) { scratchpad ^= 0x8; } } void __attribute__((noinline)) call1(unsigned long long count) { leaf1(count); printf("Done with %s\n", __func__); } void __attribute__((noinline)) call1_2(unsigned long long count) { leaf1(count); leaf2(count); printf("Done with %s\n", __func__); } void __attribute__((noinline)) call1_2_3(unsigned long long count) { leaf1(count); leaf2(count); leaf3(count); printf("Done with %s\n", __func__); } void __attribute__((noinline)) call1_2_3_4(unsigned long long count) { leaf1(count); leaf2(count); leaf3(count); leaf4(count); printf("Done with %s\n", __func__); } void __attribute__((noinline)) call_all_four_combos(unsigned long long count) { call1(count); call1_2(count); call1_2_3(count); call1_2_3_4(count); printf("Done with %s\n", __func__); } void __attribute__((noinline)) non_leaf_work(unsigned long long count) { unsigned long long orig_count = count; leaf1(count); while (count--) { scratchpad ^= 0x1; } count = orig_count; leaf2(count); while (count--) { scratchpad ^= 0x1; } count = orig_count; leaf3(count); while (count--) { scratchpad ^= 0x1; } count = orig_count; leaf4(count); while (count--) { scratchpad ^= 0x1; } printf("Done with %s\n", __func__); } void __attribute__((noinline)) extra_deep_3(unsigned long long count) { non_leaf_work(count); printf("Done with %s\n", __func__); } void __attribute__((noinline)) extra_deep_2(unsigned long long count) { extra_deep_3(count); printf("Done with %s\n", __func__); } void __attribute__((noinline)) extra_deep_1(unsigned long long count) { extra_deep_2(count); printf("Done with %s\n", __func__); } void __attribute__((noinline)) extra_deep(unsigned long long count) { extra_deep_1(count); printf("Done with %s\n", __func__); } int main (int argc, char **argv) { unsigned long long count; if (argc != 2) { fprintf(stderr, "Wrong arg count %d\n", argc); return -1; } sscanf(argv[1], "%llu", &count); call1(count); call1_2(count); call1_2_3(count); call1_2_3_4(count); call_all_four_combos(count); non_leaf_work(count); extra_deep(count); printf("Done with %llu loops, scratch=%#010x\n", count, scratchpad); return 0; }