Salta al contenuto
Note per Studenti Formulario · Microcontrollers and DSP Report

FormularioMicrocontrollers and DSP: definizioni, teoremi e formule delle note, in ordine di capitolo

In questa pagina 7

I. Processor Structure

Fetch-Execute Cycle and Datapath

Formula (single-cycle clock period). Every instruction takes one clock cycle; the period must fit the slowest instruction. With delays memory 200 ps, register file 100 ps, ALU 200 ps:

Instruction Instr. mem. Reg. read ALU Data mem. Reg. write Total
arithmetic 200 100 200 — 100 600 ps
load 200 100 200 200 100 800 ps
store 200 100 200 200 — 700 ps
branch 200 100 200 — — 500 ps

Period = 800 ps (1.25 GHz) for all instructions. Separate instruction and data memories and several adders are needed, since each unit can be used once per cycle.

II. Arithmetic-Logic Unit Circuits

Adders

Formula (full adder). S=A⊕B⊕Cin,Cout=AB+BCin+ACin=AB+Cin(A⊕B).S=A\oplus B\oplus C_{in},\qquad C_{out}=AB+BC_{in}+AC_{in}=AB+C_{in}(A\oplus B).

Formula (ripple-carry delay, worst case). NN full adders in cascade, Cout,i=Cin,i+1C_{out,i}=C_{in,i+1}. With tct_c the carry delay (Cin→CoutC_{in}\to C_{out}) and tst_s the sum delay (Cin→SC_{in}\to S) of one full adder, and Cin,0=0C_{in,0}=0: in the worst case (all P=1P=1, the carry crosses all stages) the last bit waits N−1N-1 carry delays: tadd=(N−1) tc+ts(linear in N),\boxed{t_{add}=(N-1)\,t_c+t_s}\qquad(\text{linear in }N), and tadd=tsetup+(N−1)tc+tst_{add}=t_{setup}+(N-1)t_c+t_s if set-up is counted.

Formula (carry-bypass delay and optimal block size). Worst case: the carry is generated at the first stage of the first block and crosses it (M tcarryM\,t_{carry}), skips the following blocks through N/M−1N/M-1 multiplexers, then crosses M−1M-1 stages of the last block: tadd=tsetup+M tcarry+(NM−1)tmux+(M−1) tcarry+tsum,Mopt=N tmux2 tcarry.t_{add}=t_{setup}+M\,t_{carry}+\Big(\frac NM-1\Big)t_{mux}+(M-1)\,t_{carry}+t_{sum},\qquad M_{opt}=\sqrt{\frac{N\,t_{mux}}{2\,t_{carry}}}.

Formula (linear carry-select). Blocks of MM bits, N/MN/M blocks: tadd=tsetup+M tcarry+NM tmux+tsum,Mopt=N tmuxtcarry.t_{add}=t_{setup}+M\,t_{carry}+\frac NM\,t_{mux}+t_{sum},\qquad M_{opt}=\sqrt{\frac{N\,t_{mux}}{t_{carry}}}.

Formula (square-root carry-select). N=∑j=0K−1(M+j)≈K22⇒K≈2N,tadd≈tsetup+M tcarry+2N tmux+tsum.N=\sum_{j=0}^{K-1}(M+j)\approx\frac{K^2}2\Rightarrow K\approx\sqrt{2N},\qquad t_{add}\approx t_{setup}+M\,t_{carry}+\sqrt{2N}\,t_{mux}+t_{sum}.

Shift Registers, Shifters and Multipliers

Formula (array multiplier: cells and delay). N2N^2 AND gates generate the partial products and a matrix of N(N−1)N(N-1) full adders sums the rows (the carry of each row propagates to the next). For N=4N=4: 1616 AND gates and 1212 full adders. The critical path crosses about 2N2N cells: tmult≈(2N−2) tcarry+tsum,t_{mult}\approx(2N-2)\,t_{carry}+t_{sum}, linear in NN with area O(N2)O(N^2).

Arithmetic Logic Unit

Formula (magnitude comparator). Compare bits from the most significant: A>BA>B if at the first differing bit Ai=1A_i=1, Bi=0B_i=0. With gi=AiBi‾g_i=A_i\overline{B_i}: GT=gN−1+eN−1(gN−2+eN−2(gN−3+… )),EQ=∏ei.GT=g_{N-1}+e_{N-1}\big(g_{N-2}+e_{N-2}(g_{N-3}+\dots)\big),\qquad EQ=\prod e_i.

III. Control and Instruction Set

Instruction Formats and Addressing Modes

Formula (scaled index). The factor s∈{1,2,4,8}s\in\{1,2,4,8\} steps uniformly through arrays of bytes, halfwords, words, doublewords. In ARM LDR r0, [r1, r2, LSL #2] reads element r2 of a word array starting at r1.

IV. Arithmetic

Binary Arithmetic

Formula (subtraction). a−b=a+(−b)a-b=a+(-b): compute the opposite of bb (invert the bits, add 1; see Signed Integer RepresentationsSigned integers on n bits: sign-magnitude, one's complement, two's complement and excess K, with representable ranges, computing the opposite, sign extension and a 4-bit comparison table.Signed Integer Representations →) and add. In hardware: invert the bits of bb and set the adder carry in to 1, so no subtractor is needed.

Fixed-Point and Floating-Point Numbers

Formula (value of an IEEE 754 number). x=(−1)S⋅1.M⋅2 E−biasx=(-1)^S\cdot1.M\cdot2^{\,E-\text{bias}}

Format Bits Sign SS Exponent EE Mantissa MM Bias Decimal digits
single precision 32 1 8 23 127 about 7
double precision 64 1 11 52 1023 about 16

Formula (largest and smallest normalized, spacing).

  • Largest normalized: (2−2−23)⋅2127≈3.4⋅1038(2-2^{-23})\cdot2^{127}\approx3.4\cdot10^{38}.
  • Smallest positive normalized: 2−126≈1.18⋅10−382^{-126}\approx1.18\cdot10^{-38} (pattern 0080000016\mathrm{00800000}_{16}).
  • Spacing of consecutive floats with exponent ee: 2e−232^{e-23}. Near 1 it is 2−23≈1.2⋅10−72^{-23}\approx1.2\cdot10^{-7} (machine epsilondistance between 1 and the next float); near 224≈1.7⋅1072^{24}\approx1.7\cdot10^7 it is 2: from there on not all integers are representable.

V. ARM Core and Programming

Arrays, Strings and Structures in ARM Assembly

Formula (address of an array element). An array of nn elements of ss bytes occupies n⋅sn \cdot s consecutive bytes. Element ii is at address

base+i⋅s\text{base} + i \cdot s

Formula (address of a matrix element, row-major). A matrix int m[R][C] is stored by rows: element (i,j)(i, j) is at

base+(i⋅C+j)⋅4\text{base} + (i \cdot C + j) \cdot 4

VI. Memory

Memory Hierarchy and Locality

Formula (average access time with a cache). If a miss costs the cache access plus the memory access:

Tavg=h⋅T1+(1−h)(T1+T2)=T1+(1−h) T2T_{avg} = h \cdot T_1 + (1 - h)(T_1 + T_2) = T_1 + (1 - h)\,T_2

Formula (average time with two cache levels). With two cache levels: Tavg=TL1+mL1 (TL2+mL2 Tmem)T_{avg} = T_{L1} + m_{L1}\,(T_{L2} + m_{L2}\,T_{mem}), where mm are the local miss rates.

Cache Memory

Formula (direct mapping). Each block can go into one line only:

line=(block address) mod m\text{line} = (\text{block address}) \bmod m

Address fields, from the most significant: tag, line (log⁡2m\log_2 m bits), word (ww bits).

Formula (set-associative mapping with nn ways). The mm lines are divided into v=m/nv = m/n sets of nn lines. A block goes into a fixed set, in any line of the set:

set=(block address) mod v\text{set} = (\text{block address}) \bmod v

Address fields: tag, set (log⁡2v\log_2 v bits), word.

Formula (address fields of a cache). With capacity CC, line (= block) of KK bytes, nn ways and byte-addressed memory:

lines=CK,sets=linesn,word=log⁡2K,set field=log⁡2(sets),tag=address bits−set field−word.\text{lines} = \frac{C}{K}, \quad \text{sets} = \frac{\text{lines}}{n}, \quad \text{word} = \log_2 K, \quad \text{set field} = \log_2(\text{sets}), \quad \text{tag} = \text{address bits} - \text{set field} - \text{word}.

External Memory - Disks, RAID and Optical Storage

Formula (disk capacity). Capacity = surfaces x tracks per surface x sectors per track x bytes per sector.

Formula (disk access time)

Taccess=Tseek+Tlatency+TtransferT_{access} = T_{seek} + T_{latency} + T_{transfer}

  • Positioning (seek): moving the head onto the track; a datum of the disk (average value).
  • Rotational latency: waiting for the sector to pass under the head; on average half a revolution: Tlatency=12⋅60revolutions per minute⋅1000 msT_{latency} = \frac{1}{2} \cdot \frac{60}{\text{revolutions per minute}} \cdot 1000 \ \text{ms}
  • Transfer of DD bytes on a track of NN bytes (fraction of a revolution): Ttransfer=DN⋅TrevT_{transfer} = \frac{D}{N} \cdot T_{rev}

VII. Peripherals and Interrupts

Direct Memory Access

Formula (interrupts versus DMA). Transferring 4 KB in 4-byte words = 1024 words.

  • Interrupt: 1024 interrupts; if each costs 200 cycles between context saving, routine and return, about 205 000 CPU cycles.
  • DMA: initial programming (for example 100 cycles) + one final interrupt (200 cycles) is about 300 CPU cycles, plus any cycles taken on the bus.