Artöm
It may be missed optimization
Pavel
Why shouldnt be different? One of them is “and” other one is “binary and” operator. There is no shortcut evaluation for binary operator.
They produce the same behaviour with no side effects involved. The code is rather simple. I mean, why the compiler not generated the most efficient version in both cases.
Anonymous
They produce the same behaviour with no side effects involved. The code is rather simple. I mean, why the compiler not generated the most efficient version in both cases.
because bitwise AND works on integral types and outputs an integral type. logical AND works on bool and outputs a bool
Anonymous
Hello
Anonymous
so we could have a logical AND operator that behaved like bitwise AND. that would be inefficient, so the standard has short-circuit evaluation for logical AND.
Pavel
Well, so that means I need to use bitwise AND here to make it explicit that I don't care about short-circuit evaluation?
Pavel
I mean, is the second variant preferable then?
Anonymous
Well, so that means I need to use bitwise AND here to make it explicit that I don't care about short-circuit evaluation?
no. you should use logical AND here because once again—bitwise AND works on integral types, logical AND works on bools
Anonymous
Anonymous
Pavel
Yep, my point is, that it seems to me (but I'm not sure) that the assembly code generated in the second case (with bitwise AND) is more efficient because it doesn't have branching (conditional jumps) in it.
Anonymous
Yep, my point is, that it seems to me (but I'm not sure) that the assembly code generated in the second case (with bitwise AND) is more efficient because it doesn't have branching (conditional jumps) in it.
unless you can guarantee that the three short circuit jumps will fail (in which case just have the fourth check only?) i think the logical operator will be faster
Pavel
Here I pasted it https://pastebin.com/dyAzW4yd
Pavel
because it doesn't have conditional jumps in it, and as I heard they bad for branch predictor
Pavel
Actually I started thinking about that when I found this in UE4 core code checkSlow((ArrayNum >= 0) & (ArrayMax >= ArrayNum)); // & for one branch But in that case as far as I remember assembly code was generated almost identically, so I thought it is some old stuff from the days when compilers wasn't so smart
Tokin
Btw are there ppl in here who prefer procedural way of handling solutions.. Instead of object oriented ways.. Even while using C++??
Tokin
Or did I frame the question in a wrong way?
Pavel
OK, I think I got it, thanks for the explanation @lightness_races_in_orbit, @chandradeepdey
Tokin
Definitely it would seem it's better to approach some questions in a certain way.. Coz it'd be easier or efficient in the longer run..
Tokin
Welp.. Maybe I'll ask that question once I dedicate myself to solve problems in a procedural way and then.. After some time.. I'll try doing that in object oriented way..
Cengizhan
I guess for assembly bool is also an integral type
Also, I am not sure that a comparison of two float point in this way, might cause such problems without epsilon value that you have to define.
Anonymous
It's not C with classes
Tokin
In the realm of game dev.. Do ppl prefer OOP as the main paradigm?
Pavel
In the realm of game dev.. Do ppl prefer OOP as the main paradigm?
As far as I've seen, OOP (well, depends on what meaning you put in it) is used everywhere in the high-level design, more procedural style with Data-oriented design (DOD) approaches used in low-level code.
Anonymous
/adminlist
Anunay
Heya
Anonymous
Heya
heya!
Anonymous
who is owner of this big community🤩
Anonymous
A guy named Mester
i thought dima is owner
Anunay
He went MIA couple of years ago
Anunay
Missing in attendance
Tokin
Maybe he found something better
Anonymous
Anonymous
Group is full of serious and Focused peps
Tokin
Yeah barely 7% are alive online.. And from those 7% .. Barely 1% are active
Ludovic 'Archivist'
Group is full of serious and Focused peps
Well, it is a c and c++ group, we are only here when we make clean & make -B
Dima
such a suspicious name
Aasif
if I pass a 2d array as an argument to a c++ function like this - void f(char **A), then within the function, can I access A[0][0] as the 0th row and 0th column of char array A?
Alex
Yes
Aasif
okay. thanks!
Lui
/get cbook
Verckys
/get
Verckys
/get cbook
Lui
/get cppbookguide
Andrei
Thanks !
jr somalia
Thanks you 🙏
Веселый Роджер
Heya😁 Can anyone help? I need to copy the behavior of strlcat But i dont understand how exactly it works. Can anyone enlighten ?
Manoj
Tq
Pavel
I noted that MSVC generates different disassembly for these two cases: https://godbolt.org/z/bsn93G As far as I know conditional jumps are bad for branch predictor and unnecessary conditional jumps are better to be avoided. In this case I expected that the compiler will not do short-circuit evaluation because it's only float comparisons (shouldn't they be simple enough?). Can someone explain why the compiler didn't get rid of the jumps and didn't make it the same with the second variant? Does the second variant have some disadvantages?
Update: Benchmarked it with random data. https://ideone.com/CtLqwC The second variant (with bitwise AND) is always faster. The variants get closer in time if the data is prepared in a way when the check always fails or when the check always succeeds. That looks exactly like a branch predictor thing. In the worst case, the difference is more than twice, and surprisingly the worst case happens when data is prepared in a way when the check fails often than succeeds (succeeds in 11% cases). These should be the cases when short-circuit evaluation should stop early more often. So it doesn't look like float comparison is somewhat heavy compared to branch misprediction. Got similar results on MSVC @lightness_races_in_orbit, @chandradeepdey, poke you as you may be interested.
Огни
What projects you done?
Веселый Роджер
I dont get what to do if a get an empty array. It says both dest and src should be terminated. How do i do that?
Огни
What projects you done?
Game, chat, website etc
Anonymous
Game, chat, website etc
In which language you create game
Tokin
That was random DST
Огни
I asked a question for us: what projects have you done?
Tokin
Us?
Огни
accidentally answered the wrong message
Огни
I want to see what people done on c++
Monday Morning
You are given 3 integers a,b &c. Can bitwise OR of (b and c )can be calculated if you are provided bitwise OR of (a and b) and(a,b and c) ?
Anonymous
I want to see what people done on c++
Chromium, Tensorflow, LLVM are made with C++
Mar!o
Chromium, Tensorflow, LLVM are made with C++
GTAV, RedDeadRedemption2, Unity, UnrealEngine, Cryengine, Fortnite, FarCry, CounterStrike all C++
Огни
Nono, what only one programmer done
Anonymous
Nono, what only one programmer done
Alone programmer is useless
Mar!o
Even alone you can write an engine or game or AI
Anunay
Anunay
Or what
Anonymous