Skip to content

Commit

Permalink
fix(integer): remove double carry prop in sub
Browse files Browse the repository at this point in the history
The subtraction is done via addition of the negation,
the negation is done via unchecked_neg, this will make the
first block have a carry.
Then we called add_assign_with_carry_parallelized which did
a carry propagation on the rhs which here is the negated value,
meaning the subtraction would do 2 carry propagation.

To fix that we directly call the lower function.
  • Loading branch information
tmontaigu committed Aug 13, 2024
1 parent 401cfc5 commit 594a5ce
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion tfhe/src/integer/server_key/radix_parallel/sub.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::integer::ciphertext::IntegerRadixCiphertext;
use crate::integer::server_key::radix_parallel::OutputFlag;
use crate::integer::{BooleanBlock, RadixCiphertext, ServerKey, SignedRadixCiphertext};
use crate::shortint::ciphertext::Degree;
use crate::shortint::Ciphertext;
Expand Down Expand Up @@ -226,7 +227,12 @@ impl ServerKey {
};

let neg = self.unchecked_neg(rhs);
self.add_assign_with_carry_parallelized(lhs, &neg, None);
self.advanced_add_assign_with_carry_parallelized(
lhs.blocks_mut(),
neg.blocks(),
None,
OutputFlag::None,
);
}

/// Computes the subtraction and returns an indicator of overflow
Expand Down

0 comments on commit 594a5ce

Please sign in to comment.