Polynomial
Polynomial

Reputation: 28346

Can an inline assembly (__asm) block prevent function optimisation?

When using Microsoft Visual C++ (not CLI, just standard native C++) does inline assembly cause optimisation to be disabled for the function?

When I checked using IDA, some of the function code outside the block does seem to change, but I'm not sure what the cause is. The function is (relatively) simple, containing bit manipulation and some math, but no external calls.

Other possible causes I could think of are:

Any ideas?

Upvotes: 6

Views: 751

Answers (1)

dirkgently
dirkgently

Reputation: 111298

Yes. See the MSDN articles: Optimizing Inline Assembly as well as Advantages of Inline Assembly

From the article:

The presence of an __asm block in a function affects optimization in several ways. First, the compiler doesn't try to optimize the __asm block itself. What you write in assembly language is exactly what you get. Second, the presence of an __asm block affects register variable storage. The compiler avoids enregistering variables across an __asm block if the register's contents would be changed by the __asm block. Finally, some other function-wide optimizations will be affected by the inclusion of assembly language in a function.

Upvotes: 13

Related Questions