mirror of
https://github.com/saymrwulf/pasta_curves-source.git
synced 2026-09-04 20:03:39 +00:00
Implement ec_gpu:GpuField for Fp/Fq
This commit introduces a new feature called "gpu", which enables an
`ec_gpu:GpuField` implementation of `Fp` and `Fq`. This enables the
field arithmetics to be run on a GPU.
The code to convert from a u64 to a u32 vector was taken from
07a84f9727/src/lib.rs (L102-L108)
This commit is contained in:
parent
de99732e20
commit
870939ab03
4 changed files with 42 additions and 0 deletions
|
|
@ -53,8 +53,12 @@ blake2b_simd = { version = "1", optional = true, default-features = false }
|
||||||
# sqrt-table dependencies
|
# sqrt-table dependencies
|
||||||
lazy_static = { version = "1.4.0", optional = true }
|
lazy_static = { version = "1.4.0", optional = true }
|
||||||
|
|
||||||
|
# gpu dependencies
|
||||||
|
ec-gpu = { version = "0.1.0", optional = true }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["bits", "sqrt-table"]
|
default = ["bits", "sqrt-table"]
|
||||||
alloc = ["group/alloc", "blake2b_simd"]
|
alloc = ["group/alloc", "blake2b_simd"]
|
||||||
bits = ["ff/bits"]
|
bits = ["ff/bits"]
|
||||||
|
gpu = ["alloc", "ec-gpu"]
|
||||||
sqrt-table = ["alloc", "lazy_static"]
|
sqrt-table = ["alloc", "lazy_static"]
|
||||||
|
|
|
||||||
|
|
@ -6,3 +6,11 @@ mod fq;
|
||||||
|
|
||||||
pub use fp::*;
|
pub use fp::*;
|
||||||
pub use fq::*;
|
pub use fq::*;
|
||||||
|
|
||||||
|
#[cfg(feature = "gpu")]
|
||||||
|
fn u64_to_u32(limbs: &[u64]) -> alloc::vec::Vec<u32> {
|
||||||
|
limbs
|
||||||
|
.iter()
|
||||||
|
.flat_map(|limb| alloc::vec![(limb & 0xFFFF_FFFF) as u32, (limb >> 32) as u32])
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -770,6 +770,21 @@ impl FieldExt for Fp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "gpu")]
|
||||||
|
impl ec_gpu::GpuField for Fp {
|
||||||
|
fn one() -> alloc::vec::Vec<u32> {
|
||||||
|
crate::fields::u64_to_u32(&R.0[..])
|
||||||
|
}
|
||||||
|
|
||||||
|
fn r2() -> alloc::vec::Vec<u32> {
|
||||||
|
crate::fields::u64_to_u32(&R2.0[..])
|
||||||
|
}
|
||||||
|
|
||||||
|
fn modulus() -> alloc::vec::Vec<u32> {
|
||||||
|
crate::fields::u64_to_u32(&MODULUS.0[..])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
use ff::Field;
|
use ff::Field;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -769,6 +769,21 @@ impl FieldExt for Fq {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "gpu")]
|
||||||
|
impl ec_gpu::GpuField for Fq {
|
||||||
|
fn one() -> alloc::vec::Vec<u32> {
|
||||||
|
crate::fields::u64_to_u32(&R.0[..])
|
||||||
|
}
|
||||||
|
|
||||||
|
fn r2() -> alloc::vec::Vec<u32> {
|
||||||
|
crate::fields::u64_to_u32(&R2.0[..])
|
||||||
|
}
|
||||||
|
|
||||||
|
fn modulus() -> alloc::vec::Vec<u32> {
|
||||||
|
crate::fields::u64_to_u32(&MODULUS.0[..])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
use ff::Field;
|
use ff::Field;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue