Permalink
Browse files

Refs #95 cblas: compatibility for compilers without C99 complex numbe…

…r support (e.g. Visual Studio)
  • Loading branch information...
1 parent 001c2c3 commit f93318a6c818c969a321bc47d1c8fad06d60429b @zchothia zchothia committed with Apr 22, 2012
Showing with 63 additions and 10 deletions.
  1. +1 −1 Makefile.install
  2. +9 −9 cblas.h
  3. +22 −0 common.h
  4. +31 −0 openblas_config_template.h
View
@@ -23,7 +23,7 @@ install : lib.grd
@cat config_last.h >> $(OPENBLAS_INCLUDE_DIR)/openblas_config.h
@echo \#define VERSION \" OpenBLAS $(VERSION) \" >> $(OPENBLAS_INCLUDE_DIR)/openblas_config.h
@cat openblas_config_template.h >> $(OPENBLAS_INCLUDE_DIR)/openblas_config.h
- @echo \#endif >> $(OPENBLAS_INCLUDE_DIR)/openblas_config.h
+ @echo \#endif \/\* OPENBLAS_CONFIG_H \*\/ >> $(OPENBLAS_INCLUDE_DIR)/openblas_config.h
@echo Generating f77blas.h in $(OPENBLAS_INCLUDE_DIR)
@echo \#ifndef OPENBLAS_F77BLAS_H > $(OPENBLAS_INCLUDE_DIR)/f77blas.h
View
18 cblas.h
@@ -22,15 +22,15 @@ double cblas_dsdot (blasint n, float *x, blasint incx, float *y, blasint incy);
float cblas_sdot(blasint n, float *x, blasint incx, float *y, blasint incy);
double cblas_ddot(blasint n, double *x, blasint incx, double *y, blasint incy);
-float _Complex cblas_cdotu(blasint n, float *x, blasint incx, float *y, blasint incy);
-float _Complex cblas_cdotc(blasint n, float *x, blasint incx, float *y, blasint incy);
-double _Complex cblas_zdotu(blasint n, double *x, blasint incx, double *y, blasint incy);
-double _Complex cblas_zdotc(blasint n, double *x, blasint incx, double *y, blasint incy);
-
-void cblas_cdotu_sub(blasint n, float *x, blasint incx, float *y, blasint incy, float _Complex *ret);
-void cblas_cdotc_sub(blasint n, float *x, blasint incx, float *y, blasint incy, float _Complex *ret);
-void cblas_zdotu_sub(blasint n, double *x, blasint incx, double *y, blasint incy, double _Complex *ret);
-void cblas_zdotc_sub(blasint n, double *x, blasint incx, double *y, blasint incy, double _Complex *ret);
+openblas_complex_float cblas_cdotu(blasint n, float *x, blasint incx, float *y, blasint incy);
+openblas_complex_float cblas_cdotc(blasint n, float *x, blasint incx, float *y, blasint incy);
+openblas_complex_double cblas_zdotu(blasint n, double *x, blasint incx, double *y, blasint incy);
+openblas_complex_double cblas_zdotc(blasint n, double *x, blasint incx, double *y, blasint incy);
+
+void cblas_cdotu_sub(blasint n, float *x, blasint incx, float *y, blasint incy, openblas_complex_float *ret);
+void cblas_cdotc_sub(blasint n, float *x, blasint incx, float *y, blasint incy, openblas_complex_float *ret);
+void cblas_zdotu_sub(blasint n, double *x, blasint incx, double *y, blasint incy, openblas_complex_double *ret);
+void cblas_zdotc_sub(blasint n, double *x, blasint incx, double *y, blasint incy, openblas_complex_double *ret);
float cblas_sasum (blasint n, float *x, blasint incx);
double cblas_dasum (blasint n, double *x, blasint incx);
View
@@ -374,6 +374,28 @@ typedef int blasint;
#endif
#endif
+#ifndef ASSEMBLER
+#ifndef NOINCLUDE
+/* Inclusion of a standard header file is needed for definition of __STDC_*
+ predefined macros with some compilers (e.g. GCC 4.7 on Linux). This occurs
+ as a side effect of including either <features.h> or <stdc-predef.h>. */
+#include <stdio.h>
+#endif // NOINCLUDE
+
+/* C99 supports complex floating numbers natively, which GCC also offers as an
+ extension since version 3.0. If neither are available, use a compatible
+ structure as fallback (see Clause 6.2.5.13 of the C99 standard). */
+#if defined(__STDC_IEC_559_COMPLEX__) || __STDC_VERSION__ >= 199901L || __GNUC__ >= 3
+ #define OPENBLAS_COMPLEX_C99
+ typedef float _Complex openblas_complex_float;
+ typedef double _Complex openblas_complex_double;
+#else
+ #define OPENBLAS_COMPLEX_STRUCT
+ typedef struct { float real, imag; } openblas_complex_float;
+ typedef struct { double real, imag; } openblas_complex_double;
+#endif
+#endif // ASSEMBLER
+
#ifndef IFLUSH
#define IFLUSH
#endif
View
@@ -39,3 +39,34 @@ typedef int blasint;
#define FLOATRET float
#endif
#endif
+
+/* Inclusion of a standard header file is needed for definition of __STDC_*
+ predefined macros with some compilers (e.g. GCC 4.7 on Linux). This occurs
+ as a side effect of including either <features.h> or <stdc-predef.h>. */
+#include <stdio.h>
+
+/* C99 supports complex floating numbers natively, which GCC also offers as an
+ extension since version 3.0. If neither are available, use a compatible
+ structure as fallback (see Clause 6.2.5.13 of the C99 standard). */
+#if defined(__STDC_IEC_559_COMPLEX__) || __STDC_VERSION__ >= 199901L || __GNUC__ >= 3
+ #define OPENBLAS_COMPLEX_C99
+ #include <complex.h>
+ typedef float _Complex openblas_complex_float;
+ typedef double _Complex openblas_complex_double;
+ #define openblas_make_complex_float(real, imag) ((real) + ((imag) * _Complex_I))
+ #define openblas_make_complex_double(real, imag) ((real) + ((imag) * _Complex_I))
+ #define openblas_complex_float_real(z) (creal(z))
+ #define openblas_complex_float_imag(z) (cimag(z))
+ #define openblas_complex_double_real(z) (creal(z))
+ #define openblas_complex_double_imag(z) (cimag(z))
+#else
+ #define OPENBLAS_COMPLEX_STRUCT
+ typedef struct { float real, imag; } openblas_complex_float;
+ typedef struct { double real, imag; } openblas_complex_double;
+ #define openblas_make_complex_float(real, imag) {(real), (imag)}
+ #define openblas_make_complex_double(real, imag) {(real), (imag)}
+ #define openblas_complex_float_real(z) ((z).real)
+ #define openblas_complex_float_imag(z) ((z).imag)
+ #define openblas_complex_double_real(z) ((z).real)
+ #define openblas_complex_double_imag(z) ((z).imag)
+#endif

0 comments on commit f93318a

Please sign in to comment.