Browse Source

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

pull/1975/head
MaxGraey 4 years ago
parent
commit
1033cf5748
  1. 2
      cranelift/codegen/src/preopt.peepmatic
  2. BIN
      cranelift/codegen/src/preopt.serialized
  3. 4
      cranelift/peepmatic/crates/runtime/src/operator.rs
  4. 2
      cranelift/peepmatic/crates/runtime/src/optimizer.rs

2
cranelift/codegen/src/preopt.peepmatic

@ -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))

BIN
cranelift/codegen/src/preopt.serialized

Binary file not shown.

4
cranelift/peepmatic/crates/runtime/src/operator.rs

@ -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,

2
cranelift/peepmatic/crates/runtime/src/optimizer.rs

@ -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)

Loading…
Cancel
Save