forked from M-Labs/artiq
1
0
Fork 0

py2llvm/fractions: add lt, le, gt, ge comparisons

This commit is contained in:
Sebastien Bourdeauducq 2014-10-06 23:22:05 +08:00
parent 8612a8a9ca
commit 9caaaeb414
1 changed files with 26 additions and 0 deletions

View File

@ -187,6 +187,32 @@ class VFraction(VGeneric):
def o_ne(self, other, builder): def o_ne(self, other, builder):
return self._o_eq_inv(other, builder, True) return self._o_eq_inv(other, builder, True)
def _o_cmp(self, other, icmp, builder):
diff = self.o_sub(other, builder)
if diff is NotImplemented:
return NotImplemented
r = VBool()
if builder is not None:
diff = diff.auto_load(builder)
a = builder.extract_element(
diff, lc.Constant.int(lc.Type.int(), 0))
zero = lc.Constant.int(lc.Type.int(64), 0)
ssa_r = builder.icmp(icmp, a, zero)
r.auto_store(builder, ssa_r)
return r
def o_lt(self, other, builder):
return self._o_cmp(other, lc.ICMP_SLT, builder)
def o_le(self, other, builder):
return self._o_cmp(other, lc.ICMP_SLE, builder)
def o_gt(self, other, builder):
return self._o_cmp(other, lc.ICMP_SGT, builder)
def o_ge(self, other, builder):
return self._o_cmp(other, lc.ICMP_SGE, builder)
def _o_addsub(self, other, builder, sub, invert=False): def _o_addsub(self, other, builder, sub, invert=False):
if not isinstance(other, (VInt, VFraction)): if not isinstance(other, (VInt, VFraction)):
return NotImplemented return NotImplemented