use crate::WORD_BITS;
use super::BitsEdit;
mod funcs_for_copy_words_core;
mod funcs_for_copy_words_shifted_core;
pub(crate) struct BitsCopied<'a> {
pub(crate) src: &'a [u64],
pub(crate) src_start: usize,
pub(crate) len: usize,
pub(crate) aligned: bool, }
impl BitsCopied<'_> {
#[inline]
pub(crate) fn paste_to(&self, dst: &mut [u64], dst_start: usize) {
let full_words = self.len / WORD_BITS;
let remainder_bits = self.len % WORD_BITS;
let dst_aligned = dst_start.is_multiple_of(WORD_BITS);
if self.aligned && dst_aligned {
if full_words > 0 {
let sw = self.src_start / WORD_BITS;
let dw = dst_start / WORD_BITS;
funcs_for_copy_words_core::copy_words(&mut dst[dw..], &self.src[sw..], full_words);
}
}
else if !self.aligned && dst_aligned {
if full_words > 0 {
let shift = self.src_start % WORD_BITS;
let base = self.src_start / WORD_BITS;
let dw = dst_start / WORD_BITS;
funcs_for_copy_words_shifted_core::copy_words_shifted(
&mut dst[dw..],
&self.src[base..],
full_words,
shift,
);
}
}
else if self.aligned
&& full_words > 1
&& self.src.len() > self.src_start / WORD_BITS + full_words
{
let dst_shift = dst_start % WORD_BITS;
let sw = self.src_start / WORD_BITS;
let dw = dst_start / WORD_BITS;
let mid_count = full_words - 1;
dst[dw] |= self.src[sw] << dst_shift;
funcs_for_copy_words_shifted_core::copy_words_shifted(
&mut dst[dw + 1..],
&self.src[sw..],
mid_count,
WORD_BITS - dst_shift,
);
dst[dw + full_words] |= self.src[sw + mid_count] >> (WORD_BITS - dst_shift);
}
else {
for i in 0..full_words {
let chunk = self.src.read_word_at(self.src_start + i * WORD_BITS);
dst.write_word_at(dst_start + i * WORD_BITS, chunk, WORD_BITS);
}
}
if remainder_bits > 0 {
let offset = full_words * WORD_BITS;
let chunk = self.src.read_word_at(self.src_start + offset);
dst.write_word_at(dst_start + offset, chunk, remainder_bits);
}
}
}
#[cfg(test)]
mod tests_for_copy;