diff --git a/README b/README index 28cc7e9..e74c649 100644 --- a/README +++ b/README @@ -1,8 +1,30 @@ -# dotwrp.f90 +# dotwrp.c -This is a wrapper for four Level 1 BLAS functions -CDOTC CDOTU ZDOTC ZDOTU and SDOT in Accelerate.framework -of Mac OS X. +This is a wrapper for all of the BLAS functions in Apple's vecLib Framework +that have compatibility issues between F2C and GNU Fortran. -# Reference -http://developer.apple.com/hardwaredrivers/ve/errata.html#fortran_conventions +The functions fixed are: + cdotc + cdotu + zdotc + zdotu + sdot + snrm2 + sasum + scnrm2 + scasum +All other BLAS routines work correctly with or without the -ff2c flag. + +Instead of using this package, you could instead compile your FORTRAN with +-ff2c. However, if your code exports any functions returning single-precision +or (single- or double-precision) complex results, then any code that calls +those functions will be forced to follow F2C conventions as well. + +To use, just add dotwrp.c to your existing project, or link to it statically. + +This is an expansion of the "dotwrp" project by tenomoto: + https://github.com/tenomoto/dotwrp +We've chosen to convert the f90 code to c so we can take advantage of the +__attribute__((visibility ("hidden"))) settings. This ensures that the symbols +generated by this code are not visible outside of your project---which is +important if you're mixing multiple FORTRAN-based projects together. diff --git a/dotwrp.c b/dotwrp.c new file mode 100644 index 0000000..4bb37f4 --- /dev/null +++ b/dotwrp.c @@ -0,0 +1,81 @@ +// compile with: clang -c dotwrp.c +#include + +#ifdef DOTWRP_GLOBAL +#define DYLIB_LOCAL +#else +#define DYLIB_LOCAL __attribute__ ((visibility ("hidden"))) +#endif + +typedef struct cplx_ { float r, i; } fcplx; +typedef struct dcplx_ { double r, i; } dcplx; + +DYLIB_LOCAL +dcplx zdotc_( const int* n, const dcplx* x, const int* ix, const dcplx *y, const int* iy ) +{ + dcplx z; + cblas_zdotc_sub( *n, x, *ix, y, *iy, &z ); + return z; +} + +DYLIB_LOCAL +dcplx zdotu_( const int* n, const dcplx* x, const int* ix, const dcplx *y, const int* iy ) +{ + dcplx z; + cblas_zdotu_sub( *n, x, *ix, y, *iy, &z ); + return z; +} + +DYLIB_LOCAL +fcplx cdotc_( const int* n, const fcplx* x, const int* ix, const fcplx *y, const int* iy ) +{ + fcplx z; + cblas_cdotc_sub( *n, x, *ix, y, *iy, &z ); + return z; +} + +DYLIB_LOCAL +fcplx cdotu_( const int* n, const fcplx* x, const int* ix, const fcplx *y, const int* iy ) +{ + fcplx z; + cblas_cdotu_sub( *n, x, *ix, y, *iy, &z ); + return z; +} + +DYLIB_LOCAL +float sdot_( const int* n, const float* x, const int* ix, const float *y, const int* iy ) +{ + return cblas_sdot( *n, x, *ix, y, *iy ); +} + +DYLIB_LOCAL +float sdsdot_( const int* n, const float* a, const float* x, const int* ix, const float *y, const int* iy ) +{ + return cblas_sdsdot( *n, *a, x, *ix, y, *iy ); +} + +DYLIB_LOCAL +float snrm2_( const int* n, const float* x, const int* ix ) +{ + return cblas_snrm2( *n, x, *ix ); +} + +DYLIB_LOCAL +float sasum_( const int* n, const float* x, const int* ix ) +{ + return cblas_snrm2( *n, x, *ix ); +} + +DYLIB_LOCAL +float scnrm2_( const int* n, const fcplx* x, const int* ix ) +{ + return cblas_scnrm2( *n, x, *ix ); +} + +DYLIB_LOCAL +float scasum_( const int* n, const fcplx* x, const int* ix ) +{ + return cblas_scasum( *n, x, *ix ); +} + + diff --git a/dotwrp.f90 b/dotwrp.f90 deleted file mode 100644 index 1669357..0000000 --- a/dotwrp.f90 +++ /dev/null @@ -1,50 +0,0 @@ -!g95 -fno-underscoring dotwrp.f90 -c -double complex function zdotc_(n, zx, incx, zy, incy) -double complex zx(*), zy(*), z -integer n, incx, incy - -call cblas_zdotc_sub(%val(n), zx, %val(incx), zy, %val(incy), z) - -zdotc_ = z -return -end - -double complex function zdotu_(n, zx, incx, zy, incy) -double complex zx(*), zy(*), z -integer n, incx, incy - -call cblas_zdotu_sub(%val(n), zx, %val(incx), zy, %val(incy), z) - -zdotu_ = z -return -end - -complex function cdotc_(n, cx, incx, cy, incy) -complex cx(*), cy(*), c -integer n, incx, incy - -call cblas_cdotc_sub(%val(n), cx, %val(incx), cy, %val(incy), c) - -cdotc_ = c -return -end - -complex function cdotu_(n, cx, incx, cy, incy) -complex cx(*), cy(*), c -integer n, incx, incy - -call cblas_cdotu_sub(%val(n), cx, %val(incx), cy, %val(incy), c) - -cdotu_ = c -return -end - -real function sdot_(n, sx, incx, sy, incy) -real sx(*), sy(*), s -double precision d -integer n, incx, incy - -sdot_ = cblas_sdot(%val(n), sx, %val(incx), sy, %val(incy)) - -return -end