Skip to content

Commit

Permalink
Add FloatType::toInt
Browse files Browse the repository at this point in the history
  • Loading branch information
dtcxzyw committed Jan 5, 2025
1 parent b7cf1ae commit be245a9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
16 changes: 16 additions & 0 deletions ir/type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,22 @@ expr FloatType::isNaN(const expr &v, bool signalling) const {
}
}

smt::expr FloatType::toInt(State &s, smt::expr v) const {
expr isnan = v.BV2float(getDummyFloat()).isNaN();

if (isnan.isFalse())
return v;

expr sign = s.getFreshNondetVar("#sign", expr::mkUInt(0, 1));
expr nan = sign.concat(v.trunc(bits() - 1));

return expr::mkIf(isnan, nan, v);
}

IR::StateValue FloatType::toInt(State &s, IR::StateValue v) const {
return Type::toInt(s, std::move(v));
}

unsigned FloatType::bits() const {
assert(fpType != Unknown);
return float_sizes[fpType].first;
Expand Down
2 changes: 2 additions & 0 deletions ir/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ class FloatType final : public Type {
unsigned nary, const smt::expr &a,
const smt::expr &b = {}, const smt::expr &c = {}) const;
smt::expr isNaN(const smt::expr &v, bool signalling) const;
smt::expr toInt(State &s, smt::expr v) const override;
IR::StateValue toInt(State &s, IR::StateValue v) const override;

IR::StateValue getDummyValue(bool non_poison) const override;
smt::expr getTypeConstraints() const override;
Expand Down

0 comments on commit be245a9

Please sign in to comment.