isa_cmp: arm updated
[calu.git] / 1_isacmp / arm.tex
1 \section{ARM}
2
3 ARM wurde anfangs von der Firma ACORN entwickelt und steht f\"ur Advanced Risc Machine. Es existieren
4 mehrere verschiedene Versionen des Instruktionssatzes, diese Ausarbeitung gibt aber lediglich einen \"Uberblick
5 \"uber die prizipiellen Konzepte der Architektur.
6
7 \subsection{Einsatzgebiet}
8
9 Im allgemeinen wird bei ARM eine Instruktionsl\"ange von 32 Bits verwendet. Die gek\"urzte Thumb-Version verwendet lediglich 16 Bit. 
10 Es existieren 31 general-purpose Register, 16 davon k\"onnen direkt \"uber die Registeradressen in den Instruktionen adressiert werden. 
11 Die anderen Register werden verwendet um die Fehlerbehandlung zu beschleunigen. Aus diesem Grund beschreibt die ARM Architektur 
12 eine Registermaschine mit einer RISC Architektur.
13
14 Die Register R13, R14 und R15 finden besondere Verwendung. R13 ist der Stack-Pointer, R14 das Link Register und R15 der Program-Counter. 
15 Diese Register k\"onnen allerdings auch \"uber normale Instruktionen beschrieben werden. Das Link-Register beinhaltet die R\"ucksprungadresse
16 im Falle eines Subroutinen-Calls.
17
18 ARM bietet eine breite Varianz an Kernen f\"ur den Einsatz in verschiedenen Gebieten.
19 Beispielsweise ist die ARM710 Familie designed um in Hand-Helds und anderen Multimediabereichen Anwendung zu finden. 
20 Die leistungsf\"ahigere ARM10 Familie bietet eine Vector-Floating-Point Einheit. Der Cortex A8, welcher den ARMv7 Instruktionssatz
21 verwendet, betreibt das IPhone 3GS, der Nintendo DS wird auch von einem ARM angetrieben. Diverse Linux-Distributionen laufen auf leistungsf\"ahigeren ARM-Prozessoren.
22 Einem Bericht aus 2007 zufolge verwenden ca 98 Prozent der verkauften Mobiltelefone einen ARM Prozessor (Wikipedia).
23
24 %\subsection{Where are processors that implement the ISA deployed? In embedded systems (microcontrollers,
25 %communication, multimedia), in servers, in desktop computers?}
26
27 %ARM offers a big variety of cores for usage in different areas. 
28 %The ARM710 family is designed for usage in hand-helds and multimedia. The more stronger ARM10 family is providing a Vector Floating Point unit.
29 %The Cortex A8, which uses the ARMv7 ISA, powers the IPhone 3GS. Many Linux distributions work on stronger ARM processors. 
30 %Nintendo DS uses an ARM core.
31 %As of 2007, about 98 percent of the more than one billion mobile phones sold each year use at least one ARM processor (Wikipedia).
32
33
34 %\subsection{Does the ISA describe an accumulator, a register, or a stack machine and does it describe a CISC or RISC architecture?}
35
36 %Except from the Thumb-Version, the instructions have a fixed length of 32 bit and can address one destination and two
37 %operand registers at once. ARM offers 31 general-purpose registers, where at any time 16 of them can be addressed by the 
38 %register specifiers in the instructions. The other registers are used to speed up the exception processing. 
39 %So this describes a register machine with a RISC architecture. 
40
41 %Registers R13, R14 and R15 are used as the Stack Pointer (R13), the Link Register (R14) and the Program Counter (R15), 
42 %but they can be addressed via the normal instruction set. The Link Register contains the return address in case of a 
43 %sub routine call. 
44
45 \subsection{Conditional Instructions and Jumps}
46
47 Im Vergleich zu \"alteren RISC Architekturen kommt ARM ohne die Verwendung von Branch-Delay-Slots aus, somit sind Latenzen 
48 nicht am Software-Level sichtbar. Des weiteren gibt es Predicated Instructions, welche erlauben, dass die Instruktion nur 
49 im Falle eines gesetzten Pr\"adikats ausgef\"uhrt wird. ARM verwendet f\"ur nahezu jede Instruktion 4 Bits an Pr\"adikaten. Somit 
50 k\"onnen theoretisch 16 verschiedene Ausf\"uhrungsm\"oglichkeiten abgeleitet werden, es werden 15 gen\"utzt.
51 Nach dem Testen einer Bedingung (CMP) wird dieses Ergebnis im Statusregister vermerkt (zb CMP R1, R2).
52 Nun kann beispielsweise ADDEQ R0, R2, R3 und ADDNE R7, R2, R3 folgen, was folgenden Code abbildet:
53
54 \begin{lstlisting}[caption=Beispiel]{}
55
56 if R1 = R2 then
57         R0 = R2 + R3
58 else
59         R7 = R2 + R3
60 end if
61
62 \end{lstlisting}
63
64 Somit k\"onnen kleine if-Bl\"ocke auf sequenzielle Statements ohne Sprung abgebildet werden.
65 Sollte f\"ur eine Instruktion die Kondition nicht erf\"ullt sein wird diese einfach durch ein NOP ersetzt.
66
67 Ein m\"ogliches Pr\"adikat ist auch Always, somit wird keine Bedingung im Statusregister gepr\"uft.
68
69 %\subsection{Are latencies handled by the hardware or are they visible at the ISA level? For example,
70 %branch delay slots expose the latencies of branches at the ISA level.}
71
72 %Instead of older RISC Systems ARM doesn't have a branch delay slot, so latencies are not visible at the software level.
73 %Conditional instructions allow to implement small if-blocks in a fast and code-decimating way.
74
75 %\subsection{Are conditional branches (compute condition and jump) performed in a single step, or
76 %are testing and branching unbundled?}
77
78 %Every ARM Instruction as a 4-bit condition field at the beginning. The predicated instruction is only executed, when the condition
79 %fits to the bits set in the state register. In example the bit vector $(0000)_2$ means equal, $(0001)_2$ means non equal and $(11110)_2$ means always.
80 %In case the condition doesn't fit, the instruction is replaced by one NOP.
81 %To update the state register a compare instruction is needed. So you first have to test the condition and afterwards
82 %you can place as many conditional statements as needed.
83
84 \subsection{Ziele}
85
86 Da diese Architektur immer h\"aufiger in mobilen Multimediager\"aten eingesetzt wird liegen die Ziele in
87 den folgenden Bereichen: Performance, Die Area, Energy Efficiency und Code Size. Die Liste k\"onnte noch weiter
88 fortgesetzt werden, dies sind aber die wichtigsten Punkte.
89 Energieeffizient ist wichtig f\"ur lange Batterielebenszeiten bzw. das nicht vorhanden sein von diversen K\"uhleinrichtungen. 
90 Die Codesize wird durch das Verwenden von Predicated Statements und der Destination + 2 Operanden Register Adressierung pro Befehl
91 realisiert. Dieser Punkt wirkt sich auch positiv auf die Performance des Prozessors aus. Allerdings m\"ussen durch die 
92 Load/Store Architektur Variablen immer zuerst in Register geladen werden.
93
94 %\subsection{What are the goals of the architecture? Performance, die area, energy efficiency, code
95 %size, . . .  and how are these goals reflected in the ISA?}
96
97 %Because of the extensive use in mobile and multi media devices, the goals are all of the mentioned parts. 
98 %Energy efficiency plays a huge role as far as you don't have the posibility to add a cooling device to your smartphone.
99 %Code size is reflected in the ISA by using predicated instructions. The code gets much smaller when you don't need to 
100 %add a branch for every small if-else-block. The opportunity of accessing 2 operand registers in a computation instruction
101 %and the load multiple instruction are increasing the performance of the system.
102
103 \subsection{Gut gel\"ost bzw. Verbesserungsw\"urdig}
104
105 Das Verwenden von Predicated Statements ist meiner Meinung nach sehr intelligent verwirklicht, da man 
106 das Ausf\"uhren eines Befehls von einer breiten Varianz an Bedingungen abh\"angig machen kann. Außerdem 
107 ist es durch Verwendung von konditionierten Instruktionen m\"oglich eine konstante Ausf\"uhrungszeit eines Algorithmus zu erzielen.
108
109 Ein negativer Aspekt ist das Fehlen von Shift- bzw. Rotate Instruktionen. Diese werden direkt in den einzelnen Befehlen 
110 implementiert, man kann solches Verhalten auf einen Operanden einer Anweisung anwenden. Dies hat aber nat\"urlich auch seine Vorteile.
111
112 %\subsection{Which features of the ISA do you like, which features would you change?}
113
114 %The usage of the predicated statements is very genious, because this firstly smalls the code size and secondly is a very important
115 %feature for WCET. It allows you to implement algorithms having a constant execution time, what is very necessary in safety-critical and fault
116 %tolerant real time systems. 
117 %Barrel shifter (shift as part of an instruction) is great, but a single shift operation is missing.
118
119 \subsection{Implementierung des Beispielcodes}
120
121 \begin{lstlisting}[caption=ARM Code]{ARM-Code}
122
123         ; r0 = len
124         ; r1 = ptr to arr
125         ; wenn len=0 return 0
126         cmp r0, #0
127         moveq r0, 0
128         bxeq lr;
129         add r0, r1, r0, LSL#2
130         mov r2, r1
131 loop:
132         ldr r3, [r1], #4
133         add r2,r2,r3
134         cmp r1, r0
135         bne loop;
136         mov r0,r2
137         bx lr
138
139 \end{lstlisting}
140
141 Jeder Schleifendurchlauf f\"uhrt ein Load, ein Add, ein Compare und ein Branch-Equal aus.
142
143 Implementiert auf einem ARM7TDMI, dieser verwendet eine 3-Stufige Pipeline, erhalten wir folgende
144 Aussagen \"uber die Clockcycles:
145
146 ldr 3, add 1, cmp 1, bne 3, was bedeutet, dass ein Schleifendurchlauf 8 Zyklen ben\"otigt (Informationen aus dem Manual des Prozessors entnommen).
147
148 Die Anzahl der Instruktionen in der Schleife ist 4, da auch der Sprung zum 
149 Schleifenbeginn mitgez\"ahlt wird. Die Codesize der Schleife betr\"agt 16 Byte,
150 da jede Instruktion eine L\"ange von 32 Bit hat.