From 9f3c5b967e77156ed2acd4848b893050790b3bea Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Thu, 26 Sep 2019 03:38:38 +0530 Subject: [PATCH] [codegen] add documentation for overflow Add documentation to the icmp instruction text for both signed and unsigned overflow, making it very clear why unsigned overflow is complicated and where to find it. --- .../codegen/meta/src/shared/instructions.rs | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/cranelift/codegen/meta/src/shared/instructions.rs b/cranelift/codegen/meta/src/shared/instructions.rs index 679ee1a2c1..1f0e629a2e 100644 --- a/cranelift/codegen/meta/src/shared/instructions.rs +++ b/cranelift/codegen/meta/src/shared/instructions.rs @@ -1586,8 +1586,6 @@ pub(crate) fn define( let x = &operand("x", Int); let y = &operand("y", Int); - // TODO(ryzokuken): Add documentation for unsigned overflow. - // TODO(ryzokuken): Add documentation for signed overflow. ig.push( Inst::new( "icmp", @@ -1597,16 +1595,21 @@ pub(crate) fn define( The condition code determines if the operands are interpreted as signed or unsigned integers. - ====== ======== ========= - Signed Unsigned Condition - ====== ======== ========= - eq eq Equal - ne ne Not equal - slt ult Less than - sge uge Greater than or equal - sgt ugt Greater than - sle ule Less than or equal - ====== ======== ========= + | Signed | Unsigned | Condition | + |--------|----------|-----------------------| + | eq | eq | Equal | + | ne | ne | Not equal | + | slt | ult | Less than | + | sge | uge | Greater than or equal | + | sgt | ugt | Greater than | + | sle | ule | Less than or equal | + | of | * | Overflow | + | nof | * | No Overflow | + + \* The unsigned version of overflow conditions have ISA-specific + semantics and thus have been kept as methods on the TargetIsa trait as + [unsigned_add_overflow_condition][isa::TargetIsa::unsigned_add_overflow_condition] and + [unsigned_sub_overflow_condition][isa::TargetIsa::unsigned_sub_overflow_condition]. When this instruction compares integer vectors, it returns a boolean vector of lane-wise comparisons.