public void nestedBVEXTRACTVariableMiddle(int bitWidth) { Assert.IsTrue(bitWidth >= 3 && (bitWidth % 2 == 1)); var cfb = GetConstantFoldingBuilder(); var id = GetVarAndIdExpr("x", BasicType.GetBvType(bitWidth)).Item2; Expr result = id; // Keep peeling off the least significant bit and the most significant bit // until we're only left the middle bit in the original "id" for (int count = 0; count < bitWidth / 2; ++count) { int topBit = result.Type.BvBits - 1; result = cfb.BVEXTRACT(result, topBit, 1); CheckIsBvType(result, bitWidth - (2 * (count + 1))); } var asBvExtract = ExprUtil.AsBVEXTRACT(result); Assert.IsNotNull(asBvExtract); CheckIsBvType(asBvExtract, 1); // Check there is only a single BvExtractExpr Assert.AreSame(id, asBvExtract.Bitvector); var middleBitIndex = bitWidth / 2; Assert.AreEqual(middleBitIndex + 1, asBvExtract.End); Assert.AreEqual(middleBitIndex, asBvExtract.Start); }
public void nestedBVEXTRACTVariableEnd(int bitWidth) { var cfb = GetConstantFoldingBuilder(); var id = GetVarAndIdExpr("x", BasicType.GetBvType(bitWidth)).Item2; Expr result = id; // Keep peeling off the least significant bit until we're only left // with the most significant bit for (int count = 0; count < bitWidth - 1; ++count) { int topBitPlusOne = bitWidth - count; result = cfb.BVEXTRACT(result, topBitPlusOne, 1); CheckIsBvType(result, bitWidth - count - 1); } var asBvExtract = ExprUtil.AsBVEXTRACT(result); Assert.IsNotNull(asBvExtract); CheckIsBvType(asBvExtract, 1); // Check there is only a single BvExtractExpr Assert.AreSame(id, asBvExtract.Bitvector); Assert.AreEqual(bitWidth, asBvExtract.End); Assert.AreEqual(bitWidth - 1, asBvExtract.Start); }
public void ConcatExtractsToSingleExtract() { var cfb = GetConstantFoldingBuilder(); var id = GetVarAndIdExpr("x", BasicType.GetBvType(16)).Item2; var msb = cfb.BVEXTRACT(id, 16, 8); var lsb = cfb.BVEXTRACT(id, 8, 5); var result = cfb.BVCONCAT(msb, lsb); CheckIsBvType(result, 11); var asBvExtract = ExprUtil.AsBVEXTRACT(result); Assert.IsNotNull(asBvExtract); Assert.AreSame(id, asBvExtract.Bitvector); Assert.AreEqual(16, asBvExtract.End); Assert.AreEqual(5, asBvExtract.Start); }
public void noFold() { var pair = GetSimpleAndConstantFoldingBuilder(); var sb = pair.Item1; var cfb = pair.Item2; var id = GetVarAndIdExpr("foo", BasicType.GetBvType(8)).Item2; var foldedResult = cfb.BVEXTRACT(id, 7, 0); var simpleResult = sb.BVEXTRACT(id, 7, 0); CheckIsBvType(foldedResult, 7); CheckIsBvType(simpleResult, 7); Assert.AreEqual(simpleResult, foldedResult); var asBvExtract = ExprUtil.AsBVEXTRACT(foldedResult); Assert.IsNotNull(asBvExtract); Assert.AreSame(id, asBvExtract.Bitvector); Assert.AreEqual(0, asBvExtract.Start); Assert.AreEqual(7, asBvExtract.End); }