DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

(gcc.info) Comparisons

Info Catalog (gcc.info) Arithmetic (gcc.info) RTL (gcc.info) Bit Fields
 
 Comparison Operations
 =====================
 
    Comparison operators test a relation on two operands and are
 considered to represent a machine-dependent nonzero value described by,
 but not necessarily equal to, `STORE_FLAG_VALUE' ( Misc.)  if
 the relation holds, or zero if it does not.  The mode of the comparison
 operation is independent of the mode of the data being compared.  If
 the comparison operation is being tested (e.g., the first operand of an
 `if_then_else'), the mode must be `VOIDmode'.  If the comparison
 operation is producing data to be stored in some variable, the mode
 must be in class `MODE_INT'.  All comparison operations producing data
 must use the same mode, which is machine-specific.
 
    There are two ways that comparison operations may be used.  The
 comparison operators may be used to compare the condition codes `(cc0)'
 against zero, as in `(eq (cc0) (const_int 0))'.  Such a construct
 actually refers to the result of the preceding instruction in which the
 condition codes were set.  The instructing setting the condition code
 must be adjacent to the instruction using the condition code; only
 `note' insns may separate them.
 
    Alternatively, a comparison operation may directly compare two data
 objects.  The mode of the comparison is determined by the operands; they
 must both be valid for a common machine mode.  A comparison with both
 operands constant would be invalid as the machine mode could not be
 deduced from it, but such a comparison should never exist in RTL due to
 constant folding.
 
    In the example above, if `(cc0)' were last set to `(compare X Y)',
 the comparison operation is identical to `(eq X Y)'.  Usually only one
 style of comparisons is supported on a particular machine, but the
 combine pass will try to merge the operations to produce the `eq' shown
 in case it exists in the context of the particular insn involved.
 
    Inequality comparisons come in two flavors, signed and unsigned.
 Thus, there are distinct expression codes `gt' and `gtu' for signed and
 unsigned greater-than.  These can produce different results for the same
 pair of integer values: for example, 1 is signed greater-than -1 but not
 unsigned greater-than, because -1 when regarded as unsigned is actually
 `0xffffffff' which is greater than 1.
 
    The signed comparisons are also used for floating point values.
 Floating point comparisons are distinguished by the machine modes of
 the operands.
 
 `(eq:M X Y)'
      1 if the values represented by X and Y are equal, otherwise 0.
 
 `(ne:M X Y)'
      1 if the values represented by X and Y are not equal, otherwise 0.
 
 `(gt:M X Y)'
      1 if the X is greater than Y.  If they are fixed-point, the
      comparison is done in a signed sense.
 
 `(gtu:M X Y)'
      Like `gt' but does unsigned comparison, on fixed-point numbers
      only.
 
 `(lt:M X Y)'
 `(ltu:M X Y)'
      Like `gt' and `gtu' but test for "less than".
 
 `(ge:M X Y)'
 `(geu:M X Y)'
      Like `gt' and `gtu' but test for "greater than or equal".
 
 `(le:M X Y)'
 `(leu:M X Y)'
      Like `gt' and `gtu' but test for "less than or equal".
 
 `(if_then_else COND THEN ELSE)'
      This is not a comparison operation but is listed here because it is
      always used in conjunction with a comparison operation.  To be
      precise, COND is a comparison expression.  This expression
      represents a choice, according to COND, between the value
      represented by THEN and the one represented by ELSE.
 
      On most machines, `if_then_else' expressions are valid only to
      express conditional jumps.
 
 `(cond [TEST1 VALUE1 TEST2 VALUE2 ...] DEFAULT)'
      Similar to `if_then_else', but more general.  Each of TEST1,
      TEST2, ... is performed in turn.  The result of this expression is
      the VALUE corresponding to the first non-zero test, or DEFAULT if
      none of the tests are non-zero expressions.
 
      This is currently not valid for instruction patterns and is
      supported only for insn attributes.   Insn Attributes.
 
Info Catalog (gcc.info) Arithmetic (gcc.info) RTL (gcc.info) Bit Fields
automatically generated byinfo2html