Re: [Patch, libgfortran] Add FPU Support for powerpc

2012-06-28 Thread Steven Bosscher
On Tue, May 22, 2012 at 3:45 AM, rbmj r...@verizon.net wrote:
 Hi everyone,

 This patch adds FPU support for powerpc on platforms that do not have glibc.
  It is basically the same code as glibc has.  The motivation for this was
 that right now there is no fpu-target.h that works for powerpc-*-vxworks.

 Again, 90% of this code comes directly from glibc.  But on vxworks targets
 there is no glibc.

 I also patched the configure.host script in order to add this in.

 Any opinions?

Since AFAICT nobody has responded...

I suppose this is something you need, or you would probably not be
working on it. I wouldn't have thought of VxWorks as an obvious target
platform for a Fortran compiler. :-)

The copying of the code from glibc (LGPL code) to libgfortran
(GPL+exception) is something that you probably need permission for
from the FSF. For the VxWorks specific bits, you could poke the only
listed VxWorks maintainer in MAINTAINERS (hi Nathan!).

For the configure.host bits,

+  powerpc)

Not powerpc64? Or at least powerpc|ppc?
IIUC this test is overridden for powerpc-linux by a glibc test
following your new code, right? What happens for e.g. powerpc-aix?
Shouldn't your test also be conditional on have_feenableexcept?

Ciao!
Steven


[Patch, libgfortran] Add FPU Support for powerpc

2012-05-21 Thread rbmj

Hi everyone,

This patch adds FPU support for powerpc on platforms that do not have 
glibc.  It is basically the same code as glibc has.  The motivation for 
this was that right now there is no fpu-target.h that works for 
powerpc-*-vxworks.


Again, 90% of this code comes directly from glibc.  But on vxworks 
targets there is no glibc.


I also patched the configure.host script in order to add this in.

Any opinions?

Robert Mason
From f9449738730fa0d460a30affa826a157bf97cf62 Mon Sep 17 00:00:00 2001
From: rbmj r...@verizon.net
Date: Mon, 21 May 2012 15:56:06 -0400
Subject: [PATCH 3/6] Add FPU Support for PPC on VxWorks

libgfortran/config/fpu-ppc.h:
	Started work on a fpu-target.h that will work for VxWorks on PPC.
	90% of it is stolen from glibc.  I just took the necessary pieces
	and added the right VxWorks glue.  I made as few changes to the
	glibc code as possible in order to avoid introducing a bug.
	The VxWorks part seems to be correct, but I don't have a whole
	lot of experience in this area and documentation is incomplete.

libgfortran/configure.host:
	This just adds fpu-ppc.h to the list of targets.  For some
	reason, my powerpc-wrs-vxworks is getting mis-identified as
	AIX, even though it does not have the functions, so I'll also
	have to work on a patch for configure.ac.  I'll check on that.
	Also, I put it before glibc so that glibc targets will get
	to use glibc and not rely on my cruft.
---
 libgfortran/config/fpu-ppc.h |  407 ++
 libgfortran/configure.host   |   11 ++
 2 files changed, 418 insertions(+), 0 deletions(-)
 create mode 100644 libgfortran/config/fpu-ppc.h

diff --git a/libgfortran/config/fpu-ppc.h b/libgfortran/config/fpu-ppc.h
new file mode 100644
index 000..f27df7f
--- /dev/null
+++ b/libgfortran/config/fpu-ppc.h
@@ -0,0 +1,407 @@
+/* FPU-related code for systems without glibc on powerpc.
+   Copyright (C) 1997, 1998, 1999, 2008 Free Software Foundation, Inc.
+
+This file is part of the GNU Fortran runtime library (libgfortran).
+This file incorporates code from the GNU C Library (glibc) under the GNU LGPL.
+
+Libgfortran is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
+License as published by the Free Software Foundation; either
+version 3 of the License, or (at your option) any later version.
+
+Libgfortran is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+http://www.gnu.org/licenses/.  */
+   
+/* FPU Types/Constants: */
+
+/* Type representing exception flags.  */
+typedef unsigned int fexcept_t;
+
+/* Type representing floating-point environment.  We leave it as 'double'
+   for efficiency reasons (rather than writing it to a 32-bit integer). */
+typedef double fenv_t;
+
+/* We want to specify the bit pattern of the __fe_*_env constants, so 
+   pretend they're really `long long' instead of `double'.  */
+
+/* If the default argument is used we use this value.  */
+const unsigned long long __fe_dfl_env __attribute__ ((aligned (8))) = 
+0xfff8ULL;
+#define FE_DFL_ENV	((double*)(__fe_dfl_env))
+
+/* Floating-point environment where all exceptions are enabled.  Note that
+   this is not sufficient to give you SIGFPE.  */
+const unsigned long long __fe_enabled_env __attribute__ ((aligned (8))) = 
+0xfff800f8ULL;
+# define FE_ENABLED_ENV	((double*)(__fe_enabled_env))
+
+/* Floating-point environment with (processor-dependent) non-IEEE floating
+   point.  */
+const unsigned long long __fe_nonieee_env __attribute__ ((aligned (8))) = 
+0xfff80004ULL;
+# define FE_NONIEEE_ENV	((double*)(__fe_nonieee_env))
+
+/* Provide __fe_mask_env and __fe_nomask_env */
+#ifdef __VXWORKS__
+
+/* These are based loosly off of glibc
+  
+   see also glibc/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/fe{,no}mask.c
+ */
+
+#include arch/ppc/vxPpcLib.h
+#include arch/ppc/archPpc.h
+
+#if !defined (_PPC_MSR_FE0) || !defined (_PPC_MSR_FE1)
+#error FPU Support does not appear to exist on target platform
+#else
+
+const fenv_t *
+__fe_nomask_env(void)
+{
+  UINT32 msr = vxMsrGet();
+  msr |= _PPC_MSR_FE0 | _PPC_MSR_FE1;
+  vxMsrSet(msr);
+  return FE_ENABLED_ENV;
+}
+
+const fenv_t *
+__fe_nomask_env(void)
+{
+  UINT32 msr = vxMsrGet();
+  msr = ~(_PPC_MSR_FE0 | _PPC_MSR_FE1);
+  vxMsrSet(msr);
+  return FE_DFL_ENV;
+}
+
+#endif
+
+#else
+
+/* VxWorks is the only OS that this header supports so far.  It would