Skip to content

Commit e2e98f6

Browse files
authored
Remove lower_br_fcmp from the riscv64 backend (#5519)
Remove the lower_br_fcmp function from the riscv64 backend. This PR only affects the emit implementation for FloatRound, replacing the uses of lower_br_fcmp with direct uses of FpuRRR and CondBr. Any changes in behavior here should be already covered by the runtests for ceil, floor, trunc, and nearest.
1 parent 5d429e4 commit e2e98f6

File tree

1 file changed

+25
-169
lines changed
  • cranelift/codegen/src/isa/riscv64/inst

1 file changed

+25
-169
lines changed

cranelift/codegen/src/isa/riscv64/inst/emit.rs

Lines changed: 25 additions & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -270,163 +270,6 @@ impl Inst {
270270
}
271271
}
272272

273-
pub(crate) fn lower_br_fcmp(
274-
cc: FloatCC,
275-
x: Reg,
276-
y: Reg,
277-
taken: BranchTarget,
278-
not_taken: BranchTarget,
279-
ty: Type,
280-
tmp: Writable<Reg>,
281-
) -> SmallInstVec<Inst> {
282-
assert!(tmp.to_reg().class() == RegClass::Int);
283-
let mut insts = SmallInstVec::new();
284-
let mut cc_args = FloatCCArgs::from_floatcc(cc);
285-
let eq_op = if ty == F32 {
286-
FpuOPRRR::FeqS
287-
} else {
288-
FpuOPRRR::FeqD
289-
};
290-
let lt_op = if ty == F32 {
291-
FpuOPRRR::FltS
292-
} else {
293-
FpuOPRRR::FltD
294-
};
295-
let le_op = if ty == F32 {
296-
FpuOPRRR::FleS
297-
} else {
298-
FpuOPRRR::FleD
299-
};
300-
301-
// >=
302-
if cc_args.has_and_clear(FloatCCArgs::GT | FloatCCArgs::EQ) {
303-
insts.push(Inst::FpuRRR {
304-
frm: None,
305-
alu_op: le_op,
306-
rd: tmp,
307-
rs1: y, // x and y order reversed.
308-
rs2: x,
309-
});
310-
insts.push(Inst::CondBr {
311-
taken: taken,
312-
not_taken: BranchTarget::zero(),
313-
kind: IntegerCompare {
314-
kind: IntCC::NotEqual,
315-
rs1: tmp.to_reg(),
316-
rs2: zero_reg(),
317-
},
318-
});
319-
}
320-
321-
// <=
322-
if cc_args.has_and_clear(FloatCCArgs::LT | FloatCCArgs::EQ) {
323-
insts.push(Inst::FpuRRR {
324-
frm: None,
325-
alu_op: le_op,
326-
rd: tmp,
327-
rs1: x,
328-
rs2: y,
329-
});
330-
insts.push(Inst::CondBr {
331-
taken: taken,
332-
not_taken: BranchTarget::zero(),
333-
kind: IntegerCompare {
334-
kind: IntCC::NotEqual,
335-
rs1: tmp.to_reg(),
336-
rs2: zero_reg(),
337-
},
338-
});
339-
}
340-
341-
// if eq
342-
if cc_args.has_and_clear(FloatCCArgs::EQ) {
343-
insts.push(Inst::FpuRRR {
344-
frm: None,
345-
alu_op: eq_op,
346-
rd: tmp,
347-
rs1: x,
348-
rs2: y,
349-
});
350-
insts.push(Inst::CondBr {
351-
taken: taken,
352-
not_taken: BranchTarget::zero(),
353-
kind: IntegerCompare {
354-
kind: IntCC::NotEqual,
355-
rs1: tmp.to_reg(),
356-
rs2: zero_reg(),
357-
},
358-
});
359-
}
360-
// if ne
361-
if cc_args.has_and_clear(FloatCCArgs::NE) {
362-
insts.push(Inst::FpuRRR {
363-
frm: None,
364-
alu_op: eq_op,
365-
rd: tmp,
366-
rs1: x,
367-
rs2: y,
368-
});
369-
insts.push(Inst::CondBr {
370-
taken: taken,
371-
not_taken: BranchTarget::zero(),
372-
kind: IntegerCompare {
373-
kind: IntCC::Equal,
374-
rs1: tmp.to_reg(),
375-
rs2: zero_reg(),
376-
},
377-
});
378-
}
379-
380-
// if <
381-
if cc_args.has_and_clear(FloatCCArgs::LT) {
382-
insts.push(Inst::FpuRRR {
383-
frm: None,
384-
alu_op: lt_op,
385-
rd: tmp,
386-
rs1: x,
387-
rs2: y,
388-
});
389-
insts.push(Inst::CondBr {
390-
taken: taken,
391-
not_taken: BranchTarget::zero(),
392-
kind: IntegerCompare {
393-
kind: IntCC::NotEqual,
394-
rs1: tmp.to_reg(),
395-
rs2: zero_reg(),
396-
},
397-
});
398-
}
399-
// if gt
400-
if cc_args.has_and_clear(FloatCCArgs::GT) {
401-
insts.push(Inst::FpuRRR {
402-
frm: None,
403-
alu_op: lt_op,
404-
rd: tmp,
405-
rs1: y, // x and y order reversed.
406-
rs2: x,
407-
});
408-
insts.push(Inst::CondBr {
409-
taken,
410-
not_taken: BranchTarget::zero(),
411-
kind: IntegerCompare {
412-
kind: IntCC::NotEqual,
413-
rs1: tmp.to_reg(),
414-
rs2: zero_reg(),
415-
},
416-
});
417-
}
418-
// if unordered
419-
if cc_args.has_and_clear(FloatCCArgs::UN) {
420-
insts.extend(Inst::lower_float_unordered(tmp, ty, x, y, taken, not_taken));
421-
} else {
422-
//make sure we goto the not_taken.
423-
//finally goto not_taken
424-
insts.push(Inst::Jal { dest: not_taken });
425-
}
426-
// make sure we handle all cases.
427-
assert!(cc_args.0 == 0);
428-
insts
429-
}
430273
pub(crate) fn lower_br_icmp(
431274
cc: IntCC,
432275
a: ValueRegs<Reg>,
@@ -2186,18 +2029,31 @@ impl MachInstEmit for Inst {
21862029

21872030
// get abs value.
21882031
Inst::emit_fabs(rd, rs, ty).emit(&[], sink, emit_info, state);
2189-
Inst::lower_br_fcmp(
2190-
FloatCC::GreaterThan,
2191-
// abs value > max_value_need_round
2192-
rd.to_reg(),
2193-
f_tmp.to_reg(),
2194-
BranchTarget::Label(label_x),
2195-
BranchTarget::zero(),
2196-
ty,
2197-
int_tmp,
2198-
)
2199-
.into_iter()
2200-
.for_each(|i| i.emit(&[], sink, emit_info, state));
2032+
2033+
// branch if f_tmp < rd
2034+
Inst::FpuRRR {
2035+
frm: None,
2036+
alu_op: if ty == F32 {
2037+
FpuOPRRR::FltS
2038+
} else {
2039+
FpuOPRRR::FltD
2040+
},
2041+
rd: int_tmp,
2042+
rs1: f_tmp.to_reg(),
2043+
rs2: rd.to_reg(),
2044+
}
2045+
.emit(&[], sink, emit_info, state);
2046+
2047+
Inst::CondBr {
2048+
taken: BranchTarget::Label(label_x),
2049+
not_taken: BranchTarget::zero(),
2050+
kind: IntegerCompare {
2051+
kind: IntCC::NotEqual,
2052+
rs1: int_tmp.to_reg(),
2053+
rs2: zero_reg(),
2054+
},
2055+
}
2056+
.emit(&[], sink, emit_info, state);
22012057

22022058
//convert to int.
22032059
Inst::FpuRR {

0 commit comments

Comments
 (0)