Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to use safe scaling algorithm from Reference-LAPACK PR 527 #4143

Merged
merged 8 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 49 additions & 17 deletions interface/rotg.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include <math.h>
#include <float.h>
#include "common.h"
#ifdef FUNCTION_PROFILE
#include "functable.h"
#endif


#ifndef CBLAS

void NAME(FLOAT *DA, FLOAT *DB, FLOAT *C, FLOAT *S){
Expand All @@ -14,35 +16,53 @@ void CNAME(FLOAT *DA, FLOAT *DB, FLOAT *C, FLOAT *S){

#endif

#ifdef DOUBLE
long double safmin = DBL_MIN;
#else
long double safmin = FLT_MIN;
#endif

#if defined(__i386__) || defined(__x86_64__) || defined(__ia64__) || defined(_M_X64) || defined(_M_IX86)

long double da = *DA;
long double db = *DB;
long double c;
long double s;
long double r, roe, z;
long double r, z;
long double sigma, dascal,dbscal;

long double ada = fabsl(da);
long double adb = fabsl(db);
long double scale = ada + adb;
long double maxab = MAX(ada,adb);
long double safmax;
long double scale;


#ifndef CBLAS
PRINT_DEBUG_NAME;
#else
PRINT_DEBUG_CNAME;
#endif

roe = db;
if (ada > adb) roe = da;

if (scale == ZERO) {
if (adb == ZERO) {
*C = ONE;
*S = ZERO;
*DA = ZERO;
*DB = ZERO;
} else if (ada == ZERO) {
*C = ZERO;
*S = ONE;
*DA = *DB;
*DB = ONE;
} else {
r = sqrt(da * da + db * db);
if (roe < 0) r = -r;
safmax = 1./safmin;
scale = MIN(MAX(safmin,maxab), safmax);
if (ada > adb)
sigma = copysign(1.,da);
else
sigma = copysign(1.,db);
dascal = da / scale;
dbscal = db / scale;
r = sigma * (scale * sqrt(dascal * dascal + dbscal * dbscal));
c = da / r;
s = db / r;
z = ONE;
Expand All @@ -65,32 +85,44 @@ void CNAME(FLOAT *DA, FLOAT *DB, FLOAT *C, FLOAT *S){
FLOAT db = *DB;
FLOAT c = *C;
FLOAT s = *S;
FLOAT r, roe, z;
FLOAT sigma;
FLOAT r, z;

FLOAT ada = fabs(da);
FLOAT adb = fabs(db);
FLOAT scale = ada + adb;
FLOAT maxab = MAX(ada,adb);
long double safmax ;
FLOAT scale ;

safmax = 1./safmin;
scale = MIN(MAX(safmin,maxab), safmax);

if (ada > adb)
sigma = copysign(1.,da);
else
sigma = copysign(1.,db);

#ifndef CBLAS
PRINT_DEBUG_NAME;
#else
PRINT_DEBUG_CNAME;
#endif

roe = db;
if (ada > adb) roe = da;

if (scale == ZERO) {
if (adb == ZERO) {
*C = ONE;
*S = ZERO;
*DA = ZERO;
*DB = ZERO;
} else if (ada == ZERO) {
*C = ZERO;
*S = ONE;
*DA = *DB;
*DB = ONE;
} else {
FLOAT aa = da / scale;
FLOAT bb = db / scale;

r = scale * sqrt(aa * aa + bb * bb);
if (roe < 0) r = -r;
r = sigma * scale * sqrt(aa * aa + bb * bb);
c = da / r;
s = db / r;
z = ONE;
Expand Down
Loading