flat assembler
Message board for the users of flat assembler.

Index > Heap > CPUs running hurdles

Thread Post new topic Reply to topic

Joined: 25 Sep 2003
Posts: 2141
Location: Estonia
Dear reader,
For a very long time I have not started a new topic and for the second reason, I don't have a blog Smile So to the topic...
Today I was wondering about CPUs and their long latencies when mispredicting branches. I have always tryed to minimize the jumps in the code and make it as fluent as possible. Sometimes it introduces wierd code and that is the time you wonder why? I occured to me that CPU isn't very smart and it likes to do routine jobs like some people. When they are disturbed, they get cranky and mumble something about concentration and starting over. Actually programmers do not care about the CPU, but think about the pain you cause it every time you make a jump that is not predicted. They have their horizon and they are already seeing those nice ADDs waiting to be executed when something happens - the code needs to jump - to somewhere that is far away and unknown. Oh horror!
But what about these ADDs, they are so easy to execute. Erm, no, CPUs don't do easy tasks, but they do something fancy like FSINCOS that is a juicy 100+ clock instruction. They need to forget about those ADDs and just as they have flushed their microinstruction caches - a miracle happens. The code needs to jump BACK where it came from and now CPU can execute ADDs and other easier instructions. Now the problem is that the cache was usage was wasted. It needs to be filled again.
You can pet your CPU better if you give it some power-drink while its running the hurdles. This way your CPU doesn't have to jump far to fetch some information. With conditional moves this is possible. You will feed the needed register just-in-time for you CPU and no jumping is needed. Think about running hurdles and you have your rhythm and then one hurdle is brough closer. Usually you stumble and try to continue. It costs time. That is exactly how it feels for a CPU when you make a mispredicted branch or self-modifying code.

Think about it Very Happy


My updated idol Very Happy http://www.agner.org/optimize/
Post 22 Aug 2006, 15:48
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
Verbosity in development

Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
you really seem to need a blog... Wink
Post 22 Aug 2006, 16:42
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum

Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.