Presentation is loading. Please wait.

Presentation is loading. Please wait.

32-bitni mikrokontroleri i primena - MS1BMP 2. deo

Similar presentations


Presentation on theme: "32-bitni mikrokontroleri i primena - MS1BMP 2. deo"— Presentation transcript:

1 32-bitni mikrokontroleri i primena - MS1BMP 2. deo
2013 Nenad Jovičić

2 3-stepena protočna obrada
Registraska banka 2 porta za čitanje, 1 za upis. Dodatni portovi za čitanje i upis PC-a. Barell pomerač ALU Adresni registar sa podrškom za inkrementiranje Dekoder instrukcija i kontrlna jedinica

3 Pipeline Pipeline u tri nivoa – tako zvana trostepena protočna obrada.
Pretetch jedinica može da unapred učita do tri 32-bitne instrukcije. Branch forwarding & speculation 1st Stage - Fetch 2nd Stage - Decode 3rd Stage - Execute Execute stage branch (ALU branch & Load Store Branch) Fetch (Prefetch) AGU Instruction Decode & Register Read Branch Address Phase & Write Back Data Phase Load/Store & Branch Multiply & Divide Shift ALU & Branch Write A 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 what’s 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.

4 Pipeline Fetch – učitavanje instrukcije iz memorije i smeštanje u prefetch buffer Decode – dekodiranje instrukcije i pripremanje kontrolnih signala koij regulišu protok podataka Execute – Očitavanje registara, pomeranje operanda, generisanje rezultata operacije (ALU) i upisivanje rezultata odredišni registar.

5 Optimalni pipeline Sve instrukcije su nad registrima
Efektivno 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) = 1

6 Optimalni pipeline – obrada podataka

7 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 LDR instruction can complete since there is only one writeback port in the register file

8 Pipeline 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 in’register on the 2ndcycle and a 3rd cycle is needed to transfer the data from there to the destination register

9 Pipeline sa uzastopnim Load/Store instrukcijama
 Store buffer allows STR instruction to finish before store cycle completes on the bus  Back-to-back STR instructions pipeline on the AHB-Lite bus - Also works for LDR-STR-LDR-STR

10 Pipeline sa instrukcijom skoka
3 ciklusa su potrebna da se završi skok It takes 3 cycles to complete the branch Worst case scenario – indirect branch taken

11 Pipeline 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 branch

12 Arhitektura instrukcijskog seta ISA Instruction set architecture
“Instruction 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 machine” IBM introducing 360 in 1964

13 Razvoj instrukcijskog seta
32-bitni instrukcijski set Pomešan 16-bitni i 32-bitni instrukcijski set Počev 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 može da se prebacuje programski iz jednog moda u drugi. ARM instrukcijski set je trebalo da podrži kompleksne instrukcije kakve imaju aplikativni procesori, dok je Thumb trebalo da pruži jednostavnije, ali kratke i vremenski efikasne instrukcije potrebne u mikrokontrolerskim aplikacijama. Počev od v7-M arhitekture uveden je novi Thumb-2 superset koji pokriva i ne 32-bitne instrukcije, podržava stari Thumb instrukcijski set i dodaje i neke nove i 16-bitne instrkucije. v7-R i v7-A arhitektura podržavaju i dalje ARM instrukcijski set. Glavna karakteristika kod Thumb-2 instrukcijskog seta je što podržava i 32-bitne i 16-bitne instrukcije...Dakle nam switching-a nego sve ide protočno... 16-bitni instrukcijski set

14 ARM/Thumb instrukcijski set
Tradicionalni ARM set: fiksna dužina od 32 bita Dva ili tri operanda Radi se sa podacima u registrima Memorijske transferi se obavljaju samo kroz Load/Store instrukcije Uslovno izvršavanje instrukcija Originalni Thumb instrukcijski set: Implemenaticija određenih instrukcija iz ARM seta, ali sa 16 bita Većina Thumb instrukcija ima dva operanda, tj. Jedan od izvorišnih je i odredišni operand Nisu dostupni registri r8 do r15 Nema uslovnog izvršavanja ARM coding

15 ARM/Thumb instrukcijski set
Primer implementacije instrukcije sabiranja na ARM i Thumb formatu: -nema uslovnog izvršavanja -nema rotacije neposrednog operanda -statusni flagovi se uvek postavljaju (nema S)

16 Prelaz sa ARM na Thumb i obrnuto
Kod ranijih ARM arhitektura prebacivanje sa jednog na drugi instrukcijski set je posedovalo značajan 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 podržava sve instrukcije iz Thumb-2 seta. Na primer instrukcije za koprocesor nisu podržane, kao i instrukcije za Single Instruction–Multiple Data (SIMD) instrukcije. Sa druge strane neke instrukcije iz starog Thumb seta nisu pdoržane. Na primer instrukcije za izmenu stanja procesora (Koje su ranije korišćene da se iz Thumb seta pređe u ARM set).

17 Thumb-2 Thumb-2 obuhvata i 16-bitne i 32-bitne instrukcije.
Napravljen je sa osnovnom idejom da se izbegne potreba za izmenom režima rada procesora. Thumb-2 je zadržao skoro sve insturkcije starijeg Thumb seta i implementirao većinu instrukcija iz ARM seta. Veći deo instrukcija može 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 slučaju kada se implicitno traži jedna ili druga implementacija.

18 16-bitne Thumb-2 instrukcije

19 32-bitne Thumb-2 instrukcije
Ako učitana reč (16 bita) sadrži najviših 5 bitova sledećeg sadržaja: 0b11101 0b11110 0b11111 instrukcija je 32-bitna, tj. Dekodira se i sledeća reč.

20 16 ili 32 bita? Primer instrukcije ADD (sabiranje) kada se radi nad registrima. U zavisnosti od upotrbeljenih registara ili opcionih polaj u instrukciji moguće su različite vrste kodiranja instrukcije. To se u krajnjoj liniji reflektuje na gustinu koda.

21 Značaj prefetch buffer-a

22 Poređenje performansi instrukcijskih setova
Instrukcijski set promenljive dužine ARM instrukcije su bile isključivo 32-bitne Thumb instrukcije su bile isključivo 16-bitne Thumb-2 instrukcije mogu da budu i 16-bitne i 32-bitne, Thumb-2 daje za oko 26% veću gustinu koda od ARM Thumb-2 daje za oko 25% veće performanse u odnosu na Thumb Relative Dhrystone performance and code size for ARM, Thumb and Thumb-2 Dhrzstone test je kreiran 1984 godine i namenjen je za testiranje tj. Upoređivanje performansi u celobrojnoj airtmetici. Nasuprot njemu Whetstone je namenjen za testiranje floating-point aritmetike. Variable-length instructions ARM instructions are a fixed length of 32 bits Thumb instructions are a fixed length of 16 bits Thumb-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

23 Glavni elementi arhitekture instrukcijskog seta
32-bits mov r0, #1 ld r1, [r0,#5] mem((r0)+5) bne loop subs r2, #1

24 Tipovi podataka ARM podržava tri tipa podataka:
Byte – 8-bitni podatak Halfword – 16-bitni podatak Word – 32-bitni podatak Pristup memoriji kod Cortex-M3 omogućava takozvani neporavnat (unaligned) pristup. Ali to ne važi kod nekih instrukcija. Na primer PUSH i POP rade samo aligned acces. Takođe i specijalne instrukcije za prenos blokova podataka.

25 Modovi adresiranja Neposredno adresiranje – sastavni deo instrukcije je podatak, tj. konstanta. Registarsko adresiranje – podatak je u nekom od registara opšte namene. Indirektno registarsko adresiranje – podatak je u memoriji a adresa se nalazi ili proračunava iz odgovarajućeg registra opšte 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.

26 Load /store arhitektura
Cortex-M3 je Load/Store arhitektura, što znači da se memoriji pristupa samo preko Load/Store instrukcija, a sve druge operacije se obavljaju samo nad registrima. Nema neposrednog adresiranja memorijske lokacije.

27 LDRx/STRx instrukcije
Pristup memoriji je moguć praktično 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:

28 LDRx/STRx instrukcije
Adresa podatka u memoriji se dobija kao kombinacija sadržaja baznog registra i odgovarajućeg offset-a Vrednost offset-a se određuje na sledeće načine: Neposredno: Offset je zapisan neposredno u samoj instrukciji. Rigaistarsko: Offset se nalazi u offset registru Skalirano registarsko: Offset se dobija tako što se sadržaj offset registra šiftuje za vrednost konstante zapisane u insturkciji Izračunati offset i bazni registar mogu na sledeće načine da formiraju konačnu adresu: Offset (klasični offset): Prosto dodavanje sadržaja offsetnog na bazni registar Pre-indexno: Adresa se dobija sabiranjem sadržaja baznog registra i offset-a, ali se nakon izvršene operacije sadržaj baznog registra ažurira na novu vrednost Post-indexno: Adresa se dobija samo na osnovu baznog registra, ali se nakon instrukcije na sadržaj baznog registra dodaje sadržaj izračunatog offset-a.

29 Kako upisati 32-bitnu konstantu u registar?

30 Još bolji metod! Još bolji način je aseblerska sintaksa:
LDR r0,=0x koja generiše: LDR r0,[pc, offsetto lit pool] A negde u code memoriji se nalazi oblast lit pool u kojoj se nalazi flashovana konstanta: DCD 0x

31 Instrukcije za prenos blokova podataka
Instrukcije traju više ciklusa, ali zahvaljujući ICI polju u ESPR statusnom registru mogu da budu prekinute izuzeetkom ili prekidom.

32 Uslovno izvršavanje Većini instrukcija može da se postavi dodatni uslov za izvršavanje koji zavisi od Z,N,V,C flag-ova Ova mogućnost je ograničena samo na instrukcije koje se nalaze u okviru takozvanih IT (If-Then blokova) Uslovna izvršavanja blokova su prekidiva što se obezbeđuje korišćenjem IT polja u statusnom registru EPSR.

33 Uslovno izvršavanje - primeri
Sintaksa ITx instrukcije


Download ppt "32-bitni mikrokontroleri i primena - MS1BMP 2. deo"

Similar presentations


Ads by Google