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

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

Diff for the sympow spkg p10 -> p11, for review only

  • sympow-1.018.1.

    Only in sympow-1.018.1.p11/.hg: cache
    diff -ru sympow-1.018.1.p10/SPKG.txt sympow-1.018.1.p11/SPKG.txt
    old new  
    4646
    4747== Changelog ==
    4848
    49 === sympow-1.018.1.p10 (Jeroen Demeyer, 19 Oct 2011) ===
     49=== sympow-1.018.1.p11 (Jeroen Demeyer, 19 Jan 2012) ===
    5050 * #11920: Remove -fno-expensive-optimizations workaround, instead try
    5151   various flags which might force 53-bit precision doubles.
    5252 * Find out the actual FPU precision with config/fpubits1.c and
    5353   config/fpubits2.c.
    5454 * Move all x86 extended precision FPU-control word stuff from
    5555   src/Configure to spkg-install
    56  * Generate binary datafiles when installing sympow. This ensures that
     56 * Generate binary datafiles when installing SYMPOW. This ensures that
    5757   all users (not only the one which installed Sage) can use the standard
    5858   datafiles.
    5959 * execlp.patch: Use execlp() instead of execl() to execute "sh".  This
    6060   is needed for the -new_data option to work (which surely could never
    6161   have worked before).
    6262 * Use `patch` instead of `cp` for patching.
     63 * Lots of small fixes in spkg-install.
    6364 * Remove dist/debian directory.
    6465
    6566=== sympow-1.018.1.p9 (Jeroen Demeyer, 2 May 2011) ===
  • config/fpubits1.c

    diff -ru sympow-1.018.1.p10/config/fpubits1.c sympow-1.018.1.p11/config/fpubits1.c
    old new  
    88
    99#include <stdio.h>
    1010
    11 double mul_and_add(double, double, double);
     11double mul_and_add(double, double, double);  /* config/fpubits2.c */
     12void fpu_53bits();  /* src/fpu.c */
    1213
    1314int main(int argc, char** argv)
    1415{
     16        /* If x86 is defined, set the FPU to 53 bits */
     17#ifdef x86
     18        fpu_53bits();
     19#endif
     20
    1521        /* Let a = 1 + x,
    1622         *     b = 1 + y,
    1723         * and compute
  • sympow-1.018.1.

    diff -ru sympow-1.018.1.p10/spkg-install sympow-1.018.1.p11/spkg-install
    old new  
    11#!/usr/bin/env bash
    22
    33if [ "$SAGE_LOCAL" = "" ]; then
    4    echo "SAGE_LOCAL undefined ... exiting";
    5    echo "Maybe run 'sage -sh'?"
     4   echo >&2 "SAGE_LOCAL undefined ... exiting"
     5   echo >&2 "Maybe run 'sage -sh'?"
    66   exit 1
    77fi
    88
     
    1414
    1515# If SAGE64 is "yes", build 64-bit.
    1616if [ "x$SAGE64" = xyes ] ; then
    17    echo "Building Sympow 64-bit"             
     17   echo "Building SYMPOW 64-bit"
    1818   CFLAGS="$CFLAGS $CFLAG64"
    1919   LDFLAGS="$LDFLAGS $CFLAG64"
    2020   export CFLAGS
     
    3939
    4040
    4141#######################################################################
    42 # Check FPU precision
     42# Fix FPU precision
    4343#######################################################################
    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.
    50 for FLAG in '-ffp-contract=on' '-mno-fused-madd' '-mfpmath=sse' '-mpc64'; do
     44# SYMPOW really needs doubles to have *exactly* 53 bits precision,
     45# they need to be true IEEE-754 double precision numbers.
     46# In particular, we need to avoid 80 bits extended precision on i386
     47# and we need to avoid fused multiply-add instructions (e.g. on ia64).
     48# We might need to add various flags to CFLAGS to ensure this.
     49# See Trac tickets #9703, #9734, #9166, #11226, #11920.
     50
     51# Usage: try_add_CFLAG $FLAG
     52# Try adding $FLAG to $CFLAGS, compile and run the fpubits program.
     53# If it compiles and running it doesn't crash it (with an Illegal
     54# Instruction for example), then we add $FLAG to $CFLAGS.
     55# Return 0 if we added $FLAG and the FPU correctly used 53 bits,
     56# return 1 if we added $FLAG but the FPU doesn't use 53 bits,
     57# return 2 if we did not add $FLAG.
     58try_add_CFLAG()
     59{
    5160    # We use -O3 here to really force generation of fused
    52     # multiply-and-add instructions and to keep floats as much as
     61    # multiply-add instructions and to keep floats as much as
    5362    # possible in registers.
    54     if $CC $CFLAGS $FLAG -O3 -o config/fpubits config/fpubits1.c config/fpubits2.c 2>/dev/null; then
     63    # We compile in the (already patched!) src/fpu.c which only does
     64    # something if the macro x86 is defined.
     65    if $CC -O3 $CFLAGS $FLAG config/fpubits1.c config/fpubits2.c src/fpu.c -o config/fpubits 2>/dev/null; then
    5566        # Compiled successfully, now run it
    5667        config/fpubits >/dev/null 2>/dev/null
    57         if [ $? -le 1 ]; then
     68        status=$?
     69        if [ $status -le 1 ]; then
    5870            # The program ran successfully.  For now, we don't need
    5971            # the exit status to be zero (indicating exactly 53 bits),
    6072            # we simply need the program not to crash (which would
    6173            # give an exit status > 128).
    6274            CFLAGS="$CFLAGS $FLAG"
     75            return $status
    6376        fi
    6477    fi
     78    return 2
     79}
     80
     81# These flags never hurt, so add them if possible
     82for FLAG in '-fno-fast-math' '-mfpmath=sse' '-Dx86'; do
     83    try_add_CFLAG $FLAG
     84done
     85
     86# Add at most one flag of the following to avoid gcc warnings:
     87# gcc versions which support -ffp-contract deprecate -mno-fused-madd
     88for FLAG in '-ffp-contract=on' '-mno-fused-madd'; do
     89    try_add_CFLAG $FLAG && break
     90done
     91
     92# Some flags to try as last resort.  These hurt performance, so only add
     93# them if needed.
     94for FLAG in '' '-ffloat-store' '-O0'; do
     95    # Stop the loop if the FPU precision already is 53 bits
     96    try_add_CFLAG $FLAG && break
    6597done
    6698
    6799
    68100# 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
     101$CC -O3 $CFLAGS config/fpubits1.c config/fpubits2.c src/fpu.c -o config/fpubits
    71102if [ $? -ne 0 ]; then
    72     echo "The command below failed:"
    73     echo "$CC $CFLAGS -O3 -o config/fpubits config/fpubits1.c config/fpubits2.c"
     103    echo >&2 "Error: the command below failed:"
     104    echo >&2 "$CC -O3 $CFLAGS config/fpubits1.c config/fpubits2.c src/fpu.c -o config/fpubits"
    74105    exit 1
    75106fi
     107export CFLAGS
     108
     109echo "CFLAGS for SYMPOW:$CFLAGS"
    76110
    77111config/fpubits
    78112status=$?
    79113if [ $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 ""
    83 
    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
     114cat >&2 <<EOF
     115Error: the Quad Double library used by SYMPOW assumes IEEE-754 double
     116precision numbers with exactly 53 bits in the mantissa (64 bits in
     117total).  Unfortunately, this is not the case on your system and we
     118currently have no workaround for your system.  Running SYMPOW will
     119almost certainly fail on some inputs.
     120
     121Please report this problem to sage-devel
     122(http://groups.google.com/group/sage-devel), mentioning in particular
     123your operating system, processor type and compiler version
     124(run $CC --version).
     125EOF
    108126elif [ $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
     127cat >&2 <<EOF
     128Error: something very bad happened while checking the precision of your
     129FPU.  Please report this problem (mentioning any error messages above)
     130to sage-devel (http://groups.google.com/group/sage-devel).
     131Mention in particular your operating system and compiler version
     132(run $CC --version).
     133EOF
     134exit 1
    115135fi
    116136
    117 export CFLAGS
    118 
    119137#######################################################################
    120138# Configure
    121139#######################################################################
    122140cd src/
    123141bash ./Configure  # Force bash as shell
    124142if [ $? -ne 0 ]; then
    125    echo "Error configuring sympow"
     143   echo >&2 "Error configuring SYMPOW"
    126144   exit 1
    127145fi
    128146
     
    131149# Build
    132150#######################################################################
    133151$MAKE
    134 
    135152if [ $? -ne 0 ]; then
    136    echo "Error building sympow"
    137    exit 1
    138 fi
    139 
    140 if [ ! -f sympow ]; then
    141    echo "sympow executable missing"
     153   echo >&2 "Error building SYMPOW"
    142154   exit 1
    143155fi
    144156
     
    147159#######################################################################
    148160TARGET="$SAGE_LOCAL/lib/sympow"
    149161
    150 if [ -d "$TARGET" ]; then
    151     rm -rf "$TARGET"
    152 fi
     162rm -rf "$TARGET"
    153163mkdir "$TARGET"
    154164
    155165cp sympow *.gp new_data "$TARGET/"
    156 
    157 if [ ! -f "$TARGET/sympow" ]; then
    158    echo "sympow executable didn't copy correctly"
     166if [ $? -ne 0 ]; then
     167   echo >&2 "Error copying SYMPOW files"
    159168   exit 1
    160169fi
    161170
    162171# Copy datafiles
    163172mv datafiles "$TARGET/"
    164173if [ ! -d "$TARGET/datafiles" ]; then
    165    echo "Error installing sympow datafiles."
     174   echo >&2 "Error installing SYMPOW datafiles"
    166175   exit 1
    167176fi
    168177
     
    172181    NUM=`grep -c AT $file`
    173182    ../sympow -txt2bin "$NUM" <$file ${file/%txt/bin}
    174183    if [ $? -ne 0 ]; then
    175         echo "Running sympow failed"
     184        echo >&2 "Error running SYMPOW"
    176185        exit 1
    177186    fi
    178187done
     
    180189# Create sympow script in $SAGE_ROOT/local/bin
    181190SCRIPT="$SAGE_LOCAL/bin/sympow"
    182191
    183 cat >$SCRIPT <<'EOF'
     192cat >"$SCRIPT" <<'EOF'
    184193#!/usr/bin/env bash
    185194
    186195cd "$SAGE_LOCAL/lib/sympow"
    187196exec ./sympow "$@"
    188197EOF
    189198
    190 chmod +x $SCRIPT
    191 
    192 exit 0
     199chmod +x "$SCRIPT"