Skip to content

Commit

Permalink
bump
Browse files Browse the repository at this point in the history
  • Loading branch information
ShawSumma committed Jul 26, 2024
1 parent 230658e commit 21eb15e
Show file tree
Hide file tree
Showing 20 changed files with 243 additions and 856 deletions.
34 changes: 34 additions & 0 deletions main/primes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import sympy

max_width = 60
n = 32
ls = [4, 8, 16]

with open('vm/primes.inc', 'w') as f:
p32 = 2 ** 32
while True:
p = sympy.prevprime(int(n)+1)
if p >= p32:
break
ls.append(p)
n *= 1.75
ml = max(map(len, map(str, ls)))
n = (max_width - 5) // (ml + 2)
f.write(f'// generated by: python3 main/primes.py\n\n')
f.write(f'static const uint64_t vm_primes_table[{len(ls)}] = ' + '{\n ')
for i, p in enumerate(ls):
s = str(p)
s = ' ' * (ml - len(s)) + s
f.write(f' {s},')
if i % n == n - 1:
f.write('\n ')
f.write('\n};\n\n')
f.write('static const uint64_t vm_primes_mod(uint8_t p, size_t n) {\n')
f.write(' switch (p) {\n')
f.write(' default:\n')
f.write(' __builtin_unreachable();\n')
for i, p in enumerate(ls):
f.write(f' case {i}:\n')
f.write(f' return n % {p};\n')
f.write(' }\n')
f.write('}\n')
30 changes: 28 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ OPT ?= -O2 -flto

EXE ?=

TIME_CMD ?= $(shell which gdate || which date) +%s%3N

# Reset flags for base
BASE_CFLAGS := ${OPT} -Ivendor/tree-sitter/lib/include -Ivendor/tree-sitter/lib/src ${CFLAGS}
BASE_LDFLAGS := ${OPT} ${LDFLAGS} -lm
Expand All @@ -22,24 +24,40 @@ MAIN_DEPS = ${MAIN_SRCS:%.c=build/dep/%.dep}

MAKE_INCLUDE ?=

# tests

TEST_LUAS := $(shell find test -name '*.lua')
TEST_TXTS = ${TEST_LUAS:%.lua=build/test/%.log}

# setup targets
default: all

all: minivm

minivm: build/bin/minivm${EXE}

test tests: ${TEST_TXTS}
find . -name '*.time' | xargs -I{} sh -c 'echo $$(cat {}) {}' | sort -n > build/bench/all.txt

# specific builds
clean: .dummy
rm -rf build

gcc-pgo: .dummy
$(MAKE) -Bj build/bin/minivm OPT="-O3 -flto=auto -fgcse-sm -fgcse-las -fipa-pta -fdevirtualize-at-ltrans -fdevirtualize-speculatively -fno-exceptions -fomit-frame-pointer -fprofile-generate -DNDEBUG"
$(MAKE) -Bj minivm OPT="-O3 -flto=auto -fgcse-sm -fgcse-las -fipa-pta -fdevirtualize-at-ltrans -fdevirtualize-speculatively -fno-exceptions -fomit-frame-pointer -fprofile-generate -DNDEBUG"
build/bin/minivm test/fib/fib.lua
build/bin/minivm test/tables/trees.lua
build/bin/minivm test/closure/funcret.lua
build/bin/minivm test/loop/eval.lua
$(MAKE) -Bj build/bin/minivm OPT="-O3 -flto=auto -fgcse-sm -fgcse-las -fipa-pta -fdevirtualize-at-ltrans -fdevirtualize-speculatively -fno-exceptions -fomit-frame-pointer -fprofile-use -DNDEBUG"
$(MAKE) -Bj minivm OPT="-O3 -flto=auto -fgcse-sm -fgcse-las -fipa-pta -fdevirtualize-at-ltrans -fdevirtualize-speculatively -fno-exceptions -fomit-frame-pointer -fprofile-use -DNDEBUG"

clang-pgo: .dummy
$(MAKE) -Bj minivm OPT="-O3 -flto=auto -fno-exceptions -fomit-frame-pointer -fprofile-generate -DNDEBUG"
build/bin/minivm test/fib/fib.lua
build/bin/minivm test/tables/trees.lua
build/bin/minivm test/closure/funcret.lua
build/bin/minivm test/loop/eval.lua
$(MAKE) -Bj minivm OPT="-O3 -flto=auto -fno-exceptions -fomit-frame-pointer -fprofile-use -DNDEBUG"

wasm: .dummy
$(MAKE) -Bj CC=emcc EXE=.wasm \
Expand All @@ -51,6 +69,14 @@ build/bin/minivm${EXE}: ${MAIN_OBJS}
@mkdir -p ${dir ${@}}
${CC} -o ${@} ${MAIN_OBJS} ${BASE_LDFLAGS}

${TEST_TXTS}: ${@:build/test/%.log=%.lua} minivm
@mkdir -p ${dir ${@}}
@mkdir -p ${dir ${@:build/test/%.log=build/bench/%.time}}
START_TIME=$$(${TIME_CMD}); \
build/bin/minivm${EXE} ${@:build/test/%.log=%.lua} > ${@}; \
END_TIME=$$(${TIME_CMD}); \
echo "$$END_TIME $$START_TIME - p" | dc > ${@:build/test/%.log=build/bench/%.time}

${MAIN_OBJS}:
@mkdir -p ${dir ${@}}
@mkdir -p ${dir ${@:build/obj/%.o=build/dep/%.dep}}
Expand Down
146 changes: 0 additions & 146 deletions test/app/dig.lua

This file was deleted.

32 changes: 0 additions & 32 deletions test/app/draw.lua

This file was deleted.

Loading

0 comments on commit 21eb15e

Please sign in to comment.