本文整理汇总了C++中bvt::back方法的典型用法代码示例。如果您正苦于以下问题:C++ bvt::back方法的具体用法?C++ bvt::back怎么用?C++ bvt::back使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bvt
的用法示例。
在下文中一共展示了bvt::back方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: type_conversion
bool boolbvt::type_conversion(
const typet &src_type, const bvt &src,
const typet &dest_type, bvt &dest)
{
bvtypet dest_bvtype=get_bvtype(dest_type);
bvtypet src_bvtype=get_bvtype(src_type);
if(src_bvtype==IS_C_BIT_FIELD)
return type_conversion(
c_bit_field_replacement_type(to_c_bit_field_type(src_type), ns), src, dest_type, dest);
if(dest_bvtype==IS_C_BIT_FIELD)
return type_conversion(
src_type, src, c_bit_field_replacement_type(to_c_bit_field_type(dest_type), ns), dest);
std::size_t src_width=src.size();
std::size_t dest_width=boolbv_width(dest_type);
if(dest_width==0 || src_width==0)
return true;
dest.clear();
dest.reserve(dest_width);
if(dest_type.id()==ID_complex)
{
if(src_type==dest_type.subtype())
{
forall_literals(it, src)
dest.push_back(*it);
// pad with zeros
for(std::size_t i=src.size(); i<dest_width; i++)
dest.push_back(const_literal(false));
return false;
}
else if(src_type.id()==ID_complex)
{
// recursively do both halfs
bvt lower, upper, lower_res, upper_res;
lower.assign(src.begin(), src.begin()+src.size()/2);
upper.assign(src.begin()+src.size()/2, src.end());
type_conversion(ns.follow(src_type.subtype()), lower, ns.follow(dest_type.subtype()), lower_res);
type_conversion(ns.follow(src_type.subtype()), upper, ns.follow(dest_type.subtype()), upper_res);
assert(lower_res.size()+upper_res.size()==dest_width);
dest=lower_res;
dest.insert(dest.end(), upper_res.begin(), upper_res.end());
return false;
}
}
if(src_type.id()==ID_complex)
{
assert(dest_type.id()!=ID_complex);
if(dest_type.id()==ID_signedbv ||
dest_type.id()==ID_unsignedbv ||
dest_type.id()==ID_floatbv ||
dest_type.id()==ID_fixedbv ||
dest_type.id()==ID_c_enum ||
dest_type.id()==ID_c_enum_tag ||
dest_type.id()==ID_bool)
{
// A cast from complex x to real T
// is (T) __real__ x.
bvt tmp_src(src);
tmp_src.resize(src.size()/2); // cut off imag part
return type_conversion(src_type.subtype(), tmp_src, dest_type, dest);
}
}
switch(dest_bvtype)
{
case IS_RANGE:
if(src_bvtype==IS_UNSIGNED ||
src_bvtype==IS_SIGNED ||
src_bvtype==IS_C_BOOL)
{
mp_integer dest_from=to_range_type(dest_type).get_from();
if(dest_from==0)
{
// do zero extension
dest.resize(dest_width);
for(std::size_t i=0; i<dest.size(); i++)
dest[i]=(i<src.size()?src[i]:const_literal(false));
return false;
}
}
else if(src_bvtype==IS_RANGE) // range to range
{
mp_integer src_from=to_range_type(src_type).get_from();
mp_integer dest_from=to_range_type(dest_type).get_from();
if(dest_from==src_from)
{
// do zero extension, if needed
dest=bv_utils.zero_extension(src, dest_width);
return false;
//.........这里部分代码省略.........
示例2: add_sub
bvt float_utilst::add_sub(
const bvt &src1,
const bvt &src2,
bool subtract)
{
unbiased_floatt unpacked1=unpack(src1);
unbiased_floatt unpacked2=unpack(src2);
// subtract?
if(subtract)
unpacked2.sign=!unpacked2.sign;
// figure out which operand has the bigger exponent
const bvt exponent_difference=subtract_exponents(unpacked1, unpacked2);
literalt src2_bigger=exponent_difference.back();
const bvt bigger_exponent=
bv_utils.select(src2_bigger, unpacked2.exponent, unpacked1.exponent);
// swap fractions as needed
const bvt new_fraction1=
bv_utils.select(src2_bigger, unpacked2.fraction, unpacked1.fraction);
const bvt new_fraction2=
bv_utils.select(src2_bigger, unpacked1.fraction, unpacked2.fraction);
// compute distance
const bvt distance=bv_utils.absolute_value(exponent_difference);
// limit the distance: shifting more than f+3 bits is unnecessary
const bvt limited_dist=limit_distance(distance, spec.f+3);
// pad fractions with 2 zeros from below
const bvt fraction1_padded=bv_utils.concatenate(bv_utils.zeros(3), new_fraction1);
const bvt fraction2_padded=bv_utils.concatenate(bv_utils.zeros(3), new_fraction2);
// shift new_fraction2
literalt sticky_bit;
const bvt fraction1_shifted=fraction1_padded;
const bvt fraction2_shifted=sticky_right_shift(
fraction2_padded, limited_dist, sticky_bit);
// sticky bit: or of the bits lost by the right-shift
bvt fraction2_stickied=fraction2_shifted;
fraction2_stickied[0]=prop.lor(fraction2_shifted[0], sticky_bit);
// need to have two extra fraction bits for addition and rounding
const bvt fraction1_ext=bv_utils.zero_extension(fraction1_shifted, fraction1_shifted.size()+2);
const bvt fraction2_ext=bv_utils.zero_extension(fraction2_stickied, fraction2_stickied.size()+2);
unbiased_floatt result;
// now add/sub them
literalt subtract_lit=prop.lxor(unpacked1.sign, unpacked2.sign);
result.fraction=
bv_utils.add_sub(fraction1_ext, fraction2_ext, subtract_lit);
// sign of result
literalt fraction_sign=result.fraction.back();
result.fraction=bv_utils.absolute_value(result.fraction);
result.exponent=bigger_exponent;
// adjust the exponent for the fact that we added two bits to the fraction
result.exponent=
bv_utils.add(bv_utils.sign_extension(result.exponent, result.exponent.size()+1),
bv_utils.build_constant(2, result.exponent.size()+1));
// NaN?
result.NaN=prop.lor(
prop.land(prop.land(unpacked1.infinity, unpacked2.infinity),
prop.lxor(unpacked1.sign, unpacked2.sign)),
prop.lor(unpacked1.NaN, unpacked2.NaN));
// infinity?
result.infinity=prop.land(
!result.NaN,
prop.lor(unpacked1.infinity, unpacked2.infinity));
// zero?
// Note that:
// 1. The zero flag isn't used apart from in divide and
// is only set on unpack
// 2. Subnormals mean that addition or subtraction can't round to 0,
// thus we can perform this test now
// 3. The rules for sign are different for zero
result.zero = prop.land(
!prop.lor(result.infinity, result.NaN),
!prop.lor(result.fraction));
// sign
literalt add_sub_sign=
prop.lxor(prop.lselect(src2_bigger, unpacked2.sign, unpacked1.sign),
fraction_sign);
literalt infinity_sign=
prop.lselect(unpacked1.infinity, unpacked1.sign, unpacked2.sign);
#if 1
//.........这里部分代码省略.........