I'm currently testing efficient random number generators with 8bit avr microcontrollers. This is one, not very efficient, rng I tested:
It took roughly 1400 cycles to execute on an 8bit avr. I have no intention to try write that in assembly, but I would be interested to hear some estimates of how efficient that could be if written in asm? All numbers and variables are uint 64.
My solution is, instead of wasting my time with asm, to use an AES crypto engine to generate 128bit random numbers.. it does the job in background in 375 cycles.
And a point about the efficiency of C and assembly. The truth is that C is only as efficient as the assembly code generated by the compiler. So far all compilers are better assemblers than I am..
Code:
uint64_t
random64(void)
{
v ^= (v>>21);
v ^= (v<<35);
v ^= (v>>4);
return v + 2685821657736338717LL;
}
It took roughly 1400 cycles to execute on an 8bit avr. I have no intention to try write that in assembly, but I would be interested to hear some estimates of how efficient that could be if written in asm? All numbers and variables are uint 64.
My solution is, instead of wasting my time with asm, to use an AES crypto engine to generate 128bit random numbers.. it does the job in background in 375 cycles.
And a point about the efficiency of C and assembly. The truth is that C is only as efficient as the assembly code generated by the compiler. So far all compilers are better assemblers than I am..