diff options
| author | Tom Harley | 2020-01-25 04:18:36 +0000 |
|---|---|---|
| committer | Tom Harley | 2020-01-25 04:18:36 +0000 |
| commit | 14ea550522551bcc9d9c736f65d2e4882bd989cb (patch) | |
| tree | 28b92971ef412b63d44626ef3c2e492d5efd2e57 /examples | |
| parent | Add some LLVM attributes to functions (diff) | |
| download | sinter-14ea550522551bcc9d9c736f65d2e4882bd989cb.tar.gz sinter-14ea550522551bcc9d9c736f65d2e4882bd989cb.zip | |
Committed version of codebase
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/nq/Makefile | 2 | ||||
| -rw-r--r-- | examples/nq/gglue-always.ll.pp | 78 | ||||
| -rw-r--r-- | examples/nq/gglue-never.ll.pp | 66 | ||||
| -rw-r--r-- | examples/nq/gglue-smart.ll.pp | 157 | ||||
| -rw-r--r-- | examples/nq/gglue.ll | 5 | ||||
| -rw-r--r-- | examples/nq/gglue.ll.pp | 157 | ||||
| -rwxr-xr-x | examples/nq/int-width-test.sh | 34 | ||||
| -rw-r--r-- | examples/nq/nqueens.sin | 171 |
8 files changed, 615 insertions, 55 deletions
diff --git a/examples/nq/Makefile b/examples/nq/Makefile index fb51b90..271c4a4 100644 --- a/examples/nq/Makefile +++ b/examples/nq/Makefile @@ -23,7 +23,7 @@ default: all all: $(TRGT) -$(TRGT): nqueens.o util.o either.o list.o closures.o run_func.o glue.o gglue.o +$(TRGT): nqueens.o run_func.o glue.o gglue.o clean: $(RM) $(LLEXT) *.dot *.svg *.o $(TRGT) diff --git a/examples/nq/gglue-always.ll.pp b/examples/nq/gglue-always.ll.pp new file mode 100644 index 0000000..5e6e61b --- /dev/null +++ b/examples/nq/gglue-always.ll.pp @@ -0,0 +1,78 @@ +target triple = "x86_64-unknown-linux-gnu" + +declare dso_local void @GC_init() +declare dso_local i32 @atoi(i8*) +declare dso_local i8* @gc_alloc(i64) +declare dso_local i32 @printf(i8*, ...) + +@.str = private unnamed_addr constant [2 x i8] c"p\00", align 1 +@.str.1 = private unnamed_addr constant [7 x i8] c"glue.c\00", align 1 +@__PRETTY_FUNCTION__.gc_alloc = private unnamed_addr constant [23 x i8] c"void *gc_alloc(size_t)\00", align 1 +@.str.2 = private unnamed_addr constant [13 x i8] c"usage: %s n\0A\00", align 1 +@.str.3 = private unnamed_addr constant [4 x i8] c"%i\0A\00", align 1 + +declare fastcc i8* @gen(i8*, i8*) + +declare fastcc i8* @length (i8*) + +define fastcc i8* @"+"(i8*, i8*) { + %a_uncast = bitcast i8* %0 to VINT* + %a = load VINT, VINT* %a_uncast + %b_uncast = bitcast i8* %1 to VINT* + %b = load VINT, VINT* %b_uncast + %sum = add VINT %a, %b + %res = call fastcc i8* @gc_alloc(i64 ptrtoint (VINT* getelementptr (VINT, VINT* null, i32 1) to i64)) + %sum_box_cast = bitcast i8* %res to VINT* + store VINT %sum, VINT* %sum_box_cast + ret i8* %res +} + +define fastcc i8* @"-"(i8*, i8*) { + %a_uncast = bitcast i8* %0 to VINT* + %a = load VINT, VINT* %a_uncast + %b_uncast = bitcast i8* %1 to VINT* + %b = load VINT, VINT* %b_uncast + %sum = sub VINT %a, %b + %res = call fastcc i8* @gc_alloc(i64 ptrtoint (VINT* getelementptr (VINT, VINT* null, i32 1) to i64)) + %sum_box_cast = bitcast i8* %res to VINT* + store VINT %sum, VINT* %sum_box_cast + ret i8* %res +} + +define fastcc VINT @count_solns(i32) { + %ext_p = inttoptr i32 %0 to i8* + %ext = ptrtoint i8* %ext_p to VINT + %boxed = call fastcc i8* @gc_alloc(i64 ptrtoint (VINT* getelementptr (VINT, VINT* null, i32 1) to i64)) + %box_uncast = bitcast i8* %boxed to VINT* + store VINT %ext, VINT* %box_uncast + %solns = call fastcc i8* @gen(i8* %boxed, i8* %boxed) + %n_solns = call fastcc i8* @length(i8* %solns) + %solns_uncast = bitcast i8* %n_solns to VINT* + %res = load VINT, VINT* %solns_uncast + ret VINT %res +} + +define dso_local i32 @main(i32, i8**) optnone noinline { + call void @GC_init() + %cond = icmp ne i32 %0, 2 + br i1 %cond, label %aaa, label %bbb + +aaa: + %a12 = getelementptr inbounds i8*, i8** %1, i64 0 + %a13 = load i8*, i8** %a12, align 8 + %a14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i32 0, i32 0), i8* %a13) + br label %ccc + +bbb: + %a17 = getelementptr inbounds i8*, i8** %1, i64 1 + %a18 = load i8*, i8** %a17, align 8 + %a19 = call i32 @atoi(i8* %a18) + %a21 = call fastcc VINT @count_solns(i32 %a19) + %a22_p = inttoptr VINT %a21 to i8* + %a22 = ptrtoint i8* %a22_p to i32 + %a23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i32 0, i32 0), i32 %a22) + br label %ccc + +ccc: + ret i32 0 +} diff --git a/examples/nq/gglue-never.ll.pp b/examples/nq/gglue-never.ll.pp new file mode 100644 index 0000000..75141db --- /dev/null +++ b/examples/nq/gglue-never.ll.pp @@ -0,0 +1,66 @@ +target triple = "x86_64-unknown-linux-gnu" + +declare dso_local void @GC_init() +declare dso_local i32 @atoi(i8*) +declare dso_local PINT @gc_alloc(i64) +declare dso_local i32 @printf(i8*, ...) + +@.str = private unnamed_addr constant [2 x i8] c"p\00", align 1 +@.str.1 = private unnamed_addr constant [7 x i8] c"glue.c\00", align 1 +@__PRETTY_FUNCTION__.gc_alloc = private unnamed_addr constant [23 x i8] c"void *gc_alloc(size_t)\00", align 1 +@.str.2 = private unnamed_addr constant [13 x i8] c"usage: %s n\0A\00", align 1 +@.str.3 = private unnamed_addr constant [4 x i8] c"%i\0A\00", align 1 + +declare fastcc PINT @gen(PINT, PINT) + +declare fastcc PINT @length (PINT) + +define fastcc PINT @"+"(PINT, PINT) { + %a = BTOI %0 + %b = BTOI %1 + %sum = add VINT %a, %b + %res = ITOB %sum + ret PINT %res +} + +define fastcc PINT @"-"(PINT, PINT) { + %a = BTOI %0 + %b = BTOI %1 + %sum = sub VINT %a, %b + %res = ITOB %sum + ret PINT %res +} + +define fastcc VINT @count_solns(i32) { + %ext_p = inttoptr i32 %0 to i8* + %box_res = ptrtoint i8* %ext_p to PINT + %solns = call fastcc PINT @gen(PINT %box_res, PINT %box_res) + %n_solns = call fastcc PINT @length(PINT %solns) + %res = BTOI %n_solns + ret VINT %res +} + +define dso_local i32 @main(i32, i8**) optnone noinline { + call void @GC_init() + %cond = icmp ne i32 %0, 2 + br i1 %cond, label %aaa, label %bbb + +aaa: + %a12 = getelementptr inbounds i8*, i8** %1, i64 0 + %a13 = load i8*, i8** %a12, align 8 + %a14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i32 0, i32 0), i8* %a13) + br label %ccc + +bbb: + %a17 = getelementptr inbounds i8*, i8** %1, i64 1 + %a18 = load i8*, i8** %a17, align 8 + %a19 = call i32 @atoi(i8* %a18) + %a21 = call fastcc VINT @count_solns(i32 %a19) + %a22_p = inttoptr VINT %a21 to i8* + %a22 = ptrtoint i8* %a22_p to i32 + %a23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i32 0, i32 0), i32 %a22) + br label %ccc + +ccc: + ret i32 0 +} diff --git a/examples/nq/gglue-smart.ll.pp b/examples/nq/gglue-smart.ll.pp new file mode 100644 index 0000000..96a32f2 --- /dev/null +++ b/examples/nq/gglue-smart.ll.pp @@ -0,0 +1,157 @@ +target triple = "x86_64-unknown-linux-gnu" + +declare dso_local void @GC_init() +declare dso_local i32 @atoi(i8*) +declare dso_local i8* @gc_alloc(i64) +declare dso_local i32 @printf(i8*, ...) + +@.str = private unnamed_addr constant [2 x i8] c"p\00", align 1 +@.str.1 = private unnamed_addr constant [7 x i8] c"glue.c\00", align 1 +@__PRETTY_FUNCTION__.gc_alloc = private unnamed_addr constant [23 x i8] c"void *gc_alloc(size_t)\00", align 1 +@.str.2 = private unnamed_addr constant [13 x i8] c"usage: %s n\0A\00", align 1 +@.str.3 = private unnamed_addr constant [4 x i8] c"%i\0A\00", align 1 + +declare fastcc i8* @gen(i8*, i8*) + +declare fastcc i8* @length (i8*) + +define fastcc i8* @"+"(i8*, i8*) { + %cond = icmp ule i64 ptrtoint (VINT* getelementptr (VINT, VINT* null, VINT 1) to i64), ptrtoint (i1** getelementptr (i1*, i1** null, VINT 1) to i64) + br i1 %cond, label %box_smol, label %box_beeg + +box_smol: + %a_smol = ptrtoint i8* %0 to VINT + %b_smol = ptrtoint i8* %1 to VINT + br label %box_done + +box_beeg: + %a_uncast = bitcast i8* %0 to VINT* + %a_beeg = load VINT, VINT* %a_uncast + %b_uncast = bitcast i8* %1 to VINT* + %b_beeg = load VINT, VINT* %b_uncast + br label %box_done + +box_done: + %a = phi VINT [ %a_smol, %box_smol ], [ %a_beeg, %box_beeg ] + %b = phi VINT [ %b_smol, %box_smol ], [ %b_beeg, %box_beeg ] + %sum = add VINT %a, %b + br i1 %cond, label %box_smol1, label %box_beeg1 + +box_smol1: + %sum_smol = inttoptr VINT %sum to i8* + br label %box_done1 + +box_beeg1: + %sum_boxed = call fastcc i8* @gc_alloc(i64 ptrtoint (VINT* getelementptr (VINT, VINT* null, i32 1) to i64)) + %sum_box_cast = bitcast i8* %sum_boxed to VINT* + store VINT %sum, VINT* %sum_box_cast + br label %box_done1 + +box_done1: + %res = phi i8* [ %sum_smol, %box_smol1 ], [ %sum_boxed, %box_beeg1 ] + ret i8* %res +} + +define fastcc i8* @-(i8*, i8*) { + %cond = icmp ule i64 ptrtoint (VINT* getelementptr (VINT, VINT* null, VINT 1) to i64), ptrtoint (i1** getelementptr (i1*, i1** null, VINT 1) to i64) + br i1 %cond, label %box_smol, label %box_beeg + +box_smol: + %a_smol = ptrtoint i8* %0 to VINT + %b_smol = ptrtoint i8* %1 to VINT + br label %box_done + +box_beeg: + %a_uncast = bitcast i8* %0 to VINT* + %a_beeg = load VINT, VINT* %a_uncast + %b_uncast = bitcast i8* %1 to VINT* + %b_beeg = load VINT, VINT* %b_uncast + br label %box_done + +box_done: + %a = phi VINT [ %a_smol, %box_smol ], [ %a_beeg, %box_beeg ] + %b = phi VINT [ %b_smol, %box_smol ], [ %b_beeg, %box_beeg ] + %sum = sub VINT %a, %b + br i1 %cond, label %box_smol1, label %box_beeg1 + +box_smol1: + %sum_smol = inttoptr VINT %sum to i8* + br label %box_done1 + +box_beeg1: + %sum_boxed = call fastcc i8* @gc_alloc(i64 ptrtoint (VINT* getelementptr (VINT, VINT* null, i32 1) to i64)) + %sum_box_cast = bitcast i8* %sum_boxed to VINT* + store VINT %sum, VINT* %sum_box_cast + br label %box_done1 + +box_done1: + %res = phi i8* [ %sum_smol, %box_smol1 ], [ %sum_boxed, %box_beeg1 ] + ret i8* %res +} + +define fastcc VINT @count_solns(i32) { + %ext_p = inttoptr i32 %0 to i8* + %ext = ptrtoint i8* %ext_p to VINT + ; %ext = zext i32 %0 to VINT + br label %box_cond + +box_cond: ; preds = %entry + %cond = icmp ule i64 ptrtoint (VINT* getelementptr (VINT, VINT* null, VINT 1) to i64), ptrtoint (i1** getelementptr (i1*, i1** null, VINT 1) to i64) + br i1 %cond, label %box_smol, label %box_beeg + +box_smol: ; preds = %box_cond + %cast = inttoptr VINT %ext to i8* + br label %box_done + +box_beeg: ; preds = %box_cond + %boxed = call fastcc i8* @gc_alloc(i64 ptrtoint (VINT* getelementptr (VINT, VINT* null, i32 1) to i64)) + %box_uncast = bitcast i8* %boxed to VINT* + store VINT %ext, VINT* %box_uncast + br label %box_done + +box_done: ; preds = %box_beeg, %box_smol + %box_res = phi i8* [ %cast, %box_smol ], [ %boxed, %box_beeg ] + + %solns = call fastcc i8* @gen(i8* %box_res, i8* %box_res) + %n_solns = call fastcc i8* @length(i8* %solns) + + br i1 %cond, label %box_smol1, label %box_beeg1 + +box_smol1: + %solns_smol = ptrtoint i8* %n_solns to VINT + br label %box_done1 + +box_beeg1: + %solns_uncast = bitcast i8* %n_solns to VINT* + %solns_beeg = load VINT, VINT* %solns_uncast + br label %box_done1 + +box_done1: + %res = phi VINT [ %solns_smol, %box_smol1 ], [ %solns_beeg, %box_beeg1 ] + ret VINT %res +} + +define dso_local i32 @main(i32, i8**) optnone noinline { + call void @GC_init() + %cond = icmp ne i32 %0, 2 + br i1 %cond, label %aaa, label %bbb + +aaa: + %a12 = getelementptr inbounds i8*, i8** %1, i64 0 + %a13 = load i8*, i8** %a12, align 8 + %a14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i32 0, i32 0), i8* %a13) + br label %ccc + +bbb: + %a17 = getelementptr inbounds i8*, i8** %1, i64 1 + %a18 = load i8*, i8** %a17, align 8 + %a19 = call i32 @atoi(i8* %a18) + %a21 = call fastcc VINT @count_solns(i32 %a19) + %a22_p = inttoptr VINT %a21 to i8* + %a22 = ptrtoint i8* %a22_p to i32 + %a23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i32 0, i32 0), i32 %a22) + br label %ccc + +ccc: + ret i32 0 +} diff --git a/examples/nq/gglue.ll b/examples/nq/gglue.ll index f78a603..3aa71b6 100644 --- a/examples/nq/gglue.ll +++ b/examples/nq/gglue.ll @@ -4,11 +4,6 @@ declare fastcc i8* @gen(i8*, i8*) declare fastcc i8* @length (i8*) -define fastcc i32 @inc(i32) { - %res = add i32 1, %0 - ret i32 %res -} - define fastcc i32 @"+"(i32, i32) { %res = add i32 %0, %1 ret i32 %res diff --git a/examples/nq/gglue.ll.pp b/examples/nq/gglue.ll.pp new file mode 100644 index 0000000..96a32f2 --- /dev/null +++ b/examples/nq/gglue.ll.pp @@ -0,0 +1,157 @@ +target triple = "x86_64-unknown-linux-gnu" + +declare dso_local void @GC_init() +declare dso_local i32 @atoi(i8*) +declare dso_local i8* @gc_alloc(i64) +declare dso_local i32 @printf(i8*, ...) + +@.str = private unnamed_addr constant [2 x i8] c"p\00", align 1 +@.str.1 = private unnamed_addr constant [7 x i8] c"glue.c\00", align 1 +@__PRETTY_FUNCTION__.gc_alloc = private unnamed_addr constant [23 x i8] c"void *gc_alloc(size_t)\00", align 1 +@.str.2 = private unnamed_addr constant [13 x i8] c"usage: %s n\0A\00", align 1 +@.str.3 = private unnamed_addr constant [4 x i8] c"%i\0A\00", align 1 + +declare fastcc i8* @gen(i8*, i8*) + +declare fastcc i8* @length (i8*) + +define fastcc i8* @"+"(i8*, i8*) { + %cond = icmp ule i64 ptrtoint (VINT* getelementptr (VINT, VINT* null, VINT 1) to i64), ptrtoint (i1** getelementptr (i1*, i1** null, VINT 1) to i64) + br i1 %cond, label %box_smol, label %box_beeg + +box_smol: + %a_smol = ptrtoint i8* %0 to VINT + %b_smol = ptrtoint i8* %1 to VINT + br label %box_done + +box_beeg: + %a_uncast = bitcast i8* %0 to VINT* + %a_beeg = load VINT, VINT* %a_uncast + %b_uncast = bitcast i8* %1 to VINT* + %b_beeg = load VINT, VINT* %b_uncast + br label %box_done + +box_done: + %a = phi VINT [ %a_smol, %box_smol ], [ %a_beeg, %box_beeg ] + %b = phi VINT [ %b_smol, %box_smol ], [ %b_beeg, %box_beeg ] + %sum = add VINT %a, %b + br i1 %cond, label %box_smol1, label %box_beeg1 + +box_smol1: + %sum_smol = inttoptr VINT %sum to i8* + br label %box_done1 + +box_beeg1: + %sum_boxed = call fastcc i8* @gc_alloc(i64 ptrtoint (VINT* getelementptr (VINT, VINT* null, i32 1) to i64)) + %sum_box_cast = bitcast i8* %sum_boxed to VINT* + store VINT %sum, VINT* %sum_box_cast + br label %box_done1 + +box_done1: + %res = phi i8* [ %sum_smol, %box_smol1 ], [ %sum_boxed, %box_beeg1 ] + ret i8* %res +} + +define fastcc i8* @-(i8*, i8*) { + %cond = icmp ule i64 ptrtoint (VINT* getelementptr (VINT, VINT* null, VINT 1) to i64), ptrtoint (i1** getelementptr (i1*, i1** null, VINT 1) to i64) + br i1 %cond, label %box_smol, label %box_beeg + +box_smol: + %a_smol = ptrtoint i8* %0 to VINT + %b_smol = ptrtoint i8* %1 to VINT + br label %box_done + +box_beeg: + %a_uncast = bitcast i8* %0 to VINT* + %a_beeg = load VINT, VINT* %a_uncast + %b_uncast = bitcast i8* %1 to VINT* + %b_beeg = load VINT, VINT* %b_uncast + br label %box_done + +box_done: + %a = phi VINT [ %a_smol, %box_smol ], [ %a_beeg, %box_beeg ] + %b = phi VINT [ %b_smol, %box_smol ], [ %b_beeg, %box_beeg ] + %sum = sub VINT %a, %b + br i1 %cond, label %box_smol1, label %box_beeg1 + +box_smol1: + %sum_smol = inttoptr VINT %sum to i8* + br label %box_done1 + +box_beeg1: + %sum_boxed = call fastcc i8* @gc_alloc(i64 ptrtoint (VINT* getelementptr (VINT, VINT* null, i32 1) to i64)) + %sum_box_cast = bitcast i8* %sum_boxed to VINT* + store VINT %sum, VINT* %sum_box_cast + br label %box_done1 + +box_done1: + %res = phi i8* [ %sum_smol, %box_smol1 ], [ %sum_boxed, %box_beeg1 ] + ret i8* %res +} + +define fastcc VINT @count_solns(i32) { + %ext_p = inttoptr i32 %0 to i8* + %ext = ptrtoint i8* %ext_p to VINT + ; %ext = zext i32 %0 to VINT + br label %box_cond + +box_cond: ; preds = %entry + %cond = icmp ule i64 ptrtoint (VINT* getelementptr (VINT, VINT* null, VINT 1) to i64), ptrtoint (i1** getelementptr (i1*, i1** null, VINT 1) to i64) + br i1 %cond, label %box_smol, label %box_beeg + +box_smol: ; preds = %box_cond + %cast = inttoptr VINT %ext to i8* + br label %box_done + +box_beeg: ; preds = %box_cond + %boxed = call fastcc i8* @gc_alloc(i64 ptrtoint (VINT* getelementptr (VINT, VINT* null, i32 1) to i64)) + %box_uncast = bitcast i8* %boxed to VINT* + store VINT %ext, VINT* %box_uncast + br label %box_done + +box_done: ; preds = %box_beeg, %box_smol + %box_res = phi i8* [ %cast, %box_smol ], [ %boxed, %box_beeg ] + + %solns = call fastcc i8* @gen(i8* %box_res, i8* %box_res) + %n_solns = call fastcc i8* @length(i8* %solns) + + br i1 %cond, label %box_smol1, label %box_beeg1 + +box_smol1: + %solns_smol = ptrtoint i8* %n_solns to VINT + br label %box_done1 + +box_beeg1: + %solns_uncast = bitcast i8* %n_solns to VINT* + %solns_beeg = load VINT, VINT* %solns_uncast + br label %box_done1 + +box_done1: + %res = phi VINT [ %solns_smol, %box_smol1 ], [ %solns_beeg, %box_beeg1 ] + ret VINT %res +} + +define dso_local i32 @main(i32, i8**) optnone noinline { + call void @GC_init() + %cond = icmp ne i32 %0, 2 + br i1 %cond, label %aaa, label %bbb + +aaa: + %a12 = getelementptr inbounds i8*, i8** %1, i64 0 + %a13 = load i8*, i8** %a12, align 8 + %a14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i32 0, i32 0), i8* %a13) + br label %ccc + +bbb: + %a17 = getelementptr inbounds i8*, i8** %1, i64 1 + %a18 = load i8*, i8** %a17, align 8 + %a19 = call i32 @atoi(i8* %a18) + %a21 = call fastcc VINT @count_solns(i32 %a19) + %a22_p = inttoptr VINT %a21 to i8* + %a22 = ptrtoint i8* %a22_p to i32 + %a23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i32 0, i32 0), i32 %a22) + br label %ccc + +ccc: + ret i32 0 +} diff --git a/examples/nq/int-width-test.sh b/examples/nq/int-width-test.sh new file mode 100755 index 0000000..1cbaa6d --- /dev/null +++ b/examples/nq/int-width-test.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +TIME_FORMAT="%U %S" + +echo "boxing, int_width, clang_opts, sinc_opts, call_conv, n, user_time, system_time, result, err" + +for boxing in "always" "never" "smart" ; do + for bit_width in {1..512} ; do + for O in "-O0" "-O1" "-O2" "-O3" "-Obest" ; do + for sincopt in "-O tail-recursive-mod-cons" "" ; do + for call_conv in "ccc" "fastcc" "coldcc" "'cc 10'" "webkit_jscc" "anyregcc" "preserve_mostcc" "preserve_allcc" "cxx_fast_tlscc" "swiftcc" ; do + make clean --silent + BOXING=$boxing INTWIDTH=$bit_width CLANGOPT=$O SINCOPT="$sincopt" CALLCONV="$call_conv" make --silent 2> "make-err.txt" + if [ $? -eq 0 ]; then + : + else + continue + fi + + for n in {1..10} ; do + echo -n > "nqueens-out.txt" + /bin/time -qf "$boxing, $bit_width, $O, $sincopt, $call_conv, $n, %U, %S" -o "time-out.txt" ./nqueens $n >> "nqueens-out.txt" 2> "nqueens-err.txt" + < "time-out.txt" tr -d '\n' + echo -n ", \"" + cat "nqueens-out.txt" | tr -d '\n' + echo -n "\", \"" + cat "nqueens-err.txt" | tr -d '\n' + echo "\"" + done + done + done + done + done +done diff --git a/examples/nq/nqueens.sin b/examples/nq/nqueens.sin index 35777fd..9d6917b 100644 --- a/examples/nq/nqueens.sin +++ b/examples/nq/nqueens.sin @@ -1,32 +1,117 @@ -[dec != [x y]] -[dec and [x y]] +[type closure_ [func arity arg_c args]] +[type list_ [kind head tail]] +[type nil_ [kind]] +[type left_ [kind val]] +[type right_ [kind val]] -[dec cons [x xs]] -[dec head [xs]] -[dec tail [xs]] -[dec nil []] -[dec is_nil [xs]] -[dec flatten [xs]] -[dec .. [x y]] -[dec length [xs]] -[dec map [f xs]] -[dec foldl [f acc xs]] -[dec concat [xs ys]] +[dec + [x y]] +[dec - [x y]] +[dec run_func [f arity args]] -[dec left.val [x]] +[def head [xs] + [list_.head xs]] -[dec pure [x]] -[dec empty []] -[dec return [x]] +[def tail [xs] + [list_.tail xs]] -[dec !map [c as]] -[dec !> [c a]] -[dec closure [f a]] +[def cons [h t] + [list_ 0 h t]] -[dec count_solns [n]] +[def nil [] + [nil_ 1]] -[dec + [x y]] -[dec - [x y]] +[def is_nil [xs] + [if [nil_.kind xs] + 1 + 0]] + +[def left [val] + [left_ 0 val]] + +[def right [val] + [right_ 1 val]] + +[def left.val [x] + [left_.val x]] + +[def right.val [x] + [right_.val x]] + +[def is_right [x] + [right_.kind x]] + +[def is_left [x] + [if [is_right x] + 0 + 1]] + +[def not [x] + [if x + 0 + 1]] + +[def and [x y] + [if x + y + 0]] + +[def != [x y] + [- x y]] + +[def = [x y] + [not [!= x y]]] + +[def inc [x] + [+ x 1]] + +[def append [xs x] + [if [is_nil xs] + [cons x [nil]] + [cons [head xs] [append [tail xs] x]]]] + +[def add_arg [c a] + [closure_ [closure_.func c] + [closure_.arity c] + [inc [closure_.arg_c c]] + [append [closure_.args c] a]]] + +[def wake [h] + [run_func [closure_.func h] [closure_.arity h] [closure_.args h]]] + +[def closure [f v] + [closure_ f v 0 [nil]]] + +[def _length [xs n] + [if [is_nil xs] + n + [_length [tail xs] [inc n]]]] + +[def length [xs] + [_length xs 0]] + +[def concat [as bs] + [if [is_nil as] + bs + [cons [head as] [concat [tail as] bs]]]] + +[def flatten [xs] + [if [is_nil xs] + [nil] + [concat [head xs] [flatten [tail xs]]]]] + +[def .. [x y] + [if [= x y] + [cons x [nil]] + [cons x [.. [+ x 1] y]]]] + +[def pure [x] + [cons x [nil]]] + +[def empty [] + [nil]] + +[def return [x] + [cons x [nil]]] [def safe [x d qs] [if [is_nil qs] @@ -41,45 +126,33 @@ [pure 0] [empty]]] -[def !. [g f x] - [!> g [f x]]] - -[def .! [g f x] - [g [left.val [!> f x]]]] - -[def !.! [g f x] - [!> g [!> f x]]] - -[def !foldl [c acc xs] +[def foldl [c acc xs] [if [is_nil xs] acc - [!foldl c [left.val [!> [!> c acc] [head xs]]] [tail xs]]]] - -[def !concatMapClosure [c acc x] - [concat acc [left.val [!> c x]]]] + [foldl c [wake [add_arg [add_arg c acc] [head xs]]] [tail xs]]]] -[def !concatMap [c xs] - [!foldl [!> [closure !concatMapClosure 3] c] [nil] xs]] +[def concatMapClosure [c acc x] + [concat acc [wake [add_arg c x]]]] -[def _!>>= [xs c] - [flatten [map left.val [!map c xs]]]] +[def concatMap [c xs] + [foldl [add_arg [closure concatMapClosure 3] c] [nil] xs]] -[def !>>= [xs c] - [!concatMap c xs]] +[def >>= [xs c] + [concatMap c xs]] [def gen_1_1_1 [q b _] [return [cons q b]]] [def gen_1_1 [b q] - [!>>= [guard [safe q 1 b]] - [!> [!> [closure gen_1_1_1 3] q] b]]] + [>>= [guard [safe q 1 b]] + [add_arg [add_arg [closure gen_1_1_1 3] q] b]]] [def gen_1 [nq b] - [!>>= [.. 1 nq] - [!> [closure gen_1_1 2] b]]] + [>>= [.. 1 nq] + [add_arg [closure gen_1_1 2] b]]] [def gen [n nq] [if n - [!>>= [gen [- n 1] nq] - [!> [closure gen_1 2] nq]] + [>>= [gen [- n 1] nq] + [add_arg [closure gen_1 2] nq]] [cons [nil] [nil]]]] |
