Click here to Skip to main content
14,876,602 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.
 
GeneralRe: WSO CCC OTD 2021-01-18 - we have a winner! Pin
pkfox8-Jan-21 5:02
professionalpkfox8-Jan-21 5:02 
GeneralIt's going to be one of those days. Pin
OriginalGriff7-Jan-21 21:38
mveOriginalGriff7-Jan-21 21:38 
GeneralRe: It's going to be one of those days. Pin
fd97508-Jan-21 1:01
professionalfd97508-Jan-21 1:01 
GeneralRe: It's going to be one of those days. Pin
theoldfool8-Jan-21 1:14
professionaltheoldfool8-Jan-21 1:14 
GeneralRe: It's going to be one of those days. Pin
honey the codewitch8-Jan-21 1:55
mvahoney the codewitch8-Jan-21 1:55 
GeneralRe: It's going to be one of those days. Pin
  Forogar  8-Jan-21 2:30
professional  Forogar  8-Jan-21 2:30 
GeneralRe: It's going to be one of those days. Pin
OriginalGriff8-Jan-21 3:03
mveOriginalGriff8-Jan-21 3:03 
GeneralLearning to live without if() statements Pin
honey the codewitch7-Jan-21 11:07
mvahoney the codewitch7-Jan-21 11:07 
A tale of two functions:

// returns whichever is greatest
int max(int x, int y) {
	if(x>y)
		return x;
	return y;
}

and
// returns whichever is greatest
int max(int x, int y) {
	return x*(x>y)+y*(x<=y);
}

do the same thing

one is much harder to read, but also optimizable in ways the other isn't.

the CPU really likes code like the second one. Even with the extra multiplies, you can use SIMD instructions to pay for that overhead, while the code doesn't interfere with branch prediction

but coding without ifs gets weird really fast. The above is simple. Now add code to do the same thing but operate on 4 32-bit ints at a time so that it efficiently uses SIMD. Or do something more complicated than finding a max of two values and you'll see what i mean.

Smart optimizing compilers can do some of this, and much of the stdlib is already optimized with simd instructions and branch prediction in mind, but when you're trying to squeeze every last cycle out of your CPU you have to take things into your own hands.

It's not something I'd normally do, but I'm working with a codebase that's already highly optimized, to try and make it faster. So this is par for the course.
Real programmers use butterflies

GeneralRe: Learning to live without if() statements Pin
PIEBALDconsult7-Jan-21 11:28
professionalPIEBALDconsult7-Jan-21 11:28 
GeneralRe: Learning to live without if() statements Pin
honey the codewitch7-Jan-21 11:34
mvahoney the codewitch7-Jan-21 11:34 
GeneralRe: Learning to live without if() statements Pin
trønderen7-Jan-21 11:44
Membertrønderen7-Jan-21 11:44 
GeneralRe: Learning to live without if() statements Pin
Peter_in_27807-Jan-21 14:47
professionalPeter_in_27807-Jan-21 14:47 
GeneralRe: Learning to live without if() statements Pin
Chris C-B7-Jan-21 19:43
MemberChris C-B7-Jan-21 19:43 
GeneralRe: Learning to live without if() statements Pin
honey the codewitch8-Jan-21 3:00
mvahoney the codewitch8-Jan-21 3:00 
GeneralRe: Learning to live without if() statements Pin
CPallini7-Jan-21 20:10
mveCPallini7-Jan-21 20:10 
GeneralRe: Learning to live without if() statements Pin
honey the codewitch8-Jan-21 1:53
mvahoney the codewitch8-Jan-21 1:53 
GeneralRe: Learning to live without if() statements Pin
Shao Voon Wong8-Jan-21 0:45
mvaShao Voon Wong8-Jan-21 0:45 
GeneralRe: Learning to live without if() statements Pin
honey the codewitch8-Jan-21 1:53
mvahoney the codewitch8-Jan-21 1:53 
GeneralRe: Learning to live without if() statements Pin
obermd8-Jan-21 3:31
Memberobermd8-Jan-21 3:31 
GeneralRe: Learning to live without if() statements Pin
honey the codewitch8-Jan-21 4:03
mvahoney the codewitch8-Jan-21 4:03 
GeneralRe: Learning to live without if() statements Pin
BillWoodruff9-Jan-21 3:01
mveBillWoodruff9-Jan-21 3:01 
GeneralRe: Learning to live without if() statements Pin
honey the codewitch9-Jan-21 3:16
mvahoney the codewitch9-Jan-21 3:16 
GeneralRe: Learning to live without if() statements Pin
BillWoodruff9-Jan-21 6:12
mveBillWoodruff9-Jan-21 6:12 
GeneralRe: Learning to live without if() statements Pin
honey the codewitch9-Jan-21 6:20
mvahoney the codewitch9-Jan-21 6:20 
GeneralAmazing luck Pin
Cp-Coder7-Jan-21 10:07
MemberCp-Coder7-Jan-21 10:07 

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.