Intel vISA Spec: Operands
intel_gpu_visa)Intel Gen9–Gen12 / Xe-LP / Xe-HPG / Xe-HPC / Xe2
master
Summary
Intel IGC Virtual ISA specification chapter: Operands.
Syntax / Encoding
Operands
Reference Notes
# Operands
There are two types of operands: **vector** and **raw**. Vector operands
represent vector data values used in SIMD instructions and may include
offset and region information. Raw operands are used to represent the
destination and source of memory access and sample instructions, which
must be accessed contiguously and do not support 2D element access.
Region-based Addressing
=======================
Virtual ISA supports a region-based addressing scheme for general
variables. In a Virtual ISA instruction, a general operand or an
indirect operand defines a region describing the data elements that will
be accessed from a general variable. For source operands, regions are
generalized 2D arrays in row-major order, where each row is the size of
a GRF register. Specifically, a source region takes the following
format:
**VN(R,C) < VertStride; Width, HorzStride>**
- **Region origin (VN(R,C))**: This parameter determines the location
of the first data element accessed from VN. Both R, the row offset,
and C, the column offset, must be immediate constants.
- **Width**: This parameter specifies the number of data elements of a
row.
- **HorzStride**: This parameter specifies the step size between two
adjacent data elements in a row.
- **VertStride**: This parameter specifies the step size between two
rows.
Width, HorzStride, and VertStide are all in the unit of data element
size. Together with the instruction's execution size (ExecSize), the
following pseudo-code may be used to derive the data elements accessed
by a source operand:
```
SourceDataElements[ExecSize];
int count = 0;
FirstElementIndex = R * (GRF_Size_in_Bytes / sizeof(VN_type)) + C;
for( int i = 0; i < ExecSize / Width; i++) {
for( int j = 0; j < Width; j++ ) {
SourceDataElements[count++] = VN[FirstElementIndex + i * VertStride + j * HorzStride];
}
}
```
Region for a destination operand, on the other hand, is only 1D, and it
takes the following format:
**VN(R,C) <HorzStride>**
```
DstDataElements[ExecSize];
FirstElementIndex = R * (GRF_Size_in_Bytes / sizeof(VN_type)) + C;
for (int i = 0; i < ExecSize; i++ ) {
DstDataElements[i] = VN[FirstElementIndex + i *HorzStride];
}
```
The behavior is undefined if an operand attempts to access an
out-of-bound data element. The figure below illustrates the use of
regions for general operands.

Region Interpretation for Indirect Operands
-------------------------------------------
For indirect operands, two regioning modes are supported:
**single-address** and **multi-address** (uses ExecSize/Width
addresses). A single-address indirect operand takes the following
format:
**r\[AN(k), offset\]<VertStride; Width, HorzStride> //source**
**r\[AN(k), offset\]<HorzStride> //destination**
The region parameters are interpreted identically to the general
operands, except that the region origin will be the data element at the
address AN(k) + offset. A multi-address indirect operand is specified by
a null vertical stride:
**r\[AN(k), offset\]<; Width, HorzStride> //source**
In this mode, the origin of each row is determined by the contents of
the address operand. The first element in the address operand provides
the origin of the first row, while successive contiguous address
elements provide the origin for the following rows. In the special case
where Width is equal to one, ExecSize number of address elements will be
used. Each address element is permitted to point to a different general
variable. The following pseudo-code may be used to derive the data
elements accessed by a multi-address indirect source operand:
```
SourceDataElements[ExecSize];
int count = 0;
for( int i = 0; i < ExecSize / Width; i++) {
RowStartOffset = AN(k + i) + offset;
for( int j = 0; j < Width; j++ ) {
SourceDataElements[count++] = *(RowStartOffset + j * HorzStride * sizeof(operand_type)];
}
}
```
The addresses in an indirect operand may only be generated by the special
ADDR_ADD instruction, and they must fall within range of the general variable
whose address is taken.
The behavior is undefined if an indirect operand attempts to
access an out-of-bound address. The behavior is also
undefined if any of the address offset is not aligned to the type of the
indirect operand. The figure below illustrates the use of regions for
indirect operands.

Region Restrictions
-------------------
Regions provide a powerful mechanism for per-instruction data
gather/scatter, but the following rules must be observed:
**General Restrictions on Region Parameters**
1. The legal values for Width are {1, 2, 4, 8, 16}.
2. The legal values for VertStride are {0, 1, 2, 4, 8, 16, 32}.
3. The legal values for HorzStride are {0, 1, 2, 4}.
4. ExecSize must be greater than or equal to Width.
5. HorzStride for a destination operand must not be 0.
6. The elements accessed by an operand may not span more than two
adjacent GRF registers.
**Implementation Note: To satisfy rule 6, the FE compiler must be aware
of the JIT compiler's variable alignment rules, which are as follows:**
- Variables larger than or equal to one GRF in size will be
GRF-aligned.
- Variables less than one GRF will be placed in a single GRF (that is,
it will not cross GRF-boundary).
**Additional Region Restrictions for indirect operands**
1. Multi-address indirect operand may not be used as the destination of
an instruction.
2. If a multi-address indirect operand is used inside divergent control
flow, the inactive channels must still have a valid address even if
they do not execute. A valid address is defined as an address that
is within range of a general variable and is also aligned to the
indirect operand's type.
**Implementation Note: One possible way to satisfy rule 2 is to
explicitly initialize an address register to zero for all lanes
inside divergent control flow.**
The behavior is undefined if any of the region rules are violated.
Predication
===========
Most vISA instructions are permitted to include a predicate control for
conditional SIMD channel selection for execution. The predication
control field consists of a single UW with the following binary format:
| Bit(s) | Name | Value |
| --- | --- | --- |
| 15 | Predicate Inverse | "0" - no inverse |
| | | "1" - use the inverse of each predicate bit |
| 13-14 | Predicate Combine | "00" - sequential channel-to-predicate mapping |
| | | "01" - any: returns 1 for all channels if any predicate bit is 1 |
| | | "10" - all: returns 1 for all channels if all predicate bits are 1 |
| | | "11" - reserved |
| 12 | Reserved | Must be 0 |
| 0-11 | Predicate ID | Index of the predicate variable in range of [0-4095] |
If predicate combine and predicate inverse are both enabled, the
predicate combine will take effect first before the predicate inverse is
applied. The instruction's mask control determines the starting offset
for the predicate variable; e.g., a value of {M3} means the first
element will be pred_id(8). Together with the execution mask, the
predicate control determines the set of active channels for each
instruction with the algorithm below. Only channels whose channel enable
(ChEn) bit evaluates to true will have their output written to the
destination.
```
EvaluateChEn() { // evaluate the set of enabled Channels ChEn for this instruction
// ChEn is a 32 bit mask
// mask_control is one of {M1}, {M2}, ..., {M8}, and {NoMask}
// pred_control is the controlling predicate operand
if ( mask_control == NoMask ) {
for ( n = 0; n < exec_size; n++ ) {
ChEn[n] = 1;
}
}
else {
for ( n = 0; n < exec_size; n++ ) {
ChEn[n] = EM[n + mask_control_offset] ? 1 : 0;
}
}
if ( pred_control != 0 ) {
// PMask is a 32 bit mask
for ( n = 0; n < exec_size; n++ ) {
PMask[n] = Pred[n + mask_control_offset];
}
if ( pred_control.any ) {
PMask[0:exec_size-1] = (any of the PMask[0:exec_size-1] is 1) ? 1 : 0;
}
else if ( pred_control.all ) {
PMask[0:exec_size-1] = (all of the PMask[0:exec_size-1] are 1) ? 1: 0;
}
if( pred_control.invert ) {
PMask = ~PMask;
}
for ( n = 0; n < exec_size; n++ ) {
ChEn[n] = ChEn[n] & PMask[n];
}
}
for ( n = exec_size; n < 32; n++ ) {
ChEn[n] = 0;
}
```
For instructions that do not execute on the EU (e.g., memory access and
sampler instructions), the channel enable bit mask is evaluated and then
passed to the destination shared function to indicate which SIMD
channels were enabled. It is up to the shared function to interpret or
ignore the channel enable bits based on the functionality; for example,
scatter memory accesses typically will honor the channel enable by only
reading or writing to the enabled channels, while block memory accesses
generally ignore the channel enable and always perform the operation.
For details on the behavior of each instruction refer to their section.
Vector Operands
===============
Vector operands are used in arithmetic, logical, data movement, and
comparison instructions. These operands are typically general variables,
but may also be indirect accesses through an address variable. Address
operands may appear in the special address instructions. Most
instructions also may have a predicate operand to control conditional
execution.
A vector operand structure has different format depending on its operand
class:
```
vec_operand {
ub tag;
ub info[];
}
```
- **<tag:**> This byte is common to all vector operands and contains
two items: **operand_class** and **modifiers**.
- **operand_class (bit0-2):** A source operand may be one of the
following:
- **General ("000"):** a general-purpose variable **v\#.**
- **Address ("001"):** an address variable **a\#**. Address
variables may only appear in the special address
instructions.
- **Predicate("010"):** a predicate variable **P**. Predicates
may appear either in comparison, logical, or the special
SETP instructions.
- **Indirect ("011"):** indirect access to a general-purpose
variable through an address variable **(\[a\#\]).** The
value of an indirect operand must be elements within one
base General variable (in other words, address arithmetic
must not cross variable boundary). In general, indirect
operands may appear anywhere a General operand is used.
- **Immediate ("101"):** an immediate constant **.** An
immediate constant may only be used as source operand.
- **State ("110"):** a state variable (one of
sampler/surface). Its usage is restricted to the ADDR_ADD
and MOVS instruction.
- The remaining values are reserved.
- **modifiers (bit3-5):** modifiers that can be applied on the operand
values. Valid values are:
Modifiers may only be used for General and Indirect operands; for the
other operands the modifier must be zero. The "not" modifier may only
appear in certain logic instructions (namely and, not