Exemple #1
0
    def test_bint(self):
        # type: () -> None
        x = Var('x')
        y = Var('y')
        z = Var('z')
        w = Var('w')
        v = Var('v')
        u = Var('u')

        r = Rtl(
            z << iadd(x, y),
            w << bint(v),
            u << iadd(z, w)
        )
        r1 = r.copy({})
        s = r.substitution(r1, {})

        s[x].set_typevar(TypeVar.singleton(i32.by(8)))
        s[z].set_typevar(TypeVar.singleton(i32.by(8)))
        # TODO: Relax this to simd=True
        s[v].set_typevar(TypeVar('v', '', bools=(1, 1), simd=(8, 8)))
        r1.cleanup_concrete_rtl()

        assert s is not None
        assert s[x].get_typevar().singleton_type() == i32.by(8)
        assert s[y].get_typevar().singleton_type() == i32.by(8)
        assert s[z].get_typevar().singleton_type() == i32.by(8)
        assert s[w].get_typevar().singleton_type() == i32.by(8)
        assert s[u].get_typevar().singleton_type() == i32.by(8)
        assert s[v].get_typevar().singleton_type() == b1.by(8)
Exemple #2
0
    def test_vselect_icmpimm(self):
        # type: () -> None
        x = Var('x')
        y = Var('y')
        z = Var('z')
        w = Var('w')
        v = Var('v')
        zeroes = Var('zeroes')
        imm0 = Var("imm0")

        r = Rtl(
                zeroes << iconst(imm0),
                y << icmp(intcc.eq, x, zeroes),
                v << vselect(y, z, w),
        )
        r1 = r.copy({})

        s = r.substitution(r1, {})
        s[zeroes].set_typevar(TypeVar.singleton(i32.by(4)))
        s[z].set_typevar(TypeVar.singleton(f32.by(4)))

        r1.cleanup_concrete_rtl()

        assert s is not None
        assert s[zeroes].get_typevar().singleton_type() == i32.by(4)
        assert s[x].get_typevar().singleton_type() == i32.by(4)
        assert s[y].get_typevar().singleton_type() == b32.by(4)
        assert s[z].get_typevar().singleton_type() == f32.by(4)
        assert s[w].get_typevar().singleton_type() == f32.by(4)
        assert s[v].get_typevar().singleton_type() == f32.by(4)
Exemple #3
0
 def setUp(self):
     # type: () -> None
     self.v0 = Var("v0")
     self.v1 = Var("v1")
     self.v2 = Var("v2")
     self.v3 = Var("v3")
     self.v4 = Var("v4")
     self.v5 = Var("v5")
     self.v6 = Var("v6")
     self.v7 = Var("v7")
     self.v8 = Var("v8")
     self.v9 = Var("v9")
     self.imm0 = Var("imm0")
     self.IxN_nonscalar = TypeVar("IxN_nonscalar",
                                  "",
                                  ints=True,
                                  scalars=False,
                                  simd=True)
     self.TxN = TypeVar("TxN",
                        "",
                        ints=True,
                        bools=True,
                        floats=True,
                        scalars=False,
                        simd=True)
     self.b1 = TypeVar.singleton(b1)
Exemple #4
0
    def test_cleanup_concrete_rtl_ireduce_bad(self):
        # type: () -> None
        x = Var('x')
        y = Var('y')
        x.set_typevar(TypeVar.singleton(i16.by(1)))
        r = Rtl(
                y << ireduce(x),
        )

        with self.assertRaises(AssertionError):
            r.cleanup_concrete_rtl()
Exemple #5
0
    def test_cleanup_concrete_rtl_ireduce(self):
        # type: () -> None
        x = Var('x')
        y = Var('y')
        r = Rtl(
                y << ireduce(x),
        )
        r1 = r.copy({})
        s = r.substitution(r1, {})
        s[x].set_typevar(TypeVar.singleton(i8.by(2)))
        r1.cleanup_concrete_rtl()

        assert s is not None
        assert s[x].get_typevar().singleton_type() == i8.by(2)
        assert s[y].get_typevar().singleton_type() == i8.by(2)
 def setUp(self):
     # type: () -> None
     self.v0 = Var("v0")
     self.v1 = Var("v1")
     self.v2 = Var("v2")
     self.v3 = Var("v3")
     self.v4 = Var("v4")
     self.v5 = Var("v5")
     self.v6 = Var("v6")
     self.v7 = Var("v7")
     self.v8 = Var("v8")
     self.v9 = Var("v9")
     self.imm0 = Var("imm0")
     self.IxN_nonscalar = TypeVar("IxN_nonscalar", "", ints=True,
                                  scalars=False, simd=True)
     self.TxN = TypeVar("TxN", "", ints=True, bools=True, floats=True,
                        scalars=False, simd=True)
     self.b1 = TypeVar.singleton(b1)
Exemple #7
0
    def test_cleanup_concrete_rtl(self):
        # type: () -> None
        typ = i64.by(4)
        x = Var('x')
        lo = Var('lo')
        hi = Var('hi')

        r = Rtl(
                (lo, hi) << vsplit(x),
        )
        r1 = r.copy({})
        s = r.substitution(r1, {})

        s[x].set_typevar(TypeVar.singleton(typ))
        r1.cleanup_concrete_rtl()
        assert s is not None
        assert s[x].get_typevar().singleton_type() == typ
        assert s[lo].get_typevar().singleton_type() == i64.by(2)
        assert s[hi].get_typevar().singleton_type() == i64.by(2)
GROUP = InstructionGroup("primitive", "Primitive instruction set")

BV = TypeVar('BV', 'A bitvector type.', bitvecs=True)
BV1 = TypeVar('BV1', 'A single bit bitvector.', bitvecs=(1, 1))
Real = TypeVar('Real',
               'Any real type.',
               ints=True,
               floats=True,
               bools=True,
               simd=True)

x = Operand('x', BV, doc="A semantic value X")
y = Operand('x', BV, doc="A semantic value Y (same width as X)")
a = Operand('a', BV, doc="A semantic value A (same width as X)")
cond = Operand('b', TypeVar.singleton(b1), doc='A b1 value')

real = Operand('real', Real, doc="A real cranelift value")
fromReal = Operand('fromReal',
                   Real.to_bitvec(),
                   doc="A real cranelift value converted to a BV")

#
# BV Conversion/Materialization
#
prim_to_bv = Instruction('prim_to_bv',
                         r"""
        Convert an SSA Value to a flat bitvector
        """,
                         ins=(real),
                         outs=(fromReal))
Exemple #9
0
from cdsl.ti import WiderOrEq
from base.types import b1
from base.immediates import imm64
import base.formats # noqa

GROUP = InstructionGroup("primitive", "Primitive instruction set")

BV = TypeVar('BV', 'A bitvector type.', bitvecs=True)
BV1 = TypeVar('BV1', 'A single bit bitvector.', bitvecs=(1, 1))
Real = TypeVar('Real', 'Any real type.', ints=True, floats=True,
               bools=True, simd=True)

x = Operand('x', BV, doc="A semantic value X")
y = Operand('x', BV, doc="A semantic value Y (same width as X)")
a = Operand('a', BV, doc="A semantic value A (same width as X)")
cond = Operand('b', TypeVar.singleton(b1), doc='A b1 value')

real = Operand('real', Real, doc="A real cretonne value")
fromReal = Operand('fromReal', Real.to_bitvec(),
                   doc="A real cretonne value converted to a BV")

#
# BV Conversion/Materialization
#
prim_to_bv = Instruction(
        'prim_to_bv', r"""
        Convert an SSA Value to a flat bitvector
        """,
        ins=(real), outs=(fromReal))

prim_from_bv = Instruction(