Files
astronomy/generate/ctbuild
Don Cross 2c787eca8e Refined the problematic optimizations to -ffp-contract=off.
Instead of turning off all "expensive optimizations" in gcc,
I found I can achieve consistent calculation results on
64-bit ARM processors by turning off just the "fp contract"
optimization.

This optimizer is actually supposed to produce *more* accurate
results, but the effect is to produce results that differ
across languages/processors. For the sake of the unit tests,
I have decided it must be turned off in ctest and generate.
2020-07-22 21:30:51 +00:00

37 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
Fail()
{
echo "ERROR($0): $1"
exit 1
}
[[ -z "${CC}" ]] && CC=gcc
echo "$0: C compiler = ${CC}"
if [[ "$1" == "debug" ]]; then
BUILDOPT='-g -Og'
elif [[ "$1" == "opt" ]]; then
BUILDOPT="$2"
echo "Using custom build options: ${BUILDOPT}"
elif [[ -z "$1" ]]; then
# On Arch Linux running gcc 9.3.0 on aarch64 (Rasbperry Pi 3),
# started to get some numeric discrepancies in 'ctest check' output
# until I turned off "fp contract" optimizations.
# Some processors (including 64-bit ARM) have the ability to evaluate floating point
# expressions like "a*b + c" with a single instruction, and to
# do so without rounding the intermediate multiplication result.
# Although this is *more* accurate, it produces results that are
# different from other processors, which is counterproductive for
# unit tests. Therefore, I turn it off here. Users of the C
# version of Astronomy Engine can safely build other code with '-O3' by itself.
BUILDOPT='-O3 -ffp-contract=off'
else
Fail "unrecognized command line option"
fi
${CC} ${BUILDOPT} -Wall -Werror -o ctest -I ../source/c/ ../source/c/astronomy.c ctest.c -lm || Fail "Error building ctest"
echo "$0: Built 'ctest' program."
exit 0