On Mon, 3 Aug 2009, Dave Tweed wrote: > sergio masci wrote: > > On Sun, 2 Aug 2009, Dave Tweed wrote: > > > My point was, that if you add a simple boolean flag to the FIFO > > > structure, you CAN completely fill it, and this actually has negligible > > > impact on the overall code size, and does NOT affect its thread-safe > > > properties. > > > > Ok, so please show how you would do this. > > Oh, no, that would be telling! :-) > > I've already written this up as part of the EQ quiz for Circuit Cellar #230 > (September 2009), so you'll be able to read my solution there by the end of > the month. In the meantime, give it some thought. It's actually quite > straightforward. Now I'm curious :-) But I'll respect decission and I wont discuss it here. If I send you an offlist message (to your from address) will you receive it or will your spam filter reject it as not coming from the piclist? > > > As a mater of interest what limitted expression-handling capabilities do > > you see this code trying to get around (with the use of the temporary > > variable). > > Well, you wrote it with only one operation per line. With the "proc" > keyword, it wasn't immediately obvious that this was C code. I was also > suspicious of storing the length, head and tail of the FIFO in the array > with the data. You wouldn't ordinarily do that unless a language limitation > was forcing you to. I just assumed it was some personal language of yours > that was even lower-level than C, and I guessed that it was either easily > translatable to assembly, or that it had come from assembly to begin with. > > In C, of course, you would simply write something like: > > tail = (tail + 1) % FIFO_SIZE; > > Or, if your compilier isn't smart enough to optimize the % operator: > > tail = (tail + 1 == FIFO_SIZE) ? 0 : tail + 1; > > Either of these is perfectly thread-safe; no standards-compliant compiler > would turn either statement into multiple assignments to tail. Is this guarenteed anywhere? I can see: tail = (tail + 1) % FIFO_SIZE; being optimised to (if FIFO_SIZE is a power of 2): incf tail movlw FIFO_SIZE-1 andwf tail and tail = (tail + 1 == FIFO_SIZE) ? 0 : tail + 1; being optimised to: incf tail movf tail, w xorlw FIFO_SIZE btfss STATUS, Z clrf tail Friendly Regards Sergio Masci -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist