Skip to content

Commit

Permalink
Add missing comments
Browse files Browse the repository at this point in the history
  • Loading branch information
abadams committed Apr 18, 2024
1 parent d3efa14 commit 22a04bd
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/IREquality.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ struct Comparer {
}

size_t hash(const IRNode *a, const IRNode *b) {
// A simple hash designed to get enough information into the low bits to
// avoid too many collisions, while being robust to weird things like
// having strided set of Exprs.
uintptr_t pa = (uintptr_t)a;
uintptr_t pb = (uintptr_t)b;
uintptr_t h = (((pa * 17) ^ (pb * 13)) >> 4);
Expand Down Expand Up @@ -191,6 +194,8 @@ struct Comparer {
void cmp(double a, double b) {
// Floating point scalars need special handling, due to NaNs.
if (std::isnan(a) && std::isnan(b)) {
// Two nans should be considered equal, so leave comparison state

This comment has been minimized.

Copy link
@steven-johnson

steven-johnson Apr 18, 2024

Contributor

Maybe it doesn't matter here, but IIRC IEEE754 says that nans aren't equal to anything, including other nans

This comment has been minimized.

Copy link
@abadams

abadams Apr 18, 2024

Author Member

This is comparing pieces of syntax in a syntax tree for equivalence (i.e. they'll compile to the same thing), not comparing real numbers represented as floats for their value. I'll update the comment to clarify.

This comment has been minimized.

Copy link
@abadams

abadams Apr 18, 2024

Author Member

Also here I'm just preserving existing behavior. I tried changing it to just compare the bits, but I ended up in a platform-dependent nightmare with the behavior of std::nearbyint. Will elaborate in a revised comment.

// unchanged.
} else if (std::isnan(a)) {
result = Order::LessThan;
} else if (std::isnan(b)) {
Expand Down

0 comments on commit 22a04bd

Please sign in to comment.