Talk:SE250:lab-1:jham005

From Marks Wiki
Jump to navigation Jump to search

I'm not sure about your explanation of why the noop loop is so slow. You may be right that it's to do with branch prediction, but my understanding was that processors can "learn" simple patterns and always predict the right branch. It was a while ago that I read this, so I don't have a link on hand, but I think it worked by keeping a small variable (maybe a byte) in the instruction cache along with each jump instruction. It's certainly not hard to learn the jump in question, all you'd need is a single bit indicating whether the jump was taken last time, and you'd just predict that if it was taken last time, it will probably be taken this time too. Using that algorithm, worst case in this particular scenario would be two wrong predictions. In practice I think it can learn longer patterns, so it might also take longer to figure it out, but not a million iterations.

If I had to guess why noop took longer, I'd blame the instruction decoder (or whatever it's called), or perhaps the scheduler. But I don't know enough about them to make any educated guesses. If you or anyone has a more technical explanation, I'd love to read it.

Dols008 21:03, 5 March 2008 (NZDT)