Skip to content

Commit 2a97ca6

Browse files
authored
MSVC compatibility fixes
1 parent 5dec93e commit 2a97ca6

10 files changed

Lines changed: 1413 additions & 155 deletions

File tree

lapack-netlib/SRC/clatrs3.c

Lines changed: 142 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
/* f2c.h -- Standard Fortran to C header file */
2-
3-
/** barf [ba:rf] 2. "He suggested using FORTRAN, and everybody barfed."
4-
5-
- From The Shogakukan DICTIONARY OF NEW ENGLISH (Second edition) */
6-
7-
#ifndef F2C_INCLUDE
8-
#define F2C_INCLUDE
9-
101
#include <math.h>
112
#include <stdlib.h>
123
#include <string.h>
@@ -19,18 +10,46 @@
1910
#undef I
2011
#endif
2112

22-
typedef int integer;
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+
2335
typedef unsigned int uinteger;
2436
typedef char *address;
2537
typedef short int shortint;
2638
typedef float real;
2739
typedef double doublereal;
2840
typedef struct { real r, i; } complex;
2941
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
3048
static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
3149
static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
3250
static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
3351
static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
52+
#endif
3453
#define pCf(z) (*_pCf(z))
3554
#define pCd(z) (*_pCd(z))
3655
typedef int logical;
@@ -170,8 +189,13 @@ typedef struct Namelist Namelist;
170189
#define abort_() { sig_die("Fortran abort routine called", 1); }
171190
#define c_abs(z) (cabsf(Cf(z)))
172191
#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
173196
#define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
174197
#define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
198+
#endif
175199
#define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
176200
#define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
177201
#define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
@@ -183,13 +207,13 @@ typedef struct Namelist Namelist;
183207
#define d_atan(x) (atan(*(x)))
184208
#define d_atn2(x, y) (atan2(*(x),*(y)))
185209
#define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
186-
#define r_cnjg(R, Z) { pCf(R) = conj(Cf(Z)); }
210+
#define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
187211
#define d_cos(x) (cos(*(x)))
188212
#define d_cosh(x) (cosh(*(x)))
189213
#define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
190214
#define d_exp(x) (exp(*(x)))
191215
#define d_imag(z) (cimag(Cd(z)))
192-
#define r_imag(z) (cimag(Cf(z)))
216+
#define r_imag(z) (cimagf(Cf(z)))
193217
#define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
194218
#define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
195219
#define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
@@ -229,10 +253,13 @@ static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
229253
#define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
230254
#define myexit_() break;
231255
#define mycycle_() continue;
232-
#define myceiling_(w) ceil(w)
233-
#define myhuge_(w) HUGE_VAL
256+
#define myceiling_(w) {ceil(w)}
257+
#define myhuge_(w) {HUGE_VAL}
234258
//#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
235259
#define mymaxloc_(w,s,e,n) dmaxloc_(w,*(s),*(e),n)
260+
#define myexp_(w) my_expfunc(w)
261+
262+
static int my_expfunc(float *x) {int e; (void)frexpf(*x,&e); return e;}
236263

237264
/* procedure parameter types for -A and -C++ */
238265

@@ -267,6 +294,21 @@ static double dpow_ui(double x, integer n) {
267294
}
268295
return pow;
269296
}
297+
#ifdef _MSC_VER
298+
static _Fcomplex cpow_ui(complex x, integer n) {
299+
complex pow={1.0,0.0}; unsigned long int u;
300+
if(n != 0) {
301+
if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
302+
for(u = n; ; ) {
303+
if(u & 01) pow.r *= x.r, pow.i *= x.i;
304+
if(u >>= 1) x.r *= x.r, x.i *= x.i;
305+
else break;
306+
}
307+
}
308+
_Fcomplex p={pow.r, pow.i};
309+
return p;
310+
}
311+
#else
270312
static _Complex float cpow_ui(_Complex float x, integer n) {
271313
_Complex float pow=1.0; unsigned long int u;
272314
if(n != 0) {
@@ -279,6 +321,22 @@ static _Complex float cpow_ui(_Complex float x, integer n) {
279321
}
280322
return pow;
281323
}
324+
#endif
325+
#ifdef _MSC_VER
326+
static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
327+
_Dcomplex pow={1.0,0.0}; unsigned long int u;
328+
if(n != 0) {
329+
if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
330+
for(u = n; ; ) {
331+
if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
332+
if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
333+
else break;
334+
}
335+
}
336+
_Dcomplex p = {pow._Val[0], pow._Val[1]};
337+
return p;
338+
}
339+
#else
282340
static _Complex double zpow_ui(_Complex double x, integer n) {
283341
_Complex double pow=1.0; unsigned long int u;
284342
if(n != 0) {
@@ -291,6 +349,7 @@ static _Complex double zpow_ui(_Complex double x, integer n) {
291349
}
292350
return pow;
293351
}
352+
#endif
294353
static integer pow_ii(integer x, integer n) {
295354
integer pow; unsigned long int u;
296355
if (n <= 0) {
@@ -324,6 +383,22 @@ static integer smaxloc_(float *w, integer s, integer e, integer *n)
324383
}
325384
static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
326385
integer n = *n_, incx = *incx_, incy = *incy_, i;
386+
#ifdef _MSC_VER
387+
_Fcomplex zdotc = {0.0, 0.0};
388+
if (incx == 1 && incy == 1) {
389+
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
390+
zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
391+
zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
392+
}
393+
} else {
394+
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
395+
zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
396+
zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
397+
}
398+
}
399+
pCf(z) = zdotc;
400+
}
401+
#else
327402
_Complex float zdotc = 0.0;
328403
if (incx == 1 && incy == 1) {
329404
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
@@ -336,8 +411,25 @@ static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, c
336411
}
337412
pCf(z) = zdotc;
338413
}
414+
#endif
339415
static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
340416
integer n = *n_, incx = *incx_, incy = *incy_, i;
417+
#ifdef _MSC_VER
418+
_Dcomplex zdotc = {0.0, 0.0};
419+
if (incx == 1 && incy == 1) {
420+
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
421+
zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
422+
zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
423+
}
424+
} else {
425+
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
426+
zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
427+
zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
428+
}
429+
}
430+
pCd(z) = zdotc;
431+
}
432+
#else
341433
_Complex double zdotc = 0.0;
342434
if (incx == 1 && incy == 1) {
343435
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
@@ -349,9 +441,26 @@ static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integ
349441
}
350442
}
351443
pCd(z) = zdotc;
352-
}
444+
}
445+
#endif
353446
static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
354447
integer n = *n_, incx = *incx_, incy = *incy_, i;
448+
#ifdef _MSC_VER
449+
_Fcomplex zdotc = {0.0, 0.0};
450+
if (incx == 1 && incy == 1) {
451+
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
452+
zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
453+
zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
454+
}
455+
} else {
456+
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
457+
zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
458+
zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
459+
}
460+
}
461+
pCf(z) = zdotc;
462+
}
463+
#else
355464
_Complex float zdotc = 0.0;
356465
if (incx == 1 && incy == 1) {
357466
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
@@ -364,8 +473,25 @@ static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, c
364473
}
365474
pCf(z) = zdotc;
366475
}
476+
#endif
367477
static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
368478
integer n = *n_, incx = *incx_, incy = *incy_, i;
479+
#ifdef _MSC_VER
480+
_Dcomplex zdotc = {0.0, 0.0};
481+
if (incx == 1 && incy == 1) {
482+
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
483+
zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
484+
zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
485+
}
486+
} else {
487+
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
488+
zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
489+
zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
490+
}
491+
}
492+
pCd(z) = zdotc;
493+
}
494+
#else
369495
_Complex double zdotc = 0.0;
370496
if (incx == 1 && incy == 1) {
371497
for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
@@ -386,6 +512,7 @@ static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integ
386512

387513

388514

515+
389516
/* Table of constant values */
390517

391518
static complex c_b2 = {1.f,0.f};

0 commit comments

Comments
 (0)