Skip to content

Commit

Permalink
workaround {.noInit.} mangling in templates
Browse files Browse the repository at this point in the history
  • Loading branch information
mratsim committed Jan 20, 2024
1 parent 173900f commit 887e3c8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions constantine/math/elliptic/ec_endomorphism_accel.nim
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,17 @@ template decomposeEndoImpl[scalBits: static int](
static: doAssert L >= ceilDiv_vartime(scalBits, M) + 1
const w = F.C.getCurveOrderBitwidth().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:
var alphas{.noInit.}: (
var alphas{.noInit, inject.}: (
BigInt[scalBits + babai(F)[0][0].bits],
BigInt[scalBits + babai(F)[1][0].bits]
)
elif M == 4:
var alphas{.noInit.}: (
var alphas{.noInit, inject.}: (
BigInt[scalBits + babai(F)[0][0].bits],
BigInt[scalBits + babai(F)[1][0].bits],
BigInt[scalBits + babai(F)[2][0].bits],
Expand All @@ -72,7 +76,7 @@ template decomposeEndoImpl[scalBits: static int](
# and kj = 0 - 𝛼j b0j - 𝛼1 b1j ... - 𝛼m bmj
var
k {.inject.}: array[M, BigInt[scalBits]] # zero-init required
alphaB {.noInit.}: BigInt[scalBits]
alphaB {.noInit, inject.}: BigInt[scalBits]
k[0] = scalar
staticFor miniScalarIdx, 0, M:
staticFor basisIdx, 0, M:
Expand Down
2 changes: 1 addition & 1 deletion constantine/math/elliptic/ec_multi_scalar_mul_parallel.nim
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ proc msmAffine_vartime_parallel[bits: static int, EC, ECaff](

# Prologue
# --------
const numBuckets = 1 shl (c-1)
const numBuckets {.used.} = 1 shl (c-1)
const numFullWindows = bits div c
const numWindows = numFullWindows + 1 # Even if `bits div c` is exact, the signed recoding needs to see an extra 0 after the MSB

Expand Down

0 comments on commit 887e3c8

Please sign in to comment.