Skip to content

Commit

Permalink
fix wasm build
Browse files Browse the repository at this point in the history
  • Loading branch information
kilic committed May 13, 2024
1 parent cd8b36a commit 23566df
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
5 changes: 5 additions & 0 deletions derive/src/field/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ pub(crate) fn impl_field(input: TokenStream) -> TokenStream {
let modulus_limbs = crate::utils::big_to_limbs(&modulus, num_limbs);
let modulus_str = format!("0x{}", modulus.to_str_radix(16));
let modulus_limbs_ident = quote! {[#(#modulus_limbs,)*]};

let modulus_limbs_32 = crate::utils::big_to_limbs_32(&modulus, num_limbs * 2);
let modulus_limbs_32_ident = quote! {[#(#modulus_limbs_32,)*]};

let to_token = |e: &BigUint| big_to_token(e, num_limbs);

// binary modulus
Expand Down Expand Up @@ -265,6 +269,7 @@ pub(crate) fn impl_field(input: TokenStream) -> TokenStream {
pub const SIZE: usize = #num_limbs * 8;
pub const NUM_LIMBS: usize = #num_limbs;
pub(crate) const MODULUS_LIMBS: [u64; Self::NUM_LIMBS] = #modulus_limbs_ident;
pub(crate) const MODULUS_LIMBS_32: [u32; Self::NUM_LIMBS*2] = #modulus_limbs_32_ident;
const R: Self = Self(#r1);
const R2: Self = Self(#r2);
const R3: Self = Self(#r3);
Expand Down
7 changes: 7 additions & 0 deletions derive/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ pub(crate) fn big_to_limbs(e: &BigUint, number_of_limbs: usize) -> Vec<u64> {
.collect()
}

pub(crate) fn big_to_limbs_32(e: &BigUint, number_of_limbs: usize) -> Vec<u32> {
decompose(e, number_of_limbs, 32)
.iter()
.map(|x| x.to_u32().unwrap())
.collect()
}

pub(crate) fn big_to_token(e: &BigUint, number_of_limbs: usize) -> proc_macro2::TokenStream {
let limbs = big_to_limbs(e, number_of_limbs);
quote::quote! {[#(#limbs,)*]}
Expand Down
13 changes: 11 additions & 2 deletions src/derive/field/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,16 @@ macro_rules! field_bits {

let limbs = (0..Self::NUM_LIMBS * 8 / STEP)
.map(|off| {
u64::from_le_bytes(bytes[off * STEP..(off + 1) * STEP].try_into().unwrap())
#[cfg(target_pointer_width = "64")]
let limb = u64::from_le_bytes(
bytes[off * STEP..(off + 1) * STEP].try_into().unwrap(),
);
#[cfg(not(target_pointer_width = "64"))]
let limb = u32::from_le_bytes(
bytes[off * STEP..(off + 1) * STEP].try_into().unwrap(),
);

limb
})
.collect::<Vec<_>>();

Expand All @@ -31,7 +40,7 @@ macro_rules! field_bits {
#[cfg(target_pointer_width = "64")]
let bits = ff::FieldBits::new(Self::MODULUS_LIMBS);
#[cfg(not(target_pointer_width = "64"))]
let bits = ff::FieldBits::new(MODULUS_LIMBS_32.0);
let bits = ff::FieldBits::new(Self::MODULUS_LIMBS_32);

bits
}
Expand Down

0 comments on commit 23566df

Please sign in to comment.