Beispiel #1
0
    def prepare_op_jump(self, op, fcond):
        assert self.jump_target_descr is None
        descr = op.getdescr()
        assert isinstance(descr, TargetToken)
        self.jump_target_descr = descr
        arglocs = self.assembler.target_arglocs(descr)

        # get temporary locs
        tmploc = r.ip
        vfptmploc = r.vfp_ip

        # Part about non-floats
        src_locations1 = []
        dst_locations1 = []
        # Part about floats
        src_locations2 = []
        dst_locations2 = []

        # Build the four lists
        for i in range(op.numargs()):
            box = op.getarg(i)
            src_loc = self.loc(box)
            dst_loc = arglocs[i]
            if box.type != FLOAT:
                src_locations1.append(src_loc)
                dst_locations1.append(dst_loc)
            else:
                src_locations2.append(src_loc)
                dst_locations2.append(dst_loc)
        self.assembler.check_frame_before_jump(self.jump_target_descr)
        remap_frame_layout_mixed(self.assembler, src_locations1,
                                 dst_locations1, tmploc, src_locations2,
                                 dst_locations2, vfptmploc)
        return []
Beispiel #2
0
 def test_mixed3(self):
     s23 = frame_pos(2, FLOAT)
     s2 = frame_pos(2, INT)
     remap_frame_layout_mixed(self.assembler, [r1], [s2], 'tmp', [s23],
                              [d5], 'vfptmp')
     assert self.assembler.ops == [('push', s23), ('mov', r1, s2),
                                   ('pop', d5)]
Beispiel #3
0
 def test_mixed6(self):
     s3 = frame_pos(3, INT)
     s23 = frame_pos(2, FLOAT)
     s4 = frame_pos(4, INT)
     s45 = frame_pos(4, FLOAT)
     remap_frame_layout_mixed(self.assembler, [s4], [s3], r3, [s23], [s45], d3)
     assert self.assembler.ops == [("push", s23), ("mov", s4, r3), ("mov", r3, s3), ("pop", s45)]
Beispiel #4
0
 def test_mixed2(self):
     s23 = frame_pos(2, FLOAT)  # gets stored in pos 2 and 3, with value==3
     s3 = frame_pos(3, INT)
     remap_frame_layout_mixed(self.assembler, [r1], [s3], 'tmp', [s23],
                              [d5], 'vfptmp')
     assert self.assembler.ops == [('push', s23), ('mov', r1, s3),
                                   ('pop', d5)]
Beispiel #5
0
    def prepare_op_jump(self, op, fcond):
        assert self.jump_target_descr is None
        descr = op.getdescr()
        assert isinstance(descr, TargetToken)
        self.jump_target_descr = descr
        arglocs = self.assembler.target_arglocs(descr)

        # get temporary locs
        tmploc = r.ip
        vfptmploc = r.vfp_ip

        # Part about non-floats
        src_locations1 = []
        dst_locations1 = []
        # Part about floats
        src_locations2 = []
        dst_locations2 = []

        # Build the four lists
        for i in range(op.numargs()):
            box = op.getarg(i)
            src_loc = self.loc(box)
            dst_loc = arglocs[i]
            if box.type != FLOAT:
                src_locations1.append(src_loc)
                dst_locations1.append(dst_loc)
            else:
                src_locations2.append(src_loc)
                dst_locations2.append(dst_loc)
        self.assembler.check_frame_before_jump(self.jump_target_descr)
        remap_frame_layout_mixed(self.assembler,
                                 src_locations1, dst_locations1, tmploc,
                                 src_locations2, dst_locations2, vfptmploc)
        return []
Beispiel #6
0
 def test_mixed4(self):
     s23 = frame_pos(2, FLOAT)
     s4 = frame_pos(4, INT)
     s45 = frame_pos(4, FLOAT)
     s1 = frame_pos(1, INT)
     remap_frame_layout_mixed(self.assembler, [s4], [s1], r3, [s23], [s45], d3)
     assert self.assembler.ops == [("mov", s4, r3), ("mov", r3, s1), ("mov", s23, d3), ("mov", d3, s45)]
Beispiel #7
0
 def test_mixed6(self):
     s3 = frame_pos(3, INT)
     s23 = frame_pos(2, FLOAT)
     s4 = frame_pos(4, INT)
     s45 = frame_pos(4, FLOAT)
     remap_frame_layout_mixed(self.assembler, [s4], [s3], r3, [s23], [s45],
                              d3)
     assert self.assembler.ops == [('push', s23), ('mov', s4, r3),
                                   ('mov', r3, s3), ('pop', s45)]
Beispiel #8
0
 def test_mixed4(self):
     s23 = frame_pos(2, FLOAT)
     s4 = frame_pos(4, INT)
     s45 = frame_pos(4, FLOAT)
     s1 = frame_pos(1, INT)
     remap_frame_layout_mixed(self.assembler, [s4], [s1], r3, [s23], [s45],
                              d3)
     assert self.assembler.ops == [('mov', s4, r3), ('mov', r3, s1),
                                   ('mov', s23, d3), ('mov', d3, s45)]
Beispiel #9
0
def test_random_mixed():
    assembler = MockAssembler()
    registers1 = all_regs
    registers2 = all_vfp_regs
    VFPWORDS = 2

    #
    def pick1():
        n = random.randrange(-3, 10)
        if n < 0:
            return registers1[n]
        else:
            return frame_pos(n, INT)

    def pick2():
        n = random.randrange(-3, 10 // VFPWORDS)
        if n < 0:
            return registers2[n]
        else:
            return frame_pos(n * VFPWORDS, FLOAT)

    #
    def pick1c():
        n = random.randrange(-2000, 500)
        if n >= 0:
            return imm(n)
        else:
            return pick1()

    #
    def pick_dst(fn, count, seen):
        result = []
        while len(result) < count:
            x = fn()
            keys = [x.as_key()]
            if x.is_stack() and x.width > WORD:
                keys.append(keys[0] + 1)
            for key in keys:
                if key in seen:
                    break
            else:
                for key in keys:
                    seen[key] = True
                result.append(x)
        return result

    #
    def get_state(locations):
        regs1 = {}
        regs2 = {}
        stack = {}
        for i, loc in enumerate(locations):
            if loc.is_vfp_reg():
                if loc.width > WORD:
                    newvalue = ('value-vfp-%d' % i, 'value-vfp-hiword-%d' % i)
                else:
                    newvalue = 'value-vfp-%d' % i
                regs2[loc.value] = newvalue
            elif loc.is_core_reg():
                regs1[loc.value] = 'value-int-%d' % i
            elif loc.is_stack():
                stack[loc.position] = 'value-width%d-%d' % (loc.width, i)
                if loc.width > WORD:
                    stack[loc.position + 1] = 'value-hiword-%d' % i
            else:
                assert loc.is_imm() or loc.is_imm_float()
        return regs1, regs2, stack

    #
    for i in range(500):
        seen = {}
        src_locations2 = [pick2() for i in range(4)]
        dst_locations2 = pick_dst(pick2, 4, seen)
        src_locations1 = [pick1c() for i in range(5)]
        dst_locations1 = pick_dst(pick1, 5, seen)
        assembler = MockAssembler()
        remap_frame_layout_mixed(assembler, src_locations1, dst_locations1, ip,
                                 src_locations2, dst_locations2, vfp_ip)
        #
        regs1, regs2, stack = get_state(src_locations1 + src_locations2)

        #
        def read(loc, expected_width=None):
            if expected_width is not None:
                assert loc.width == expected_width * WORD
            if loc.is_vfp_reg():
                return regs2[loc.value]
            elif loc.is_core_reg():
                return regs1[loc.value]
            elif loc.is_stack():
                got = stack[loc.position]
                if loc.width > WORD:
                    got = (got, stack[loc.position + 1])
                return got
            if loc.is_imm() or loc.is_imm_float():
                return 'const-%d' % loc.value
            assert 0, loc

        #
        def write(loc, newvalue):
            if loc.is_vfp_reg():
                regs2[loc.value] = newvalue
            elif loc.is_core_reg():
                regs1[loc.value] = newvalue
            elif loc.is_stack():
                if loc.width > WORD:
                    newval1, newval2 = newvalue
                    stack[loc.position] = newval1
                    stack[loc.position + 1] = newval2
                else:
                    stack[loc.position] = newvalue
            else:
                assert 0, loc

        #
        src_values1 = [read(loc, 1) for loc in src_locations1]
        src_values2 = [read(loc, 2) for loc in src_locations2]
        #
        extrapushes = []
        for op in assembler.ops:
            if op[0] == 'mov':
                src, dst = op[1:]
                assert src.is_core_reg() or src.is_vfp_reg() or src.is_stack(
                ) or src.is_imm_float() or src.is_imm()
                assert dst.is_core_reg() or dst.is_vfp_reg() or dst.is_stack()
                assert not (src.is_stack() and dst.is_stack())
                write(dst, read(src))
            elif op[0] == 'push':
                src, = op[1:]
                assert src.is_core_reg() or src.is_vfp_reg() or src.is_stack()
                extrapushes.append(read(src))
            elif op[0] == 'pop':
                dst, = op[1:]
                assert dst.is_core_reg() or dst.is_vfp_reg() or dst.is_stack()
                write(dst, extrapushes.pop())
            else:
                assert 0, "unknown op: %r" % (op, )
        assert not extrapushes
        #
        for i, loc in enumerate(dst_locations1):
            assert read(loc, 1) == src_values1[i]
        for i, loc in enumerate(dst_locations2):
            assert read(loc, 2) == src_values2[i]
Beispiel #10
0
 def test_mixed(self):
     s23 = frame_pos(2, FLOAT)  # non-conflicting locations
     s4 = frame_pos(4, INT)
     remap_frame_layout_mixed(self.assembler, [r1], [s4], 'tmp', [s23],
                              [d5], 'vfptmp')
     assert self.assembler.ops == [('mov', r1, s4), ('mov', s23, d5)]
Beispiel #11
0
def test_random_mixed():
    assembler = MockAssembler()
    registers1 = all_regs
    registers2 = all_vfp_regs
    VFPWORDS = 2
    #
    def pick1():
        n = random.randrange(-3, 10)
        if n < 0:
            return registers1[n]
        else:
            return frame_pos(n, INT)

    def pick2():
        n = random.randrange(-3, 10 // VFPWORDS)
        if n < 0:
            return registers2[n]
        else:
            return frame_pos(n * VFPWORDS, FLOAT)

    #
    def pick1c():
        n = random.randrange(-2000, 500)
        if n >= 0:
            return imm(n)
        else:
            return pick1()

    #
    def pick_dst(fn, count, seen):
        result = []
        while len(result) < count:
            x = fn()
            keys = [x.as_key()]
            if x.is_stack() and x.width > WORD:
                keys.append(keys[0] + 1)
            for key in keys:
                if key in seen:
                    break
            else:
                for key in keys:
                    seen[key] = True
                result.append(x)
        return result

    #
    def get_state(locations):
        regs1 = {}
        regs2 = {}
        stack = {}
        for i, loc in enumerate(locations):
            if loc.is_vfp_reg():
                if loc.width > WORD:
                    newvalue = ("value-vfp-%d" % i, "value-vfp-hiword-%d" % i)
                else:
                    newvalue = "value-vfp-%d" % i
                regs2[loc.value] = newvalue
            elif loc.is_core_reg():
                regs1[loc.value] = "value-int-%d" % i
            elif loc.is_stack():
                stack[loc.position] = "value-width%d-%d" % (loc.width, i)
                if loc.width > WORD:
                    stack[loc.position + 1] = "value-hiword-%d" % i
            else:
                assert loc.is_imm() or loc.is_imm_float()
        return regs1, regs2, stack

    #
    for i in range(500):
        seen = {}
        src_locations2 = [pick2() for i in range(4)]
        dst_locations2 = pick_dst(pick2, 4, seen)
        src_locations1 = [pick1c() for i in range(5)]
        dst_locations1 = pick_dst(pick1, 5, seen)
        assembler = MockAssembler()
        remap_frame_layout_mixed(assembler, src_locations1, dst_locations1, ip, src_locations2, dst_locations2, vfp_ip)
        #
        regs1, regs2, stack = get_state(src_locations1 + src_locations2)
        #
        def read(loc, expected_width=None):
            if expected_width is not None:
                assert loc.width == expected_width * WORD
            if loc.is_vfp_reg():
                return regs2[loc.value]
            elif loc.is_core_reg():
                return regs1[loc.value]
            elif loc.is_stack():
                got = stack[loc.position]
                if loc.width > WORD:
                    got = (got, stack[loc.position + 1])
                return got
            if loc.is_imm() or loc.is_imm_float():
                return "const-%d" % loc.value
            assert 0, loc

        #
        def write(loc, newvalue):
            if loc.is_vfp_reg():
                regs2[loc.value] = newvalue
            elif loc.is_core_reg():
                regs1[loc.value] = newvalue
            elif loc.is_stack():
                if loc.width > WORD:
                    newval1, newval2 = newvalue
                    stack[loc.position] = newval1
                    stack[loc.position + 1] = newval2
                else:
                    stack[loc.position] = newvalue
            else:
                assert 0, loc

        #
        src_values1 = [read(loc, 1) for loc in src_locations1]
        src_values2 = [read(loc, 2) for loc in src_locations2]
        #
        extrapushes = []
        for op in assembler.ops:
            if op[0] == "mov":
                src, dst = op[1:]
                assert src.is_core_reg() or src.is_vfp_reg() or src.is_stack() or src.is_imm_float() or src.is_imm()
                assert dst.is_core_reg() or dst.is_vfp_reg() or dst.is_stack()
                assert not (src.is_stack() and dst.is_stack())
                write(dst, read(src))
            elif op[0] == "push":
                src, = op[1:]
                assert src.is_core_reg() or src.is_vfp_reg() or src.is_stack()
                extrapushes.append(read(src))
            elif op[0] == "pop":
                dst, = op[1:]
                assert dst.is_core_reg() or dst.is_vfp_reg() or dst.is_stack()
                write(dst, extrapushes.pop())
            else:
                assert 0, "unknown op: %r" % (op,)
        assert not extrapushes
        #
        for i, loc in enumerate(dst_locations1):
            assert read(loc, 1) == src_values1[i]
        for i, loc in enumerate(dst_locations2):
            assert read(loc, 2) == src_values2[i]
Beispiel #12
0
 def test_mixed3(self):
     s23 = frame_pos(2, FLOAT)
     s2 = frame_pos(2, INT)
     remap_frame_layout_mixed(self.assembler, [r1], [s2], "tmp", [s23], [d5], "vfptmp")
     assert self.assembler.ops == [("push", s23), ("mov", r1, s2), ("pop", d5)]
Beispiel #13
0
 def test_mixed2(self):
     s23 = frame_pos(2, FLOAT)  # gets stored in pos 2 and 3, with value==3
     s3 = frame_pos(3, INT)
     remap_frame_layout_mixed(self.assembler, [r1], [s3], "tmp", [s23], [d5], "vfptmp")
     assert self.assembler.ops == [("push", s23), ("mov", r1, s3), ("pop", d5)]
Beispiel #14
0
 def test_mixed(self):
     s23 = frame_pos(2, FLOAT)  # non-conflicting locations
     s4 = frame_pos(4, INT)
     remap_frame_layout_mixed(self.assembler, [r1], [s4], "tmp", [s23], [d5], "vfptmp")
     assert self.assembler.ops == [("mov", r1, s4), ("mov", s23, d5)]