forked from nim-lang/Nim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for nim-lang#23854 and nim-lang#23855, prepare for cleanup
- Loading branch information
Showing
5 changed files
with
127 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# issue #23854 | ||
|
||
import std/bitops | ||
|
||
const WordBitWidth = sizeof(pointer) * 8 | ||
|
||
func wordsRequired*(bits: int): int {.inline.} = | ||
const divShiftor = fastLog2(uint32(WordBitWidth)) | ||
result = (bits + WordBitWidth - 1) shr divShiftor | ||
|
||
type | ||
Algebra* = enum | ||
BLS12_381 | ||
|
||
BigInt*[bits: static int] = object | ||
limbs*: array[wordsRequired(bits), uint] | ||
|
||
Fr*[Name: static Algebra] = object | ||
residue_form*: BigInt[255] | ||
|
||
Fp*[Name: static Algebra] = object | ||
residue_form*: BigInt[381] | ||
|
||
FF*[Name: static Algebra] = Fp[Name] or Fr[Name] | ||
|
||
type | ||
EC_ShortW_Aff*[F] = object | ||
## Elliptic curve point for a curve in Short Weierstrass form | ||
## y² = x³ + a x + b | ||
## | ||
## over a field F | ||
x*, y*: F | ||
|
||
type FieldKind* = enum | ||
kBaseField | ||
kScalarField | ||
|
||
template getBigInt*[Name: static Algebra](T: type FF[Name]): untyped = | ||
## Get the underlying BigInt type. | ||
BigInt[123] | ||
|
||
func bits*[Name: static Algebra](T: type FF[Name]): static int = | ||
T.getBigInt().bits | ||
|
||
template getScalarField*(EC: type EC_ShortW_Aff): untyped = | ||
Fr[EC.F.Name] | ||
|
||
# ------------------------------------------------------------------------------ | ||
|
||
type | ||
ECFFT_Descriptor*[EC] = object | ||
## Metadata for FFT on Elliptic Curve | ||
order*: int | ||
rootsOfUnity1*: ptr UncheckedArray[BigInt[EC.getScalarField().bits()]] # Error: in expression 'EC.getScalarField()': identifier expected, but found 'EC.getScalarField' | ||
rootsOfUnity2*: ptr UncheckedArray[BigInt[getScalarField(EC).bits()]] # Compiler SIGSEGV: Illegal Storage Access | ||
|
||
func new*(T: type ECFFT_Descriptor): T = | ||
discard | ||
|
||
# ------------------------------------------------------------------------------ | ||
|
||
proc main() = | ||
let ctx = ECFFT_Descriptor[EC_ShortW_Aff[Fp[BLS12_381]]].new() | ||
|
||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# issue #23855 | ||
|
||
import std/bitops | ||
|
||
const WordBitWidth = sizeof(pointer) * 8 | ||
|
||
func wordsRequired*(bits: int): int {.inline.} = | ||
const divShiftor = fastLog2(uint32(WordBitWidth)) | ||
result = (bits + WordBitWidth - 1) shr divShiftor | ||
|
||
type | ||
Algebra* = enum | ||
BLS12_381 | ||
|
||
BigInt*[bits: static int] = object | ||
limbs*: array[wordsRequired(bits), uint] | ||
|
||
Fr*[Name: static Algebra] = object | ||
residue_form*: BigInt[255] | ||
|
||
Fp*[Name: static Algebra] = object | ||
residue_form*: BigInt[381] | ||
|
||
FF*[Name: static Algebra] = Fp[Name] or Fr[Name] | ||
|
||
template getBigInt*[Name: static Algebra](T: type FF[Name]): untyped = | ||
## Get the underlying BigInt type. | ||
BigInt[123] | ||
|
||
type | ||
EC_ShortW_Aff*[F] = object | ||
## Elliptic curve point for a curve in Short Weierstrass form | ||
## y² = x³ + a x + b | ||
## | ||
## over a field F | ||
x*, y*: F | ||
|
||
func bits*[Name: static Algebra](T: type FF[Name]): static int = | ||
T.getBigInt().bits | ||
|
||
# ------------------------------------------------------------------------------ | ||
|
||
type | ||
ECFFT_Descriptor*[EC] = object | ||
## Metadata for FFT on Elliptic Curve | ||
order*: int | ||
rootsOfUnity*: ptr UncheckedArray[BigInt[Fr[EC.F.Name].bits()]] # Undeclared identifier `Name` | ||
|
||
func new*(T: type ECFFT_Descriptor): T = | ||
discard | ||
|
||
# ------------------------------------------------------------------------------ | ||
|
||
proc main() = | ||
let ctx = ECFFT_Descriptor[EC_ShortW_Aff[Fp[BLS12_381]]].new() | ||
|
||
main() |