les 4: gegevensmanipulatie-instructies en machinemodellen

87
ca4-1 Les 4: Gegevensmanipulatie- instructies en machinemodellen “Everything that can be invented has been invented.” — Charles H. Duell, Commissioner, U.S. Office of

Upload: metea

Post on 11-Jan-2016

31 views

Category:

Documents


1 download

DESCRIPTION

Les 4: Gegevensmanipulatie-instructies en machinemodellen. “Everything that can be invented has been invented.” — Charles H. Duell, Commissioner, U.S. Office of Patents, 1899. BUS. Von Neumann-machine Fysiek zicht. BUS. adres. adres. CVE. Controle. controle. cache. data. data. klok. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-1

Les 4: Gegevensmanipulatie-

instructies en machinemodellen

“Everything that can be invented has been invented.” — Charles H. Duell, Commissioner, U.S. Office of Patents, 1899

Page 2: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-2

Von Neumann-machineFysiek zicht

Invoer/Uitvoer

Geheugen:bau-cellen

RAM

adres

controle

data

BUS

controlecontrole

klokklok

registersregistersALU

Invoer/Uitvoer

ControleControle

klokklok

registersregisters

Geheugen

CVEadres

controle

dataALU

BUS

cachecache

Page 3: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-3

Overzicht

• Aritmetische instructies

• Logische instructies

• Vlottende-komma-instructies

• MMX-instructies

• SSE/SSE2-4-instructies

• Varia

• Machinemodellen

Page 4: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-4

Operatorgedeelte

R

O1

O2

controle

c-bits-bito-bitz-bit

S

Page 5: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-5

s

Toestandsbits bij 32-bit optelling R = 01 + 02

O1: 00111000101001010101010100001100

O2: 01001110001010010101010101100110

R: 10000110110011101010101001110010

c z-bit = 1 indien resultaat = 0

Page 6: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-6

overflowOverflow

-4

-3

-2

-1

0

1

2

3

100

101

110

111

000

001

010

011

010 2

+011 3

101 5

110 -2

+101 -3

1011 -5

110 -2

+111 -1

1101 -3

010 2

+001 1

011 3

o-bit = carry(31) xor carry(30)

Page 7: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-7

Getallencirkel000

001

010

011

100

101

110

1110

1

2

3

-4

-3

-2

-1

optellenaftre

kken

Page 8: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-8

Saturatierekenen

Overflow kan ook opgevangen worden door de waarden te plafonneren op de extremen

-4

-3

-2

-1

0

1

2

3

100

101

110

111

000

001

010

011

010 2

010 2

100 -4+

011 3 (max)

110 -2

101 -3

1011 3

+

100 -4 (min)

Page 9: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-9

Saturatierekenen

overflow modulo

saturatie

Page 10: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-10

Resoluties hoofdbewerkingen

• Som: n bit + n bit (n+1) bit

• Verschil: n bit - n bit (n+1) bit

• Product: n bit * n bit (2n) bit

• Deling: n bit / n bit n bit

Page 11: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-11

Optelling

add doel, bron 00B0030080000000003300200003300A….

0004080C10

32

00920000

00004000

eax

ebx

0092400000924010

add eax, ebx

add eax, 10h

add eax, [4]

socz

0000

80924010

1

Alle waarden zijn hexadecimaal!Alle waarden zijn hexadecimaal!

Instructie:add

Page 12: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-12

Aftrekking

sub doel, bron 00B0030080000000003300200003300A….

0004080C10

32

00920000

00004000

eax

ebx

0091C0000091BFF0

sub eax, ebx

sub eax, 10h

sub eax, [4]

socz

0000

8091BFF0

111

Alle waarden zijn hexadecimaal!Alle waarden zijn hexadecimaal!

Instructie:sub

Page 13: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-13

Integer hoofdbewerkingenadd d,s adc d,ssub d,s sbb d,smul simul sdiv sidiv sneg d inc ddec d

d = d + sd = d + s + cd = d - sd = d - s - cvermenigvuldiging (unsigned)vermenigvuldiging (signed) deling (unsigned)deling (signed)d = -dd = d + 1d = d - 1

Page 14: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-14

mov eax,[10h]mov ebx,[14h]add eax,[18h]adc ebx,[1ch]mov [20h],eaxmov [24h],ebx

64-bit optelling10h 14h 18h 1ch 20h 24h 28h

ebx [14h] eax [10h]

[1ch]

[20h][24h]

[18h]+

Page 15: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-15

mul & div

edx:eax = bron * eax (bin)mul bronmul bron

eax = edx:eax / bron (bin)

edx = edx:eax % bron

div brondiv bron

edx:eax = bron * eax (2c)imul bronimul bron

deeltal = quotiënt * deler + rest en rest * deeltal ≥ 0.

Instructie:mul

Instructie:div

Page 16: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-16

imul: 3 varianten

edx:eax = bron * eaximul bronimul bron

d = d * bron imul d,bronimul d,bron

d = bron1 * bron2imul d,bron1,bron2imul d,bron1,bron2

Page 17: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-17

Product in helften

b.v. Alpha (64 bit)

reg[c]:=(reg[a]*reg[b])<63:0>

reg[c]:=(reg[a]*reg[b])<127:64>

mulq a,b,c mulq a,b,c

umulh a,b,c umulh a,b,c

<n1:n2> bits n1 tot n2 (neerwaarts genummerd)

Page 18: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-18

Deling

Indien deling door een constante, kan dit ook door vermenigvuldiging, b.v. deling door 15

X/15 =X*(1/15)

1/15 = 0.0001000100010001…2= 0.111116

50/15 = 003216 * 0.111116 = 0003.555216

45/15 = 002D16 * 0.111116 = 0002.FFFD16

45/15 = 002D16 * 0.111216 = 0003.002A16

Page 19: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-19

Vergelijkingen

cmp d,s

test d,s

d-s vlaggen

d ‘and’ s vlaggen

cmp: vergelijken van waarden: >, =, <

test: testen van bits: aan, uit

cmp: vergelijken van waarden: >, =, <

test: testen van bits: aan, uit

Instructie:cmd Instructie:test

Page 20: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-20

000 0001 1010 2011 3100 4101 5110 6111 7

010 2

-011 3

111 ?

011 3

-010 2

001 1

c

Natuurlijke getallen (binair)

a nbe (c or z) == 0 aboveae nb c == 0 above or equalb nae c == 1 belowbe na (c or z) == 1 below or equal

a nbe (c or z) == 0 aboveae nb c == 0 above or equalb nae c == 1 belowbe na (c or z) == 1 below or equal binair

Page 21: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-21

100 -4

101 -3

110 -2

111 -1

000 0

001 1

010 2

011 3

010 2

-011 3

111 -1

101 -3

-010 2

011 ?

011 3

-010 2

001 1

010 2

-101 -3

101 ?

o == 1

o == 0

s == 1 s == 0

Gehele getallen (2-complement)

g nle ((s xor o) or z) == 0 greater ge nl (s xor o) == 0 greater or equal l nge (s xor o) == 1 lessle ng ((s xor o) or z) == 1 less or equal

g nle ((s xor o) or z) == 0 greater ge nl (s xor o) == 0 greater or equal l nge (s xor o) == 1 lessle ng ((s xor o) or z) == 1 less or equal 2-comp

Page 22: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-22

Conditiecodesz z == 1 zeroc c == 1 carryo o == 1 overflowp p == 1 paritys s == 1 sign

nz z == 0 no zeronc c == 0 no carryno o == 0 no overflownp p == 0 no parityns s == 0 no sign

g nle ((s xor o) or z) == 0 greater ge nl (s xor o) == 0 greater or equal l nge (s xor o) == 1 lessle ng ((s xor o) or z) == 1 less or equal

e z == 1 equalne z == 0 not equala nbe (c or z) == 0 aboveae nb c == 0 above or equalb nae c == 1 belowbe na (c or z) == 1 below or equal

z z == 1 zeroc c == 1 carryo o == 1 overflowp p == 1 paritys s == 1 sign

nz z == 0 no zeronc c == 0 no carryno o == 0 no overflownp p == 0 no parityns s == 0 no sign

g nle ((s xor o) or z) == 0 greater ge nl (s xor o) == 0 greater or equal l nge (s xor o) == 1 lessle ng ((s xor o) or z) == 1 less or equal

e z == 1 equalne z == 0 not equala nbe (c or z) == 0 aboveae nb c == 0 above or equalb nae c == 1 belowbe na (c or z) == 1 below or equal binair

2-comp

01000010000010101000

0101

00110001101110011111110111001110

01000101

0111001100100110

Page 23: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-23

Overzicht

• Aritmetische instructies• Logische instructies• Vlottende-komma-instructies• MMX-instructies• SSE/SSE2-4-instructies• Varia• Machinemodellen

Page 24: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-24

Logische Operaties

and d,s or d,s xor d,s not d

d = d ‘and’ sd = d ‘or’ sd = d ‘xor’ sd = ‘not’ d

Page 25: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-25

Verschuivingenshl d,n

shr d,n

sal d,n

sar d,n

shld d,s,n

shrd d,s,n

rol d,n

ror d,n

rcl d,n

rcr d,n

shl d,n

shr d,n

sal d,n

sar d,n

shld d,s,n

shrd d,s,n

rol d,n

ror d,n

rcl d,n

rcr d,n

d = d << n

d = d >> n

aritmetisch d = d << n

aritmetisch d = d >> n

d = (d:s << n)<63:32>

d = (s:d >> n)<31:0>

bitrotatie naar links

bitrotatie naar rechts

uitgebreide bitrotatie naar links

uitgebreide bitrotatie naar rechts

Page 26: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-26

Schuifoperaties

110100010010101010101010011

101000100101010101010100110C=1

C=0 001001010101010101001100000

Schuif 1 positie naar links

Schuif 5 posities naar links

Instructie: schuifoperatie

Page 27: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-27

Schuifoperaties

C 0SHL

CSAR

C0SHR

C 0SAL

Page 28: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-28

Schuifoperaties

DCSHLD

S

S

C

SHRD

D

Page 29: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-29

Rotatieoperaties

CROL

CROR

CRCL

CRCR

Instructie: rotatieoperatie

Page 30: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-30

Schuifoperaties: logisch

00011 3

00110 6

01100 12

links 1 x 2

links 1 x 2

00110 6

00011 3

rechts 1 2

rechts 1 2

links n x 2n rechts n 2n

Page 31: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-31

Schuifoperaties: aritmetisch

11101 -3

11010 -6

10100 -12

links 1 x 2

links 1 x 2

11010 -6

11101 -3

rechts 1 2

rechts 1 2

11110 -2

11111 -1

rechts 1 2

rechts 1 2

Page 32: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-32

Oefening

001011000011 101011

sal 2

sar 2

001100

000011

101100

111011

101100

111011

shl 2

shr 2

001011000011 101011

001100

000011

101100

001011

101100

001011

Page 33: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-33

Voorbeeld

mov eax, [10]

mov ebx, eax

shl ebx, 3

shl eax, 5

add eax, ebx

add eax, 10

mov [14], eax

; reg[eax] := ‘i’*8+’i’*32+10

; reg[eax] := ‘i’*8+’i’*32

; reg[eax] := ‘i’*32

; reg[ebx] := ‘i’*8

; reg[ebx] := ‘i’

; reg[eax] := mem32[i]

j := i*40+10

; mem32[j] := reg[eax]

Page 34: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-34

Product door verschuivingen

x 3x 4x 5x 6x 7x 8x 9x 10 x 11x 12

0110100010101100111

010000100101010 0101101100

10111001011101010011000

1011110110 1010110100

x2+x1x4x4+x1x4+x2

x8-x1x8x8+x1x8+x2x8+x2+x1x8+x4

x4-x1

x8-x2

x16-x4-x1x16-x4

Page 35: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-35

Verschuivingen

x 57 = x64 - x8 + x1

x 113 = x128 - x16 + x1

Soms combinatie van de twee:

Page 36: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-36

Bit test instructies

bt d, o

bts d, o

btr d, o

btc d, o

bt d, o

bts d, o

btr d, o

btc d, o

c = d<o:o>

c = d<o:o>; d<o:o> = 1

c = d<o:o>; d<o:o> = 0

c = d<o:o>; d<o:o> = d<o:o>

Instructie: bitoperaties

Page 37: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-37

Bit scan instructies

bsf d, s

bsr d, s

bsf d, s

bsr d, s

d = minst significante 1-bit

d = meest significante 1-bit

d = index van bit, neerwaarts genummerd

Indien allemaal 0: d = onbepaald, z=1

Page 38: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-38

Set byte on condition

set<cc> dset<cc> d d = conditiecode

setge al

seto ah

setge al

seto ah

reg[al] = ge ? 1 : 0

reg[ah] = o ? 1 : 0

setno al

dec al

setno al

dec al reg[al] = o ? 0ffh : 00h

Page 39: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-39

Overzicht

• Aritmetische instructies

• Logische instructies

• Vlottende-komma-instructies

• MMX-instructies

• SSE/SSE2-4-instructies

• Varia

• Machinemodellen

Page 40: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-40

Vlottende-komma-registerverzameling

063647978

s exp mantisse

stst(1)st(2)st(3)

st(7)st(6)st(5)st(4)

Registers: vlottende-komma

Page 41: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-41

Datatypes

• FP Enkelvoudige precisie (32 bit)

• FP Dubbele precisie (64 bit)

• FP Dubbele extended precisie (80 bit)

• Integer woord (16 bit)

• Integer dubbelwoord (32 bit)

• Integer quadwoord (64 bit)

• BCD 18 nibbles + tekenbyte (80 bit)

Page 42: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-42

Zuivere stapeladresseringfadd st(1) = st+st(1); pop

Registeradressering

fadd st(i) st = st+st(i)

fadd st(i),st st(i) = st+st(i)

fadd st,st(i) st = st(i)+st

faddp st(i),st st(i) = st+st(i); pop

Geheugenadressering fadd <ae> st = st+mem[ae]

Adresseermodes

Page 43: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-43

Vlottende-kommabewerkingen

fadd

fsub

fdiv

fprem

fmul

fabs

fchs

fcomi

fadd

fsub

fdiv

fprem

fmul

fabs

fchs

fcomi

FP optelling

verschil

deling

rest na deling

vermenigvuldiging

absolute waarde st = abs(st)

negatie st = - st

FP compare and set eflags

Page 44: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-44

Wiskundige functies

fsqrtfsinfcosfptanfpatanfyl2xfyl2xp1f2xm1

fsqrtfsinfcosfptanfpatanfyl2xfyl2xp1f2xm1

vierkantswortelsinuscosinustangensarcus tangenslogaritme st(1) = st(1)*log2(st); poplogaritme st(1) = st(1)*log2(st+1); popexponent st = 2st-1

Page 45: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-45

Load-store operaties

fbldfbstpfildfistfldfst

fbldfbstpfildfistfldfst

Load/push BCD-getal (ld=load)

Store BCD and pop

Load/push integer 16/32/64 bit

Store integer 16/32/64 bit

Load/push floating point value 32/64/80 bit

Store floating point value 32/64/80 bit

Page 46: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-46

Load constant

fld1fldl2tfldl2efldpifldlg2fldln2fldz

fld1fldl2tfldl2efldpifldlg2fldln2fldz

push 1.0push log210push log2epush πpush log102push loge2push +0.0

Page 47: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-47

Overzicht

• Aritmetische instructies

• Logische instructies

• Vlottende-komma-instructies

• MMX-instructies

• SSE/SSE2-4-instructies

• Varia

• Machinemodellen

Page 48: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-48

Aanleiding

• Multimedia-applicaties en het web

– Beeld (10 kiB)

– Geluid (100 kiB)

– Video (MiB).

• Opkomst van 64-bit processors

• Kleine data-elementen (8 of 16 bit)

• Zeer veel data-elementen

• Onafhankelijke data-elementen

Page 49: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-49

Maar

00 00 00 00 00 00 00

00 00 00 00 00 00

64 bit

64 bit

64 bitOplossing:

Page 50: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-50

Multimedia-extensies

• Sparc: Visual Instruction Set• PA-RISC: MAX-2• X64: MMX, SSE• PowerPC: Altivec

Page 51: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-51

MMX: registers

• 8 MMX-registers van 64 bit (mm0-mm7)

• Dezelfde registers als ST

• register geschikt voor de opslag van

8 bytes

4 woorden

2 dubbelwoorden

1 quadwoord

Registers: mmx

Page 52: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-52

MMX: Instructies

• 57 instructies die subwoordparallellisme ondersteunen

• Voorbeeld:– acht 8-bit optellingen in parallel– vier 16-bit optellingen in parallel– twee 32-bit optellingen in parallel– één 64-bit optelling

Page 53: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-53

Instructies

paddb

paddw

paddd

paddq

padds[b/w]

paddus[b/w]

psubb

psubw

psubd

psubq

psubs[b/w]

psubus[b/w]

Page 54: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-54

paddb

paddb mm0,mm1paddb mm0,mm1

mm0+ + + + + + + +

mm1

mm0

Page 55: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-55

paddd

paddd mm0,mm1paddd mm0,mm1

mm0 + +

mm1

mm0

Page 56: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-56

Instructies

a b c d

e f g h

(a*e).l (b*f).l (c*g).l (d*h).lpmullw

(a*e).h (b*f).h (c*g).h (d*h).hpmulhw

a*e+b*f c*g+d*hpmaddwd

Page 57: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-57

pcmpeqd

pcmpeqd mm0,mm1pcmpeqd mm0,mm1

FF 00 00 FF FF 00 FF FF mm0

Andere: pcmpeq[b/w/d] pcmpgt[b/w/d]

FF FF FF FF 00 00 00 00 mm0

FF 00 00 FF FF 00 00 00 mm1

Page 58: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-58

Logische instructies

psra[w/d]

psll[w/d/q]

psrl[w/d/q]

pand

pandn

por

pxor

psra[w/d]

psll[w/d/q]

psrl[w/d/q]

pand

pandn

por

pxor

Page 59: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-59

Unpack instructies

punpckl[bw/wd/dq] punpckh[bw/wd/dq]punpckl[bw/wd/dq] punpckh[bw/wd/dq]

mm0

punpckhbw mm0,mm1punpckhbw mm0,mm1

mm1

mm0

Page 60: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-60

Pack instructies

packss[wb/dw]packss[wb/dw]

packssdw mm0,mm1packssdw mm0,mm1

mm0

mm1

mm0

packuswbpackuswb

Page 61: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-61

Einde van MMX-programma

emms empty MMX state

Page 62: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-62

Overzicht

• Aritmetische instructies

• Logische instructies

• Vlottende-komma-instructies

• MMX-instructies

• SSE/SSE2-4-instructies

• Varia

• Machinemodellen

Page 63: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-63

SSE-extensies

• Streaming SIMD Extensions: 70 nieuwe instructies

• 8 extra registers XMM (128 bits lang)

• Subwoordparallellisme met vlottende-kommagetallen (enkelvoudige precisie)

128 bit

Page 64: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-64

Packed SSE-operaties

xmm0

xmm1

xmm0

x3 x2 x1 x0

y3 y2 y1 y0

x3+y3 x2+y2 x1+y1 x0+y0

addps xmm0, xmm1addps xmm0, xmm1

Page 65: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-65

Scalaire SSE-operaties

xmm0

xmm1

xmm0

x3 x2 x1 x0

y3 y2 y1 y0

x3 x2 x1 x0+y0

addss xmm0, xmm1addss xmm0, xmm1

Page 66: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-66

SSE2-extensies

• Subwoordparallellisme met vlottende-kommagetallen (dubbele precisie) + integers.

• 144 nieuwe instructies

8 woorden

4 dubbelwoorden

2 quadwoorden

16 bytesInt

Int

Int

FP/Int

Page 67: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-67

Packed SSE2-operaties

xmm0

xmm1

xmm0

x1 x0

y1 y0

x1+y1 x0+y0

addpd xmm0, xmm1addpd xmm0, xmm1

Page 68: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-68

Scalaire SSE2-operaties

xmm0

xmm1

xmm0

x1 x0

y1 y0

x1 x0+y0

addsd xmm0, xmm1addsd xmm0, xmm1

Page 69: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-69

Shuffle operaties

shufps xmm0, xmm1, patshufps xmm0, xmm1, pat

xmm0

xmm1

xmm0

x3 x2 x1 x0

y3 y2 y1 y0

y? y? x? x?

Page 70: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-70

SSE3-uitbreidingen

haddps xmm0, xmm1haddps xmm0, xmm1

xmm0

xmm1

xmm0

x3 x2 x1 x0

y3 y2 y1 y0

x3+x2 x1+x0 y3+y2 y1+y0

haddps = Horizontal-Add-Packed-Single

Page 71: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

SSE4-uitbreidingen

• 54 bijkomende instructies

• Zeer gespecialiseerd

ca4-71

Page 72: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-72

Overzicht

• Aritmetische instructies

• Logische instructies

• Vlottende-komma-instructies

• MMX-instructies

• SSE/SSE2-4-instructies

• Varia

• Machinemodellen

Page 73: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-73

nop

nopnop doe niets

Instructie: nop

Page 74: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-74

xadd

xadd d,sxadd d,s t = d+ss = dd = t

Page 75: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-75

cmpxchg

cmpxchg d,scmpxchg d,s if (reg[eax]==d) d = s;else reg[eax] = d;

Page 76: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-76

lock-prefix

lock add [1000],eaxlock add [1000],eax

atomaire optelling van eax bij de geheugenlocatie [1000]

slechts combineerbaar met een beperkt aantal instructies

Page 77: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-77

set/clear status bits

stc

clc

std

cld

sti

cli

stc

clc

std

cld

sti

cli

c = 1

c = 0

d = 1

d = 0

i = 1

i = 0

Page 78: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-78

Overzicht

• Aritmetische instructies

• Logische instructies

• Vlottende-komma-instructies

• MMX-instructies

• SSE/SSE2-4-instructies

• Varia

• Machinemodellen

Page 79: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-79

Globale machinetypes

• Stapelmachines

• Accumulatormachines

• Registermachines

Page 80: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-80

Stapelmachine

O1

O2

R A := (B-C)/D

PUSH B

PUSH C

SUB

PUSH D

DIV

POP A

b.v.: hp-calculator

Exp

ress

iest

apel

Page 81: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-81

A := (B-C)/D

LOAD B

SUB C

DIV D

STORE A

Accumulatormachine

ACC RO1

O2

b.v.: klassieke calculator

Page 82: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-82

A := (B-C)/D

MOV R1,B

MOV R2,C

SUB R3,R1,R2

MOV R1,D

DIV R2,R3,R1

MOV A,R2

Registermachine

O1

O2

R0R1R2R3R4R5R6R7

R

Page 83: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-83

A := (B-C)/D

Registermachine

O1

O2

R

MOV R1,B

SUB R1,C

DIV R1,D

MOV A,R1

R0R1R2R3R4R5R6R7

Page 84: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-84

A := (B-C)/D

Registermachine

O1

O2

R

SUB R1,B,C

DIV A,R1,D

R0R1R2R3R4R5R6R7

Page 85: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-85

stapelmachine 0-adresmachine -accumulatormachine 1-adresmachine met registeroperand R met geheugenoperand Mregistermachine 2-adresmachine

tot 0 geheugenoperandi RR tot 1 geheugenoperand MR tot 2 geheugenoperandi MM

3-adresmachine tot 0 geheugenoperandi RRR tot 1 geheugenoperand MRR tot 2 geheugenoperandi MMR tot 3 geheugenoperandi MMM

Machinetypes

Page 86: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-86

Oefening

A := (A+B)*(C+D)

Stapel Accu RRRpush Apush Baddpush Cpush Daddmulpop A

load Cadd Dstore Tload Aadd Bmul Tstore A

mov R1,Amov R2,Badd R1,R2,R1mov R2,Cmov R3,Dadd R2,R3,R2mul R1,R2,R1mov A,R1

Page 87: Les 4:  Gegevensmanipulatie-instructies en machinemodellen

ca4-87

Pauze