[njs] Ensuring that double type is always evaluated at standard precision.
Dmitry Volyntsev
xeioex at nginx.com
Wed Jul 6 06:02:36 UTC 2022
details: https://hg.nginx.org/njs/rev/545d2d21dda5
branches:
changeset: 1903:545d2d21dda5
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Tue Jul 05 22:58:12 2022 -0700
description:
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.
diffstat:
auto/types | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 54 insertions(+), 0 deletions(-)
diffs (61 lines):
diff -r b7c4e0f714a9 -r 545d2d21dda5 auto/types
--- a/auto/types Tue Jun 28 23:04:00 2022 -0700
+++ b/auto/types Tue Jul 05 22:58:12 2022 -0700
@@ -118,3 +118,57 @@ njs_feature_test="#include <time.h>
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
More information about the nginx-devel
mailing list