Skip to content

Commit

Permalink
Requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
storojs72 committed May 31, 2022
1 parent 772d33f commit 0f535fb
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 21 deletions.
2 changes: 2 additions & 0 deletions fil-proofs-param/src/bin/fakeipfsadd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ enum Cli {
Add {
#[structopt(help = "Positional argument for the path to the file to add.")]
file_path: String,
#[structopt(short = "Q", help = "Simulates the -Q argument to `ipfs add`.")]
_quieter: bool,
},
}

Expand Down
4 changes: 2 additions & 2 deletions fil-proofs-param/tests/paramfetch/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl ParamFetchSessionBuilder {

/// Launch paramfetch in an environment configured by the builder.
pub fn build(self) -> ParamFetchSession {
let session = match spawn_bash_with_retries(10, Some(self.session_timeout_ms)) {
let pty_session = match spawn_bash_with_retries(10, Some(self.session_timeout_ms)) {
Err(e) => panic_any(e),
Ok(mut session) => {
let cache_dir_path = format!("{:?}", self.cache_dir.path());
Expand Down Expand Up @@ -103,7 +103,7 @@ impl ParamFetchSessionBuilder {
};

ParamFetchSession {
pty_session: session,
pty_session,
_cache_dir: self.cache_dir,
}
}
Expand Down
4 changes: 2 additions & 2 deletions fil-proofs-param/tests/parampublish/support/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl ParamPublishSessionBuilder {

/// Launch parampublish in an environment configured by the builder.
pub fn build(self) -> (ParamPublishSession, Vec<PathBuf>) {
let session = match spawn_bash_with_retries(10, Some(self.session_timeout_ms)) {
let pty_session = match spawn_bash_with_retries(10, Some(self.session_timeout_ms)) {
Err(err) => panic_any(err),
Ok(mut session) => {
let cache_dir_path = format!("{:?}", self.cache_dir.path());
Expand Down Expand Up @@ -148,7 +148,7 @@ impl ParamPublishSessionBuilder {

(
ParamPublishSession {
pty_session: session,
pty_session,
_cache_dir: self.cache_dir,
},
cache_contents,
Expand Down
11 changes: 8 additions & 3 deletions sha2raw/src/sha256_intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ use x86::{

/// Process a block with the SHA-256 algorithm.
/// Based on https://github.com/noloader/SHA-Intrinsics/blob/master/sha256-x86.c
#[allow(clippy::needless_late_init)]
#[inline(always)]
pub unsafe fn compress256(state: &mut [u32; 8], blocks: &[&[u8]]) {
assert_eq!(blocks.len() % 2, 0);

let mut state0: __m128i;
let mut state1: __m128i;

let mut msg: __m128i;
let mut tmp: __m128i;

let mut msg0: __m128i;
let mut msg1: __m128i;
Expand All @@ -35,12 +40,12 @@ pub unsafe fn compress256(state: &mut [u32; 8], blocks: &[&[u8]]) {
);

// Load initial values
let mut tmp = _mm_loadu_si128(state.as_ptr().add(0) as *const __m128i);
let mut state1 = _mm_loadu_si128(state.as_ptr().add(4) as *const __m128i);
tmp = _mm_loadu_si128(state.as_ptr().add(0) as *const __m128i);
state1 = _mm_loadu_si128(state.as_ptr().add(4) as *const __m128i);

tmp = _mm_shuffle_epi32(tmp, 0xB1); // CDAB
state1 = _mm_shuffle_epi32(state1, 0x1B); // EFGH
let mut state0 = _mm_alignr_epi8(tmp, state1, 8); // ABEF
state0 = _mm_alignr_epi8(tmp, state1, 8); // ABEF
state1 = _mm_blend_epi16(state1, tmp, 0xF0); // CDGH

for i in (0..blocks.len()).step_by(2) {
Expand Down
10 changes: 5 additions & 5 deletions storage-proofs-porep/src/stacked/vanilla/create_label/multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ fn fill_buffer(
cur_node: u64,
parents_cache: &CacheReader<u32>,
mut cur_parent: &[u32], // parents for this node
layer_labels: &UnsafeSlice<u32>,
exp_labels: Option<&UnsafeSlice<u32>>, // None for layer0
layer_labels: &UnsafeSlice<'_, u32>,
exp_labels: Option<&UnsafeSlice<'_, u32>>, // None for layer0
buf: &mut [u8],
base_parent_missing: &mut BitMask,
) {
Expand Down Expand Up @@ -140,15 +140,15 @@ fn fill_buffer(
#[allow(clippy::too_many_arguments)]
fn create_label_runner(
parents_cache: &CacheReader<u32>,
layer_labels: &UnsafeSlice<u32>,
exp_labels: Option<&UnsafeSlice<u32>>, // None for layer 0
layer_labels: &UnsafeSlice<'_, u32>,
exp_labels: Option<&UnsafeSlice<'_, u32>>, // None for layer 0
num_nodes: u64,
cur_producer: &AtomicU64,
cur_awaiting: &AtomicU64,
stride: u64,
lookahead: u64,
ring_buf: &RingBuf,
base_parent_missing: &UnsafeSlice<BitMask>,
base_parent_missing: &UnsafeSlice<'_, BitMask>,
) {
info!("created label runner");
// Label data bytes per node
Expand Down
21 changes: 12 additions & 9 deletions storage-proofs-porep/src/stacked/vanilla/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,44 @@ use std::slice::{self, ChunksExactMut};
/// A slice type which can be shared between threads, but must be fully managed by the caller.
/// Any synchronization must be ensured by the caller, which is why all access is `unsafe`.
#[derive(Debug)]
pub struct UnsafeSlice<T> {
pub struct UnsafeSlice<'a, T> {
// holds the data to ensure lifetime correctness
_data: UnsafeCell<&'a mut [T]>,
/// pointer to the data
ptr: *mut T,
/// Number of elements, not bytes.
len: usize,
}

unsafe impl<T> Sync for UnsafeSlice<T> {}
unsafe impl<'a, T> Sync for UnsafeSlice<'a, T> {}

impl<T> UnsafeSlice<T> {
impl<'a, T> UnsafeSlice<'a, T> {
/// Takes mutable slice, to ensure that `UnsafeSlice` is the only user of this memory, until it gets dropped.
pub fn from_slice(source: &mut [T]) -> Self {
pub fn from_slice(source: &'a mut [T]) -> Self {
let len = source.len();
let ptr = source.as_mut_ptr();
Self { ptr, len }
let _data = UnsafeCell::new(source);
Self { _data, ptr, len }
}

/// Safety: The caller must ensure that there are no unsynchronized parallel access to the same regions.
#[inline]
pub unsafe fn as_mut_slice(&self) -> &mut [T] {
pub unsafe fn as_mut_slice(&self) -> &'a mut [T] {
slice::from_raw_parts_mut(self.ptr, self.len)
}
/// Safety: The caller must ensure that there are no unsynchronized parallel access to the same regions.
#[inline]
pub unsafe fn as_slice(&self) -> &[T] {
pub unsafe fn as_slice(&self) -> &'a [T] {
slice::from_raw_parts(self.ptr, self.len)
}

#[inline]
pub unsafe fn get(&self, index: usize) -> &T {
pub unsafe fn get(&self, index: usize) -> &'a T {
&*self.ptr.add(index)
}

#[inline]
pub unsafe fn get_mut(&self, index: usize) -> &mut T {
pub unsafe fn get_mut(&self, index: usize) -> &'a mut T {
&mut *self.ptr.add(index)
}
}
Expand Down

0 comments on commit 0f535fb

Please sign in to comment.