Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uint - allow compile-time evaluation for all procs #54

Merged
merged 3 commits into from
Jun 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions benchmarks/bench_mod.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ../stint/mpint, times
import ../stint, times


# Warmup on normal int
Expand All @@ -18,10 +18,10 @@ echo "Warmup: " & $(stop - start) & "s"

start = cpuTime()
block:
var foo = 123.u(256)
var foo = 123.u256
for i in 0 ..< 10_000_000:
foo += i.u(256) * i.u(256) mod 456.u(256)
foo = foo mod 789.u(256)
foo += i.u256 * i.u256 mod 456.u256
foo = foo mod 789.u256

stop = cpuTime()
echo "Library: " & $(stop - start) & "s"
Expand All @@ -47,3 +47,9 @@ when defined(bench_ttmath):
# Warmup: 0.04060799999999999s
# Library: 0.9576759999999999s
# TTMath: 0.758443s


# After PR #54 for compile-time evaluation
# which includes loop unrolling but may bloat the code
# Warmup: 0.03993500000000001s
# Library: 0.848464s
6 changes: 3 additions & 3 deletions stint/private/as_signed_words.nim
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ proc isInt*(x: NimNode): static[bool] =
elif eqIdent(x, "int8"): true
else: false

macro most_significant_word*(x: IntImpl): untyped =
macro most_significant_word_signed*(x: IntImpl): untyped =

let optim_type = optimInt(x)
if optim_type.isInt:
Expand Down Expand Up @@ -87,8 +87,8 @@ macro asSignedWordsZip*[T](
first_y = quote do:
cast[`optim_type`](`y`)
else:
first_x = getAST(most_significant_word(x))
first_y = getAST(most_significant_word(y))
first_x = getAST(most_significant_word_signed(x))
first_y = getAST(most_significant_word_signed(y))

replacing.add first_x
replacing.add first_y
Expand Down
Loading