source: doc/theses/andrew_beach_MMath/code/resume-empty.cfa @ 20be782

ADTast-experimentalpthread-emulation
Last change on this file since 20be782 was 18783b4, checked in by Peter A. Buhr <pabuhr@…>, 3 years ago

attempt to remove tail-recursion optimization

  • Property mode set to 100644
File size: 960 bytes
Line 
1// Resume Across Empty Function
2#include <clock.hfa>
3#include <exception.hfa>
4#include <fstream.hfa>
5#include <stdlib.hfa>                                                                   // strto
6
7exception empty_exception;
8vtable(empty_exception) empty_vt;
9
10void nounwind_empty(unsigned int frames) {
11        if (frames) {
12                nounwind_empty(frames - 1);
13                if ( frames == -1 ) printf( "42" );                             // prevent recursion optimizations
14        } else {
15                throwResume (empty_exception){&empty_vt};
16        }
17}
18
19int main(int argc, char * argv[]) {
20        unsigned int times = 1;
21        unsigned int total_frames = 1;
22        if (1 < argc) {
23                times = strto(argv[1], 0p, 10);
24        }
25        if (2 < argc) {
26                total_frames = strto(argv[2], 0p, 10);
27        }
28
29        Time start_time = timeHiRes();
30        for (unsigned int count = 0 ; count < times ; ++count) {
31                try {
32                        nounwind_empty(total_frames);
33                } catchResume (empty_exception *) {
34                        asm volatile ("# fixup block");
35                }
36        }
37        Time end_time = timeHiRes();
38        sout | "Run-Time (s): " | wd(0,1, (end_time - start_time)`ns / 1_000_000_000.);
39}
Note: See TracBrowser for help on using the repository browser.