File: acoptim.m4

package info (click to toggle)
freefem++ 3.61.1+dfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 17,108 kB
  • sloc: cpp: 141,214; ansic: 28,664; sh: 4,925; makefile: 3,142; fortran: 1,171; perl: 844; awk: 290; php: 199; pascal: 41; f90: 32
file content (275 lines) | stat: -rw-r--r-- 8,296 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# Choosing debugging and/or optimization flags for compilation
# ------------------------------------------------------------

AC_ARG_ENABLE(profiling,[  --enable-profiling	Turn on profiling])
if test "$enable_profiling" = yes
then
	CXXFLAGS="$CXXFLAGS -pg"
	LDFLAGS="$LDFLAGS -pg"
fi

if test "$enable_m64" = yes -a "$enable_m32" 
then
  	    AC_MSG_ERROR([ Choose  32 or 64 architecture not the both ],1);  
fi
AC_ARG_ENABLE(m64,[  --enable-m64	Turn on 64 bits architecture])
if test "$enable_m64" = yes
then
	ff_m64=-m64	
	ff_ok=no
        CHECK_COMPILE_FLAG(C,$ff_m64,CFLAGS,ff_ok)
        if test "$ff_ok" = yes ;then  CNOFLAGS="$CFLAGS $ff_m64";fi
	CHECK_COMPILE_FLAG(C++,$ff_m64,CXXFLAGS)
	CHECK_COMPILE_FLAG(Fortran 77,$ff_m64,FFLAGS)	
#  add -fPIC on on 64 architecture 
   if test "$ff_ok" = yes -a "$ff_fpic" != "no" ;then    
        CHECK_COMPILE_FLAG(C,-fPIC,CFLAGS,ff_ok)
	CHECK_COMPILE_FLAG(C++,-fPIC,CXXFLAGS)
	CHECK_COMPILE_FLAG(Fortran 77,-fPIC,FFLAGS)	
  fi

fi
AC_ARG_ENABLE(m32,[  --enable-m32	Turn on 32 bits architecture])
if test "$enable_m32" = yes 
then
	ff_m32=-m32	
	ff_ok=no
        CHECK_COMPILE_FLAG(C,$ff_m32,CFLAGS,ff_ok)
        if test "$ff_ok" = yes ;then  CNOFLAGS="$CFLAGS $ff_m32";fi
        CHECK_COMPILE_FLAG(C,$ff_m32,CNOFLAGS)
	CHECK_COMPILE_FLAG(C++,$ff_m32,CXXFLAGS)
	CHECK_COMPILE_FLAG(Fortran 77,$ff_m32,FFLAGS)	
#  add -fPIC on on 64 architecture 
#        CHECK_COMPILE_FLAG(C,-fPIC,CFLAGS)
#	CHECK_COMPILE_FLAG(C++,-fPIC,CXXFLAGS)
#	CHECK_COMPILE_FLAG(Fortran 77,-fPIC,FFLAGS)	

fi

# Debug mode (no optimisation)
# ----------------------------

AC_MSG_CHECKING(whether to generate debugging information)

AC_ARG_ENABLE(debug,[  --enable-debug	Turn on debug versions of FreeFem++])
AC_ARG_ENABLE(optim,[  --enable-optim	Turn on compiler optimization])

if test "$enable_debug" = yes;
then

	AC_MSG_RESULT(yes)
	CFLAGS="`echo $CFLAGS | sed 's/-O2//g'`"
	FFLAGS="`echo $FFLAGS | sed 's/-O2//g'`"
	CXXFLAGS="`echo $CXXFLAGS | sed 's/-O2//g'`"
        CHECK_COMPILE_FLAG(C,-g,CFLAGS)
	CHECK_COMPILE_FLAG(C++,-g,CXXFLAGS)
	CHECK_COMPILE_FLAG(Fortran 77,-g,FFLAGS)	

else
	AC_MSG_RESULT(no)

	# No debugging information in optimized code

	CFLAGS="$CFLAGS -DNDEBUG"
	FFLAGS="$FFLAGS -DNDEBUG"
	CXXFLAGS="$CXXFLAGS -DNDEBUG"
fi

# Hardware-independant optimization
# ---------------------------------

if test "$enable_debug" != yes -a "$enable_optim" != no;
then
	CHECK_COMPILE_FLAG(C,-O3,CFLAGS)
	CHECK_COMPILE_FLAG(C++,-O3,CXXFLAGS)
	CHECK_COMPILE_FLAG(Fortran 77,-O3,FFLAGS)
fi

AC_ARG_ENABLE(generic,
[  --enable-generic	Turn off hardware-dependant optimization options])

# FFCS: remove "-mcpu=common" to allow other hardware-dependant values of cpu for PowerPC - thank you Fred (20/02/11)

if test $enable_ffcs = yes
then
    # Generic code
    if test "$enable_debug" != yes \
	-a "$enable_optim" != no \
	-a "$enable_generic" = yes
    then
	CHECK_COMPILE_FLAG(C,-mcpu=common,CFLAGS)
	CHECK_COMPILE_FLAG(C++,-mcpu=common,CXXFLAGS)
	CHECK_COMPILE_FLAG(Fortran 77,-mcpu=common,FFLAGS)
    fi
fi

# Hardware-dependant optimization
# -------------------------------

if test "$enable_debug" != yes \
    -a "$enable_optim" != no \
    -a "$enable_generic" != yes
then

# Autoconf always chooses -O2. -O2 in gcc makes some functions
# disappear. This is not ideal for debugging. And when we optimize, we
# do not use -O2 anyway.

CFLAGS="`echo $CFLAGS | sed 's/-O2//g'`"
FFLAGS="`echo $FFLAGS | sed 's/-O2//g'`"
CXXFLAGS="`echo $CXXFLAGS | sed 's/-O2//g'`"

    # MacOS X Darwin
    if test -x /usr/bin/hostinfo
	then
        

	# If we are on MacOS X to choise the optimisaztion 
	AC_MSG_CHECKING(GCC version)

        ff_gcc4=`$CC  --version |awk  ' NR==1 {print $3}'|sed -e 's/\..*$//'` 
	ff_clang=`$CC  --version |awk  '/clang/  {print $4}'`
	if test -n "$ff_clang" ; then ff_gcc4="llvm"; fi
	AC_MSG_RESULT($ff_gcc4)

	# At the moment, we do not know how to produce correct
	# optimizated code on G5.
	AC_MSG_CHECKING(PowerPC architecture)
	ff_machine=`(test -x /usr/bin/machine && /usr/bin/machine) || echo unknow`
        ff_fast="-O3"
	if test	-n "$ff_clang" ; then
          ff_fast='-O3'
	elif test `uname` = Darwin 
	    then
	    # Optimization flags: -fast option do not work because the
	    # -malign-natural flags create wrong IO code
            if test  "$ff_gcc4" -eq 4 
	    then
               ff_fast='-fast'
            else
	      ff_fast='-O3 -funroll-loops -fstrict-aliasing -fsched-interblock -falign-loops=16 -falign-jumps=16 -falign-functions=16 -falign-jumps-max-skip=15 -falign-loops-max-skip=15 -ffast-math  -mpowerpc-gpopt -force_cpusubtype_ALL -fstrict-aliasing  -mpowerpc64 '
	    fi
	fi        


        # CPU detection

	case $ff_machine  in
	  ppc7450) # G4
		ff_fast="$ff_fast -mtune=G4 -mcpu=G4";;
          ppc970) # G5 
	        # remove -fstrict-aliasing on G5 to much optim the
	        # code cash in GC
		ff_fast="`echo $ff_fast -mtune=G5 -mcpu=G5| sed 's/-fstrict-aliasing //g'`";;
          ppc*) # G3 ????
	       ff_fast="-O3";;
	  i486)
	    ff_fast="-O3 $ff_fast";;
	  x86_64*)
	  ff_fast="-O3 $ff_fast";;
	  *)
	    AC_MSG_ERROR(cannot determine apple cpu type )
	    ff_fast="-O3";;
	 esac


	AC_MSG_RESULT($ff_fast)

        CHECK_COMPILE_FLAG(C,$ff_fast,CFLAGS)
	CHECK_COMPILE_FLAG(C++,$ff_fast,CXXFLAGS)
	CHECK_COMPILE_FLAG(Fortran 77,$ff_fast,FFLAGS)


    # Linux
    elif test -f /proc/cpuinfo
	then

	# Specific processors
	proc_type=unknown
	ff_optim_type=
	if test `grep 'Pentium III (Coppermine)' /proc/cpuinfo|wc -l` -gt 0
	    then
	    proc_type=pentium3
	    ff_optim_type=-P3
	elif test `grep 'Intel(R) Pentium(R) III ' /proc/cpuinfo|wc -l` -gt 0
	    then
	    proc_type=pentium3
	    ff_optim_type=-P3
	elif test `grep 'Intel(R) Pentium(R) 4 ' /proc/cpuinfo|wc -l` -gt 0
	    then
	    proc_type=pentium4
	    ff_optim_type=-P4
	elif test `grep 'Intel(R) Xeon(TM) CPU' /proc/cpuinfo|wc -l` -gt 0
	    then
	    proc_type=pentium4
	    ff_optim_type=-P4
	elif test `grep 'AMD Athlon(tm) Processor' /proc/cpuinfo|wc -l` -gt 0
	    then
	    proc_type=athlon
	    ff_optim_type=-Athlon
	elif test `grep 'AMD Athlon(tm) XP' /proc/cpuinfo|wc -l` -gt 0
	    then
	    proc_type=athlon-xp
	    ff_optim_type=-AthlonXP
	fi

	if test "$proc_type" != unknown
	    then
	    CHECK_COMPILE_FLAG(C,-march=$proc_type,CFLAGS)
	    CHECK_COMPILE_FLAG(C++,-march=$proc_type,CXXFLAGS)
	    CHECK_COMPILE_FLAG(Fortran 77,-march=$proc_type,FFLAGS)
	fi

	# If we did not find a processor type (this happens with
	# cygwin), try and select separate capabilities instead.

	if test "$proc_type" = unknown
	    then
	    if test `grep -e '^flags.*mmx' /proc/cpuinfo|wc -l` -gt 0
		then
		CHECK_COMPILE_FLAG(C,-mmmx,CFLAGS)
		CHECK_COMPILE_FLAG(C++,-mmmx,CXXFLAGS)
		CHECK_COMPILE_FLAG(Fortran 77,-mmmx,FFLAGS)
	    fi
	    if test `grep -e '^flags.*avx' /proc/cpuinfo|wc -l` -gt 0
		then
		CHECK_COMPILE_FLAG(C,-mavx,CFLAGS)
		CHECK_COMPILE_FLAG(C++,-mavx,CXXFLAGS)
		CHECK_COMPILE_FLAG(Fortran 77,-mavx,FFLAGS)
	    else
	        if test `grep -e '^flags.*sse4_2' /proc/cpuinfo|wc -l` -gt 0
		    then
		    CHECK_COMPILE_FLAG(C,-msse4.2,CFLAGS)
		    CHECK_COMPILE_FLAG(C++,-msse4.2,CXXFLAGS)
		    CHECK_COMPILE_FLAG(Fortran 77,-msse4.2,FFLAGS)
	        else
	            if test `grep -e '^flags.*sse2' /proc/cpuinfo|wc -l` -gt 0
	                then
	                CHECK_COMPILE_FLAG(C,-msse2,CFLAGS)
	                CHECK_COMPILE_FLAG(C++,-msse2,CXXFLAGS)
	                CHECK_COMPILE_FLAG(Fortran 77,-msse2,FFLAGS)
				else
	            	if test `grep -e '^flags.*sse ' /proc/cpuinfo|wc -l` -gt 0
		        	then
		        	CHECK_COMPILE_FLAG(C,-msse,CFLAGS)
		        	CHECK_COMPILE_FLAG(C++,-msse,CXXFLAGS)
		        	CHECK_COMPILE_FLAG(Fortran 77,-msse,FFLAGS)
	            	fi
	            	if test `grep -e '^flags.*3dnow' /proc/cpuinfo|wc -l` -gt 0
		        	then
		        	CHECK_COMPILE_FLAG(C,-m3dnow,CFLAGS)
		        	CHECK_COMPILE_FLAG(C++,-m3dnow,CXXFLAGS)
		        	CHECK_COMPILE_FLAG(Fortran 77,-m3dnow,FFLAGS)
	            	fi
	            fi
            fi
        fi
	fi
    fi
fi

# Defines a variable containing the optimization type, to be used in
# binary archive names. It may be empty if only generic optimization
# is used.

AC_SUBST(OPTIM_TYPE,$ff_optim_type)