Prechádzať zdrojové kódy

extra sentence explaining why regs are restored before jmp

Michael Vollmer 6 rokov pred
rodič
commit
2d7984d0cb
1 zmenil súbory, kde vykonal 12 pridanie a 9 odobranie
  1. 12 9
      book.tex

+ 12 - 9
book.tex

@@ -5739,15 +5739,18 @@ For the \code{print-x86} pass, we recommend the following translations:
   (indirect-callq |\itm{arg}|) |$\Rightarrow$| callq *|\itm{arg}|
 \end{lstlisting}
 Handling \code{indirect-jmp} requires a bit more care. A
-straightforward translation of \code{indirect-jmp} would be
-\code{jmp *$\itm{arg}$}, which is what we will want to do,
-but \emph{before} this jump we need to pop the saved registers
-and reset the frame pointer. This is why it was convenient to
-ensure the \code{jmp} argument was \itm{rax}. A sufficiently
-clever compiler could determine that a function body always
-ends in a tail call, and thus avoid generating code to restore
-registers and return via \code{ret}, but for simplicity we do
-not need to do this.
+straightforward translation of \code{indirect-jmp} would be \code{jmp
+  *$\itm{arg}$}, which is what we will want to do, but \emph{before}
+this jump we need to pop the saved registers and reset the frame
+pointer. Basically, we want to restore the state of the registers to
+the point they were at when the current function was called, since we
+are about to jump to the beginning of a \emph{new} function.
+
+This is why it was convenient to ensure the \code{jmp} argument was
+\itm{rax}. A sufficiently clever compiler could determine that a
+function body always ends in a tail call, and thus avoid generating
+code to restore registers and return via \code{ret}, but for
+simplicity we do not need to do this.
 
 \margincomment{\footnotesize The reason we can't easily optimize
   this is because the details of function prologue and epilogue