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

Compatibility with Nim v1.6.x, Nim v2.0.x, Nim v2.2.x #434

Merged
merged 1 commit into from
Jul 17, 2024
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
8 changes: 3 additions & 5 deletions constantine/math/endomorphisms/split_scalars.nim
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,8 @@ template decomposeEndoImpl[scalBits: static int](
static: doAssert L >= ceilDiv_vartime(frBits, M) + 1
const w = frBits.wordsRequired()

# Upstream bug:
# {.noInit.} variables must be {.inject.} as well
# or they'll be mangled as foo`gensym12345 instead of fooX60gensym12345 in C codegen

when M == 2:
# inject works around alphas'gensym codegen in Nim v2.0.8 (not necessary in Nim v2.2.x) - https://github.com/nim-lang/Nim/pull/23801#issue-2393452970
var alphas{.noInit, inject.}: (
BigInt[frBits + babai(Name, G)[0][0].bits],
BigInt[frBits + babai(Name, G)[1][0].bits]
Expand All @@ -76,7 +73,8 @@ template decomposeEndoImpl[scalBits: static int](
# We have k0 = s - 𝛼0 b00 - 𝛼1 b10 ... - 𝛼m bm0
# and kj = 0 - 𝛼j b0j - 𝛼1 b1j ... - 𝛼m bmj
var
k {.inject.}: array[M, BigInt[frBits]] # zero-init required
k {.inject.}: array[M, BigInt[frBits]] # zero-init required, and inject for caller visibility
# inject works around alphas'gensym codegen in Nim v2.0.8 (not necessary in Nim v2.2.x) - https://github.com/nim-lang/Nim/pull/23801#issue-2393452970
alphaB {.noInit, inject.}: BigInt[frBits]
k[0].copyTruncatedFrom(scalar)
staticFor miniScalarIdx, 0, M:
Expand Down
12 changes: 5 additions & 7 deletions constantine/math/extension_fields/towers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1436,15 +1436,14 @@ func mul_sparse_by_x0*(a: var QuadraticExt, sparseB: QuadraticExt) =
## Sparse in-place multiplication
a.mul_sparse_by_x0(a, sparseB)

func mulCheckSparse*(a: var QuadraticExt, b: static QuadraticExt) {.inline.} =
template mulCheckSparse*(a: var QuadraticExt, b: QuadraticExt) =
when isOne(b).bool:
discard
elif isMinusOne(b).bool:
a.neg()
elif isZero(c0(b)).bool and isOne(c1(b)).bool:
# TODO: raise upstream, in Nim v2 templates {.noInit.} temporaries use incorrect t`gensymXXXX
# hence we use an inline function with static argument
var t {.noInit.}: type(a.c0)
# inject works around t'gensym codegen in Nim v2.0.8 (not necessary in Nim v2.2.x) - https://github.com/nim-lang/Nim/pull/23801#issue-2393452970
var t {.noInit, inject.}: type(a.c0)
when fromComplexExtension(b):
t.neg(a.c1)
a.c1 = a.c0
Expand All @@ -1454,9 +1453,8 @@ func mulCheckSparse*(a: var QuadraticExt, b: static QuadraticExt) {.inline.} =
a.c1 = a.c0
a.c0 = t
elif isZero(c0(b)).bool and isMinusOne(c1(b)).bool:
# TODO: raise upstream, in Nim v2 templates {.noInit.} temporaries use incorrect t`gensymXXXX
# hence we use an inline function with static argument
var t {.noInit.}: type(a.c0)
# inject works around t'gensym codegen in Nim v2.0.8 (not necessary in Nim v2.2.x) - https://github.com/nim-lang/Nim/pull/23801#issue-2393452970
var t {.noInit, inject.}: type(a.c0)
when fromComplexExtension(b):
t = a.c1
a.c1.neg(a.c0)
Expand Down
Loading