ee 586l report

Upload: fiyadh-shahid

Post on 25-Feb-2018

212 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/25/2019 EE 586L Report

    1/6

    Nolan Miller - 5339012800EE-434 Assignment 2 - January 28, 2016

    Due to the difficulty involved with benchmarking the code, it is not clear what the units of the timing function return valueshould be. They are consistent throughout the optimization and are proportional to clock cycles so I will give them the unitics.

    Baseline

    Here is a snippet of the relevant (to be optimized) sections of my code. It had a dt value of roughly 5866 tics.

    # d e f in e d e la y 1 0 00

    short f i l t_ b u ff [ d e l a y ] = { 0 };

    float a l ph a = . 1;

    short f i l t e r ( short i n pu t ) {

    in t i ;

    / / i ir c om b f i lt er

    short o ut = f i l t_ b u ff [ 0 ] * a l p ha + i n pu t * (1 - a l p h a ) ;

    fo r ( i = 1; i < delay ; i + +) {

    f i l t_ b u ff [ i - 1 ] = f i l t_ b u ff [ i ] ;

    }

    f i l t_ b u ff [ d e la y - 1 ] = o u t ;

    return o u t ;}

    / / I n t er r u pt S e r vi c e R o u ti n e

    i n t e r r u p t void c _ i nt 1 1 ( ) {

    tic(); / / S ta rt t he t im er

    if ( ++ l o o p i n de x > = l o o p_ c o un t ) {

    l o op i nd e x = 0 ;

    if ( l e d _ st a t e ) {

    D S K 6 7 1 3 _ L E D _ o n ( 0 ) ;

    l e d_ s ta t e = 0 ;

    } else {

    D S K 6 7 1 3 _ L E D _ o f f ( 0 ) ;

    l e d_ s ta t e = 1 ;}

    }

    if ( ++ p e r i o d _ in d x > = p e r i od _ c ou n t ) {

    p e ri o d_ i nd x = 0 ;

    }

    short s mp l = 0;

    if ( D S K 6 7 1 3 _D I P _ ge t ( 1 ) ) {

    s m pl = i n p ut _ s a mp l e ( ) ;

    } else {

    s m pl = s i n _t b l [ ( p e r i od _ i nd x * t b l _s i z e ) / p e r io d _ co u n t ] ;

    }

    o u t p u t _ s a m p l e ( f i l t e r ( s m p l ) ) ;

    in t d t = t oc ( ); / / g et t im er v al ue

    return ; / / b r ea k po i nt s et h er e t o e x am i ne d t

    }

    1

  • 7/25/2019 EE 586L Report

    2/6

    Optimization 1

    I optimized the filter buffer to use a circular buffer rather than the data-shifting method previously used. This improved therun-time from 5866 tics to 140 tics. It also significantly sped up the execution so the buffer had to be extended.

    # d e f in e d e la y 1 0 00 0

    short f i l t_ b u ff [ d e l a y ] = { 0 };

    float a l ph a = . 1;

    short i dx = 0;

    / / d o n t s h if t m e mo r y , s h if t i n de x

    short f i l t e r ( short i n pu t ) {idx = ( idx - 1 + de la y) % d el ay ;

    / / i ir c om b f i lt er

    short o ut = f i l t_ b u ff [ i d x ] * a l ph a + i n pu t * (1 - a l p h a ) ;

    f i l t_ b u ff [ ( i d x + 1 )% d e l a y ] = o u t ;

    return o u t ;

    }

    Optimization 2

    I started using a board that was not broken and the behavior changed (although the performance did not). To correct forthe change, I changed the alpha value from .1 to .3. I then changed the buffer iteration direction to reduce the number oops. This reduced the time from 140 to 135 tics.

    # d e f in e d e la y 1 0 00 0

    short f i l t_ b u ff [ d e l a y ] = { 0 };

    float a l ph a = . 3;

    short i dx = 0;

    / / d o n t s h if t m e mo r y , s h if t i n de x

    short f i l t e r ( short i n pu t ) {

    idx = ( idx + 1) % d el ay ;

    / / i ir c om b f i lt er

    short o ut = f i l t_ b u ff [ i d x ] * a l ph a + i n pu t * (1 - a l p h a ) ;

    f i l t_ b u ff [ i d x ] = o u t ;

    return o u t ;

    }

    Optimization 3

    I removed the local variable from the filter function and condensed the function to a single line. The run time went from 135to 130 tics.

    # d e f in e d e la y 1 0 00 0

    short f i l t_ b u ff [ d e l a y ] = { 0 };

    float a l ph a = . 3;

    short i dx = 0;

    / / d o n t s h if t m e mo r y , s h if t i n de x

    short f i l t e r ( short i n pu t ) {return f i l t_ b u ff [ i d x ] = f i l t_ b u ff [ i d x = ( i dx + 1 ) % d e l ay ] * a l p h a + i np u t * (1 - a l p h a ) ;

    }

    2

  • 7/25/2019 EE 586L Report

    3/6

    Optimization 4

    I removed the Function call entirely and performed all logic in the ISR. The run time went from 130 to 117 tics.

    / / I n t er r u pt S e r vi c e R o u ti n e

    i n t e r r u p t void c _ i nt 1 1 ( ) {

    tic(); / / s ta rt t he t im er

    if ( ++ l o o p i n de x > = l o o p_ c o un t ) {

    l o op i nd e x = 0 ;

    if ( l e d _ st a t e ) {

    D S K 6 7 1 3 _ L E D _ o n ( 0 ) ;l e d_ s ta t e = 0 ;

    } else {

    D S K 6 7 1 3 _ L E D _ o f f ( 0 ) ;

    l e d_ s ta t e = 1 ;

    }

    }

    if ( ++ p e r i o d _ in d x > = p e r i od _ c ou n t ) {

    p e ri o d_ i nd x = 0 ;

    }

    short s m p l ;

    short d i p = D S K 6 71 3 _ D IP _ g e t ( 1 );

    if ( dip == 0) {

    s m pl = i n p ut _ s a mp l e ( ) ;

    } else {

    s m pl = s i n _t b l [ ( p e r i od _ i nd x * t b l _s i z e ) / p e r io d _ co u n t ] ;

    }

    o u t p u t _ s a m p l e ( f i l t _ b u f f [ i d x ] = f i l t _ b u f f [ i d x = ( i d x + 1 ) % d e l a y ] * a l p h a + s m p l * ( 1 - a l p h a ) ) ;

    in t d t = t oc ( ); / / g et t im er v al ue

    return ; / / r e tu r n f r om i n t er r u pt

    }

    3

  • 7/25/2019 EE 586L Report

    4/6

    Optimization 5

    I removed removed the modular arithmetic. The run time went from 117 to 112 tics.

    / / I n t er r u pt S e r vi c e R o u ti n e

    i n t e r r u p t void c _ i nt 1 1 ( ) {

    tic(); / / s ta rt t he t im er

    if ( + + l oo pi n de x >= l o op _ co u nt ) {

    l o op i nd e x = 0 ;

    if ( l e d _ st a t e ) {

    D S K 6 7 1 3 _ L E D _ o n ( 0 ) ;l e d_ s ta t e = 0 ;

    } else {

    D S K 6 7 1 3 _ L E D _ o f f ( 0 ) ;

    l e d_ s ta t e = 1 ;

    }

    }

    if ( ++ p e r i o d _ in d x > = p e r i od _ c ou n t ) {

    p e ri o d_ i nd x = 0 ;

    }

    short s m p l ;

    short d i p = D S K 6 71 3 _ D IP _ g e t ( 1 );

    if ( dip == 0) {

    s m pl = i n p ut _ s a mp l e ( ) ;

    } else {

    s m pl = s i n _t b l [ ( p e r i od _ i nd x * t b l _s i z e ) / p e r io d _ co u n t ] ;

    }

    if ( ++ i d x >= d el ay ) {

    idx = 0;

    }

    o u t p ut _ s a mp l e ( f i l t _ bu f f [ i d x ] = f i l t_ b u ff [ i d x ] * a l p ha + s m pl * ( 1 - a l p ha ) ) ;

    in t d t = t oc ( ); / / g et t im er v al ue

    return ; / / r e tu r n f r om i n t er r u pt

    }

    Failed optimization

    The original iteration was pretty sparse of floating point operations (with the only exception being the setup which I didntcount in the runtime and the multiplication of the alpha factors). I tried computing the alpha multiplications with fixedpoint ops, however it actually reduced the performance by a factor of about 2 (presumably because of the increase in thetotal number of ops required - extra divisions for normalization).

    4

  • 7/25/2019 EE 586L Report

    5/6

    Optimized source code

    / / s i n e8 _ i n tr . c A s s ig n m en t 2 s o l ut i o n : N o la n M i ll e r

    # inc lud e " D S K 67 1 3_ A I C2 3 . h " // codec su ppor t

    # i n c l ud e < m a th . h >

    # i n c l ud e < c s l _ ti m e r . h >

    # i n c l ud e < c s l .h >

    # i n c l ud e < c s l _i r q . h >

    U i n t 3 2 fs = D S K 6 7 1 3 _ A I C 2 3 _ F R E Q _ 4 4 K H Z ; / / s et s a m pl i n g r a te# d e f in e D S K 6 7 13 _ A I C2 3 _ I N PU T _ M I C 0 x 0 0 15

    # d e f in e D S K 6 7 13 _ A I C 23 _ I N PU T _ L I NE 0 x 0 0 11

    U i n t 1 6 in p u t s o u r c e = D S K 6 7 1 3 _ A I C 2 3 _ I N P U T _ M I C ; / / s e le ct i np ut

    short l o op i nd e x = 0 ; / / l oo k u p t ab le i nd ex

    / / U in t 16 s ps = 4 41 0 0;

    # d e fi ne F L AS H _R A TE 2 / / H z

    U i nt 16 l o op _ co u nt = ( 4 41 00 / ( 2 * F L AS H _R A TE ) ) ;

    short l e d_ s ta t e = 0 ;

    # d e f in e A U D IO _ F RE Q 1 0 0

    U i nt 16 p e ri o d_ i nd x = 0 ;

    U i nt 16 p e ri o d_ c ou n t = ( 44 1 00 / ( A U DI O _F R EQ ) ) ;

    # d e f in e t b l _s i z e 1 0 0

    short s i n _t b l [ t b l _ si z e ] = { 0 };

    / / {0 , 64 3 , 9 85 , 8 66 , 3 42 , - 342 , -8 66 , - 985 , -6 43 , 0 };

    # d e f in e g a in 1 0 00 0

    # d e f in e M _ PI 3 . 1 4 1 59 2 6 5 3 58 9 7 9 3 23 8 4 6

    / // / G IV ES US A T IM ER / // /

    T I M E R_ H a n dl e t m ;

    void t i m e r _ i n i t ( ) {t m = T I M ER _ o pe n ( T I M E R_ D EV 1 , T I M E R_ O P E N_ R E S ET ) ;

    T I M E R _ c o n f i g A r g s ( t m , T I M E R _ C T L _ R M K (

    TIMER_CTL_INVINP_NO ,

    TIMER_CTL_CLKSRC_CPUOVR4 ,

    TIMER_CTL_CP _PULSE ,

    TIMER_CTL_HLD _YES ,

    TIMER_CTL_GO_NO ,

    TIMER_CTL_PW ID_ONE ,

    TIMER_CTL_DA TOUT_0 ,

    TIMER_CTL_INVOUT_NO ,

    T I M E R _ C T L _ F U N C _ G P I O ) , 0 x 0 0 1 0 0 0 00 , 0 x 0 0 0 0 0 0 0 0 ) ;

    }

    void t i c ( ) { T I M E R _ st a r t ( t m ) ;}in t t oc ( ) { return T I M E R _ g e t C o u n t ( t m ) ; }

    / // / B AC K T O T HE C OD E N OW / // /

    void i n i t _ si n _ t bl ( ) {

    in t i ;

    fo r ( i = 0; i < t bl _s iz e ; i + +) {

    s in _ tb l [ i ] = ( short ) r o u n d ( g a i n * s i n ( i * ( M _ P I * 2 . 0 / ( t b l _ s iz e - 1 ) ) ) ) ;

    }

    }

    5

  • 7/25/2019 EE 586L Report

    6/6

    # d e f in e d e la y 1 0 00 0

    short f i l t_ b u ff [ d e l a y ] = { 0 };

    float a l ph a = . 3;

    short i dx = 0;

    / / I n t er r u pt S e r vi c e R o u ti n e

    i n t e r r u p t void c _ i nt 1 1 ( ) {

    tic(); / / s ta rt t he t im er

    if ( + + l oo pi n de x >= l o op _ co u nt ) {l o op i nd e x = 0 ;

    if ( l e d _ st a t e ) {

    D S K 6 7 1 3 _ L E D _ o n ( 0 ) ;

    l e d_ s ta t e = 0 ;

    } else {

    D S K 6 7 1 3 _ L E D _ o f f ( 0 ) ;

    l e d_ s ta t e = 1 ;

    }

    }

    if ( ++ p e r i o d _ in d x > = p e r i od _ c ou n t ) {

    p e ri o d_ i nd x = 0 ;

    }

    short s m p l ;short d i p = D S K 6 71 3 _ D IP _ g e t ( 1 );

    if ( dip == 0) {

    s m pl = i n p ut _ s a mp l e ( ) ;

    } else {

    s m pl = s i n _t b l [ ( p e r i od _ i nd x * t b l _s i z e ) / p e r io d _ co u n t ] ;

    }

    if ( ++ i d x >= d el ay ) {

    idx = 0;

    }

    o u t p ut _ s a mp l e ( f i l t _ bu f f [ i d x ] = f i l t_ b u ff [ i d x ] * a l p ha + s m pl * ( 1 - a l p ha ) ) ;

    in t d t = t oc ( ); / / g et t im er v al ue

    return ; / / r e tu r n f r om i n t er r u pt

    }

    void m a in ( ) {

    i n i t _ s i n _ t b l ( ) ;

    t i m e r _ i n i t ( ) ; / / s et up t he t im er

    D S K 6 7 1 3 _ L E D _ i n i t ( ) ;

    D S K 6 7 1 3 _ D I P _ i n i t ( ) ;

    c o m m _ i n t r ( ) ; / / i n it i al i se D SK

    while (1); / / i nf i ni te l oo p

    }

    6