From 9caaaeb4140a8c16aa0afbd1cdae2ec1bd5fb087 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Mon, 6 Oct 2014 23:22:05 +0800 Subject: [PATCH] py2llvm/fractions: add lt, le, gt, ge comparisons --- artiq/py2llvm/fractions.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/artiq/py2llvm/fractions.py b/artiq/py2llvm/fractions.py index 5eeffb964..297ce23c4 100644 --- a/artiq/py2llvm/fractions.py +++ b/artiq/py2llvm/fractions.py @@ -187,6 +187,32 @@ class VFraction(VGeneric): def o_ne(self, other, builder): 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): if not isinstance(other, (VInt, VFraction)): return NotImplemented