Skip to content

Commit

Permalink
docs: render the fcmp tables as code (#3735)
Browse files Browse the repository at this point in the history
Looking at [the `fcmp`
documentation](https://docs.rs/cranelift-codegen/0.80.0/cranelift_codegen/ir/trait.InstBuilder.html#method.fcmp)--generated
from Cranelift's instruction definitions, the charts explaining the
logic for the various conditions is unreadable. Since rendering those charts
as plain text is problematic, this change wraps them as code sections
for a consistent layout.
  • Loading branch information
abrown authored Jan 28, 2022
1 parent 7928a3f commit 90bfa12
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cranelift/codegen/meta/src/shared/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3035,12 +3035,14 @@ pub(crate) fn define(
Two IEEE 754-2008 floating point numbers, `x` and `y`, relate to each
other in exactly one of four ways:
```text
== ==========================================
UN Unordered when one or both numbers is NaN.
EQ When `x = y`. (And `0.0 = -0.0`).
LT When `x < y`.
GT When `x > y`.
== ==========================================
```
The 14 `floatcc` condition codes each correspond to a subset of
the four relations, except for the empty set which would always be
Expand All @@ -3049,6 +3051,7 @@ pub(crate) fn define(
The condition codes are divided into 7 'ordered' conditions which don't
include UN, and 7 unordered conditions which all include UN.
```text
+-------+------------+---------+------------+-------------------------+
|Ordered |Unordered |Condition |
+=======+============+=========+============+=========================+
Expand All @@ -3066,13 +3069,15 @@ pub(crate) fn define(
+-------+------------+---------+------------+-------------------------+
|ge |GT | EQ |uge |UN | GT | EQ|Greater than or equal |
+-------+------------+---------+------------+-------------------------+
```
The standard C comparison operators, `<, <=, >, >=`, are all ordered,
so they are false if either operand is NaN. The C equality operator,
`==`, is ordered, and since inequality is defined as the logical
inverse it is *unordered*. They map to the `floatcc` condition
codes as follows:
```text
==== ====== ============
C `Cond` Subset
==== ====== ============
Expand All @@ -3083,6 +3088,7 @@ pub(crate) fn define(
`>` gt GT
`>=` ge GT | EQ
==== ====== ============
```
This subset of condition codes also corresponds to the WebAssembly
floating point comparisons of the same name.
Expand Down

0 comments on commit 90bfa12

Please sign in to comment.