Skip to content

Commit

Permalink
add with_flags_chained helper
Browse files Browse the repository at this point in the history
  • Loading branch information
T0b1-iOS committed Apr 11, 2023
1 parent 2589d7c commit afa26e9
Show file tree
Hide file tree
Showing 6 changed files with 299 additions and 66 deletions.
8 changes: 8 additions & 0 deletions cranelift/codegen/src/isa/aarch64/inst.isle
Original file line number Diff line number Diff line change
Expand Up @@ -2012,6 +2012,14 @@
(MInst.AluRRR alu_op (operand_size ty) dst src1 src2)
dst)))

;; Should only be used for AdcS and SbcS
(decl alu_rrr_with_flags_chained (Type Reg Reg ALUOp) ConsumesAndProducesFlags)
(rule (alu_rrr_with_flags_chained ty src1 src2 alu_op)
(let ((dst WritableReg (temp_writable_reg $I64)))
(ConsumesAndProducesFlags.ReturnsReg
(MInst.AluRRR alu_op (operand_size ty) dst src1 src2)
dst)))

;; Helper for emitting `MInst.BitRR` instructions.
(decl bit_rr (BitOp Type Reg) Reg)
(rule (bit_rr op ty src)
Expand Down
12 changes: 3 additions & 9 deletions cranelift/codegen/src/isa/aarch64/lower.isle
Original file line number Diff line number Diff line change
Expand Up @@ -2683,17 +2683,11 @@
;; cannot use the with_flags helper here but it should be fine right now
(let
((lo_inst ProducesFlags (alu_rrr_with_flags_paired $I64 x_lo y_lo alu_op1))
(hi_inst ProducesFlags (alu_rrr_with_flags_paired $I64 x_hi y_hi alu_op2))
(hi_inst ConsumesAndProducesFlags (alu_rrr_with_flags_chained $I64 x_hi y_hi alu_op2))
(of_inst ConsumesFlags (cset_paired cond))

(result InstOutputRef (output_to_output_ref (with_flags_extended (produces_flags_concat lo_inst hi_inst) of_inst)))

(lo ValueRegs (inst_output_get result 0))
(hi ValueRegs (inst_output_get result 1))
(of ValueRegs (inst_output_get result 2)))
(output_pair
(value_regs (value_regs_get lo 0) (value_regs_get hi 0))
of)))
(result MultiReg (with_flags_chained lo_inst hi_inst of_inst)))
(multi_reg_to_pair_and_single result)))
)

;;;; Rules for `uadd_overflow` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down
12 changes: 12 additions & 0 deletions cranelift/codegen/src/isa/x64/inst.isle
Original file line number Diff line number Diff line change
Expand Up @@ -2135,6 +2135,18 @@
dst)
dst)))

;; Should only be used for Adc and Sbb
(decl x64_alurmi_with_flags_chained (AluRmiROpcode Type Gpr GprMemImm) ConsumesAndProducesFlags)
(rule (x64_alurmi_with_flags_chained opc (fits_in_64 ty) src1 src2)
(let ((dst WritableGpr (temp_writable_gpr)))
(ConsumesAndProducesFlags.ReturnsReg
(MInst.AluRmiR (raw_operand_size_of_type ty)
opc
src1
src2
dst)
dst)))

;; Helper for creating `adc` instructions.
(decl x64_adc_paired (Type Gpr GprMemImm) ConsumesFlags)
(rule (x64_adc_paired ty src1 src2)
Expand Down
12 changes: 3 additions & 9 deletions cranelift/codegen/src/isa/x64/lower.isle
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,11 @@
(y_lo Gpr (value_regs_get_gpr y_regs 0))
(y_hi Gpr (value_regs_get_gpr y_regs 1)))
(let ((lo_inst ProducesFlags (x64_alurmi_with_flags_paired op1 $I64 x_lo y_lo))
(hi_inst ProducesFlags (x64_alurmi_with_flags_paired op2 $I64 x_hi y_hi))
(hi_inst ConsumesAndProducesFlags (x64_alurmi_with_flags_chained op2 $I64 x_hi y_hi))
(of_inst ConsumesFlags (x64_setcc_paired cc))

(result InstOutputRef (output_to_output_ref (with_flags_extended (produces_flags_concat lo_inst hi_inst) of_inst)))

(lo ValueRegs (inst_output_get result 0))
(hi ValueRegs (inst_output_get result 1))
(of ValueRegs (inst_output_get result 2)))
(output_pair (value_regs (value_regs_get lo 0)
(value_regs_get hi 0))
of)))))
(result MultiReg (with_flags_chained lo_inst hi_inst of_inst)))
(multi_reg_to_pair_and_single result)))))

;;;; Rules for `uadd_overflow` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Expand Down
16 changes: 0 additions & 16 deletions cranelift/codegen/src/machinst/isle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ pub type VecMask = Vec<u8>;
pub type ValueRegs = crate::machinst::ValueRegs<Reg>;
pub type WritableValueRegs = crate::machinst::ValueRegs<WritableReg>;
pub type InstOutput = SmallVec<[ValueRegs; 2]>;
pub type InstOutputRef = InstOutput;
pub type InstOutputBuilder = Cell<InstOutput>;
pub type BoxExternalName = Box<ExternalName>;
pub type Range = (usize, usize);
Expand Down Expand Up @@ -99,16 +98,6 @@ macro_rules! isle_lower_prelude_methods {
builder.take()
}

#[inline]
fn output_to_output_ref(&mut self, output: InstOutput) -> InstOutputRef {
output
}

#[inline]
fn output_ref_to_output(&mut self, output: &InstOutputRef) -> InstOutput {
output.clone()
}

#[inline]
fn temp_writable_reg(&mut self, ty: Type) -> WritableReg {
let value_regs = self.lower_ctx.alloc_tmp(ty);
Expand Down Expand Up @@ -157,11 +146,6 @@ macro_rules! isle_lower_prelude_methods {
regs.regs().len()
}

#[inline]
fn inst_output_get(&mut self, output: &InstOutputRef, i: usize) -> ValueRegs {
output[i]
}

#[inline]
fn value_list_slice(&mut self, list: ValueList) -> ValueSlice {
(list, 0)
Expand Down
Loading

0 comments on commit afa26e9

Please sign in to comment.