• AVR Freaks

Hot!Circular Reference (auto index rollover)

Author
dB4301
New Member
  • Total Posts : 15
  • Reward points : 0
  • Joined: 2019/11/22 14:34:09
  • Location: 0
  • Status: offline
2020/01/17 13:45:56 (permalink)
0

Circular Reference (auto index rollover)

Hello,
 
I am trying to duplicate some functionality on a PIC32 that is used on a TI 5402 chip. They have a feature in assembly that allows an automatic rollover for circular buffers on an index. So for example (not worrying about using pointers for optimization in the example):
 
i= (0 < index value < sizeof(buff1), a circular index)
 
i2=0;
while (i< VAL)
buff1[i++] *= buff2[i2++];
 
...where buff1 is a circular buffer (and buff2 is not and  VAL is within bounds for buff2). The TI function would allow for i (for buff1) to automatically rollover to zero when it reaches  the end without having to check the value of i each time in the while loop.
 
Is there an equivalent way to do this in the PIC32 C environment or even in assembly?
Thanks in advance for your thoughts.
 
#1

6 Replies Related Threads

    NKurzman
    A Guy on the Net
    • Total Posts : 18245
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: Circular Reference (auto index rollover) 2020/01/17 14:26:50 (permalink)
    +1 (1)
    Common ways to do this is to use an 8 bit variable for a 256 byte buffer.
    Or to have the buffer a power of two and XOR the index.
     
    What Opcodes are they using to achieve this?
    #2
    dB4301
    New Member
    • Total Posts : 15
    • Reward points : 0
    • Joined: 2019/11/22 14:34:09
    • Location: 0
    • Status: offline
    Re: Circular Reference (auto index rollover) 2020/01/17 14:44:17 (permalink)
    0
    Hi NKurzman,
     
    So will probably try to use a 256 byte index / array-size if it will appear as rolled-over, but if you had to use an odd values like 124? The XOR sounds like another possibility.
    I wondered if there is some kind of software control for a counter with compare? Probably less efficient than what you are suggesting.
    The multiply accumulate function for TI looks like this:
    rptz a,(rxbuf_len-1) ; repeat next instruction n times
    mac *AR2+,*AR4+0%,a
     
    ...where I believe the "+0%" is the circular reference.
     
    Thanks for your help.
     
    #3
    NorthGuy
    Super Member
    • Total Posts : 5906
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: Circular Reference (auto index rollover) 2020/01/17 15:13:52 (permalink)
    0
    dsPIC33 has hardware rollovers. PIC32 is MIPS and doesn't have anything of that sort.
    #4
    NKurzman
    A Guy on the Net
    • Total Posts : 18245
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: Circular Reference (auto index rollover) 2020/01/17 17:03:32 (permalink)
    0
    The XOR is only for Powers of 2
    For any number modulus will work 
    i = i % 124;
     
    #5
    1and0
    Access is Denied
    • Total Posts : 10294
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Circular Reference (auto index rollover) 2020/01/17 17:20:55 (permalink)
    +1 (1)
    What you are looking for is hardware modulo addressing, which is typical of DSP processor. PIC32 is not DSP.
     
    That being said, if the size is a power of 2 then you can use either bitwise AND or bit clear; e.g. for size of 16
     
    i++;
    i &= 0x0F;   // mask lower bits
     
    i++;
    i &= 0xEF;   // clear bit 4
     
    #6
    NKurzman
    A Guy on the Net
    • Total Posts : 18245
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: offline
    Re: Circular Reference (auto index rollover) 2020/01/17 20:52:03 (permalink)
    +1 (1)
    Yes I think AND is what I was thinking.
    #7
    Jump to:
    © 2020 APG vNext Commercial Version 4.5