Patch for Quad.cc compile error on Sun/GCC
Carsten Clark
tantumquantum+gnuoctave at gmail.com
Tue May 5 01:34:52 CDT 2009
2009/5/4 John W. Eaton <jwe at octave.org>:
>
> I checked in the change, but what about
>
> quad (@(x) x, single (0), single (2))
>
> ? Are you using the Sun Fortran compiler? My guess is that it will
> work, and that GCC and the Sun Fortran compiler will handle floats in
> a compatible way, unlike for doubles.
I was using g77 from GCC 4. This works:
$ octave -qf
octave:1> quad ( @(x) x, 0, 2 )
ans = 2
octave:2> quad ( @(x) x, single(0), single(2) )
ans = 2.0000
I rebuilt using g++4 and this Sun Studio Fortran compiler:
$ /opt/SunStudioExpress/bin/f77 -V
NOTICE: Invoking /opt/SunStudioExpress/bin/f90 -f77 -ftrap=%none -V
f90: Sun Ceres Fortran 95 8.3 SunOS_i386 2008/10/22
and that works, too (your guess is right!):
octave:1> quad ( @(x) x, 0, 2 )
ans = 2
octave:2> quad ( @(x) x, single(0), single(2) )
ans = 2
Actually, the GCC manual
(http://gcc.gnu.org/onlinedocs/gcc-4.3.3/gcc/Interoperation.html)
states that the compatibility problem that access_double() solves only
occurs on SPARC systems. I'm on an Intel PC. Changing the #ifdefs in
Quad.cc and sun-utils.h to __sparc, as in the attached patch, I can
still run the above test code successfully, with both g77 and Sun
Studio f77. (I verified that __sparc is not defined for me and the
access_double() lines are not compiled.)
I've checked a SPARC system at work, and it does define __sparc and
sparc. The Sun Studio 12 User's Guide
(http://docs.sun.com/app/docs/doc/819-5267/6n7c46edt) also lists these
symbols as defined on SPARC only. However, I don't have GCC 4 on that
system, so probably can't try building Octave.
At any rate, access_double() and assign_double() aren't necessary on
my system, and it looks like this should be true of Solaris/Intel
systems in general, unless I'm a fluke for some reason.
Regards,
Carsten Clark
-------------- next part --------------
diff -r 7ea76c8a59f7 liboctave/ChangeLog
--- a/liboctave/ChangeLog Mon May 04 21:22:36 2009 -0400
+++ b/liboctave/ChangeLog Tue May 05 02:17:13 2009 -0400
@@ -1,3 +1,8 @@
+2009-05-05 Carsten Clark <tantumquantum+gnuoctave at gmail.com>
+
+ * Quad.cc (user_function), sun-utils.h: use access_double() and
+ assign_double() only on SPARC, not on all Sun.
+
2009-05-04 Carsten Clark <tantumquantum+gnuoctave at gmail.com>
* Quad.cc (float_user_function): Remove Sun/GCC special case.
diff -r 7ea76c8a59f7 liboctave/Quad.cc
--- a/liboctave/Quad.cc Mon May 04 21:22:36 2009 -0400
+++ b/liboctave/Quad.cc Tue May 05 02:17:13 2009 -0400
@@ -77,7 +77,7 @@
{
BEGIN_INTERRUPT_WITH_EXCEPTIONS;
-#if defined (sun) && defined (__GNUC__)
+#if defined (__sparc) && defined (__GNUC__)
double xx = access_double (x);
#else
double xx = *x;
@@ -87,7 +87,7 @@
double xresult = (*user_fcn) (xx);
-#if defined (sun) && defined (__GNUC__)
+#if defined (__sparc) && defined (__GNUC__)
assign_double (result, xresult);
#else
*result = xresult;
diff -r 7ea76c8a59f7 liboctave/sun-utils.h
--- a/liboctave/sun-utils.h Mon May 04 21:22:36 2009 -0400
+++ b/liboctave/sun-utils.h Tue May 05 02:17:13 2009 -0400
@@ -24,12 +24,12 @@
#define octave_sun_utils_h 1
// This is only needed to dereference pointers to doubles if mixing
-// GCC and Sun f77/cc compiled code. See the GCC manual (where the
+// GCC and Sun SPARC f77/cc compiled code. See the GCC manual (where the
// function access_double() is described) and the Sun f77 manual,
// which explains that doubles are not always aligned on 8 byte
// boundaries.
-#if defined (sun) && defined (__GNUC__)
+#if defined (__sparc) && defined (__GNUC__)
inline double
access_double (double *unaligned_ptr)
More information about the Bug-octave
mailing list