Artöm
It requires less bytes in asm
3 for xor, 5 or 6 for mov
Ariana
gcc automatically does xor
Artöm
uh no
I mean xor vs mov, not =0 vs ^=
Ariana
yes
Ariana
gcc does xor anyways
Artöm
Ariana
ik mov eax 0 is 5 bytes cant rmb xor eax eax
Artöm
afair 3
Ariana
oh its 2
Ariana
31c0
Ariana
thats nice to know
Artöm
0500000000 for mov eax 0
Well, I'll have asm classes next year only
Ariana
no one memorises shellcodes actually
Ariana
But overtime if you do shellcoding for exploitation you’ll memorise some of them subconsciously
Ariana
anyways use var=0, basically all compilers would xor eax eax anyways
Ariana
try to avoid bitwise operations cuz it just makes the code more unreadable
Ariana
Unless theres a very specific purpose like fast inverse square root
Artöm
no one memorises shellcodes actually
No need. For C asm is enough. Not for compiler writers, but that's a different level
Ariana
I said no one memorise them anyways.-.
Francisco
gcc does xor anyways
It does xor when optimization level is -O2 or higher. With -O1 it does the move
Ariana
(but overtime you’ll remember some common ones)
Ariana
even for xmm
Mihail
At least in GCC -O2 is minimum
Mihail
Weird but you should be using O2 anyways
Ariana
hmm thats weird
Ariana
anyways theres legit no reason tp not use O2
Francisco
Ariana
oh wait what
Ariana
It does for floats but not for ints
Ariana
my gcc is weird
Artöm
Weird but you should be using O2 anyways
And debugging? inline makes it harder
Ariana
It's easier to debug
(you have the source code why bother reading assembly)
Mihail
And debugging? inline makes it harder
No I mean for final builds like ones you'd publicly release
Francisco
(you have the source code why bother reading assembly)
Cause the compiler does crazy things when optimizing, and sometimes it can eliminate calls you want to debug
Mihail
For debugging there is Og
Artöm
Ariana
i dont find debugging with assembly useful tbh, like it doesn’t tell you much unless your one line is like 50 operations
Ariana
tho i do occasionally miss -g and just debug in assembly from laziness
Francisco
Ariana
uh no?
Ariana
unless your code does nothing in O(n)
Ariana
Then might as well O(n^n) to O(1)
Francisco
Then might as well O(n^n) to O(1)
It's for special cases, not always, obviously
Ariana
im quite sure O(n) to O(1) isn’t possible
Artöm
unless your code does nothing in O(n)
Summation and popcnt are famous examples
Ariana
Eh do you consider them O(n)
Artöm
Clang transforms loop to n(n+1)/2
Ariana
Exactly
Ariana
The thing is O(1), just that it is implemented pretty poorly
Artöm
Eh do you consider them O(n)
Yeah, since in source it's array traverse
Ariana
or by someone who doesn’t know Σn
Francisco
Eh do you consider them O(n)
No, the fact you program a summation with an O(n) algorithm and the compiler deduces the formula is quite amazing
Ariana
Isnt it like hardcoded?
Mihail
The thing is O(1), just that it is implemented pretty poorly
There is no way to use popcnt tho, is there? Without inline asm
Ariana
oh
Mihail
It's pretty fucking smart tbh
Ariana
wait so if i sum like n^5 it can collapse it to like a sextic for me
Artöm
Isnt it like hardcoded?
They use some heuristics to recognise pattern. Same for popcnt
Ariana
that’s pretty impressive
Mihail
Because of the intermediate representation
Mihail
It's so verbose
Mihail
And things like this stand out
Francisco
https://kristerw.blogspot.com/2019/04/how-llvm-optimizes-geometric-sums.html
Francisco
The maths behind the compiler are quite impressive tbh
Ariana
insane
Ariana
automated solver for O(1) problems
Francisco
That's why sometimes you want no optimizations for debugging, because of this kind of stuff
Ariana
For me debugging i just add the -g and thats it
Mihail
Mihail
So might as well do that
Francisco
Og is all the optimizations which won't affect debugging
-Og enables optimizations that do not interfere with debugging