Forum > Embedded

A circular / ring buffer for embedded

(1/5) > >>

d.ioannidis:
Ηι,

  if you need a circular / ring buffer, I added the spsc_ringbuffer  in ccrause's fpc-avr github repo. It's very small, fast, lock free and even if it's in an AVR specific repo it's not only for AVR ( i think ... :) ).

  It's a single producer / single consumer ring buffer. That means that there must be only one reader and only one writer. The basis for this came from an article in Jack Ganssle's Embedded Muse: http://www.ganssle.com/tem/tem110.pdf and with hints from this forum thread ( thx Martin ! ) .

Have fun !

regards,

marcov:
Shouldn't at least some of those be inline?

d.ioannidis:
Hi,


--- Quote from: marcov on October 10, 2022, 03:19:24 pm ---Shouldn't at least some of those be inline?

--- End quote ---

AFAIU, inline will have numerous copies of the same code at many places and I wanted it to be as small as possible .

I'll look again the asm tonight to see if I missed something .

regards,

marcov:

--- Quote from: d.ioannidis on October 10, 2022, 03:54:02 pm ---AFAIU, inline will have numerous copies of the same code at many places and I wanted it to be as small as possible .

--- End quote ---

But the code might be smaller than the function overhead.


--- Quote ---I'll look again the asm tonight to see if I missed something .

--- End quote ---

I don't do much AVR work, mostly dspic. (in C, not Pascal). Dspic-E and -Cs have a 4 cycle branch, so inlining wins back 3 cycles before even anything else is done.

d.ioannidis:
Hi,


--- Quote from: marcov on October 10, 2022, 04:07:33 pm ---
But the code might be smaller than the function overhead.


--- End quote ---

If all the methods are inlined, then if the amount of calls to readbyte and/or writebyte methods is more than > 2 in the project, the project size is increased more than if you didn't inline them. But if the amount of calls to readbyte and/or writebyte methods is <=2, then the project size is smaller than if you didn't inline them.  %)

Now I'm little puzzled on what I should use .... Maybe a define. some ifdef's and inform the user of the buffer library, for the pros and cons of enabling inline or not .


--- Quote from: marcov on October 10, 2022, 04:07:33 pm ---
I don't do much AVR work, mostly dspic. (in C, not Pascal). Dspic-E and -Cs have a 4 cycle branch, so inlining wins back 3 cycles before even anything else is done.


--- End quote ---

If by branch you mean conditional branch, then AFAIK, on AVR is 1 cycle if condition is false and 2 cycles if the condition is true ( instruction pointer needs to be loaded with new target ). No much gain in this regard . If you mean call or rcall then it's 4 cycles ( for the mcu's with 16 bit PC that is ) as the Dspic-E you use .

regards,

Navigation

[0] Message Index

[#] Next page

Go to full version