|
If I understand your question, and the problem correctly, then because of locality. The code would be in the cache. And based on what you said before, it uses history to predict, but most recently you also said it would rely on branch order - i am a little unclear on that, but right now I'm assuming you mean it uses both, which seems likely.
Real programmers use butterflies
|
|
|
|
|
honey the codewitch wrote: it uses history to predict Yeah, the 'jump table' would most likely have that address with a weighted score.
honey the codewitch wrote: but most recently you also said it would rely on branch order - i am a little unclear on that I think looking at executables as a visual graph[^] make it easier to understand. The cpu does not have any control over branch ordering. Your compiler/linker controls this. This entire conversation was about how likely and unlikely keywords affect that ordering. And how that influences branch prediction.
Anyway, I am falling behind in my work, gotta go
|
|
|
|
|
Randor wrote: The cpu does not have any control over branch ordering. Your compiler/linker controls this.
Yeah, I understand that. What I'm saying is you seemed to be saying that the CPU relies on the order those branches appear in the instruction stream in order to predict. I heard you as saying it would favor the first one it encountered. Maybe I misunderstood you.
Randor wrote: Anyway, I am falling behind in my work, gotta go
Don't work too hard.
Real programmers use butterflies
|
|
|
|
|
Stuart,
We are discussing jump tables in the CPU related to branch prediction. There are two address locations in the example you have given that would be added to the jump table. Both the je and jne would result in a jump table entry. It's actually extremely easy to understand:
Branch prediction basically works like this: (note that this is a simplification and each vendor does it differently)
- As your program is executing the CPU tracks each and every time a jump instruction has executed. It keeps a table of the address of these jumps and increments an internal counter each time that jump instruction is executed.
- As executable code is being loaded and cached, the cpu attempts to predict which path will be executed. It uses that internal counter as a 'weight'. In other words previous taken paths have a higher probability of being chosen. If it incorrectly predicts a path... this is known as a branch misprediction. After a misprediction the cpu has to throw away everything it just computed and go back and predict the path again until it gets it right.(This is actually the core problem with the spectre vulnerability[^]) as you can look at the timing and use very small intervals of time to know what is inside the cpu cache.
The likely and unlikely keywords effect the ordering of the jump instructions in such a way so that branch prediction will be more accurate.
Best Wishes,
-David Delaune
modified 5-Jan-21 3:48am.
|
|
|
|
|
Randor wrote: This is actually the core problem with the spectre vulnerability[^]
I just read about that now, thanks to your comment. I don't know whether to be impressed by the hack, or appalled at the amount of time the creator of it must have had on their hands.
Real programmers use butterflies
|
|
|
|
|
cool. i'll check it out
Real programmers use butterflies
|
|
|
|
|
For something a little bit different, try programming GPUs. You have to think in terms of using a few thousand processors that can all work at once. The challenge is to arrange your algorithm and data so they actually can all work at once. It's really quite fun.
"They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"
|
|
|
|
|
I've played a little bit with that, enough to at least have a general feel for the landscape. It dovetails with this kind of coding actually, because branchless coding tends to be parallelizable. It's not always true of course, but it just tends to lend itself to it.
Real programmers use butterflies
|
|
|
|
|
No offense intended, but I can think of some things that are a lot more fun, and less contrived.
|
|
|
|
|
Anyone worked on Face Recognition projects? I'm looking to write an app and would like some guidance.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
CP Search[^] is a good place to start
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
I've been porting large chunks of C code to C#.
Some routines are quite long and deal with a lot of C "math.h", etc.
In some case, I'll do a straight c "cos" to c# "Math.Cos", for example.
In other cases, a "local delegate" avoids having to make a lot of changes or adding a method with the same name. e.g.
Func<double, double> cos = Math.Cos;
double cosX = cos(x);
double cosY = cos(y).
...
...
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Would this be better as a Tip?
|
|
|
|
|
This brings to mind pre-processor games that attempted to make C more "Pascal-like" by replacing '{' with 'begin', '}' with 'end', etc. This is of limited utility, and only confuses those who expect to see native C# code.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
#define while if
#define true ((__LINE__&31)!=31)
Always fun to work with ...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Who in their right mind would ever let you loose with a preprocessor?
Real programmers use butterflies
|
|
|
|
|
What's the problem? It's true most of the time ...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I mean, wouldn't it just be simpler to pour a sticky beverage on your CPU?
Real programmers use butterflies
|
|
|
|
|
Ah, but sticky liquids don't change the results when you start adding debug code ... :EvilGrinSmiley:
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
In that case, run one of your DRAM sticks over your cat in a dry climate. That should do the trick.
Real programmers use butterflies
|
|
|
|
|
If you have a rope you can hang yourself, it doesn't mean you should.
I'm not sure how many cookies it makes to be happy, but so far it's not 27.
JaxCoder.com
|
|
|
|
|
They should revoke your coding license.
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
This must be a usage of 'fun' specific to Wales.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
I was recently porting C# code to C. I did several times for recent projects. It's because I have years of C# code I'm not actively using but I'm currently developing stuff in C++ and sometimes C
Real programmers use butterflies
|
|
|
|
|
Quote: I've been porting large chunks of C code to C#.
So next you will have to use something like Clang bindings for .NET and Mono written in C# to get it back up to speed
Seriously: did you consider using P/Invoke?
Espen Harlinn
Senior Architect - Ulriken Consulting AS
The competent programmer is fully aware of the strictly limited size of his own skull; therefore he approaches the programming task in full humility, and among other things he avoids clever tricks like the plague.Edsger W.Dijkstra
|
|
|
|