#C to Assembly?

1 messages · Page 1 of 1 (latest)

dark mountain
#

Hi guys,

I am looking for any reference out there that has more or less covered all kinds of usages on how a certain C/C++ code is going to use which x86_64 assembly instruction. Has anyone compiled something like this or anything close to this available?

I am asking because I recently started to relearn assembly language and I just want to see how the compiler is able to optimize away a lot of code using appropriate instructions.

warm plankBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

quaint estuary
dark mountain
#

you misunderstand my question. ofcourse i will use godbolt. but i want to knw if people have tried out with various types of code and see what assembly it generates, hopefully covering a major set of x86_64 instructions

limpid sail
#

the is no direct mapping from C or C++ to assembly.

#

C and C++ are a lot more than just shorthand notation for assembly.

dark mountain
#

ofcourse i understand tht. i think people need to read my question well than blindly answering

cold storm
# dark mountain you misunderstand my question. ofcourse i will use godbolt. but i want to knw if...

You can't.
You would need to do this for every optimization setting for every version for every compiler with every possible code-structures which is just unfeasible (mainly because of the "with every possible code-structure" part).

What you can do is type

gcc -Q -O<level> --help=optimizers
```to let it display all the optimizations it supports together with an `[enabled]`/`[disabled]` depending on whether it's on/off for the given optimization level.
#

And then I guess you can look up the optimizations like e.g. if you wanted to know what

-fbranch-count-reg
```does, then you can look it up on the gcc page where it says:
> `-fno-branch-count-reg`
> 
>     Disable the optimization pass that scans for opportunities to use “decrement and branch” instructions on a count register instead of instruction sequences that decrement a register, compare it against zero, and then branch based upon the result. This option is only meaningful on architectures that support such instructions, which include x86, PowerPC, IA-64 and S/390. Note that the `-fno-branch-count-reg` option doesn’t remove the decrement and branch instructions from the generated instruction stream introduced by other optimization passes.
> 
>     The default is `-fbranch-count-reg` at -O1 and higher, except for -Og.

If you want to get even more in-depth then I guess you can look through the source code of `gcc` yourself, although I probably wouldn't recommend that.
dark mountain
#

!solved

warm plankBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity