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

Implement ec_gpu:GpuField for Fp/Fq #31

Merged
merged 4 commits into from
Mar 24, 2022
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
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ blake2b_simd = { version = "1", optional = true, default-features = false }
# sqrt-table dependencies
lazy_static = { version = "1.4.0", optional = true }

# gpu dependencies
ec-gpu = { version = "0.1.0", optional = true }

[features]
default = ["bits", "sqrt-table"]
alloc = ["group/alloc", "blake2b_simd"]
bits = ["ff/bits"]
gpu = ["alloc", "ec-gpu"]
sqrt-table = ["alloc", "lazy_static"]
13 changes: 13 additions & 0 deletions src/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,16 @@ mod fq;

pub use fp::*;
pub use fq::*;

/// Converts 64-bit little-endian limbs to 32-bit little endian limbs.
#[cfg(feature = "gpu")]
fn u64_to_u32(limbs: &[u64]) -> alloc::vec::Vec<u32> {
str4d marked this conversation as resolved.
Show resolved Hide resolved
limbs
.iter()
.flat_map(|limb| {
Some((limb & 0xFFFF_FFFF) as u32)
.into_iter()
.chain(Some((limb >> 32) as u32))
})
.collect()
}
15 changes: 15 additions & 0 deletions src/fields/fp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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[..])
}
str4d marked this conversation as resolved.
Show resolved Hide resolved

fn modulus() -> alloc::vec::Vec<u32> {
crate::fields::u64_to_u32(&MODULUS.0[..])
}
}

#[cfg(test)]
use ff::Field;

Expand Down
15 changes: 15 additions & 0 deletions src/fields/fq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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[..])
str4d marked this conversation as resolved.
Show resolved Hide resolved
}

fn modulus() -> alloc::vec::Vec<u32> {
crate::fields::u64_to_u32(&MODULUS.0[..])
}
}

#[cfg(test)]
use ff::Field;

Expand Down