def test_elaborate_iadd_elaborate_1(self): # type: () -> None i32.by(2) # Make sure i32x2 exists. r = Rtl( self.v0 << iadd.i32x2(self.v1, self.v2), ) r.cleanup_concrete_rtl() sem = elaborate(r) x = Var('x') y = Var('y') a = Var('a') bvx_1 = Var('bvx_1') bvx_2 = Var('bvx_2') bvx_5 = Var('bvx_5') bvlo_1 = Var('bvlo_1') bvlo_2 = Var('bvlo_2') bvhi_1 = Var('bvhi_1') bvhi_2 = Var('bvhi_2') bva_3 = Var('bva_3') bva_4 = Var('bva_4') exp = Rtl( bvx_1 << prim_to_bv.i32x2(x), (bvlo_1, bvhi_1) << bvsplit.bv64(bvx_1), bvx_2 << prim_to_bv.i32x2(y), (bvlo_2, bvhi_2) << bvsplit.bv64(bvx_2), bva_3 << bvadd.bv32(bvlo_1, bvlo_2), bva_4 << bvadd.bv32(bvhi_1, bvhi_2), bvx_5 << bvconcat.bv32(bva_3, bva_4), a << prim_from_bv.i32x2(bvx_5) ) exp.cleanup_concrete_rtl() assert concrete_rtls_eq(sem, exp)
def test_elaborate_vconcat(self): # type: () -> None i32.by(4) # Make sure i32x4 exists. i32.by(2) # Make sure i32x2 exists. r = Rtl( self.v0 << vconcat.i32x2(self.v1, self.v2), ) r.cleanup_concrete_rtl() sem = elaborate(r) bvx = Var('bvx') bvlo = Var('bvlo') bvhi = Var('bvhi') x = Var('x') lo = Var('lo') hi = Var('hi') exp = Rtl( bvlo << prim_to_bv.i32x2(lo), bvhi << prim_to_bv.i32x2(hi), bvx << bvconcat.bv64(bvlo, bvhi), x << prim_from_bv.i32x4(bvx) ) exp.cleanup_concrete_rtl() assert concrete_rtls_eq(sem, exp)
def test_elaborate_vsplit(self): # type: () -> None i32.by(4) # Make sure i32x4 exists. i32.by(2) # Make sure i32x2 exists. r = Rtl( (self.v0, self.v1) << vsplit.i32x4(self.v2), ) r.cleanup_concrete_rtl() sem = elaborate(r) bvx = Var('bvx') bvlo = Var('bvlo') bvhi = Var('bvhi') x = Var('x') lo = Var('lo') hi = Var('hi') exp = Rtl( bvx << prim_to_bv.i32x4(x), (bvlo, bvhi) << bvsplit.bv128(bvx), lo << prim_from_bv.i32x2(bvlo), hi << prim_from_bv.i32x2(bvhi) ) exp.cleanup_concrete_rtl() assert concrete_rtls_eq(sem, exp)
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_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_singleton(self): x = TypeVar.singleton(i32) self.assertEqual(str(x), '`i32`') self.assertEqual(x.type_set.min_int, 32) self.assertEqual(x.type_set.max_int, 32) self.assertEqual(x.type_set.min_lanes, 1) self.assertEqual(x.type_set.max_lanes, 1) x = TypeVar.singleton(i32.by(4)) self.assertEqual(str(x), '`i32x4`') self.assertEqual(x.type_set.min_int, 32) self.assertEqual(x.type_set.max_int, 32) self.assertEqual(x.type_set.min_lanes, 4) self.assertEqual(x.type_set.max_lanes, 4)
def test_elaborate_iadd_simple(self): # type: () -> None i32.by(2) # Make sure i32x2 exists. x = Var('x') y = Var('y') a = Var('a') bvx = Var('bvx') bvy = Var('bvy') bva = Var('bva') r = Rtl( a << iadd.i32(x, y), ) r.cleanup_concrete_rtl() sem = elaborate(r) exp = Rtl( bvx << prim_to_bv.i32(x), bvy << prim_to_bv.i32(y), bva << bvadd.bv32(bvx, bvy), a << prim_from_bv.i32(bva) ) exp.cleanup_concrete_rtl() assert concrete_rtls_eq(sem, exp)
def test_get_singleton(self): # Raise error when calling get_singleton() on non-singleton TS t = TypeSet(lanes=(1, 1), ints=(8, 8), floats=(32, 32)) with self.assertRaises(AssertionError): t.get_singleton() t = TypeSet(lanes=(1, 2), floats=(32, 32)) with self.assertRaises(AssertionError): t.get_singleton() self.assertEqual(TypeSet(ints=(16, 16)).get_singleton(), i16) self.assertEqual(TypeSet(floats=(64, 64)).get_singleton(), f64) self.assertEqual(TypeSet(bools=(1, 1)).get_singleton(), b1) self.assertEqual( TypeSet(lanes=(4, 4), ints=(32, 32)).get_singleton(), i32.by(4))
def test_get_singleton(self): # Raise error when calling get_singleton() on non-singleton TS t = TypeSet(lanes=(1, 1), ints=(8, 8), floats=(32, 32)) with self.assertRaises(AssertionError): t.get_singleton() t = TypeSet(lanes=(1, 2), floats=(32, 32)) with self.assertRaises(AssertionError): t.get_singleton() self.assertEqual(TypeSet(ints=(16, 16)).get_singleton(), i16) self.assertEqual(TypeSet(floats=(64, 64)).get_singleton(), f64) self.assertEqual(TypeSet(bools=(1, 1)).get_singleton(), b1) self.assertEqual(TypeSet(lanes=(4, 4), ints=(32, 32)).get_singleton(), i32.by(4))
def test_singleton(self): x = TypeVar.singleton(i32) self.assertEqual(str(x), '`i32`') self.assertEqual(min(x.type_set.ints), 32) self.assertEqual(max(x.type_set.ints), 32) self.assertEqual(min(x.type_set.lanes), 1) self.assertEqual(max(x.type_set.lanes), 1) self.assertEqual(len(x.type_set.floats), 0) self.assertEqual(len(x.type_set.bools), 0) x = TypeVar.singleton(i32.by(4)) self.assertEqual(str(x), '`i32x4`') self.assertEqual(min(x.type_set.ints), 32) self.assertEqual(max(x.type_set.ints), 32) self.assertEqual(min(x.type_set.lanes), 4) self.assertEqual(max(x.type_set.lanes), 4) self.assertEqual(len(x.type_set.floats), 0) self.assertEqual(len(x.type_set.bools), 0)