24
TSEA44: Computer hardware – a system on a chip Lecture 8: Memories, lab4 Today Memories/memory controller Lab4, new instrucon 2016-11-30 2 TSEA44: Computer hardware – a system on a chip 2016-11-30 20:47

TSEA44: Computer hardware – a system on a chip · Refresh cycle TSEA44: Computer hardware – a system on a chip 2016-11-30 27 Start of refresh cycle Start of WB cycle Lab 4, Custom

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: TSEA44: Computer hardware – a system on a chip · Refresh cycle TSEA44: Computer hardware – a system on a chip 2016-11-30 27 Start of refresh cycle Start of WB cycle Lab 4, Custom

TSEA44: Computer hardware – a system on a chipLecture 8: Memories, lab4

Today● Memories/memory controller● Lab4, new instruction

2016-11-30 2TSEA44: Computer hardware – a system on a chip

2016-11-30 20:47

Page 2: TSEA44: Computer hardware – a system on a chip · Refresh cycle TSEA44: Computer hardware – a system on a chip 2016-11-30 27 Start of refresh cycle Start of WB cycle Lab 4, Custom

Practical info● Lab closed after 22/12

– Opens again after new year (probably after 2/1-17)– Ask me or Erik to let you in (if we are at the work)– Remote login still works

● Office corridors locked during christmas/new year– Hard to get access to people (if they are not on

vacation)● Lab used for other courses in the spring

– No access guaranteed after the course end– Will try to set up some limited access location

● Probably a lab location with limited access only on non-scheduled hours

2016-11-30 3TSEA44: Computer hardware – a system on a chip

PKMC2016-11-30 4TSEA44: Computer hardware – a system on a chip

Per KarlströmsMemory Controller

adrdat_odat_i

stb

ack

dat_io

adr

cs_sdramcs_sramcs_flash

Wishbone bus Memory bus

2016-11-30 20:47

Page 3: TSEA44: Computer hardware – a system on a chip · Refresh cycle TSEA44: Computer hardware – a system on a chip 2016-11-30 27 Start of refresh cycle Start of WB cycle Lab 4, Custom

Memory on board2016-11-30 5TSEA44: Computer hardware – a system on a chip

Memory on board, cont.2016-11-30 6TSEA44: Computer hardware – a system on a chip

2016-11-30 20:47

Page 4: TSEA44: Computer hardware – a system on a chip · Refresh cycle TSEA44: Computer hardware – a system on a chip 2016-11-30 27 Start of refresh cycle Start of WB cycle Lab 4, Custom

SRAM; Static RAM● Asynchronous device● Memory element: latch● 2 x (256k x 16) = 1 MB

* = active low

2016-11-30 7TSEA44: Computer hardware – a system on a chip

SRAM

data

oe*

ce*

address

16

18

we*

SRAM - Cell2016-11-30 8TSEA44: Computer hardware – a system on a chip

[email protected] 8

2016-11-30 20:47

Page 5: TSEA44: Computer hardware – a system on a chip · Refresh cycle TSEA44: Computer hardware – a system on a chip 2016-11-30 27 Start of refresh cycle Start of WB cycle Lab 4, Custom

SRAM - Read● WL=0,

Prechargebitlines to Vdd/2

● WL=1connectsinvertersto bitlines

● Bitlines aredriven to lowand high

2016-11-30 9TSEA44: Computer hardware – a system on a chip

[email protected]

01

011/2

10

1/2

SRAM - Read● No clocking!

2016-11-30 10TSEA44: Computer hardware – a system on a chip

2016-11-30 20:47

Page 6: TSEA44: Computer hardware – a system on a chip · Refresh cycle TSEA44: Computer hardware – a system on a chip 2016-11-30 27 Start of refresh cycle Start of WB cycle Lab 4, Custom

SRAM - Write● WL=0,

Set logic valueson bitlines

● WL=1connectsinvertersto bitlines

● Bitline valuesoverride internalvalue

2016-11-30 11TSEA44: Computer hardware – a system on a chip

[email protected]

01

0 1

10

0 1

SRAM - Write● Timing important (avoid writing to wrong adress)

2016-11-30 12TSEA44: Computer hardware – a system on a chip

2016-11-30 20:47

Page 7: TSEA44: Computer hardware – a system on a chip · Refresh cycle TSEA44: Computer hardware – a system on a chip 2016-11-30 27 Start of refresh cycle Start of WB cycle Lab 4, Custom

SDRAM; Synchronous Dynamic RAM● Clocked device● Memory element: Capacitance● Needs periodic refreshing● Pipelined operation● Burst oriented

– Single burst in our design● 2 x (16M x 16) = 64MB

2016-11-30 13TSEA44: Computer hardware – a system on a chip

SDRAM4

data

command

clk

multiplexedaddress

16

15

A measurement: make sim_jpeg● Sketchy read cycle

– Precharge bit line to Vdd/2– Let bit line float– Connect sense amp to

bit line– Connect C to bit line– Hold value in latch– Write value back to C

● Refresh cycle– Dummy read cycle

2016-11-30 14TSEA44: Computer hardware – a system on a chip

WordBit

C

GND

Precharge

Sense amp

Latch

2016-11-30 20:47

Page 8: TSEA44: Computer hardware – a system on a chip · Refresh cycle TSEA44: Computer hardware – a system on a chip 2016-11-30 27 Start of refresh cycle Start of WB cycle Lab 4, Custom

SDRAM Architecture2016-11-30 15TSEA44: Computer hardware – a system on a chip

SDRAM Read2016-11-30 16TSEA44: Computer hardware – a system on a chip

2016-11-30 20:47

Page 9: TSEA44: Computer hardware – a system on a chip · Refresh cycle TSEA44: Computer hardware – a system on a chip 2016-11-30 27 Start of refresh cycle Start of WB cycle Lab 4, Custom

SDRAM Write2016-11-30 17TSEA44: Computer hardware – a system on a chip

Consecutive read bursts● Mode register must be programmed

2016-11-30 18TSEA44: Computer hardware – a system on a chip

2016-11-30 20:47

Page 10: TSEA44: Computer hardware – a system on a chip · Refresh cycle TSEA44: Computer hardware – a system on a chip 2016-11-30 27 Start of refresh cycle Start of WB cycle Lab 4, Custom

FLASH - Interface● Looks like SRAM

– Read– Write commands

● Erase is done in blocks● Contains uCLinux kernel + file system

2016-11-30 19TSEA44: Computer hardware – a system on a chip

FLASH - Cell2016-11-30 20TSEA44: Computer hardware – a system on a chip

2016-11-30 20:47

Page 11: TSEA44: Computer hardware – a system on a chip · Refresh cycle TSEA44: Computer hardware – a system on a chip 2016-11-30 27 Start of refresh cycle Start of WB cycle Lab 4, Custom

FLASH – Read (NOR)2016-11-30 21TSEA44: Computer hardware – a system on a chip

1

0 1

FLASH – Program (to 0)2016-11-30 22TSEA44: Computer hardware – a system on a chip

U (~13 V)

7 V

2016-11-30 20:47

Page 12: TSEA44: Computer hardware – a system on a chip · Refresh cycle TSEA44: Computer hardware – a system on a chip 2016-11-30 27 Start of refresh cycle Start of WB cycle Lab 4, Custom

FLASH – Erase (to 1)● Only blockwise

2016-11-30 23TSEA44: Computer hardware – a system on a chip

U

0

System Overview2016-11-30 24TSEA44: Computer hardware – a system on a chip

WB

OR1200 PKMC

FPGA

FLASH SRAM SDRAM

2016-11-30 20:47

Page 13: TSEA44: Computer hardware – a system on a chip · Refresh cycle TSEA44: Computer hardware – a system on a chip 2016-11-30 27 Start of refresh cycle Start of WB cycle Lab 4, Custom

PKMC internals2016-11-30 25TSEA44: Computer hardware – a system on a chip

PKMCAddrDec

SDRAMCtrl

SD

S

F

FF

FPGA Board

SRAMCtrl

FLASHCtrl

WB

SDRAM Controller Internals2016-11-30 26TSEA44: Computer hardware – a system on a chip

FSMCommand

Refreshcounter

7.2 s between refreshes

WBcommans

2016-11-30 20:47

Page 14: TSEA44: Computer hardware – a system on a chip · Refresh cycle TSEA44: Computer hardware – a system on a chip 2016-11-30 27 Start of refresh cycle Start of WB cycle Lab 4, Custom

Refresh cycle2016-11-30 27TSEA44: Computer hardware – a system on a chip

Start of refresh cycle

Start of WB cycle

Lab 4, Custom instruction● Increase performance by adjusting instruction set● Specific for application domain

– General purpose processor is general purpose– Not exceptionally good at anything

● Use profiling to find out the most timeconsuming part of the application code

2016-11-30 28TSEA44: Computer hardware – a system on a chip

2016-11-30 20:47

Page 15: TSEA44: Computer hardware – a system on a chip · Refresh cycle TSEA44: Computer hardware – a system on a chip 2016-11-30 27 Start of refresh cycle Start of WB cycle Lab 4, Custom

Huffman Encoding/Decoding

[22 12 0 −12 0 0 0 00 0 −8 0 0 0 0 04 0 0 0 0 0 0 00 0 0 0 0 0 0 10 0 0 0 0 0 0 00 0 0 0 0 0 0 00 0 0 0 0 0 0 00 0 0 0 0 0 0 0

]

2016-11-30 29TSEA44: Computer hardware – a system on a chip

reg

1) After Q 3) After RLE

2) After zig-zag

4) Huffman coding- Value are HC (variable length) using table lookup- raw bits are left untouched

22120 40 0 -12-80 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 1

Value raw bits (amplitude value) 05 10110 04 1100 13 100 24 0011 04 0111 F0 F0 D1 1 00

Run of 0:s Magnitude

-12 =>12-1, force MSB=0=> 0011

-8 =>8-1, force MSB=0=> 0111

Huffman in JFIF● Output: 1 – 16 bits● Encodes bytes● 2 tables used

– Y DC– Y AC

2016-11-30 30TSEA44: Computer hardware – a system on a chip

2016-11-30 20:47

Page 16: TSEA44: Computer hardware – a system on a chip · Refresh cycle TSEA44: Computer hardware – a system on a chip 2016-11-30 27 Start of refresh cycle Start of WB cycle Lab 4, Custom

jpegfiles2016-11-30 31TSEA44: Computer hardware – a system on a chip

draw_image()

init_encoder()

encode_image()

finish_pass_huff()

init_huffman()

init_image()

forward_DCT()

encode_mcu_huff()

flush_bits()

”write header,init your HW”

jpeg_fdct_islow()

”quantize”

emit_bits()

”flush remaining bits”

jpegtest.c, jcdctmgr.c, jdct.c, jchuff.c

”init some variables”

Emit_bits()/* Only the right 24 bits of put_buffer are used; the valid bits are left-justified in * this part. At most 16 bits can be passed to emit_bits in one call, and we never retain * more than 7 bits in put_buffer between calls, so 24 bits are sufficient. */static void emit_bits (unsigned int code, int size){ unsigned int startcycle;

new_put_buffer = (int) code;

// Add new bits to old bits. If at least 8 bits then write a char to buffer, // save the rest until we get more bits.

new_put_buffer &= (1<<size) - 1; /* mask off any extra bits in code */ current_buffer_bit += size; /* new number of bits in buffer */ new_put_buffer = new_put_buffer << (24 - current_buffer_bit); /* align incoming bits */ new_put_buffer = new_put_buffer | old_put_buffer; /* and merge with old buffer contents */

while (current_buffer_bit >= 8) { int c = ((new_put_buffer >> 16) & 0xFF); // Mask out the 8 bits we want buffer[next_buffer] = (char) c; next_buffer++; if (c == 0xFF) { // 0xFF is a reserved code for tags, if we get image data buffer[next_buffer] = 0x00; // with an FF value it has to be followed by 0x00. next_buffer++; } new_put_buffer <<= 8; current_buffer_bit -= 8; } old_put_buffer = new_put_buffer; /* update state variables */}

2016-11-30 32TSEA44: Computer hardware – a system on a chip

2016-11-30 20:47

Page 17: TSEA44: Computer hardware – a system on a chip · Refresh cycle TSEA44: Computer hardware – a system on a chip 2016-11-30 27 Start of refresh cycle Start of WB cycle Lab 4, Custom

Emit_bits()2016-11-30 33TSEA44: Computer hardware – a system on a chip

old_put_buffer current_buffer_bit=7

codesize=16

new_put_buffer current_buffer_bit=23

Write bytes to mem

old_put_buffer current_buffer_bit=7

Adding an Instruction1. Instruction Selection

2. Hardware modification

3. Assembler modification

4. Compiler modification

2016-11-30 34TSEA44: Computer hardware – a system on a chip

2016-11-30 20:47

Page 18: TSEA44: Computer hardware – a system on a chip · Refresh cycle TSEA44: Computer hardware – a system on a chip 2016-11-30 27 Start of refresh cycle Start of WB cycle Lab 4, Custom

Instruction Selection● l.custx

– No operands● Instructions for 64 bit

– Not used– Assembler can understand– l.sd I(rA),rB

2016-11-30 35TSEA44: Computer hardware – a system on a chip

Hardware Modifications● Instruction decoder modifications

– Legal instruction– or1200_ctrl.v

● Special purpose register– New group– or1200_sprs.v

● Data path– New hardware– or1200_lsu.v– or1200_vlx_top.v

2016-11-30 36TSEA44: Computer hardware – a system on a chip

2016-11-30 20:47

Page 19: TSEA44: Computer hardware – a system on a chip · Refresh cycle TSEA44: Computer hardware – a system on a chip 2016-11-30 27 Start of refresh cycle Start of WB cycle Lab 4, Custom

IF

ID

EX

WB

vlx

Or1200 Pipeline2016-11-30 37TSEA44: Computer hardware – a system on a chip

l.sd (rA),rB

code size

= align

Or1200 Pipeline● Remember stall

2016-11-30 38TSEA44: Computer hardware – a system on a chip

2016-11-30 20:47

Page 20: TSEA44: Computer hardware – a system on a chip · Refresh cycle TSEA44: Computer hardware – a system on a chip 2016-11-30 27 Start of refresh cycle Start of WB cycle Lab 4, Custom

Align reg2mem2016-11-30 39TSEA44: Computer hardware – a system on a chip

Proposed Architecture2016-11-30 40TSEA44: Computer hardware – a system on a chip

Data path

ControlUnit

Store unit

size code

adr data store_byte_o

stall_cpu_o

Internal regs(mapped as SPR)bit_regbit_reg_wr_posvlx_addr_o

2016-11-30 20:47

Page 21: TSEA44: Computer hardware – a system on a chip · Refresh cycle TSEA44: Computer hardware – a system on a chip 2016-11-30 27 Start of refresh cycle Start of WB cycle Lab 4, Custom

Inline asm2016-11-30 41TSEA44: Computer hardware – a system on a chip

asm volatile("l.sd 0x0(%0),%1" : : "r"(code), "r"(size));

In jpegfiles insert:

=> code and size will show up at your vlx

template

input input

Data Path● Fill buffer alternatives

– One bit/clock cycle– All bits at once

● Write to mem alternatives– One byte– One 32 bit word, must be on word boundaries

2016-11-30 42TSEA44: Computer hardware – a system on a chip

buffer

input

mem

2016-11-30 20:47

Page 22: TSEA44: Computer hardware – a system on a chip · Refresh cycle TSEA44: Computer hardware – a system on a chip 2016-11-30 27 Start of refresh cycle Start of WB cycle Lab 4, Custom

Control● May not be needed● May be an FSM

2016-11-30 43TSEA44: Computer hardware – a system on a chip

Store Unit● Stores the data● 0xFF stored as 0xFF00

– JPEG markers● Only byte alignment!

– Parallel stores faster

2016-11-30 44TSEA44: Computer hardware – a system on a chip

2016-11-30 20:47

Page 23: TSEA44: Computer hardware – a system on a chip · Refresh cycle TSEA44: Computer hardware – a system on a chip 2016-11-30 27 Start of refresh cycle Start of WB cycle Lab 4, Custom

Software● New assembler

– Easy● New compiler

– Hard problem for complex instructions– Compiler knows functions

● C– Inline Assembler

2016-11-30 45TSEA44: Computer hardware – a system on a chip

Instruction Usage2016-11-30 46TSEA44: Computer hardware – a system on a chip

unsigned char* sb_get_buff_pos(void){ unsigned char* pos; asm volatile("l.mfspr %0,%1,0x2":"=r"(pos):"r"(0xc000)); return pos;}

output

00000250 <_sb_get_buff_pos>: 250: 9c 21 ff fc l.addi r1,r1,0xfffffffc 254: d4 01 10 00 l.sw 0x0(r1),r2 258: 9c 41 00 04 l.addi r2,r1,0x4 25c: a9 60 c0 00 l.ori r11,r0,0xc000 260: b5 6b 00 02 l.mfspr r11,r11,0x2 264: 84 41 00 00 l.lwz r2,0x0(r1) 268: 44 00 48 00 l.jr r9 26c: 9c 21 00 04 l.addi r1,r1,0x4

2016-11-30 20:47

Page 24: TSEA44: Computer hardware – a system on a chip · Refresh cycle TSEA44: Computer hardware – a system on a chip 2016-11-30 27 Start of refresh cycle Start of WB cycle Lab 4, Custom

www.liu.se

2016-11-30 20:47