1/** \file
2 *  \brief Testing code for the Cilk-like Tweed library.
3 */
4
5/*
6 * Copyright (c) 2010, ETH Zurich.
7 * All rights reserved.
8 *
9 * This file is distributed under the terms in the attached LICENSE file.
10 * If you do not find this file, copies can be found by writing to:
11 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
12 */
13#include "tweed/tweed.h"
14
15#include <stdio.h>
16#include <barrelfish/threads.h>
17
18#include "trace/trace.h"
19#include <trace_definitions/trace_defs.h>
20#include <arch/x86/barrelfish_kpi/asm_inlines_arch.h>
21
22
23TASK(int, fib, 1, int, n) {
24    if (n < 2) {
25        return n;
26    } else {
27        SPAWN(fib, 1, n-1);
28        int a = CALL(fib, 1, n-2);
29        int b = SYNC(fib, 1);
30        return a+b;
31    }
32}
33
34MAIN_TASK(main, args) {
35    trace_event(TRACE_SUBSYS_BENCH, TRACE_EVENT_BENCH_PCBENCH, 1);
36    trace_event(TRACE_SUBSYS_TWEED, TRACE_EVENT_TWEED_START, 0);
37    uint64_t start = rdtsc();
38    int fib_res = CALL(fib, 1, 35);
39    uint64_t end = rdtsc();
40    trace_event(TRACE_SUBSYS_TWEED, TRACE_EVENT_TWEED_END, 0);
41    trace_event(TRACE_SUBSYS_BENCH, TRACE_EVENT_BENCH_PCBENCH, 0);
42    printf("cycles taken - %ld\n", (end - start));
43    printf("result - %d\n", (fib_res));
44    return 0;
45}
46
47int main (int argc, char* argv[]) {
48    INIT_TWEED((atoi(argv[1])), main, NULL);
49    return 0;
50}
51