How do I replace __asm jno no_oflow with an intristic in a VS2008 64bit build?
I have this code:
__asm jno no_oflow
overflow = 1;
__asm no_oflow:
It produces this nice warning:
error C4235: nonstandard extension used : '__asm' keyword not supported on this architecture
What would be an equivalent/acceptable replacement for this code to check the overflow of a subtrac开发者_如何学Pythontion operation that happened before it?
First define the following:
#ifdef _M_IX86
typedef unsigned int READETYPE;
#else
typedef unsigned __int64 READETYPE;
#endif
extern "C"
{
READETYPE __readeflags();
}
#pragma intrinsic(__readeflags)
You can then check the eflags register as follows:
if ( (__readeflags() & 0x800))
{
overflow = 1;
}
I assume that the code above is trying to catch some sort of integer overflow/underflow? Maybe the answers to this question will help: How to detect integer overflow?
Here's a list of intrinsics available on all platforms. Looks there's nothing suitable there. I guess the most portable way would be to check before the subtraction whether it will lead to an overflow.
I'm not sure why Microsoft disallowed inline assembly in 64-bit. but you can still write assembly in a separate .asm file, and link your program against it.
精彩评论