diff options
-rw-r--r-- | thesis/abbr.tex | 4 | ||||
-rw-r--r-- | thesis/intro.tex | 6 | ||||
-rw-r--r-- | thesis/load-offsets.tex | 40 | ||||
-rw-r--r-- | thesis/preamble.tex | 3 | ||||
-rw-r--r-- | thesis/thesis.tex | 3 |
5 files changed, 52 insertions, 4 deletions
diff --git a/thesis/abbr.tex b/thesis/abbr.tex index d66f06a..566a62c 100644 --- a/thesis/abbr.tex +++ b/thesis/abbr.tex @@ -11,11 +11,13 @@ \item[LSB(s)] Least significant bit(s), the bit(s) with the lowest value in a word. \item[PC] - Program counter. + Program counter, \ual{r15} on ARM. \item[RTS] Run-time system. Clean's run-time system ensures that the \clean{Start} node is reduced and printed. It also takes care of garbage collecting. + \item[SP] + Stack pointer, \ual{r13} on ARM. \item[UAL] Unified Assembler Language. %todo diff --git a/thesis/intro.tex b/thesis/intro.tex index 1056d9f..a7f00e7 100644 --- a/thesis/intro.tex +++ b/thesis/intro.tex @@ -313,8 +313,10 @@ In much of the rest of this thesis we discuss differences between ARM and Thumb, In \cref{sec:storing-pc}, we consider an issue arising from halfword-aligned instructions and the way a read of PC is interpreted under Thumb. \Cref{sec:code-addresses} discusses problems related to the fact that Thumb instruction addresses use bit 1 and should have bit 0 set for interworking, while under ARM a branch will automatically clear both these bits. +There was a minor problem with negative offsets to the \ual{ldr} instruction, + that cannot be as large in Thumb as they can in ARM. +\Cref{sec:load-offsets} deals with this. -The Thumb backend for Clean has been benchmarked. -The results are collected and discussed in \cref{sec:results}. +We benchmark the Thumb backend for Clean and discuss the results in \cref{sec:results}. \end{multicols} diff --git a/thesis/load-offsets.tex b/thesis/load-offsets.tex new file mode 100644 index 0000000..bfd09ef --- /dev/null +++ b/thesis/load-offsets.tex @@ -0,0 +1,40 @@ +\section{Reduced offset space for memory load instructions} +\label{sec:load-offsets} + +\begin{multicols}{2} + +\subsection{Introduction} +\label{sec:load-offsets:intro} +The \ual{LDR} (immediate) instruction loads a word from memory into a register. +The address is specified by a base register and an offset + (which can possibly be added to the base register before or after the load). +On ARM, this offset is encoded in twelve bits, and one bit is used for its sign. +That allows for any offset between $-4095$ and $4095$ bytes. +For details, see \cite[A8.8.63]{armv7ar}. + +The Thumb instruction set defines four different variants of the immediate \ual{LDR} instruction~\parencite[6.7.42]{armv7m}: + +\begin{itemize}[itemsep=0pt] + \item + 16-bits, any base register, a 5-bit positive offset. + \item + 16-bits, SP as base, a 8-bit positive offset. + \item + 32-bits, any base register, a 12-bit positive offset. + \item + 32-bits, any base register, a 8-bit negative offset. +\end{itemize} + +While in some cases a narrow \ual{LDR} instructions can be used in Thumb, + some uses in ARM cannot be used directly in Thumb: + the offset can now only be between $-255$ and $4095$ bytes. + +\subsection{Usage in Clean} +\label{sec:load-offsets:clean} +For most Clean programs, the generated code will not attempt to load memory with large negative offsets. +However, it can occur when a function has to look far down the A-stack. +In practice, this happens when a function has a high arity or many complex expressions in its right hand side. + +\todo{rest} + +\end{multicols} diff --git a/thesis/preamble.tex b/thesis/preamble.tex index ae16a89..342cf02 100644 --- a/thesis/preamble.tex +++ b/thesis/preamble.tex @@ -1,7 +1,7 @@ \documentclass[a4paper,twoside]{article} \newif\ifdraft -\drafttrue +\draftfalse \ifdraft \usepackage[inner=2cm,outer=2cm,top=2cm,bottom=25mm]{geometry} @@ -16,6 +16,7 @@ \usepackage[british]{babel} \usepackage[babel=true]{csquotes} +\usepackage{enumitem} \usepackage[usenames,dvipsnames,svgnames,table]{xcolor} \definecolor{linkcolor}{rgb}{0,0.65,0} diff --git a/thesis/thesis.tex b/thesis/thesis.tex index 9bcd318..9cc6482 100644 --- a/thesis/thesis.tex +++ b/thesis/thesis.tex @@ -26,6 +26,8 @@ The Thumb-2 instruction set combines the best features of the ARM and Thumb inst We discuss the differences between the ARM and Thumb-2 instruction sets, and their influences on code generation. Specifically, we look at code generation for the purely functional programming language Clean. +The code generator proposed here can be used in situations where small code size is important, + and on devices where the ARM instruction set is not available, like the Cortex-M series. \todo{results, efficiency, etc.} \end{abstract} @@ -49,6 +51,7 @@ Specifically, we look at code generation for the purely functional programming l \input{intro} \input{storing-pc} \input{code-addresses} +\input{load-offsets} \input{results} \ifdraft\else |