| 1 |
c { dg-do compile } |
| 2 |
c { dg-options "-std=legacy" } |
| 3 |
c |
| 4 |
c This demonstrates a problem with g77 and pic on x86 where |
| 5 |
c egcs 1.0.1 and earlier will generate bogus assembler output. |
| 6 |
c unfortunately, gas accepts the bogus acssembler output and |
| 7 |
c generates code that almost works. |
| 8 |
c |
| 9 |
|
| 10 |
|
| 11 |
C Date: Wed, 17 Dec 1997 23:20:29 +0000 |
| 12 |
C From: Joao Cardoso <[email protected]> |
| 13 |
C To: [email protected] |
| 14 |
C Subject: egcs-1.0 f77 bug on OSR5 |
| 15 |
C When trying to compile the Fortran file that I enclose bellow, |
| 16 |
C I got an assembler error: |
| 17 |
C |
| 18 |
C ./g77 -B./ -fpic -O -c scaleg.f |
| 19 |
C /usr/tmp/cca002D8.s:123:syntax error at ( |
| 20 |
C |
| 21 |
C ./g77 -B./ -fpic -O0 -c scaleg.f |
| 22 |
C /usr/tmp/cca002EW.s:246:invalid operand combination: leal |
| 23 |
C |
| 24 |
C Compiling without the -fpic flag runs OK. |
| 25 |
|
| 26 |
subroutine scaleg (n,ma,a,mb,b,low,igh,cscale,cperm,wk) |
| 27 |
c |
| 28 |
c *****parameters: |
| 29 |
integer igh,low,ma,mb,n |
| 30 |
double precision a(ma,n),b(mb,n),cperm(n),cscale(n),wk(n,6) |
| 31 |
c |
| 32 |
c *****local variables: |
| 33 |
integer i,ir,it,j,jc,kount,nr,nrp2 |
| 34 |
double precision alpha,basl,beta,cmax,coef,coef2,coef5,cor, |
| 35 |
* ew,ewc,fi,fj,gamma,pgamma,sum,t,ta,tb,tc |
| 36 |
c |
| 37 |
c *****fortran functions: |
| 38 |
double precision dabs, dlog10, dsign |
| 39 |
c float |
| 40 |
c |
| 41 |
c *****subroutines called: |
| 42 |
c none |
| 43 |
c |
| 44 |
c --------------------------------------------------------------- |
| 45 |
c |
| 46 |
c *****purpose: |
| 47 |
c scales the matrices a and b in the generalized eigenvalue |
| 48 |
c problem a*x = (lambda)*b*x such that the magnitudes of the |
| 49 |
c elements of the submatrices of a and b (as specified by low |
| 50 |
c and igh) are close to unity in the least squares sense. |
| 51 |
c ref.: ward, r. c., balancing the generalized eigenvalue |
| 52 |
c problem, siam j. sci. stat. comput., vol. 2, no. 2, june 1981, |
| 53 |
c 141-152. |
| 54 |
c |
| 55 |
c *****parameter description: |
| 56 |
c |
| 57 |
c on input: |
| 58 |
c |
| 59 |
c ma,mb integer |
| 60 |
c row dimensions of the arrays containing matrices |
| 61 |
c a and b respectively, as declared in the main calling |
| 62 |
c program dimension statement; |
| 63 |
c |
| 64 |
c n integer |
| 65 |
c order of the matrices a and b; |
| 66 |
c |
| 67 |
c a real(ma,n) |
| 68 |
c contains the a matrix of the generalized eigenproblem |
| 69 |
c defined above; |
| 70 |
c |
| 71 |
c b real(mb,n) |
| 72 |
c contains the b matrix of the generalized eigenproblem |
| 73 |
c defined above; |
| 74 |
c |
| 75 |
c low integer |
| 76 |
c specifies the beginning -1 for the rows and |
| 77 |
c columns of a and b to be scaled; |
| 78 |
c |
| 79 |
c igh integer |
| 80 |
c specifies the ending -1 for the rows and columns |
| 81 |
c of a and b to be scaled; |
| 82 |
c |
| 83 |
c cperm real(n) |
| 84 |
c work array. only locations low through igh are |
| 85 |
c referenced and altered by this subroutine; |
| 86 |
c |
| 87 |
c wk real(n,6) |
| 88 |
c work array that must contain at least 6*n locations. |
| 89 |
c only locations low through igh, n+low through n+igh, |
| 90 |
c ..., 5*n+low through 5*n+igh are referenced and |
| 91 |
c altered by this subroutine. |
| 92 |
c |
| 93 |
c on output: |
| 94 |
c |
| 95 |
c a,b contain the scaled a and b matrices; |
| 96 |
c |
| 97 |
c cscale real(n) |
| 98 |
c contains in its low through igh locations the integer |
| 99 |
c exponents of 2 used for the column scaling factors. |
| 100 |
c the other locations are not referenced; |
| 101 |
c |
| 102 |
c wk contains in its low through igh locations the integer |
| 103 |
c exponents of 2 used for the row scaling factors. |
| 104 |
c |
| 105 |
c *****algorithm notes: |
| 106 |
c none. |
| 107 |
c |
| 108 |
c *****history: |
| 109 |
c written by r. c. ward....... |
| 110 |
c modified 8/86 by bobby bodenheimer so that if |
| 111 |
c sum = 0 (corresponding to the case where the matrix |
| 112 |
c doesn't need to be scaled) the routine returns. |
| 113 |
c |
| 114 |
c --------------------------------------------------------------- |
| 115 |
c |
| 116 |
if (low .eq. igh) go to 410 |
| 117 |
do 210 i = low,igh |
| 118 |
wk(i,1) = 0.0d0 |
| 119 |
wk(i,2) = 0.0d0 |
| 120 |
wk(i,3) = 0.0d0 |
| 121 |
wk(i,4) = 0.0d0 |
| 122 |
wk(i,5) = 0.0d0 |
| 123 |
wk(i,6) = 0.0d0 |
| 124 |
cscale(i) = 0.0d0 |
| 125 |
cperm(i) = 0.0d0 |
| 126 |
210 continue |
| 127 |
c |
| 128 |
c compute right side vector in resulting linear equations |
| 129 |
c |
| 130 |
basl = dlog10(2.0d0) |
| 131 |
do 240 i = low,igh |
| 132 |
do 240 j = low,igh |
| 133 |
tb = b(i,j) |
| 134 |
ta = a(i,j) |
| 135 |
if (ta .eq. 0.0d0) go to 220 |
| 136 |
ta = dlog10(dabs(ta)) / basl |
| 137 |
220 continue |
| 138 |
if (tb .eq. 0.0d0) go to 230 |
| 139 |
tb = dlog10(dabs(tb)) / basl |
| 140 |
230 continue |
| 141 |
wk(i,5) = wk(i,5) - ta - tb |
| 142 |
wk(j,6) = wk(j,6) - ta - tb |
| 143 |
240 continue |
| 144 |
nr = igh-low+1 |
| 145 |
coef = 1.0d0/float(2*nr) |
| 146 |
coef2 = coef*coef |
| 147 |
coef5 = 0.5d0*coef2 |
| 148 |
nrp2 = nr+2 |
| 149 |
beta = 0.0d0 |
| 150 |
it = 1 |
| 151 |
c |
| 152 |
c start generalized conjugate gradient iteration |
| 153 |
c |
| 154 |
250 continue |
| 155 |
ew = 0.0d0 |
| 156 |
ewc = 0.0d0 |
| 157 |
gamma = 0.0d0 |
| 158 |
do 260 i = low,igh |
| 159 |
gamma = gamma + wk(i,5)*wk(i,5) + wk(i,6)*wk(i,6) |
| 160 |
ew = ew + wk(i,5) |
| 161 |
ewc = ewc + wk(i,6) |
| 162 |
260 continue |
| 163 |
gamma = coef*gamma - coef2*(ew**2 + ewc**2) |
| 164 |
+ - coef5*(ew - ewc)**2 |
| 165 |
if (it .ne. 1) beta = gamma / pgamma |
| 166 |
t = coef5*(ewc - 3.0d0*ew) |
| 167 |
tc = coef5*(ew - 3.0d0*ewc) |
| 168 |
do 270 i = low,igh |
| 169 |
wk(i,2) = beta*wk(i,2) + coef*wk(i,5) + t |
| 170 |
cperm(i) = beta*cperm(i) + coef*wk(i,6) + tc |
| 171 |
270 continue |
| 172 |
c |
| 173 |
c apply matrix to vector |
| 174 |
c |
| 175 |
do 300 i = low,igh |
| 176 |
kount = 0 |
| 177 |
sum = 0.0d0 |
| 178 |
do 290 j = low,igh |
| 179 |
if (a(i,j) .eq. 0.0d0) go to 280 |
| 180 |
kount = kount+1 |
| 181 |
sum = sum + cperm(j) |
| 182 |
280 continue |
| 183 |
if (b(i,j) .eq. 0.0d0) go to 290 |
| 184 |
kount = kount+1 |
| 185 |
sum = sum + cperm(j) |
| 186 |
290 continue |
| 187 |
wk(i,3) = float(kount)*wk(i,2) + sum |
| 188 |
300 continue |
| 189 |
do 330 j = low,igh |
| 190 |
kount = 0 |
| 191 |
sum = 0.0d0 |
| 192 |
do 320 i = low,igh |
| 193 |
if (a(i,j) .eq. 0.0d0) go to 310 |
| 194 |
kount = kount+1 |
| 195 |
sum = sum + wk(i,2) |
| 196 |
310 continue |
| 197 |
if (b(i,j) .eq. 0.0d0) go to 320 |
| 198 |
kount = kount+1 |
| 199 |
sum = sum + wk(i,2) |
| 200 |
320 continue |
| 201 |
wk(j,4) = float(kount)*cperm(j) + sum |
| 202 |
330 continue |
| 203 |
sum = 0.0d0 |
| 204 |
do 340 i = low,igh |
| 205 |
sum = sum + wk(i,2)*wk(i,3) + cperm(i)*wk(i,4) |
| 206 |
340 continue |
| 207 |
if(sum.eq.0.0d0) return |
| 208 |
alpha = gamma / sum |
| 209 |
c |
| 210 |
c determine correction to current iterate |
| 211 |
c |
| 212 |
cmax = 0.0d0 |
| 213 |
do 350 i = low,igh |
| 214 |
cor = alpha * wk(i,2) |
| 215 |
if (dabs(cor) .gt. cmax) cmax = dabs(cor) |
| 216 |
wk(i,1) = wk(i,1) + cor |
| 217 |
cor = alpha * cperm(i) |
| 218 |
if (dabs(cor) .gt. cmax) cmax = dabs(cor) |
| 219 |
cscale(i) = cscale(i) + cor |
| 220 |
350 continue |
| 221 |
if (cmax .lt. 0.5d0) go to 370 |
| 222 |
do 360 i = low,igh |
| 223 |
wk(i,5) = wk(i,5) - alpha*wk(i,3) |
| 224 |
wk(i,6) = wk(i,6) - alpha*wk(i,4) |
| 225 |
360 continue |
| 226 |
pgamma = gamma |
| 227 |
it = it+1 |
| 228 |
if (it .le. nrp2) go to 250 |
| 229 |
c |
| 230 |
c end generalized conjugate gradient iteration |
| 231 |
c |
| 232 |
370 continue |
| 233 |
do 380 i = low,igh |
| 234 |
ir = wk(i,1) + dsign(0.5d0,wk(i,1)) |
| 235 |
wk(i,1) = ir |
| 236 |
jc = cscale(i) + dsign(0.5d0,cscale(i)) |
| 237 |
cscale(i) = jc |
| 238 |
380 continue |
| 239 |
c |
| 240 |
c scale a and b |
| 241 |
c |
| 242 |
do 400 i = 1,igh |
| 243 |
ir = wk(i,1) |
| 244 |
fi = 2.0d0**ir |
| 245 |
if (i .lt. low) fi = 1.0d0 |
| 246 |
do 400 j =low,n |
| 247 |
jc = cscale(j) |
| 248 |
fj = 2.0d0**jc |
| 249 |
if (j .le. igh) go to 390 |
| 250 |
if (i .lt. low) go to 400 |
| 251 |
fj = 1.0d0 |
| 252 |
390 continue |
| 253 |
a(i,j) = a(i,j)*fi*fj |
| 254 |
b(i,j) = b(i,j)*fi*fj |
| 255 |
400 continue |
| 256 |
410 continue |
| 257 |
return |
| 258 |
c |
| 259 |
c last line of scaleg |
| 260 |
c |
| 261 |
end |