[erlang-questions] Testing reliable floating points exeption fails on x86?

Mikael Pettersson mikpe@REDACTED
Wed Sep 19 16:28:46 CEST 2007

On Wed, 19 Sep 2007 16:50:51 +0400, Sergei Golovan wrote:
> But what may cause FP exceptions to be unreliable? Do they require
> some special support in Linux kernel for example, or if it's Linux 2.6
> than they must be reliable? Or it depends on a user hardware (in this
> case we probably should disable FP exceptions in non-HiPE package,
> because in Debian we use binary packages which should work for
> anyone)?

Reliable FP exceptions require:
1. A CPU architecture that allows user-space to program the FPU
   control, or failing that a kernel that offers a system call for
   that purpose. PowerPC needs a system call, but x86/sparc do not.
2. Knowledge about the FPU in the erts source code. For instance,
   on x86 we must know about both x87 and sse2.
3. A kernel that preserves FPU control across context switches.
4. sigaction() with SA_SIGINFO and appropriate #include files so
   the signal handler can access the sigcontext/ucontext.
5. A libc that doesn't clobber the FPU control behind the user's back.

A broken /usr/include/, for instance, would prevent reliable
FP exceptions, even if the CPU and kernel would allow them.

On the currently supported CPU architectures, the FPU programming
model is pretty much the same for all CPU models. (We do detect
dynamically if an x86 is using x87, sse2, or both.) The only real
problem is that some ancient or low-end embedded CPU models
don't have FPU HW. If their kernels also lack FPU emulation, then
FP-using code won't work. However, that would break Erlang/OTP
regardless of whether FP exceptions work or not, so it's not
really an issue here.

> > Floating-point arithmetic in the base BEAM system will be slower
> > if FP exceptions don't work.
> I've found references to NO_FPE_SIGNALS macro in erl_interface. Should
> it matter if an application will use erl_interface built without using
> FP and run on erlang with FP (and vice versa)?

The usage in lib/erl_interface/src/decode/decode_big.c is bogus.
The code there is incomplete and unsafe for x86-64 and any
x86-32 environment configured to use sse2.

As far as I can tell, erl_interface will be linked with the
Erlang runtime system, and should use FP exceptions if and
only if the Erlang runtime system also uses them.


More information about the erlang-questions mailing list