I am trying to compile libsoxr (it is derived from libsox library by Audacity team) library. I can compile osx 32, osx 64 and win32. They use inline asm and Windows x64 platform doesn’t support inline asm. Problematic code piece is this:
#if HAVE_FENV_H
#include <fenv.h>
#elif defined _MSC_VER
#define FE_INVALID 1
#define FE_DIVBYZERO 4
#define FE_OVERFLOW 8
#define FE_UNDERFLOW 16
#define FE_INEXACT 32
#define FE_ALL_EXCEPT (FE_INEXACT|FE_DIVBYZERO|FE_UNDERFLOW|FE_OVERFLOW|FE_INVALID)
static __inline int fetestexcept(int excepts)
{
short status_word;
__asm fnstsw status_word
return status_word & excepts & FE_ALL_EXCEPT;
}
static __inline int feclearexcept(int excepts)
{
int16_t status[14];
__asm fnstenv status
status[2] &= ~(excepts & FE_ALL_EXCEPT);
__asm fldenv status
return 0;
}
#endif
I don’t know what fnstenv and fldenv do. May somebody guide me for making compatible with x64?
Assuming that you are compiling with the Microsoft compiler then you can use RTL functions instead of inline assembly.
To test for particular floating point status flags call
_statusfp. To clear floating point status flags call_clearfp.In order to use
_statusfpyou’ll need to translate from the raw 8087 flags, to the abstract flags used by_statusfp.Update
The code in the question is an implementation of a small part of
fenv.hwhich is part of C99. It’s needed for the MS compiler since it only implements C89. In my view you would be much better off using a real C99 compiler. That would come with an implementation offenv.h.