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
{
@@ -810,9 +812,9 @@ exprt float_bvt::relation(
810
812
not_exprt (nan));
811
813
}
812
814
else
813
- assert ( 0 ) ;
815
+ UNREACHABLE ;
814
816
815
- // not reached
817
+ UNREACHABLE;
816
818
return false_exprt ();
817
819
}
818
820
@@ -870,7 +872,7 @@ void float_bvt::normalization_shift(
870
872
// bits minus one, in case the faction is one exactly.
871
873
std::size_t fraction_bits=to_unsignedbv_type (fraction.type ()).get_width ();
872
874
std::size_t exponent_bits=to_signedbv_type (exponent.type ()).get_width ();
873
- assert (fraction_bits!= 0 );
875
+ PRECONDITION (fraction_bits != 0 );
874
876
875
877
std::size_t depth = address_bits (fraction_bits - 1 );
876
878
@@ -882,7 +884,9 @@ void float_bvt::normalization_shift(
882
884
for (int d=depth-1 ; d>=0 ; d--)
883
885
{
884
886
unsigned distance=(1 <<d);
885
- assert (fraction_bits>distance);
887
+ INVARIANT (
888
+ fraction_bits > distance,
889
+ " distance must be within the range of fraction bits" );
886
890
887
891
// check if first 'distance'-many bits are zeros
888
892
const extractbits_exprt prefix (
@@ -900,7 +904,7 @@ void float_bvt::normalization_shift(
900
904
if_exprt (prefix_is_zero, shifted, fraction);
901
905
902
906
// add corresponding weight to exponent
903
- assert (d< (signed int )exponent_bits);
907
+ INVARIANT (d < (signed int )exponent_bits, " " );
904
908
905
909
exponent_delta=
906
910
bitor_exprt (exponent_delta,
@@ -926,7 +930,7 @@ void float_bvt::denormalization_shift(
926
930
// exponent for subnormal numbers.
927
931
928
932
std::size_t exponent_bits=to_signedbv_type (exponent.type ()).get_width ();
929
- assert (exponent_bits>= spec.e );
933
+ PRECONDITION (exponent_bits >= spec.e );
930
934
931
935
#if 1
932
936
// Need to sign extend to avoid overflow. Note that this is a
@@ -1041,7 +1045,7 @@ exprt float_bvt::fraction_rounding_decision(
1041
1045
std::size_t fraction_bits=
1042
1046
to_unsignedbv_type (fraction.type ()).get_width ();
1043
1047
1044
- assert (dest_bits< fraction_bits);
1048
+ PRECONDITION (dest_bits < fraction_bits);
1045
1049
1046
1050
// we have too many fraction bits
1047
1051
std::size_t extra_bits=fraction_bits-dest_bits;
@@ -1061,7 +1065,8 @@ exprt float_bvt::fraction_rounding_decision(
1061
1065
}
1062
1066
1063
1067
// the rounding bit is the last extra bit
1064
- assert (extra_bits>=1 );
1068
+ INVARIANT (
1069
+ extra_bits >= 1 , " the extra bits contain at least the rounding bit" );
1065
1070
const extractbit_exprt rounding_bit (fraction, extra_bits - 1 );
1066
1071
1067
1072
// we get one bit of the fraction for some rounding decisions
@@ -1116,7 +1121,8 @@ void float_bvt::round_fraction(
1116
1121
else // fraction gets smaller -- rounding
1117
1122
{
1118
1123
std::size_t extra_bits=result_fraction_size-fraction_size;
1119
- assert (extra_bits>=1 );
1124
+ INVARIANT (
1125
+ extra_bits >= 1 , " the extra bits include at least the rounding bit" );
1120
1126
1121
1127
// this computes the rounding decision
1122
1128
exprt increment=fraction_rounding_decision (
@@ -1203,13 +1209,10 @@ void float_bvt::round_exponent(
1203
1209
std::size_t result_exponent_size=
1204
1210
to_signedbv_type (result.exponent .type ()).get_width ();
1205
1211
1212
+ PRECONDITION (result_exponent_size >= spec.e );
1213
+
1206
1214
// 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
1215
+ if (result_exponent_size == spec.e ) // it stays
1213
1216
{
1214
1217
// do nothing
1215
1218
}
@@ -1278,7 +1281,8 @@ float_bvt::biased_floatt float_bvt::bias(
1278
1281
result.exponent =add_bias (src.exponent , spec);
1279
1282
1280
1283
// strip off the hidden bit
1281
- assert (to_unsignedbv_type (src.fraction .type ()).get_width ()==spec.f +1 );
1284
+ PRECONDITION (
1285
+ to_unsignedbv_type (src.fraction .type ()).get_width () == spec.f + 1 );
1282
1286
1283
1287
const extractbit_exprt hidden_bit (src.fraction , spec.f );
1284
1288
const not_exprt denormal (hidden_bit);
@@ -1354,8 +1358,8 @@ exprt float_bvt::pack(
1354
1358
const biased_floatt &src,
1355
1359
const ieee_float_spect &spec)
1356
1360
{
1357
- assert (to_unsignedbv_type (src.fraction .type ()).get_width ()== spec.f );
1358
- assert (to_unsignedbv_type (src.exponent .type ()).get_width ()== spec.e );
1361
+ PRECONDITION (to_unsignedbv_type (src.fraction .type ()).get_width () == spec.f );
1362
+ PRECONDITION (to_unsignedbv_type (src.exponent .type ()).get_width () == spec.e );
1359
1363
1360
1364
// do sign -- we make this 'false' for NaN
1361
1365
const if_exprt sign_bit (src.NaN , false_exprt (), src.sign );
0 commit comments