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)
def test_double_def(self): src = Rtl( a << iadd_imm(x, 1), a << iadd(x, y)) dst = Rtl(a << iadd(x, y)) with self.assertRaisesRegexp(AssertionError, "'a' multiply defined"): XForm(src, dst)
def test_fully_bound_inst_inference_bad(self): # Can't force a mistyped XForm using bound instructions with self.assertRaises(AssertionError): XForm( Rtl(self.v0 << iadd(self.v1, self.v2), ), Rtl(self.v3 << uextend.i32.i8(self.v1), self.v4 << uextend.i32.i16(self.v2), self.v5 << iadd(self.v3, self.v4), self.v0 << ireduce(self.v5)))
def test_fully_bound_inst_inference_bad(self): # Can't force a mistyped XForm using bound instructions with self.assertRaises(AssertionError): XForm( Rtl( self.v0 << iadd(self.v1, self.v2), ), Rtl( self.v3 << uextend.i32.i8(self.v1), self.v4 << uextend.i32.i16(self.v2), self.v5 << iadd(self.v3, self.v4), self.v0 << ireduce(self.v5) ))
def test_iadd_cin(self): # type: () -> None x = XForm( Rtl(self.v0 << iadd_cin(self.v1, self.v2, self.v3)), Rtl(self.v4 << iadd(self.v1, self.v2), self.v5 << bint(self.v3), self.v0 << iadd(self.v4, self.v5))) itype = TypeVar("t", "", ints=True, simd=(1, 1)) check_typing(x.ti, ({ self.v0: itype, self.v1: itype, self.v2: itype, self.v3: self.b1, self.v4: itype, self.v5: itype, }, []), x.symtab)
def test_iadd_cin(self): # type: () -> None x = XForm(Rtl(self.v0 << iadd_cin(self.v1, self.v2, self.v3)), Rtl( self.v4 << iadd(self.v1, self.v2), self.v5 << bint(self.v3), self.v0 << iadd(self.v4, self.v5) )) itype = TypeVar("t", "", ints=True, simd=(1, 1)) check_typing(x.ti, ({ self.v0: itype, self.v1: itype, self.v2: itype, self.v3: self.b1, self.v4: itype, self.v5: itype, }, []), x.symtab)
def test_bound_inst_inference(self): # First example from issue #26 x = XForm( Rtl(self.v0 << iadd(self.v1, self.v2), ), Rtl(self.v3 << uextend.i32(self.v1), self.v4 << uextend.i32(self.v2), self.v5 << iadd(self.v3, self.v4), self.v0 << ireduce(self.v5))) itype = TypeVar("t", "", ints=True, simd=True) i32t = TypeVar.singleton(i32) check_typing(x.ti, ({ self.v0: itype, self.v1: itype, self.v2: itype, self.v3: i32t, self.v4: i32t, self.v5: i32t, }, [WiderOrEq(i32t, itype)]), x.symtab)
def test_fully_bound_inst_inference(self): # Second example taken from issue #26 with complete bounds x = XForm( Rtl(self.v0 << iadd(self.v1, self.v2), ), Rtl(self.v3 << uextend.i32.i8(self.v1), self.v4 << uextend.i32.i8(self.v2), self.v5 << iadd(self.v3, self.v4), self.v0 << ireduce(self.v5))) i8t = TypeVar.singleton(i8) i32t = TypeVar.singleton(i32) # Note no constraints here since they are all trivial check_typing(x.ti, ({ self.v0: i8t, self.v1: i8t, self.v2: i8t, self.v3: i32t, self.v4: i32t, self.v5: i32t, }, []), x.symtab)
def test_bint(self): # type: () -> None r = Rtl(self.v4 << iadd(self.v1, self.v2), self.v5 << bint(self.v3), self.v0 << iadd(self.v4, self.v5)) ti = TypeEnv() typing = ti_rtl(r, ti) itype = TypeVar("t", "", ints=True, simd=(1, 256)) btype = TypeVar("b", "", bools=True, simd=True) # Check that self.v5 gets the same integer type as # the rest of them # TODO: Add constraint nlanes(v3) == nlanes(v1) when we # add that type constraint to bint check_typing(typing, ({ self.v1: itype, self.v2: itype, self.v4: itype, self.v5: itype, self.v3: btype, self.v0: itype, }, []))
def test_fully_bound_inst_inference_bad(self): # Incompatible bound instructions fail accordingly r = Rtl( self.v3 << uextend.i32(self.v1), self.v4 << uextend.i16(self.v2), self.v5 << iadd(self.v3, self.v4), ) ti = TypeEnv() typing = ti_rtl(r, ti) self.assertEqual( typing, "On line 2: fail ti on `typeof_v4` <: `4`: " + "Error: empty type created when unifying " + "`i16` and `i32`")
def test_bound_inst_inference(self): # First example from issue #26 x = XForm( Rtl( self.v0 << iadd(self.v1, self.v2), ), Rtl( self.v3 << uextend.i32(self.v1), self.v4 << uextend.i32(self.v2), self.v5 << iadd(self.v3, self.v4), self.v0 << ireduce(self.v5) )) itype = TypeVar("t", "", ints=True, simd=True) i32t = TypeVar.singleton(i32) check_typing(x.ti, ({ self.v0: itype, self.v1: itype, self.v2: itype, self.v3: i32t, self.v4: i32t, self.v5: i32t, }, [WiderOrEq(i32t, itype)]), x.symtab)
def test_fully_bound_inst_inference_bad(self): # Incompatible bound instructions fail accordingly r = Rtl( self.v3 << uextend.i32(self.v1), self.v4 << uextend.i16(self.v2), self.v5 << iadd(self.v3, self.v4), ) ti = TypeEnv() typing = ti_rtl(r, ti) self.assertEqual(typing, "On line 2: fail ti on `typeof_v4` <: `4`: " + "Error: empty type created when unifying " + "`i16` and `i32`")
def test_iadd_cout(self): # type: () -> None x = XForm( Rtl((self.v0, self.v1) << iadd_cout(self.v2, self.v3), ), Rtl(self.v0 << iadd(self.v2, self.v3), self.v1 << icmp(intcc.ult, self.v0, self.v2))) itype = TypeVar("t", "", ints=True, simd=(1, 1)) check_typing(x.ti, ({ self.v0: itype, self.v2: itype, self.v3: itype, self.v1: itype.as_bool(), }, []), x.symtab)
def test_iadd_cout(self): # type: () -> None x = XForm(Rtl((self.v0, self.v1) << iadd_cout(self.v2, self.v3),), Rtl( self.v0 << iadd(self.v2, self.v3), self.v1 << icmp(intcc.ult, self.v0, self.v2) )) itype = TypeVar("t", "", ints=True, simd=(1, 1)) check_typing(x.ti, ({ self.v0: itype, self.v2: itype, self.v3: itype, self.v1: itype.as_bool(), }, []), x.symtab)
def test_bint(self): # type: () -> None r = Rtl( self.v4 << iadd(self.v1, self.v2), self.v5 << bint(self.v3), self.v0 << iadd(self.v4, self.v5) ) ti = TypeEnv() typing = ti_rtl(r, ti) itype = TypeVar("t", "", ints=True, simd=(1, 256)) btype = TypeVar("b", "", bools=True, simd=True) # Check that self.v5 gets the same integer type as # the rest of them # TODO: Add constraint nlanes(v3) == nlanes(v1) when we # add that type constraint to bint check_typing(typing, ({ self.v1: itype, self.v2: itype, self.v4: itype, self.v5: itype, self.v3: btype, self.v0: itype, }, []))
def test_fully_bound_inst_inference(self): # Second example taken from issue #26 with complete bounds x = XForm( Rtl( self.v0 << iadd(self.v1, self.v2), ), Rtl( self.v3 << uextend.i32.i8(self.v1), self.v4 << uextend.i32.i8(self.v2), self.v5 << iadd(self.v3, self.v4), self.v0 << ireduce(self.v5) )) i8t = TypeVar.singleton(i8) i32t = TypeVar.singleton(i32) # Note no constraints here since they are all trivial check_typing(x.ti, ({ self.v0: i8t, self.v1: i8t, self.v2: i8t, self.v3: i32t, self.v4: i32t, self.v5: i32t, }, []), x.symtab)
def test_macro_pattern(self): src = Rtl(a << iadd_imm(x, y)) dst = Rtl( c << iconst(y), a << iadd(x, c)) XForm(src, dst)
qv13 = Var('qv13') qv14 = Var('qv14') qv15 = Var('qv15') qv16 = Var('qv16') qc77 = Var('qc77') qc0F = Var('qc0F') qc01 = Var('qc01') x86_expand.legalize( qv16 << insts.popcnt.i64(qv1), Rtl(qv3 << insts.ushr_imm(qv1, imm64(1)), qc77 << insts.iconst(imm64(0x7777777777777777)), qv4 << insts.band(qv3, qc77), qv5 << insts.isub(qv1, qv4), qv6 << insts.ushr_imm(qv4, imm64(1)), qv7 << insts.band(qv6, qc77), qv8 << insts.isub(qv5, qv7), qv9 << insts.ushr_imm(qv7, imm64(1)), qv10 << insts.band(qv9, qc77), qv11 << insts.isub(qv8, qv10), qv12 << insts.ushr_imm(qv11, imm64(4)), qv13 << insts.iadd(qv11, qv12), qc0F << insts.iconst(imm64(0x0F0F0F0F0F0F0F0F)), qv14 << insts.band(qv13, qc0F), qc01 << insts.iconst(imm64(0x0101010101010101)), qv15 << insts.imul(qv14, qc01), qv16 << insts.ushr_imm(qv15, imm64(56)))) lv1 = Var('lv1') lv3 = Var('lv3') lv4 = Var('lv4') lv5 = Var('lv5') lv6 = Var('lv6') lv7 = Var('lv7') lv8 = Var('lv8') lv9 = Var('lv9') lv10 = Var('lv10')
def test_extra_input(self): src = Rtl(a << iadd_imm(x, 1)) dst = Rtl(a << iadd(x, y)) with self.assertRaisesRegexp(AssertionError, "extra inputs in dst"): XForm(src, dst)
qc01 = Var('qc01') intel_expand.legalize( qv16 << insts.popcnt.i64(qv1), Rtl( qv3 << insts.ushr_imm(qv1, imm64(1)), qc77 << insts.iconst(imm64(0x7777777777777777)), qv4 << insts.band(qv3, qc77), qv5 << insts.isub(qv1, qv4), qv6 << insts.ushr_imm(qv4, imm64(1)), qv7 << insts.band(qv6, qc77), qv8 << insts.isub(qv5, qv7), qv9 << insts.ushr_imm(qv7, imm64(1)), qv10 << insts.band(qv9, qc77), qv11 << insts.isub(qv8, qv10), qv12 << insts.ushr_imm(qv11, imm64(4)), qv13 << insts.iadd(qv11, qv12), qc0F << insts.iconst(imm64(0x0F0F0F0F0F0F0F0F)), qv14 << insts.band(qv13, qc0F), qc01 << insts.iconst(imm64(0x0101010101010101)), qv15 << insts.imul(qv14, qc01), qv16 << insts.ushr_imm(qv15, imm64(56)) )) lv1 = Var('lv1') lv3 = Var('lv3') lv4 = Var('lv4') lv5 = Var('lv5') lv6 = Var('lv6') lv7 = Var('lv7') lv8 = Var('lv8') lv9 = Var('lv9')