Skip to content

Commit

Permalink
fix handcomp test abi usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Singer authored and VoxSciurorum committed Aug 27, 2024
1 parent 452b2c8 commit b71274e
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 38 deletions.
34 changes: 19 additions & 15 deletions handcomp_test/cilksort.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ ELM *binsplit(ELM val, ELM *low, ELM *high) {
}

static void __attribute__ ((noinline))
cilkmerge_spawn_helper(ELM *low1, ELM *high1, ELM *low2, ELM *high2, ELM *lowdest);
cilkmerge_spawn_helper(ELM *low1, ELM *high1, ELM *low2, ELM *high2, ELM *lowdest,
__cilkrts_stack_frame *parent);

void cilkmerge(ELM *low1, ELM *high1,
ELM *low2, ELM *high2, ELM *lowdest) {
Expand Down Expand Up @@ -371,7 +372,7 @@ void cilkmerge(ELM *low1, ELM *high1,

/* cilk_spawn cilkmerge(low1, split1 - 1, low2, split2, lowdest); */
if (!__cilk_prepare_spawn(&sf)) {
cilkmerge_spawn_helper(low1, split1 - 1, low2, split2, lowdest);
cilkmerge_spawn_helper(low1, split1 - 1, low2, split2, lowdest, &sf);
}
cilkmerge(split1 + 1, high1, split2 + 1, high2, lowdest + lowsize + 2);

Expand All @@ -385,16 +386,18 @@ void cilkmerge(ELM *low1, ELM *high1,

static void __attribute__ ((noinline))
cilkmerge_spawn_helper(ELM *low1, ELM *high1,
ELM *low2, ELM *high2, ELM *lowdest) {
ELM *low2, ELM *high2, ELM *lowdest,
__cilkrts_stack_frame *parent) {

__cilkrts_stack_frame sf;
__cilkrts_enter_frame_helper(&sf);
__cilkrts_detach(&sf);
__cilkrts_enter_frame_helper(&sf, parent, false);
__cilkrts_detach(&sf, parent);
cilkmerge(low1, high1, low2, high2, lowdest);
__cilk_helper_epilogue(&sf);
__cilk_helper_epilogue(&sf, parent, false);
}

static void __attribute__ ((noinline)) cilksort_spawn_helper(ELM *low, ELM *tmp, long size);
static void __attribute__ ((noinline)) cilksort_spawn_helper(ELM *low, ELM *tmp, long size,
__cilkrts_stack_frame *parent);

void cilksort(ELM *low, ELM *tmp, long size) {

Expand Down Expand Up @@ -430,17 +433,17 @@ void cilksort(ELM *low, ELM *tmp, long size) {

/* cilk_spawn cilksort(A, tmpA, quarter); */
if (!__cilk_prepare_spawn(&sf)) {
cilksort_spawn_helper(A, tmpA, quarter);
cilksort_spawn_helper(A, tmpA, quarter, &sf);
}

/* cilk_spawn cilksort(B, tmpB, quarter); */
if (!__cilk_prepare_spawn(&sf)) {
cilksort_spawn_helper(B, tmpB, quarter);
cilksort_spawn_helper(B, tmpB, quarter, &sf);
}

/* cilk_spawn cilksort(C, tmpC, quarter); */
if (!__cilk_prepare_spawn(&sf)) {
cilksort_spawn_helper(C, tmpC, quarter);
cilksort_spawn_helper(C, tmpC, quarter, &sf);
}
cilksort(D, tmpD, size - 3 * quarter);

Expand All @@ -449,7 +452,7 @@ void cilksort(ELM *low, ELM *tmp, long size) {

/* cilk_spawn cilkmerge(A, A + quarter - 1, B, B + quarter - 1, tmpA); */
if (!__cilk_prepare_spawn(&sf)) {
cilkmerge_spawn_helper(A, A + quarter - 1, B, B + quarter - 1, tmpA);
cilkmerge_spawn_helper(A, A + quarter - 1, B, B + quarter - 1, tmpA, &sf);
}
cilkmerge(C, C + quarter - 1, D, low + size - 1, tmpC);

Expand All @@ -463,13 +466,14 @@ void cilksort(ELM *low, ELM *tmp, long size) {
return;
}

static void __attribute__ ((noinline)) cilksort_spawn_helper(ELM *low, ELM *tmp, long size) {
static void __attribute__ ((noinline)) cilksort_spawn_helper(ELM *low, ELM *tmp, long size,
__cilkrts_stack_frame *parent) {

__cilkrts_stack_frame sf;
__cilkrts_enter_frame_helper(&sf);
__cilkrts_detach(&sf);
__cilkrts_enter_frame_helper(&sf, parent, false);
__cilkrts_detach(&sf, parent);
cilksort(low, tmp, size);
__cilk_helper_epilogue(&sf);
__cilk_helper_epilogue(&sf, parent, false);
}

void scramble_array(ELM *arr, unsigned long size) {
Expand Down
14 changes: 8 additions & 6 deletions handcomp_test/fib.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ int fib(int n) {
extern size_t ZERO;
void __attribute__((weak)) dummy(void *p) { return; }

static void __attribute__ ((noinline)) fib_spawn_helper(int *x, int n);
static void __attribute__ ((noinline)) fib_spawn_helper(int *x, int n,
__cilkrts_stack_frame *parent);

int fib(int n) {
int x = 0, y, _tmp;
Expand All @@ -48,7 +49,7 @@ int fib(int n) {

/* x = spawn fib(n-1) */
if (!__cilk_prepare_spawn(&sf)) {
fib_spawn_helper(&x, n-1);
fib_spawn_helper(&x, n-1, &sf);
}

y = fib(n - 2);
Expand All @@ -62,13 +63,14 @@ int fib(int n) {
return _tmp;
}

static void __attribute__ ((noinline)) fib_spawn_helper(int *x, int n) {
static void __attribute__ ((noinline)) fib_spawn_helper(int *x, int n,
__cilkrts_stack_frame *parent) {

__cilkrts_stack_frame sf;
__cilkrts_enter_frame_helper(&sf);
__cilkrts_detach(&sf);
__cilkrts_enter_frame_helper(&sf, parent, false);
__cilkrts_detach(&sf, parent);
*x = fib(n);
__cilk_helper_epilogue(&sf);
__cilk_helper_epilogue(&sf, parent, false);
}

int main(int argc, char * args[]) {
Expand Down
24 changes: 13 additions & 11 deletions handcomp_test/mm_dac.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ static void mm_dac_serial(int *C, const int *A, const int *B, int n, int length)
}

__attribute__((noinline)) static void
mm_dac_spawn_helper(int *C, const int *A, const int *B, int n, int length);
mm_dac_spawn_helper(int *C, const int *A, const int *B, int n, int length,
__cilkrts_stack_frame *parent);

/**
* Recursive implementation of matrix multiply.
Expand Down Expand Up @@ -105,17 +106,17 @@ static void mm_dac(int *C, const int *A, const int *B, int n, int length) {

/* cilk_spawn mm_dac(C00, A00, B00, n, mid); */
if (!__cilk_prepare_spawn(&sf)) {
mm_dac_spawn_helper(C00, A00, B00, n, mid);
mm_dac_spawn_helper(C00, A00, B00, n, mid, &sf);
}

/* cilk_spawn mm_dac(C01, A00, B01, n, mid); */
if (!__cilk_prepare_spawn(&sf)) {
mm_dac_spawn_helper(C01, A00, B01, n, mid);
mm_dac_spawn_helper(C01, A00, B01, n, mid, &sf);
}

/* cilk_spawn mm_dac(C10, A10, B00, n, mid); */
if (!__cilk_prepare_spawn(&sf)) {
mm_dac_spawn_helper(C10, A10, B00, n, mid);
mm_dac_spawn_helper(C10, A10, B00, n, mid, &sf);
}
mm_dac(C11, A10, B01, n, mid);

Expand All @@ -124,17 +125,17 @@ static void mm_dac(int *C, const int *A, const int *B, int n, int length) {

/* cilk_spawn mm_dac(C00, A01, B10, n, mid); */
if (!__cilk_prepare_spawn(&sf)) {
mm_dac_spawn_helper(C00, A01, B10, n, mid);
mm_dac_spawn_helper(C00, A01, B10, n, mid, &sf);
}

/* cilk_spawn mm_dac(C01, A01, B11, n, mid); */
if (!__cilk_prepare_spawn(&sf)) {
mm_dac_spawn_helper(C01, A01, B11, n, mid);
mm_dac_spawn_helper(C01, A01, B11, n, mid, &sf);
}

/* cilk_spawn mm_dac(C10, A11, B10, n, mid); */
if (!__cilk_prepare_spawn(&sf)) {
mm_dac_spawn_helper(C10, A11, B10, n, mid);
mm_dac_spawn_helper(C10, A11, B10, n, mid, &sf);
}
mm_dac(C11, A11, B11, n, mid);

Expand All @@ -145,13 +146,14 @@ static void mm_dac(int *C, const int *A, const int *B, int n, int length) {
}

__attribute__((noinline))
static void mm_dac_spawn_helper(int *C, const int *A, const int *B, int n, int length) {
static void mm_dac_spawn_helper(int *C, const int *A, const int *B, int n, int length,
__cilkrts_stack_frame *parent) {

__cilkrts_stack_frame sf;
__cilkrts_enter_frame_helper(&sf);
__cilkrts_detach(&sf);
__cilkrts_enter_frame_helper(&sf, parent, false);
__cilkrts_detach(&sf, parent);
mm_dac(C, A, B, n, length);
__cilk_helper_epilogue(&sf);
__cilk_helper_epilogue(&sf, parent, false);
}

static void rand_matrix(int *dest, int n) {
Expand Down
14 changes: 8 additions & 6 deletions handcomp_test/nqueens.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ static int ok (int n, char *a) {
}

static void __attribute__ ((noinline))
nqueens_spawn_helper(int *count, int n, int j, char *a);
nqueens_spawn_helper(int *count, int n, int j, char *a,
__cilkrts_stack_frame *parent);

static int nqueens(int n, int j, char *a) {

Expand Down Expand Up @@ -88,7 +89,7 @@ static int nqueens(int n, int j, char *a) {

/* count[i] = cilk_spawn nqueens(n, j + 1, b); */
if (!__cilk_prepare_spawn(&sf)) {
nqueens_spawn_helper(&(count[i]), n, j+1, b);
nqueens_spawn_helper(&(count[i]), n, j+1, b, &sf);
}
}
}
Expand All @@ -105,13 +106,14 @@ static int nqueens(int n, int j, char *a) {
}

static void __attribute__ ((noinline))
nqueens_spawn_helper(int *count, int n, int j, char *a) {
nqueens_spawn_helper(int *count, int n, int j, char *a,
__cilkrts_stack_frame *parent) {

__cilkrts_stack_frame sf;
__cilkrts_enter_frame_helper(&sf);
__cilkrts_detach(&sf);
__cilkrts_enter_frame_helper(&sf, parent, false);
__cilkrts_detach(&sf, parent);
*count = nqueens(n, j, a);
__cilk_helper_epilogue(&sf);
__cilk_helper_epilogue(&sf, parent, false);
}

int main(int argc, char *argv[]) {
Expand Down

0 comments on commit b71274e

Please sign in to comment.