def test_extend_reduce(self): # type: () -> None r = Rtl( self.v1 << uextend(self.v0), self.v2 << ireduce(self.v1), self.v3 << sextend(self.v2), ) ti = TypeEnv() typing = ti_rtl(r, ti) typing = typing.extract() itype0 = TypeVar("t", "", ints=True, simd=(1, 256)) itype1 = TypeVar("t1", "", ints=True, simd=(1, 256)) itype2 = TypeVar("t2", "", ints=True, simd=(1, 256)) itype3 = TypeVar("t3", "", ints=True, simd=(1, 256)) check_typing(typing, ({ self.v0: itype0, self.v1: itype1, self.v2: itype2, self.v3: itype3, }, [ WiderOrEq(itype1, itype0), WiderOrEq(itype1, itype2), WiderOrEq(itype3, itype2) ]))
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_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()
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_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 test_reduce_extend(self): # type: () -> None r = Rtl( self.v1 << uextend(self.v0), self.v2 << ireduce(self.v1), self.v3 << sextend(self.v2), ) x = XForm(r, r) tv0_exp = 'Some({})'.format(self.v0.get_typevar().name) tv1_exp = 'Some({})'.format(self.v1.get_typevar().name) tv2_exp = 'Some({})'.format(self.v2.get_typevar().name) tv3_exp = 'Some({})'.format(self.v3.get_typevar().name) self.check_yo_check( x, sequence(wider_check(tv1_exp, tv0_exp), wider_check(tv1_exp, tv2_exp), wider_check(tv3_exp, tv2_exp)))
def test_bound_inst_inference1(self): # Second example taken from issue #26 x = XForm( Rtl(self.v0 << iadd(self.v1, self.v2), ), Rtl(self.v3 << uextend(self.v1), self.v4 << uextend(self.v2), self.v5 << iadd.i32(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_reduce_extend(self): # type: () -> None r = Rtl( self.v1 << uextend(self.v0), self.v2 << ireduce(self.v1), self.v3 << sextend(self.v2), ) x = XForm(r, r) tv0_exp = 'Some({})'.format(self.v0.get_typevar().name) tv1_exp = 'Some({})'.format(self.v1.get_typevar().name) tv2_exp = 'Some({})'.format(self.v2.get_typevar().name) tv3_exp = 'Some({})'.format(self.v3.get_typevar().name) self.check_yo_check( x, sequence(wider_check(tv1_exp, tv0_exp), wider_check(tv1_exp, tv2_exp), wider_check(tv3_exp, tv2_exp)))
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_bound_inst_inference1(self): # Second example taken from issue #26 x = XForm( Rtl( self.v0 << iadd(self.v1, self.v2), ), Rtl( self.v3 << uextend(self.v1), self.v4 << uextend(self.v2), self.v5 << iadd.i32(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_extend_reduce(self): # type: () -> None r = Rtl( self.v1 << uextend(self.v0), self.v2 << ireduce(self.v1), self.v3 << sextend(self.v2), ) ti = TypeEnv() typing = ti_rtl(r, ti) typing = typing.extract() itype0 = TypeVar("t", "", ints=True, simd=(1, 256)) itype1 = TypeVar("t1", "", ints=True, simd=(1, 256)) itype2 = TypeVar("t2", "", ints=True, simd=(1, 256)) itype3 = TypeVar("t3", "", ints=True, simd=(1, 256)) check_typing(typing, ({ self.v0: itype0, self.v1: itype1, self.v2: itype2, self.v3: itype3, }, [WiderOrEq(itype1, itype0), WiderOrEq(itype1, itype2), WiderOrEq(itype3, itype2)]))