• AVR Freaks

Avoid interrupt push/pop context save for DSP

Author
tilly
Super Member
  • Total Posts : 250
  • Reward points : 0
  • Joined: 2008/02/19 14:01:24
  • Location: 0
  • Status: offline
2009/11/30 04:14:51 (permalink)
0

Avoid interrupt push/pop context save for DSP


Hi,
I am just writing a PID control application for dsPIC33-MC family, and there the PWM interrupt should be as fast as possible as it is invoked very often (for several motors).

I use DSP code only in this PWM interrupt, and I want to get rid of the DSP context save (CORCON, ACCAL, ACCAH, ACCAU, ACCBL, ACCBH, ACCBU). I hope this does not sound too bizarre, but these are 7 push's and 7 pop's which I think I could skip.

Is there some pragma or attribute or other way to tell the compiler, to exclude some registers from the push+pop? I looked through the manual and forum, but did not find any solution.
#1

11 Replies Related Threads

    gcfreddy
    Starting Member
    • Total Posts : 39
    • Reward points : 0
    • Joined: 2009/10/17 22:03:45
    • Location: 0
    • Status: offline
    RE: Avoid interrupt push/pop context save for DSP 2009/11/30 04:24:19 (permalink)
    0
    I often use the attribute ((__interrupt__,no_auto_psv)).

    By using this attribute I only get one push-pop and some working register saved.
    #2
    tilly
    Super Member
    • Total Posts : 250
    • Reward points : 0
    • Joined: 2008/02/19 14:01:24
    • Location: 0
    • Status: offline
    RE: Avoid interrupt push/pop context save for DSP 2009/11/30 04:40:52 (permalink)
    +2 (1)
    Thank you for this fast answer gcfreddy, but this is included already in my interrupt definition, it is defined like this now:

    void __attribute__((interrupt, no_auto_psv)) _PWMInterrupt(void){
    ... some DSP code, as e. g.
    DSPaLoadL( l24_8MeasuredPosition);
    DSPbLoadL( l24_8CommandedPosition);
    DSPaSubB;
    DSPaShiftRightSaveIR( -8, iPidError);                     
    ...
    }


    The macros are given in my previous post, e. g.:

    #define DSPaLoadL(l) asm( "LAC %d0, A\nMOV %0, ACCAL" : : "r"(l) : "A")
    #define DSPbLoadL(l) asm( "LAC %d0, B\nMOV %0, ACCBL" : : "r"(l) : "B")
    #define DSPaSubB  asm( "SUB A" : : : "A" )
    #define DSPaShiftRightSaveIR( Shift_8t7, i) asm( "SAC.R A, #%1, %0\n" : "=r"(i) : "i"(Shift_8t7) : "A")


    I was just playing around a bit more. And I found out, that if I take out the clobber instructions : "A" and : "B" from the asm commands in the macros, then the compiler also deletes the stack saving push and pop for ACCA and ACCB. In this case the compiler does not know any more that the "A" and "B" are changed in the asm instructions. This is slightly dangerous, as it might have also some other implications on the code generation - in worst case I would have to go like this.
    post edited by tilly - 2009/11/30 06:09:53
    #3
    DavidePizzolato
    Junior Member
    • Total Posts : 95
    • Reward points : 0
    • Joined: 2010/11/25 11:55:54
    • Location: 0
    • Status: offline
    RE: Avoid interrupt push/pop context save for DSP 2011/01/20 10:41:33 (permalink)
    0
    Thank you very much tilly, your solution without the clobber instructions works perfectly.
     
    I had a similar problem with the builtin functions: as soon as I write the “register int accA asm("A");” declaration, the compiler fills all the interrupt service routines with push and pops, even if no DSP instruction is used [8D]
    In this case we really need a compiler option to skip unnecessary context savings.
    #4
    threedog
    Super Member
    • Total Posts : 998
    • Reward points : 0
    • Joined: 2009/12/04 12:28:11
    • Location: Boise
    • Status: offline
    Re:Avoid interrupt push/pop context save for DSP 2011/01/20 11:49:47 (permalink)
    0
    Determine what the C compiler generates and use that as a reference.
    Then code up the ISR in pure assembly.
     
    #5
    eddygo
    Super Member
    • Total Posts : 691
    • Reward points : 0
    • Joined: 2004/03/04 15:45:37
    • Location: Bucharest, ROMANIA
    • Status: offline
    Re:Avoid interrupt push/pop context save for DSP 2011/01/20 13:38:05 (permalink)
    0
    Try using __("naked")__ attribute for ISR handler function.

    Regards,
    Edi

    ENEA, OSECK
    http://www.enea.com
    #6
    sborden
    Super Member
    • Total Posts : 1935
    • Reward points : 0
    • Joined: 2010/08/05 02:12:53
    • Location: 0
    • Status: offline
    Re:Avoid interrupt push/pop context save for DSP 2011/01/20 13:48:56 (permalink)
    0
    Now we're getting into sexy programmingSmile!
    #7
    DavidePizzolato
    Junior Member
    • Total Posts : 95
    • Reward points : 0
    • Joined: 2010/11/25 11:55:54
    • Location: 0
    • Status: offline
    Re:Avoid interrupt push/pop context save for DSP 2011/01/20 23:52:44 (permalink)
    0
    eddygo
    Try using __("naked")__ attribute for ISR handler function.

    that attibute is too much, the compiler exits with a parental lock error. "popless" should be enough.
    #8
    cawilkie
    Administrator
    • Total Posts : 1990
    • Reward points : 0
    • Joined: 2003/11/07 12:49:11
    • Status: offline
    RE: Avoid interrupt push/pop context save for DSP 2011/01/21 10:20:49 (permalink)
    0
    DavidePizzolato

    Thank you very much tilly, your solution without the clobber instructions works perfectly.
     
    I had a similar problem with the builtin functions: as soon as I write the “register int accA asm("A");” declaration, the compiler fills all the interrupt service routines with push and pops, even if no DSP instruction is used [8D]
    In this case we really need a compiler option to skip unnecessary context savings.


    These are not unnecessary.  A, B are registers much like W8-W15, the compiler arranges to preserve them if they are used inside a function.  Perhaps we should make one of the registers 'scratch' like W0-W7?

    It is important that at least one of these registers be part of the preserved set in the ABI.

    Regards
    Calum
    #9
    sborden
    Super Member
    • Total Posts : 1935
    • Reward points : 0
    • Joined: 2010/08/05 02:12:53
    • Location: 0
    • Status: offline
    RE: Avoid interrupt push/pop context save for DSP 2011/01/21 13:18:27 (permalink)
    0
    you can also try using "shadow", but only in this one ISR.
    #10
    DavidePizzolato
    Junior Member
    • Total Posts : 95
    • Reward points : 0
    • Joined: 2010/11/25 11:55:54
    • Location: 0
    • Status: offline
    RE: Avoid interrupt push/pop context save for DSP 2011/01/23 23:45:14 (permalink)
    0
    sborden
    you can also try using "shadow", but only in this one ISR.

    No: shadow works for w0-w3, not for DSP accumulators
    post edited by DavidePizzolato - 2011/01/23 23:51:20
    #11
    sborden
    Super Member
    • Total Posts : 1935
    • Reward points : 0
    • Joined: 2010/08/05 02:12:53
    • Location: 0
    • Status: offline
    RE: Avoid interrupt push/pop context save for DSP 2011/01/24 06:32:24 (permalink)
    0
    It still saves a lot of context-saving time.
    #12
    Jump to:
    © 2019 APG vNext Commercial Version 4.5