Click here to Skip to main content
15,885,546 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralBritain's largest supermarket offers to help aid Covid jab rollout by providing use of its distribution arm Pin
OriginalGriff3-Jan-21 11:30
mveOriginalGriff3-Jan-21 11:30 
GeneralRe: Britain's largest supermarket offers to help aid Covid jab rollout by providing use of its distribution arm Pin
RickZeeland3-Jan-21 19:35
mveRickZeeland3-Jan-21 19:35 
GeneralRe: Britain's largest supermarket offers to help aid Covid jab rollout by providing use of its distribution arm Pin
OriginalGriff3-Jan-21 20:47
mveOriginalGriff3-Jan-21 20:47 
GeneralRe: Britain's largest supermarket offers to help aid Covid jab rollout by providing use of its distribution arm Pin
W Balboos, GHB4-Jan-21 3:33
W Balboos, GHB4-Jan-21 3:33 
GeneralRe: Britain's largest supermarket offers to help aid Covid jab rollout by providing use of its distribution arm Pin
OriginalGriff4-Jan-21 4:08
mveOriginalGriff4-Jan-21 4:08 
GeneralRe: Britain's largest supermarket offers to help aid Covid jab rollout by providing use of its distribution arm Pin
W Balboos, GHB4-Jan-21 4:20
W Balboos, GHB4-Jan-21 4:20 
GeneralRe: Britain's largest supermarket offers to help aid Covid jab rollout by providing use of its distribution arm Pin
OriginalGriff4-Jan-21 4:26
mveOriginalGriff4-Jan-21 4:26 
Generalbizarro land coding Pin
honey the codewitch3-Jan-21 8:39
mvahoney the codewitch3-Jan-21 8:39 
I've now entered bizarro land, and I'm programming without conditional branching in code.

That means no ifs, no whiles, no dos.

Superscalar architectures use branch prediction to get way out in front of your instructions - basically it executes ahead - which is cool when it gets it right, but costly when it realizes it has been executing the wrong code this time around.

So one way to prevent branch mispredictions is to ... wait for it! avoid branching.

so instead of say, writing

C++
if(0!=foo)
   printf("foo\r\n");
else
   printf("bar\r\n");


you do like
C++
const char* szfoo="foo";
const char* szbar="bar";
printf("%s\r\n",(szfoo*!!foo)+(szbar*!!(!foo)));

or something to that effect.
printf() probably branches anyway, but I'm just trying to illustrate a concept.

The weird thing is, it generates more, and slower code, because you have to do a bunch of calculations any time you want to simulate branching.

However, they have SIMD which loves branchless code, and can often be used to "pay for" the extra overhead of those computations.

It's funny when you think about it, because effectively, to let the CPU get way out ahead you have to perform a bunch of extra multiplies and adds, that you essentially waste, but it doesn't matter because you're doing 4 of them at a time, and wasting 2 or 3.

So you break even cycle per cycle on the branchless code, but the CPU still executes it faster because of branch prediction, prefetching, and all of that.

Or at least that's how i understand it so far. I'm learning a lot from the simdjson developers.

Fun times.
Real programmers use butterflies

GeneralRe: bizarro land coding Pin
Greg Utas3-Jan-21 8:48
professionalGreg Utas3-Jan-21 8:48 
GeneralRe: bizarro land coding Pin
honey the codewitch3-Jan-21 9:05
mvahoney the codewitch3-Jan-21 9:05 
GeneralRe: bizarro land coding Pin
Randor 3-Jan-21 9:40
professional Randor 3-Jan-21 9:40 
GeneralRe: bizarro land coding Pin
honey the codewitch3-Jan-21 10:53
mvahoney the codewitch3-Jan-21 10:53 
GeneralRe: bizarro land coding Pin
Greg Utas3-Jan-21 10:13
professionalGreg Utas3-Jan-21 10:13 
GeneralRe: bizarro land coding Pin
Stuart Dootson4-Jan-21 0:44
professionalStuart Dootson4-Jan-21 0:44 
GeneralRe: bizarro land coding Pin
honey the codewitch4-Jan-21 2:51
mvahoney the codewitch4-Jan-21 2:51 
GeneralRe: bizarro land coding Pin
Stuart Dootson4-Jan-21 6:49
professionalStuart Dootson4-Jan-21 6:49 
GeneralRe: bizarro land coding Pin
honey the codewitch4-Jan-21 7:05
mvahoney the codewitch4-Jan-21 7:05 
GeneralRe: bizarro land coding Pin
Randor 4-Jan-21 19:51
professional Randor 4-Jan-21 19:51 
GeneralRe: bizarro land coding Pin
honey the codewitch4-Jan-21 23:45
mvahoney the codewitch4-Jan-21 23:45 
GeneralRe: bizarro land coding Pin
Randor 5-Jan-21 0:18
professional Randor 5-Jan-21 0:18 
GeneralRe: bizarro land coding Pin
honey the codewitch5-Jan-21 0:21
mvahoney the codewitch5-Jan-21 0:21 
GeneralRe: bizarro land coding Pin
Randor 5-Jan-21 0:35
professional Randor 5-Jan-21 0:35 
GeneralRe: bizarro land coding Pin
honey the codewitch5-Jan-21 0:45
mvahoney the codewitch5-Jan-21 0:45 
QuestionRe: bizarro land coding Pin
Randor 5-Jan-21 0:56
professional Randor 5-Jan-21 0:56 
AnswerRe: bizarro land coding Pin
honey the codewitch5-Jan-21 1:06
mvahoney the codewitch5-Jan-21 1:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.