| 1 |
\section{Delay Slot Filling} |
| 2 |
\subsection{ Overview } |
| 3 |
|
| 4 |
Superscalar architectures such as the Sparc, MIPS, and PA-RISC |
| 5 |
contain delayed branch and/or load instructions. |
| 6 |
Delay slot filling is necessary |
| 7 |
task of the back end to keep the instruction pipelines busy. To accomodate |
| 8 |
the intricate semantics of branch delay slot in various architectures, |
| 9 |
MLRISC uses the following very general framework for dealing with |
| 10 |
delayed instructions. |
| 11 |
|
| 12 |
\begin{description} |
| 13 |
\item[Instruction representation] |
| 14 |
To make it easy to deal with instruction with delay slot, MLRISC allow |
| 15 |
the following extensions to instruction representations. |
| 16 |
\begin{itemize} |
| 17 |
\item Instructions with delay slot may have a |
| 18 |
\begin{color}{#aa0000}nop\end{color} flag. When this flag is true |
| 19 |
the delay slot is assumed to be filled with a NOP instruction. |
| 20 |
\item Instructions with delay slots that can be nullified may have a |
| 21 |
\begin{color}{#aa0000}nullified\end{color} flag. |
| 22 |
When this flag is true the branch delay slot is assumed to be |
| 23 |
nullified. |
| 24 |
\end{itemize} |
| 25 |
\item[Nullification semantics] |
| 26 |
Unfortunately, nullification semantics |
| 27 |
in architectures vary. In general, MLRISC allows the following |
| 28 |
additional nullification characteristics to be specified. |
| 29 |
\begin{itemize} |
| 30 |
\item Nullification can be specified as illegal; this is needed |
| 31 |
because some instructions can not be nullified |
| 32 |
\item When nullification is enabled, the semantics of the delay slot |
| 33 |
instruction may depend on the direction of the branch, and whether |
| 34 |
a conditional test succeeds. |
| 35 |
\item Certain class of instructions may be declared to be illegal |
| 36 |
to fit into certain class of delay slots. |
| 37 |
\end{itemize} |
| 38 |
\end{description} |
| 39 |
|
| 40 |
For example, conditional branch instructions on the Sparc are defined |
| 41 |
as follows: |
| 42 |
\begin{verbatim} |
| 43 |
Bicc of {b:branch, a:bool, label:Label.label, nop:bool} |
| 44 |
asm: ``b<b><a>\t<label><nop>'' |
| 45 |
padding: nop = true |
| 46 |
nullified: a = true and (case b of I.BA => false | _ => true) |
| 47 |
delayslot candidate: false |
| 48 |
\end{verbatim} |
| 49 |
\noindent where \sml{a} is \emph{annul} flag and \sml{nop} is the nop |
| 50 |
flag (see \mlrischref{sparc/sparc.md}{the Sparc machine description}). |
| 51 |
A constructor term |
| 52 |
\begin{SML} |
| 53 |
Bicc\{b=BE, a=true, label=label, nop=true\} |
| 54 |
\end{SML} |
| 55 |
denotes the instruction sequence |
| 56 |
\begin{verbatim} |
| 57 |
be,a label |
| 58 |
nop |
| 59 |
\end{verbatim} |
| 60 |
while |
| 61 |
\begin{SML} |
| 62 |
Bicc\{b=BE, a=false, label=label, nop=false\} |
| 63 |
\end{SML} |
| 64 |
denotes |
| 65 |
\begin{verbatim} |
| 66 |
be label |
| 67 |
\end{verbatim} |
| 68 |
|
| 69 |
|
| 70 |
\subsection{The Interface} |
| 71 |
|
| 72 |
Architecture information about how delay slot filling is to be performed |
| 73 |
is described in the signature |
| 74 |
\mlrischref{backpatch/delaySlotProps.sig}{DELAY\_SLOT\_PROPERTIES}. |
| 75 |
\begin{SML} |
| 76 |
signature DELAY_SLOT_PROPERTIES = |
| 77 |
sig |
| 78 |
structure I : INSTRUCTIONS |
| 79 |
|
| 80 |
datatype delay_slot = |
| 81 |
D_NONE | D_ERROR | D_ALWAYS |
| 82 |
| D_TAKEN | D_FALLTHRU |
| 83 |
|
| 84 |
val delaySlotSize : int |
| 85 |
val delaySlot : \{ instr : I.instruction, backward : bool \} -> |
| 86 |
\{ n : bool, |
| 87 |
nOn : delay_slot, |
| 88 |
nOff : delay_slot, |
| 89 |
nop : bool |
| 90 |
\} |
| 91 |
val enableDelaySlot : |
| 92 |
\{instr : I.instruction, n:bool, nop:bool\} -> I.instruction |
| 93 |
val conflict : |
| 94 |
\{regmap:int->int,src:I.instruction,dst:I.instruction\} -> bool |
| 95 |
val delaySlotCandidate : |
| 96 |
\{ jmp : I.instruction, delaySlot : I.instruction \} -> bool |
| 97 |
val setTarget : I.instruction * Label.label -> I.instruction |
| 98 |
end |
| 99 |
\end{SML} |
| 100 |
|
| 101 |
The components of this signature are: |
| 102 |
\begin{description} |
| 103 |
\item[delay\_slot] This datatype describes properties related to a |
| 104 |
delay slot. |
| 105 |
\begin{description} |
| 106 |
\item[D\_NONE] This indicates that no delay slot is possible. |
| 107 |
\item[D\_ERROR] This indicates that it is an error |
| 108 |
\item[D\_ALWAYS] This indicates that the delay slot is always active |
| 109 |
\item[D\_TAKEN] This indicates that the |
| 110 |
delay slot is only active when branch is taken |
| 111 |
\item[D\_FALLTHRU] This indicates that the delay slot |
| 112 |
is only active when branch is not taken |
| 113 |
\end{description} |
| 114 |
\item[delaySlotSize] This is size of delay slot in bytes. |
| 115 |
|
| 116 |
\item[delaySlot] This method takes an instruction \sml{instr} |
| 117 |
and a flag indicating whether the branch is \sml{backward}, |
| 118 |
and returns the delay slot properties of an instruction. The |
| 119 |
properties is described by four fields. |
| 120 |
\begin{description} |
| 121 |
\item[n : bool] This bit is if the nullified bit in the |
| 122 |
instruction is currently set. |
| 123 |
\item[nOn : delay\_slot] This field indicates the delay slot |
| 124 |
type when the instruction is nullified. |
| 125 |
\item[nOff : delay\_slot] This field indiciates the delay slot |
| 126 |
type when the instruction is not nullified. |
| 127 |
\item[nop : bool] This bit indicates whether there is an |
| 128 |
implicit padded nop. |
| 129 |
\end{description} |
| 130 |
|
| 131 |
|
| 132 |
\item[enableDelaySlot] |
| 133 |
This method set the nullification and nop flags of an instruction. |
| 134 |
|
| 135 |
\item[conflict] This method checks whether there are any conflicts |
| 136 |
between instruction \sml{src} and \sml{dst}. |
| 137 |
\item[delaySlotCandidate] |
| 138 |
This method checks whether instruction \sml{delaySlot} is within the |
| 139 |
class of instructions that can fit within the delay slot of |
| 140 |
instruction \sml{jmp}. |
| 141 |
|
| 142 |
\item[setTarget] |
| 143 |
This method changes the branch target of an instruction. |
| 144 |
\end{description} |
| 145 |
|
| 146 |
\subsubsection{Examples} |
| 147 |
For example, |
| 148 |
\begin{SML} |
| 149 |
delaySlot\{instr=instr, backward=true\} = |
| 150 |
\{n=true, nOn=D_ERROR, nOff=D_ALWAYS, nop=true\} |
| 151 |
\end{SML} |
| 152 |
\noindent means that the instruction nullification bit is on, the |
| 153 |
the nullification cannot be turned off, delay slot is always active |
| 154 |
(when not nullified), and there is currently an implicit padded nop. |
| 155 |
|
| 156 |
\begin{SML} |
| 157 |
delaySlot\{instr=instr, backward=false\} = |
| 158 |
\{n=false, nOn=D_NONE, nOff=D_TAKEN, nop=false\} |
| 159 |
\end{SML} |
| 160 |
\noindent means that the nullification bit is off, the delay slot |
| 161 |
is inactive when the nullification bit is off, the delay slot is only |
| 162 |
active when the (forward) branch is taken when \sml{instr} is |
| 163 |
not-nullified, and there |
| 164 |
is no implicitly padded nop. |
| 165 |
|
| 166 |
\begin{SML} |
| 167 |
delaySlot\{instr=instr, backward=true\} = |
| 168 |
\{n=true, nOn=D_TAKEN, nOff=D_ALWAYS, nop=true\} |
| 169 |
\end{SML} |
| 170 |
\noindent means that the nullification bit is on, the delay slot |
| 171 |
is active on a taken (backward) branch when the nullification bit is off, |
| 172 |
the delay slot is always active when \sml{instr} is not-nullified, |
| 173 |
and there is currently an implicitly padded nop. |
| 174 |
|