use (isub 1 $C) instead (iadd -1 $C)

This commit is contained in:
MaxGraey
2020-07-03 11:01:35 +03:00
parent d839d83f7e
commit 1033cf5748
4 changed files with 7 additions and 1 deletions

View File

@@ -195,4 +195,4 @@
;; Reminder by a power of two -> bitwise and with decreased by one constant.
(=> (when (urem_imm $C $x)
(is-power-of-two $C))
(band_imm $(iadd -1 $C) $x))
(band_imm $(isub 1 $C) $x))

View File

@@ -233,6 +233,10 @@ pub enum UnquoteOperator {
#[peepmatic(params(iNN, iNN), result(iNN))]
Iadd,
/// Compile-time `iadd` of two constant values.
#[peepmatic(params(iNN, iNN), result(iNN))]
Isub,
/// Compile-time `imul` of two constant values.
#[peepmatic(params(iNN, iNN), result(iNN))]
Imul,

View File

@@ -77,6 +77,7 @@ where
| UnquoteOperator::Bor
| UnquoteOperator::Bxor
| UnquoteOperator::Iadd
| UnquoteOperator::Isub
| UnquoteOperator::Imul => unreachable!("not a unary unquote operator: {:?}", operator),
}
}
@@ -98,6 +99,7 @@ where
UnquoteOperator::Bor => fold_ints!(a, b, |x, y| x | y),
UnquoteOperator::Bxor => fold_ints!(a, b, |x, y| x ^ y),
UnquoteOperator::Iadd => fold_ints!(a, b, |x, y| x.wrapping_add(y)),
UnquoteOperator::Isub => fold_ints!(a, b, |x, y| x.wrapping_sub(y)),
UnquoteOperator::Imul => fold_ints!(a, b, |x, y| x.wrapping_mul(y)),
UnquoteOperator::Log2 | UnquoteOperator::Neg => {
unreachable!("not a binary unquote operator: {:?}", operator)