On Oct 7, 2009, at 7:54 AM, Vincent Labrecque wrote:
>
> And as I'm writing this, with regards to optimization flags, maybe  
> the sage build system should provide an abstraction over -On.   As  
> I'm sure you know, these have widely differing behaviors across  
> compilers.  Sometimes -O3 will do nothing, sometimes it will break  
> your code.  ``high'', ``medium'' and ``low'' can be translated by an  
> expert on the particular platform (os/compiler/compiler-version).

This probably should even be per-package.  In particular with packages  
doing complex operation chains.  It could be made easy for a package  
to change the optimization level.

To put what I tried to explain in the last post in practice, here's  
over egineering in the form of a helper program, where packages can  
downgrade optimization levels if they know better:

   eval `./interpret-optimization -O0 -O2 -O3`
   #runs  CFLAGS_OPTIMIZATION_LOW=-O0; export CFLAGS_OPTIMIZATION_LOW
   #          CFLAGS_OPTIMIZATION_MEDIUM=-O2; export  
CFLAGS_OPTIMIZATION_MEDIUM
   #          CFLAGS_OPTIMIZATION_HIGH=-O3; export  
CFLAGS_OPTIMIZATION_MEDIUM

   # Here's what could happen if another part of the build system  
decided that anything over -O3 was unsafe.
   CFLAGS_OPTIMIZATION_HIGH=-O2
   eval `./interpret-optimization -O1 -O2 -O4`
   # runs CFLAGS_OPTIMIZATION_LOW=-O1; export CFLAGS_OPTIMIZATION_LOW
   #          CFLAGS_OPTIMIZATION_MEDIUM=-O2; export  
CFLAGS_OPTIMIZATION_MEDIUM

Maybe one would want to also make sure low <= medium <= high at all  
times, which would require a few more lines.
Keep in mind that this was only barely tested.  Anyway.  Here's how  
you can unintrusively share environment variables.

--Vincent

#!/bin/sh
new_low=${1-"-O0"}; new_medium=${2-"-O2"}; new_high=${3-"-O3"}
current_low=${CFLAGS_OPTIMIZATION_LOW-"-O10"}
current_medium=${CFLAGS_OPTIMIZATION_MEDIUM-"-O10"}
current_high=${CFLAGS_OPTIMIZATION_HIGH-"-O10"}

new_low_n=`echo $new_low | sed 's/^-O//'`
new_medium_n=`echo $new_medium | sed 's/^-O//'`
new_high_n=`echo $new_high | sed 's/^-O//'`

current_low_n=`echo $current_low | sed 's/^-O//'`;
current_medium_n=`echo $current_medium | sed 's/^-O//'`
current_high_n=`echo $current_high | sed 's/-O//'`

[ "$current_low_n" -gt "$new_low_n" ] && echo  
'CFLAGS_OPTIMIZATION_LOW='"$new_low"'; export CFLAGS_OPTIMIZATION_LOW'
[ "$current_medium_n" -gt "$new_medium_n" ] && echo  
'CFLAGS_OPTIMIZATION_MEDIUM='"$new_medium"'; export  
CFLAGS_OPTIMIZATION_MEDIUM'
[ "$current_high_n" -gt "$new_high_n" ] && echo  
'CFLAGS_OPTIMIZATION_HIGH='"$new_high"'; export  
CFLAGS_OPTIMIZATION_HIGH'
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel-unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to