[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Who would win?

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 52
Thread images: 3

File: Untitled.png (9KB, 515x488px) Image search: [Google]
Untitled.png
9KB, 515x488px
Who would win?
>>
>>56852598
If enabled is true, it is false, if its not true, its true, after those operations you would set the Boolean to false, and the setting it to true again.
>>
>>56852598
Second one. The first one is BS and the last one is pretty much the same as the second one but less intuitive and less used (and not all languages have similar construct available).
>>
>>56852598
Terms of speed? Last one.
>>
>>56852763
> doing pre-mature optimization

second and third should be equivalent after compiling
>>
>>56852744
>and not all languages have similar construct available
>not all languages have basic boolean operators
kys
>>
enabled = enabled? false:true
>>
>>56852598
Middle.
>>
>>56852797
Not all languages have a bitwise xor that works this way on boolean values.

>>56852782
All three would probably be the same speed with a reasonably optimizing compiler. I bet gcc would generate the exact same code at -O2 and above, if not -O1.
>>
>>56852858
>Not all languages have a bitwise xor that works this way on boolean values.
just kys
>>
>>56852898
>>>www.reddit.com/r/programming
>>
>>56852858
Here's -O2
>>
>>56853036
>volatile
well memed
>>
>>56853101
What?
>>
enabled = 1 - enabled
>>
>>56853103
Why not use atomic operations while you're at it?
>>
>>56853125
Are you retarded?
>>
>>56853036
>-O2
FUCKING NORMIE LEEEEEEEEEEAVE

-Ofast is only accepted optimization level here
>>
>>56853135
Are you? Adding volatile will completely change code generation compared to OPs question. The same way atomic operations would.
>>
>>56853036
yep, as expected 2nd and 3rd are equivalent. first one isn't because if statements often prevent optimization opportunities.

>>56853101
you're retarded if you don't understand why volatile is necessary here.
>>
>>56853151
>Adding volatile will completely change code generation
No it won't. It's only there to stop the compiler from precomputing the final value of the variable and generating nothing but a single instruction.

I'm not going to write code to randomly generate an initial value just because some idiot doesn't understand simple qualifiers.
>>
>>56853179
>you're retarded if you don't understand why volatile is necessary here.
Babbys first benchmark? If you don't know how to check the generated assembly without adding volatile then you've no place talking in this thread at all.
>No it won't.
Yeah? Then why does GCC at O2 generate completely different code here:
#include <stdbool.h>

extern bool enabled;

void f(void)
{
if (enabled == true) {
enabled = false;
} else {
enabled = true;
}
}

void g(void)
{
enabled = !enabled;
}

void h(void)
{
enabled ^= true;
}


f:
cmpb $0, enabled(%rip)
sete enabled(%rip)
ret
h:
xorb $1, enabled(%rip)
ret
g:
jmp h
>>
>>56853211
>completely different code
>jmp h
This guy really is fucking retarded
>>
>>56852598

Nr. 2
>>
>>56853211
pretty entertaining troll to be honest. lel at jmp h.
>>
File: yir2015-image002.jpg (44KB, 600x444px) Image search: [Google]
yir2015-image002.jpg
44KB, 600x444px
>>56853281
>troll
I don't think so, he's just a moron on his way up to mount stupid
>>
>>56852598
>>56852763
Second one is more common than the third and is faster than the firs. We can all agree though that the first is High School course-teir
>>
>>56852598
just do ~enable
>>
2nd one is more readable
>>
>>56852763
>muh bool ar fester then ur bools bcus i xor dem lul
if your compiler doesn't generate the same assembly for all three, you've got a shit compiler.
>>
>>56853388
Compilers generate the same code for the second two, not the first one.
>>
>>56852598
What kind of operator is ^=?
>>
>>56853416
quantum exclusion
>>
>>56853416
bitwise xor assignment
>>
>>56853416
logical xor equals.

1 1 = 0
0 1 = 1
1 0 = 1
0 0 = 0
>>
>>56853403
You sure famalam?
clang: https://godbolt.org/g/Q0fQ4N
gcc: https://godbolt.org/g/VkRIyQ
icc: https://godbolt.org/g/NtlUcg (last one uses CMP, the other two use TEST, essentailly it's the same)
>>
Last one. Only because my normie coworkers don't understand it.
>>
>>56853452
>-O1
>>
>>56853464
Test other -O parameters yourself, it's not that hard and all of the three cases still produce the same code. C'mon don't be a lazy ass.
>>
>>56853416
a ^= b is equivalent to a = a ^ b
>>
>>56853036
What Editor do u used?
>>
>>56853036
Cute font, what is it?
>>
>>56852598
Set a while loop before this code and put a print/cout in the end that verifies the state of it. That'd be interesting.
>>
>>56853482
vim
>>56853491
profont

>>56853445
It's bitwise, not logical. != is the logical xor, and there is no logical xor equals operator in C
>>
>>56853511
I meant bitwise logic. In this situation it really doesn't matter.
>>
>>56852598
bitwise operations are slow as fuck
>>
>>56853724
No they aren't. Where did you get that idea?
>>
>>56853738
try doing them in javascript
>>
>>56853751
> javascript
hahahahahahahahha
>>
>>56853751
You should have mentioned you were a web dev in the first place so I knew to ignore you
>>
>>56853772
>>56853773
u mad bro?
mad that javascript is the most popular and useful language?
>>
>>56853036
What is this theme?
Thread posts: 52
Thread images: 3


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.