From e0e56b0da80406a01d8c3e733c96b4bdfb7409ac Mon Sep 17 00:00:00 2001 From: Dmitry Volyntsev Date: Tue, 5 Jul 2022 22:58:12 -0700 Subject: [PATCH] Ensuring that double type is always evaluated at standard precision. Previously, GCC on x86 uses extended precision for intermediate calculations by default. This might conflict with njs_diyfp_t because GCC is not always rounds back the intermediate values to standard precision. The fix is to explicitly tell to a compiler to do so. This closes #507 issue on Github. --- auto/types | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/auto/types b/auto/types index 7bb9c16a..6e1c2c61 100644 --- a/auto/types +++ b/auto/types @@ -118,3 +118,57 @@ njs_feature_test="#include return 0; }" . auto/feature + + +# Ensuring that double type is always evaluated at standard +# precision required by njs_diyfp_t + + +case $NJS_CC_NAME in + + gcc) + NJS_CFLAGS="$NJS_CFLAGS -fexcess-precision=standard" + ;; + + clang) + + njs_found=no + + njs_feature="flag -ffp-eval-method=double" + njs_feature_name=NJS_HAVE_FP_EVAL_METHOD + njs_feature_run=no + njs_feature_incs="-ffp-eval-method=double" + njs_feature_libs= + njs_feature_test="int main(void) { + return 0; + }" + + . auto/feature + + if [ $njs_found = yes ]; then + NJS_CFLAGS="$NJS_CFLAGS -ffp-eval-method=double" + fi + + ;; + + SunC) + + njs_found=no + + njs_feature="flag -xarch=sse2" + njs_feature_name=NJS_HAVE_XARCH_SSE2 + njs_feature_run=no + njs_feature_incs="-xarch=sse2" + njs_feature_libs= + njs_feature_test="int main(void) { + return 0; + }" + + . auto/feature + + if [ $njs_found = yes ]; then + NJS_CFLAGS="$NJS_CFLAGS -xarch=sse2" + fi + ;; + +esac -- 2.47.3