示例#1
0
    def o_roundx(self, target_bits, builder):
        if builder is None:
            return VInt(target_bits)
        else:
            r = VInt(64)
            a, b = self._nd(builder)
            h_b = builder.ashr(b, ll.Constant(ll.IntType(64), 1))

            function = builder.basic_block.function
            add_block = function.append_basic_block("fr_add")
            sub_block = function.append_basic_block("fr_sub")
            merge_block = function.append_basic_block("fr_merge")

            condition = builder.icmp_signed(
                "<", a, ll.Constant(ll.IntType(64), 0))
            builder.cbranch(condition, sub_block, add_block)

            builder.position_at_end(add_block)
            a_add = builder.add(a, h_b)
            builder.branch(merge_block)
            builder.position_at_end(sub_block)
            a_sub = builder.sub(a, h_b)
            builder.branch(merge_block)

            builder.position_at_end(merge_block)
            a = builder.phi(ll.IntType(64))
            a.add_incoming(a_add, add_block)
            a.add_incoming(a_sub, sub_block)
            r.auto_store(builder, builder.sdiv(a, b))
            return r.o_intx(target_bits, builder)
示例#2
0
文件: fractions.py 项目: cr1901/artiq
    def o_roundx(self, target_bits, builder):
        if builder is None:
            return VInt(target_bits)
        else:
            r = VInt(64)
            a, b = self._nd(builder)
            h_b = builder.ashr(b, ll.Constant(ll.IntType(64), 1))

            function = builder.basic_block.function
            add_block = function.append_basic_block("fr_add")
            sub_block = function.append_basic_block("fr_sub")
            merge_block = function.append_basic_block("fr_merge")

            condition = builder.icmp_signed(
                "<", a, ll.Constant(ll.IntType(64), 0))
            builder.cbranch(condition, sub_block, add_block)

            builder.position_at_end(add_block)
            a_add = builder.add(a, h_b)
            builder.branch(merge_block)
            builder.position_at_end(sub_block)
            a_sub = builder.sub(a, h_b)
            builder.branch(merge_block)

            builder.position_at_end(merge_block)
            a = builder.phi(ll.IntType(64))
            a.add_incoming(a_add, add_block)
            a.add_incoming(a_sub, sub_block)
            r.auto_store(builder, builder.sdiv(a, b))
            return r.o_intx(target_bits, builder)
示例#3
0
文件: arrays.py 项目: yuyichao/artiq
    def set_value(self, builder, v):
        if not isinstance(v, VArray):
            raise TypeError
        if v.llvm_value is not None:
            raise NotImplementedError("Array aliasing is not supported")

        i = VInt()
        i.alloca(builder, "ai_i")
        i.auto_store(builder, lc.Constant.int(lc.Type.int(), 0))

        function = builder.basic_block.function
        copy_block = function.append_basic_block("ai_copy")
        end_block = function.append_basic_block("ai_end")
        builder.branch(copy_block)

        builder.position_at_end(copy_block)
        self.o_subscript(i, builder).set_value(builder, v.el_init)
        i.auto_store(builder, builder.add(
            i.auto_load(builder), lc.Constant.int(lc.Type.int(), 1)))
        cont = builder.icmp(
            lc.ICMP_SLT, i.auto_load(builder),
            lc.Constant.int(lc.Type.int(), self.count))
        builder.cbranch(cont, copy_block, end_block)

        builder.position_at_end(end_block)
示例#4
0
文件: fractions.py 项目: cr1901/artiq
 def o_intx(self, target_bits, builder):
     if builder is None:
         return VInt(target_bits)
     else:
         r = VInt(64)
         a, b = self._nd(builder)
         r.auto_store(builder, builder.sdiv(a, b))
         return r.o_intx(target_bits, builder)
示例#5
0
文件: lists.py 项目: fallen/artiq
 def o_len(self, builder):
     r = VInt()
     if builder is not None:
         count_ptr = builder.gep(self.llvm_value, [
             ll.Constant(ll.IntType(32), 0),
             ll.Constant(ll.IntType(32), 0)])
         r.auto_store(builder, builder.load(count_ptr))
     return r
示例#6
0
 def o_intx(self, target_bits, builder):
     if builder is None:
         return VInt(target_bits)
     else:
         r = VInt(64)
         a, b = self._nd(builder)
         r.auto_store(builder, builder.sdiv(a, b))
         return r.o_intx(target_bits, builder)
示例#7
0
文件: lists.py 项目: neuroidss/artiq
 def o_len(self, builder):
     r = VInt()
     if builder is not None:
         count_ptr = builder.gep(self.llvm_value, [
             ll.Constant(ll.IntType(32), 0),
             ll.Constant(ll.IntType(32), 0)])
         r.auto_store(builder, builder.load(count_ptr))
     return r
示例#8
0
文件: fractions.py 项目: cr1901/artiq
 def o_getattr(self, attr, builder):
     if attr == "numerator":
         idx = 0
     elif attr == "denominator":
         idx = 1
     else:
         raise AttributeError
     r = VInt(64)
     if builder is not None:
         elt = builder.extract_value(self.auto_load(builder), idx)
         r.auto_store(builder, elt)
     return r
示例#9
0
 def o_getattr(self, attr, builder):
     if attr == "numerator":
         idx = 0
     elif attr == "denominator":
         idx = 1
     else:
         raise AttributeError
     r = VInt(64)
     if builder is not None:
         elt = builder.extract_value(self.auto_load(builder), idx)
         r.auto_store(builder, elt)
     return r
示例#10
0
 def o_getattr(self, attr, builder):
     if attr == "numerator":
         idx = 0
     elif attr == "denominator":
         idx = 1
     else:
         raise AttributeError
     r = VInt(64)
     if builder is not None:
         elt = builder.extract_element(
             self.auto_load(builder),
             lc.Constant.int(lc.Type.int(), idx))
         r.auto_store(builder, elt)
     return r