8
8
9
9
#include " float_bv.h"
10
10
11
- #include < cassert>
12
11
#include < algorithm>
13
12
14
13
#include < util/std_expr.h>
@@ -364,7 +363,9 @@ exprt float_bvt::conversion(
364
363
unsignedbv_typet (dest_spec.f +1 ));
365
364
366
365
// the exponent gets sign-extended
367
- assert (unpacked_src.exponent .type ().id ()==ID_signedbv);
366
+ INVARIANT (
367
+ unpacked_src.exponent .type ().id () == ID_signedbv,
368
+ " the exponent needs to have a signed type" );
368
369
result.exponent =
369
370
typecast_exprt (unpacked_src.exponent , signedbv_typet (dest_spec.e ));
370
371
@@ -406,15 +407,14 @@ exprt float_bvt::subtract_exponents(
406
407
// extend both by one bit
407
408
std::size_t old_width1=to_signedbv_type (src1.exponent .type ()).get_width ();
408
409
std::size_t old_width2=to_signedbv_type (src2.exponent .type ()).get_width ();
409
- assert (old_width1== old_width2);
410
+ PRECONDITION (old_width1 == old_width2);
410
411
411
412
const typecast_exprt extended_exponent1 (
412
413
src1.exponent , signedbv_typet (old_width1 + 1 ));
414
+
413
415
const typecast_exprt extended_exponent2 (
414
416
src2.exponent , signedbv_typet (old_width2 + 1 ));
415
417
416
- assert (extended_exponent1.type ()==extended_exponent2.type ());
417
-
418
418
// compute shift distance (here is the subtraction)
419
419
return minus_exprt (extended_exponent1, extended_exponent2);
420
420
}
@@ -738,7 +738,9 @@ exprt float_bvt::relation(
738
738
else if (rel==relt::GE)
739
739
return relation (src2, relt::LE, src1, spec); // swapped
740
740
741
- assert (rel==relt::EQ || rel==relt::LT || rel==relt::LE);
741
+ INVARIANT (
742
+ rel == relt::EQ || rel == relt::LT || rel == relt::LE,
743
+ " relation should be equality, less-than, or less-or-equal" );
742
744
743
745
// special cases: -0 and 0 are equal
744
746
const exprt is_zero1 = is_zero (src1);
@@ -799,7 +801,7 @@ exprt float_bvt::relation(
799
801
return and_exprt (or_bv, not_exprt (nan));
800
802
}
801
803
else
802
- assert ( false ) ;
804
+ UNREACHABLE ;
803
805
}
804
806
else if (rel==relt::EQ)
805
807
{
@@ -809,10 +811,8 @@ exprt float_bvt::relation(
809
811
or_exprt (bitwise_equal, both_zero),
810
812
not_exprt (nan));
811
813
}
812
- else
813
- assert (0 );
814
814
815
- // not reached
815
+ UNREACHABLE;
816
816
return false_exprt ();
817
817
}
818
818
@@ -870,7 +870,7 @@ void float_bvt::normalization_shift(
870
870
// bits minus one, in case the faction is one exactly.
871
871
std::size_t fraction_bits=to_unsignedbv_type (fraction.type ()).get_width ();
872
872
std::size_t exponent_bits=to_signedbv_type (exponent.type ()).get_width ();
873
- assert (fraction_bits!= 0 );
873
+ PRECONDITION (fraction_bits != 0 );
874
874
875
875
std::size_t depth = address_bits (fraction_bits - 1 );
876
876
@@ -882,7 +882,9 @@ void float_bvt::normalization_shift(
882
882
for (int d=depth-1 ; d>=0 ; d--)
883
883
{
884
884
unsigned distance=(1 <<d);
885
- assert (fraction_bits>distance);
885
+ INVARIANT (
886
+ fraction_bits > distance,
887
+ " distance must be within the range of fraction bits" );
886
888
887
889
// check if first 'distance'-many bits are zeros
888
890
const extractbits_exprt prefix (
@@ -900,7 +902,7 @@ void float_bvt::normalization_shift(
900
902
if_exprt (prefix_is_zero, shifted, fraction);
901
903
902
904
// add corresponding weight to exponent
903
- assert (d< (signed int )exponent_bits);
905
+ INVARIANT (d < (signed int )exponent_bits, " " );
904
906
905
907
exponent_delta=
906
908
bitor_exprt (exponent_delta,
@@ -926,7 +928,7 @@ void float_bvt::denormalization_shift(
926
928
// exponent for subnormal numbers.
927
929
928
930
std::size_t exponent_bits=to_signedbv_type (exponent.type ()).get_width ();
929
- assert (exponent_bits>= spec.e );
931
+ PRECONDITION (exponent_bits >= spec.e );
930
932
931
933
#if 1
932
934
// Need to sign extend to avoid overflow. Note that this is a
@@ -1041,7 +1043,7 @@ exprt float_bvt::fraction_rounding_decision(
1041
1043
std::size_t fraction_bits=
1042
1044
to_unsignedbv_type (fraction.type ()).get_width ();
1043
1045
1044
- assert (dest_bits< fraction_bits);
1046
+ PRECONDITION (dest_bits < fraction_bits);
1045
1047
1046
1048
// we have too many fraction bits
1047
1049
std::size_t extra_bits=fraction_bits-dest_bits;
@@ -1061,7 +1063,8 @@ exprt float_bvt::fraction_rounding_decision(
1061
1063
}
1062
1064
1063
1065
// the rounding bit is the last extra bit
1064
- assert (extra_bits>=1 );
1066
+ INVARIANT (
1067
+ extra_bits >= 1 , " the extra bits contain at least the rounding bit" );
1065
1068
const extractbit_exprt rounding_bit (fraction, extra_bits - 1 );
1066
1069
1067
1070
// we get one bit of the fraction for some rounding decisions
@@ -1116,7 +1119,8 @@ void float_bvt::round_fraction(
1116
1119
else // fraction gets smaller -- rounding
1117
1120
{
1118
1121
std::size_t extra_bits=result_fraction_size-fraction_size;
1119
- assert (extra_bits>=1 );
1122
+ INVARIANT (
1123
+ extra_bits >= 1 , " the extra bits include at least the rounding bit" );
1120
1124
1121
1125
// this computes the rounding decision
1122
1126
exprt increment=fraction_rounding_decision (
@@ -1203,13 +1207,10 @@ void float_bvt::round_exponent(
1203
1207
std::size_t result_exponent_size=
1204
1208
to_signedbv_type (result.exponent .type ()).get_width ();
1205
1209
1210
+ PRECONDITION (result_exponent_size >= spec.e );
1211
+
1206
1212
// do we need to enlarge the exponent?
1207
- if (result_exponent_size<spec.e )
1208
- {
1209
- // should have been done before
1210
- assert (false );
1211
- }
1212
- else if (result_exponent_size==spec.e ) // it stays
1213
+ if (result_exponent_size == spec.e ) // it stays
1213
1214
{
1214
1215
// do nothing
1215
1216
}
@@ -1278,7 +1279,8 @@ float_bvt::biased_floatt float_bvt::bias(
1278
1279
result.exponent =add_bias (src.exponent , spec);
1279
1280
1280
1281
// strip off the hidden bit
1281
- assert (to_unsignedbv_type (src.fraction .type ()).get_width ()==spec.f +1 );
1282
+ PRECONDITION (
1283
+ to_unsignedbv_type (src.fraction .type ()).get_width () == spec.f + 1 );
1282
1284
1283
1285
const extractbit_exprt hidden_bit (src.fraction , spec.f );
1284
1286
const not_exprt denormal (hidden_bit);
@@ -1354,8 +1356,8 @@ exprt float_bvt::pack(
1354
1356
const biased_floatt &src,
1355
1357
const ieee_float_spect &spec)
1356
1358
{
1357
- assert (to_unsignedbv_type (src.fraction .type ()).get_width ()== spec.f );
1358
- assert (to_unsignedbv_type (src.exponent .type ()).get_width ()== spec.e );
1359
+ PRECONDITION (to_unsignedbv_type (src.fraction .type ()).get_width () == spec.f );
1360
+ PRECONDITION (to_unsignedbv_type (src.exponent .type ()).get_width () == spec.e );
1359
1361
1360
1362
// do sign -- we make this 'false' for NaN
1361
1363
const if_exprt sign_bit (src.NaN , false_exprt (), src.sign );
0 commit comments