Verifying compiler optimizations in gcc/g++ by analyzing assembly listings

前端 未结 8 1935
闹比i
闹比i 2021-02-04 09:00

I just asked a question related to how the compiler optimizes certain C++ code, and I was looking around SO for any questions about how to verify that the compiler has performed

8条回答
  •  青春惊慌失措
    2021-02-04 09:35

    Adding the -L option (eg, gcc -L -ahl) may provide slightly more intelligible listings.

    The equivalent MSVC option is /FAcs (and it's a little better because it intersperses the source, machine language, and binary, and includes some helpful comments).


    About one third of my job consists of doing just what you're doing: juggling C code around and then looking at the assembly output to make sure it's been optimized correctly (which is preferred to just writing inline assembly all over the place).

    Game-development blogs and articles can be a good resource for the topic since games are effectively real-time applications in constant memory -- I have some notes on it, so does Mike Acton, and others. I usually like to keep Intel's instruction set reference up in a window while going through listings.

    The most helpful thing is to get a good ground-level understanding of assembly programming generally first -- not because you want to write assembly code, but because having done so makes reading disassembly much easier. I've had a hard time finding a good modern textbook though.

提交回复
热议问题