overview motivation dataflow programming -...

10

Upload: truongliem

Post on 05-Oct-2018

228 views

Category:

Documents


0 download

TRANSCRIPT

Dataflow Programming

Jörn W. Janneck

[email protected]

Computer Science Dept.Lund University

2

overview

motivationthe need for a parallel programming model

dataflow programmingactors, dataflow, and the CAL actor language

examplesdeterminacy � the structure of a computation

researchthings still left to do

3

motivationthe need for a parallel programming model

dataflow programmingactors, dataflow, and the CAL actor language

examplesdeterminacy � the structure of a computation

researchthings still left to do

10

motivationthe need for a parallel programming model

dataflow programmingactors, dataflow, and the CAL actor language

examplesdeterminacy � the structure of a computation

researchthings still left to do

11

dataflow

� computational kernels (aka actors)� provide explicit concurrency

� directed point-to-point connections� lossless, order-preserving� conceptually unbounded� asynchrony, abstraction from time

� communicating streams of discrete data packets (tokens)

� no shared state

12

domain expert's lunchtime rendition of an MPEG4 video decoder

digital signal processingmedia processing

video codingimage processing / analytics

audionetworking / packet processing

...

not exactly a new model...

15

dataflow with firing� computational kernels (aka actors)

� provide explicit concurrency

� directed point-to-point connections� lossless, order-preserving� conceptually unbounded� asynchrony, abstraction from time

� communicating streams of discrete data packets (tokens)

� no shared state

state

actions

� actors execute in a sequence of steps� described in actions

� steps (firings) are...� uninterrupted, non-overlapping,

terminating

� a step may...� consume input tokens� produce output tokens� modify local state

16

actors as stream operators

actors operate on infinite objects

they need not terminate(although each step must)

17

dataflow with firing

s0

s1

s3

s2

s

actor step may- consume input tokens- produce output tokens- modify the state

18

dataflow with firing

s0

s1

s3

s2

s

actors & actor networks operate on infinite objects (streams)

they need not terminate

streams are processed incrementally

each step is a classical, terminating computation

looking at the steps (or actors) in isolation is not enough

� determinacy, deadlock, throughput, time-dependency, buffer sizes, boundedness, schedule, parallelism, ...

19

actor Add () A, B ==> X:

action A: [a], B: [b] ==> X: [a + b] endend

CAL � a crash course 1/5state

actions

consumption & production of tokens

actor AddSeq () A ==> X:

action A: [a1, a2] ==> X: [a1 + a2] endend

3 4 -1 1 2 ...7 -9 7 2 0 ...

10 -5 6 3 2 ...

7 -9 7 2 0 -1 ...

-2 9 -1 ...

20

actor Sum () A ==> X:

s := 0;

action A: [a] ==> X: [s] do s := s + a; endend

CAL � a crash course 2/5state

actions

state

7 -9 7 2 0 ...

7 -2 5 7 7 ...

21

actor Merge () A, B ==> X:

action A: [v] ==> X: [v] end action B: [v] ==> X: [v] endend

CAL � a crash course 3/5state

actions

multiple actions

1 2 3 ...a b c ...

1 2 3 a b c ...

a b c 1 2 3 ...1 a 2 b 3 c ...

ororor ...

22

CAL � a crash course 4/5state

actions

actor Split () A ==> P, N:

action A: [v] ==> P: [v] guard v >= 0 end

action A: [v] ==> N: [-v] guard v < 0 endend

guards

actor PingPongMergeMerge () A, B ==> X:

action A: [v] ==> X: [v] guard s = 0 begin s := 1; end action B: [v] ==> X: [v] guard s = 1 begin s := 0; end s := 0;end7 -9 7 2 0 ...

7 7 2 0 ...-9 ...

1 2 3 ...a b c ...

1 a 2 b 3 c ...

23

actor BiasedMerge () A, B ==> X:

CopyA: action A: [v] ==> X: [v] end CopyB: action B: [v] ==> X: [v] end

priority CopyA > CopyB; endend

CAL � a crash course 5/5state

actions

priorities

1 2 3 ...a b c ...

1 2 3 ... a b c ...

24

actor Add () A, B ==> X:

action A: [a], B: [b] ==> X: [a + b] endend

actor Sum () A ==> X:

s := 0;

action A: [a] ==> X: [s] do s := s + a; endend

actor Merge () A, B ==> X:

action A: [v] ==> X: [v] end action B: [v] ==> X: [v] endend

actor BiasedMerge () A, B ==> X:

CopyA: action A: [v] ==> X: [v] end CopyB: action B: [v] ==> X: [v] end

priority CopyA > CopyB; endend

CAL � a crash coursestate

actions

1. consumption & production of tokens2. state

3. multiple actions

4. guards 5. prioritiesactor Split () A ==> P, N:

action A: [v] ==> P: [v] guard v >= 0 end

action A: [v] ==> N: [-v] guard v < 0 endend

25

2 47 4 , 0, 2 4 82 , 30 3 4 , 2 4 9 0 , 3 0 2 6, 2 49 8 , 30 1 8 , 25 0 6 , 2 9 7 8 , 2 5 14 , 2 89 0 , 25 2 2 , 2 7 7 0, 2 5 30 , 2 71 4 , 25 3 8 , 2 6 5 8 , 2 5 46 , 2 63 4 , 25 5 4 , 2 6 1 0, 2 5 62 , 2 58 6 , 25 7 0 , 2 5 7 8 , 1 , 1 , 1 , 1 , 25 9 4 , 2 6 0 2, 1, 1 , 1 , 1 , 2 6 18 , 2 62 6 , 12 8 , -1 2 8 , 12 4 , -1 2 4 , 2 6 4 2, 2 6 50 , 1 20 , - 12 0 , 1 1 6 , - 1 1 6 , 26 6 6 , 2 6 9 0 , 2 6 74 , 2 68 2 , 11 2 , -1 1 2 , 1 0 8 , - 1 0 8, 26 9 8 , 2 7 0 6 , 1 0 4, - 1 04 , 1 00 , - 10 0 , 2 7 2 2 , 2 7 4 6, 27 3 0 , 2 7 3 8 , 9 6 , - 9 6 , 9 2 , - 9 2 , 2 7 5 4, 2 7 62 , 88 , - 88 , 8 4, - 84 , 2 77 8 , 28 3 4 , 2 7 8 6, 2 8 10 , 27 9 4 , 2 8 0 2 , 8 0 , - 8 0 , 7 6 , - 7 6 , 2 8 1 8, 2 8 26 , 72 , - 72 , 6 8, - 68 , 2 84 2 , 28 6 6 , 2 8 5 0, 2 8 58 , 64 , - 64 , 6 0, - 60 , 2 87 4 , 28 8 2 , 5 6 , - 5 6 , 52 , - 52 , 2 89 8 , 2 9 7 0 , 2 9 0 6, 2 9 46 , 29 1 4 , 2 9 3 8 , 29 2 2 , 2 9 3 0 , 4 8 , - 4 8 , 4 4 , - 4 4 , 4 0 , - 4 0 , 29 5 4 , 2 9 6 2 , 3 6 , - 3 6 , 3 2 , - 3 2 , 2 8 , - 2 8 , 29 8 6 , 3 0 1 0 , 2 9 94 , 3 00 2 , 24 , - 24 , 20 , - 20 , 16 , - 16 , 1 2, - 12 , 8 , - 8 , 4 , - 4 ] ;

/ / S ta r t i ng i nd i c e s i n t o V L D t a b l e a b ov e i n t MC B P C _I V O P_ S T A RT _ I N DE X = 0 ; i n t MC B P C _P V O P_ S T A RT _ I N DE X = 1 6; i n t CB P Y _ ST A R T_ I N D EX = 5 8; i n t DC B I T S_ Y _ ST A R T _I N D E X = 9 2; i n t DC B I T S_ U V _S T A R T_ I N D EX = 1 18 ; i n t CO E F F _I N T ER _ S T AR T _ I ND E X = 1 44 ; i n t CO E F F _I N T RA _ S T AR T _ I ND E X = 3 80 ; i n t MV _ S T AR T _ IN D E X = 6 16 ;

/ / V LD d e co d e e n g i ne . i n t ( s i z e =V L D _T A B L E_ A D D R_ B I T S ) v ld _ i nd e x ; i n t ( s i z e =V L D _T A B L E_ D A T A_ B I T S ) v ld _ c od e w o rd : = 1 ; p r o c ed u r e s t a rt _ v l d_ e n g in e ( in t i nd e x ) b e g i n v l d_ i n d ex : = i n d ex ; v l d_ c o d ew o r d : = 2; e n d f u n c ti o n vl d _ su c c e ss ( ) -- > b oo l : b i t an d ( v ld _ c o de w o r d, 3 ) = 0 en d f u n c ti o n vl d _ fa i l u re ( ) -- > b oo l : b i t an d ( v ld _ c o de w o r d, 1 ) = 1 en d f u n c ti o n vl d _ re s u l t( ) - -> i n t( s i ze = V LD _ T A BL E _ D AT A _ B IT S ) : r sh i f t (v l d _ co d e wo r d , 2) e n d a c t i on b i ts : [ b ] == > g u a r d b i ta n d ( vl d _ co d e w or d , 3 ) = 2 d o v l d_ c o d ew o r d : = vl d _ t ab l e [ v l d _i n d e x + i f b t he n 1 e l s e 0 e nd ] ; v l d_ i n d ex : = r s h if t ( v ld _ c o de w o rd , 2 ) ; b i t_ c o u nt : = b i t _c o u n t + 1 ; e n d v l d _ fa i l u re : ac t i o n = = > g u a r d v l d_ f a i lu r e ()/ / d o/ / pr i n t ln ( " Ba d V LD c o de w o r d" ) ; e n d

g e n e ri c _ d on e : a c t i on = = > g u a r d d o ne _ r e ad i n g_ b i t s( ) e n d

g e n e ri c _ d on e _ wi t h _ bi t r e ad : a ct i o n b i t s: [ b ] = = > g u a r d d o ne _ r e ad i n g_ b i t s( ) d o b i t_ c o u nt : = b i t _c o u n t + 1 ; e n d

/ / s tu c k : a c t io n = => / / d o / / s e t _ bi t s _t o _ r ea d ( 0 ); / / r e s e t_ t e xt u r e () ; / / p r i n tl n ( "S t u c k a t bi t _ c ou n t " + bi t _ c ou n t ) ; / / e nd

t e s t _z e r o _b y t e: a c ti o n == > g u a r d d o ne _ r e ad i n g_ b i t s( ) , b i ta n d ( r e a d_ r e s ul t ( ) , 2 5 5 ) = 0 e n d

t e s t _o n e _ by t e : a c t io n = => g u a r d d o ne _ r e ad i n g_ b i t s( ) , b i ta n d ( r e a d_ r e s ul t ( ) , 2 5 5 ) = 1 e n d

r e q u es t _ b yt e : a c t i on = = > g u a r d d o ne _ r e ad i n g_ b i t s( ) d o s e t_ b i t s_ t o _r e a d ( 8 ) ; e n d

r e q u es t _ v ol : ac t i o n = = > d o s e t_ b i t s_ t o _r e a d ( V O L _S T A R T_ C O DE _ L E NG T H ); e n d

s c h e du l e fs m st u c k _1 a / * l o o k_ f o r _v o */ :

/ / P r o c es s a n e w V O L l o ok _ f o r_ v o ( lo o k _ fo r _ vo ) - - > v o _ h ea d e r; v o _h e a d er ( ge n e r ic _ d on e ) - - > s t u c k; v o _h e a d er ( vo _ h e ad e r .g o o d ) - - > l o o k _f o r _v o l ;

/ / P r o c es s a n e w V O L l o ok _ f o r_ v o l ( ge n e r ic _ d on e ) - - > s t u c k; l o ok _ f o r_ v o l ( vo l _ s ta r t co d e . go o d ) - - > v o l _ ob j e ct ; v o l_ o b j ec t ( vo l _ o bj e c t_ l a y er _ i d en t i f ic a t io n ) - - > v o l _ as p e ct ; v o l_ a s p ec t ( vo l _ a sp e c t. d e t ai l e d ) - - > v o l _ co n t ro l ; v o l_ a s p ec t ( ge n e r ic _ d on e ) - - > v o l _ co n t ro l ; v o l_ c o n tr o l ( vo l _ c on t r ol . d e ta i l e d ) - - > v o l _ vb v ; v o l_ c o n tr o l ( ge n e r ic _ d on e _ w it h _ b it r e a d ) - - > v o l _ sh a p e; v o l_ v b v ( vo l _ v bv . d et a i l ed ) - - > v o l _ sh a p e; v o l_ v b v ( ge n e r ic _ d on e _ w it h _ b it r e a d ) - - > v o l _ sh a p e; v o l_ s h a pe ( vo l _ s ha p e ) - - > v o l _ ti m e _i n c _ re s ; v o l_ t i m e_ i n c_ r e s ( vo l _ t im e _ in c _ r es ) - - > v o l _ wi d t h; v o l_ w i d th ( vo l _ w id t h ) - - > v o l _ he i g ht ; v o l_ h e i gh t ( vo l _ h ei g h t ) - - > v o l _ mi s c ; / / v o l _ mi s c ( v o l_ m i sc . u n su p p o rt e d ) -- > s tu c k ; v o l_ m i s c ( ge n e r ic _ d on e ) - - > l o o k _f o r _v o p ;

/ / P r o c es s a n e w V O P l o ok _ f o r_ v o p ( by t e _ al i g n ) - - > g e t _ vo p _ co d e ; g e t_ v o p _c o d e ( ge t _ v op _ c od e ) - - > v o p _ co d e ; v o p_ c o d e ( vo _ h e ad e r .g o o d ) - - > l o o k _f o r _v o l ; / / DB P : pe r m it c o nc a t e na t i o n o f s e q u en c e s w i t h ou t pr o p e r e n d c o d e v o p_ c o d e ( vo p _ c od e . do n e ) - - > l o o k _f o r _v o ; / / DB P : st a r t f r o m t h e b e g i nn i n g v o p_ c o d e ( vo p _ c od e . st a r t ) - - > v o p _ pr e d ic t ; v o p_ c o d e ( ge n e r ic _ d on e ) - - > s t u c k; v o p_ p r e di c t ( vo p _ p re d i ct / * . s u p po r t e d * / ) - - > v o p _ ti m e ba s e ; / / v o p _ pr e d ic t ( g e ne r i c_ d o n e ) -- > s tu c k ; v o p_ t i m eb a s e ( vo p _ t im e b as e . o ne ) - - > v o p _ ti m e ba s e ; v o p_ t i m eb a s e ( vo p _ t im e b as e . z er o ) - - > v o p _ co d i ng ; v o p_ c o d in g ( vo p _ c od i n g. u n c od e d ) - - > l o o k _f o r _v o p ;v op _ c o di n g ( v o p _ co d i n g. c o de d ) - - > s e n d_ n e w _v o p _i n f o ;s en d _ n ew _ v o p_ i n fo ( s e n d _n e w _ vo p _ cm d ) - - > s e n d_ n e w _v o p _w i d t h;s en d _ n ew _ v o p_ w i dt h ( s e n d _n e w _ vo p _ wi d t h ) - - > s e n d_ n e w _v o p _h e i g ht ;s en d _ n ew _ v o p_ h e ig h t ( s e n d _n e w _ vo p _ he i g h t ) - - > m b ;

/ / S t a r t M B m b ( m b _d o n e ) - - > l o ok _ f o r_ v o p ;m b ( m c b p c_ p v o p_ u n c od e d ) - - > pv o p _u n c o de d 1 ;p vo p _ u nc o d e d1 ( m c b p c_ p v o p_ u n c od e d 1 ) - - > pv o p _u n c o de d 2 ;p vo p _ u nc o d e d2 ( m c b p c_ p v o p_ u n c od e d 1 ) - - > pv o p _u n c o de d 3 ;p vo p _ u nc o d e d3 ( m c b p c_ p v o p_ u n c od e d 1 ) - - > pv o p _u n c o de d 4 ;p vo p _ u nc o d e d4 ( m c b p c_ p v o p_ u n c od e d 1 ) - - > pv o p _u n c o de d 5 ;p vo p _ u nc o d e d5 ( m c b p c_ p v o p_ u n c od e d 1 ) - - > mb ; m b ( g e t_ m c b pc ) - - > g e t_ m b t yp e ; g e t_ m b t yp e ( v l d_ f a i lu r e ) - - > s t uc k ; g e t_ m b t yp e ( g e t_ m b t yp e ) - - > f i na l _ c bp y ; f i na l _ c bp y ( v l d_ f a i lu r e ) - - > s t uc k ; f i na l _ c bp y ( f i na l _ c bp y _ i nt r a ) - - > b l oc k ; f i na l _ c bp y ( f i na l _ c bp y _ i nt e r ) - - > m v ; / / p r o c es s al l b lo c k s i n a n M B b l oc k ( m b _ di s p a tc h _ d on e ) - - > m b ; b l oc k ( m b _ di s p a tc h _ i nt r a ) - - > t e x tu r e ; b l oc k ( m b _ di s p a tc h _ i nt e r _a c _ c od e d ) - - > t e x tu r e ; b l oc k ( m b _ di s p a tc h _ i nt e r _n o _ a c ) - - > b l o ck ;

/ / S t a r t t e xt u r e t e xt u r e ( v l d _s t a r t_ i n t ra ) - - > g e t _d c _ b it s ; t e xt u r e ( v l d _s t a r t_ i n t er ) - - > t e x ac ; g e t_ d c _ bi t s ( g e t_ d c _ bi t s . no n e ) - - > t e x ac ; g e t_ d c _ bi t s ( g e t_ d c _ bi t s . so m e ) - - > g e t _d c ; g e t_ d c _ bi t s ( v l d_ f a i lu r e ) - - > s t u ck ; g e t_ d c ( d c _b i t s _s h i f t ) - - > g e t _d c _ a ; g e t_ d c _ a ( g e t_ d c ) - - > t e x ac ; t e xa c ( b l oc k _ d on e ) - - > b l o ck ; t e xa c ( d c t_ c o e ff ) - - > v l d 1; v l d1 ( v l d_ c o d e ) - - > t e x ac ; v l d1 ( v l d_ l e v el ) - - > v l d 4; v l d1 ( v l d_ r u n _o r _ d ir e c t ) - - > v l d 7; v l d7 ( v l d_ r u n ) - - > v l d 6; v l d7 ( v l d_ d i r ec t _ r ea d ) - - > v l d _d i r e ct ; v l d1 ( v l d_ f a i lu r e ) - - > s t u ck ; v l d_ d i r ec t ( v l d_ d i r ec t ) - - > t e x ac ; v l d4 ( do _ l ev e l _ lo o k u p ) -- > v ld 4 a ; v l d4 ( vl d _ fa i l u re ) - - > st u c k ; v l d4 a ( v l d _l e v e l_ l o o ku p ) - - > t e x a c; v l d6 ( do _ r un _ l o ok u p ) - - > vl d 6 a ; v l d6 ( vl d _ fa i l u re ) - - > st u c k ; v l d6 a ( v l d _r u n _ lo o k u p ) - - > t e x a c;

/ / m v ( ) m v ( m v c od e _ d on e ) - - > b l oc k ; m v ( m v c od e ) - - > m a g_ x ; m a g_ x ( v l d _f a i l ur e ) - - > s t uc k ; m a g_ x ( m a g _x ) - - > g e t_ r e si d u a l_ x ; g e t_ r e s id u a l_ x ( g e t _r e s i du a l _x ) - - > m v _y ; m v _y ( m v c od e ) - - > m a g_ y ; m a g_ y ( v l d _f a i l ur e ) - - > s t uc k ; m a g_ y ( m a g _y ) - - > g e t_ r e si d u a l_ y ; g e t_ r e s id u a l_ y ( g e t _r e s i du a l _y ) - - > m v ;

/ / s t u c k( s tu c k ) - - > s t u c k_ f o r_ g o o d; / / D B P : a d d m i n i ma l e rr o r re s i li e n c e. / / b y t e a l i gn , t he n l oo k f or a V O h ea d e r s t a r ti n g o n a ny b y te b o un d a ry . / / C a n ' t h a nd l e bi t i ns e r t io n or d e le t i o n, o b vi o u sl y . Th e V O h e a de r / / i s h ex 0 00 0 0 1 00 . s t uc k ( by t e _ al i g n ) - - > s t u ck _ 1 a ;

s t uc k _ 1 a ( re q u e st _ b y te ) - - > s t u ck _ 1 b ; s t uc k _ 1 b ( te s t _ ze r o _ by t e ) - - > s t u ck _ 2 a ; s t uc k _ 1 b ( ge n e r ic _ d o ne ) - - > s t u ck _ 1 a ;

s t uc k _ 2 a ( re q u e st _ b y te ) - - > s t u ck _ 2 b ; s t uc k _ 2 b ( te s t _ ze r o _ by t e ) - - > s t u ck _ 3 a ; s t uc k _ 2 b ( ge n e r ic _ d o ne ) - - > s t u ck _ 1 a ;

s t uc k _ 3 a ( re q u e st _ b y te ) - - > s t u ck _ 3 b ; s t uc k _ 3 b ( te s t _ ze r o _ by t e ) - - > s t u ck _ 3 a ; s t uc k _ 3 b ( te s t _ on e _ b yt e ) - - > s t u ck _ 4 a ; s t uc k _ 3 b ( ge n e r ic _ d o ne ) - - > s t u ck _ 1 a ;

s t uc k _ 4 a ( re q u e st _ b y te ) - - > s t u ck _ 4 b ; s t uc k _ 4 b ( te s t _ ze r o _ by t e ) - - > r e q ue s t _ vo l ; // F ou n d a g o o d V O he a d er ( A ss u m e s V O ID f ie l d = 0) s t uc k _ 4 b ( ge n e r ic _ d o ne ) - - > s t u ck _ 1 a ;

r e qu e s t _v o l ( r e qu e s t _v o l ) - - > l o o k_ f o r _v o l ;

e n d

p r i o ri t y v o _h e a d er . g oo d > ge n e ri c _ d on e ; v o l_ a s p ec t . de t a i le d > ge n e ri c _ d on e ; v o l_ c o n tr o l .d e t a il e d > ge n e ri c _ d on e _ w it h _ b it r e ad ; v o l_ v b v .d e t ai l e d > ge n e ri c _ d on e _ w it h _ b it r e ad ; / / v o l _ mi s c .u n s u pp o r t ed > g en e r i c_ d o n e;

v o p_ c o d e. d o ne > ge n e ri c _ d on e ; v o p_ c o d e. s t ar t > ge n e ri c _ d on e ; / / v o p _ pr e d ic t . s up p o r te d > g en e r i c_ d o n e; v o p_ t i m eb a s e. o n e > vo p _ ti m e b as e . z er o ; v o p_ c o d in g . un c o d ed > vo p _ co d i n g. c o d ed ; m b _d o n e > g et _ m c bp c ; m b _d o n e > m cb p c _ pv o p _ un c o d ed ; g e t_ m c b pc . p vo p > m c b p c_ p v o p_ u n co d e d ;

g e t_ m b t yp e . no a c > g e t _m b t y pe . a c; f i na l _ c bp y _ in t e r > f i na l _ c bp y _ in t r a ; m b _d i s p at c h _d o n e > m b _d i s p at c h _i n t r a > m b _d i s p at c h _i n t e r_ n o _ ac > mb _ d is p a t ch _ i n te r _ a c_ c o de d ;

v l d_ s t a rt _ i nt r a > v l d _s t a r t_ i n te r ; g e t_ d c _ bi t s .n o n e > g e t_ d c _ bi t s .s o m e ; b l oc k _ d on e > d c t _c o e f f; v l d_ c o d e > vl d _ l ev e l > v l d _r u n _o r _ d ir e c t ; v l d_ r u n > v ld _ d i re c t _ re a d ;

v l d_ s t a rt _ i nt e r . ac _ c o de d > v l d _s t a r t_ i n t er . n o t_ a c _c o d e d;

m v co d e _ do n e > m v co d e ; t e st _ z e ro _ b yt e > g e n e ri c _ d on e ; t e st _ o n e_ b y te > g e n e ri c _ d on e ; e n d

e nd

/* BE G I N CO P Y R IG H T X

Co p y r ig h t (c ) 20 0 4 - 20 0 6 , X i l i nx I nc .Al l r ig h t s r e s er v e d .

Re d i s tr i b u ti o n a n d us e i n s o u rc e an d b in a r y f o r m s, wi t h or w i th o u t m o d if i c a ti o n , a r e p e r m it t e d p r o v id e d th a t th e f ol l o wi n g co n d i ti o n s a r e m e t :- R e d is t r i bu t i on s o f s o u rc e c od e mu s t re t a i n t h e a b o ve c o p yr i g ht n o ti c e , t h i s l i s t o f co n d i ti o n s a n d th e f o l lo w i ng d i sc l a i me r .- R e d is t r i bu t i on s i n b i n ar y f or m mu s t re p r o du c e th e a b o ve c op y r i gh t n ot i c e , t h i s l i st o f c o n d it i o n s a n d t h e f o l lo w i n g d i s cl a i m er i n t h e d o c u me n t a ti o n an d / or o t h er m at e r i al s p ro v i d ed w i th t he d i st r i b ut i o n .- N e i th e r th e na m e of t h e c o p yr i g ht h o ld e r no r t he n am e s o f it s co n t r ib u t o rs m a y b e us e d t o e nd o r s e o r pr o m ot e p r o du c t s d e r iv e d fr o m th i s so f t wa r e wi t h o ut s p ec i f ic p r i or w ri t t e n p e r mi s s i on .TH I S SO F T W AR E IS P R OV I D E D B Y TH E CO P Y R IG H T HO L D E RS A ND CO N T R IB U T O RS " AS I S " A N D A N Y EX P R ES S O R I M P LI E D WA R R AN T I E S, IN C L U DI N G , B U T N O T LI M I T ED T O , T H E I M P LI E D WA R R A NT I E S O F ME R C H AN T A B IL I T Y A N D F I T N ES S F OR A P A R T IC U L A R P U R PO S E A R E DI S C L AI M E D . I N N O E VE N T SH A L L T H E C O P Y RI G H T O W N E R O R CO N T R IB U T O RS B E L I A BL E F OR A N Y D I RE C T , I N D I RE C T , I N C ID E N T AL , SP E C I AL , E XE M P LA R Y , O R C ON S E Q UE N T IA L D AM A G E S ( I N CL U D IN G , BU T NO T L IM I T E D T O , P R O CU R E M EN T O F S U BS T I T UT E G OO D S OR S ER V I C ES ; LO S S OF U S E, D AT A , OR P R OF I T S ; O R B U S I NE S S IN T E R RU P T IO N ) HO W E V ER C A US E D A N D ON A N Y T H E OR Y OF L I AB I L I TY , W HE T H ER I N CO N T R AC T , ST R I CT L I AB I L I TY , O R T O RT ( I NC L U D IN G N EG L I GE N C E O R OT H E R WI S E ) A R I SI N G IN A N Y W A Y O U T O F T HE U S E O F TH I S SO F T W AR E , EV E N I F A DV I S E D O F TH E PO S S I BI L I T Y O F SU C H D A M A GE .EN D C O PY R I G HT*/// P a rs e H e ad e r s. c a l//// A u th o r : D a v id B . P a r l ou r ( da v e .p a r l ou r @ x il i n x .c o m )//

im p o r t a l l c a l tr o p . li b . B it O p s ;

// B T YP E O ut p u t// A si n g l e s t re a m of c o nt r o l t o k en s i s s e n t o n th e BT Y P E o u t p ut t o d i s tr i b u te// V O P a n d b l o ck t y pe i n fo r m a ti o n . A m in i m u m o f 12 b it s i s r e q ui r e d f o r t h i s t o k e n,// w h ic h a ls o se n d s t h e VO P w id t h a n d he i g h t p a r am e t er s . Th e r el e v a nt p ar a m e te r s ar e :

// M B_ C O O RD _ S Z - s i z e o f a ny v ar i a b le t h at c o nt a i ns a ma c r o bl o c k c o o rd i n a te// B TY P E _ SZ - s i ze o f t h e BT Y P E o u t pu t ( mi n . 12 )// B it s t o s i gn a l to k e n t y p e// N EW V O P 2 0 4 8// I NT R A 1 0 2 4// I NT E R 5 1 2

// I f t h e N E W VO P b it s i s s e t , t h e f o l lo w i n g f i e ld c an b e m a s k ed o f f:// Q UA N T _ MA S K 31// R OU N D _ TY P E 32// F CO D E _ MA S K 4 48// F CO D E _ SH I F T 6

// T he n e xt t wo t o ke n s af t e r N E W VO P a re t h e w i d th a nd h e ig h t in m a cr o b lo c k s

// T he I N TE R ty p e al s o ha s// A CP R E D 1// A CC O D E D 2// F OU R M V 4// M OT I O N 8// T he I N TR A ty p e al s o ha s A CP R E D

ac t o r P a r s eH e a de r s ( / / M a x im u m im a g e w i d t h ( i n u n i ts o f m a c r ob l o ck s ) th a t t h e d ec o d er c a n h a nd l e . / / I t is u s ed t o a l l o ca t e l i n e b u f fe r s p ac e at c o mp i l e t i m e . i nt M A XW _ I N _M B ,

i n t M B _ CO O R D _S Z , i n t B T Y PE _ S Z , i n t M V _ SZ , i n t N E W VO P , i n t I N T RA , i n t I N T ER , i n t Q U A NT _ M A SK , i n t R O U ND _ T Y PE , i n t F C O DE _ M A SK , i n t F C O DE _ S H IF T , i n t A C P RE D , i n t A C C OD E D , i n t F O U RM V , i n t M O T IO N , i n t S A M PL E _ C OU N T _ SZ , i n t S A M PL E _ S Z ) b o ol b it s = => i n t( s i z e= B T YP E _ S Z) B T YP E , in t ( si z e = MV _ S Z ) M V , i n t (s i z e =S A M P LE _ C O UN T _ SZ ) R UN , i nt ( s i ze = S AM P L E _S Z ) VA L U E , b o ol L A ST :

/ / Co n s ta n t s f o r va r i o us f i el d le n g t hs ( b it s ) an d sp e c i al v a lu e s .

i n t V O _ HE A D E R_ L E N GT H = 2 7 ; i n t V O _ NO _ S H OR T _ H EA D E R = 8 ; i n t V O _ ID _ L E NG T H = 5 ;

i n t V O L _S T A R T_ C O D E_ L E N GT H = 2 8 ; i n t V O L _S T A R T_ C O D E = 1 8 ; i n t V O L _I D _ L EN G T H = 5 ; i n t V I D EO _ O B JE C T _ TY P E _ IN D I C AT I O N_ L E N GT H = 8 ; i n t V I S UA L _ O BJ E C T _L A Y E R_ V E R ID _ L EN G T H = 4 ; i n t V I S UA L _ O BJ E C T _L A Y E R_ P R I OR I T Y_ L E N GT H = 3 ; i n t A S P EC T _ R AT I O _ IN F O _ LE N G T H = 4 ; i n t A S P EC T _ R AT I O _ IN F O _ IS _ D E TA I L ED = 1 5 ; i n t P A R _W I D T H_ L E N GT H = 8 ; i n t P A R _H E I G HT _ L E NG T H = 8 ; i n t C H R OM A _ F OR M A T _L E N G TH = 2 ; i n t L O W _D E L A Y_ L E N GT H = 1 ; i n t F I R ST _ H A LF _ B I T_ R A T E_ L E N GT H = 1 5 ; i n t L A S T_ H A L F_ B I T _R A T E _L E N G TH = 1 5 ; i n t F I R ST _ H A LF _ V B V_ B U F _S Z _ L EN G T H = 1 5 ; i n t L A S T_ H A L F_ V B V _B U F _ SZ _ L E NG T H = 3 ; i n t F I R ST _ H A LF _ V B V_ O C C _L E N G TH = 1 1 ; i n t L A S T_ H A L F_ V B V _O C C _ LE N G T H = 1 5 ; i n t V O L _S H A P E_ L E N GT H = 2 ; i n t M A R KE R _ L EN G T H = 1 ; i n t T I M E_ I N C _R E S _ LE N G T H = 1 6 ; i n t V O L _W I D T H_ L E N GT H = 1 3 ; i n t V O L _H E I G HT _ L E NG T H = 1 3 ;

/ / i nt T IM E _ I NC _ R E S_ M A S K = l s hi f t ( 1 , TI M E _ IN C _ R ES _ L EN G T H ) - 1; / / No t e : m a s k o f f w i d t h, h e ig h t i n u ni t s of M B s, n ot p i xe l s / / i nt V OL _ W I DT H _ M AS K = l s hi f t ( 1 , VO L _ W ID T H _ LE N G TH - 4 ) - 1; / / i nt V OL _ H E IG H T _ MA S K = l s hi f t ( 1 , VO L _ H EI G H T _L E N GT H - 4 ) - 1; / / i nt A SP E C T _R A T I O_ I N F O_ M A S K = l s hi f t ( 1 , AS P E C T_ R A T IO _ I NF O _ L EN G T H ) - 1;

i n t R U N _L E N G TH = 6 ; i n t R U N _M A S K = l s h i ft ( 1, R U N_ L E N GT H ) - 1 ; i n t L E V EL _ L E NG T H = 1 2 ; i n t L E V EL _ M A SK = l s h i ft ( 1, L E VE L _ L EN G T H ) - 1 ;

/ / co u n t o f mi s c VO L b it s : / / i nt e r l ac e d O B M C_ d i s ab l e d v o l_ s p r it e _ u sa g e n o t_ 8 _ b it / / v ol _ q u an t _ t yp e c o m pl e x i ty _ e s t_ d i s ab l e r e sy n c _ ma r k e r_ d i sa b l e d a ta _ p a rt i t io n i n g_ e n a bl e / / s ca l a b il i t y / / No t e : W e as s u m e d a t a_ p a r ti t i on i n g _e n a b le i s a l w ay s f al s e , s o t he m od e l / / d o e s n o t d o a c o n d it i o na l r ea d o f r e v er s i bl e _ v lc _ e n ab l e i n t M I S C_ B I T _L E N G TH = 9;

i n t V O P _S T A R T_ C O D E_ L E N GT H = 3 2 ; i n t V O P _S T A R T_ C O D E = 4 3 8 ; i n t V O P _P R E D IC T I O N_ L E N GT H = 2 ; i n t B _ V OP = 2 ; i n t P _ V OP = 1 ; i n t I _ V OP = 0 ; i n t I N T RA _ D C _V L C _ TH R _ L EN G T H = 3 ; i n t V O P _F C O D E_ F O R _L E N G TH = 3 ; i n t V O P _F C O D E_ F O R _M A S K = l s h if t ( 1, V OP _ F C OD E _ F OR _ L E NG T H ) - 1; i n t B I T S_ Q U A NT = 5 ; i n t B I T S_ Q U A NT _ M A SK = l s h if t ( 1, B IT S _ Q UA N T ) - 1; i n t M C B PC _ L E NG T H = 9 ; i n t E S C AP E _ C OD E = 7 1 6 7;

f u n ct i o n m a s k_ b i t s( v , n ) -- > in t : b it a n d ( v , ls h i ft ( 1 , n )- 1 ) e n d / / Ut i l it y a ct i o n t o r ea d a s p e ci f i e d n u m be r o f b i ts . / / Th i s i s a n u n n am e d ac t i o n, i e i t is a l wa y s en a b le d a nd h a s h i g he s t p r i o ri t y . / / Us e th e p ro c e d ur e s se t _ b it s _ to _ r e ad ( ) to s t ar t re a d i ng , t es t f or / / co m p le t i o n w i t h t h e b o o l ea n do n e _ re a d i ng _ b i ts ( ) a n d ge t t he v a lu e / / wi t h r e a d _r e s u lt ( ) . U s e th e do n e fu n c t io n i n a gu a r d t o w ai t f or t he / / re a d in g t o b e co m p l et e . i n t (s i z e= 7 ) bi t s _ to _ r e ad _ c o un t := - 1 ; i n t (s i z e= 3 3 ) r e a d _r e s u lt _ i n _p r o gr e s s ; p r o ce d u re s e t_ b i t s_ t o _ re a d ( i n t c o u n t ) b e g in b it s _ t o_ r e a d_ c o un t : = c o u nt - 1; r ea d _ r es u l t _i n _ pr o g r e ss : = 0 ; e n d f u n ct i o n d o n e_ r e a di n g _ bi t s ( ) - - > b o o l : b it s _ t o_ r e ad _ c o un t < 0 e n d f u n ct i o n r e a d_ r e s ul t ( ) - - > in t : r e a d_ r e s ul t _ i n_ p r og r e s s e n d a c t io n bi t s : [ b ] = = > g u a rd n ot d o ne _ r e ad i n g_ b i t s () d o r ea d _ r es u l t _i n _ pr o g r e ss : = b i t or ( ls h i f t ( r e ad _ r e su l t _i n _ p r og r e ss , 1 ), i f b t he n 1 e l s e 0 e nd ) ; b it s _ t o_ r e a d_ c o un t : = b i t s_ t o _ re a d _c o u n t - 1 ; b it _ c o un t : = b i t_ c o u n t + 1; e n d

i n t (s i z e= 4 ) bi t _ c ou n t := 0 ;

/* * * * ** * * * ** * * ** * * * ** * * * ** * * * ** * * ** * * * ** * * * ** * * * ** * * ** * * * ** * * * * * * * ** * * ** * * * ** * * * ** * * * ** * * ** * * * ** * * * ** * * * ** * * ** * * * ** * * * ** * * * * * * * ** * * s ta r t VO L * * * ** * * * * * * * ** * * ** * * * ** * * * ** * * * ** * * ** * * * ** * * * ** * * * ** * * ** * * * ** * * * ** * * * * * * * ** * * ** * * * ** * * * ** * * * ** * * ** * * * ** * * * ** * * * ** * * ** * * * ** * * * ** * * * /

/ / DB P : m o d i fi e d to s u pp o r t o n l y V O _ NO _ S H OR T _ H EA D E R l o o k_ f o r_ v o : a c t i on = = > d o s et _ b i ts _ t o _r e a d( V O _ HE A D ER _ L E NG T H + V O _ ID _ L EN G T H ) ; e n d

/ / We c an o n ly h a nd l e VO L w it h o ut s h or t h ea d e r v o _ he a d er . g o od : a ct i o n = = > g u a rd d on e _ r ea d i n g_ b i ts ( ) , m as k _ b it s ( rs h i ft ( r e ad _ r es u l t () , VO _ I D _ LE N G TH ) , V O _ HE A D E R _L E N GT H ) = V O_ N O _ SH O R T _H E A D ER d o s et _ b i ts _ t o _r e a d( V O L _S T A RT _ C O DE _ L EN G T H ); e n d v o l _s t a rt c o d e. g o o d: a c ti o n == > g u a rd d on e _ r ea d i n g_ b i ts ( ) , m as k _ b it s ( re a d _r e s u l t( ) , V O L _ ST A R T_ C O D E _L E N GT H ) = V OL _ S T A RT _ C OD E d o / / I g n or e t he n ex t t w o f i el d s s et _ b i ts _ t o _r e a d( V O L _I D _ LE N G T H + VI D E O _ OB J E CT _ T Y PE _ I ND I C A T IO N _ LE N G T H ) ; e n d

v o l _o b j ec t _ l ay e r _ id e n t if i c a ti o n : a c t io n b it s : [ b] = => g u a rd d on e _ r ea d i n g_ b i ts ( ) d o s et _ b i ts _ t o _r e a d( i f b t h en / / i s _o b j e ct _ l a ye r _ i de n t if i e r a s s e rt e d V IS U A L_ O B J EC T _ L AY E R _ VE R I D_ L E N GT H + V I S U AL _ O BJ E C T _L A Y E R_ P R I OR I T Y_ L E N GT H + A S P E CT _ R AT I O _ IN F O _ LE N G T H e l s e A SP E C T_ R A T IO _ I N FO _ L E NG T H e n d ) ; b it _ c o un t : = b i t_ c o u n t + 1; e n d

v o l _a s p ec t . d et a i l ed : a ct i o n = = > g u a rd d on e _ r ea d i n g_ b i ts ( ) , m as k _ b it s ( re a d _r e s u l t( ) , A S P E CT _ R AT I O _ I NF O _ LE N G T H ) = A S P E CT _ R AT I O _ IN F O _I S _ D ET A I L ED d o / / S k i p o v e r a s pe c t r at i o d e t a il s s et _ b i ts _ t o _r e a d( P A R _W I D TH _ L E NG T H + P A R _H E I GH T _ L EN G T H ) ; e n d

v o l _c o n tr o l . de t a i le d : ac t i o n b i ts : [ b ] = = > g u a rd d on e _ r ea d i n g_ b i ts ( ) , b d o s et _ b i ts _ t o _r e a d( C H R OM A _ FO R M A T_ L E NG T H + L O W _D E L A Y_ L E NG T H ) ; b it _ c o un t : = b i t_ c o u n t + 1; e n d v o l _v b v .d e t a il e d : a c t i on b i ts : [ b] = = > g u a rd d on e _ r ea d i n g_ b i ts ( ) , b d o s et _ b i ts _ t o _r e a d( F IR S T _H A L F _B I T _R A T E _ LE N G TH + M AR K E R _ LE N G TH + LA S T _H A L F _B I T _ RA T E _ LE N G TH + M AR K E R _L E N GT H + FI R S T_ H A L F_ V B V _B U F _ SZ _ L EN G T H + M AR K E R _L E N GT H + LA S T _H A L F _V B V _ BU F _ S Z_ L E NG T H + FI R S T_ H A L F_ V B V _O C C _ LE N G TH + M AR K E R _L E N GT H + LA S T _H A L F _V B V _ OC C _ L EN G T H + M AR K E R _L E N GT H ) ; b it _ c o un t : = b i t_ c o u n t + 1; e n d

v o l _s h a pe : a ct i o n = = > g u a rd d on e _ r ea d i n g_ b i ts ( ) d o s et _ b i ts _ t o _r e a d( V O L _S H A PE _ L E NG T H + M A R KE R _ LE N G T H + TI M E _ I NC _ R ES _ L E NG T H + M A RK E R _ LE N G T H + 1 ) ; e n d

i n t (s i z e= 7 ) my l o g ;

v o l _t i m e_ i n c _r e s : a c t i on = = > g u a rd d on e _ r ea d i n g_ b i ts ( ) v a r i nt ( s i ze = T I ME _ I NC _ R E S _L E N GT H + 1 ) t i me _ i n c _r e s : = m as k _ bi t s ( rs h i ft ( r ea d _ re s u l t( ) , 2 ) , TI M E _I N C _ RE S _ L EN G T H ) , / / p ic k o ut t h e t i me _ i n c _r e s f i e l d i nt ( s i ze = 7 ) c o u nt : = 0, i nt ( s i ze = 7 ) o n e s : = 0 d o w hi l e ( c o u nt = 0 o r ti m e _i n c _ re s != 0 ) d o i f b it a n d( t i me _ i n c_ r e s , 1 ) = 1 t h e n o ne s : = o n e s + 1 ; e n d c o u n t : = c o u n t + 1 ; t i m e _i n c _r e s := r s hi f t ( t i m e_ i n c _r e s , 1 ) ; e nd m yl o g := i f o n e s > 1 th e n c o u n t e l se c o u nt - 1 e n d; m yl o g := i f m y l og < 1 t h e n 1 e ls e my l o g en d ; s et _ b i ts _ t o _r e a d( i f b it a n d( r e ad _ r es u l t ( ), 1 ) = 1 t h en / / f ix e d v o p ra t e / / m y lo g + M A R KE R _ L EN G T H m y l o g e ls e / / v ar i a bl e v op r a te / / M A RK E R _L E N G TH 0 e nd + MA R K E R_ L E NG T H + V O L _W I D T H_ L E NG T H + M A R KE R _ L EN G T H ) ; e n d

/ / Th e vo l w id t h an d h ei g h t i n un i t s o f m ac r o b lo c k s, i e . t h e p i x e l w / h d i v id e d by 1 6 . / / No t e : t h e re i s n o p ro v i s io n in t h e m o d el f o r p i xe l s iz e s th a t ar e no m u lt i p l es o f 1 6 . i n t (s i z e= M B _ CO O R D _S Z ) vo l _ w id t h ; i n t (s i z e= M B _ CO O R D _S Z ) vo l _ h ei g h t;

v o l _w i d th : a ct i o n = = > g u a rd d on e _ r ea d i n g_ b i ts ( ) d o v ol _ w i dt h := m as k _ b i ts ( rs h i f t( r ea d _ r e su l t () , M AR K E R_ L E N G TH + 4 ) , V O L _W I D T H_ L E N GT H - 4 ) ; // s t ri p m ar k e r a n d d i v i de b y 1 6 s et _ b i ts _ t o _r e a d( V O L _H E I GH T _ L EN G T H + M A RK E R _L E N G TH ) ; e n d

v o l _h e i gh t : ac t i o n = = > g u a rd d on e _ r ea d i n g_ b i ts ( ) d o v ol _ h e ig h t : = ma s k _ b it s ( r s h i ft ( re a d _ r es u l t( ) , MA R K ER _ L E N GT H + 4 ), V OL _ H E IG H T _ LE N G T H ) ; / / s tr i p ma r k e r a n d d i v id e b y 1 6 s et _ b i ts _ t o _r e a d( M I S C_ B I T_ L E N GT H ); e n d

/ / De t e ct u n su p p o rt e d fe a t u re s : / / in t e rl a c e d, s p ri t e s , n o t 8 - b it p i xe l s , n o t us i n g m e t ho d 2 q u a n ti z a ti o n , d a t a p a r t it i o ni n g , s c a l ab i l i ty / / vo l _ mi s c . un s u p po r t e d: a c ti o n = = > / / gu a r d / / d o ne _ r e ad i n g _b i t s () , / / t e s t m a s k i s 9 - b i t b i n ar y 1 01 1 1 00 1 1 / / b i ta n d ( r e a d _r e s u lt ( ) , 3 7 1 ) ! = 0 / / en d

/* * * * ** * * * ** * * ** * * * ** * * * ** * * * ** * * ** * * * ** * * * ** * * * ** * * ** * * * ** * * * * * * * ** * * ** * * * ** * * * ** * * * ** * * ** * * * ** * * * ** * * * ** * * ** * * * ** * * * ** * * * * * * * ** * * s ta r t VO P * * * ** * * * * * * * ** * * ** * * * ** * * * ** * * * ** * * ** * * * ** * * * ** * * * ** * * ** * * * ** * * * ** * * * * * * * ** * * ** * * * ** * * * ** * * * ** * * ** * * * ** * * * ** * * * ** * * ** * * * ** * * * ** * * * /

b y t e_ a l ig n : ac t i o n = = > d o s et _ b i ts _ t o _r e a d( 8 - b i t an d ( bi t _ co u n t , 7 ) ) ; e n d

/ / No t e : n o ch e c k f o r co r r e ct b it s t uf f i n g

g e t _v o p _c o d e : a c t io n = => g u a rd d on e _ r ea d i n g_ b i ts ( ) d o s et _ b i ts _ t o _r e a d( V O P _S T A RT _ C O DE _ L EN G T H ); e n d

/ / No t e : t h e m o d e l d o e s n o t s u p po r t us e r da t a he r e v o p _c o d e. d o n e: a c ti o n == > g u a rd d on e _ r ea d i n g_ b i ts ( ) , r ea d _ r es u l t () = 1 d o b it _ c o un t : = 0 ; e n d i n t (s i z e= M B _ CO O R D _S Z ) mb x ; i n t (s i z e= M B _ CO O R D _S Z ) mb y ;

v o p _c o d e. s t a rt : a ct i o n = = > g u a rd d on e _ r ea d i n g_ b i ts ( ) , r ea d _ r es u l t () = V O P _ S TA R T _C O D E

d o m b x : = 0 ; m b y : = 0 ; s e t _b i t s_ t o _ re a d ( V O P _ PR E D I CT I O N_ L E N GT H ) ; en d

// i n t( s i z e= 2 ) p r e d ic t i o n_ t y p e;

// v o p_ p r e di c t .s u p p or t e d : a c t io n == > // g u ar d // do n e _ re a d in g _ b it s ( ) , // ma s k _ bi t s ( r e a d_ r e s ul t ( ) , V O P_ P R E DI C T I ON _ L E NG T H ) = I_ V O P o r // ma s k _ bi t s ( r e a d_ r e s ul t ( ) , V O P_ P R E DI C T I ON _ L E NG T H ) = P_ V O P // d o // pr e d i ct i o n_ t y p e : = re a d _ re s u lt ( ) ; // e n d

bo o l pr e d i ct i o n_ i s _ IV O P ;

vo p _ p re d i c t: a ct i o n = = > gu a r d d o n e_ r e ad i n g _b i t s () do p r e di c t io n _ i s_ I V O P : = ma s k _ bi t s ( r e a d_ r e s ul t ( ) , V O P_ P R E DI C T I ON _ L E NG T H ) = I_ V O P ; en d // N o te : t he m od e l do e s no t s up p o rt t i me _ b a se . I t j u st s k ip s o ve r t he r ig h t nu m b e r o f bi t s . vo p _ t im e b a se . o ne : a ct i o n b i t s :[ b ] = = > gu a r d b do / / Sk i p o v e r m o d u le - t i me _ b a se b i t _c o u nt : = b i t _ co u n t + 1 ; en d vo p _ t im e b a se . z er o : a ct i o n b i t s :[ b ] = = > do b i t _c o u nt : = b i t _ co u n t + 1 ; s e t _b i t s_ t o _ re a d ( M A R K ER _ L E NG T H + m y lo g + M A R K ER _ L EN G T H ) ; en d

in t ( s iz e = 4 ) c o mp ;

// T O DO : t he m od e l do e s no t c om m u ni c a t e t o th e d is p l ay d r iv e r // t o r e - u se t he c u rr e n t V O P in p la c e of t h e u n c od e d o n e . vo p _ c od i n g .u n c od e d : a c t i on b i ts : [ b] = = > gu a r d d o n e_ r e ad i n g _b i t s () , n o t b do c o m p : = 0 ; b i t _c o u nt : = b i t _ co u n t + 1 ; en d

vo p _ c od i n g .c o d ed : a ct i o n b i t s :[ b ] = = > gu a r d d o n e_ r e ad i n g _b i t s () do s e t _b i t s_ t o _ re a d ( if n ot p r ed i c t io n _ i s_ I V OP t h en / / ro u n d_ t y p e, i n tr a _ d c_ v l c _t h r [3 ] , vo p _ q ua n t [ 5] , vo p _ f co d e _ fo r [ 3 ] 1 + I N T RA _ D C _V L C _ TH R _ L EN G T H + B IT S _ Q UA N T + V O P _F C O DE _ F O R_ L E N GT H el s e / / in t r a_ d c _ vl c _ t hr [ 3 ] , v o p _q u a nt [ 5 ] I N T RA _ D C_ V L C _T H R _ LE N G T H + B IT S _ QU A N T en d ); b i t _c o u nt : = b i t _ co u n t + 1 ; en d

// i n t( s i z e= 1 0 ) r e s yn c _ m ar k e r _l e n gt h ; in t ( s iz e = V OP _ F CO D E _ FO R _ L EN G T H +1 ) fc o d e ;

se n d _ ne w _ v op _ c md : a ct i o n = = > BT Y P E: [ c md ] gu a r d d o n e_ r e ad i n g _b i t s () va r b o o l r o un d : = f a l se , i n t (s i z e= B T Y PE _ S Z ) c m d : = b it o r ( N E W VO P , if p r ed i c ti o n _ is _ I V OP t h en I NT R A el s e IN T E R e n d ) , i n t (s i z e= B I T S_ Q U A NT + 1 ) v o p _ qu a n t do i f no t pr e d i ct i o n _i s _ I VO P t he n r ou n d := b i ta n d ( r s h i ft ( re a d _ re s u lt ( ) , IN T R A_ D C _ VL C _ TH R _ L E NG T H + B I TS _ Q UA N T + V O P _F C O D E_ F O R_ L E N GT H ) , 1 ) = 1 ; v op _ q u an t : = b i ta n d ( rs h i ft ( r ea d _ re s u l t () , VO P _ F CO D E _F O R _ L EN G T H ) , BI T S _Q U A N T_ M A S K ) ; f co d e := b i ta n d ( r e a d _r e s ul t ( ) , V O P_ F C O D E_ F O R_ M A S K ) ; / / r e s yn c _ m ar k e r_ l e n g th : = 1 6 + f c od e ; e l s e v op _ q u an t : = b i ta n d ( re a d _r e s u lt ( ) , B I T S _Q U A NT _ M A SK ) ; f co d e := 0 ; / / r e s yn c _ m ar k e r_ l e n g th : = 1 7 ; e n d c m d : = bi t o r ( c m d , b i t an d ( v op _ q ua n t , QU A N T _M A S K ) ) ; c m d : = bi t o r ( c m d , i f ro u n d t h e n R O U ND _ T Y PE e l se 0 e n d ); c m d : = bi t o r ( c m d , b i t an d ( ls h i ft ( f co d e , F C O D E_ S H IF T ) , F C O D E_ M A S K) ) ;e n ds e nd _ n e w_ v o p _w i d t h: a ct i o n == > BT Y P E : [ vo l _ w i dt h ] e n d

s e nd _ n e w_ v o p _h e i g ht : ac t i o n = = > B T Y P E: [ v o l _ h ei g h t ] e nd

/ * ** * * * ** * * * ** * * * ** * * ** * * * * ** * * ** * * * ** * * ** * * * * ** * * ** * * * ** * * ** * * ** * * * ** * * * ** * * ** * * * ** * * * ** * * * ** * * ** * * * ** * * * ** * * * ** * * ** * * * ** * * ** * * * ** s t a r t M B ** * * * ** * * ** * * * ** * * * ** * * ** * * * ** * * * ** * * * ** * * ** * * * ** * * * ** * * * ** * * ** * * * ** * * ** * * * ** * * * ** * * ** * * * ** * * * ** * * * ** * * ** * * * ** * * * ** * * * ** * * ** * * * ** * /

in t C BP _ S Z = 7 ; in t ( s iz e = C BP _ S Z) c b p;

// A d va n c e t h e m b c oo r d i na t e s w i t h w r a p pr o c e du r e ne x t _m b x y () be g i n m b x : = mb x + 1 ; i f mb x = v o l _w i d t h t h e n m bx : = 0 ; m by : = m b y + 1 ; e n d en d // G o l o o k f o r n e x t V O P mb _ d o ne : a ct i o n = = > gu a r d m b y = v ol _ h e ig h t en d ;

ge t _ m cb p c . iv o p : a c t io n = => gu a r d p r e di c t io n _ i s_ I V O P do s t a rt _ v ld _ e n gi n e ( M C B P C_ I V O P_ S T AR T _ I ND E X ); en d

ge t _ m cb p c . pv o p : a c t io n b it s : [ b] = => gu a r d n o t p r e di c t i on _ i s _I V O P , n o t b do s t a rt _ v ld _ e n gi n e ( M C B P C_ P V O P_ S T AR T _ I ND E X ) ; b i t _c o u nt : = b i t _ co u n t + 1 ; en d

// N o th i n g t o do - un c o d ed mc b p c _p v o p _u n c od e d : a c t i on b i ts : [ b] = = > B TY P E : [ I N T ER ] gu a r d n o t p r e di c t i on _ i s _I V O P do n e x t_ m b xy ( ) ; b i t _c o u nt : = b i t _ co u n t + 1 ; en d

mc b p c _p v o p _u n c od e d 1 : a c t io n = => B TY P E : [ I N T ER ] en d bo o l ac p r e df l a g; bo o l bt y p e _i s _ IN T R A ; in t ( s iz e = C BP _ S Z) c b pc ; bo o l fo u r m vf l a g;

ge t _ m bt y p e .n o a c: a c ti o n == > gu a r d v l d _s u c ce s s ( ), t y p e ! = 3 , t y p e ! = 4 va r i n t m c b pc = vl d _ r es u l t () , i n t t y p e = b it a n d ( m c b pc , 7 ) do b t y pe _ i s_ I N T RA : = t y p e > = 3 ; f o u rm v f la g : = ( t y pe = 2) ; c b p c : = b i t a nd ( r sh i f t ( m c b pc , 4 ) , 3 ) ; a c p re d f la g : = f a l se ; s t a rt _ v ld _ e n gi n e ( C B P Y _S T A R T_ I N DE X ) ; en d

ge t _ m bt y p e .a c : a c t i on b i ts : [ b ] = = > gu a r d v l d _s u c ce s s ( ) va r i n t m c b pc = vl d _ r es u l t () , i n t t y p e = b it a n d ( m c b pc , 7 ) do b t y pe _ i s_ I N T RA : = t r u e ; c b p c : = b i t a nd ( r sh i f t ( m c b pc , 4 ) , 3 ) ; a c p re d f la g : = b ; b i t _c o u nt : = b i t _ co u n t + 1 ; s t a rt _ v ld _ e n gi n e ( C B P Y _S T A R T_ I N DE X ) ; en d

bo o l ac _ c o de d ;

in t ( s iz e = 4 ) m v co m p ;

fi n a l _c b p y _i n t er : a ct i o n = = > gu a r d v l d _s u c ce s s ( ), n o t b t y pe _ i s _I N T R A va r i n t c b p y = 1 5 - v ld _ r e su l t ( ) do c o m p : = 0 ; m v c om p := 0 ; c b p : = bi t o r ( l s h if t ( cb p y , 2 ) , c b p c ) ; en d

fi n a l _c b p y _i n t ra : a ct i o n = = > gu a r d v l d _s u c ce s s ( ) va r i n t c b p y = v ld _ r e su l t ( ) do c o m p : = 0 ; c b p : = bi t o r ( l s h if t ( c bp y , 2) , cb p c ); en d

mb _ d i sp a t c h_ d o ne : a ct i o n = = > gu a r d c o m p = 6 do n e x t_ m b xy ( ) ; en d

mb _ d i sp a t c h_ i n tr a : ac t i o n = = > B T Y PE : [ cm d ] gu a r d b t y pe _ i s_ I N T RA va r i n t (s i z e= B T Y PE _ S Z ) c m d : = I NT R A do a c _ co d e d : = bi t a n d( c b p, l s hi f t ( 1 , 5 - co m p ) ) ! = 0 ; c m d : = bi t o r ( c m d , i f ac _ c o de d th e n AC C O D ED e l se 0 e n d ); c m d : = bi t o r ( c m d , i f ac p r e df l a g t h e n A C P RE D e ls e 0 e n d ) ; en d mb _ d i sp a t c h_ i n te r _ n o_ a c : a c t i on = => B T YP E : [ b i t o r( I NT E R , b i t o r( M O TI O N , i f fo u r m vf l a g t h e n F O U RM V e ls e 0 e n d ) ) ] gu a r d b i t an d ( c b p , l s h i ft ( 1 , 5 - c o mp ) ) = 0 do a c _ co d e d : = fa l s e ; c o m p : = c o m p + 1 ; en d

mb _ d i sp a t c h_ i n te r _ a c_ c o d ed : a ct i o n = = > B T Y P E: [ b it o r (b i t o r( I N TE R , AC C O DE D ) , b i t or ( M OT I O N, i f f o u r mv f l a g t h en F O UR M V el s e 0 e n d ) ) ] do a c _ co d e d : = tr u e ; en d

vl d _ s ta r t _ in t r a: a c ti o n == > gu a r d b t y pe _ i s_ I N T RA do s t a rt _ v ld _ e n gi n e ( i f c om p < 4 t he n D CB I T S _Y _ S T AR T _ IN D E X e l s e D C B I TS _ U V_ S T A RT _ I N DE X e nd ) ; b _ l as t := f a ls e ; en d

// T h er e a re A C c o e ff i c i en t s vl d _ s ta r t _ in t e r. a c _ co d e d : a c t io n == > gu a r d a c _ co d e d do b _ l as t := f a ls e ; en d

// N o A C c oe f f ic i e n ts vl d _ s ta r t _ in t e r. n o t _a c _ c od e d : a c t io n = => R U N: [ 0 ] , V A LU E : [ 0] , L AS T : [ tr u e ] do b _ l as t := t r ue ; en d // T h e Y D C v a lu e i s a t mo s t 12 b it s , UV a t m o s t 1 3 bi t s in t ( s iz e = 5 ) d c _b i t s ;

ge t _ d c_ b i t s. n o ne : a ct i o n = = > RU N : [0 ] , VA L U E :[ 0 ] , L A S T: [ n ot a c _c o d e d ] gu a r d v l d _s u c ce s s ( ), v l d _r e s ul t ( ) = 0 do b _ l as t := n o t a c _ co d e d ; en d

ge t _ d c_ b i t s. s o me : a ct i o n = = > gu a r d v l d _s u c ce s s ( ) do d c _ bi t s : = v ld _ r e su l t ( ); s e t _b i t s_ t o _ re a d ( d c _ b it s ) ; en d in t ( s iz e = 1 4) m sb _ r e su l t ; dc _ b i ts _ s h if t : a c t i on = = > va r i n t (s i z e= 5 ) co u n t = d c _b i t s , i n t (s i z e= 1 4 ) s h i f t = 1 do w h i le c ou n t > 1 d o s hi f t := l s hi f t ( s h i f t, 1 ) ; c ou n t := c o un t - 1 ; e n d m s b _r e s ul t : = s h i ft ; en d

ge t _ d c: a c ti o n = = > R U N : [0 ] , VA L U E: [ v ] , L A S T: [ n ot a c_ c o d ed ] gu a r d d o n e_ r e ad i n g _b i t s () va r i n t (s i z e= 1 4 ) v = re a d _ re s u l t( ) do i f bi t a nd ( v , m s b _r e s u lt ) = 0 th e n v : = v + 1 - l s hi f t ( ms b _ re s u l t, 1 ) ; e n d s e t _b i t s_ t o _ re a d ( i f d c_ b i t s > 8 t h e n M A R KE R _ L EN G T H e l s e 0 e nd ) ; b _ l as t := n o t a c _ co d e d ; en d

bo o l b_ l a s t; bl o c k _d o n e : a c ti o n == > gu a r d d o n e_ r e ad i n g _b i t s () , b _ l as t do c o m p : = c o m p + 1 ; en d

dc t _ c oe f f : a c t io n = => gu a r d d o n e_ r e ad i n g _b i t s () do s t a rt _ v ld _ e n gi n e ( i f b ty p e _ is _ I NT R A th e n CO E F F _I N T RA _ S T AR T _ I ND E X el s e C O E F F_ I N T ER _ S T AR T _ IN D E X e n d ); en d

vl d _ c od e : ac t i on b i ts : [ s ig n ] == > VA L U E :[ i f si g n th e n - l e v el e l se l e ve l en d ] , R U N : [r u n ] , L A ST : [ la s t ] gu a r d v l d _s u c ce s s ( ), v a l ! = ES C A P E_ C O D E va r i n t (s i z e= V L D _T A B L E_ D A T A_ B I T S) v al = vl d _ r es u l t () , i n t (s i z e= S A M PL E _ C OU N T _ SZ ) r un , i n t (s i z e= S A M PL E _ S Z) l e ve l , b o o l l a st do r u n : = i f bt y p e _i s _ I NT R A th e n b i t a nd ( r sh i f t ( v a l, 8 ) , 2 5 5 ) el s e b i t a nd ( r sh i f t ( v a l, 4 ) , 2 5 5 ) e n d ; l a s t : = i f bt y p e _i s _ I NT R A th e n b i t a nd ( r sh i f t ( v a l, 1 6 ), 1 ) ! = 0 el s e b i t a nd ( r sh i f t ( v a l, 1 2 ), 1 ) ! = 0 e n d ; l e v el : = i f bt y p e _i s _ I NT R A th e n b i t a nd ( v al , 2 55 ) el s e b i t a nd ( v al , 1 5) e nd ; b _ l as t := l a st ; b i t _c o u nt : = b i t _ co u n t + 1 ; en d

vl d _ l ev e l : a c t io n b it s : [ le v e l _o f f se t ] == > gu a r d v l d _s u c ce s s ( ), n o t l e v el _ o f fs e t do b i t _c o u nt : = b i t _ co u n t + 1 ; s t a rt _ v ld _ e n gi n e ( i f b ty p e _ is _ I NT R A th e n CO E F F _I N T RA _ S T AR T _ I ND E X el s e C O E F F_ I N T ER _ S T AR T _ IN D E X e n d ); en d

vl d _ r un _ o r _d i r ec t : ac t i o n b i t s: [ l ev e l _ of f s e t] = = > gu a r d v l d _s u c ce s s ( ) do b i t _c o u nt : = b i t _ co u n t + 1 ; en d

vl d _ ru n : ac t i o n b i t s: [ r un _ o f fs e t ] = = > g u ar d n ot r un _ o f fs e t d o b it _ c ou n t := b i t_ c o u nt + 1 ; s ta r t _v l d _ en g i n e( i f b t y pe _ i s _I N T R A t h e n C O EF F _ I NT R A _ ST A R T _I N D EX e l se C O EF F _ I NT E R _S T A R T_ I N D EX e n d ) ; e n d

v l d_ d i r ec t _ r ea d : ac t i on b i ts : [ r un _ o f fs e t ] = = > d o b it _ c ou n t := b i t_ c o u nt + 1 ; s et _ b it s _ t o_ r e a d( 1 + R U N_ L E N GT H + M A R K ER _ L EN G T H + L E VE L _ L EN G T H + M AR K E R _L E N G TH ) ; e n d

v l d_ d i r ec t : ac t i o n = => V AL U E : [i f s ig n th e n -l e v e l e l s e l e ve l e nd ] , RU N : [ ru n ] , L A S T: [ l as t ] g u ar d d on e _ re a d i ng _ b i ts ( ) v a r i nt ( s iz e = S AM P L E _C O U N T_ S Z ) r u n , i nt ( s iz e = S AM P L E _S Z ) le v e l, b oo l si g n , b oo l la s t d o l as t : = b it a n d ( r s h if t ( r e a d _r e s u lt ( ) , R U N _L E N G TH + MA R K E R_ L E NG T H + L E V EL _ L E NG T H + M A RK E R _ LE N G T H ) , 1 ) ! = 0 ; r un : = b it a n d ( r s h if t ( r e a d _r e s u lt ( ) , MA R K E R_ L E NG T H + L E V EL _ L E NG T H + M A RK E R _ LE N G T H ) , R U N _ MA S K ) ; l ev e l : = b it a n d ( r s h if t ( r e a d _r e s u lt ( ) , M A RK E R _ LE N G T H ) , L E V E L_ M A S K ) ; i f l e ve l > = 2 0 4 8 t h e n s i g n : = t r u e ; l e v el : = 4 0 9 6 - l ev e l ; e ls e s i g n : = fa l s e ; e nd b _l a s t : = la s t ; e n d f u nc t i o n i n t ra _ m a x_ l e ve l ( bo o l la s t , i n t r u n ) : i f n o t l a s t t h e n i f ru n = 0 t h en 2 7 e l s e i f r u n = 1 th e n 10 e l se i f r un = 2 t h en 5 el s e i f r u n = 3 th e n 4 e l s e if r u n < 8 t h e n 3 e ls e i f ru n < 1 0 th e n 2 e l s e i f r u n < 1 5 t h e n 1 e ls e 0 e n d e n d en d e n d e n d e nd e n d e ls e i f ru n = 0 t h en 8 e l s e i f r u n = 1 th e n 3 e l s e i f r un < 7 t h en 2 el s e i f r u n < 2 1 t h e n 1 e l se 0 en d e n d e nd e n d e nd e n d

f u nc t i o n i n t er _ m a x_ l e ve l ( bo o l la s t , i n t r u n ) : i f n o t l a s t t h e n i f ru n = 0 t h en 1 2 e l s e i f r u n = 1 th e n 6 e l s e i f r un = 2 t h en 4 el s e i f r u n < 7 th e n 3 e l s e if r u n < 1 1 t h en 2 el s e i f ru n < 2 7 th e n 1 e l s e 0 e nd en d e n d e n d e nd e n d e ls e i f ru n = 0 t h en 3 e l s e i f r u n = 1 th e n 2 e l s e i f r un < 41 t he n 1 e l s e 0 e n d e nd e n d e nd e n d i n t( s i z e= S A M PL E _ S Z) l ev e l _ lo o k u p_ i n t er ; i n t( s i z e= S A M PL E _ S Z) l ev e l _ lo o k u p_ i n t ra ; d o _l e v e l_ l o o ku p : ac t i on = = > g ua r d v ld _ s uc c e s s( ) v a r i nt ( s iz e = V LD _ T A BL E _ D AT A _ BI T S - 2) v a l = v ld _ r es u l t () d o l ev e l _l o o k up _ i n te r : = i n te r _ m ax _ l e ve l ( bi t a nd ( r sh i f t ( v a l , 1 2 ), 1 ) ! = 0 , b i t an d ( r s h i ft ( v al , 4 ), 2 55 ) ) ; l ev e l _l o o k up _ i n tr a : = i n tr a _ m ax _ l e ve l ( bi t a nd ( r sh i f t ( v a l , 1 6 ), 1 ) ! = 0 , b i t an d ( r s h i ft ( v al , 8 ), 2 55 ) ) ; e n d v l d_ l e v el _ l o ok u p : a c t io n b it s : [ si g n ] = = > V A L U E: [ i f s i g n t h e n - l e ve l e ls e l ev e l e n d ] , R U N :[ r u n ], L AS T : [ l a s t ] v a r i nt ( s iz e = V LD _ T A BL E _ D AT A _ BI T S - 2) v a l = v ld _ r es u l t () , i nt ( s iz e = S AM P L E _C O U N T_ S Z ) r u n , i nt ( s iz e = S AM P L E _S Z ) le v e l, b oo l la s t d o r un : = i f b t y pe _ i s _I N T RA t h en b i ta n d ( r s h if t ( va l , 8) , 2 55 ) e l se b i ta n d ( r s h if t ( va l , 4) , 25 5 ) en d ; l as t : = i f b t y pe _ i s _I N T RA t h en b i ta n d ( r s h if t ( va l , 16 ) , 1) ! = 0 e l se b i ta n d ( r s h if t ( va l , 12 ) , 1 ) ! = 0 e nd ; l ev e l : = i f b t y pe _ i s _I N T RA t h en b i ta n d ( v a l , 2 5 5 ) + l ev e l _ lo o k up _ i n tr a e l se b i ta n d ( v a l , 1 5 ) + l e ve l _ lo o k u p_ i n t er e n d; b _l a s t : = la s t ; b it _ c ou n t := b i t_ c o u nt + 1 ; e n d

f u nc t i o n i n t ra _ m a x_ r u n( b o ol l a st , i nt l ev e l ) : i f n o t l a s t t h e n i f le v e l = 1 th e n 1 4 e ls e i f l e v el = 2 t h e n 9 e ls e i f l ev e l = 3 th e n 7 e l s e i f l e v e l = 4 t h e n 3 e ls e if l e ve l = 5 t he n 2 e l s e i f le v e l < 1 1 t h e n 1 e ls e 0 e n d en d e n d e n d e nd e n d e ls e if l ev e l = 1 t he n 2 0 e l se i f l e v el = 2 t h e n 6 e ls e i f l ev e l = 3 th e n 1 e l s e 0 e nd e nd e n d e nd e n d

f u nc t i o n i n t er _ m a x_ r u n( b o ol l a st , i nt l ev e l ) : i f n o t l a s t t h e n i f le v e l = 1 th e n 2 6 e ls e i f l e v el = 2 t h e n 1 0 el s e i f l ev e l = 3 th e n 6 e l s e i f l e v e l = 4 t h e n 2 e ls e if l e ve l = 5 o r l e v el = 6 t h e n 1 el s e 0 e n d e n d e n d e nd e n d e ls e i f le v e l = 1 th e n 4 0 e ls e i f l e v el = 2 t h e n 1 e ls e 0 e n d e n d e nd e n d

i n t( s i z e= S A M PL E _ S Z) r un _ l o ok u p _ in t e r ; i n t( s i z e= S A M PL E _ S Z) r un _ l o ok u p _ in t r a ;

/ / D o l oo k u p b o t h w a y s d o _r u n _ lo o k u p: a c ti o n = = > g u ar d v ld _ s uc c e s s( ) v a r i nt ( s iz e = V LD _ T A BL E _ D AT A _ BI T S - 2) v a l = v ld _ r es u l t () d o r un _ l oo k u p _i n t e r : = in t e r_ m a x _r u n ( b i t a nd ( rs h i f t( v a l, 1 2 ), 1 ) ! = 0, b i t an d ( v a l , 1 5 ) ); r un _ l oo k u p _i n t r a : = in t r a_ m a x _r u n ( b i t a nd ( rs h i f t( v a l, 1 6 ), 1 ) ! = 0, b i t an d ( v a l , 2 5 5 ) ) ; e n d v l d_ r u n _l o o k up : a ct i o n b i t s: [ s i gn ] = => V AL U E : [i f s ig n t he n -l e v e l e l s e l e v el e nd ] , RU N : [ ru n ] , L A S T: [ l as t ] v a r i nt ( s iz e = V LD _ T A BL E _ D AT A _ BI T S - 2) v a l = v ld _ r es u l t () , i nt ( s iz e = S AM P L E _C O U N T_ S Z ) r u n , i nt ( s iz e = S AM P L E _S Z ) le v e l, b oo l la s t d o l as t : = i f b t y pe _ i s _I N T RA t h en b i ta n d ( r s h if t ( va l , 16 ) , 1) ! = 0 e l se b i ta n d ( r s h if t ( va l , 12 ) , 1 ) ! = 0 e nd ; l ev e l : = i f b t y pe _ i s _I N T RA t h en b i ta n d ( v a l , 2 5 5 ) e l se b i ta n d ( v a l , 1 5 ) e n d ; r un : = i f b t y pe _ i s _I N T RA t h en b i ta n d ( r s h if t ( va l , 8) , 2 55 ) + r u n _l o o k up _ i n tr a e l se b i ta n d ( r s h if t ( va l , 4) , 25 5 ) + r u n _l o o k up _ i nt e r en d + 1 ; b _l a s t : = la s t ; b it _ c ou n t := b i t_ c o u nt + 1 ; e n d/* * * ** * * * ** * * * ** * * * ** * * ** * * * ** * * * ** * * * ** * * ** * * * ** * * * ** * * * ** * * * * * * * ** * * ** * * * ** * * * ** * * * ** * * ** * * * ** * * * ** * * * ** * * ** * * * ** * * * ** * * * * * * * ** * * Mo t i on D e co d e * * * ** * * * * * * * ** * * ** * * * ** * * * ** * * * ** * * ** * * * ** * * * ** * * * ** * * ** * * * ** * * * ** * * * * * * * ** * * ** * * * ** * * * ** * * * ** * * ** * * * ** * * * ** * * * ** * * ** * * * ** * * * ** * * * /

m v co d e _ do n e : a c t i on = => g u ar d m vc o m p = 4 o r ( mv c o m p = 1 a n d n o t fo u r m vf l a g ) e n d

m v co d e : a c t i on = = > d o s ta r t _v l d _ en g i n e( M V _S T A RT _ I N DE X ) ; e n d

m a g_ x : ac t i o n = = > M V : [ m v v al ] g u ar d v ld _ s uc c e s s( ) v a r i nt ( si z e = VL D _ T AB L E _ DA T A _B I T S ) m v v al = vl d _ re s u l t( ) d o s et _ b it s _ t o_ r e a d( i f f c o de < = 1 o r m v v a l = 0 t h e n 0 e ls e f co d e e n d ); e n d

g e t_ r e s id u a l _x : a ct i o n = = > M V : [ r e a d _r e s ul t ( ) ] g u ar d d on e _ re a d i ng _ b i ts ( ) e n d

m a g_ y : ac t i o n = = > M V : [ m v v al ] g u ar d v ld _ s uc c e s s( ) v a r i nt ( si z e = VL D _ T AB L E _ DA T A _B I T S ) m v v al = vl d _ re s u l t( ) d o s et _ b it s _ t o_ r e a d( i f f c o de < = 1 o r m v v a l = 0 t h e n 0 e ls e f co d e -1 e n d ) ; e n d

g e t_ r e s id u a l _y : a ct i o n = = > M V : [ r e a d _r e s ul t ( ) ] g u ar d d on e _ re a d i ng _ b i ts ( ) d o m vc o m p : = mv c o m p + 1 ; e n d

i n t V L D _T A B L E_ A D D R_ B I TS = 1 2 ; i n t V L D _T A B L E_ D A T A_ B I TS = 2 0 ;

l i st ( t yp e : i nt ( s iz e = VL D _ T AB L E _ DA T A _ BI T S ) , s iz e = 7 60 ) vl d _ ta b l e = [

// A ut o m a ti c a l ly - g e ne r a te d t ab l e s f o r bi t w is e M PE G - 4 V L D//// D ec o d i ng p r oc e e d s a s f o l l ow s :// 1 . S e t i n d e x t o a s t ar t i n g v a l ue f o r t h e d e s ir e d co d e (s e e e m b e dd e d co m m e nt s ) .// 2 . R e a d t h e n e x t b i t i n t he i n co m i n g s t re a m .// 3 . F e t ch t h e v a l ue a t t a b le [ i nd e x + b i t ]// 4 . T a k e t h e f o l l ow i n g a c t io n b as e d on t ab l e va l u e :// 4 . 1. I f l s b = 1 , t e r m in a t e d e c o di n g w i t h i l l e ga l c od e w or d e rr o r .// 4 . 2. I f 2 n d ls b = 1 , th e c od e w o rd i s n o t c o m p le t e ,// s o s e t in d e x t o va l u e > > 2 , g o t o s te p 2 .// 4 . 3. F o r a l l o t h er v a lu e s st o p de c o di n g an d r et u r n v a l ue > > 2

// s ta r t in d e x f o r MC B P C_ I V O P i s 0// ( cu m u l at i v e t a b l e s i ze i s 1 6 w or d s x 2 0 b i t s )

1 0 , 12 , 18 , 5 8, 2 6 , 7 6 , 3 4 , 1 6 , 4 2 , 50 , 1, 8 0 , 1 4 4 , 2 0 8 , 1 4 0, 2 0 4,

// s ta r t in d e x f o r MC B P C_ P V O P i s 16// ( cu m u l at i v e t a b l e s i ze i s 5 8 w or d s x 2 0 b i t s ) 7 4 , 0, 8 2, 2 2 6, 9 0 , 2 1 8 , 9 8 , 2 0 2 , 1 0 6 , 1 7 8 , 1 1 4 , 1 6 2 , 1 2 2 , 1 4 6, 1 3 0, 1 3 8, 1 , 1 , 2 0 8, 1 4 4, 1 5 4, 1 4 0, 8 0, 1 9 6, 1 7 0 , 2 0 4 , 7 6 , 2 0 0 , 1 8 6 , 1 9 4 , 1 3 6 , 7 2 , 1 3 2 , 6 8 , 2 1 0 , 1 2 , 16 , 1 92 , 12 8 , 64 , 8 , 4 ,

// s ta r t in d e x f o r CB P Y i s 5 8// ( cu m u l at i v e t a b l e s i ze i s 9 2 w or d s x 2 0 b i t s )

2 4 2 , 3 3 8 , 2 5 0 , 3 1 4 , 2 5 8 , 2 9 8, 2 6 6, 2 9 0, 2 7 4 , 2 8 2 , 1 , 1, 2 4 , 3 6 , 3 2 , 1 6 , 3 0 6 , 0 , 8, 4 , 3 2 2 , 3 3 0 , 4 8 , 4 0 , 5 6 , 20 , 34 6 , 60 , 3 54 , 3 62 , 52 , 1 2, 4 4 , 28 ,

// s ta r t in d e x f o r DC B I TS _ Y is 9 2// ( cu m u l at i v e t a b l e s i ze i s 1 1 8 wo r d s x 2 0 b i t s)

3 7 8 , 4 6 6 , 3 8 6 , 4 5 8 , 3 9 4 , 1 6 , 4 0 2 , 2 0 , 4 1 0 , 2 4 , 4 1 8 , 2 8 , 42 6 , 32 , 43 4 , 36 , 4 4 2 , 4 0 , 4 5 0 , 4 4 , 1, 4 8 , 1 2 , 0 , 8 , 4 ,// s ta r t in d e x f o r DC B I TS _ U V i s 1 18// ( cu m u l at i v e t a b l e s i ze i s 1 4 4 wo r d s x 2 0 b i t s)

4 8 2 , 5 7 0 , 4 9 0 , 8 , 49 8 , 12 , 50 6 , 16 , 5 1 4 , 2 0 , 5 2 2 , 2 4 , 53 0 , 28 , 53 8 , 32 , 5 4 6 , 3 6 , 5 5 4 , 4 0 , 56 2 , 44 , 1, 4 8 , 4 , 0 ,

// s ta r t in d e x f o r CO E F F_ I N T ER i s 1 4 4// ( cu m u l at i v e t a b l e s i ze i s 3 8 0 wo r d s x 2 0 b i t s)

5 8 6 , 1 4 9 8, 5 9 4, 1 4 26 , 6 02 , 13 3 8 , 6 1 0 , 1 1 9 4 , 6 1 8 , 1 0 6 6, 6 2 6, 8 7 4, 6 3 4, 8 18 , 6 42 , 7 94 , 6 5 0 , 7 7 0 , 6 5 8 , 7 1 4 , 6 6 6 , 6 9 0, 6 7 4, 6 8 2, 1 , 1 , 1 , 1 , 6 98 , 7 06 , 1 , 1 , 1 , 1 , 7 2 2, 7 4 6, 7 3 0, 7 3 8, 1 , 1 , 1 , 1 , 7 5 4, 7 6 2, 1 , 1 , 1 , 1 , 7 7 8 , 7 8 6 , 1 6 4 56 , 1 63 9 6 , 4 4 , 4 0 , 80 2 , 81 0 , 1 8 1 8 0, 1 81 1 6 , 1 8 0 5 2, 1 7 98 8 , 8 2 6 , 8 5 0 , 8 3 4 , 8 4 2 , 5 8 4 , 5 2 0 , 4 5 6 , 3 9 2 , 8 5 8 , 8 6 6, 3 2 8, 2 0 4, 1 4 0 , 8 0 , 8 8 2 , 2 8 6 6 8, 8 9 0, 9 46 , 8 98 , 9 22 , 9 0 6 , 9 1 4 , 4 8 , 8 4 , 14 7 6 , 1 5 4 0, 9 3 0, 9 3 8, 1 8 2 4 4, 1 83 0 8 , 1 8 3 7 2, 1 8 43 6 , 9 5 4 , 1 0 1 0 , 9 6 2 , 9 8 6, 9 7 0 , 9 7 8 , 8 8 , 1 4 4 , 2 6 8 , 3 3 2 , 9 9 4 , 1 0 0 2, 3 9 6 , 6 4 8 , 1 6 0 4, 1 6 68 , 1 01 8 , 1 0 4 2 , 1 0 2 6, 1 0 34 , 1 8 5 0 0, 1 85 6 4 , 1 8 6 2 8, 1 8 69 2 , 1 0 5 0 , 1 0 5 8, 1 8 75 6 , 1 8 8 2 0, 1 8 8 8 4, 1 89 4 8 , 1 0 7 4 , 1 1 3 8, 1 08 2 , 11 1 4 , 1 0 9 0 , 1 1 06 , 1 0 9 8 , 1 7 92 4 , 36 , 3 2, 1 7 86 0 , 1 7 7 9 6, 1 1 22 , 1 13 0 , 1 7 7 3 2, 1 76 6 8 , 1 7 6 0 4, 1 7 54 0 , 1 1 4 6 , 1 1 7 0, 1 1 54 , 11 6 2 , 1 7 4 7 6, 1 63 9 2 , 1 4 1 2 , 1 3 4 8, 1 17 8 , 11 8 6 , 1 2 8 4 , 1 2 20 , 1 1 5 6 , 1 0 92 , 1 20 2 , 12 8 2 , 1 2 1 0, 1 2 58 , 1 21 8 , 12 4 2 , 1 2 2 6 , 1 2 34 , 1 02 8 , 96 4 , 26 4 , 2 0 0 , 1 2 5 0 , 1 7 4 12 , 2 8 , 24 , 12 6 6 , 1 2 7 4 , 1 7 3 48 , 17 2 8 4 , 1 7 2 20 , 1 71 5 6 , 1 2 9 0 , 1 3 14 , 1 29 8 , 13 0 6 , 1 7 0 92 , 1 70 2 8 , 1 6 9 6 4, 9 00 , 1 3 2 2 , 1 3 30 , 8 36 , 1 36 , 7 6, 2 0, 1 3 46 , 1 40 2 , 1 3 5 4 , 1 3 78 , 1 36 2 , 13 7 0 , 1 6 9 00 , 1 68 3 6 , 1 6 7 7 2, 1 67 0 8 , 1 3 8 6 , 1 3 94 , 7 72 , 7 08 , 6 44 , 16 , 1 41 0 , 14 1 8 , 1 6 6 4 4, 1 65 8 0 , 1 6 5 1 6, 1 6 45 2 , 1 4 3 4 , 1 4 8 2, 1 4 42 , 14 6 6 , 1 4 5 0 , 1 4 58 , 5 80 , 5 16 , 4 52 , 38 8 , 14 7 4 , 3 2 4 , 7 2 , 12 , 14 9 0 , 1 6 3 8 8, 2 6 0, 1 96 , 4 , 1 5 0 6, 6 8 , 15 1 4 , 1 3 2 , 8 ,

// s ta r t in d e x f o r CO E F F_ I N T RA i s 3 8 0// ( cu m u l at i v e t a b l e s i ze i s 6 1 6 wo r d s x 2 0 b i t s)

1 5 3 0 , 2 4 42 , 1 53 8 , 23 7 0 , 1 5 4 6, 2 2 82 , 1 55 4 , 21 3 8 , 1 5 6 2 , 2 0 10 , 1 57 0 , 18 1 8 , 1 5 7 8, 1 7 62 , 1 58 6 , 17 3 8 , 1 5 9 4 , 1 7 14 , 1 60 2 , 16 5 8 , 1 6 1 0, 1 6 34 , 1 61 8 , 16 2 6 , 1 , 1 , 1 , 1 , 1 64 2 , 16 5 0 , 1 , 1, 1 , 1 , 1 6 66 , 1 69 0 , 16 7 4 , 1 6 8 2, 1 , 1 , 1 , 1 , 1 6 98 , 1 70 6 , 1, 1 , 1 , 1, 1 7 2 2 , 1 7 30 , 2 62 1 7 2 , 2 6 2 16 8 , 8 8 , 84 , 1 74 6 , 17 5 4 , 2 6 4 2 00 , 26 3 1 8 0, 2 6 21 6 4 , 1 3 3 16 , 1 77 0 , 17 9 4 , 1 7 7 8, 1 7 86 , 5 1 3 2 , 8 2 00 , 4 10 8 , 30 8 8 , 1 8 0 2, 1 8 10 , 2 06 4 , 10 5 2 , 8 0 , 76 , 18 2 6 , 2 8 6 6 8, 1 8 34 , 18 9 0 , 1 8 4 2 , 1 8 6 6, 1 8 5 0 , 1 8 58 , 9 2, 9 6 , 1 0 5 6, 9 22 4 , 18 7 4 , 1 8 8 2 , 2 6 5 2 24 , 26 6 2 4 8, 2 7 75 0 8 , 2 7 8 53 2 , 18 9 8 , 1 9 5 4 , 1 9 06 , 1 93 0 , 1 9 1 4 , 1 9 22 , 1 00 , 1 04 , 1 08 , 10 6 0 , 1 9 3 8 , 1 9 4 6, 6 1 5 6 , 1 0 64 , 2 06 8 , 71 8 0 , 1 9 6 2, 1 9 86 , 1 97 0 , 19 7 8 , 1 4 3 4 0, 2 62 1 7 6 , 2 6 7 27 2 , 26 8 2 96 , 1 99 4 , 20 0 2 , 2 7 9 55 6 , 28 0 5 8 0, 2 8 1 6 04 , 28 2 6 2 8, 2 0 18 , 2 08 2 , 2 0 2 6 , 2 0 5 8, 2 0 34 , 20 5 0 , 2 0 4 2 , 2 7 64 8 4 , 7 2 , 68 , 2 75 4 6 0, 2 7 44 3 6 , 2 0 6 6 , 2 0 74 , 2 7 3 4 12 , 27 2 3 8 8, 2 6 31 7 6 , 2 6 2 16 0 , 20 9 0 , 2 1 1 4 , 2 0 98 , 2 10 6 , 1 2 2 9 2, 1 12 6 8 , 7 1 7 6 , 6 1 5 2, 2 12 2 , 21 3 0 , 5 1 2 8 , 3 0 84 , 2 0 6 0 , 1 0 48 , 2 14 6 , 22 2 6 , 2 1 5 4, 2 2 02 , 2 16 2 , 21 8 6 , 2 1 7 0 , 2 1 78 , 1 04 4 , 64 , 4 10 4 , 6 0 , 21 9 4 , 2 7 0 3 40 , 5 6 , 52 , 22 1 0 , 2 2 1 8 , 2 6 9 31 6 , 2 6 8 2 92 , 2 62 1 5 6 , 1 0 24 4 , 2 2 3 4 , 2 2 58 , 2 24 2 , 22 5 0 , 9 2 2 0, 8 1 96 , 2 71 3 6 4 , 3 0 80 , 2 2 6 6 , 2 2 74 , 1 04 0 , 48 , 4 4, 4 0, 2 2 90 , 2 34 6 , 2 2 9 8 , 2 3 22 , 2 30 6 , 23 1 4 , 2 6 6 24 4 , 26 5 2 2 0, 6 1 48 , 26 7 2 6 8, 2 3 3 0 , 2 3 38 , 7 17 2 , 20 5 6 , 1 0 3 6, 3 6 , 2 3 5 4, 2 3 62 , 2 6 2 1 52 , 51 2 4 , 2 6 4 1 96 , 2 63 1 7 2, 2 3 78 , 2 42 6 , 23 8 6 , 2 4 1 0, 2 3 9 4 , 2 4 02 , 4 10 0 , 30 7 6 , 3 2 , 2 8 , 24 1 8 , 2 0 5 2 , 1 0 3 2 , 2 4 , 2 4 3 4, 2 6 21 4 8 , 2 0 , 1 6 , 4, 2 4 50 , 8 , 2 45 8 , 1 0 2 8 , 1 2 ,

// s ta r t in d e x f o r MV i s 6 1 6// ( cu m u l at i v e t a b l e s i ze i s 7 6 0 wo r d s x 2 0 b i t s)

/ * B EG I N C OP Y R I GH T X

C op y r i gh t ( c) 2 00 7 , Xi l i n x I n c .A ll r i gh t s re s e rv e d .R ed i s t ri b u t io n an d u se i n s o u r ce a nd b i na r y fo r m s , w it h o r w i t ho u t m o d i fi c a t io n , ar e pe r m i tt e d pr o v i de d t ha t t he f o ll o w in g c on d i t io n s ar e me t :- R e d i st r i b ut i o ns o f s o u r ce c o de m us t r et a i n t h e ab o v e c o p y ri g h t n o t ic e , th i s li s t o f c on d i t io n s an d th e f o l l ow i n g d i s cl a i m er .- R e d i st r i b ut i o ns i n b i n a ry f o rm m us t r ep r o d uc e t he a b o v e c o py r i g ht n o ti c e , t h i s l i s t o f co n d i ti o n s a n d t h e fo l l ow i n g d i s c la i m e r i n t h e do c u m en t a t io n an d / o r o t h e r m a te r i a ls p r ov i d e d w i th t h e d i s tr i b u ti o n .- N e i t he r t he n am e o f t h e c o p y ri g h t h o l de r n or t h e n a me s o f i ts c on t r i bu t o r s m a y b e us e d to e n do r s e o r pr o m o te p r o d uc t s d e r i ve d f ro m t hi s so f t w ar e w it h o u t s p ec i f i c p r i o r w r it t e n p e r m is s i o n.

T HI S S OF T W A RE I S P R O VI D E D B Y T HE C OP Y R I GH T H OL D E R S A N D C ON T R I BU T O R S " A S I S " A N D AN Y E XP R E SS O R I M P L IE D W AR R A NT I E S , I NC L U D IN G , BU T NO T L IM I T E D T O , T H E I M P L IE D W AR R A N TI E S O F M ER C H A NT A B I LI T Y A N D FI T N E SS F O R A PA R T I CU L A R P U R P OS E AR E D IS C L A IM E D . I N NO E V EN T S HA L L TH E CO P Y R IG H T OW N E R O R C ON T R I BU T O R S B E L I A B LE F O R A N Y D I R EC T , IN D I R EC T , IN C I DE N T A L, S PE C I A L, E X EM P L AR Y , OR C O NS E Q U EN T I AL D A MA G E S ( I N C LU D I NG , B UT N OT L I MI T E D T O , P R O C UR E M E NT O F S U B ST I T U TE G O OD S O R S E RV I C E S; L OS S O F U S E , D A TA , O R P R O FI T S ; O R BU S I N ES S I NT E R R UP T I ON ) H OW E V E R C A U SE D AN D O N A N Y T H E O RY O F L I A BI L I T Y, W H ET H E R I N C ON T R A CT , S TR I C T L I A BI L I T Y, O R T O R T ( I N CL U D I NG N E GL I G EN C E OR O TH E R W IS E ) AR I S IN G I N A N Y W A Y OU T OF T H E U S E O F T HI S S OF T W A RE , E VE N IF A D VI S E D O F T HE P OS S I B IL I T Y O F S UC H DA M A G E.E ND C O P YR I G H T* /

i mp o r t a l l ca l t ro p . l ib . B i tO p s ;

a ct o r Fo r e m an S o ur c e () i n t( s i z e= 8 ) M P E G , i n t (s i z e =8 ) CO M P A RE = = > i n t (s i z e= 8 ) da t a o ut , i nt ( s iz e = 3 2) e r ro r s : i n t mi s m at c h := 0 ; i n t ( si z e =2 4 ) co u n t : = 0 ; a c t i on M PE G : [ mp e g ] , C O M PA R E :[ c o m p] = = > d a t ao u t :[ m p eg ] g ua r d mi s m at c h = 0 d o mi s m at c h := b i tx o r ( mp e g , c o m p) ; co u n t : = co u n t + 1 ; e n d

a c t i on = => e r ro r s : [ b i t or ( l sh i f t (c o u n t, 8 ) , b i ta n d ( ol d m is m a t ch , 0x F F ) ) ] g ua r d mi s m at c h != 0 d o mi s m at c h := 0 ; e n d e nd

Compare23 lines(without header comments)

ParseHeaders1320 lines(without header comments)

http://opendf.svn.sourceforge.net/viewvc/opendf/models/MPEG4_SP_Decoder/

actors, big and small

26

actor execution model

actionselection

actionexecution

27

enabling conditions

1. input patterns are satisfiedactor Add () A, B ==> X:

action A: [a], B: [b] ==> X: [a + b] endend

2. guards are true

3. no higher-priority action is enabled

actor Split () A ==> P, N:

action A: [v] ==> P: [v] guard v >= 0 end

action A: [v] ==> N: [v] guard v < 0 endend

actor BiasedMerge () A, B ==> X:

CopyA: action A: [v] ==> X: [v] end CopyB: action B: [v] ==> X: [v] end

priority CopyA > CopyB; endend

actionselection

actionexecution

28

motivationthe need for a parallel programming model

dataflow programmingactors, dataflow, and the CAL actor language

examplesdeterminacy � the structure of a computation

researchthings still left to do

29

(non)determinacy � the classic case

n = 0;

t1 = n;n = t1 + 1;

t2 = n;n = t2 + 1;

Thread 1: Thread 2:

thread race on shared state

Each thread is determinate.

Their composition is not.

In the domain of threads, determinacy is not compositional.

Which non-trivial property of threads would guarantee compositional determinacy?

30

actor determinism

If there is always at most one enabled action, the actor is determinate.

Otherwise, it may not be.(Which means that actors are more 'unruly' than threads.)

Some simple (sufficient) conditions for determinism:

There is only one action.

Actions are totally priority-ordered.

actor Add () A, B ==> X:

action A: [a], B: [b] ==> X: [a + b] endend

actor BiasedMerge () A, B ==> X:

CopyA: action A: [v] ==> X: [v] end CopyB: action B: [v] ==> X: [v] end

priority CopyA > CopyB; endend

31

dataflow program determinism

1

2

M

actor BiasedMerge () A, B ==> X:

CopyA: action A: [v] ==> X: [v] end CopyB: action B: [v] ==> X: [v] end

priority CopyA > CopyB; endend

actor Constant1 () ==> X:

action ==> X: [1] endend

actor Constant2 () ==> X:

action ==> X: [2] endend

2, M, 1, M, ...

1, 2, ...2, 1, M, M, ...

2, 1, ...

firing sequence output

A

B

In dataflow, too, determinacy is not compositional.

Can we find a property of actors that is compositional, andthat entails determinacy?

32

source of nondeterminism

1

2

M

We can predict (determinate) actor behavior for each input sequence.

Unfortunately, we cannot predict the input sequence at each point in time.

2, M, 1, M, ...

1, 2, ...2, 1, M, M, ...

2, 1, ...

firing sequence output

Can we characterize actors that produce the same output irrespective of the relative timing of token arrival?

33

timing independence

actor Add () A, B ==> X: action A: [a], B: [b] ==> X: [a + b] endend

If the B-token is available, but the A-token is late, nothing happens:

actor BiasedMerge () A, B ==> X:

CopyA: action A: [v] ==> X: [v] end CopyB: action B: [v] ==> X: [v] end

priority CopyA > CopyB; endend

Here, if the A-token is late,the actor does something else instead.(In this case, the CopyB action.)

The actor just waits for the A-tokento arrive. The actor just waits for the A-tokento arrive.

An earlier arrival of the A-token wouldhave disabled that action.

An actor is timing-independent1 if additional input tokens never disable an action.

1 aka �prefix-monotonic�

34

timing independence

1. all input patterns are satisfiedaction A: [a], B: [b] ==> ...

2. all guards are true

3. no higher-priority action is enabled

action A: [v] ==> P: [v] guard v >= 0

CopyA: action A: [v] ==> X: [v] endCopyB: action B: [v] ==> X: [v] endpriority CopyA > CopyB; end

How can additional input disable an action?

It would have to �unsatisfy� a previously satisfied enabling condition.

The additional input tokens would have to enable a higher-priority action.

35

timing independence

How would additional tokens enable a higher-priority action?

The higher-priority action would have to require at least one tokennot needed by the lower-priority action.

actor BiasedMerge () A, B ==> X:

CopyA: action A: [v] ==> X: [v] end CopyB: action B: [v] ==> X: [v] end

priority CopyA > CopyB; endend

36

timing independence

actor TI () A ==> X:

Hi: action A: [v] ==> X: [1] end Lo: action A: [v, w] ==> X: [0] end

priority Hi > Lo; endend

actor TD () A ==> X:

Hi: action A: [v, w] ==> X: [1] end Lo: action A: [v] ==> X: [0] end

priority Hi > Lo; endend

timing-independent timing-dependent

Looking at the input patterns and the priority order, we can derive guarantees about timing-independence of each actor.

At compile time.

Any composition of timing-independent actors is determinate.It is also timing-independent itself.

38

a taxonomy of actors

determinate(functional)

nondeterminate(non-functional)

timing-dependenttiming-independent(prefix-monotonic)

39

a taxonomy of actors

determinate(functional)

nondeterminate(non-functional)

timing-dependenttiming-independent(prefix-monotonic)

actor Add () A, B ==> X:

action A: [a], B: [b] ==> X: [a + b] endend

40

a taxonomy of actors

determinate(functional)

nondeterminate(non-functional)

timing-dependenttiming-independent(prefix-monotonic)

actor Add () A, B ==> X:

action A: [a], B: [b] ==> X: [a + b] endend

41

a taxonomy of actors

determinate(functional)

nondeterminate(non-functional)

timing-dependenttiming-independent(prefix-monotonic)

actor Merge () A, B ==> X:

action A: [v] ==> X: [v] end action B: [v] ==> X: [v] endend

actor Add () A, B ==> X:

action A: [a], B: [b] ==> X: [a + b] endend

42

a taxonomy of actors

determinate(functional)

nondeterminate(non-functional)

timing-dependenttiming-independent(prefix-monotonic)

actor Merge () A, B ==> X:

action A: [v] ==> X: [v] end action B: [v] ==> X: [v] endend

actor Add () A, B ==> X:

action A: [a], B: [b] ==> X: [a + b] endend

43

a taxonomy of actors

determinate(functional)

nondeterminate(non-functional)

timing-dependenttiming-independent(prefix-monotonic)

actor Add () A, B ==> X:

action A: [a], B: [b] ==> X: [a + b] endend

actor BiasedMerge () A, B ==> X:

CopyA: action A: [v] ==> X: [v] end CopyB: action B: [v] ==> X: [v] end

priority CopyA > CopyB; endend

actor Merge () A, B ==> X:

action A: [v] ==> X: [v] end action B: [v] ==> X: [v] endend

44

a taxonomy of actors

determinate(functional)

nondeterminate(non-functional)

timing-dependenttiming-independent(prefix-monotonic)

actor Add () A, B ==> X:

action A: [a], B: [b] ==> X: [a + b] endend

actor BiasedMerge () A, B ==> X:

CopyA: action A: [v] ==> X: [v] end CopyB: action B: [v] ==> X: [v] end

priority CopyA > CopyB; endend

actor Merge () A, B ==> X:

action A: [v] ==> X: [v] end action B: [v] ==> X: [v] endend

45

a taxonomy of actors

determinate(functional)

nondeterminate(non-functional)

timing-dependenttiming-independent(prefix-monotonic)

actor Add () A, B ==> X:

action A: [a], B: [b] ==> X: [a + b] endend

actor BiasedMerge () A, B ==> X:

CopyA: action A: [v] ==> X: [v] end CopyB: action B: [v] ==> X: [v] end

priority CopyA > CopyB; endend

actor Merge () A, B ==> X:

action A: [v] ==> X: [v] end action B: [v] ==> X: [v] endend

actor PingPongMergeMerge () A, B ==> X:

action A: [v] ==> X: [v] guard s = 0 begin s := 1; end action B: [v] ==> X: [v] guard s = 1 begin s := 0; end s := 0;end

46

a taxonomy of actors

determinate(functional)

nondeterminate(non-functional)

timing-dependenttiming-independent(prefix-monotonic)

actor Add () A, B ==> X:

action A: [a], B: [b] ==> X: [a + b] endend

actor BiasedMerge () A, B ==> X:

CopyA: action A: [v] ==> X: [v] end CopyB: action B: [v] ==> X: [v] end

priority CopyA > CopyB; endend

actor Merge () A, B ==> X:

action A: [v] ==> X: [v] end action B: [v] ==> X: [v] endend

actor PingPongMergeMerge () A, B ==> X:

action A: [v] ==> X: [v] guard s = 0 begin s := 1; end

action B: [v] ==> X: [v] guard s = 1 begin s := 0; end

s := 0;end

47

motivationthe need for a parallel programming model

dataflow programmingactors, dataflow, and the CAL actor language

examplesdeterminacy � the structure of a computation

researchthings still left to do

48

structure of a computation

actor B () A ==> X: action A: [a] ==> X: [f(a)] endend

actor A () ==> X: s := 0;

action ==> X: [s] do s := s + 1; endend

actor C () A ==>: action A: [a] ==> endend

A B C

A:1

B:1

C:1

A:2

B:2

C:2

A:3

B:3

C:3

trace is a DAG vertices are action firings

edges are dependencies

dependencies mediated by tokens

state variables

(ports)

51

trace metrics (examples)

cost(S area * time)

input(bytes)

parallelizability(cost/latency)

latency(incremental)

52

motivationthe need for a parallel programming model

dataflow programmingactors, dataflow, and the CAL actor language

examplesdeterminacy � the structure of a computation

researchthings still left to do

54

open problems

� implementation tools� efficient code generation for processors and multicores� implementation on other targets: GPUs, processor arrays,

heterogeneous targets� runtime, virtual machine

� design tools� partitioning, profiling, early performance prediction� trace analysis� refactoring and code transformation (e.g. unrolling, folding, multi-

channelization)� debugging, deadlock/bottleneck detection and tracking

55

open problems, cont'd

� foundations� program analysis, partial static scheduling, theory, machine model

� applications� streaming applications (graphics, packet processing, ...)� other application areas (HPC, processor design, �)

� architecture� building dataflow hardware

56

credits & resourcesJohan Eker Ericsson Edward A. Lee UC Berkeley Marco Mattavelli EPFL Carl von Platen Ericsson Dave B. Parlour Tabula Ian Miller Overture Mickaël Raulet INSA Rennes Mathieu Wipliez INSA Rennes Christophe Lucarz EPFL Shuvra S Bhattacharyya U Maryland Karl-Erik Arzen LTH Ruirui Gu Microsoft Ghislain Roquier EPFL

opendf.sf.netopen source tool suite

opendf.orgOpen Dataflow portal

orcc.sf.netOpen RVC-CAL Compiler

mpeg.chiariglione.orgMPEG [email protected]

www.actors-project.euACTORS Project