32-bitni mikrokontroleri i primena - MS1BMP 2. deo

  • Upload
    harmon

  • View
    61

  • Download
    2

Embed Size (px)

DESCRIPTION

32-bitni mikrokontroleri i primena - MS1BMP 2. deo. 2013 Nenad Jovičić. 3-stepena protočna obrada. Registraska banka 2 porta za čitanje, 1 za upis. D odatni portovi za čitanje i upis PC-a. Barell pomerač ALU Adresni registar sa podrškom za inkrementiranje - PowerPoint PPT Presentation

Citation preview

MS1BMP

32-bitni mikrokontroleri i primena - MS1BMP2. deo2013Nenad Jovii3-stepena protona obradaRegistraska banka2 porta za itanje, 1 za upis.Dodatni portovi za itanje i upis PC-a.Barell pomeraALUAdresni registar sa podrkom za inkrementiranjeDekoder instrukcija i kontrlna jedinica

PipelinePipeline u tri nivoa tako zvana trostepena protona obrada.Pretetch jedinica moe da unapred uita do tri 32-bitne instrukcije.Branch forwarding & speculation1st Stage - Fetch2nd Stage - Decode3rd Stage - ExecuteExecute stage branch (ALU branch & Load Store Branch)Fetch(Prefetch)AGUInstruction Decode & Register ReadBranchAddress Phase & Write BackData Phase Load/Store & BranchMultiply & DivideShiftALU & BranchWriteA prefetch unit fetches instructions in advance and can buffer up to three 32-bit instructions or six 16-bit instructions, or a combination.For direct branches (address or label vs. register), It does whats called Branch Forwarding where in decode, it can fetch both possible instructions following a conditional branch (the fall through instruction and the branch target instruction) (point to first dotted). Then in execute, the branch is resolved and if the branch is not to be taken, the next instruction is already available. If the branch is to be taken, the branch instruction is made available at the same time as the decision is made, resulting in a single idle cycle. In an ARM7, branches always flush the pipe and usually cost 3 cycles.

CM3 runs at bus speed you must fetch instructions at CPU clock speed, mostly without wait states. These two points may limit how fast you can push the CM3 in any particular process.

3PipelineFetch uitavanje instrukcije iz memorije i smetanje u prefetch bufferDecode dekodiranje instrukcije i pripremanje kontrolnih signala koij reguliu protok podatakaExecute Oitavanje registara, pomeranje operanda, generisanje rezultata operacije (ALU) i upisivanje rezultata odredini registar.

Optimalni pipelineSve instrukcije su nad registrimaEfektivno dobijamo instrukciju po ciklusu

All operations here are on registers (single cycle execution) In this example it takes 6 clock cycles to execute 6 instructions Clock cycles per Instruction (CPI) = 15Optimalni pipeline obrada podataka

Pipeline sa memorijskim prenosom

In this example it takes 7 clock cycles to execute 6 instructions Clock cycles per Instruction (CPI) = 1.2 The read cycle must complete on the bus before the LDRinstruction can complete since there is only one writeback port inthe register file7Pipeline sa memorijskim prenosom

Computes a memory address similar to a data processing instruction.Load instruction follows a similar pattern except that the data from memory only gets as far as the data inregister on the 2ndcycle and a 3rd cycle is needed to transfer the data from there to the destination register8Pipeline sa uzastopnim Load/Store instrukcijama

Store buffer allows STR instruction to finish before storecycle completes on the bus Back-to-back STR instructions pipeline on the AHB-Lite bus- Also works for LDR-STR-LDR-STR9Pipeline sa instrukcijom skoka3 ciklusa su potrebna da se zavri skok

It takes 3 cycles to complete the branchWorst case scenario indirect branch taken10Pipeline sa instrukcijom skoka

The third cycle, which is required tocomplete thepipeline refilling, is also used to mark the small correction to the value stored in the linkregister in order that is points directly at the instruction which follows the branch11Arhitektura instrukcijskog setaISA Instruction set architectureInstruction set architecture (ISA) is the structure of a computer that a machine language programmer (or a compiler) must understand to write a correct (timing independent) program for that machineIBM introducing 360 in 1964

Razvoj instrukcijskog seta

32-bitni instrukcijski set16-bitni instrukcijski setPomean 16-bitni i 32-bitni instrukcijski setPoev od ARM7TDMI procesora uvedena su dva instrukcijska seta- ARM i Thumb. ARM je bit 32-bitni, a Thumb 16-bitni. Ideja je bila da procesor moe da se prebacuje programski iz jednog moda u drugi. ARM instrukcijski set je trebalo da podri kompleksne instrukcije kakve imaju aplikativni procesori, dok je Thumb trebalo da prui jednostavnije, ali kratke i vremenski efikasne instrukcije potrebne u mikrokontrolerskim aplikacijama.Poev od v7-M arhitekture uveden je novi Thumb-2 superset koji pokriva i ne 32-bitne instrukcije, podrava stari Thumb instrukcijski set i dodaje i neke nove i 16-bitne instrkucije.v7-R i v7-A arhitektura podravaju i dalje ARM instrukcijski set.

Glavna karakteristika kod Thumb-2 instrukcijskog seta je to podrava i 32-bitne i 16-bitne instrukcije...Dakle nam switching-a nego sve ide protono...13ARM/Thumb instrukcijski setTradicionalni ARM set: fiksna duina od 32 bitaDva ili tri operandaRadi se sa podacima u registrimaMemorijske transferi se obavljaju samo kroz Load/Store instrukcijeUslovno izvravanje instrukcijaOriginalni Thumb instrukcijski set:Implemenaticija odreenih instrukcija iz ARM seta, ali sa 16 bitaVeina Thumb instrukcija ima dva operanda, tj. Jedan od izvorinih je i odredini operandNisu dostupni registri r8 do r15Nema uslovnog izvravanja

ARM coding14ARM/Thumb instrukcijski setPrimer implementacije instrukcije sabiranja na ARM i Thumb formatu:

-nema uslovnog izvravanja-nema rotacije neposrednog operanda-statusni flagovi se uvek postavljaju (nema S)15Prelaz sa ARM na Thumb i obrnutoKod ranijih ARM arhitektura prebacivanje sa jednog na drugi instrukcijski set je posedovalo znaajan overhead.

With the introduction of the Thumb-2 instruction set, it is now possible to handle all processing requirements in one operation state. There is no need to switch between the two. In fact, the Cortex-M3 does not support the ARM code. Even interrupts are now handled with the Thumb state. (Previously, the ARM core entered interrupt handlers in the ARM state.)

Zanimljive instrukcije: UFBX, BFI, and BFC: Bit field extract, insert, and clear instructions UDIV and SDIV: Unsigned and signed divide instructions WFE, WFI, and SEV: Wait-For-Event, Wait-For-Interrupts, and Send-Event; these allow the processor to enter sleep mode and to handle task synchronization on multiprocessor systems MSR and MRS: Move to special register from general-purpose register and move special register to general-purpose register; for access to the special registers

ALI, Cortex-M3 ne podrava sve instrukcije iz Thumb-2 seta. Na primer instrukcije za koprocesor nisu podrane, kao i instrukcije za Single InstructionMultiple Data (SIMD) instrukcije.Sa druge strane neke instrukcije iz starog Thumb seta nisu pdorane. Na primer instrukcije za izmenu stanja procesora (Koje su ranije koriene da se iz Thumb seta pree u ARM set).

16Thumb-2

Thumb-2 obuhvata i 16-bitne i 32-bitne instrukcije.Napravljen je sa osnovnom idejom da se izbegne potreba za izmenom reima rada procesora. Thumb-2 je zadrao skoro sve insturkcije starijeg Thumb seta i implementirao veinu instrukcija iz ARM seta.Vei deo instrukcija moe da se prevede i u 16-bitni i u 32-bitni format u zavisnosti od parametara konkretne instrukcije.Odluku o implementaciji donosi kompajler osim u sluaju kada se implicitno trai jedna ili druga implementacija.

1716-bitne Thumb-2 instrukcije

1832-bitne Thumb-2 instrukcijeAko uitana re (16 bita) sadri najviih 5 bitova sledeeg sadraja:0b111010b111100b11111instrukcija je 32-bitna, tj. Dekodira se i sledea re.

1916 ili 32 bita?Primer instrukcije ADD (sabiranje) kada se radi nad registrima.U zavisnosti od upotrbeljenih registara ili opcionih polaj u instrukciji mogue su razliite vrste kodiranja instrukcije.To se u krajnjoj liniji reflektuje na gustinu koda.

20Znaaj prefetch buffer-a

21Poreenje performansi instrukcijskih setovaInstrukcijski set promenljive duineARM instrukcije su bile iskljuivo 32-bitneThumb instrukcije su bile iskljuivo 16-bitneThumb-2 instrukcije mogu da budu i 16-bitne i 32-bitne,

Thumb-2 daje za oko 26% veu gustinu koda od ARM

Thumb-2 daje za oko 25% vee performanse u odnosu na Thumb

Relative Dhrystone performance and code size for ARM, Thumb and Thumb-2Dhrzstone test je kreiran 1984 godine i namenjen je za testiranje tj. Uporeivanje performansi u celobrojnoj airtmetici.Nasuprot njemu Whetstone je namenjen za testiranje floating-point aritmetike.

Variable-length instructionsARM instructions are a fixed length of 32 bitsThumb instructions are a fixed length of 16 bitsThumb-2 instructions can be either 16-bit or 32-bit

Thumb-2 gives approximately 26% improvement in code density over ARM

Thumb-2 gives approximately 25% improvement in performance over Thumb

22Glavni elementi arhitekture instrukcijskog seta

32-bits mov r0, #1

ld r1, [r0,#5]

mem((r0)+5)

bne loop

subs r2, #123Tipovi podatakaARM podrava tri tipa podataka:Byte 8-bitni podatakHalfword 16-bitni podatakWord 32-bitni podatakPristup memoriji kod Cortex-M3 omoguava takozvani neporavnat (unaligned) pristup.

Ali to ne vai kod nekih instrukcija. Na primer PUSH i POP rade samo aligned acces. Takoe i specijalne instrukcije za prenos blokova podataka.

24Modovi adresiranjaNeposredno adresiranje sastavni deo instrukcije je podatak, tj. konstanta.Registarsko adresiranje podatak je u nekom od registara opte namene.Indirektno registarsko adresiranje podatak je u memoriji a adresa se nalazi ili proraunava iz odgovarajueg registra opte namene.Immediate: The offset is an unsigned number that can be added to or subtracted from the base register value. Immediate offset addressing is useful for accessing data elements that are a fixed distance from the start of the data object, such as structure fields, stack offsets and input/output registers.

Register: The offset is a value from a general-purpose register. This register cannot be the PC. The value can be added to, or subtracted from, the base register value. Register offsets are useful for accessing arrays or blocks of data.

Scaled register: The offset is a general-purpose register, other than the PC, shifted by an immediate value, then added to or subtracted from the base register. This means an array index can be scaled by the size of each array element. The offset and base register can be used in three different ways to formthe memory address. The addressing modes are described as follows:Offset The offset is added to or subtracted from the base register to form the memory address.Pre-indexed The offset is added to or subtracted from the base register to form the memory address. The base register isthen updated with this new address, to permit automatic indexing through an array or memory block. Post-indexed The value of the base register alone is used as the memory address. The offset is then added to or subtracted from the base register. and this value is stored back in the base register, to permit automatic indexing through an array or memory block.25Load /store arhitekturaCortex-M3 je Load/Store arhitektura, to znai da se memoriji pristupa samo preko Load/Store instrukcija, a sve druge operacije se obavljaju samo nad registrima.

Nema neposrednog adresiranja memorijske lokacije.

26LDRx/STRx instrukcijePristup memoriji je mogu praktino jedino preko ovih instrukcija. Sve kasnije instrukcije za obradu podataka rade sa podacima koji su sastavni deo instrukcije (konstante) i podacima koji su ve u registrima.

Primeri:27LDRx/STRx instrukcijeAdresa podatka u memoriji se dobija kao kombinacija sadraja baznog registra i odgovarajueg offset-aVrednost offset-a se odreuje na sledee naine:Neposredno:Offset je zapisan neposredno u samoj instrukciji.Rigaistarsko:Offset se nalazi u offset registruSkalirano registarsko:Offset se dobija tako to se sadraj offset registra iftuje za vrednost konstante zapisane u insturkciji

Izraunati offset i bazni registar mogu na sledee naine da formiraju konanu adresu:Offset (klasini offset):Prosto dodavanje sadraja offsetnog na bazni registarPre-indexno:Adresa se dobija sabiranjem sadraja baznog registra i offset-a, ali se nakon izvrene operacije sadraj baznog registra aurira na novu vrednostPost-indexno:Adresa se dobija samo na osnovu baznog registra, ali se nakon instrukcije na sadraj baznog registra dodaje sadraj izraunatog offset-a.Kako upisati 32-bitnu konstantu u registar?

Jo bolji metod!Jo bolji nain je aseblerska sintaksa:LDR r0,=0x55555555koja generie: LDR r0,[pc, offsetto lit pool]A negde u code memoriji se nalazi oblast lit pool u kojoj se nalazi flashovana konstanta: DCD 0x55555555Instrukcije za prenos blokova podatakaInstrukcije traju vie ciklusa, ali zahvaljujui ICI polju u ESPR statusnom registru mogu da budu prekinute izuzeetkom ili prekidom.

Uslovno izvravanjeVeini instrukcija moe da se postavi dodatni uslov za izvravanje koji zavisi od Z,N,V,C flag-ovaOva mogunost je ograniena samo na instrukcije koje se nalaze u okviru takozvanih IT (If-Then blokova)Uslovna izvravanja blokova su prekidiva to se obezbeuje korienjem IT polja u statusnom registru EPSR.

32Uslovno izvravanje - primeri

Sintaksa ITx instrukcije33