|
|
|
|
|
by graycat
4843 days ago
|
|
"I think C might make more sense if you are more familiar with assembly language." I've written some assembler in the machine language of at least three different processors. On one machine I was surprised that my assembler code ran, whatever it was, 5-8 times faster than Fortran. Why? Because I made better use of the registers. Of course, that Fortran compiler was not very 'smart', and smarter compilers are quite good at 'optimizing' register usage. I will write some assembler again if I need it, e.g., for R(n+1) = (A*R(n) + B) mod C where A = 5^15, B = 1, and C = 2^47. Why that calculation? For random number generation. Why in assembler? Because basically want to take two 64
bit integers, accumulate in two registers the 128
bit product, then divide the contents of the two
registers by a 64 bit integer and keep the 64
bit remainder. Due to the explicit usage of
registers, usually need to do this in assembler. But at one point I read a comment: For significantly
long pieces of code, the code from a good compiler tends
to be faster than the code from hand coded assembler.
The explanation went: For longer pieces of code, good compilers do good things for
reducing execution time that are mostly too difficult
to program by hand which means that the assembler code
tends to be using some inefficient techniques. |
|