-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c31a0ae
commit 922d072
Showing
8 changed files
with
150 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,17 @@ | ||
BUILD_DIR=$(abspath build) | ||
|
||
.PHONY: algo unit integration | ||
.PHONY: algo integration perf unit | ||
|
||
all: algo unit integration | ||
all: algo integration unit | ||
|
||
algo: | ||
$(MAKE) -C algo BUILD_DIR=$(BUILD_DIR) | ||
|
||
unit: | ||
$(MAKE) -C unit BUILD_DIR=$(BUILD_DIR) | ||
|
||
integration: | ||
$(MAKE) -C integration BUILD_DIR=$(BUILD_DIR) | ||
|
||
perf: | ||
$(MAKE) -C perf BUILD_DIR=$(BUILD_DIR) | ||
|
||
unit: | ||
$(MAKE) -C unit BUILD_DIR=$(BUILD_DIR) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
ALFLAGS=-i altlib ../../altlib/ | ||
CFLAGS=-g -fno-stack-protector -I include -I ../../stdlib/include | ||
LDFLAGS=-z noexecstack | ||
|
||
SRCS_AL := $(wildcard *.al) | ||
EXES_AL := $(patsubst %.al, $(BUILD_DIR)/test/perf/%, $(SRCS_AL)) | ||
|
||
OBJS_ARCH := $(wildcard $(BUILD_DIR)/arch/*.o) | ||
OBJS_ALTLIB := $(wildcard $(BUILD_DIR)/altlib/*.o) | ||
OBJS_STDLIB := $(wildcard $(BUILD_DIR)/stdlib/*.o) | ||
|
||
all: $(EXES_AL) | ||
|
||
$(BUILD_DIR)/test/perf/%: %.al make_dir | ||
echo $(patsubst %.al, %, $<) > $(patsubst %, %_report, $@) | ||
|
||
$(BUILD_DIR)/calias -a $(ALFLAGS) $< -o $(patsubst %, %1.o, $@) | ||
ld $(LDFLAGS) -o $(patsubst %, %1, $@) $(patsubst %, %1.o, $@) $(OBJS_ARCH) $(OBJS_ALTLIB) | ||
{ time -p $(patsubst %, %1, $@) ; } 2>&1 | grep real | awk '{print $$2}' >> $(patsubst %, %_report, $@) | ||
|
||
gcc $(CFLAGS) -c $(patsubst %.al, %.c, $<) -o $(patsubst %, %2.o, $@) | ||
gcc $(LDFLAGS) -o $(patsubst %, %2, $@) $(patsubst %, %2.o, $@) $(OBJS_ARCH) $(OBJS_STDLIB) | ||
{ time -p $(patsubst %, %2, $@) ; } 2>&1 | grep real | awk '{print $$2}' >> $(patsubst %, %_report, $@) | ||
|
||
make_dir: | ||
mkdir -p $(BUILD_DIR)/test/perf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
include altlib."posix.al" | ||
include altlib."stdio.al" | ||
include altlib."test_allocator.al" | ||
|
||
func .merge_sort(a #1I, lx #I, rx #I, allocator #1TestAllocator) -> #V { | ||
eval if (rx - lx > 1) { | ||
def m := (lx + rx) / 2 | ||
eval merge_sort(a, lx, m, allocator) | ||
eval merge_sort(a, m, rx, allocator) | ||
def b := allocator.alloc((rx - lx) * $#I) | ||
def ptr1 := lx | ||
def ptr2 := m | ||
def ptr3 := 0 | ||
eval while (ptr3 < rx - lx) { | ||
eval if (ptr1 < m and (ptr2 = rx or a[ptr1] < a[ptr2])) { | ||
b[ptr3]& <- a[ptr1] | ||
ptr1 := ptr1 + 1 | ||
} | ||
else { | ||
b[ptr3]& <- a[ptr2] | ||
ptr2 := ptr2 + 1 | ||
} | ||
ptr3 := ptr3 + 1 | ||
} | ||
ptr3 := 0 | ||
eval while (ptr3 < rx - lx) { | ||
a[lx + ptr3]& <- b[ptr3] | ||
ptr3 := ptr3 + 1 | ||
} | ||
} | ||
} | ||
|
||
func ^._start() -> #V { | ||
def allocator #TestAllocator | ||
eval allocator&.init(1024 * 1024 * 1024) | ||
defer eval allocator&.deinit() | ||
|
||
def n := 1000000 | ||
def a := allocator&.alloc(n * $#I) as #1I | ||
def i := 0 | ||
def seed := 123 | ||
eval while (i < n) { | ||
a[i]& <- rand_(seed) | ||
seed := a[i] | ||
i := i + 1 | ||
} | ||
|
||
eval merge_sort(a, 0, n, allocator&) | ||
|
||
eval posix_exit(0) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
void merge_sort(int *a, int lx, int rx) { | ||
if (rx - lx > 1) { | ||
int m = (lx + rx) / 2; | ||
merge_sort(a, lx, m); | ||
merge_sort(a, m, rx); | ||
|
||
int *b = _malloc((rx - lx) * sizeof(int)); | ||
int ptr1 = lx, ptr2 = m, ptr3 = 0; | ||
while (ptr3 < rx - lx) { | ||
if (ptr1 < m && (ptr2 == rx || a[ptr1] < a[ptr2])) { | ||
b[ptr3] = a[ptr1]; | ||
ptr1 += 1; | ||
} | ||
else { | ||
b[ptr3] = a[ptr2]; | ||
ptr2++; | ||
} | ||
ptr3++; | ||
} | ||
ptr3 = 0; | ||
while (ptr3 < rx - lx) { | ||
a[lx + ptr3] = b[ptr3]; | ||
ptr3++; | ||
} | ||
} | ||
} | ||
|
||
int main() { | ||
int n = 1000000; | ||
int *a = _malloc(n * sizeof(int)); | ||
int seed = 123; | ||
for (int i = 0; i < n; i++) { | ||
a[i] = _rand(seed); | ||
seed = a[i]; | ||
} | ||
|
||
merge_sort(a, 0, n); | ||
for(int i=0;i<n;i++) _puti(a[i]); | ||
|
||
return 0; | ||
} |