Skip to content

Commit

Permalink
Enabled bounded-int abs optimization in i128 mul.
Browse files Browse the repository at this point in the history
commit-id:8d2ec222

fixup! Enabled bounded-int `abs` optimization in i128 mul.
  • Loading branch information
orizi committed Sep 25, 2024
1 parent 3222142 commit f2951b8
Show file tree
Hide file tree
Showing 4 changed files with 7,708 additions and 7,863 deletions.
8 changes: 5 additions & 3 deletions corelib/src/integer.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -1931,9 +1931,11 @@ impl I128Neg of Neg<i128> {
impl I128Mul of Mul<i128> {
fn mul(lhs: i128, rhs: i128) -> i128 {
let (lhs_u127, lhs_neg) = lhs.abs_and_sign();
let (rhs_u127, res_neg) = match i128_diff(rhs, 0) {
Result::Ok(v) => (v, lhs_neg),
Result::Err(v) => (~v + 1, !lhs_neg),
let (rhs_u127, res_neg) = match core::internal::bounded_int::constrain::<i128, 0>(rhs) {
Result::Ok(lt0) => (
upcast(core::internal::bounded_int::NegateHelper::negate(lt0)), !lhs_neg
),
Result::Err(ge0) => (upcast(ge0), lhs_neg),
};
let res_as_u128 = lhs_u127 * rhs_u127;
let res_as_felt252: felt252 = if res_neg {
Expand Down
Loading

0 comments on commit f2951b8

Please sign in to comment.