From 22f9be6a47cee65f40db9dd5ee7eb34b91b19cf0 Mon Sep 17 00:00:00 2001 From: Simon Maertens Date: Fri, 12 Jul 2024 14:52:11 +0100 Subject: [PATCH 1/2] Added parentheses to multiplications to prevent compilers from using FMAs where the different rounding can lead to a change in control flow. --- SRC/dlanv2.f | 8 ++++++-- SRC/slanv2.f | 10 +++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/SRC/dlanv2.f b/SRC/dlanv2.f index c55b0ce510..a4bd262c98 100644 --- a/SRC/dlanv2.f +++ b/SRC/dlanv2.f @@ -248,10 +248,14 @@ SUBROUTINE DLANV2( A, B, C, D, RT1R, RT1I, RT2R, RT2I, CS, SN ) * * Compute [ A B ] = [ CS SN ] [ AA BB ] * [ C D ] [-SN CS ] [ CC DD ] +* +* Note: Some of the multiplications are wrapped in parentheses to +* prevent compilers from using FMA instructions. See +* https://github.com/Reference-LAPACK/lapack/issues/1031. * A = AA*CS + CC*SN - B = BB*CS + DD*SN - C = -AA*SN + CC*CS + B = ( BB*CS ) + ( DD*SN ) + C = -( AA*SN ) + ( CC*CS ) D = -BB*SN + DD*CS * TEMP = HALF*( A+D ) diff --git a/SRC/slanv2.f b/SRC/slanv2.f index ac1a197822..40470867e7 100644 --- a/SRC/slanv2.f +++ b/SRC/slanv2.f @@ -144,7 +144,7 @@ SUBROUTINE SLANV2( A, B, C, D, RT1R, RT1I, RT2R, RT2I, CS, SN ) * .. * .. Local Scalars .. REAL AA, BB, BCMAX, BCMIS, CC, CS1, DD, EPS, P, SAB, - $ SAC, SCALE, SIGMA, SN1, TAU, TEMP, Z, SAFMIN, + $ SAC, SCALE, SIGMA, SN1, TAU, TEMP, Z, SAFMIN, $ SAFMN2, SAFMX2 INTEGER COUNT * .. @@ -248,10 +248,14 @@ SUBROUTINE SLANV2( A, B, C, D, RT1R, RT1I, RT2R, RT2I, CS, SN ) * * Compute [ A B ] = [ CS SN ] [ AA BB ] * [ C D ] [-SN CS ] [ CC DD ] +* +* Note: Some of the multiplications are wrapped in parentheses to +* prevent compilers from using FMA instructions. See +* https://github.com/Reference-LAPACK/lapack/issues/1031. * A = AA*CS + CC*SN - B = BB*CS + DD*SN - C = -AA*SN + CC*CS + B = ( BB*CS ) + ( DD*SN ) + C = -( AA*SN ) + ( CC*CS ) D = -BB*SN + DD*CS * TEMP = HALF*( A+D ) From 349b76a5ee8586c6cbddfee5a08ff536707fe2ff Mon Sep 17 00:00:00 2001 From: Simon Maertens Date: Fri, 12 Jul 2024 15:00:39 +0100 Subject: [PATCH 2/2] Remove trailing whitespace --- SRC/dlanv2.f | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SRC/dlanv2.f b/SRC/dlanv2.f index a4bd262c98..9008fdde08 100644 --- a/SRC/dlanv2.f +++ b/SRC/dlanv2.f @@ -144,7 +144,7 @@ SUBROUTINE DLANV2( A, B, C, D, RT1R, RT1I, RT2R, RT2I, CS, SN ) * .. * .. Local Scalars .. DOUBLE PRECISION AA, BB, BCMAX, BCMIS, CC, CS1, DD, EPS, P, SAB, - $ SAC, SCALE, SIGMA, SN1, TAU, TEMP, Z, SAFMIN, + $ SAC, SCALE, SIGMA, SN1, TAU, TEMP, Z, SAFMIN, $ SAFMN2, SAFMX2 INTEGER COUNT * ..