VRIL Instructions
The specification document of the instructions of VRIL.
- Operation Codes
- Arithmetic Instructions
(ADD, SUB, MUL, DIV, REM, NEG) - Comparison Instructions
(EQ, NEQ, GT, LT, GEQ, LEQ) - Logical Instructions
(ANDM, ORM, NOT) - Transfer Instructions
(MOV, REF, POP, MOVPOP, REFPOP, MOVELM, REFELM, CAST, REORD, FILL) - Memory Management Instructions
(ALLOC, ALLOCR, ALLOCP, ALLOCT, FREE) - Control Instructions
(JMP, JMPN, CALL, CALLX, RET, ENDFUN, ENDPRM, END, NOP, LABEL) - Extended Instructions
(EX)
Operation Codes
The followings are the list of operation codes (opcodes) of VRIL.
Arithmetic Instructions
Opcode | ADD |
---|---|
Category | SIMD Arithmetic Instruction |
Syntax | ADD type output inputA inputB; |
Description |
The instruction to perform an addition operation. When this instruction is executed, the calculation of "inputA + inputB" will be performed, and then result data will be stored in the "output". The data type of all operands should be the same (specify the data type name to "type" operand). Also, the number of the array-length and the array-rank of data of all operands should be the same. |
Opcode | SUB |
---|---|
Category | SIMD Arithmetic Instruction |
Syntax | SUB type output inputA inputB; |
Description |
The instruction to perform a subtraction operation. When this instruction is executed, the calculation of "inputA - inputB" will be performed, and then result data will be stored in the "output". The data type of all operands should be the same (specify the data type name to "type" operand). Also, the number of the array-length and the array-rank of data of all operands should be the same. |
Opcode | MUL |
---|---|
Category | SIMD Arithmetic Instruction |
Syntax | MUL type output inputA inputB; |
Description |
The instruction to perform a multiplication operation. When this instruction is executed, the calculation of "inputA * inputB" will be performed, and then result data will be stored in the "output". The data type of all operands should be the same (specify the data type name to "type" operand). Also, the number of the array-length and the array-rank of data of all operands should be the same. |
Opcode | DIV |
---|---|
Category | SIMD Arithmetic Instruction |
Syntax | DIV type output inputA inputB; |
Description |
The instruction to perform a division operation. When this instruction is executed, the calculation of "inputA / inputB" will be performed, and then result data will be stored in the "output". The data type of all operands should be the same (specify the data type name to "type" operand). Also, the number of the array-length and the array-rank of data of all operands should be the same. |
Opcode | REM |
---|---|
Category | SIMD Arithmetic Instruction |
Syntax | REM type output inputA inputB; |
Description |
The instruction to perform a remainder operation. When this instruction is executed, the calculation of "inputA % inputB" will be performed, and then result data will be stored in the "output". The data type of all operands should be the same (specify the data type name to "type" operand). Also, the number of the array-length and the array-rank of data of all operands should be the same. |
Opcode | NEG |
---|---|
Category | SIMD Arithmetic Instruction |
Syntax | NEG type output input; |
Description |
The instruction to perform a sign inversion operation. When this instruction is executed, the calculation of "-input" will be performed, and then result data will be stored in the "output". The data type of all operands should be the same (specify the data type name to "type" operand). Also, the number of the array-length and the array-rank of data of all operands should be the same. |
Comparison Instructions
Opcode | EQ |
---|---|
Category | SIMD Comparison Instruction |
Syntax | EQ type output inputA inputB; |
Description |
The instruction to perform the equality comparison operation. When this instruction is executed, the comparison operation of "inputA == inputB" will be performed, and then result data will be stored in the "output". The data type of "inputA" and "inputB" operands should be the same. Specify the name of the data type to "type". In addition, the data type of "output" should be "BOOL". |
Opcode | NEQ |
---|---|
Category | SIMD Comparison Instruction |
Syntax | NEQ type output inputA inputB; |
Description |
The instruction to perform the "non-equality" comparison operation. When this instruction is executed, the comparison operation of "inputA != inputB" will be performed, and then result data will be stored in the "output". The data type of "inputA" and "inputB" operands should be the same. Specify the name of the data type to "type". In addition, the data type of "output" should be BOOL. |
Opcode | GT |
---|---|
Category | SIMD Comparison Instruction |
Syntax | GT type output inputA inputB; |
Description |
The instruction to perform the "grater-than" comparison operation. When this instruction is executed, the comparison operation of "inputA > inputB" will be performed, and then result data will be stored in the "output". The data type of "inputA" and "inputB" operands should be the same. Specify the name of the data type to "type". In addition, the data type of "output" should be BOOL. |
Opcode | LT |
---|---|
Category | SIMD Comparison Instruction |
Syntax | LT type output inputA inputB; |
Description |
The instruction to perform the "less-than" comparison operation. When this instruction is executed, the comparison operation of "inputA < inputB" will be performed, and then result data will be stored in the "output". The data type of "inputA" and "inputB" operands should be the same. Specify the name of the data type to "type". In addition, the data type of "output" should be BOOL. |
Opcode | GEQ |
---|---|
Category | SIMD Comparison Instruction |
Syntax | GEQ type output inputA inputB; |
Description |
The instruction to perform the "grater-equal" comparison operation. When this instruction is executed, the comparison operation of "inputA >= inputB" will be performed, and then result data will be stored in the "output". The data type of "inputA" and "inputB" operands should be the same. Specify the name of the data type to "type". In addition, the data type of "output" should be BOOL. |
Opcode | LEQ |
---|---|
Category | SIMD Comparison Instruction |
Syntax | LEQ type output inputA inputB; |
Description |
The instruction to perform the "less-equal" comparison operation. When this instruction is executed, the comparison operation of "inputA <= inputB" will be performed, and then result data will be stored in the "output". The data type of "inputA" and "inputB" operands should be the same. Specify the name of the data type to "type". In addition, the data type of "output" should be BOOL. |
Logical Instructions
Opcode | ANDM |
---|---|
Category | SIMD Logical Instruction |
Syntax | ANDM type output inputA inputB; |
Description |
The instruction to perform the logical-and comparison operation. When this instruction is executed, the logical operation of "inputA && inputB" will be performed, and then result data will be stored in the "output". The data type of all operands should be BOOL, and "bool" should be specified to "type". Also, this instruction does not access to "inputB" when the result can be determined from only the value of "inputA", to simplify the generated code of short-circuit evaluation of "&&" operator. More precisely: when operands are scalars, accessing to "inputB" will be skipped if the value of "inputA" is false. When operands are vectors, accessing to "inputB" will be skipped if all elements of "inputA" are false. |
Opcode | ORM |
---|---|
Category | SIMD Logical Instruction |
Syntax | ANDM type output inputA inputB; |
Description |
The instruction to perform the logical-or comparison operation. When this instruction is executed, the logical operation of "inputA || inputB" will be performed, and then result data will be stored in the "output". The data type of all operands should be BOOL, and "bool" should be specified to "type". Also, this instruction does not access to "inputB" when the result can be determined from only the value of "inputA", to simplify the generated code of short-circuit evaluation of "||" operator. More precisely: when operands are scalars, accessing to "inputB" will be skipped if the value of "inputA" is true. When operands are vectors, accessing to "inputB" will be skipped if all elements of "inputA" are true. |
Opcode | NOT |
---|---|
Category | SIMD Logical Instruction |
Syntax | NOT type output input; |
Description |
The instruction to perform the logical-not comparison operation. When this instruction is executed, the logical operation of "! input" will be performed, and then result data will be stored in the "output". The data type of all operands should be BOOL, and "bool" should be specified to "type". |
Transfer Instructions
Opcode | MOV |
---|---|
Category | SIMD Transfer Instruction |
Syntax | MOV type output input; |
Description |
The instruction to perform the copy-assignment operation. When this instruction is executed, the data of "input" will be copied and stored in the "output". The data type of all operands should be the same. Specify the name of the data type to "type". |
Opcode | REF |
---|---|
Category | SIMD Transfer Instruction |
Syntax | REF type output input; |
Description |
The instruction to perform the reference-assignment operation. When this instruction is executed, the data reference of "output" will be the same with it of "input". The data type of all operands should be the same. Specify the name of the data type to "type". |
Opcode | POP |
---|---|
Category | SIMD Transfer Instruction |
Syntax | POP -; |
Description | The instruction to pop data from the stack, but does not store it in anywhere. |
Opcode | MOVPOP |
---|---|
Category | SIMD Transfer Instruction |
Syntax | MOVPOP type output; |
Description |
The instruction to pop data from the stack and performs the copy-assignment operation. When this instruction is executed, the data poped from the stack will be copied and stored in the "output". Specify the name of the data type of "output" to "type". |
Opcode | REFPOP |
---|---|
Category | SIMD Transfer Instruction |
Syntax | MOVPOP type output; |
Description |
The instruction to pop data from the stack and performs the reference-assignment operation. When this instruction is executed, the data reference of "output" will set to the data popped from the stack. Specify the name of the data type of "output" to "type". |
Opcode | MOVELM |
---|---|
Category | Scalar Transfer Instruction |
Syntax | MOVELM type output input index1 index2 index3 ... indexN ; (variable length) |
Description |
The instruction to copy the value of an element of an array. When this instruction is executed, the value of an element at [index1][index2][index3]...[indexN] of the array "input" will be copied and stored in the "output". The data type of all operands should be the same. Specify the name of the data type to "type". |
Opcode | REFELM |
---|---|
Category | Scalar Transfer Instruction |
Syntax | REFELM type output input index1 index2 index3 ... indexN ; (variable length) |
Description |
The instruction to refer to an element of an array. When this instruction is executed, the reference of data of "output" points to the element with [index1][index2][index3]...[indexN] of the array "output". The data type of all operands should be the same. Specify the name of the data type to "type". |
Opcode | CAST |
---|---|
Category | SIMD Transfer Instruction |
Syntax | CAST toType:fromType output input; |
Description |
The instruction to perform the type-cast operation. When this instruction is executed, a data of "input" of which data-type is "fromType" type will be casted to "toType" type, and then result data will be stored to "output". |
Opcode | REORD |
---|---|
Category | SIMD Transfer Instruction |
Syntax | REORD type output input; |
Description | (Unused) The instruction to perform assignment operations of elements of which indices is the same between multi-dimensional arrays having different lengths. |
Opcode | FILL |
---|---|
Category | SIMD Transfer Instruction |
Syntax | FILL type output input; |
Description |
The instruction to fill all elements of the array with the same value. When this instruction is executed, the scalar value "input" will be copied to all elements of the array "output". The data type of all operands should be the same. Specify the name of the data type to "type". |
Memory Management Instructions
Opcode | ALLOC |
---|---|
Category | Memory Management Instruction |
Syntax | ALLOC type target len1 len2 len3 ... lenN; (variable length) |
Description |
The instruction to allocate memory. When this instruction is executed, a data container for storing data of "target" of which data type is "type" will be created in the virtual memory. For operands len1 ... lenN, specify array-lengths of each dimensions of data to be stored. For example, specify R0 R1 R2 for storing array of which lengths are [R0][R1][R2]. Scalar data is handled as a 0-dimension array, so to store scalar data, specify no operands for len1 ... lenN. |
Opcode | ALLOCR |
---|---|
Category | Memory Management Instruction |
Syntax | ALLOCR type target sample; |
Description |
A variation of the ALLOC instruction, to allocate memory of which size is the same as the other data. When this instruction is executed, a data container for storing data of "target" of which data type is "type" and having the same size with "sample" will be created in the virtual memory. As named as "-R", this instruction is mainly used for allocating a register for storing a result of a vector operation, but this instruction is also available for allocating non-register data. |
Opcode | ALLOCP |
---|---|
Category | Memory Management Instruction |
Syntax | ALLOCP type target; |
Description |
A variation of the ALLOC instruction to allocate memory, of which size is the same as the data which is at the top of the stack. When this instruction is executed, a data container for storing data of "target" of which data type is "type" and having the same size with data which is at the top of the stack will be created in the virtual memory. |
Opcode | ALLOCT |
---|---|
Category | Memory Management Instruction |
Syntax | ALLOCT type target len1 len2 len3 ... lenN; |
Description |
A variation of the ALLOC instruction, to only declare data type and array ranks/lengths for readability and optimizability of code, without allocating the actual memory. For an example of use, this instruction is used at the point at which data will be popped from the stack. Data passed through the stack depends on the processing flow of the code on runtime, so it is not easy to grasp/infere type of popped data (containing the array-rank) without executing code is not easy. Therefore, in such cases, declaring type/rank/lengths of data by this instruction is helpful for readers of code and optimizers. (the compiler knows the type of data to be popped from the stack, so it can generate this instruction at the above point.) |
Opcode | FREE |
---|---|
Category | Memory Management Instruction |
Syntax | FREE type target; |
Description |
The instruction to release memory. When this instruction is executed, a data container for storing data of "target" in the virtual memory will be released. |
Control Instructions
Opcode | JMP |
---|---|
Category | Control Instruction |
Syntax | JMP bool - label condition; |
Description |
The instruction to jump when the condition is true. When this instruction is executed, the processing flow will jump to the instruction at the next of the "label", if the value of "condition" is true. (When "condition" is an array, it will jump if all elements of "condition" are true.) The data-type of "condition" should be "bool" type. |
Opcode | JMPN |
---|---|
Category | Control Instruction |
Syntax | JMPN bool - label condition; |
Description |
The instruction to jump when the condition is false. When this instruction is executed, the processing flow will jump to the instruction at the next of the "label", if the value of "condition" is false. (When "condition" is an array, it will jump if all elements of "condition" are false.) The data-type of "condition" should be "bool" type. |
Opcode | CALL |
---|---|
Category | Control Instruction |
Syntax | CALL returnType - signature arg1 arg2 arg3 ... argN; (variable length) |
Description |
The instruction to call an internal function. When this instruction is executed, the internal function of which identifier (mungled name) is "identifier" will be called with arguments [arg1, arg2, arg3, ..., argN]. Specifically, at first, the instruction-address of the next instruction of this instruction (return address) will be pushed to the stack. Then, all arguments will be pushed to the stack from the left to the right. Finally, the processing flow will be jumped to the next instruction of the label which is declared by the same name as "identifier". To "returnType", specify the name of the data type of the return value which will be put on the stack. At the end of the internal function, the return value will be pushed at the top of the stack, and then the processing flow will be returned to the instruction at the return address by RET instruction. Therefore it requires to pop the return value from the stack after this instruction. |
Opcode | CALLX |
---|---|
Category | Control Instruction |
Syntax | CALLX returnType returnValue identifier arg1 arg2 arg3 ... argN; (variable length) |
Description |
The instruction to call the external function. When this instruction is executed, the external function of which identifier (mungled name) is "identifier" will be called with arguments [arg1, arg2, arg3, ..., argN], and then returned value will be stored to "returnValue". Specify the name of the data type of the return value to "returnType". |
Opcode | RET |
---|---|
Category | Control Instruction |
Syntax | RET type returnData; |
Description |
The instruction to return from the internal function. Specify the data of the return value of the function to "result", and specify the name of its data-type to "type". If the return value does not exist, specify nothing to "result", and specify the place-holder "-" to "type". When this instruction is executed, the instruction-address (return address) which is at the top of the stack will be poped, and the return value of the function will be pushed. If there is no return value, a blank data container will be pushed. Then, the processing flow will be jumped to the instruction at the popped instruction-address. |
Opcode | ENDFUN |
---|---|
Category | Control Instruction |
Syntax | ENDFUN type functionName; |
Description |
The special instruction which is put at the end of a function. Specify the identifier of the function to "functionName" (it will be used in the error message), and specify "string" to "type". If the script is described correctly, this instruction will not be executed, because the execution flow will returns to the caller-side by RET instruction locating before this instruction. This instruction will be executed when the content of the script is incorrect and the execution flow of a function which should return a value ends without returning a value (without executing RET instructions). Therefore, when this instruction is executed, an error to notify the above cause will occur, and the execution of code will end. |
Opcode | ENDPRM |
---|---|
Category | Control Instruction |
Syntax | ENDPRM type functionName; |
Description |
The special instruction which is put at the end of the transfer part between arguments and parameters in a function. Specify the identifier of the function to "functionName", and specify "string" to "type". When this instruction is executed, nothing will occur, but this instruction is useful as meta information for optimizations in the VM. Also, this instruction improves readability of the VRIL code a little. |
Opcode | END |
---|---|
Category | Control Instruction |
Syntax | END type result; |
Description |
The special instruction which is put at the end of code. Specify the data to be regarded as the evaluated value of code to "result", and specify the name of its data-type to "type". If the evaluated value does not exist, specify nothing to "result", and specify the place-holder "-" to "type". How it will be done depends on the script engine and the application, but "result" operand of this instruction may be used for the such purpose. |
Opcode | NOP |
---|---|
Category | Control Instruction |
Syntax | NOP -; |
Description | The instruction to perform nothing, but it isn't removed by optimizations. |
Opcode | LABEL |
---|---|
Category | Control Instruction |
Syntax | LABEL -; |
Description |
Same as NOP, performs nothing, but may be removed by optimizations. This operation code is mainly used for instructions at branch destinations. Branch destination labels in VRIL code will be translated to this instruction. |
Extended Instructions
Opcode | EX |
---|---|
Category | Extended Instruction |
Syntax | (Dipends on the implementation of the VM) |
Description | The operation code to make extended instructions. |