def test_subst_enum_var_const(self): src = Rtl(a << icmp(CC1, x, y)) dst = Rtl(b << icmp(intcc.eq, z, u)) assert src.substitution(dst, {}) == {CC1: intcc.eq, x: z, y: u, a: b},\ "{} != {}".format(src.substitution(dst, {}), {CC1: intcc.eq, x: z, y: u, a: b}) src = Rtl(a << icmp(intcc.eq, x, y)) dst = Rtl(b << icmp(CC1, z, u)) assert src.substitution(dst, {}) == {CC1: intcc.eq, x: z, y: u, a: b}
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)
def test_enumeration_with_constraints(self): # type: () -> None xform = XForm( Rtl( self.v0 << iconst(self.imm0), self.v1 << icmp(intcc.eq, self.v2, self.v0), self.v5 << vselect(self.v1, self.v3, self.v4) ), Rtl( self.v0 << iconst(self.imm0), self.v1 << icmp(intcc.eq, self.v2, self.v0), self.v5 << vselect(self.v1, self.v3, self.v4) )) # Check all var assigns are correct assert len(xform.ti.constraints) > 0 concrete_var_assigns = list(xform.ti.concrete_typings()) v0 = xform.symtab[str(self.v0)] v1 = xform.symtab[str(self.v1)] v2 = xform.symtab[str(self.v2)] v3 = xform.symtab[str(self.v3)] v4 = xform.symtab[str(self.v4)] v5 = xform.symtab[str(self.v5)] for var_m in concrete_var_assigns: assert var_m[v0] == var_m[v2] and \ var_m[v3] == var_m[v4] and\ var_m[v5] == var_m[v3] and\ var_m[v1] == var_m[v2].as_bool() and\ var_m[v1].get_typeset() == var_m[v3].as_bool().get_typeset() check_concrete_typing_xform(var_m, xform) # The number of possible typings here is: # 8 cases for v0 = i8xN times 2 options for v3 - i8, b8 = 16 # 8 cases for v0 = i16xN times 2 options for v3 - i16, b16 = 16 # 8 cases for v0 = i32xN times 3 options for v3 - i32, b32, f32 = 24 # 8 cases for v0 = i64xN times 3 options for v3 - i64, b64, f64 = 24 # # (Note we have 8 cases for lanes since vselect prevents scalars) # Total: 2*16 + 2*24 = 80 assert len(concrete_var_assigns) == 80
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_vselect_imm(self): # type: () -> None ts = TypeSet(lanes=(2, 256), ints=True, floats=True, bools=(8, 64)) r = Rtl( self.v0 << iconst(self.imm0), self.v1 << icmp(intcc.eq, self.v2, self.v0), self.v5 << vselect(self.v1, self.v3, self.v4), ) x = XForm(r, r) tv2_exp = 'Some({}).map(|t: Type| -> t.as_bool())'\ .format(self.v2.get_typevar().name) tv3_exp = 'Some({}).map(|t: Type| -> t.as_bool())'\ .format(self.v3.get_typevar().name) self.check_yo_check( x, sequence(typeset_check(self.v3, ts), equiv_check(tv2_exp, tv3_exp)))
def test_vselect_imm(self): # type: () -> None ts = TypeSet(lanes=(2, 256), ints=True, floats=True, bools=(8, 64)) r = Rtl( self.v0 << iconst(self.imm0), self.v1 << icmp(intcc.eq, self.v2, self.v0), self.v5 << vselect(self.v1, self.v3, self.v4), ) x = XForm(r, r) tv2_exp = 'Some({}).map(|t: crate::ir::Type| t.as_bool())'\ .format(self.v2.get_typevar().name) tv3_exp = 'Some({}).map(|t: crate::ir::Type| t.as_bool())'\ .format(self.v3.get_typevar().name) self.check_yo_check( x, sequence(typeset_check(self.v3, ts), equiv_check(tv2_exp, tv3_exp)))
def test_vselect_icmpimm(self): # type: () -> None r = Rtl( self.v0 << iconst(self.imm0), self.v1 << icmp(intcc.eq, self.v2, self.v0), self.v5 << vselect(self.v1, self.v3, self.v4), ) ti = TypeEnv() typing = ti_rtl(r, ti) ixn = self.IxN_nonscalar.get_fresh_copy("IxN1") txn = self.TxN.get_fresh_copy("TxN1") check_typing(typing, ({ self.v0: ixn, self.v1: ixn.as_bool(), self.v2: ixn, self.v3: txn, self.v4: txn, self.v5: txn, }, [TypesEqual(ixn.as_bool(), txn.as_bool())]))
def test_subst_enum_bad_var_const(self): a1 = Var('a1') x1 = Var('x1') y1 = Var('y1') b1 = Var('b1') z1 = Var('z1') u1 = Var('u1') # Var mapping to 2 different constants src = Rtl(a << icmp(CC1, x, y), a1 << icmp(CC1, x1, y1)) dst = Rtl(b << icmp(intcc.eq, z, u), b1 << icmp(intcc.sge, z1, u1)) assert src.substitution(dst, {}) is None # 2 different constants mapping to the same var src = Rtl(a << icmp(intcc.eq, x, y), a1 << icmp(intcc.sge, x1, y1)) dst = Rtl(b << icmp(CC1, z, u), b1 << icmp(CC1, z1, u1)) assert src.substitution(dst, {}) is None # Var mapping to var and constant - note that full unification would # have allowed this. src = Rtl(a << icmp(CC1, x, y), a1 << icmp(CC1, x1, y1)) dst = Rtl(b << icmp(CC2, z, u), b1 << icmp(intcc.sge, z1, u1)) assert src.substitution(dst, {}) is None
def test_subst_enum_bad(self): src = Rtl(a << icmp(intcc.eq, x, y)) dst = Rtl(b << icmp(intcc.sge, z, u)) assert src.substitution(dst, {}) is None
def test_subst_enum_const(self): src = Rtl(a << icmp(intcc.eq, x, y)) dst = Rtl(b << icmp(intcc.eq, z, u)) assert src.substitution(dst, {}) == {a: b, x: z, y: u}
def test_subst_enum_var(self): src = Rtl(a << icmp(CC1, x, y)) dst = Rtl(b << icmp(CC2, z, u)) assert src.substitution(dst, {}) == {a: b, CC1: CC2, x: z, y: u}