-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Vectorized structure for rejection sampling.
- Loading branch information
Showing
5 changed files
with
70 additions
and
18 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,21 @@ | ||
use crate::simd::traits::FIELD_MODULUS; | ||
|
||
#[inline(always)] | ||
pub fn rejection_sample_less_than_field_modulus(randomness: &[u8], out: &mut [i32]) -> usize { | ||
let mut sampled = 0; | ||
|
||
for bytes in randomness.chunks(3) { | ||
let b0 = bytes[0] as i32; | ||
let b1 = bytes[1] as i32; | ||
let b2 = bytes[2] as i32; | ||
|
||
let coefficient = ((b2 << 16) | (b1 << 8) | b0) & 0x00_7F_FF_FF; | ||
|
||
if coefficient < FIELD_MODULUS { | ||
out[sampled] = coefficient; | ||
sampled += 1; | ||
} | ||
} | ||
|
||
sampled | ||
} |
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