Go Down

Topic: Fast Data Type (Read 1 time) previous topic - next topic

Korman

#5
Sep 25, 2010, 03:34 pm Last Edit: Sep 25, 2010, 03:44 pm by Korman Reason: 1
Quote
Using assembly code is not fair


No it isn't, but when people start counting CPU-cycles, what else is one supposed to do?

I don't really know the C-compiler well enough to know how it'll optimise it what will be the resulting codes. In assembler at least, any mess I create is of my own device and I know who to blame.

And I think the SBIC and SBIS are really cool instructions. Perhaps I should make me a T-Shirt with them on it. How about:
I know about SBIC and WDR.
How did you waste your life
to end up here?


Or in a more general view how about: ROR >> LOL
Korman

deSilva

Quote
ROR >> LOL

But that IS cool  8-)

davewking

Thanks for all the ideas! There's a lot of good information to go off of.  I agree with the space issues with the array, I was just using that to illustrate what I need.  Like I said I only need to save a 1 or a 0 for each reading.  I might be missing something, but all the examples are only for a single byte, is there an easy way to do multiple bytes easily?  From what I've seen it looks like the array is slow to assign to because of the indexing, not the actual assignment.

Again, I really appreciate everyone's help with this.

Korman

Writing out a byte is reasonably fast. The code shown above was only to demonstrate various ideas how to handle the bitwise stuff. After that group of 8, you just store the byte and start with the next one. Done in assembler,  writing to the array and incrementing the pointer would entail a penalty of 2 CPU cycles. If you consider that too slow, it's time to rethink your structure and perhaps even the platform choice again.


Korman


westfw

I think you want something like
Code: [Select]
byte bits[512];
byte i;

void loop() {
 byte *ptr=&bits[0];
 i = 0;
 do {
   *ptr++ = PIND;
   i--;
 } while (i != 0);
 do {
   *ptr++ = PIND;
   i--;
 } while (i != 0);
}

Using the two loops prevents the AVR from having to do slower 16bit math...  This will compile to code that would be hard to write any faster using equivalent algorithm (ie looping)
Code: [Select]
void loop() {
 byte *ptr=&bits[0];
 a8:   e0 e0           ldi     r30, 0x00       ; 0
 aa:   f1 e0           ldi     r31, 0x01       ; 1
 i = 0;
 ac:   90 e0           ldi     r25, 0x00       ; 0
 do {
   *ptr++ = PIND;
 ae:   89 b1           in      r24, 0x09       ; 9
 b0:   81 93           st      Z+, r24
  i--;
 b2:   91 50           subi    r25, 0x01       ; 1
 } while (i != 0);
 b4:   e1 f7           brne    .-8             ; 0xae <loop+0x6>
 
 do {
   *ptr++ = PIND;
 b6:   89 b1           in      r24, 0x09       ; 9
 b8:   81 93           st      Z+, r24
   i--;
 ba:   91 50           subi    r25, 0x01       ; 1
    } while (i != 0);
 bc:   e1 f7           brne    .-8             ; 0xb6 <loop+0xe>
 be:   10 92 00 03     sts     0x0300, r1
}
 c2:   08 95           ret


If you need faster than that, replace the loop with 512 consecutive "*ptr++ = PIND;" lines (ugly!)

Go Up