浏览代码

update select instr for R6

Jeremy Siek 4 年之前
父节点
当前提交
2b1c6408c7
共有 1 个文件被更改,包括 33 次插入20 次删除
  1. 33 20
      book.tex

+ 33 - 20
book.tex

@@ -10733,33 +10733,46 @@ C_4 & ::= & \gray{ \PROGRAMDEFS{\itm{info}}{\LP\Def\ldots\RP} }
 \section{Select Instructions}
 \label{sec:select-r6}
 
-% TODO: talk about vector-ref and vector-set! -Jeremy
+\paragraph{Vector-ref}
 
-%% Recall instruction selection for `vector-ref`:
-
-%%     (Assign lhs (Prim 'vector-ref (list evec (Int n))))
-%%     ===>
-%%     movq evec', %r11
-%%     movq offset(%r11), lhs'
+Recall that instruction selection for \code{vector-ref} in
+Section~\ref{sec:select-instructions-gc} depends on knowing the index $n$
+at compile time:
+\begin{lstlisting}
+(Assign |$\itm{lhs}$| (Prim 'vector-ref (list |$\itm{vec}$| (Int |$n$|))))
+|$\Longrightarrow$|
+movq |$\itm{vec}'$|, %r11
+movq |$\itm{offset}$|(%r11), |$\itm{lhs'}$|
+\end{lstlisting}
+where $\itm{offset} = 8(n+1)$.
+%
+In $R_6$ the index may be an arbitrary expression so instead of
+computing the offset at compile time, instructions need to be
+generated to compute the offset at runtime as follows. Note the use of
+the new instruction \code{imulq}.
+\begin{center}
+\begin{minipage}{0.96\textwidth}
+\begin{lstlisting}
+(Assign |$\itm{lhs}$| (Prim 'vector-ref (list |$\itm{vec}$| |$e$|)))
+|$\Longrightarrow$|
+movq |$e'$|, %r11
+addq $1, %r11
+imulq $8, %r11
+addq |$\itm{vec'}$|, %r11
+movq 0(%r11) |$\itm{lhs'}$|
+\end{lstlisting}
+\end{minipage}
+\end{center}
 
-%%     where offset is 8(n+1)
+\paragraph{Vector-set!}
 
-%% If the index is not of the form `(Int i)`, but an arbitrary
-%% expression, then instead of computing the offset `8(n+1)` at compile
-%% time, you can generate the following instructions. Note the use of the
-%% new instruction `imulq`.
+The same issue discussed above for \code{vector-ref} also applies to
+\code{vector-set!}.  The index may be an arbitrary expression so one
+must generate instructions to compute the offset at runtime.
 
-%%     (Assign lhs (Prim 'vector-ref (list evec en)))
-%%     ===>
-%%     movq en', %r11
-%%     addq $1, %r11
-%%     imulq $8, %r11
-%%     addq evec', %r11
-%%     movq 0(%r11) lhs'
 
 %% The same idea applies to `vector-set!`.
 
-
 \paragraph{Make-any}
 
 We recommend compiling the \key{make-any} primitive as follows if the