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 4a1aa2e
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 24 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
2 changes: 1 addition & 1 deletion fil-proofs-param/src/bin/parampublish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ fn get_filenames_in_cache_dir() -> Vec<String> {
fn publish_file(ipfs_bin: &str, filename: &str) -> Result<String> {
let path = get_full_path_for_file_within_cache(filename);
let output = Command::new(ipfs_bin)
.args(&["add", path.to_str().unwrap()])
.args(&["add", "-Q", path.to_str().unwrap()])
.output()
.expect("failed to run ipfs subprocess");
stderr()
Expand Down
2 changes: 1 addition & 1 deletion fil-proofs-param/src/bin/srspublish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fn get_filenames_in_cache_dir() -> Vec<String> {
fn publish_file(ipfs_bin: &str, filename: &str) -> Result<String> {
let path = get_full_path_for_file_within_cache(filename);
let output = Command::new(ipfs_bin)
.args(&["add", path.to_str().unwrap()])
.args(&["add", "-Q", path.to_str().unwrap()])
.output()
.expect("failed to run ipfs subprocess");
stderr()
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
1 change: 1 addition & 0 deletions fil-proofs-param/tests/support/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ impl FakeIpfsBin {
pub fn compute_checksum<P: AsRef<Path>>(&self, path: P) -> Result<String, failure::Error> {
let output = Command::new(&self.bin_path)
.arg("add")
.arg("-Q")
.arg(path.as_ref())
.output()?;

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
1 change: 0 additions & 1 deletion storage-proofs-porep/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![deny(clippy::all, clippy::perf, clippy::correctness, rust_2018_idioms)]
#![allow(clippy::mut_from_ref)]
#![warn(clippy::unwrap_used)]
#![cfg_attr(target_arch = "aarch64", feature(stdsimd))]
#![warn(clippy::unnecessary_wraps)]
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
23 changes: 14 additions & 9 deletions storage-proofs-porep/src/stacked/vanilla/utils.rs
Original file line number Diff line number Diff line change
@@ -1,44 +1,49 @@
#![allow(clippy::mut_from_ref)]

use std::cell::UnsafeCell;
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 4a1aa2e

Please sign in to comment.