Real Time Embedded Systems "System On Programmable Chip" - - PowerPoint PPT Presentation

real time embedded systems
SMART_READER_LITE
LIVE PREVIEW

Real Time Embedded Systems "System On Programmable Chip" - - PowerPoint PPT Presentation

Real Time Embedded Systems "System On Programmable Chip" NIOSII Custom Instruction rene.beuchat@epfl.ch LAP/ISIM/IC/EPFL Charg de cours rene.beuchat@hesge.ch LSN/hepia Prof. HES 1 RB - 2011 Contents Introduction Custom


slide-1
SLIDE 1

rene.beuchat@epfl.ch LAP/ISIM/IC/EPFL Chargé de cours rene.beuchat@hesge.ch LSN/hepia

  • Prof. HES

RB - 2011 1

Real Time Embedded Systems

"System On Programmable Chip" NIOSII Custom Instruction

slide-2
SLIDE 2

Contents

  • Introduction
  • Custom Instructions on NIOS II
  • Hardware
  • Software access from C

References :

  • http://www.altera.com/literature/ug/ug_nios2_custom_instruction.pdf

(NIOS II Custom Instruction, User Guide, Altera January 2011)

3 RB - 2011

slide-3
SLIDE 3

Introduction A processor has an initial Instruction Set Architecture defined by the processor design architect. The instruction set is done to be the more efficient in general cases but not for special cases. Processors as DSP (Digital Signal Processor) have specialized instructions and not good for general purpose applications. With softcore processor, it’s possible to add instructions on the basic set available.

4 RB - 2011

slide-4
SLIDE 4

Introduction If the result is correct and enough fast, it's nice. Some times it is necessary to accelerate the calculus time. Optimization is some time possible:

  • Rewriting part of the code more efficiently
  • Writing some part in assembly language
  • Using a better processor or system
  • Using specialize (co)processor
  • Using multiprocessors
  •  Transfer part of the code in hardware in an

accelerator i.e. in a FPGA

5 RB - 2011

slide-5
SLIDE 5

Custom Instruction in FPGA

  • In parallel to the

normal ALU, custom logic can be added

6 RB - 2011

slide-6
SLIDE 6

Instruction implementation The instruction can be:

  • Combinational
  • Multi-cycle
  • Extended (until 256

instructions)

  • With internal Register

File

  • With external acces

7 RB - 2011

slide-7
SLIDE 7

Combinatorial Instruction

8 RB - 2011

  • 2 * 32 bits data, 32 bits result
  • 1 clock cycle to resolve
slide-8
SLIDE 8

Multi-cycle Instruction

9 RB - 2011

  • 2 * 32 bits data, 32 bits result
  • n clock cycle to resolve
  • start – done handshake
slide-9
SLIDE 9

Multi-cycle Instruction

10 RB - 2011

slide-10
SLIDE 10

Extended instructions

11 RB - 2011

  • More than 1 instruction in the bloc
  • Use a power of 2 instruction space (1, 2, 4, 8, …256)
  • n[ … ] signals added for instruction index
slide-11
SLIDE 11

Internal Register File

12 RB - 2011

  • Internal registers  until 32
  • 2 sources registers (Ra, Rb)
  • 1 destination register (Rc)
  • Can be mixed with Dataa, Datab or Datac 32 bits data bus
slide-12
SLIDE 12

Internal Register File

13 RB - 2011

  • Example of mixed data selection
  • dataa, datab and Rc
slide-13
SLIDE 13

External interface

14 RB - 2011

  • External access allowed for multi-cycle access
  • Available with internal register file too
slide-14
SLIDE 14

Custom Instruction

15 RB - 2011

  • Access done in C with macro defined
  • Use extension of gcc
  • Instruction: __builtin_custom_oni1i2 (instr num, input 1, input 2)
  • Types of o i1 i2:
  • i

integer

  • f

float

  • p

void *

slide-15
SLIDE 15

Custom Instruction

16 RB - 2011

  • Example:
  • void *__builtin_custom_pnif (int n, int dataa, float datab);
  • pnif :
  • p
  • utput:

void *

  • n

separator

  • i

input 1: integer

  • f

input 2: float (32 bits)

  • All 3 parameters o i1 i2 are optional

void __builtin_custom_nf (int n, float dataa); float __builtin_custom_fnpi (int n, void * dataa, int datab);

slide-16
SLIDE 16

Custom instruction example of use

  • 2 instructions defined :

17 RB - 2011

slide-17
SLIDE 17

Assembly language definition

  • Custom opcode : 0x32

18 RB - 2011

slide-18
SLIDE 18

Instruction assembly syntax

  • Assembly syntaxe:
  • custom N, xC, xA, xB
  • N:

instruction number from system.h

  • x:

r NIOS II register through dataa, datab and result

readra, rb, rc at 1

  • x:

c Custom register file through a[], b[], c[] selection

readra, rb, rc at 0

19 RB - 2011

slide-19
SLIDE 19

Implementation

  • Implementation in HDL (VHDL or Verilog)

through SOPC Builder

20 RB - 2011

slide-20
SLIDE 20

Exercise

  • To test the capabilities of software vs

hardware implementation, design a NIOSII system to realize the basic function of bits mirror and swap:

  • A 32 bits input a31..a0
  • A 32 bits output result o31..o0
  • a31.. a24

 o7 .. o0

byte position change

  • a7 .. a0

 o31 .. o24

  • a23 .. a8

 o8 .. o23

bits order change !

21 RB - 2011

slide-21
SLIDE 21

Exercise

  • This function can be done for a single

variable

  • This function can be done in a table of 1 to

thousand of long data

  • Do this function in C
  • Implement it as a custom instruction
  • Implement it in an accelerator module
  • Implement it with the help of C2H
  • Measure the performance in all cases

22 RB - 2011