SQL Kiwi (9/23/2012)
Jeff Moden (9/23/2012)
SQL Kiwi (9/23/2012)
The C# code will indeed be compiled down to just one machine-code instruction (which may take less than one CPU cycle to execute)...Are you sure, Paul? IIRC, even a simple JMP instruction takes at least 2 clock cycles.
I was referring to the fact that modern processors employ tricks like prefetch, pipelining, branch prediction, speculative execution, out-of-order execution...and so on...meaning that multiple instructions can be retired per clock. An simple instruction that multiplies by two (which may well be optimized to a left shift as Tom mentions) may be timed at 1 clock but might well take less than that. e.g. http://stackoverflow.com/questions/692718/how-to-find-cpu-cycle-for-an-assembly-instruction
Thanks for the explanation, Paul. It's been a long time (6502 days) since I've even gone near machine language. The processors certainly have come a long way at that level.
--Jeff Moden
Change is inevitable... Change for the better is not.