Compile the Paranoia.c code with gnu compiler and test the correctness of the Floating Point arithmetic
This program is designed to see how compliant a compiler and its options are with the IEEE standard. In the first part of this exercise we will play just with the Gnu compiler.
If time is left we invite you to go further and evaluate Intel and PGI compilers as well: it is really important to check carefully which version of the gcc compiler you are using and learn about important flags regarding IEEE arithmetic.
Instructions:
1. Check-out which version of gcc we are playing with:
$ gcc -v
You should get something like the following output:
Using built-in specs. Target: x86_64-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enablethreads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic --host=x86_64-redhat-linux Thread model: posix gcc version 4.1.2 20071124 (Red Hat 4.1.2-42)
You should then take a look at the gcc man pages and pay special attention to the following section: (look for it through the huge man page)
The following options control compiler behavior regarding floating point arithmetic. These options trade off between speed and correctness. All must be specifically enabled. -ffloat-store -ffast-math etc..
2. Start Compiling the paranoia code with gcc using standard different level of optimization producing different executables
$ cd .. $ cd paranoia $ gcc -g paranoia.c -o paranoia-g -lm $ gcc paranoia.c -O0 -o paranoia-0 -lm $ gcc paranoia.c –O1 -o paranoia-1 -lm $ gcc paranoia.c –O2 -o paranoia-2 -lm $ gcc paranoia.c –O3 -o paranoia-3 -lm
3. Run all of them saving the output on different files
$ ./paranoia-g > out_paranoia-g
4. You should find something strange starting from optimization level 01. What is happening (please report this on your wiki) ?
5. (optional) Repeat steps 1,2,3 for intel C compiler and pgi C compiler.