[erlang-patches] Detect reliable floating point exceptions on OS X Tiger

Trannie Carter tranniec@REDACTED
Fri Jan 16 18:20:58 CET 2009


Hi,

This patch modifies the reliable floating point exception test in the
erts configure.in script to correctly test FPEs on Mac OS X Tiger.  It
moves the "modern (leopard) mcontext" test above the FPE test and then
uses the DARWIN_MODERN_MCONTEXT define to choose which mcontext
structure to use in the test.

Without this patch, I can't enable HiPE on Intel/Tiger.  

I don't have an appropriate machine to test on, but I think that
PPC/Tiger has had HiPE working only because the FPE test still uses the
pre-Leopard mcontext in the __ppc__ section and I would guess that HiPE
will be disabled on PPC/Leopard.  I haven't modified that part of the
test because I don't have Leopard include files.  Maybe someone can take
a look?

I'm happy to alter the patch to make it acceptable for inclusion.

I've tested it on Intel/Tiger and PPC/Tiger and the system builds
successfully and HiPE nicely accellerates the Ackermann function. I
don't think I've broken anything :)

thanks,

trannie
-------------- next part --------------
--- otp_src_R12B-5/erts/configure.in	2008-11-04 05:51:24.000000000 -0500
+++ otp_src_R12B-5.tiger-mcontext/erts/configure.in	2009-01-16 09:50:18.000000000 -0500
@@ -1862,6 +1862,44 @@
       ;;
   esac
 fi
+
+case $ARCH-$OPSYS in
+	amd64-darwin*|x86-darwin*)
+		AC_MSG_CHECKING([For modern (leopard) style mcontext_t])
+		AC_TRY_COMPILE([
+				#include <stdlib.h>
+				#include <sys/types.h>
+				#include <unistd.h>
+				#include <mach/mach.h>
+				#include <pthread.h>
+				#include <machine/signal.h>
+				#include <ucontext.h>
+				],[
+				#if defined(__APPLE__) && defined(__MACH__) && !defined(__DARWIN__)
+				#define __DARWIN__ 1
+				#endif
+
+				#ifndef __DARWIN__
+				#error inpossible
+				#else
+
+    				mcontext_t mc = NULL;
+    				int x = mc->__fs.__fpu_mxcsr;
+
+				#endif
+				],darwin_mcontext_leopard=yes,
+				darwin_mcontext_leopard=no)
+				if test X"$darwin_mcontext_leopard" = X"yes"; then
+				   AC_DEFINE(DARWIN_MODERN_MCONTEXT,[],[Modern style mcontext_t in MacOSX])
+				   AC_MSG_RESULT(yes)
+				else
+				   AC_MSG_RESULT(no)
+				fi		
+		;;
+	*)	
+		darwin_mcontext_leopard=no
+		;;
+esac
 if test X${enable_fp_exceptions} = Xauto ; then
    if test X${enable_hipe} = Xyes; then
       enable_fp_exceptions=yes
@@ -2239,6 +2277,7 @@
     regs[PT_FPSCR] = 0x80|0x40|0x10;	/* VE, OE, ZE; not UE or XE */
 #endif
 #elif defined(__DARWIN__)
+#if defined(DARWIN_MODERN_MCONTEXT)
 #if defined(__x86_64__)
      mcontext_t mc = uc->uc_mcontext;
     struct __darwin_x86_float_state64 *fpstate = &mc->__fs;
@@ -2254,6 +2293,23 @@
     mc->ss.srr0 += 4;
     mc->fs.fpscr = 0x80|0x40|0x10;
 #endif
+#else
+#if defined(__x86_64__)
+    mcontext_t mc = uc->uc_mcontext;
+    struct x86_float_state64_t *fpstate = &mc->fs;
+    fpstate->fpu_mxcsr = 0x1F80;
+    *(unsigned short *)&fpstate->fpu_fsw &= ~0xFF;
+#elif defined(__i386__)
+    mcontext_t mc = uc->uc_mcontext;
+    x86_float_state32_t	*fpstate = &mc->fs;
+    fpstate->fpu_mxcsr = 0x1F80;
+    *(unsigned short *)&fpstate->fpu_fsw &= ~0xFF;
+#elif defined(__ppc__)
+    mcontext_t mc = uc->uc_mcontext;
+    mc->ss.srr0 += 4;
+    mc->fs.fpscr = 0x80|0x40|0x10;
+#endif
+#endif
 #elif defined(__FreeBSD__) && defined(__x86_64__)
     mcontext_t *mc = &uc->uc_mcontext;
     struct savefpu *savefpu = (struct savefpu*)&mc->mc_fpstate;
@@ -2360,43 +2416,6 @@
     fi
 fi	
 
-case $ARCH-$OPSYS in
-	amd64-darwin*|x86-darwin*)
-		AC_MSG_CHECKING([For modern (leopard) style mcontext_t])
-		AC_TRY_COMPILE([
-				#include <stdlib.h>
-				#include <sys/types.h>
-				#include <unistd.h>
-				#include <mach/mach.h>
-				#include <pthread.h>
-				#include <machine/signal.h>
-				#include <ucontext.h>
-				],[
-				#if defined(__APPLE__) && defined(__MACH__) && !defined(__DARWIN__)
-				#define __DARWIN__ 1
-				#endif
-
-				#ifndef __DARWIN__
-				#error inpossible
-				#else
-
-    				mcontext_t mc = NULL;
-    				int x = mc->__fs.__fpu_mxcsr;
-
-				#endif
-				],darwin_mcontext_leopard=yes,
-				darwin_mcontext_leopard=no)
-				if test X"$darwin_mcontext_leopard" = X"yes"; then
-				   AC_DEFINE(DARWIN_MODERN_MCONTEXT,[],[Modern style mcontext_t in MacOSX])
-				   AC_MSG_RESULT(yes)
-				else
-				   AC_MSG_RESULT(no)
-				fi		
-		;;
-	*)	
-		darwin_mcontext_leopard=no
-		;;
-esac
 	
 	 
 		


More information about the erlang-patches mailing list