Skip to content

BLAS: inline DCABS1 in DZASUM - #1421

Open
ACSimon33 wants to merge 1 commit into
Reference-LAPACK:masterfrom
ACSimon33:blas-dzasum-inlines-dcabs1
Open

ACSimon33 wants to merge 1 commit into
Reference-LAPACK:masterfrom
ACSimon33:blas-dzasum-inlines-dcabs1

Conversation

@ACSimon33

Copy link
Copy Markdown
Collaborator

Description

DZASUM accumulates with STEMP = STEMP + DCABS1(ZX(I)). That is the last call to DCABS1 anywhere in the library, and on a build without link-time optimization it is the whole cost of the loop: the helper lives in its own translation unit, so the compiler cannot inline it and the accumulation runs at one call per element. This PR writes the call out as STEMP + (ABS(DBLE(ZX(I))) + ABS(DIMAG(ZX(I)))).

The outer parentheses are important. DCABS1 adds the two parts to each other and returns one value, which DZASUM then folds into STEMP: one rounding for the pair and one into the accumulator. Parenthesised, the inline form does exactly that, so every result DZASUM returns is unchanged, bit for bit. Without the parentheses it would become (STEMP + |re|) + |im|, two roundings into the accumulator, which is the grouping SCASUM uses and a different answer.

This PR replaces #1418, which went the other way: it made SCASUM call SCABS1 and so moved SCASUM onto DZASUM's grouping, which changed 95% of its results by about 6.8 ulp.

We keep ?CABS1 for backwards compatibility and because basically all vendor BLAS libraries export it as well. I added a small test in the test suite to cover it.

The call is the last one to DCABS1 in the library, and it costs more
than twice the loop it sits in unless the build uses LTO.  Writing it
out with the inner parentheses kept returns bit-identical results.

That leaves SCABS1 and DCABS1 with no caller at all, so xBLAT1 gains a
case of its own for each, and both say in their documentation that they
are kept for the callers outside this library.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@codecov

codecov Bot commented Sep 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.36%. Comparing base (a6c6e74) to head (4e5b091).
⚠️ Report is 2 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1421   +/-   ##
=======================================
  Coverage   69.36%   69.36%           
=======================================
  Files        6122     6122           
  Lines      486711   486725   +14     
  Branches    23268    23268           
=======================================
+ Hits       337584   337601   +17     
+ Misses     148689   148686    -3     
  Partials      438      438           
Components Coverage Δ
BLAS 97.96% <100.00%> (+0.02%) ⬆️
CBLAS 96.98% <ø> (ø)
LAPACK 82.38% <ø> (ø)
LAPACKE 2.17% <ø> (ø)
TMGLIB 55.69% <ø> (ø)
BLAS testing 88.34% <100.00%> (+<0.01%) ⬆️
CBLAS testing 89.63% <ø> (ø)
LAPACK testing 82.20% <ø> (ø)
LAPACKE testing ∅ <ø> (∅)
Files with missing lines Coverage Δ
BLAS/SRC/dcabs1.f 100.00% <ø> (ø)
BLAS/SRC/dzasum.f 100.00% <100.00%> (ø)
BLAS/SRC/scabs1.f 100.00% <ø> (+100.00%) ⬆️
BLAS/TESTING/cblat1.f 89.03% <100.00%> (+0.26%) ⬆️
BLAS/TESTING/zblat1.f 89.03% <100.00%> (+0.26%) ⬆️

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a6c6e74...4e5b091. Read the comment docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant