Ticket #11920: sympow-1.018.1.p9-p10.diff

File sympow-1.018.1.p9-p10.diff, 32.9 KB (added by jdemeyer, 9 years ago)

Diff for the new Sympow spkg, for review only

  • SPKG.txt

    diff --git a/SPKG.txt b/SPKG.txt
    a b  
    1818  Previous (possibly still usable) email is watkins@maths.usyd.edu.au
    1919
    2020== Dependencies ==
    21  * None
     21 * GNU patch
    2222
    2323== Special Update/Build Instructions ==
    2424 * Some of the code is very dubious, and it is anyones guess really what
     
    3535   opened to implement Watkins-Delaunay's algorithm for computing modular
    3636   degrees in Sage. Once implemented, it should be possible to remove this
    3737   package.
    38  * The package is configured such that the data file written are in a directory
     38 * The package is configured such that the data files are in a directory
    3939   below where 'sympow' is installed. If Sage is installed globally, then
    4040   it will be impossible to create the data files without being root.
    4141   This has been fixed in the Gentoo Linux distribution. Some information
    4242   from Christopher can be see on http://trac.sagemath.org/sage_trac/ticket/9703
    43    but at the time of writing, this package has not been modified.
    44  * Experimenting with some of these compiler options to gcc might bring
    45    benefits in some cases. -mfpmath=sse, -mpc32, -mpc64, -mpc80.
     43   This package will generate binary versions of all shipped datafiles,
     44   so these will work. However, creating totally new datafiles from scratch
     45   will not work.
    4646
    4747== Changelog ==
    4848
     49=== sympow-1.018.1.p10 (Jeroen Demeyer, 19 Oct 2011) ===
     50 * #11920: Remove -fno-expensive-optimizations workaround, instead try
     51   various flags which might force 53-bit precision doubles.
     52 * Find out the actual FPU precision with config/fpubits1.c and
     53   config/fpubits2.c.
     54 * Move all x86 extended precision FPU-control word stuff from
     55   src/Configure to spkg-install
     56 * Generate binary datafiles when installing sympow. This ensures that
     57   all users (not only the one which installed Sage) can use the standard
     58   datafiles.
     59 * execlp.patch: Use execlp() instead of execl() to execute "sh".  This
     60   is needed for the -new_data option to work (which surely could never
     61   have worked before).
     62 * Use `patch` instead of `cp` for patching.
     63 * Remove dist/debian directory.
     64
    4965=== sympow-1.018.1.p9 (Jeroen Demeyer, 2 May 2011) ===
    5066 * #11226: Add flag -fno-expensive-optimizations when compiling with
    5167   gcc 4.6.x on a ia64 system.  See also gcc bugzilla:
  • new file config/fpubits1.c

    diff --git a/config/fpubits1.c b/config/fpubits1.c
    new file mode 100644
    - +  
     1/*
     2 * Copyright Jeroen Demeyer 2011
     3 *
     4 * Find out the precision of "double" floating-point numbers.
     5 * Return 0 if the precision is exactly 53,
     6 * return 1 if the precision is different from 53.
     7 */
     8
     9#include <stdio.h>
     10
     11double mul_and_add(double, double, double);
     12
     13int main(int argc, char** argv)
     14{
     15        /* Let a = 1 + x,
     16         *     b = 1 + y,
     17         * and compute
     18         * a*b - 1 = (1 + x + y + x*y) - 1
     19         *         = x + y + x*y
     20         * The last equality will hold computationally if (1 + x + y + x*y)
     21         * can be represented exactly as floating-point number.
     22         * Assuming x and y are negative powers of 2, this will work as long
     23         * as x*y >= (1/2)^(p-1) where p is the precision of the FPU in bits.
     24         */
     25
     26        int n = 0;
     27        double x = 1;
     28        double y = 1;
     29        for (;;)
     30        {
     31                /* Make sure x*y = (1/2)^n
     32                 * and that x and y are roughly equal. */
     33                n++;
     34                if (x >= y)
     35                        x /= 2;
     36                else
     37                        y /= 2;
     38
     39                double r = mul_and_add(1+x, 1+y, -1);
     40                if (r != x + y + x*y) break;
     41
     42                if (n >= 600)
     43                {
     44                        printf("The double precision of your FPU seems to be more than %i bits, bailing out.\n", n);
     45                        return 1;
     46                }
     47        }
     48
     49        printf("The double precision of your FPU is %i bits.\n", n);
     50        if (n == 53) return 0;
     51        return 1;
     52}
  • new file config/fpubits2.c

    diff --git a/config/fpubits2.c b/config/fpubits2.c
    new file mode 100644
    - +  
     1/*
     2 * Copyright Jeroen Demeyer 2011
     3 *
     4 * Compute a*b + c
     5 * If the processor has a fused multiply-and-add instruction
     6 * (as on ia64), such an instruction will normally be used here.  Since
     7 * a fused multiply-and-add only rounds after the addition, it will
     8 * cause a larger apparent precision.
     9 *
     10 * We put this function in a separate file to make sure the compiler
     11 * does not optimize away the call to this function.
     12 */
     13double mul_and_add(double a, double b, double c)
     14{
     15        return a*b + c;
     16}
  • deleted file dist/debian/binary/sympow

    diff --git a/dist/debian/binary/sympow b/dist/debian/binary/sympow
    deleted file mode 100755
    + -  
    1 #!/bin/sh
    2 cd /usr/lib/sympow
    3 ./sympow $*
  • deleted file dist/debian/changelog

    diff --git a/dist/debian/changelog b/dist/debian/changelog
    deleted file mode 100644
    + -  
    1 sympow (1.018-1) unstable; urgency=low
    2 
    3   * Initial release.
    4 
    5  -- Tim Abbott <tabbott@mit.edu>  Wed, 14 Nov 2007 20:27:50 -0500
  • deleted file dist/debian/compat

    diff --git a/dist/debian/compat b/dist/debian/compat
    deleted file mode 100644
    + -  
    1 5
  • deleted file dist/debian/control

    diff --git a/dist/debian/control b/dist/debian/control
    deleted file mode 100644
    + -  
    1 Source: sympow
    2 Section: math
    3 Priority: extra
    4 Maintainer: Tim Abbott <tabbott@mit.edu>
    5 Build-Depends: cdbs (>= 0.4.23-1.1), debhelper (>= 5), quilt, patchutils (>= 0.2.25), cdbs (>= 0.4.27-1), pari-gp
    6 Standards-Version: 3.7.2
    7 
    8 Package: sympow
    9 Architecture: any
    10 Depends: ${shlibs:Depends}, ${misc:Depends}
    11 Description: Special values of symmetric power elliptic curve L-functions
    12  SYMPOW is a package to compute special values of symmetric power
    13  elliptic curve L-functions.
    14  .
    15  Homepage: http://www.maths.bris.ac.uk/~mamjw/
    16 
  • deleted file dist/debian/control.in

    diff --git a/dist/debian/control.in b/dist/debian/control.in
    deleted file mode 100644
    + -  
    1 Source: sympow
    2 Section: math
    3 Priority: extra
    4 Maintainer: Tim Abbott <tabbott@mit.edu>
    5 Build-Depends: @cdbs@, pari-gp
    6 Standards-Version: 3.7.2
    7 
    8 Package: sympow
    9 Architecture: any
    10 Depends: ${shlibs:Depends}, ${misc:Depends}
    11 Description: Special values of symmetric power elliptic curve L-functions
    12  SYMPOW is a package to compute special values of symmetric power
    13  elliptic curve L-functions.
    14  .
    15  Homepage: http://www.maths.bris.ac.uk/~mamjw/
    16 
  • deleted file dist/debian/copyright

    diff --git a/dist/debian/copyright b/dist/debian/copyright
    deleted file mode 100644
    + -  
    1 This package was debianized by Tim Abbott <tabbott@mit.edu> in 2008.
    2 
    3 It was downloaded from http://www.maths.bris.ac.uk/~mamjw/
    4 
    5 Upstream Author: Mark Watkins <watkins@maths.usyd.edu.au>
    6 
    7 Copyright: (C) 2005-2006 Mark Watkins
    8 
    9 License:
    10 
    11 Copyright (c) 2005-6,
    12  Mark Watkins, Institut Henri Poincare, University of Bristol.
    13 All rights reserved.
    14 
    15 Redistribution and use in source and binary forms, with or without
    16 modification, are permitted provided that the following conditions are met:
    17   * Redistribution of source code must retain the above copyright notice,
    18  this list of conditions and the following disclaimer.
    19   * Redistribution in binary form must reproduce the above copyright
    20  notice, this list of conditions and the following disclaimer in the
    21  documentation and/or other materials provided with the distribution.
    22   * If redistribution is done as a part of a compilation that has a more
    23  restrictive license (such as the GPL), then the fact that SYMPOW has
    24  a less restrictive license must be made clear to the recipient.
    25  For example, a line like (include bracketed text if SYMPOW is modified):
    26   "This compilation includes [a modification of] SYMPOW whose [original]
    27    code has a less-restrictive license than the entire compilation."
    28  should appear in a suitable place in the COPYING and/or LICENSE file.
    29 
    30 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    31 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    32 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    33 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    34 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    35 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    36 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    37 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    38 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    39 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    40 POSSIBILITY OF SUCH DAMAGE.
    41 
    42 The Debian packaging is (C) 2008, Tim Abbott <tabbott@mit.edu> and is
    43 licensed under the GPL, see `/usr/share/common-licenses/GPL'.
  • deleted file dist/debian/rules

    diff --git a/dist/debian/rules b/dist/debian/rules
    deleted file mode 100755
    + -  
    1 #!/usr/bin/make -f
    2 
    3 include /usr/share/cdbs/1/rules/debhelper.mk
    4 include /usr/share/cdbs/1/class/makefile.mk
    5 include /usr/share/cdbs/1/rules/patchsys-quilt.mk
    6 
    7 DEB_MAKE_INVOKE +=
    8 
    9 debian/stamp-makefile-build: Makefile
    10 
    11 Makefile:
    12         ./Configure
    13 
    14 clean::
    15         rm -f Makefile
  • deleted file dist/debian/sympow.install

    diff --git a/dist/debian/sympow.install b/dist/debian/sympow.install
    deleted file mode 100644
    + -  
    1 *.gp usr/lib/sympow/
    2 datafiles usr/lib/sympow/
    3 new_data usr/lib/sympow/datafiles
    4 sympow usr/lib/sympow/
    5 debian/binary/sympow usr/bin/
  • deleted file patches/Configure

    diff --git a/patches/Configure b/patches/Configure
    deleted file mode 100755
    + -  
    1 #! /bin/sh
    2 # Despite making some small changes to this rather strange shell script
    3 # I did not write 99% of it. David Kirkby, 21st August 2010.
    4 
    5 if [ "$1" != "" ]; then
    6   echo "**ERROR**: Configure does not take any options for SYMPOW"; exit 1;
    7 fi
    8 
    9 whichexe() {
    10 #    if [ -f /bin/$1 ]; then
    11 #        echo /bin/$1
    12 #        return;
    13 #    fi;
    14 #    if [ -f /usr/bin/$1 ]; then
    15 #        echo /usr/bin/$1
    16 #        return;
    17 #    fi;
    18 #    if [ -f /usr/local/bin/$1 ]; then
    19 #        echo /usr/local/bin/$1
    20 #        return;
    21 #    fi;
    22 #    echo `which $1`
    23     echo $1
    24 }
    25 
    26 FILE="Makefile.new"
    27 CONFIG="config.h"
    28 RM=`whichexe rm`
    29 if [ -z "$RM" ]; then
    30   echo "**ERROR**: Could not find rm"; exit 1;
    31 else
    32   echo "RM = $RM"
    33 fi
    34 $RM -f $FILE
    35 $RM -f $CONFIG
    36 VERSION=1.018
    37 echo "#define VERSION \"$VERSION\"" >> $CONFIG
    38 echo "VERSION = $VERSION" >> $FILE
    39 echo "#define RM \"$RM\"" >> $CONFIG
    40 
    41 GREP=`whichexe grep` && echo "#define GREP \"$GREP\"" >> $CONFIG
    42 if [ -z "$GREP" ]; then
    43   echo "*WARNING*: Could not find grep --- will not be able to build new_data";
    44   echo "#define GREP grep" >> $CONFIG
    45 else
    46   echo "GREP = $GREP"
    47 fi
    48 
    49 GP=`whichexe gp` && echo "#define GP \"$GP\"" >> $CONFIG
    50 if [ -z "$GP" ]; then
    51   echo "*WARNING*: Could not find gp --- will not be able to build new_data";
    52   echo "#define GP gp" >> $CONFIG
    53 else
    54   echo "GP = $GP"
    55 fi
    56 
    57 
    58 SED=`whichexe sed` && echo "#define SED \"$SED\"" >> $CONFIG
    59 if [ -z "$SED" ]; then
    60   echo "*WARNING*: Could not find sed --- will not be able to build new_data";
    61   echo "#define SED sed" >> $CONFIG
    62 else
    63   echo "SED = $SED"
    64 fi
    65 
    66 [ -n "$GREP" ] && [ -n "$GP" ] && [ -n "$SED" ]\
    67  && echo "#define NEW_DATA" >> $CONFIG
    68 
    69 SH=`whichexe sh` && echo "#define SH \"$SH\"" >> $CONFIG
    70 if [ -z "$SH" ]; then
    71   echo "**ERROR**: Could not find sh"; exit 1;
    72 else
    73   echo "SH = $SH"
    74 fi
    75 
    76 UNAME=`whichexe uname`
    77 if [ -z "$UNAME" ];then
    78   echo "**ERROR**: Could not find uname"; exit 1;
    79 else
    80   echo "UNAME = $UNAME"
    81 fi
    82 
    83 echo "CC=$CC" >> $FILE
    84 
    85 # We need to set the prcision of the FPU to double precision
    86 # (53 bit mantissa, 64-bits total) and not the default
    87 # extended precision (64-bits mantissa, 80 bits total).
    88 # on Intel and AMD CPUs based on the x86 architecture.
    89  
    90 # It appears that on OS X, this is not necessary, since
    91 # the default is to use the faster but less accurate SSE
    92 # instructions. But it is necessary to do this on Linux,
    93 # Cygwin, Solaris and probably other systems which use
    94 # x86 type processors.
    95 
    96 for machine_hardware in ix86 i386 i486 i586 i686 x86_64 i86pc ia64
    97 do
    98   if [ "x`uname -m`" = "x$machine_hardware" ] && [ "x`uname`" != xDarwin ] ; then
    99      echo "You appear to have a x86 based system. The Quad Double"
    100      echo "program used by SYMPOW assumes IEEE-754 double precision numbers"
    101      echo "with 53-bits in in the mantissa and 64-bits in total."
    102      echo ""
    103      echo "However, the default mode of operating of the the FPU"
    104      echo "in the x86 chips (first introduced in the 8087)"
    105      echo "is to use extended precision, with 64-bits in the mantissa"
    106      echo "and 80 bits in total. This has to be disabled"
    107      echo "SYMPOW will add code to set the CPU's control word"
    108      echo "to disable this extended precision. This is critical"
    109      echo "and was the cause of several annoying Sage bugs - see"
    110      echo "http://trac.sagemath.org/sage_trac/ticket/9703 (Solaris x86)"
    111      echo "http://trac.sagemath.org/sage_trac/ticket/9734 (Solaris x86)"
    112      echo "http://trac.sagemath.org/sage_trac/ticket/9166 (Cygwin)"
    113      DEFS="-Dx86"
    114   fi
    115 done
    116 echo "DEFS = $DEFS" >> $FILE
    117 
    118 OPT="-O3" && echo "OPT = $OPT" >> $FILE
    119 
    120 echo "SRCS1 = analrank.c analytic.c compute.c compute2.c fpu.c help.c" >> $FILE
    121 echo "SRCS2 = conductors.c disk.c ec_ap.c ec_ap_bsgs.c ec_ap_large.c" >> $FILE
    122 echo "SRCS3 = eulerfactors.c factor.c generate.c init_curve.c main.c" >> $FILE
    123 echo "SRCS4 = moddeg.c periods.c prepare.c QD.c rootno.c util.c" >> $FILE
    124 echo "SRCS = \$(SRCS1) \$(SRCS2) \$(SRCS3) \$(SRCS4)" >> $FILE
    125 echo "OBJS = \$(SRCS:.c=.o)" >> $FILE
    126 echo "OTHERS = new_data *.gp COPYING README Configure"  >> $FILE
    127 echo "HEADERS = sympow.h" >> $FILE
    128 echo "SRC = \$(SRCS) \$(HEADERS) \$(OTHERS)" >> $FILE
    129 echo "TILDES = *~ datafiles/*~" >> $FILE
    130 df="datafiles"
    131 echo "DATAFILES = $df/*M.txt $df/*S.txt $df/param_data" >> $FILE
    132 
    133 echo "RM = $RM" >> $FILE
    134 CP=`whichexe cp` && echo "CP = $CP" >> $FILE
    135 if [ -z "$CP" ]; then
    136 echo "**ERROR**: Could not find cp"; exit 1;
    137 else
    138    echo "CP = $CP"
    139 fi
    140 MKDIR=`whichexe mkdir` && echo "MKDIR = $MKDIR" >> $FILE
    141 if [ -z "$MKDIR" ]; then
    142   echo "**ERROR**: Could not find mkdir"; exit 1;
    143 else
    144   echo "MKDIR = $MKDIR"
    145 fi
    146 TOUCH=`whichexe touch` && echo "TOUCH = $TOUCH" >> $FILE
    147 if [ -z "$TOUCH" ]; then
    148   echo "**ERROR**: Could not find touch"; exit 1;
    149 else
    150   echo "TOUCH = $TOUCH"
    151 fi
    152 TAR=`whichexe tar` && echo "TAR = $TAR" >> $FILE
    153 if [ -z "$TAR" ]; then
    154   echo "*WARNING*: Could not find tar --- source/archive omitted from Makefile";
    155 else
    156   echo "TAR = $TAR"
    157   echo "TARS = sympow.tar sympow.src.tar" >> $FILE
    158   echo "WDIR = SYMPOW-\$(VERSION)" >> $FILE && echo "" >> $FILE
    159 fi
    160 
    161 echo "all: sympow" >> $FILE
    162 echo "sympow: \$(OBJS)" >> $FILE
    163 echo "  \$(MKDIR) -p datafiles" >> $FILE
    164 echo "  \$(TOUCH) datafiles/param_data" >> $FILE
    165 LINE="\$(CC) \$(OPT) \$(CFLAGS) -o \$@ \$(DEFS) \$(OBJS) \$(LIBS)"
    166 echo "  $LINE" >> $FILE
    167 echo "%.o : %.c \$(HEADERS) Makefile" >> $FILE
    168 echo "  \$(CC) \$(OPT) \$(CFLAGS) \$(DEFS) -c -o \$@ \$<" >> $FILE
    169 echo "clean:" >> $FILE
    170 echo "  \$(RM) -f \$(OBJS) sympow \$(TILDES) \$(TARS)" >> $FILE
    171 
    172 if [ -n "$TAR" ]; then
    173   echo "source:" >> $FILE
    174   echo "        \$(MKDIR) \$(WDIR)" >> $FILE
    175   echo "        \$(CP) \$(SRC) \$(WDIR)" >> $FILE
    176   echo "        \$(TAR) cf sympow.src.tar \$(WDIR)/*" >> $FILE
    177   echo "        \$(RM) -rf \$(WDIR)" >> $FILE
    178   echo "archive:" >> $FILE
    179   echo "        \$(MKDIR) \$(WDIR)" >> $FILE
    180   echo "        \$(CP) \$(SRC) \$(WDIR)" >> $FILE
    181   echo "        \$(MKDIR) \$(WDIR)/datafiles" >> $FILE
    182   echo "        \$(CP) \$(DATAFILES) \$(WDIR)/datafiles" >> $FILE
    183   echo "        \$(TAR) cf sympow.tar \$(WDIR)/*" >> $FILE
    184   echo "        \$(RM) -rf \$(WDIR)" >> $FILE
    185 fi
    186 
    187 $RM -f Makefile
    188 $CP Makefile.new Makefile
    189 $RM -f Makefile.new
    190 
    191 echo "Makefile has been re-made. Use make if you wish to build SYMPOW"
    192 echo ""
    193 echo "**ATTENTION** If you wish build SYMPOW, please ensure beforehand"
    194 echo "that the various licenses of your C compiler, linker, assembler, etc."
    195 echo "allow you to create a derived work based on SYMPOW and your C libraries"
  • deleted file patches/Configure.diff

    diff --git a/patches/Configure.diff b/patches/Configure.diff
    deleted file mode 100644
    + -  
    1 --- src/Configure       2007-08-21 05:57:01.000000000 +0100
    2 +++ patches/Configure   2010-08-22 00:33:18.001198818 +0100
    3 @@ -1,23 +1,26 @@
    4  #! /bin/sh
    5 +# Despite making some small changes to this rather strange shell script
    6 +# I did not write 99% of it. David Kirkby, 21st August 2010.
    7  
    8  if [ "$1" != "" ]; then
    9    echo "**ERROR**: Configure does not take any options for SYMPOW"; exit 1;
    10  fi
    11  
    12  whichexe() {
    13 -    if [ -f /bin/$1 ]; then
    14 -        echo /bin/$1
    15 -        return;
    16 -    fi;
    17 -    if [ -f /usr/bin/$1 ]; then
    18 -        echo /usr/bin/$1
    19 -        return;
    20 -    fi;
    21 -    if [ -f /usr/local/bin/$1 ]; then
    22 -        echo /usr/local/bin/$1
    23 -        return;
    24 -    fi;
    25 -    echo `which $1`
    26 +#    if [ -f /bin/$1 ]; then
    27 +#        echo /bin/$1
    28 +#        return;
    29 +#    fi;
    30 +#    if [ -f /usr/bin/$1 ]; then
    31 +#        echo /usr/bin/$1
    32 +#        return;
    33 +#    fi;
    34 +#    if [ -f /usr/local/bin/$1 ]; then
    35 +#        echo /usr/local/bin/$1
    36 +#        return;
    37 +#    fi;
    38 +#    echo `which $1`
    39 +    echo $1
    40  }
    41  
    42  FILE="Makefile.new"
    43 @@ -70,13 +73,6 @@
    44    echo "SH = $SH"
    45  fi
    46  
    47 -CC=`whichexe cc` && echo "CC = $CC" >> $FILE
    48 -if [ -z "$CC" ]; then
    49 -  echo "**ERROR**: Could not find cc"; exit 1;
    50 -else
    51 -  echo "CC = $CC"
    52 -fi
    53 -
    54  UNAME=`whichexe uname`
    55  if [ -z "$UNAME" ];then
    56    echo "**ERROR**: Could not find uname"; exit 1;
    57 @@ -84,18 +80,39 @@
    58    echo "UNAME = $UNAME"
    59  fi
    60  
    61 -MACH=`"$UNAME" -m`
    62 -for x in ix86 i386 i486 i586 i686 x86_64 ia64
    63 +echo "CC=$CC" >> $FILE
    64 +
    65 +# We need to set the prcision of the FPU to double precision
    66 +# (53 bit mantissa, 64-bits total) and not the default
    67 +# extended precision (64-bits mantissa, 80 bits total).
    68 +# on Intel and AMD CPUs based on the x86 architecture.
    69 +
    70 +# It appears that on OS X, this is not necessary, since
    71 +# the default is to use the faster but less accurate SSE
    72 +# instructions. But it is necessary to do this on Linux,
    73 +# Cygwin, Solaris and probably other systems which use
    74 +# x86 type processors.
    75 +
    76 +for machine_hardware in ix86 i386 i486 i586 i686 x86_64 i86pc ia64
    77  do
    78 -  if [ "$MACH" = "$x" -a `uname` = "Linux" ]; then
    79 -     echo "You appear to have a $x based Linux system --- using fpu.c"
    80 +  if [ "x`uname -m`" = "x$machine_hardware" ] && [ "x`uname`" != xDarwin ] ; then
    81 +     echo "You appear to have a x86 based system. The Quad Double"
    82 +     echo "program used by SYMPOW assumes IEEE-754 double precision numbers"
    83 +     echo "with 53-bits in in the mantissa and 64-bits in total."
    84 +     echo ""
    85 +     echo "However, the default mode of operating of the the FPU"
    86 +     echo "in the x86 chips (first introduced in the 8087)"
    87 +     echo "is to use extended precision, with 64-bits in the mantissa"
    88 +     echo "and 80 bits in total. This has to be disabled"
    89 +     echo "SYMPOW will add code to set the CPU's control word"
    90 +     echo "to disable this extended precision. This is critical"
    91 +     echo "and was the cause of several annoying Sage bugs - see"
    92 +     echo "http://trac.sagemath.org/sage_trac/ticket/9703 (Solaris x86)"
    93 +     echo "http://trac.sagemath.org/sage_trac/ticket/9734 (Solaris x86)"
    94 +     echo "http://trac.sagemath.org/sage_trac/ticket/9166 (Cygwin)"
    95       DEFS="-Dx86"
    96    fi
    97  done
    98 -if [ -z "$DEFS" ]; then
    99 -  echo "You do not appear to have an x86 based system --- not using fpu.c"
    100 -fi
    101 -
    102  echo "DEFS = $DEFS" >> $FILE
    103  
    104  OPT="-O3" && echo "OPT = $OPT" >> $FILE
  • new file patches/Configure.patch

    diff --git a/patches/Configure.patch b/patches/Configure.patch
    new file mode 100644
    - +  
     1diff -ur src/Configure src.new/Configure
     2--- src/Configure       2007-08-21 06:57:01.000000000 +0200
     3+++ src.new/Configure   2011-10-19 22:20:50.000000000 +0200
     4@@ -1,23 +1,26 @@
     5 #! /bin/sh
     6+# Despite making some small changes to this rather strange shell script
     7+# I did not write 99% of it. David Kirkby, 21st August 2010.
     8 
     9 if [ "$1" != "" ]; then
     10   echo "**ERROR**: Configure does not take any options for SYMPOW"; exit 1;
     11 fi
     12 
     13 whichexe() {
     14-    if [ -f /bin/$1 ]; then
     15-        echo /bin/$1
     16-        return;
     17-    fi;
     18-    if [ -f /usr/bin/$1 ]; then
     19-        echo /usr/bin/$1
     20-        return;
     21-    fi;
     22-    if [ -f /usr/local/bin/$1 ]; then
     23-        echo /usr/local/bin/$1
     24-        return;
     25-    fi;
     26-    echo `which $1`
     27+#    if [ -f /bin/$1 ]; then
     28+#        echo /bin/$1
     29+#        return;
     30+#    fi;
     31+#    if [ -f /usr/bin/$1 ]; then
     32+#        echo /usr/bin/$1
     33+#        return;
     34+#    fi;
     35+#    if [ -f /usr/local/bin/$1 ]; then
     36+#        echo /usr/local/bin/$1
     37+#        return;
     38+#    fi;
     39+#    echo `which $1`
     40+    echo $1
     41 }
     42 
     43 FILE="Makefile.new"
     44@@ -70,13 +73,6 @@
     45   echo "SH = $SH"
     46 fi
     47 
     48-CC=`whichexe cc` && echo "CC = $CC" >> $FILE
     49-if [ -z "$CC" ]; then
     50-  echo "**ERROR**: Could not find cc"; exit 1;
     51-else
     52-  echo "CC = $CC"
     53-fi
     54-
     55 UNAME=`whichexe uname`
     56 if [ -z "$UNAME" ];then
     57   echo "**ERROR**: Could not find uname"; exit 1;
     58@@ -84,18 +80,11 @@
     59   echo "UNAME = $UNAME"
     60 fi
     61 
     62-MACH=`"$UNAME" -m`
     63-for x in ix86 i386 i486 i586 i686 x86_64 ia64
     64-do
     65-  if [ "$MACH" = "$x" -a `uname` = "Linux" ]; then
     66-     echo "You appear to have a $x based Linux system --- using fpu.c"
     67-     DEFS="-Dx86"
     68-  fi
     69-done
     70-if [ -z "$DEFS" ]; then
     71-  echo "You do not appear to have an x86 based system --- not using fpu.c"
     72-fi
     73+echo "CC=$CC" >> $FILE
     74 
     75+# All x86 extended precision FPU-control word stuff: moved to spkg-install
     76+# -- Jeroen Demeyer
     77+DEFS=""
     78 echo "DEFS = $DEFS" >> $FILE
     79 
     80 OPT="-O3" && echo "OPT = $OPT" >> $FILE
  • new file patches/execlp.patch

    diff --git a/patches/execlp.patch b/patches/execlp.patch
    new file mode 100644
    - +  
     1diff -ur src/generate.c src.new/generate.c
     2--- src/generate.c      2007-08-21 06:57:01.000000000 +0200
     3+++ src.new/generate.c  2011-10-17 21:55:10.000000000 +0200
     4@@ -201,4 +201,4 @@
     5  else if (c) sprintf(ARGS,"-cm -sp %i",sp);
     6  else if (sp&1) sprintf(ARGS,"-sp %i -dv %i",sp,dv);
     7  else sprintf(ARGS,"-sp %i",sp);
     8- execl(SH,SH,PATH,SH,GP,ARGS,NULL);}
     9+ execlp(SH,SH,PATH,SH,GP,ARGS,NULL);}
  • deleted file patches/fpu.c

    diff --git a/patches/fpu.c b/patches/fpu.c
    deleted file mode 100644
    + -  
    1 /* David Kirkby 21st August 2010
    2 Licenced under the GPL version 2 or at your option any later version.
    3 
    4 Set the FPU 's precion control to 53 bits (double precision) instead of the
    5 64-bits (extended precision). I've commented it fairly librarily, with
    6 the hope it's helpful if anyone needs to edit it.
    7 
    8 Note, the extended precision uses 80 bits in total,
    9 of which 64 are for the mantissa.
    10 
    11 Double precsion uses 64 bits in total, but ony 53 are
    12 for the mantissa.
    13 
    14 The precision is set by bits 8 and 9 of the Control Word in the floating
    15 point processor. The Control word has 16 bits.
    16 
    17 Data taken from The 80387 Programmer's reference Manual, Intel
    18 1987.
    19 
    20 00 = 24-bits (single precision)
    21 01 = reserved (or at least it was at the time the 387 was released)
    22 10 = 53-bits (double precision)
    23 11 = 64-bits (extended precision).
    24 
    25 FLDCW is an x86 instruction to "Load the Control Word"
    26 FNSTCW is an x88 instruction to "Store FPU Control Word"
    27 It does so without checking for pending unmasked floating-point
    28 exceptions. (A similar FSTCW checks for them first).
    29 */
    30 
    31 #ifdef x86
    32    #define _SET_FPU_CONTROL_WORD(x) asm volatile ("fldcw %0": :"m" (x));
    33    #define _READ_FPU_CONTROL_WORD(x) asm volatile ("fnstcw %0":"=m" (x));
    34 
    35    void fpu_53bits()
    36    {
    37       /* The control word is 16 bits, numbered 0 to 15 */
    38       volatile unsigned short control_word;
    39 
    40      _READ_FPU_CONTROL_WORD(control_word); /* Read the FPU control word */
    41      control_word=control_word & 0xfeff; /* Set bit 8 = 0 */
    42      control_word=control_word | 0x200; /* Set bit 9 = 1 */
    43      _SET_FPU_CONTROL_WORD(control_word); /* Force double-precision, 53-bit mantissa */
    44    }
    45 
    46 #endif
  • new file patches/fpu.patch

    diff --git a/patches/fpu.patch b/patches/fpu.patch
    new file mode 100644
    - +  
     1diff -u -r src/fpu.c src.new/fpu.c
     2--- src/fpu.c   2007-08-21 06:57:01.000000000 +0200
     3+++ src.new/fpu.c       2011-10-19 22:50:37.000000000 +0200
     4@@ -1,8 +1,46 @@
     5+/* David Kirkby 21st August 2010
     6+Licenced under the GPL version 2 or at your option any later version.
     7+
     8+Set the FPU's precision control to 53 bits (double precision) instead of
     9+the default 64-bits (extended precision). I've commented it fairly
     10+liberally, with the hope it's helpful if anyone needs to edit it.
     11+
     12+Note, the extended precision uses 80 bits in total,
     13+of which 64 are for the mantissa.
     14+
     15+Double precsion uses 64 bits in total, but ony 53 are
     16+for the mantissa.
     17+
     18+The precision is set by bits 8 and 9 of the Control Word in the floating
     19+point processor. The Control word has 16 bits.
     20+
     21+Data taken from The 80387 Programmer's reference Manual, Intel,
     22+1987.
     23+
     24+00 = 24-bits (single precision)
     25+01 = reserved (or at least it was at the time the 387 was released)
     26+10 = 53-bits (double precision)
     27+11 = 64-bits (extended precision).
     28+
     29+FLDCW is an x86 instruction to "Load the Control Word"
     30+FNSTCW is an x88 instruction to "Store FPU Control Word"
     31+It does so without checking for pending unmasked floating-point
     32+exceptions. (A similar FSTCW checks for them first).
     33+*/
     34+
     35+#ifdef x86
     36+
     37+#define _SET_FPU_CONTROL_WORD(x) asm volatile ("fldcw %0": :"m" (x));
     38+#define _READ_FPU_CONTROL_WORD(x) asm volatile ("fnstcw %0":"=m" (x));
     39 
     40 void fpu_53bits()
     41 {
     42-#ifdef x86
     43-#include <fpu_control.h>
     44-fpu_control_t fpu_control=0x027f; _FPU_SETCW(fpu_control);
     45-#endif
     46+    /* The control word is 16 bits, numbered 0 to 15 */
     47+    volatile unsigned short control_word;
     48+
     49+    _READ_FPU_CONTROL_WORD(control_word); /* Read the FPU control word */
     50+    control_word=control_word & 0xfeff; /* Set bit 8 = 0 */
     51+    control_word=control_word | 0x200; /* Set bit 9 = 1 */
     52+    _SET_FPU_CONTROL_WORD(control_word); /* Force double-precision, 53-bit mantissa */
     53 }
     54+#endif
  • spkg-install

    diff --git a/spkg-install b/spkg-install
    a b  
    2121   export LDFLAGS
    2222fi
    2323
    24 # Workaround problems with gcc 4.6.0 on ia64 systems:
    25 if [ "x`uname -m`" = "xia64" ] && [ "x`$SAGE_LOCAL/bin/testcc.sh $CC`" = xGCC ] ; then
    26     if $CC -dumpversion 2>/dev/null |grep >/dev/null '^4\.6\.' ; then
    27         echo "Detected GCC version `$CC -dumpversion` on Itanium. Adding"
    28         echo "work-around to fix a bug when sympow is compiled with gcc 4.6.0"
    29         CFLAGS="$CFLAGS -fno-expensive-optimizations"
    30         export CFLAGS
     24
     25#######################################################################
     26# Apply all patches
     27#######################################################################
     28cd src
     29for patch in ../patches/*.patch; do
     30    patch -p1 <"$patch"
     31    if [ $? -ne 0 ]; then
     32        echo >&2 "Error applying '$patch'"
     33        exit 1
    3134    fi
     35done
     36
     37# Back to top level
     38cd ..
     39
     40
     41#######################################################################
     42# Check FPU precision
     43#######################################################################
     44# Try adding various flags to CFLAGS to ensure that doubles are really
     45# IEEE doubles with 53 bits of precision.
     46# In particular, we need to avoid 80 bits extended precision on x86 and
     47# we need to avoid fused multiply-and-instructions (e.g. on ia64).
     48# To check whether a flag is supported, compile and run a program
     49# compiled with that flag.
     50for FLAG in '-ffp-contract=on' '-mno-fused-madd' '-mfpmath=sse' '-mpc64'; do
     51    # We use -O3 here to really force generation of fused
     52    # multiply-and-add instructions and to keep floats as much as
     53    # possible in registers.
     54    if $CC $CFLAGS $FLAG -O3 -o config/fpubits config/fpubits1.c config/fpubits2.c 2>/dev/null; then
     55        # Compiled successfully, now run it
     56        config/fpubits >/dev/null 2>/dev/null
     57        if [ $? -le 1 ]; then
     58            # The program ran successfully.  For now, we don't need
     59            # the exit status to be zero (indicating exactly 53 bits),
     60            # we simply need the program not to crash (which would
     61            # give an exit status > 128).
     62            CFLAGS="$CFLAGS $FLAG"
     63        fi
     64    fi
     65done
     66
     67
     68# Check the actual FPU precision with our new flags.
     69# As before, we use -O3 for "worst case" behaviour.
     70$CC $CFLAGS -O3 -o config/fpubits config/fpubits1.c config/fpubits2.c
     71if [ $? -ne 0 ]; then
     72    echo "The command below failed:"
     73    echo "$CC $CFLAGS -O3 -o config/fpubits config/fpubits1.c config/fpubits2.c"
     74    exit 1
    3275fi
    3376
     77config/fpubits
     78status=$?
     79if [ $status -eq 1 ]; then
     80    echo "The Quad Double library used by SYMPOW assumes IEEE-754 double precision"
     81    echo "numbers with exactly 53 bits in the mantissa (64 bits in total)."
     82    echo ""
    3483
    35 # Add some code to disable the extended precision of Intel
    36 # x86 based floating point processors. The code in SYMPOW
    37 # already works for Linux, so there's no need to do that.
     84    # Check whether src/fpu.c (already patched!) compiles with -Dx86.
     85    # If it does, we are almost surely on a x86 system. There is no need to
     86    # run anything, we only need to see whether the asm instructions are
     87    # recognized.
     88    if $CC $CFLAGS -Dx86 -c -o config/srcfpu.o src/fpu.c >/dev/null 2>/dev/null; then
     89        echo "It looks like you are running an x86 system. The default mode of"
     90        echo "operation of the FPU in the x86 chips (first introduced in the 8087) is"
     91        echo "to use extended precision, with 64 bits in the mantissa (and 80 bits in"
     92        echo "total). We will add code to set the CPU's control word to disable this"
     93        echo "extended precision. This is critical and was the cause of several"
     94        echo "annoying Sage bugs - see"
     95        echo "http://trac.sagemath.org/sage_trac/ticket/9703 (Solaris x86)"
     96        echo "http://trac.sagemath.org/sage_trac/ticket/9734 (Solaris x86)"
     97        echo "http://trac.sagemath.org/sage_trac/ticket/9166 (Cygwin)"
     98        CFLAGS="$CFLAGS -Dx86"
     99    else
     100        echo "Unfortunately, we currently have no workaround for your system."
     101        echo "Running SYMPOW will almost certainly fail on some inputs."
     102        echo "Please report this problem to"
     103        echo "sage-devel (http://groups.google.com/group/sage-devel),"
     104        echo "mentioning in particular your operating system, processor type"
     105        echo "and compiler version (run $CC --version)."
     106        exit 1
     107    fi
     108elif [ $status -ne 0 ]; then
     109    echo "Something very bad happened while checking the precision of your FPU."
     110    echo "Please report this problem (mentioning any error messages above) to"
     111    echo "sage-devel (http://groups.google.com/group/sage-devel)."
     112    echo "Mention in particular your operating system and compiler version"
     113    echo "(run $CC --version)."
     114    exit 1
     115fi
    38116
    39 # For now this is only done on Cygwin and Solaris, as its needed
    40 # on Solaris x86. (It's ignored on SPARC, so there's no need to be specific
    41 # about it). It might potentially need to be enabled on other systems such
    42 # as FreeBSD, NetBSD, OpenBSD or anything else that uses an x86 processor.
     117export CFLAGS
    43118
    44 if [ "x$UNAME"  = xSunOS ] || [ "x$UNAME"  = xCYGWIN ] ; then
    45    cp patches/fpu.c src/
    46 fi
    47 
    48 cp patches/Configure src/   
    49 
     119#######################################################################
     120# Configure
     121#######################################################################
    50122cd src/
    51 
    52 ./Configure
    53 
     123bash ./Configure  # Force bash as shell
    54124if [ $? -ne 0 ]; then
    55125   echo "Error configuring sympow"
    56126   exit 1
    57127fi
    58128
    59 make
     129
     130#######################################################################
     131# Build
     132#######################################################################
     133$MAKE
    60134
    61135if [ $? -ne 0 ]; then
    62136   echo "Error building sympow"
     
    68142   exit 1
    69143fi
    70144
     145#######################################################################
     146# Install
     147#######################################################################
    71148TARGET="$SAGE_LOCAL/lib/sympow"
    72149
    73150if [ -d "$TARGET" ]; then
     
    75152fi
    76153mkdir "$TARGET"
    77154
    78 mv datafiles "$TARGET/"
    79 
    80 if [ ! -d "$TARGET/datafiles" ]; then
    81    echo "Error installing sympow datafiles."
    82    exit 1
    83 fi
    84 
    85155cp sympow *.gp new_data "$TARGET/"
    86156
    87157if [ ! -f "$TARGET/sympow" ]; then
     
    89159   exit 1
    90160fi
    91161
     162# Copy datafiles
     163mv datafiles "$TARGET/"
     164if [ ! -d "$TARGET/datafiles" ]; then
     165   echo "Error installing sympow datafiles."
     166   exit 1
     167fi
     168
     169# Create binary versions of datafiles
     170cd "$TARGET/datafiles"
     171for file in *.txt; do
     172    NUM=`grep -c AT $file`
     173    ../sympow -txt2bin "$NUM" <$file ${file/%txt/bin}
     174    if [ $? -ne 0 ]; then
     175        echo "Running sympow failed"
     176        exit 1
     177    fi
     178done
     179
     180# Create sympow script in $SAGE_ROOT/local/bin
    92181SCRIPT="$SAGE_LOCAL/bin/sympow"
    93182
    94 echo "#!/bin/sh" > $SCRIPT
    95 echo "cd \$SAGE_LOCAL/lib/sympow" >> $SCRIPT
    96 echo "./sympow \$*" >> $SCRIPT
     183cat >$SCRIPT <<'EOF'
     184#!/usr/bin/env bash
     185
     186cd "$SAGE_LOCAL/lib/sympow"
     187exec ./sympow "$@"
     188EOF
     189
    97190chmod +x $SCRIPT
    98191
    99192exit 0