Ticket #11920: sympow-1.018.1.p10-p11.diff
File sympow-1.018.1.p10-p11.diff, 10.9 KB (added by , 9 years ago) |
---|
-
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 46 46 47 47 == Changelog == 48 48 49 === sympow-1.018.1.p1 0 (Jeroen Demeyer, 19 Oct 2011) ===49 === sympow-1.018.1.p11 (Jeroen Demeyer, 19 Jan 2012) === 50 50 * #11920: Remove -fno-expensive-optimizations workaround, instead try 51 51 various flags which might force 53-bit precision doubles. 52 52 * Find out the actual FPU precision with config/fpubits1.c and 53 53 config/fpubits2.c. 54 54 * Move all x86 extended precision FPU-control word stuff from 55 55 src/Configure to spkg-install 56 * Generate binary datafiles when installing sympow. This ensures that56 * Generate binary datafiles when installing SYMPOW. This ensures that 57 57 all users (not only the one which installed Sage) can use the standard 58 58 datafiles. 59 59 * execlp.patch: Use execlp() instead of execl() to execute "sh". This 60 60 is needed for the -new_data option to work (which surely could never 61 61 have worked before). 62 62 * Use `patch` instead of `cp` for patching. 63 * Lots of small fixes in spkg-install. 63 64 * Remove dist/debian directory. 64 65 65 66 === 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 8 8 9 9 #include <stdio.h> 10 10 11 double mul_and_add(double, double, double); 11 double mul_and_add(double, double, double); /* config/fpubits2.c */ 12 void fpu_53bits(); /* src/fpu.c */ 12 13 13 14 int main(int argc, char** argv) 14 15 { 16 /* If x86 is defined, set the FPU to 53 bits */ 17 #ifdef x86 18 fpu_53bits(); 19 #endif 20 15 21 /* Let a = 1 + x, 16 22 * b = 1 + y, 17 23 * and compute -
sympow-1.018.1.
diff -ru sympow-1.018.1.p10/spkg-install sympow-1.018.1.p11/spkg-install
old new 1 1 #!/usr/bin/env bash 2 2 3 3 if [ "$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'?" 6 6 exit 1 7 7 fi 8 8 … … 14 14 15 15 # If SAGE64 is "yes", build 64-bit. 16 16 if [ "x$SAGE64" = xyes ] ; then 17 echo "Building S ympow 64-bit"17 echo "Building SYMPOW 64-bit" 18 18 CFLAGS="$CFLAGS $CFLAG64" 19 19 LDFLAGS="$LDFLAGS $CFLAG64" 20 20 export CFLAGS … … 39 39 40 40 41 41 ####################################################################### 42 # CheckFPU precision42 # Fix FPU precision 43 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. 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. 58 try_add_CFLAG() 59 { 51 60 # We use -O3 here to really force generation of fused 52 # multiply-a nd-add instructions and to keep floats as much as61 # multiply-add instructions and to keep floats as much as 53 62 # 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 55 66 # Compiled successfully, now run it 56 67 config/fpubits >/dev/null 2>/dev/null 57 if [ $? -le 1 ]; then 68 status=$? 69 if [ $status -le 1 ]; then 58 70 # The program ran successfully. For now, we don't need 59 71 # the exit status to be zero (indicating exactly 53 bits), 60 72 # we simply need the program not to crash (which would 61 73 # give an exit status > 128). 62 74 CFLAGS="$CFLAGS $FLAG" 75 return $status 63 76 fi 64 77 fi 78 return 2 79 } 80 81 # These flags never hurt, so add them if possible 82 for FLAG in '-fno-fast-math' '-mfpmath=sse' '-Dx86'; do 83 try_add_CFLAG $FLAG 84 done 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 88 for FLAG in '-ffp-contract=on' '-mno-fused-madd'; do 89 try_add_CFLAG $FLAG && break 90 done 91 92 # Some flags to try as last resort. These hurt performance, so only add 93 # them if needed. 94 for FLAG in '' '-ffloat-store' '-O0'; do 95 # Stop the loop if the FPU precision already is 53 bits 96 try_add_CFLAG $FLAG && break 65 97 done 66 98 67 99 68 100 # 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 71 102 if [ $? -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" 74 105 exit 1 75 106 fi 107 export CFLAGS 108 109 echo "CFLAGS for SYMPOW:$CFLAGS" 76 110 77 111 config/fpubits 78 112 status=$? 79 113 if [ $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 114 cat >&2 <<EOF 115 Error: the Quad Double library used by SYMPOW assumes IEEE-754 double 116 precision numbers with exactly 53 bits in the mantissa (64 bits in 117 total). Unfortunately, this is not the case on your system and we 118 currently have no workaround for your system. Running SYMPOW will 119 almost certainly fail on some inputs. 120 121 Please report this problem to sage-devel 122 (http://groups.google.com/group/sage-devel), mentioning in particular 123 your operating system, processor type and compiler version 124 (run $CC --version). 125 EOF 108 126 elif [ $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 127 cat >&2 <<EOF 128 Error: something very bad happened while checking the precision of your 129 FPU. Please report this problem (mentioning any error messages above) 130 to sage-devel (http://groups.google.com/group/sage-devel). 131 Mention in particular your operating system and compiler version 132 (run $CC --version). 133 EOF 134 exit 1 115 135 fi 116 136 117 export CFLAGS118 119 137 ####################################################################### 120 138 # Configure 121 139 ####################################################################### 122 140 cd src/ 123 141 bash ./Configure # Force bash as shell 124 142 if [ $? -ne 0 ]; then 125 echo "Error configuring sympow"143 echo >&2 "Error configuring SYMPOW" 126 144 exit 1 127 145 fi 128 146 … … 131 149 # Build 132 150 ####################################################################### 133 151 $MAKE 134 135 152 if [ $? -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" 142 154 exit 1 143 155 fi 144 156 … … 147 159 ####################################################################### 148 160 TARGET="$SAGE_LOCAL/lib/sympow" 149 161 150 if [ -d "$TARGET" ]; then 151 rm -rf "$TARGET" 152 fi 162 rm -rf "$TARGET" 153 163 mkdir "$TARGET" 154 164 155 165 cp sympow *.gp new_data "$TARGET/" 156 157 if [ ! -f "$TARGET/sympow" ]; then 158 echo "sympow executable didn't copy correctly" 166 if [ $? -ne 0 ]; then 167 echo >&2 "Error copying SYMPOW files" 159 168 exit 1 160 169 fi 161 170 162 171 # Copy datafiles 163 172 mv datafiles "$TARGET/" 164 173 if [ ! -d "$TARGET/datafiles" ]; then 165 echo "Error installing sympow datafiles."174 echo >&2 "Error installing SYMPOW datafiles" 166 175 exit 1 167 176 fi 168 177 … … 172 181 NUM=`grep -c AT $file` 173 182 ../sympow -txt2bin "$NUM" <$file ${file/%txt/bin} 174 183 if [ $? -ne 0 ]; then 175 echo "Running sympow failed"184 echo >&2 "Error running SYMPOW" 176 185 exit 1 177 186 fi 178 187 done … … 180 189 # Create sympow script in $SAGE_ROOT/local/bin 181 190 SCRIPT="$SAGE_LOCAL/bin/sympow" 182 191 183 cat > $SCRIPT<<'EOF'192 cat >"$SCRIPT" <<'EOF' 184 193 #!/usr/bin/env bash 185 194 186 195 cd "$SAGE_LOCAL/lib/sympow" 187 196 exec ./sympow "$@" 188 197 EOF 189 198 190 chmod +x $SCRIPT 191 192 exit 0 199 chmod +x "$SCRIPT"