Optimize fma_rows() to avoid multiplying by 1

This commit is contained in:
Christopher Berner 2019-02-03 19:28:32 -08:00
parent 62554ac9d0
commit ece0c54244
3 changed files with 21 additions and 6 deletions

@ -621,9 +621,15 @@ impl IntermediateSymbolDecoder {
}
fn fma_rows(&mut self, i: usize, iprime: usize, beta: Octet) {
self.debug_symbol_mul_ops += 1;
let temp = self.D[self.d[i]].clone();
self.D[self.d[iprime]].fused_addassign_mul_scalar(&temp, &beta);
if beta == Octet::one() {
let temp = self.D[self.d[i]].clone();
self.D[self.d[iprime]] += &temp;
}
else {
self.debug_symbol_mul_ops += 1;
let temp = self.D[self.d[i]].clone();
self.D[self.d[iprime]].fused_addassign_mul_scalar(&temp, &beta);
}
for j in 0..self.L {
self.A[iprime][j] += &self.A[i][j] * β
}

@ -131,6 +131,12 @@ impl AddAssign for Octet {
}
}
impl<'a> AddAssign<&'a Octet> for Octet {
fn add_assign(&mut self, other: &'a Octet) {
self.value ^= other.value;
}
}
impl Sub for Octet {
type Output = Octet;

@ -64,10 +64,13 @@ impl Add for Symbol {
}
}
impl AddAssign for Symbol {
fn add_assign(&mut self, other: Symbol) {
impl<'a> AddAssign<&'a Symbol> for Symbol {
fn add_assign(&mut self, other: &'a Symbol) {
assert_eq!(self.value.len(), other.value.len());
for i in 0..self.value.len() {
self.value[i] += other.value[i].clone();
unsafe {
*self.value.get_unchecked_mut(i) += other.value.get_unchecked(i);
}
}
}
}