This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Integer Overflow/Wrap and GCC Optimizations


[ gcc-help@gcc.gnu.org ? ]

On Thu, 24 Jan 2013, Jeffrey Walton wrote:

Hi All,

I have a question on integer overflow and wrap, and GCC optimizations.

I have a small library that uses inline assembly to check OV/CY flags
for both x86/x64 and ARM. x86/x64 uses FLAGS/EFLAGS, while ARM uses
CPSR.

Do I have to worry about GCC optimizing out addition, subtractions,
etc under any circumstances?

It would help to see what kind of code you are worried about. If the addition is done in an inline asm, gcc doesn't know it is an addition and doesn't optimize it. If it is done outside the asm, you don't have any guarantee that once the asm starts the flags are still what you want.


Note that using unsigned types would avoid a lot of issues.

--
Marc Glisse


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]