C_LAPACK: Fixes to make it compile with MSVC (#3605)
[platform/upstream/openblas.git] / lapack-netlib / SRC / slaqr5.c
1 #include <math.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <stdio.h>
5 #include <complex.h>
6 #ifdef complex
7 #undef complex
8 #endif
9 #ifdef I
10 #undef I
11 #endif
12
13 #if defined(_WIN64)
14 typedef long long BLASLONG;
15 typedef unsigned long long BLASULONG;
16 #else
17 typedef long BLASLONG;
18 typedef unsigned long BLASULONG;
19 #endif
20
21 #ifdef LAPACK_ILP64
22 typedef BLASLONG blasint;
23 #if defined(_WIN64)
24 #define blasabs(x) llabs(x)
25 #else
26 #define blasabs(x) labs(x)
27 #endif
28 #else
29 typedef int blasint;
30 #define blasabs(x) abs(x)
31 #endif
32
33 typedef blasint integer;
34
35 typedef unsigned int uinteger;
36 typedef char *address;
37 typedef short int shortint;
38 typedef float real;
39 typedef double doublereal;
40 typedef struct { real r, i; } complex;
41 typedef struct { doublereal r, i; } doublecomplex;
42 #ifdef _MSC_VER
43 static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
44 static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
45 static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
46 static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
47 #else
48 static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
49 static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
50 static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
51 static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
52 #endif
53 #define pCf(z) (*_pCf(z))
54 #define pCd(z) (*_pCd(z))
55 typedef int logical;
56 typedef short int shortlogical;
57 typedef char logical1;
58 typedef char integer1;
59
60 #define TRUE_ (1)
61 #define FALSE_ (0)
62
63 /* Extern is for use with -E */
64 #ifndef Extern
65 #define Extern extern
66 #endif
67
68 /* I/O stuff */
69
70 typedef int flag;
71 typedef int ftnlen;
72 typedef int ftnint;
73
74 /*external read, write*/
75 typedef struct
76 {       flag cierr;
77         ftnint ciunit;
78         flag ciend;
79         char *cifmt;
80         ftnint cirec;
81 } cilist;
82
83 /*internal read, write*/
84 typedef struct
85 {       flag icierr;
86         char *iciunit;
87         flag iciend;
88         char *icifmt;
89         ftnint icirlen;
90         ftnint icirnum;
91 } icilist;
92
93 /*open*/
94 typedef struct
95 {       flag oerr;
96         ftnint ounit;
97         char *ofnm;
98         ftnlen ofnmlen;
99         char *osta;
100         char *oacc;
101         char *ofm;
102         ftnint orl;
103         char *oblnk;
104 } olist;
105
106 /*close*/
107 typedef struct
108 {       flag cerr;
109         ftnint cunit;
110         char *csta;
111 } cllist;
112
113 /*rewind, backspace, endfile*/
114 typedef struct
115 {       flag aerr;
116         ftnint aunit;
117 } alist;
118
119 /* inquire */
120 typedef struct
121 {       flag inerr;
122         ftnint inunit;
123         char *infile;
124         ftnlen infilen;
125         ftnint  *inex;  /*parameters in standard's order*/
126         ftnint  *inopen;
127         ftnint  *innum;
128         ftnint  *innamed;
129         char    *inname;
130         ftnlen  innamlen;
131         char    *inacc;
132         ftnlen  inacclen;
133         char    *inseq;
134         ftnlen  inseqlen;
135         char    *indir;
136         ftnlen  indirlen;
137         char    *infmt;
138         ftnlen  infmtlen;
139         char    *inform;
140         ftnint  informlen;
141         char    *inunf;
142         ftnlen  inunflen;
143         ftnint  *inrecl;
144         ftnint  *innrec;
145         char    *inblank;
146         ftnlen  inblanklen;
147 } inlist;
148
149 #define VOID void
150
151 union Multitype {       /* for multiple entry points */
152         integer1 g;
153         shortint h;
154         integer i;
155         /* longint j; */
156         real r;
157         doublereal d;
158         complex c;
159         doublecomplex z;
160         };
161
162 typedef union Multitype Multitype;
163
164 struct Vardesc {        /* for Namelist */
165         char *name;
166         char *addr;
167         ftnlen *dims;
168         int  type;
169         };
170 typedef struct Vardesc Vardesc;
171
172 struct Namelist {
173         char *name;
174         Vardesc **vars;
175         int nvars;
176         };
177 typedef struct Namelist Namelist;
178
179 #define abs(x) ((x) >= 0 ? (x) : -(x))
180 #define dabs(x) (fabs(x))
181 #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
182 #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
183 #define dmin(a,b) (f2cmin(a,b))
184 #define dmax(a,b) (f2cmax(a,b))
185 #define bit_test(a,b)   ((a) >> (b) & 1)
186 #define bit_clear(a,b)  ((a) & ~((uinteger)1 << (b)))
187 #define bit_set(a,b)    ((a) |  ((uinteger)1 << (b)))
188
189 #define abort_() { sig_die("Fortran abort routine called", 1); }
190 #define c_abs(z) (cabsf(Cf(z)))
191 #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
192 #ifdef _MSC_VER
193 #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
194 #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/Cd(b)._Val[1]);}
195 #else
196 #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
197 #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
198 #endif
199 #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
200 #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
201 #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
202 //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
203 #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
204 #define d_abs(x) (fabs(*(x)))
205 #define d_acos(x) (acos(*(x)))
206 #define d_asin(x) (asin(*(x)))
207 #define d_atan(x) (atan(*(x)))
208 #define d_atn2(x, y) (atan2(*(x),*(y)))
209 #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
210 #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
211 #define d_cos(x) (cos(*(x)))
212 #define d_cosh(x) (cosh(*(x)))
213 #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
214 #define d_exp(x) (exp(*(x)))
215 #define d_imag(z) (cimag(Cd(z)))
216 #define r_imag(z) (cimagf(Cf(z)))
217 #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
218 #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
219 #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
220 #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
221 #define d_log(x) (log(*(x)))
222 #define d_mod(x, y) (fmod(*(x), *(y)))
223 #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
224 #define d_nint(x) u_nint(*(x))
225 #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
226 #define d_sign(a,b) u_sign(*(a),*(b))
227 #define r_sign(a,b) u_sign(*(a),*(b))
228 #define d_sin(x) (sin(*(x)))
229 #define d_sinh(x) (sinh(*(x)))
230 #define d_sqrt(x) (sqrt(*(x)))
231 #define d_tan(x) (tan(*(x)))
232 #define d_tanh(x) (tanh(*(x)))
233 #define i_abs(x) abs(*(x))
234 #define i_dnnt(x) ((integer)u_nint(*(x)))
235 #define i_len(s, n) (n)
236 #define i_nint(x) ((integer)u_nint(*(x)))
237 #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
238 #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
239 #define pow_si(B,E) spow_ui(*(B),*(E))
240 #define pow_ri(B,E) spow_ui(*(B),*(E))
241 #define pow_di(B,E) dpow_ui(*(B),*(E))
242 #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
243 #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
244 #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
245 #define s_cat(lpp, rpp, rnp, np, llp) {         ftnlen i, nc, ll; char *f__rp, *lp;     ll = (llp); lp = (lpp);         for(i=0; i < (int)*(np); ++i) {                 nc = ll;                if((rnp)[i] < nc) nc = (rnp)[i];                ll -= nc;               f__rp = (rpp)[i];               while(--nc >= 0) *lp++ = *(f__rp)++;         }  while(--ll >= 0) *lp++ = ' '; }
246 #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
247 #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
248 #define sig_die(s, kill) { exit(1); }
249 #define s_stop(s, n) {exit(0);}
250 static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
251 #define z_abs(z) (cabs(Cd(z)))
252 #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
253 #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
254 #define myexit_() break;
255 #define mycycle_() continue;
256 #define myceiling_(w) {ceil(w)}
257 #define myhuge_(w) {HUGE_VAL}
258 //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
259 #define mymaxloc_(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
260
261 /* procedure parameter types for -A and -C++ */
262
263 #define F2C_proc_par_types 1
264 #ifdef __cplusplus
265 typedef logical (*L_fp)(...);
266 #else
267 typedef logical (*L_fp)();
268 #endif
269
270 static float spow_ui(float x, integer n) {
271         float pow=1.0; unsigned long int u;
272         if(n != 0) {
273                 if(n < 0) n = -n, x = 1/x;
274                 for(u = n; ; ) {
275                         if(u & 01) pow *= x;
276                         if(u >>= 1) x *= x;
277                         else break;
278                 }
279         }
280         return pow;
281 }
282 static double dpow_ui(double x, integer n) {
283         double pow=1.0; unsigned long int u;
284         if(n != 0) {
285                 if(n < 0) n = -n, x = 1/x;
286                 for(u = n; ; ) {
287                         if(u & 01) pow *= x;
288                         if(u >>= 1) x *= x;
289                         else break;
290                 }
291         }
292         return pow;
293 }
294 #ifdef _MSC_VER
295 static _Fcomplex cpow_ui(complex x, integer n) {
296         complex pow={1.0,0.0}; unsigned long int u;
297                 if(n != 0) {
298                 if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
299                 for(u = n; ; ) {
300                         if(u & 01) pow.r *= x.r, pow.i *= x.i;
301                         if(u >>= 1) x.r *= x.r, x.i *= x.i;
302                         else break;
303                 }
304         }
305         _Fcomplex p={pow.r, pow.i};
306         return p;
307 }
308 #else
309 static _Complex float cpow_ui(_Complex float x, integer n) {
310         _Complex float pow=1.0; unsigned long int u;
311         if(n != 0) {
312                 if(n < 0) n = -n, x = 1/x;
313                 for(u = n; ; ) {
314                         if(u & 01) pow *= x;
315                         if(u >>= 1) x *= x;
316                         else break;
317                 }
318         }
319         return pow;
320 }
321 #endif
322 #ifdef _MSC_VER
323 static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
324         _Dcomplex pow={1.0,0.0}; unsigned long int u;
325         if(n != 0) {
326                 if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
327                 for(u = n; ; ) {
328                         if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
329                         if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
330                         else break;
331                 }
332         }
333         _Dcomplex p = {pow._Val[0], pow._Val[1]};
334         return p;
335 }
336 #else
337 static _Complex double zpow_ui(_Complex double x, integer n) {
338         _Complex double pow=1.0; unsigned long int u;
339         if(n != 0) {
340                 if(n < 0) n = -n, x = 1/x;
341                 for(u = n; ; ) {
342                         if(u & 01) pow *= x;
343                         if(u >>= 1) x *= x;
344                         else break;
345                 }
346         }
347         return pow;
348 }
349 #endif
350 static integer pow_ii(integer x, integer n) {
351         integer pow; unsigned long int u;
352         if (n <= 0) {
353                 if (n == 0 || x == 1) pow = 1;
354                 else if (x != -1) pow = x == 0 ? 1/x : 0;
355                 else n = -n;
356         }
357         if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
358                 u = n;
359                 for(pow = 1; ; ) {
360                         if(u & 01) pow *= x;
361                         if(u >>= 1) x *= x;
362                         else break;
363                 }
364         }
365         return pow;
366 }
367 static integer dmaxloc_(double *w, integer s, integer e, integer *n)
368 {
369         double m; integer i, mi;
370         for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
371                 if (w[i-1]>m) mi=i ,m=w[i-1];
372         return mi-s+1;
373 }
374 static integer smaxloc_(float *w, integer s, integer e, integer *n)
375 {
376         float m; integer i, mi;
377         for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
378                 if (w[i-1]>m) mi=i ,m=w[i-1];
379         return mi-s+1;
380 }
381 static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
382         integer n = *n_, incx = *incx_, incy = *incy_, i;
383 #ifdef _MSC_VER
384         _Fcomplex zdotc = {0.0, 0.0};
385         if (incx == 1 && incy == 1) {
386                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
387                         zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
388                         zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
389                 }
390         } else {
391                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
392                         zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
393                         zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
394                 }
395         }
396         pCf(z) = zdotc;
397 }
398 #else
399         _Complex float zdotc = 0.0;
400         if (incx == 1 && incy == 1) {
401                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
402                         zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
403                 }
404         } else {
405                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
406                         zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
407                 }
408         }
409         pCf(z) = zdotc;
410 }
411 #endif
412 static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
413         integer n = *n_, incx = *incx_, incy = *incy_, i;
414 #ifdef _MSC_VER
415         _Dcomplex zdotc = {0.0, 0.0};
416         if (incx == 1 && incy == 1) {
417                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
418                         zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
419                         zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
420                 }
421         } else {
422                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
423                         zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
424                         zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
425                 }
426         }
427         pCd(z) = zdotc;
428 }
429 #else
430         _Complex double zdotc = 0.0;
431         if (incx == 1 && incy == 1) {
432                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
433                         zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
434                 }
435         } else {
436                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
437                         zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
438                 }
439         }
440         pCd(z) = zdotc;
441 }
442 #endif  
443 static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
444         integer n = *n_, incx = *incx_, incy = *incy_, i;
445 #ifdef _MSC_VER
446         _Fcomplex zdotc = {0.0, 0.0};
447         if (incx == 1 && incy == 1) {
448                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
449                         zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
450                         zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
451                 }
452         } else {
453                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
454                         zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
455                         zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
456                 }
457         }
458         pCf(z) = zdotc;
459 }
460 #else
461         _Complex float zdotc = 0.0;
462         if (incx == 1 && incy == 1) {
463                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
464                         zdotc += Cf(&x[i]) * Cf(&y[i]);
465                 }
466         } else {
467                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
468                         zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
469                 }
470         }
471         pCf(z) = zdotc;
472 }
473 #endif
474 static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
475         integer n = *n_, incx = *incx_, incy = *incy_, i;
476 #ifdef _MSC_VER
477         _Dcomplex zdotc = {0.0, 0.0};
478         if (incx == 1 && incy == 1) {
479                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
480                         zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
481                         zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
482                 }
483         } else {
484                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
485                         zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
486                         zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
487                 }
488         }
489         pCd(z) = zdotc;
490 }
491 #else
492         _Complex double zdotc = 0.0;
493         if (incx == 1 && incy == 1) {
494                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
495                         zdotc += Cd(&x[i]) * Cd(&y[i]);
496                 }
497         } else {
498                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
499                         zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
500                 }
501         }
502         pCd(z) = zdotc;
503 }
504 #endif
505 /*  -- translated by f2c (version 20000121).
506    You must link the resulting object file with the libraries:
507         -lf2c -lm   (in that order)
508 */
509
510
511
512
513 /* Table of constant values */
514
515 static real c_b7 = 0.f;
516 static real c_b8 = 1.f;
517 static integer c__2 = 2;
518 static integer c__1 = 1;
519 static integer c__3 = 3;
520
521 /* > \brief \b SLAQR5 performs a single small-bulge multi-shift QR sweep. */
522
523 /*  =========== DOCUMENTATION =========== */
524
525 /* Online html documentation available at */
526 /*            http://www.netlib.org/lapack/explore-html/ */
527
528 /* > \htmlonly */
529 /* > Download SLAQR5 + dependencies */
530 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slaqr5.
531 f"> */
532 /* > [TGZ]</a> */
533 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slaqr5.
534 f"> */
535 /* > [ZIP]</a> */
536 /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slaqr5.
537 f"> */
538 /* > [TXT]</a> */
539 /* > \endhtmlonly */
540
541 /*  Definition: */
542 /*  =========== */
543
544 /*       SUBROUTINE SLAQR5( WANTT, WANTZ, KACC22, N, KTOP, KBOT, NSHFTS, */
545 /*                          SR, SI, H, LDH, ILOZ, IHIZ, Z, LDZ, V, LDV, U, */
546 /*                          LDU, NV, WV, LDWV, NH, WH, LDWH ) */
547
548 /*       INTEGER            IHIZ, ILOZ, KACC22, KBOT, KTOP, LDH, LDU, LDV, */
549 /*      $                   LDWH, LDWV, LDZ, N, NH, NSHFTS, NV */
550 /*       LOGICAL            WANTT, WANTZ */
551 /*       REAL               H( LDH, * ), SI( * ), SR( * ), U( LDU, * ), */
552 /*      $                   V( LDV, * ), WH( LDWH, * ), WV( LDWV, * ), */
553 /*      $                   Z( LDZ, * ) */
554
555
556 /* > \par Purpose: */
557 /*  ============= */
558 /* > */
559 /* > \verbatim */
560 /* > */
561 /* >    SLAQR5, called by SLAQR0, performs a */
562 /* >    single small-bulge multi-shift QR sweep. */
563 /* > \endverbatim */
564
565 /*  Arguments: */
566 /*  ========== */
567
568 /* > \param[in] WANTT */
569 /* > \verbatim */
570 /* >          WANTT is LOGICAL */
571 /* >             WANTT = .true. if the quasi-triangular Schur factor */
572 /* >             is being computed.  WANTT is set to .false. otherwise. */
573 /* > \endverbatim */
574 /* > */
575 /* > \param[in] WANTZ */
576 /* > \verbatim */
577 /* >          WANTZ is LOGICAL */
578 /* >             WANTZ = .true. if the orthogonal Schur factor is being */
579 /* >             computed.  WANTZ is set to .false. otherwise. */
580 /* > \endverbatim */
581 /* > */
582 /* > \param[in] KACC22 */
583 /* > \verbatim */
584 /* >          KACC22 is INTEGER with value 0, 1, or 2. */
585 /* >             Specifies the computation mode of far-from-diagonal */
586 /* >             orthogonal updates. */
587 /* >        = 0: SLAQR5 does not accumulate reflections and does not */
588 /* >             use matrix-matrix multiply to update far-from-diagonal */
589 /* >             matrix entries. */
590 /* >        = 1: SLAQR5 accumulates reflections and uses matrix-matrix */
591 /* >             multiply to update the far-from-diagonal matrix entries. */
592 /* >        = 2: Same as KACC22 = 1. This option used to enable exploiting */
593 /* >             the 2-by-2 structure during matrix multiplications, but */
594 /* >             this is no longer supported. */
595 /* > \endverbatim */
596 /* > */
597 /* > \param[in] N */
598 /* > \verbatim */
599 /* >          N is INTEGER */
600 /* >             N is the order of the Hessenberg matrix H upon which this */
601 /* >             subroutine operates. */
602 /* > \endverbatim */
603 /* > */
604 /* > \param[in] KTOP */
605 /* > \verbatim */
606 /* >          KTOP is INTEGER */
607 /* > \endverbatim */
608 /* > */
609 /* > \param[in] KBOT */
610 /* > \verbatim */
611 /* >          KBOT is INTEGER */
612 /* >             These are the first and last rows and columns of an */
613 /* >             isolated diagonal block upon which the QR sweep is to be */
614 /* >             applied. It is assumed without a check that */
615 /* >                       either KTOP = 1  or   H(KTOP,KTOP-1) = 0 */
616 /* >             and */
617 /* >                       either KBOT = N  or   H(KBOT+1,KBOT) = 0. */
618 /* > \endverbatim */
619 /* > */
620 /* > \param[in] NSHFTS */
621 /* > \verbatim */
622 /* >          NSHFTS is INTEGER */
623 /* >             NSHFTS gives the number of simultaneous shifts.  NSHFTS */
624 /* >             must be positive and even. */
625 /* > \endverbatim */
626 /* > */
627 /* > \param[in,out] SR */
628 /* > \verbatim */
629 /* >          SR is REAL array, dimension (NSHFTS) */
630 /* > \endverbatim */
631 /* > */
632 /* > \param[in,out] SI */
633 /* > \verbatim */
634 /* >          SI is REAL array, dimension (NSHFTS) */
635 /* >             SR contains the real parts and SI contains the imaginary */
636 /* >             parts of the NSHFTS shifts of origin that define the */
637 /* >             multi-shift QR sweep.  On output SR and SI may be */
638 /* >             reordered. */
639 /* > \endverbatim */
640 /* > */
641 /* > \param[in,out] H */
642 /* > \verbatim */
643 /* >          H is REAL array, dimension (LDH,N) */
644 /* >             On input H contains a Hessenberg matrix.  On output a */
645 /* >             multi-shift QR sweep with shifts SR(J)+i*SI(J) is applied */
646 /* >             to the isolated diagonal block in rows and columns KTOP */
647 /* >             through KBOT. */
648 /* > \endverbatim */
649 /* > */
650 /* > \param[in] LDH */
651 /* > \verbatim */
652 /* >          LDH is INTEGER */
653 /* >             LDH is the leading dimension of H just as declared in the */
654 /* >             calling procedure.  LDH >= MAX(1,N). */
655 /* > \endverbatim */
656 /* > */
657 /* > \param[in] ILOZ */
658 /* > \verbatim */
659 /* >          ILOZ is INTEGER */
660 /* > \endverbatim */
661 /* > */
662 /* > \param[in] IHIZ */
663 /* > \verbatim */
664 /* >          IHIZ is INTEGER */
665 /* >             Specify the rows of Z to which transformations must be */
666 /* >             applied if WANTZ is .TRUE.. 1 <= ILOZ <= IHIZ <= N */
667 /* > \endverbatim */
668 /* > */
669 /* > \param[in,out] Z */
670 /* > \verbatim */
671 /* >          Z is REAL array, dimension (LDZ,IHIZ) */
672 /* >             If WANTZ = .TRUE., then the QR Sweep orthogonal */
673 /* >             similarity transformation is accumulated into */
674 /* >             Z(ILOZ:IHIZ,ILOZ:IHIZ) from the right. */
675 /* >             If WANTZ = .FALSE., then Z is unreferenced. */
676 /* > \endverbatim */
677 /* > */
678 /* > \param[in] LDZ */
679 /* > \verbatim */
680 /* >          LDZ is INTEGER */
681 /* >             LDA is the leading dimension of Z just as declared in */
682 /* >             the calling procedure. LDZ >= N. */
683 /* > \endverbatim */
684 /* > */
685 /* > \param[out] V */
686 /* > \verbatim */
687 /* >          V is REAL array, dimension (LDV,NSHFTS/2) */
688 /* > \endverbatim */
689 /* > */
690 /* > \param[in] LDV */
691 /* > \verbatim */
692 /* >          LDV is INTEGER */
693 /* >             LDV is the leading dimension of V as declared in the */
694 /* >             calling procedure.  LDV >= 3. */
695 /* > \endverbatim */
696 /* > */
697 /* > \param[out] U */
698 /* > \verbatim */
699 /* >          U is REAL array, dimension (LDU,2*NSHFTS) */
700 /* > \endverbatim */
701 /* > */
702 /* > \param[in] LDU */
703 /* > \verbatim */
704 /* >          LDU is INTEGER */
705 /* >             LDU is the leading dimension of U just as declared in the */
706 /* >             in the calling subroutine.  LDU >= 2*NSHFTS. */
707 /* > \endverbatim */
708 /* > */
709 /* > \param[in] NV */
710 /* > \verbatim */
711 /* >          NV is INTEGER */
712 /* >             NV is the number of rows in WV agailable for workspace. */
713 /* >             NV >= 1. */
714 /* > \endverbatim */
715 /* > */
716 /* > \param[out] WV */
717 /* > \verbatim */
718 /* >          WV is REAL array, dimension (LDWV,2*NSHFTS) */
719 /* > \endverbatim */
720 /* > */
721 /* > \param[in] LDWV */
722 /* > \verbatim */
723 /* >          LDWV is INTEGER */
724 /* >             LDWV is the leading dimension of WV as declared in the */
725 /* >             in the calling subroutine.  LDWV >= NV. */
726 /* > \endverbatim */
727
728 /* > \param[in] NH */
729 /* > \verbatim */
730 /* >          NH is INTEGER */
731 /* >             NH is the number of columns in array WH available for */
732 /* >             workspace. NH >= 1. */
733 /* > \endverbatim */
734 /* > */
735 /* > \param[out] WH */
736 /* > \verbatim */
737 /* >          WH is REAL array, dimension (LDWH,NH) */
738 /* > \endverbatim */
739 /* > */
740 /* > \param[in] LDWH */
741 /* > \verbatim */
742 /* >          LDWH is INTEGER */
743 /* >             Leading dimension of WH just as declared in the */
744 /* >             calling procedure.  LDWH >= 2*NSHFTS. */
745 /* > \endverbatim */
746 /* > */
747 /*  Authors: */
748 /*  ======== */
749
750 /* > \author Univ. of Tennessee */
751 /* > \author Univ. of California Berkeley */
752 /* > \author Univ. of Colorado Denver */
753 /* > \author NAG Ltd. */
754
755 /* > \date January 2021 */
756
757 /* > \ingroup realOTHERauxiliary */
758
759 /* > \par Contributors: */
760 /*  ================== */
761 /* > */
762 /* >       Karen Braman and Ralph Byers, Department of Mathematics, */
763 /* >       University of Kansas, USA */
764 /* > */
765 /* >       Lars Karlsson, Daniel Kressner, and Bruno Lang */
766 /* > */
767 /* >       Thijs Steel, Department of Computer science, */
768 /* >       KU Leuven, Belgium */
769
770 /* > \par References: */
771 /*  ================ */
772 /* > */
773 /* >       K. Braman, R. Byers and R. Mathias, The Multi-Shift QR */
774 /* >       Algorithm Part I: Maintaining Well Focused Shifts, and Level 3 */
775 /* >       Performance, SIAM Journal of Matrix Analysis, volume 23, pages */
776 /* >       929--947, 2002. */
777 /* > */
778 /* >       Lars Karlsson, Daniel Kressner, and Bruno Lang, Optimally packed */
779 /* >       chains of bulges in multishift QR algorithms. */
780 /* >       ACM Trans. Math. Softw. 40, 2, Article 12 (February 2014). */
781 /* > */
782 /*  ===================================================================== */
783 /* Subroutine */ int slaqr5_(logical *wantt, logical *wantz, integer *kacc22, 
784         integer *n, integer *ktop, integer *kbot, integer *nshfts, real *sr, 
785         real *si, real *h__, integer *ldh, integer *iloz, integer *ihiz, real 
786         *z__, integer *ldz, real *v, integer *ldv, real *u, integer *ldu, 
787         integer *nv, real *wv, integer *ldwv, integer *nh, real *wh, integer *
788         ldwh)
789 {
790     /* System generated locals */
791     integer h_dim1, h_offset, u_dim1, u_offset, v_dim1, v_offset, wh_dim1, 
792             wh_offset, wv_dim1, wv_offset, z_dim1, z_offset, i__1, i__2, i__3,
793              i__4, i__5, i__6, i__7;
794     real r__1, r__2, r__3, r__4, r__5;
795
796     /* Local variables */
797     real beta;
798     logical bmp22;
799     integer jcol, jlen, jbot, mbot;
800     real swap;
801     integer jtop, jrow, mtop, i__, j, k, m;
802     real alpha;
803     logical accum;
804     integer ndcol, incol;
805     extern /* Subroutine */ int sgemm_(char *, char *, integer *, integer *, 
806             integer *, real *, real *, integer *, real *, integer *, real *, 
807             real *, integer *);
808     integer krcol, nbmps, i2, k1, i4;
809     extern /* Subroutine */ int slaqr1_(integer *, real *, integer *, real *, 
810             real *, real *, real *, real *);
811     real h11, h12, h21, h22;
812     integer m22;
813     extern /* Subroutine */ int slabad_(real *, real *);
814     integer ns, nu;
815     extern real slamch_(char *);
816     real vt[3], safmin, safmax;
817     extern /* Subroutine */ int slarfg_(integer *, real *, real *, integer *, 
818             real *), slacpy_(char *, integer *, integer *, real *, integer *, 
819             real *, integer *), slaset_(char *, integer *, integer *, 
820             real *, real *, real *, integer *);
821     real refsum, smlnum, scl;
822     integer kdu, kms;
823     real ulp, tst1, tst2;
824
825
826 /*  -- LAPACK auxiliary routine (version 3.7.1) -- */
827 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
828 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
829 /*     June 2016 */
830
831
832 /*  ================================================================ */
833
834
835 /*     ==== If there are no shifts, then there is nothing to do. ==== */
836
837     /* Parameter adjustments */
838     --sr;
839     --si;
840     h_dim1 = *ldh;
841     h_offset = 1 + h_dim1 * 1;
842     h__ -= h_offset;
843     z_dim1 = *ldz;
844     z_offset = 1 + z_dim1 * 1;
845     z__ -= z_offset;
846     v_dim1 = *ldv;
847     v_offset = 1 + v_dim1 * 1;
848     v -= v_offset;
849     u_dim1 = *ldu;
850     u_offset = 1 + u_dim1 * 1;
851     u -= u_offset;
852     wv_dim1 = *ldwv;
853     wv_offset = 1 + wv_dim1 * 1;
854     wv -= wv_offset;
855     wh_dim1 = *ldwh;
856     wh_offset = 1 + wh_dim1 * 1;
857     wh -= wh_offset;
858
859     /* Function Body */
860     if (*nshfts < 2) {
861         return 0;
862     }
863
864 /*     ==== If the active block is empty or 1-by-1, then there */
865 /*     .    is nothing to do. ==== */
866
867     if (*ktop >= *kbot) {
868         return 0;
869     }
870
871 /*     ==== Shuffle shifts into pairs of real shifts and pairs */
872 /*     .    of complex conjugate shifts assuming complex */
873 /*     .    conjugate shifts are already adjacent to one */
874 /*     .    another. ==== */
875
876     i__1 = *nshfts - 2;
877     for (i__ = 1; i__ <= i__1; i__ += 2) {
878         if (si[i__] != -si[i__ + 1]) {
879
880             swap = sr[i__];
881             sr[i__] = sr[i__ + 1];
882             sr[i__ + 1] = sr[i__ + 2];
883             sr[i__ + 2] = swap;
884
885             swap = si[i__];
886             si[i__] = si[i__ + 1];
887             si[i__ + 1] = si[i__ + 2];
888             si[i__ + 2] = swap;
889         }
890 /* L10: */
891     }
892
893 /*     ==== NSHFTS is supposed to be even, but if it is odd, */
894 /*     .    then simply reduce it by one.  The shuffle above */
895 /*     .    ensures that the dropped shift is real and that */
896 /*     .    the remaining shifts are paired. ==== */
897
898     ns = *nshfts - *nshfts % 2;
899
900 /*     ==== Machine constants for deflation ==== */
901
902     safmin = slamch_("SAFE MINIMUM");
903     safmax = 1.f / safmin;
904     slabad_(&safmin, &safmax);
905     ulp = slamch_("PRECISION");
906     smlnum = safmin * ((real) (*n) / ulp);
907
908 /*     ==== Use accumulated reflections to update far-from-diagonal */
909 /*     .    entries ? ==== */
910
911     accum = *kacc22 == 1 || *kacc22 == 2;
912
913 /*     ==== clear trash ==== */
914
915     if (*ktop + 2 <= *kbot) {
916         h__[*ktop + 2 + *ktop * h_dim1] = 0.f;
917     }
918
919 /*     ==== NBMPS = number of 2-shift bulges in the chain ==== */
920
921     nbmps = ns / 2;
922
923 /*     ==== KDU = width of slab ==== */
924
925     kdu = nbmps << 2;
926
927 /*     ==== Create and chase chains of NBMPS bulges ==== */
928
929     i__1 = *kbot - 2;
930     i__2 = nbmps << 1;
931     for (incol = *ktop - (nbmps << 1) + 1; i__2 < 0 ? incol >= i__1 : incol <=
932              i__1; incol += i__2) {
933
934 /*        JTOP = Index from which updates from the right start. */
935
936         if (accum) {
937             jtop = f2cmax(*ktop,incol);
938         } else if (*wantt) {
939             jtop = 1;
940         } else {
941             jtop = *ktop;
942         }
943
944         ndcol = incol + kdu;
945         if (accum) {
946             slaset_("ALL", &kdu, &kdu, &c_b7, &c_b8, &u[u_offset], ldu);
947         }
948
949 /*        ==== Near-the-diagonal bulge chase.  The following loop */
950 /*        .    performs the near-the-diagonal part of a small bulge */
951 /*        .    multi-shift QR sweep.  Each 4*NBMPS column diagonal */
952 /*        .    chunk extends from column INCOL to column NDCOL */
953 /*        .    (including both column INCOL and column NDCOL). The */
954 /*        .    following loop chases a 2*NBMPS+1 column long chain of */
955 /*        .    NBMPS bulges 2*NBMPS-1 columns to the right.  (INCOL */
956 /*        .    may be less than KTOP and and NDCOL may be greater than */
957 /*        .    KBOT indicating phantom columns from which to chase */
958 /*        .    bulges before they are actually introduced or to which */
959 /*        .    to chase bulges beyond column KBOT.)  ==== */
960
961 /* Computing MIN */
962         i__4 = incol + (nbmps << 1) - 1, i__5 = *kbot - 2;
963         i__3 = f2cmin(i__4,i__5);
964         for (krcol = incol; krcol <= i__3; ++krcol) {
965
966 /*           ==== Bulges number MTOP to MBOT are active double implicit */
967 /*           .    shift bulges.  There may or may not also be small */
968 /*           .    2-by-2 bulge, if there is room.  The inactive bulges */
969 /*           .    (if any) must wait until the active bulges have moved */
970 /*           .    down the diagonal to make room.  The phantom matrix */
971 /*           .    paradigm described above helps keep track.  ==== */
972
973 /* Computing MAX */
974             i__4 = 1, i__5 = (*ktop - krcol) / 2 + 1;
975             mtop = f2cmax(i__4,i__5);
976 /* Computing MIN */
977             i__4 = nbmps, i__5 = (*kbot - krcol - 1) / 2;
978             mbot = f2cmin(i__4,i__5);
979             m22 = mbot + 1;
980             bmp22 = mbot < nbmps && krcol + (m22 - 1 << 1) == *kbot - 2;
981
982 /*           ==== Generate reflections to chase the chain right */
983 /*           .    one column.  (The minimum value of K is KTOP-1.) ==== */
984
985             if (bmp22) {
986
987 /*              ==== Special case: 2-by-2 reflection at bottom treated */
988 /*              .    separately ==== */
989
990                 k = krcol + (m22 - 1 << 1);
991                 if (k == *ktop - 1) {
992                     slaqr1_(&c__2, &h__[k + 1 + (k + 1) * h_dim1], ldh, &sr[(
993                             m22 << 1) - 1], &si[(m22 << 1) - 1], &sr[m22 * 2],
994                              &si[m22 * 2], &v[m22 * v_dim1 + 1]);
995                     beta = v[m22 * v_dim1 + 1];
996                     slarfg_(&c__2, &beta, &v[m22 * v_dim1 + 2], &c__1, &v[m22 
997                             * v_dim1 + 1]);
998                 } else {
999                     beta = h__[k + 1 + k * h_dim1];
1000                     v[m22 * v_dim1 + 2] = h__[k + 2 + k * h_dim1];
1001                     slarfg_(&c__2, &beta, &v[m22 * v_dim1 + 2], &c__1, &v[m22 
1002                             * v_dim1 + 1]);
1003                     h__[k + 1 + k * h_dim1] = beta;
1004                     h__[k + 2 + k * h_dim1] = 0.f;
1005                 }
1006
1007 /*              ==== Perform update from right within */
1008 /*              .    computational window. ==== */
1009
1010 /* Computing MIN */
1011                 i__5 = *kbot, i__6 = k + 3;
1012                 i__4 = f2cmin(i__5,i__6);
1013                 for (j = jtop; j <= i__4; ++j) {
1014                     refsum = v[m22 * v_dim1 + 1] * (h__[j + (k + 1) * h_dim1] 
1015                             + v[m22 * v_dim1 + 2] * h__[j + (k + 2) * h_dim1])
1016                             ;
1017                     h__[j + (k + 1) * h_dim1] -= refsum;
1018                     h__[j + (k + 2) * h_dim1] -= refsum * v[m22 * v_dim1 + 2];
1019 /* L30: */
1020                 }
1021
1022 /*              ==== Perform update from left within */
1023 /*              .    computational window. ==== */
1024
1025                 if (accum) {
1026                     jbot = f2cmin(ndcol,*kbot);
1027                 } else if (*wantt) {
1028                     jbot = *n;
1029                 } else {
1030                     jbot = *kbot;
1031                 }
1032                 i__4 = jbot;
1033                 for (j = k + 1; j <= i__4; ++j) {
1034                     refsum = v[m22 * v_dim1 + 1] * (h__[k + 1 + j * h_dim1] + 
1035                             v[m22 * v_dim1 + 2] * h__[k + 2 + j * h_dim1]);
1036                     h__[k + 1 + j * h_dim1] -= refsum;
1037                     h__[k + 2 + j * h_dim1] -= refsum * v[m22 * v_dim1 + 2];
1038 /* L40: */
1039                 }
1040
1041 /*              ==== The following convergence test requires that */
1042 /*              .    the tradition small-compared-to-nearby-diagonals */
1043 /*              .    criterion and the Ahues & Tisseur (LAWN 122, 1997) */
1044 /*              .    criteria both be satisfied.  The latter improves */
1045 /*              .    accuracy in some examples. Falling back on an */
1046 /*              .    alternate convergence criterion when TST1 or TST2 */
1047 /*              .    is zero (as done here) is traditional but probably */
1048 /*              .    unnecessary. ==== */
1049
1050                 if (k >= *ktop) {
1051                     if (h__[k + 1 + k * h_dim1] != 0.f) {
1052                         tst1 = (r__1 = h__[k + k * h_dim1], abs(r__1)) + (
1053                                 r__2 = h__[k + 1 + (k + 1) * h_dim1], abs(
1054                                 r__2));
1055                         if (tst1 == 0.f) {
1056                             if (k >= *ktop + 1) {
1057                                 tst1 += (r__1 = h__[k + (k - 1) * h_dim1], 
1058                                         abs(r__1));
1059                             }
1060                             if (k >= *ktop + 2) {
1061                                 tst1 += (r__1 = h__[k + (k - 2) * h_dim1], 
1062                                         abs(r__1));
1063                             }
1064                             if (k >= *ktop + 3) {
1065                                 tst1 += (r__1 = h__[k + (k - 3) * h_dim1], 
1066                                         abs(r__1));
1067                             }
1068                             if (k <= *kbot - 2) {
1069                                 tst1 += (r__1 = h__[k + 2 + (k + 1) * h_dim1],
1070                                          abs(r__1));
1071                             }
1072                             if (k <= *kbot - 3) {
1073                                 tst1 += (r__1 = h__[k + 3 + (k + 1) * h_dim1],
1074                                          abs(r__1));
1075                             }
1076                             if (k <= *kbot - 4) {
1077                                 tst1 += (r__1 = h__[k + 4 + (k + 1) * h_dim1],
1078                                          abs(r__1));
1079                             }
1080                         }
1081 /* Computing MAX */
1082                         r__2 = smlnum, r__3 = ulp * tst1;
1083                         if ((r__1 = h__[k + 1 + k * h_dim1], abs(r__1)) <= 
1084                                 f2cmax(r__2,r__3)) {
1085 /* Computing MAX */
1086                             r__3 = (r__1 = h__[k + 1 + k * h_dim1], abs(r__1))
1087                                     , r__4 = (r__2 = h__[k + (k + 1) * h_dim1]
1088                                     , abs(r__2));
1089                             h12 = f2cmax(r__3,r__4);
1090 /* Computing MIN */
1091                             r__3 = (r__1 = h__[k + 1 + k * h_dim1], abs(r__1))
1092                                     , r__4 = (r__2 = h__[k + (k + 1) * h_dim1]
1093                                     , abs(r__2));
1094                             h21 = f2cmin(r__3,r__4);
1095 /* Computing MAX */
1096                             r__3 = (r__1 = h__[k + 1 + (k + 1) * h_dim1], abs(
1097                                     r__1)), r__4 = (r__2 = h__[k + k * h_dim1]
1098                                      - h__[k + 1 + (k + 1) * h_dim1], abs(
1099                                     r__2));
1100                             h11 = f2cmax(r__3,r__4);
1101 /* Computing MIN */
1102                             r__3 = (r__1 = h__[k + 1 + (k + 1) * h_dim1], abs(
1103                                     r__1)), r__4 = (r__2 = h__[k + k * h_dim1]
1104                                      - h__[k + 1 + (k + 1) * h_dim1], abs(
1105                                     r__2));
1106                             h22 = f2cmin(r__3,r__4);
1107                             scl = h11 + h12;
1108                             tst2 = h22 * (h11 / scl);
1109
1110 /* Computing MAX */
1111                             r__1 = smlnum, r__2 = ulp * tst2;
1112                             if (tst2 == 0.f || h21 * (h12 / scl) <= f2cmax(r__1,
1113                                     r__2)) {
1114                                 h__[k + 1 + k * h_dim1] = 0.f;
1115                             }
1116                         }
1117                     }
1118                 }
1119
1120 /*              ==== Accumulate orthogonal transformations. ==== */
1121
1122                 if (accum) {
1123                     kms = k - incol;
1124 /* Computing MAX */
1125                     i__4 = 1, i__5 = *ktop - incol;
1126                     i__6 = kdu;
1127                     for (j = f2cmax(i__4,i__5); j <= i__6; ++j) {
1128                         refsum = v[m22 * v_dim1 + 1] * (u[j + (kms + 1) * 
1129                                 u_dim1] + v[m22 * v_dim1 + 2] * u[j + (kms + 
1130                                 2) * u_dim1]);
1131                         u[j + (kms + 1) * u_dim1] -= refsum;
1132                         u[j + (kms + 2) * u_dim1] -= refsum * v[m22 * v_dim1 
1133                                 + 2];
1134 /* L50: */
1135                     }
1136                 } else if (*wantz) {
1137                     i__6 = *ihiz;
1138                     for (j = *iloz; j <= i__6; ++j) {
1139                         refsum = v[m22 * v_dim1 + 1] * (z__[j + (k + 1) * 
1140                                 z_dim1] + v[m22 * v_dim1 + 2] * z__[j + (k + 
1141                                 2) * z_dim1]);
1142                         z__[j + (k + 1) * z_dim1] -= refsum;
1143                         z__[j + (k + 2) * z_dim1] -= refsum * v[m22 * v_dim1 
1144                                 + 2];
1145 /* L60: */
1146                     }
1147                 }
1148             }
1149
1150 /*           ==== Normal case: Chain of 3-by-3 reflections ==== */
1151
1152             i__6 = mtop;
1153             for (m = mbot; m >= i__6; --m) {
1154                 k = krcol + (m - 1 << 1);
1155                 if (k == *ktop - 1) {
1156                     slaqr1_(&c__3, &h__[*ktop + *ktop * h_dim1], ldh, &sr[(m 
1157                             << 1) - 1], &si[(m << 1) - 1], &sr[m * 2], &si[m *
1158                              2], &v[m * v_dim1 + 1]);
1159                     alpha = v[m * v_dim1 + 1];
1160                     slarfg_(&c__3, &alpha, &v[m * v_dim1 + 2], &c__1, &v[m * 
1161                             v_dim1 + 1]);
1162                 } else {
1163
1164 /*                 ==== Perform delayed transformation of row below */
1165 /*                 .    Mth bulge. Exploit fact that first two elements */
1166 /*                 .    of row are actually zero. ==== */
1167
1168                     refsum = v[m * v_dim1 + 1] * v[m * v_dim1 + 3] * h__[k + 
1169                             3 + (k + 2) * h_dim1];
1170                     h__[k + 3 + k * h_dim1] = -refsum;
1171                     h__[k + 3 + (k + 1) * h_dim1] = -refsum * v[m * v_dim1 + 
1172                             2];
1173                     h__[k + 3 + (k + 2) * h_dim1] -= refsum * v[m * v_dim1 + 
1174                             3];
1175
1176 /*                 ==== Calculate reflection to move */
1177 /*                 .    Mth bulge one step. ==== */
1178
1179                     beta = h__[k + 1 + k * h_dim1];
1180                     v[m * v_dim1 + 2] = h__[k + 2 + k * h_dim1];
1181                     v[m * v_dim1 + 3] = h__[k + 3 + k * h_dim1];
1182                     slarfg_(&c__3, &beta, &v[m * v_dim1 + 2], &c__1, &v[m * 
1183                             v_dim1 + 1]);
1184
1185 /*                 ==== A Bulge may collapse because of vigilant */
1186 /*                 .    deflation or destructive underflow.  In the */
1187 /*                 .    underflow case, try the two-small-subdiagonals */
1188 /*                 .    trick to try to reinflate the bulge.  ==== */
1189
1190                     if (h__[k + 3 + k * h_dim1] != 0.f || h__[k + 3 + (k + 1) 
1191                             * h_dim1] != 0.f || h__[k + 3 + (k + 2) * h_dim1] 
1192                             == 0.f) {
1193
1194 /*                    ==== Typical case: not collapsed (yet). ==== */
1195
1196                         h__[k + 1 + k * h_dim1] = beta;
1197                         h__[k + 2 + k * h_dim1] = 0.f;
1198                         h__[k + 3 + k * h_dim1] = 0.f;
1199                     } else {
1200
1201 /*                    ==== Atypical case: collapsed.  Attempt to */
1202 /*                    .    reintroduce ignoring H(K+1,K) and H(K+2,K). */
1203 /*                    .    If the fill resulting from the new */
1204 /*                    .    reflector is too large, then abandon it. */
1205 /*                    .    Otherwise, use the new one. ==== */
1206
1207                         slaqr1_(&c__3, &h__[k + 1 + (k + 1) * h_dim1], ldh, &
1208                                 sr[(m << 1) - 1], &si[(m << 1) - 1], &sr[m * 
1209                                 2], &si[m * 2], vt);
1210                         alpha = vt[0];
1211                         slarfg_(&c__3, &alpha, &vt[1], &c__1, vt);
1212                         refsum = vt[0] * (h__[k + 1 + k * h_dim1] + vt[1] * 
1213                                 h__[k + 2 + k * h_dim1]);
1214
1215                         if ((r__1 = h__[k + 2 + k * h_dim1] - refsum * vt[1], 
1216                                 abs(r__1)) + (r__2 = refsum * vt[2], abs(r__2)
1217                                 ) > ulp * ((r__3 = h__[k + k * h_dim1], abs(
1218                                 r__3)) + (r__4 = h__[k + 1 + (k + 1) * h_dim1]
1219                                 , abs(r__4)) + (r__5 = h__[k + 2 + (k + 2) * 
1220                                 h_dim1], abs(r__5)))) {
1221
1222 /*                       ==== Starting a new bulge here would */
1223 /*                       .    create non-negligible fill.  Use */
1224 /*                       .    the old one with trepidation. ==== */
1225
1226                             h__[k + 1 + k * h_dim1] = beta;
1227                             h__[k + 2 + k * h_dim1] = 0.f;
1228                             h__[k + 3 + k * h_dim1] = 0.f;
1229                         } else {
1230
1231 /*                       ==== Starting a new bulge here would */
1232 /*                       .    create only negligible fill. */
1233 /*                       .    Replace the old reflector with */
1234 /*                       .    the new one. ==== */
1235
1236                             h__[k + 1 + k * h_dim1] -= refsum;
1237                             h__[k + 2 + k * h_dim1] = 0.f;
1238                             h__[k + 3 + k * h_dim1] = 0.f;
1239                             v[m * v_dim1 + 1] = vt[0];
1240                             v[m * v_dim1 + 2] = vt[1];
1241                             v[m * v_dim1 + 3] = vt[2];
1242                         }
1243                     }
1244                 }
1245
1246 /*              ====  Apply reflection from the right and */
1247 /*              .     the first column of update from the left. */
1248 /*              .     These updates are required for the vigilant */
1249 /*              .     deflation check. We still delay most of the */
1250 /*              .     updates from the left for efficiency. ==== */
1251
1252 /* Computing MIN */
1253                 i__5 = *kbot, i__7 = k + 3;
1254                 i__4 = f2cmin(i__5,i__7);
1255                 for (j = jtop; j <= i__4; ++j) {
1256                     refsum = v[m * v_dim1 + 1] * (h__[j + (k + 1) * h_dim1] + 
1257                             v[m * v_dim1 + 2] * h__[j + (k + 2) * h_dim1] + v[
1258                             m * v_dim1 + 3] * h__[j + (k + 3) * h_dim1]);
1259                     h__[j + (k + 1) * h_dim1] -= refsum;
1260                     h__[j + (k + 2) * h_dim1] -= refsum * v[m * v_dim1 + 2];
1261                     h__[j + (k + 3) * h_dim1] -= refsum * v[m * v_dim1 + 3];
1262 /* L70: */
1263                 }
1264
1265 /*              ==== Perform update from left for subsequent */
1266 /*              .    column. ==== */
1267
1268                 refsum = v[m * v_dim1 + 1] * (h__[k + 1 + (k + 1) * h_dim1] + 
1269                         v[m * v_dim1 + 2] * h__[k + 2 + (k + 1) * h_dim1] + v[
1270                         m * v_dim1 + 3] * h__[k + 3 + (k + 1) * h_dim1]);
1271                 h__[k + 1 + (k + 1) * h_dim1] -= refsum;
1272                 h__[k + 2 + (k + 1) * h_dim1] -= refsum * v[m * v_dim1 + 2];
1273                 h__[k + 3 + (k + 1) * h_dim1] -= refsum * v[m * v_dim1 + 3];
1274
1275 /*              ==== The following convergence test requires that */
1276 /*              .    the tradition small-compared-to-nearby-diagonals */
1277 /*              .    criterion and the Ahues & Tisseur (LAWN 122, 1997) */
1278 /*              .    criteria both be satisfied.  The latter improves */
1279 /*              .    accuracy in some examples. Falling back on an */
1280 /*              .    alternate convergence criterion when TST1 or TST2 */
1281 /*              .    is zero (as done here) is traditional but probably */
1282 /*              .    unnecessary. ==== */
1283
1284                 if (k < *ktop) {
1285                     goto L880;
1286                 }
1287 /*     $              CALL MYCYCLE */
1288                 if (h__[k + 1 + k * h_dim1] != 0.f) {
1289                     tst1 = (r__1 = h__[k + k * h_dim1], abs(r__1)) + (r__2 = 
1290                             h__[k + 1 + (k + 1) * h_dim1], abs(r__2));
1291                     if (tst1 == 0.f) {
1292                         if (k >= *ktop + 1) {
1293                             tst1 += (r__1 = h__[k + (k - 1) * h_dim1], abs(
1294                                     r__1));
1295                         }
1296                         if (k >= *ktop + 2) {
1297                             tst1 += (r__1 = h__[k + (k - 2) * h_dim1], abs(
1298                                     r__1));
1299                         }
1300                         if (k >= *ktop + 3) {
1301                             tst1 += (r__1 = h__[k + (k - 3) * h_dim1], abs(
1302                                     r__1));
1303                         }
1304                         if (k <= *kbot - 2) {
1305                             tst1 += (r__1 = h__[k + 2 + (k + 1) * h_dim1], 
1306                                     abs(r__1));
1307                         }
1308                         if (k <= *kbot - 3) {
1309                             tst1 += (r__1 = h__[k + 3 + (k + 1) * h_dim1], 
1310                                     abs(r__1));
1311                         }
1312                         if (k <= *kbot - 4) {
1313                             tst1 += (r__1 = h__[k + 4 + (k + 1) * h_dim1], 
1314                                     abs(r__1));
1315                         }
1316                     }
1317 /* Computing MAX */
1318                     r__2 = smlnum, r__3 = ulp * tst1;
1319                     if ((r__1 = h__[k + 1 + k * h_dim1], abs(r__1)) <= f2cmax(
1320                             r__2,r__3)) {
1321 /* Computing MAX */
1322                         r__3 = (r__1 = h__[k + 1 + k * h_dim1], abs(r__1)), 
1323                                 r__4 = (r__2 = h__[k + (k + 1) * h_dim1], abs(
1324                                 r__2));
1325                         h12 = f2cmax(r__3,r__4);
1326 /* Computing MIN */
1327                         r__3 = (r__1 = h__[k + 1 + k * h_dim1], abs(r__1)), 
1328                                 r__4 = (r__2 = h__[k + (k + 1) * h_dim1], abs(
1329                                 r__2));
1330                         h21 = f2cmin(r__3,r__4);
1331 /* Computing MAX */
1332                         r__3 = (r__1 = h__[k + 1 + (k + 1) * h_dim1], abs(
1333                                 r__1)), r__4 = (r__2 = h__[k + k * h_dim1] - 
1334                                 h__[k + 1 + (k + 1) * h_dim1], abs(r__2));
1335                         h11 = f2cmax(r__3,r__4);
1336 /* Computing MIN */
1337                         r__3 = (r__1 = h__[k + 1 + (k + 1) * h_dim1], abs(
1338                                 r__1)), r__4 = (r__2 = h__[k + k * h_dim1] - 
1339                                 h__[k + 1 + (k + 1) * h_dim1], abs(r__2));
1340                         h22 = f2cmin(r__3,r__4);
1341                         scl = h11 + h12;
1342                         tst2 = h22 * (h11 / scl);
1343
1344 /* Computing MAX */
1345                         r__1 = smlnum, r__2 = ulp * tst2;
1346                         if (tst2 == 0.f || h21 * (h12 / scl) <= f2cmax(r__1,r__2)
1347                                 ) {
1348                             h__[k + 1 + k * h_dim1] = 0.f;
1349                         }
1350                     }
1351                 }
1352 L880:
1353 /* L80: */
1354                 ;
1355             }
1356
1357 /*           ==== Multiply H by reflections from the left ==== */
1358
1359             if (accum) {
1360                 jbot = f2cmin(ndcol,*kbot);
1361             } else if (*wantt) {
1362                 jbot = *n;
1363             } else {
1364                 jbot = *kbot;
1365             }
1366
1367             i__6 = mtop;
1368             for (m = mbot; m >= i__6; --m) {
1369                 k = krcol + (m - 1 << 1);
1370 /* Computing MAX */
1371                 i__4 = *ktop, i__5 = krcol + (m << 1);
1372                 i__7 = jbot;
1373                 for (j = f2cmax(i__4,i__5); j <= i__7; ++j) {
1374                     refsum = v[m * v_dim1 + 1] * (h__[k + 1 + j * h_dim1] + v[
1375                             m * v_dim1 + 2] * h__[k + 2 + j * h_dim1] + v[m * 
1376                             v_dim1 + 3] * h__[k + 3 + j * h_dim1]);
1377                     h__[k + 1 + j * h_dim1] -= refsum;
1378                     h__[k + 2 + j * h_dim1] -= refsum * v[m * v_dim1 + 2];
1379                     h__[k + 3 + j * h_dim1] -= refsum * v[m * v_dim1 + 3];
1380 /* L90: */
1381                 }
1382 /* L100: */
1383             }
1384
1385 /*           ==== Accumulate orthogonal transformations. ==== */
1386
1387             if (accum) {
1388
1389 /*              ==== Accumulate U. (If needed, update Z later */
1390 /*              .    with an efficient matrix-matrix */
1391 /*              .    multiply.) ==== */
1392
1393                 i__6 = mtop;
1394                 for (m = mbot; m >= i__6; --m) {
1395                     k = krcol + (m - 1 << 1);
1396                     kms = k - incol;
1397 /* Computing MAX */
1398                     i__7 = 1, i__4 = *ktop - incol;
1399                     i2 = f2cmax(i__7,i__4);
1400 /* Computing MAX */
1401                     i__7 = i2, i__4 = kms - (krcol - incol) + 1;
1402                     i2 = f2cmax(i__7,i__4);
1403 /* Computing MIN */
1404                     i__7 = kdu, i__4 = krcol + (mbot - 1 << 1) - incol + 5;
1405                     i4 = f2cmin(i__7,i__4);
1406                     i__7 = i4;
1407                     for (j = i2; j <= i__7; ++j) {
1408                         refsum = v[m * v_dim1 + 1] * (u[j + (kms + 1) * 
1409                                 u_dim1] + v[m * v_dim1 + 2] * u[j + (kms + 2) 
1410                                 * u_dim1] + v[m * v_dim1 + 3] * u[j + (kms + 
1411                                 3) * u_dim1]);
1412                         u[j + (kms + 1) * u_dim1] -= refsum;
1413                         u[j + (kms + 2) * u_dim1] -= refsum * v[m * v_dim1 + 
1414                                 2];
1415                         u[j + (kms + 3) * u_dim1] -= refsum * v[m * v_dim1 + 
1416                                 3];
1417 /* L110: */
1418                     }
1419 /* L120: */
1420                 }
1421             } else if (*wantz) {
1422
1423 /*              ==== U is not accumulated, so update Z */
1424 /*              .    now by multiplying by reflections */
1425 /*              .    from the right. ==== */
1426
1427                 i__6 = mtop;
1428                 for (m = mbot; m >= i__6; --m) {
1429                     k = krcol + (m - 1 << 1);
1430                     i__7 = *ihiz;
1431                     for (j = *iloz; j <= i__7; ++j) {
1432                         refsum = v[m * v_dim1 + 1] * (z__[j + (k + 1) * 
1433                                 z_dim1] + v[m * v_dim1 + 2] * z__[j + (k + 2) 
1434                                 * z_dim1] + v[m * v_dim1 + 3] * z__[j + (k + 
1435                                 3) * z_dim1]);
1436                         z__[j + (k + 1) * z_dim1] -= refsum;
1437                         z__[j + (k + 2) * z_dim1] -= refsum * v[m * v_dim1 + 
1438                                 2];
1439                         z__[j + (k + 3) * z_dim1] -= refsum * v[m * v_dim1 + 
1440                                 3];
1441 /* L130: */
1442                     }
1443 /* L140: */
1444                 }
1445             }
1446
1447 /*           ==== End of near-the-diagonal bulge chase. ==== */
1448
1449 /* L145: */
1450         }
1451
1452 /*        ==== Use U (if accumulated) to update far-from-diagonal */
1453 /*        .    entries in H.  If required, use U to update Z as */
1454 /*        .    well. ==== */
1455
1456         if (accum) {
1457             if (*wantt) {
1458                 jtop = 1;
1459                 jbot = *n;
1460             } else {
1461                 jtop = *ktop;
1462                 jbot = *kbot;
1463             }
1464 /* Computing MAX */
1465             i__3 = 1, i__6 = *ktop - incol;
1466             k1 = f2cmax(i__3,i__6);
1467 /* Computing MAX */
1468             i__3 = 0, i__6 = ndcol - *kbot;
1469             nu = kdu - f2cmax(i__3,i__6) - k1 + 1;
1470
1471 /*           ==== Horizontal Multiply ==== */
1472
1473             i__3 = jbot;
1474             i__6 = *nh;
1475             for (jcol = f2cmin(ndcol,*kbot) + 1; i__6 < 0 ? jcol >= i__3 : jcol 
1476                     <= i__3; jcol += i__6) {
1477 /* Computing MIN */
1478                 i__7 = *nh, i__4 = jbot - jcol + 1;
1479                 jlen = f2cmin(i__7,i__4);
1480                 sgemm_("C", "N", &nu, &jlen, &nu, &c_b8, &u[k1 + k1 * u_dim1],
1481                          ldu, &h__[incol + k1 + jcol * h_dim1], ldh, &c_b7, &
1482                         wh[wh_offset], ldwh);
1483                 slacpy_("ALL", &nu, &jlen, &wh[wh_offset], ldwh, &h__[incol + 
1484                         k1 + jcol * h_dim1], ldh);
1485 /* L150: */
1486             }
1487
1488 /*           ==== Vertical multiply ==== */
1489
1490             i__6 = f2cmax(*ktop,incol) - 1;
1491             i__3 = *nv;
1492             for (jrow = jtop; i__3 < 0 ? jrow >= i__6 : jrow <= i__6; jrow += 
1493                     i__3) {
1494 /* Computing MIN */
1495                 i__7 = *nv, i__4 = f2cmax(*ktop,incol) - jrow;
1496                 jlen = f2cmin(i__7,i__4);
1497                 sgemm_("N", "N", &jlen, &nu, &nu, &c_b8, &h__[jrow + (incol + 
1498                         k1) * h_dim1], ldh, &u[k1 + k1 * u_dim1], ldu, &c_b7, 
1499                         &wv[wv_offset], ldwv);
1500                 slacpy_("ALL", &jlen, &nu, &wv[wv_offset], ldwv, &h__[jrow + (
1501                         incol + k1) * h_dim1], ldh);
1502 /* L160: */
1503             }
1504
1505 /*           ==== Z multiply (also vertical) ==== */
1506
1507             if (*wantz) {
1508                 i__3 = *ihiz;
1509                 i__6 = *nv;
1510                 for (jrow = *iloz; i__6 < 0 ? jrow >= i__3 : jrow <= i__3; 
1511                         jrow += i__6) {
1512 /* Computing MIN */
1513                     i__7 = *nv, i__4 = *ihiz - jrow + 1;
1514                     jlen = f2cmin(i__7,i__4);
1515                     sgemm_("N", "N", &jlen, &nu, &nu, &c_b8, &z__[jrow + (
1516                             incol + k1) * z_dim1], ldz, &u[k1 + k1 * u_dim1], 
1517                             ldu, &c_b7, &wv[wv_offset], ldwv);
1518                     slacpy_("ALL", &jlen, &nu, &wv[wv_offset], ldwv, &z__[
1519                             jrow + (incol + k1) * z_dim1], ldz);
1520 /* L170: */
1521                 }
1522             }
1523         }
1524 /* L180: */
1525     }
1526
1527 /*     ==== End of SLAQR5 ==== */
1528
1529     return 0;
1530 } /* slaqr5_ */
1531