Skip to content

Commit

Permalink
fixup: remove testing test
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Nov 5, 2020
1 parent 8b9920a commit f8340e2
Showing 1 changed file with 0 additions and 83 deletions.
83 changes: 0 additions & 83 deletions filecoin-proofs/src/fr32_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,87 +361,4 @@ mod tests {

assert_eq!(buf.into_boxed_slice(), bit_vec_padding(source));
}

const BLOCK_SIZE: usize = 127 * 8;

#[test]
fn test_fast() {
// unpadded 127 * 8 bits => 4 * 254
// padded 128 * 8 bits => 4 * 256

// source: 127bytes
// [
// 0: 0..254 (0..31)
// 1: 254..508 (31..64)
// 254..318
// 318..382
// 382..446
//
// 2: 508..762 (64..96)
// 3: 762..1016 (96..)
// ]

// target: 128bytes

let data = [255u8; 127];
let mut padded = [0u8; 128];

let num_bits = data.len() * 8;
assert_eq!(num_bits % 127, 0);

let num_blocks = div_ceil(num_bits, BLOCK_SIZE);

let mut in_buffer_bytes = [0u8; 128];
let mut out_buffer = [0u128; NUM_U128S_PER_BLOCK];
for block in 0..num_blocks {
// load current block
let block_offset_start = block * 127;
let block_offset_end = std::cmp::min(block_offset_start + 128, data.len());
let end = block_offset_end - block_offset_start;
in_buffer_bytes[..end]
.copy_from_slice(&data[dbg!(block_offset_start)..dbg!(block_offset_end)]);
let in_buffer: &[u128] = in_buffer_bytes.as_slice_of::<u128>().unwrap();

// write out fr chunks

// 0..254
{
out_buffer[0] = in_buffer[0];
out_buffer[1] = in_buffer[1] & MASK_SKIP_HIGH_2;
}
// 254..508
{
out_buffer[2] = in_buffer[1] >> 126; // top 2 bits
out_buffer[2] |= in_buffer[2] << 2; // low 126 bits
out_buffer[3] = in_buffer[2] >> 126; // top 2 bits
out_buffer[3] |= in_buffer[3] << 2; // low 124 bits
out_buffer[3] &= MASK_SKIP_HIGH_2; // zero high 2 bits
}
// 508..762
{
out_buffer[4] = in_buffer[3] >> 124; // top 4 bits
out_buffer[4] |= in_buffer[4] << 4; // low 124 bits
out_buffer[5] = in_buffer[4] >> 124; // top 4 bits
out_buffer[5] |= in_buffer[5] << 4; // low 122 bits
out_buffer[5] &= MASK_SKIP_HIGH_2; // zero high 2 bits
}
// 762..1016
{
out_buffer[6] = in_buffer[5] >> 122; // top 6 bits
out_buffer[6] |= in_buffer[6] << 6; // low 122 bits
out_buffer[7] = in_buffer[6] >> 122; // top 6 bits
out_buffer[7] |= in_buffer[7] << 6; // low 120 bits
out_buffer[7] &= MASK_SKIP_HIGH_2; // zero high 2 bits
}
padded[block * 128..(block + 1) * 128].copy_from_slice(out_buffer.as_byte_slice());
}

assert_eq!(&padded[0..31], &data[0..31]);
assert_eq!(padded[31], 0b0011_1111);
assert_eq!(padded[32], 0b1111_1111);

assert_eq!(padded.len(), 128);

assert_eq!(&padded[..], &bit_vec_padding(data.to_vec())[..]);
}
}

0 comments on commit f8340e2

Please sign in to comment.