From 8bdeb1672ce1d0412e1fcc6cff0821bb66f02c1a Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Thu, 17 Apr 2014 00:00:31 -0400 Subject: support setting fpu precision on m68k (closes #20904) Patch from Andreas Schwab. --- Include/pyport.h | 19 +++++++++++++++++++ Misc/NEWS | 2 ++ configure | 32 ++++++++++++++++++++++++++++++++ configure.ac | 13 +++++++++++++ pyconfig.h.in | 3 +++ 5 files changed, 69 insertions(+) diff --git a/Include/pyport.h b/Include/pyport.h index c706213..69deb9f 100644 --- a/Include/pyport.h +++ b/Include/pyport.h @@ -588,6 +588,25 @@ extern "C" { } while (0) #endif +#ifdef HAVE_GCC_ASM_FOR_MC68881 +#define HAVE_PY_SET_53BIT_PRECISION 1 +#define _Py_SET_53BIT_PRECISION_HEADER \ + unsigned int old_fpcr, new_fpcr +#define _Py_SET_53BIT_PRECISION_START \ + do { \ + __asm__ ("fmove.l %%fpcr,%0" : "=g" (old_fpcr)); \ + /* Set double precision / round to nearest. */ \ + new_fpcr = (old_fpcr & ~0xf0) | 0x80; \ + if (new_fpcr != old_fpcr) \ + __asm__ volatile ("fmove.l %0,%%fpcr" : : "g" (new_fpcr)); \ + } while (0) +#define _Py_SET_53BIT_PRECISION_END \ + do { \ + if (new_fpcr != old_fpcr) \ + __asm__ volatile ("fmove.l %0,%%fpcr" : : "g" (old_fpcr)); \ + } while (0) +#endif + /* default definitions are empty */ #ifndef HAVE_PY_SET_53BIT_PRECISION #define _Py_SET_53BIT_PRECISION_HEADER diff --git a/Misc/NEWS b/Misc/NEWS index 4bef299..5c6a5be 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,8 @@ Release date: TBA Core and Builtins ----------------- +- Issue #20904: Support setting FPU precision on m68k. + - Issue #21209: Fix sending tuples to custom generator objects with the yield from syntax. diff --git a/configure b/configure index 7b0c6a9..31a3c67 100755 --- a/configure +++ b/configure @@ -13244,6 +13244,38 @@ $as_echo "#define HAVE_GCC_ASM_FOR_X87 1" >>confdefs.h fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we can use gcc inline assembler to get and set mc68881 fpcr" >&5 +$as_echo_n "checking whether we can use gcc inline assembler to get and set mc68881 fpcr... " >&6; } +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + unsigned int fpcr; + __asm__ __volatile__ ("fmove.l %%fpcr,%0" : "=g" (fpcr)); + __asm__ __volatile__ ("fmove.l %0,%%fpcr" : : "g" (fpcr)); + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + have_gcc_asm_for_mc68881=yes +else + have_gcc_asm_for_mc68881=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $have_gcc_asm_for_mc68881" >&5 +$as_echo "$have_gcc_asm_for_mc68881" >&6; } +if test "$have_gcc_asm_for_mc68881" = yes +then + +$as_echo "#define HAVE_GCC_ASM_FOR_MC68881 1" >>confdefs.h + +fi + # Detect whether system arithmetic is subject to x87-style double # rounding issues. The result of this test has little meaning on non # IEEE 754 platforms. On IEEE 754, test should return 1 if rounding diff --git a/configure.ac b/configure.ac index 457819b..f2e4b1c 100644 --- a/configure.ac +++ b/configure.ac @@ -3810,6 +3810,19 @@ then [Define if we can use gcc inline assembler to get and set x87 control word]) fi +AC_MSG_CHECKING(whether we can use gcc inline assembler to get and set mc68881 fpcr) +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[ + unsigned int fpcr; + __asm__ __volatile__ ("fmove.l %%fpcr,%0" : "=g" (fpcr)); + __asm__ __volatile__ ("fmove.l %0,%%fpcr" : : "g" (fpcr)); +]])],[have_gcc_asm_for_mc68881=yes],[have_gcc_asm_for_mc68881=no]) +AC_MSG_RESULT($have_gcc_asm_for_mc68881) +if test "$have_gcc_asm_for_mc68881" = yes +then + AC_DEFINE(HAVE_GCC_ASM_FOR_MC68881, 1, + [Define if we can use gcc inline assembler to get and set mc68881 fpcr]) +fi + # Detect whether system arithmetic is subject to x87-style double # rounding issues. The result of this test has little meaning on non # IEEE 754 platforms. On IEEE 754, test should return 1 if rounding diff --git a/pyconfig.h.in b/pyconfig.h.in index 3574f67..e469f6a 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -313,6 +313,9 @@ /* Define to 1 if you have the `gamma' function. */ #undef HAVE_GAMMA +/* Define if we can use gcc inline assembler to get and set mc68881 fpcr */ +#undef HAVE_GCC_ASM_FOR_MC68881 + /* Define if we can use x64 gcc inline assembler */ #undef HAVE_GCC_ASM_FOR_X64 -- cgit v0.12