## GCN ISA VOPC/VOP3 instructions VOPC instructions can be encoded in the VOPC encoding and the VOP3A encoding. List of fields for VOPC encoding: Bits | Name | Description ------|----------|------------------------------ 0-8 | SRC0 | First (scalar or vector) source operand 9-16 | VSRC1 | Second (scalar or vector) source operand 17-24 | OPCODE | Operation code 25-31 | ENCODING | Encoding type. Must be 0b0111110 Syntax: INSTRUCTION VCC, SRC0, VSRC1 List of fields for VOP3A/VOP3B encoding (GCN 1.0/1.1): Bits | Name | Description ------|----------|------------------------------ 0-7 | SDST | Scalar destination operand 8-10 | ABS | Absolute modifiers for source operands (VOP3A) 11 | CLAMP | CLAMP modifier (VOP3A) 17-25 | OPCODE | Operation code 26-31 | ENCODING | Encoding type. Must be 0b110100 32-40 | SRC0 | First (scalar or vector) source operand 41-49 | SRC1 | Second (scalar or vector) source operand 50-58 | SRC2 | Third (scalar or vector) source operand 59-60 | OMOD | OMOD modifier. Multiplication modifier 61-63 | NEG | Negation modifier for source operands List of fields for VOP3A/VOP3B encoding (GCN 1.2/1.4): Bits | Name | Description ------|----------|------------------------------ 0-7 | SDST | Scalar destination operand 8-10 | ABS | Absolute modifiers for source operands (VOP3A) 11-14 | OP_SEL | Operand selection (VOP3A) (GCN 1.4) 15 | CLAMP | CLAMP modifier 16-25 | OPCODE | Operation code 26-31 | ENCODING | Encoding type. Must be 0b110100 32-40 | SRC0 | First (scalar or vector) source operand 41-49 | SRC1 | Second (scalar or vector) source operand 50-58 | SRC2 | Third (scalar or vector) source operand 59-60 | OMOD | OMOD modifier. Multiplication modifier 61-63 | NEG | Negation modifier for source operands Syntax: INSTRUCTION SDST(2), SRC0, SRC1 [MODIFIERS] Modifiers: * -SRC - negate floating point value from source operand. Applied after ABS modifier. * ABS(SRC), |SRC| - apply absolute value to source operand * OP_SEL:VALUE|[B0,...] - operand half selection (0 - lower 16-bits, 1 - bits) NOTE: ABS and negation is applied to source operand for any instruction. Negation and absolute value can be combined: `-ABS(V0)`. Operand half selection (OP_SEL) take value with bits number depends of number operands. Last bit control destination operand. Zero in bit choose lower 16-bits in dword, one choose higher 16-bits. Example: op_sel:[0,1,1] - higher 16-bits in second source and in destination. List of bits of OP_SEL field: Bit | Operand | Description ----|---------|---------------------- 11 | SRC0 | Choose part of SRC0 (first source operand) 12 | SRC1 | Choose part of SRC1 (second source operand) 13 | SRC2 | Choose part of SRC2 (third source operand) 14 | VDST | Choose part of VDST (destination) Limitations for operands: * only one SGPR can be read by instruction. Multiple occurrences of this same SGPR is allowed * only one literal constant can be used, and only when a SGPR or M0 is not used in source operands * only SRC0 can holds LDS_DIRECT Unaligned pairs of SGPRs are allowed in source and destination operands. VOPC opcodes (0-255) and VOP3 opcodes are same. NOTE: Bits for inactive threads in the 64-bit scalar destination (VCC or pair of SGPRs) are always zeroed. ### Tables of opcodes and their descriptions Table of floating point comparison instructions by opcode (GCN 1.0/1.1): Opcode range | Instruction | Description --------------------|--------------------|--------------------------- 0-15 (0x00-0x0f) | V_CMP_{OP16}_F32 | Signal on sNAN input only. Single FP values. 16-31 (0x10-0x1f) | V_CMPX_{OP16}_F32 | Signal on sNAN input only. Also write result to EXEC. Single FP values. 32-47 (0x20-0x2f) | V_CMP_{OP16}_F64 | Signal on sNAN input only. Double FP values. 48-63 (0x30-0x3f) | V_CMPX_{OP16}_F64 | Signal on sNAN input only. Also write result to EXEC. Double FP values. 64-79 (0x40-0x4f) | V_CMPS_{OP16}_F32 | Signal on any sNAN. Single FP values. 80-95 (0x50-0x5f) | V_CMPSX_{OP16}_F32 | Signal on any sNAN. Also write result to EXEC. Single FP values. 96-111 (0x60-0x6f) | V_CMPS_{OP16}_F64 | Signal on any sNAN. Double FP values. 112-127 (0x70-0x7f) | V_CMPSX_{OP16}_F64 | Signal on any sNAN. Also write result to EXEC. Double FP values. Table of floating point comparison instructions by opcode (GCN 1.2/1.4): Opcode range | Instruction | Description --------------------|--------------------|--------------------------- 32-47 (0x20-0x2f) | V_CMP_{OP16}_F16 | Signal on sNAN input only. Half FP values. 48-63 (0x30-0x3f) | V_CMPX_{OP16}_F16 | Signal on sNAN input only. Also write result to EXEC. Half FP values. 64-79 (0x40-0x4f) | V_CMP_{OP16}_F32 | Signal on sNAN input only. Single FP values. 80-95 (0x50-0x5f) | V_CMPX_{OP16}_F32 | Signal on sNAN input only. Also write result to EXEC. Single FP values. 96-111 (0x60-0x6f) | V_CMP_{OP16}_F64 | Signal on sNAN input only. Double FP values. 112-127 (0x70-0x7f) | V_CMPX_{OP16}_F64 | Signal on sNAN input only. Also write result to EXEC. Double FP values. Table of OP16 (compare operations) for floating point values comparisons: Opcode offset | OP16 name | Description --------------|-----------|-------------------------- 0 (0x0) | F | SDST(LANEID) = 0 1 (0x1) | LT | SDST(LANEID) = ASTYPE(SRC0) < ASTYPE(SRC1_ 2 (0x2) | EQ | SDST(LANEID) = ASTYPE(SRC0) == ASTYPE(SRC1) 3 (0x3) | LE | SDST(LANEID) = ASTYPE(SRC0) <= ASTYPE(SRC1) 4 (0x4) | GT | SDST(LANEID) = ASTYPE(SRC0) > ASTYPE(SRC1) 5 (0x5) | LG | SDST(LANEID) = ASTYPE(SRC0) != ASTYPE(SRC1) 6 (0x6) | GE | SDST(LANEID) = ASTYPE(SRC0) >= ASTYPE(SRC1) 7 (0x7) | O | SDST(LANEID) = (!ISNAN(ASTYPE(SRC0)) && !ISNAN(ASTYPE(SRC1)) 8 (0x8) | U | SDST(LANEID) = (!ISNAN(ASTYPE(SRC0)) || !ISNAN(ASTYPE(SRC1))) 9 (0x9) | NGE | SDST(LANEID) = !(ASTYPE(SRC0) >= ASTYPE(SRC1)) 10 (0xa) | NLG | SDST(LANEID) = !(ASTYPE(SRC0) != ASTYPE(SRC1)) 11 (0xb) | NGT | SDST(LANEID) = !(ASTYPE(SRC0) > ASTYPE(SRC1)) 12 (0xc) | NLE | SDST(LANEID) = !(ASTYPE(SRC0) <= ASTYPE(SRC1)) 13 (0xd) | NEQ | SDST(LANEID) = !(ASTYPE(SRC0) == ASTYPE(SRC1)) 14 (0xe) | NLT | SDST(LANEID) = !(ASTYPE(SRC0) < ASTYPE(SRC1)) 15 (0xf) | TRU, T | SDST(LANEID) = 1 NOTE: Comparison operators (<,<=,!=,==) compares only non NaN values. If any operand is NaN then returns false. By contrast, negations of comparisons (NLT, NGT) returns true if any operand is NaN value. This feature distinguish for example NGE from LT. LANEID in description is lane id. ASTYPE function that treat compared values as value of type (ASFLOAT for _FP32, ASDOUBLE for _FP64). Sample instructions: ``` V_CMPX_LT_F32 VCC, V0, V1 # V0 (TYPE)SRC1 5 (0x5) | LG, NE | SDST(LANEID) = (TYPE)SRC0 != (TYPE)SRC1 6 (0x6) | GE | SDST(LANEID) = (TYPE)SRC0 >= (TYPE)SRC1 7 (0x7) | TRU, T | SDST(LANEID) = 1 LANEID in description is lane id. TYPE is type of compared values (UINT32 for _U32, INT32 for _I32,...). Sample instructions: ``` V_CMP_LT_U32 VCC, V0, V1 # V0