@@ -583,7 +583,7 @@ bool Literal::operator<(const Literal& other) const {
583583 return externalize () < other.externalize ();
584584}
585585
586- bool Literal::isNaN () {
586+ bool Literal::isNaN () const {
587587 if (type == Type::f32 && std::isnan (getf32 ())) {
588588 return true ;
589589 }
@@ -594,15 +594,15 @@ bool Literal::isNaN() {
594594 return false ;
595595}
596596
597- bool Literal::isCanonicalNaN () {
597+ bool Literal::isCanonicalNaN () const {
598598 if (!isNaN ()) {
599599 return false ;
600600 }
601601 return (type == Type::f32 && NaNPayload (getf32 ()) == (1u << 22 )) ||
602602 (type == Type::f64 && NaNPayload (getf64 ()) == (1ull << 51 ));
603603}
604604
605- bool Literal::isArithmeticNaN () {
605+ bool Literal::isArithmeticNaN () const {
606606 if (!isNaN ()) {
607607 return false ;
608608 }
@@ -1602,37 +1602,53 @@ Literal Literal::rotR(const Literal& other) const {
16021602}
16031603
16041604Literal Literal::eq (const Literal& other) const {
1605- switch (type.getBasic ()) {
1606- case Type::i32 :
1607- return Literal (i32 == other.i32 );
1608- case Type::i64 :
1609- return Literal (i64 == other.i64 );
1610- case Type::f32 :
1611- return Literal (getf32 () == other.getf32 ());
1612- case Type::f64 :
1613- return Literal (getf64 () == other.getf64 ());
1614- case Type::v128:
1615- case Type::none:
1616- case Type::unreachable:
1617- WASM_UNREACHABLE (" unexpected type" );
1605+ if (type != other.type ) {
1606+ return Literal (int32_t (0 ));
1607+ }
1608+ if (type.isBasic ()) {
1609+ switch (type.getBasic ()) {
1610+ case Type::i32 :
1611+ return Literal (i32 == other.i32 );
1612+ case Type::i64 :
1613+ return Literal (i64 == other.i64 );
1614+ case Type::f32 :
1615+ return Literal (getf32 () == other.getf32 ());
1616+ case Type::f64 :
1617+ return Literal (getf64 () == other.getf64 ());
1618+ case Type::v128:
1619+ case Type::none:
1620+ case Type::unreachable:
1621+ WASM_UNREACHABLE (" unexpected type" );
1622+ }
1623+ }
1624+ if (type.isRef ()) {
1625+ return Literal (int32_t (*this == other));
16181626 }
16191627 WASM_UNREACHABLE (" unexpected type" );
16201628}
16211629
16221630Literal Literal::ne (const Literal& other) const {
1623- switch (type.getBasic ()) {
1624- case Type::i32 :
1625- return Literal (i32 != other.i32 );
1626- case Type::i64 :
1627- return Literal (i64 != other.i64 );
1628- case Type::f32 :
1629- return Literal (getf32 () != other.getf32 ());
1630- case Type::f64 :
1631- return Literal (getf64 () != other.getf64 ());
1632- case Type::v128:
1633- case Type::none:
1634- case Type::unreachable:
1635- WASM_UNREACHABLE (" unexpected type" );
1631+ if (type != other.type ) {
1632+ return Literal (int32_t (1 ));
1633+ }
1634+ if (type.isBasic ()) {
1635+ switch (type.getBasic ()) {
1636+ case Type::i32 :
1637+ return Literal (i32 != other.i32 );
1638+ case Type::i64 :
1639+ return Literal (i64 != other.i64 );
1640+ case Type::f32 :
1641+ return Literal (getf32 () != other.getf32 ());
1642+ case Type::f64 :
1643+ return Literal (getf64 () != other.getf64 ());
1644+ case Type::v128:
1645+ case Type::none:
1646+ case Type::unreachable:
1647+ WASM_UNREACHABLE (" unexpected type" );
1648+ }
1649+ }
1650+ if (type.isRef ()) {
1651+ return Literal (int32_t (*this != other));
16361652 }
16371653 WASM_UNREACHABLE (" unexpected type" );
16381654}
0 commit comments