Optimizing SPIN code for performance (array copies)
ags
Posts: 386
I'm using a circular buffer similar to the rx_buffer in the Propeller Serial Terminal object, and am wondering which is faster when copying a byte sequence from the circular buffer to another (linear) buffer. [Recall that in a circular buffer (source) sequential bytes may wrap around from the end of the circular buffer back to the beginning] The circular buffer will be 64, 128 or 256 bytes long. I'll be copying anywhere from 6 to nearly the entire (circular) buffer length at a time. I'll need to check for the overflow (wrap around) condition in either case.
I think it boils down to the question: how much faster (if at all) is bytemove compared to using a repeat loop incrementing one byte at a time? Is bytemove slower for small copies (say one byte) but then faster beyond a "break even point" where the cost for setting up the move becomes dominated by the speed of the SPIN interpreter optimization?
I think it boils down to the question: how much faster (if at all) is bytemove compared to using a repeat loop incrementing one byte at a time? Is bytemove slower for small copies (say one byte) but then faster beyond a "break even point" where the cost for setting up the move becomes dominated by the speed of the SPIN interpreter optimization?
Comments
A tight loop calling the rx_check method can process slightly more than 57,600 baud. With rxblock1 you can process over 1 mega-baud. This routine uses a handle that points to a struct containing the rxhead, rxtail, rxmask and rxbuffer values. rx_head, rx_tail, rx_mask and rx_buffer are byte offsets into the struct. In the normal serial driver rx_head, rx_tail, rx_mask and rx_buffer are the actual variables, and you would use them directly.