Skip to content

Commit

Permalink
gt: rework conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
mratsim committed Nov 27, 2024
1 parent 298d33b commit db2e9c9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
6 changes: 3 additions & 3 deletions constantine/math/pairings/gt_multiexp.nim
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,9 @@ template withTorus[exponentsBits: static int, GT](
static: doAssert Gt is QuadraticExt, "GT was: " & $Gt
type F = typeof(elems[0].c0)
var elemsTorus = allocHeapArrayAligned(T2Aff[F], len, alignment = 64)
elemsTorus.toOpenArray(0, len-1).batchFromGT_vartime(
elems.toOpenArray(0, len-1)
)
batchFromGT_vartime(
elemsTorus.toOpenArray(0, len-1),
elems.toOpenArray(0, len-1))
var r_torus {.noInit.}: T2Prj[F]
multiExpProc(r_torus, elemsTorus, expos, len, c)
r.fromTorus2_vartime(r_torus)
Expand Down
28 changes: 19 additions & 9 deletions constantine/math/pairings/gt_multiexp_parallel.nim
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,24 @@ template withEndo[exponentsBits: static int, GT](
# Torus acceleration
# -----------------------------------------------------------------------------------------------------------------------

proc paraNaiveConversion[F](
tp: Threadpool,
dst: ptr UncheckedArray[T2Aff[F]],
src: ptr UncheckedArray[QuadraticExt[F]],
N: int) =

# Cryptic error
# Error: cannot use symbol of kind 'param' as a 'let'
# if we inline the following in the `withTorus` template

# TODO: Parallel Montgomery batch inversion

syncScope:
tp.parallelFor i in 0 ..< N:
captures: {dst, src}
# TODO: Parallel batch conversion
fromGT_vartime(dst[i], src[i])

template withTorus[exponentsBits: static int, GT](
multiExpProc: untyped,
tp: Threadpool,
Expand All @@ -173,15 +191,7 @@ template withTorus[exponentsBits: static int, GT](
static: doAssert Gt is QuadraticExt, "GT was: " & $Gt
type F = typeof(elems[0].c0)
var elemsTorus = allocHeapArrayAligned(T2Aff[F], len, alignment = 64)
# TODO: macro symbol resolution bug
# syncScope:
# tp.parallelFor i in 0 ..< N:
# captures: {elems, elemsTorus}
# # TODO: Parallel batch conversion
# elemsTorus.fromGT_vartime(elems[i])
elemsTorus.toOpenArray(0, len-1).batchFromGT_vartime(
elems.toOpenArray(0, len-1)
)
paraNaiveConversion(tp, elemsTorus, elems, len)
var r_torus {.noInit.}: T2Prj[F]
multiExpProc(tp, r_torus.addr, elemsTorus, expos, len, c)
r[].fromTorus2_vartime(r_torus)
Expand Down

0 comments on commit db2e9c9

Please sign in to comment.