cmp - Compare

cmp - Compare

Calling Format

cmp     mode0, mode1, src0, src1

Operands

Name Description
mode0 Comparison mode 0 (0: ==, 1: !=, 2: <, 3: <=, 4: >, 5: >=)
mode1 Comparison mode 1 (0: ==, 1: !=, 2: <, 3: <=, 4: >, 5: >=)
src0 A temporary register, an input register, or a floating-point constant register.
src1 A temporary register, an input register, or a floating-point constant register.

You cannot specify a floating-point constant register for both src0 and src1.
You cannot specify input registers using different indices for src0 and src1 at the same time.

Overview

Compares the contents of registers src0 and src1 and stores the result in the status registers.
It only compares the x and y components of src0 and src1. (The x and y components after swizzling)
Status register 0 stores the result of comparing the x components based on the condition specified by mode0. Status register 1 stores the result of comparing the y components based on the condition specified by mode1. The status register is set to 1 if the comparison result is true, and it is set to 0 if the comparison result is false. The conditions are as follows:
If mode0 (or mode1) is 1: src0 == src1
If 2: src0 < src1
If 3: src0 <= src1
If 4: src0 > src1
If 5: src0 >= src1.

Use this instruction to distinguish between infinity, negative infinity, and NaN. A value of 0x7f0000 indicates infinity, 0xff0000 indicates negative infinity, and any value greater than 0x7f0000 and less than 0xff0000 indicates NaN.

Both status register 0 and 1 are always updated. It is not possible to update only one or the other.

Operation

switch ( mode0 )
{
    case 0 : status_register0 = ( src0.x == src1.x ) ? 1 : 0 ; break ;
    case 1 : status_register0 = ( src0.x != src1.x ) ? 1 : 0 ; break ;
    case 2 : status_register0 = ( src0.x <  src1.x ) ? 1 : 0 ; break ;
    case 3 : status_register0 = ( src0.x <= src1.x ) ? 1 : 0 ; break ;
    case 4 : status_register0 = ( src0.x >  src1.x ) ? 1 : 0 ; break ;
    case 5 : status_register0 = ( src0.x >= src1.x ) ? 1 : 0 ; break ;
}
switch ( mode1 )
{
    case 0 : status_register1 = ( src0.y == src1.y ) ? 1 : 0 ; break ;
    case 1 : status_register1 = ( src0.y != src1.y ) ? 1 : 0 ; break ;
    case 2 : status_register1 = ( src0.y <  src1.y ) ? 1 : 0 ; break ;
    case 3 : status_register1 = ( src0.y <= src1.y ) ? 1 : 0 ; break ;
    case 4 : status_register1 = ( src0.y >  src1.y ) ? 1 : 0 ; break ;
    case 5 : status_register1 = ( src0.y >= src1.y ) ? 1 : 0 ; break ;
}

Code Example

def     c0, 0, 1, 2, 3

mov     r0, c0
cmp     0, 0, r0, c0
ifc     1, 1, 2
    // This is executed when r0.x == 0
endif

Timetable

12345
cmp read CMP post write

Revision History

2011/12/20
Initial version.

CONFIDENTIAL