Dear Ger Hobbelt and Dave Thompson,

Thanks for the wealth of information and free lecture. Now, I have followed the 
simple memcpy function you gave earlier, and I have a simple question, which is 
faster ?
1. Memcpy
2. (data[n] & 0xFF) | (data[n+1]<<8 & 0xFF00) | (data[n+2]<<16 & 0xFF0000) | 
(data[n+3]<<24 & 0xFF000000);

I measured the clock cycles my system takes, and it seems memcpy is slower than 
a simple byte alignment function.

> #2 (and this is what the crypto hardware needs!) not only must the
> input be word-aligned, its *length*
> must also be word-aligned. (That's where 'padding' comes in)
> 
> wordsize=8, input length = 21, then the solution is QUITE different:
> 
> 1 2 3 | 4 5 6 7 8 9 0 1 | 2 3 4 5 6 7 8 9 | 0 1
> 
> must be *moved* (copy is fine too ;-) ) to an _aligned_ buffer, i.e.
> 
> -> 1 2 3 4 5 6 7 8 | 9 0 1 2 3 4 5 6 | 7 8 9 0 1
> 
> and padded:
> 
> -> 1 2 3 4 5 6 7 8 | 9 0 1 2 3 4 5 6 | 7 8 9 0 1 p p p |

Yes, this is my scenario (case 2).


> Sigh. Too bad you're not on M68K hardware or other machinery which
> simply (and quite fatally) bombs out on you at a hardware level when
> addressing words at UNaligned boundaries. Ah, those were the days...
> Java doesn't care any more. (Oops, sorry. let's stop this rant in its
> tracks!)
> 
> 
> If you run on Intel (and you very probably are), you don't get that
> penalty, so (performance degrading!) unaligned word accesses will
> 'work'. Combine this with your given fault description, then consider
> that 'aligning the data' /may/ not be the answer you seek -- mark the
> mention of the padding in passing. Consider it a hint that other
> things may be wrong with your code. (hint != answer)

I am using a soft CPU called Nios II (Verilog based CPU from Altera). I am 
running uClinux. Unaligned access does not work for me.

I now am able to get my system working. And I fixed the 'free bugs' in you code 
based on Dave's suggestion.

Regards,
Vishnu.

_________________________________________________________________
Easily publish your photos to your Spaces with Photo Gallery.
http://get.live.com/photogallery/overview

Reply via email to