Click here to Skip to main content
15,886,919 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.

 
AnswerRe: Programing gut feeling Pin
Greg Utas14-Sep-22 1:07
professionalGreg Utas14-Sep-22 1:07 
AnswerRe: Programing gut feeling Pin
Randor 14-Sep-22 1:21
professional Randor 14-Sep-22 1:21 
GeneralRe: Programing gut feeling Pin
harold aptroot14-Sep-22 5:52
harold aptroot14-Sep-22 5:52 
GeneralRe: Programing gut feeling Pin
Randor 14-Sep-22 6:26
professional Randor 14-Sep-22 6:26 
AnswerRe: Programing gut feeling Pin
PIEBALDconsult14-Sep-22 3:29
mvePIEBALDconsult14-Sep-22 3:29 
AnswerRe: Programing gut feeling Pin
Dan Neely14-Sep-22 3:56
Dan Neely14-Sep-22 3:56 
GeneralRe: Programing gut feeling Pin
  Forogar  14-Sep-22 5:48
professional  Forogar  14-Sep-22 5:48 
AnswerRe: Programing gut feeling Pin
harold aptroot14-Sep-22 5:44
harold aptroot14-Sep-22 5:44 
I'll put the if there, especially if wrapping is unusual.

Even on modern chips with so-called "fast division", 64-bit div (surely we're talking about unsigned numbers here?) takes over a dozen cycles at best. Sure it has only a few µops today, but they're µops with a high latency (or at least one of them is anyway). Further in the past, div only gets worse. Computers with "slow division" are still extremely common. Cascade Lake still had slow division, those are high-end computers that are only a couple of years old.

By contrast, a branch can be bad, but this one won't be, if the comment is to be believed. If wrapping is unusual, then the branch will usually be correctly predicted non-taken. The comparison (and associated loads, if any) that happens before the branch is also nearly irrelevant in that case, because that dependency chain ends in the branch. Code after it does not need to wait until the comparison is done. In the normal case where there is no wrapping, an instruction that uses the new value of gopNr may be able to execute back-to-back with the instruction that produced it (doesn't mean it will, but it could). That is of course impossible if there was a div between them.


If that is expensive, there might even be an if in the operator already...


Doesn't happen on any compiler I'm familiar with. I'm not familiar with the Go compiler, but still. It's not really a thing.

modified 14-Sep-22 11:58am.

GeneralRe: Programing gut feeling - ** Update! ** Pin
jsc4214-Sep-22 22:55
professionaljsc4214-Sep-22 22:55 
GeneralWSO CCC OTD 2022-09-14 Pin
OriginalGriff13-Sep-22 21:47
mveOriginalGriff13-Sep-22 21:47 
GeneralRe: WSO CCC OTD 2022-09-14 Pin
pkfox13-Sep-22 22:37
professionalpkfox13-Sep-22 22:37 
GeneralRe: WSO CCC OTD 2022-09-14 Pin
DerekT-P13-Sep-22 23:06
professionalDerekT-P13-Sep-22 23:06 
GeneralRe: WSO CCC OTD 2022-09-14 - we have a winner! Pin
OriginalGriff13-Sep-22 23:12
mveOriginalGriff13-Sep-22 23:12 
RantI give up Pin
honey the codewitch13-Sep-22 18:29
mvahoney the codewitch13-Sep-22 18:29 
GeneralRe: I give up Pin
CPallini13-Sep-22 20:37
mveCPallini13-Sep-22 20:37 
GeneralRe: I give up Pin
honey the codewitch13-Sep-22 23:34
mvahoney the codewitch13-Sep-22 23:34 
GeneralRe: I give up Pin
Rage13-Sep-22 20:54
professionalRage13-Sep-22 20:54 
GeneralRe: I give up Pin
honey the codewitch13-Sep-22 23:28
mvahoney the codewitch13-Sep-22 23:28 
GeneralRe: I give up Pin
Jörgen Andersson13-Sep-22 20:57
professionalJörgen Andersson13-Sep-22 20:57 
GeneralRe: I give up Pin
honey the codewitch13-Sep-22 23:29
mvahoney the codewitch13-Sep-22 23:29 
GeneralRe: I give up Pin
megaadam13-Sep-22 21:23
professionalmegaadam13-Sep-22 21:23 
GeneralRe: I give up PinPopular
honey the codewitch13-Sep-22 23:32
mvahoney the codewitch13-Sep-22 23:32 
GeneralRe: I give up Pin
Kornfeld Eliyahu Peter13-Sep-22 23:35
professionalKornfeld Eliyahu Peter13-Sep-22 23:35 
GeneralRe: I give up Pin
megaadam14-Sep-22 0:39
professionalmegaadam14-Sep-22 0:39 
GeneralRe: I give up Pin
honey the codewitch14-Sep-22 0:52
mvahoney the codewitch14-Sep-22 0:52 

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.