Skip to content

Commit eb0a731

Browse files
committed
Implement 128bit comparison binops
1 parent d0f099a commit eb0a731

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

src/codegen_i128.rs

+28-7
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,43 @@ pub fn maybe_codegen<'a, 'tcx>(
6060
assert!(!checked);
6161
let (lhs_lsb, lhs_msb) = fx.bcx.ins().isplit(lhs_val);
6262
let (rhs_lsb, rhs_msb) = fx.bcx.ins().isplit(rhs_val);
63-
let res = match (bin_op, is_signed) {
64-
(BinOp::Eq, _) => {
63+
64+
let res = match bin_op {
65+
BinOp::Eq => {
6566
let lsb_eq = fx.bcx.ins().icmp(IntCC::Equal, lhs_lsb, rhs_lsb);
6667
let msb_eq = fx.bcx.ins().icmp(IntCC::Equal, lhs_msb, rhs_msb);
6768
fx.bcx.ins().band(lsb_eq, msb_eq)
6869
}
69-
(BinOp::Ne, _) => {
70+
BinOp::Ne => {
7071
let lsb_ne = fx.bcx.ins().icmp(IntCC::NotEqual, lhs_lsb, rhs_lsb);
7172
let msb_ne = fx.bcx.ins().icmp(IntCC::NotEqual, lhs_msb, rhs_msb);
7273
fx.bcx.ins().bor(lsb_ne, msb_ne)
7374
}
7475
_ => {
75-
// FIXME implement it
76-
let out_layout = fx.layout_of(out_ty);
77-
return Some(crate::trap::trap_unreachable_ret_value(fx, out_layout, format!("unimplemented 128bit binop {:?}", bin_op)));
78-
},
76+
// if msb_eq {
77+
// lhs_cc
78+
// } else {
79+
// msb_cc
80+
// }
81+
let cc = match (bin_op, is_signed) {
82+
(BinOp::Ge, false) => IntCC::UnsignedGreaterThanOrEqual,
83+
(BinOp::Gt, false) => IntCC::UnsignedGreaterThan,
84+
(BinOp::Lt, false) => IntCC::UnsignedLessThan,
85+
(BinOp::Le, false) => IntCC::UnsignedLessThanOrEqual,
86+
87+
(BinOp::Ge, true) => IntCC::SignedGreaterThanOrEqual,
88+
(BinOp::Gt, true) => IntCC::SignedGreaterThan,
89+
(BinOp::Lt, true) => IntCC::SignedLessThan,
90+
(BinOp::Le, true) => IntCC::SignedLessThanOrEqual,
91+
_ => unreachable!(),
92+
};
93+
94+
let msb_eq = fx.bcx.ins().icmp(IntCC::Equal, lhs_msb, rhs_msb);
95+
let lsb_cc = fx.bcx.ins().icmp(cc, lhs_lsb, rhs_lsb);
96+
let msb_cc = fx.bcx.ins().icmp(cc, lhs_msb, rhs_msb);
97+
98+
fx.bcx.ins().select(msb_eq, lsb_cc, msb_cc)
99+
}
79100
};
80101

81102
let res = fx.bcx.ins().bint(types::I8, res);

0 commit comments

Comments
 (0)