6. Control Flow#
6.1. call#
Call a function.
Unconditional function call:
call retval, target (<arg1> <, arg2> ... <, argn>)
- retval can be a register or void
- target can be a 64-bit register or a function name
Restrictions
type of
retvalmust matchtargetfunction return type
PISA Notes
introduced in PISA version 0.1
requires PISA target 100 or compatible
Conditional function call:
call.cond <!>pred, retval, target (<arg1> <, arg2> ... <, argn>)
- pred is a predicate register
- retval can be a register or void
- target can be a 64-bit register or a function name
Restrictions
type of
retvalmust matchtargetfunction return type
PISA Notes
introduced in PISA version 0.1
requires PISA target 100 or compatible
Semantics:
$caller_PC = $PC_next; // instruction after call
// implementation-defined mechanism to pass arguments to callee
$PC = target
xfer_control = pred
if ('!' is set)
xfer_control = !xfer_control
if (xfer_control)
$caller_PC = $PC_next; // instruction after call
// implementation-defined mechanism to pass arguments to callee
$PC = target
else
nop // fall-through
Notes:
<arg1>...<argn> are actual function arguments passed by the caller. Arguments must
be register variables, immediate values are not allowed.
When the callee executes the return instruction, control flow will be transfered
back to the next instruction following the call in the caller. If retval is not
void, the return value specified in the callee’s return instruction will also be written
to retval.
It is undefined behavior if contents of the register do not point to function code.
Examples:
.reg .32b %src0, %retval;
.reg .64b %fptr;
.pred %p;
// call a void function with no arguments
call void, @func0();
// call function returning 32-bit value only if %p is true
call.cond %p, %retval, @func1();
// call function with arguments only if %p is false
call.cond !%p, %retval, @func2(%src0);
// call a function through a function pointer
addrof.64b %fptr, @func0;
call void, %fptr();
6.2. goto#
Branch to a label.
Unconditional branch:
goto label - label is a named location within current function
PISA Notes
introduced in PISA version 0.1
requires PISA target 100 or compatible
Conditional branch:
goto.cond <!>pred, label - pred is a predicate register - label is a named location within current function
PISA Notes
introduced in PISA version 0.1
requires PISA target 100 or compatible
Semantics:
$PC = label;
xfer_control = pred
if ('!' is set)
xfer_control = !xfer_control
if (xfer_control)
$PC = label
else
nop // fall-through
Examples:
.pred %p;
// jump to label1 within this function
goto label1;
label1:
// jump to label2 within this function only if %p is true
goto.cond %p, label2;
// jump to label2 within this function only if %p is false
goto.cond !%p, label2;
label2:
6.3. return#
Return from a function or end a work-item’s execution in a kernel.
Unconditional return:
return <retval> - retval can be a register or an immediate
Restrictions
type of
retvalmust match current function return type
PISA Notes
introduced in PISA version 0.1
requires PISA target 100 or compatible
Conditional return:
return.cond <!>pred, retval - pred is a predicate register - retval can be a register or an immediate
Restrictions
type of
retvalmust match current function return type
PISA Notes
introduced in PISA version 0.1
requires PISA target 100 or compatible
Semantics:
$PC = $caller_PC; // instruction after call()
xfer_control = pred
if ('!' is set)
xfer_control = !xfer_control
if (xfer_control)
$PC = $caller_PC; // instruction after call()
else
nop // fall-through
Notes:
If return is executed in a kernel, it ends this work-item’s execution.
retval specifies the function return value. It must be omitted for kernels
and void functions. In non-void functions, return must be the last instruction.
Examples:
.pred %p;
// unconditional return (ends work-item in a kernel; returns from .func)
return;
// return only if %p is true
return.cond %p;
// return only if %p is false
return.cond !%p;