mangle.h

Go to the documentation of this file.
00001 
00035 #if !defined(INC_OSKI_MANGLE_H)
00036 
00037 #define INC_OSKI_MANGLE_H
00038 
00039 /*
00040  *  Check that type macros have been defined so we can "instantiate"
00041  *  template types.
00042  */
00043 #if !defined(IND_TAG_CHAR)
00044 #error "ERROR: Must instantiate scalar integer index type."
00045 #endif
00046 
00047 #if !defined(VAL_TAG_CHAR)
00048 #error "ERROR: Must instantiate scalar non-zero value types."
00049 #endif
00050 
00051 /* -----------------------------------------------------------------
00052  *  Select default macro scalar-type expansions.
00053  */
00054 #if IND_TAG_CHAR == 'i'
00055 
00056 
00057 #  undef IND_T
00058 #  define IND_T int
00059 #  undef IND_TAG
00060 #  define IND_TAG i
00061 #  undef IND_TAG_CAPS
00062 #  define IND_TAG_CAPS I
00063 #  undef IND_TYPE_ID
00064 #  define IND_TYPE_ID INT
00065 
00066 #elif IND_TAG_CHAR == 'l'
00067 
00068 
00069 #  undef IND_T
00070 #  define IND_T long
00071 #  undef IND_TAG
00072 #  define IND_TAG l
00073 #  undef IND_TAG_CAPS
00074 #  define IND_TAG_CAPS L
00075 #  undef IND_TYPE_ID
00076 #  define IND_TYPE_ID LONG
00077 
00078 #elif !defined(IND_T) || !defined(IND_TAG) || !defined(IND_TAG_CAPS) || !defined(IND_TYPE_ID)
00079 #error "Integer index type specification is incomplete: must define IND_T, IND_TAG, IND_TAG_CAPS, and IND_TYPE_ID"
00080 #endif
00081 
00082 #if VAL_TAG_CHAR == 's'
00083 
00084 
00085 #  undef VAL_T
00086 #  define VAL_T float
00087 #  undef VAL_TAG
00088 #  define VAL_TAG s
00089 #  undef VAL_TAG_CAPS
00090 #  define VAL_TAG_CAPS S
00091 #  undef VAL_TYPE_ID
00092 #  define VAL_TYPE_ID SINGLE
00093 
00094 #elif VAL_TAG_CHAR == 'd'
00095 
00096 
00097 #  undef VAL_T
00098 #  define VAL_T double
00099 #  undef VAL_TAG
00100 #  define VAL_TAG d
00101 #  undef VAL_TAG_CAPS
00102 #  define VAL_TAG_CAPS D
00103 #  undef VAL_TYPE_ID
00104 #  define VAL_TYPE_ID DOUBLE
00105 
00106 #elif VAL_TAG_CHAR == 'c'
00107 
00108 
00109 #  undef VAL_T
00110 #  define VAL_T complex_t
00111 #  undef VAL_TAG
00112 #  define VAL_TAG c
00113 #  undef VAL_TAG_CAPS
00114 #  define VAL_TAG_CAPS C
00115 #  undef VAL_TYPE_ID
00116 #  define VAL_TYPE_ID COMPLEX
00117 
00118 #elif VAL_TAG_CHAR == 'z'
00119 
00120 
00121 #  undef VAL_T
00122 #  define VAL_T doublecomplex_t
00123 #  undef VAL_TAG
00124 #  define VAL_TAG z
00125 #  undef VAL_TAG_CAPS
00126 #  define VAL_TAG_CAPS Z
00127 #  undef VAL_TYPE_ID
00128 #  define VAL_TYPE_ID DOUBLECOMPLEX
00129 
00130 #elif !defined(VAL_T) || !defined(VAL_TAG) || !defined(VAL_TAG_CAPS) || !defined(VAL_TYPE_ID)
00131 #  error "Non-zero value type specification is incomplete: must define VAL_T, VAL_TAG, VAL_TAG_CAPS, and VAL_TYPE_ID"
00132 #endif
00133 
00134 /* ----------------------------------------------------------------- */
00135 
00142 #define IS_VAL_COMPLEX  ((VAL_TAG_CHAR=='c') || (VAL_TAG_CHAR=='z'))
00143 
00147 #define IS_VALPREC_SINGLE  ((VAL_TAG_CHAR=='s') || (VAL_TAG_CHAR=='c'))
00148 
00152 #define IS_VALPREC_DOUBLE  ((VAL_TAG_CHAR=='d') || (VAL_TAG_CHAR=='z'))
00153 
00154 #if IS_VALPREC_DOUBLE
00155 #  if HAVE_EPS_DOUBLE
00156 #    include <float.h>
00157 #    define VAL_EPS DBL_EPSILON 
00158 #  else 
00159 #    define VAL_EPS 1e-15
00160 #  endif
00161 #elif IS_VALPREC_SINGLE
00162 #  if HAVE_EPS_FLOAT
00163 #    include <float.h>
00164 #      define VAL_EPS FLT_EPSILON 
00165 #  else
00166 #    define VAL_EPS 1e-7 
00167 #  endif
00168 #else
00169 #  warning "WARNING: Not sure how to define machine epsilon..."
00170 #  define VAL_EPS 1e-7 
00171 #endif
00172 
00173 #define VAL_ZERO    (0.0)  
00174 #define VAL_ONE     (1.0)  
00175 #define VAL_NEG_ONE  (-1.0) 
00177 #include <math.h>
00178 
00179 #  if HAVE_C99_FPCLASSIFY
00180 
00181 #    define IS_REAL_ZERO(x)  (fpclassify(x) == FP_ZERO)
00182 #  else
00183 
00184 #    define IS_REAL_ZERO(x)  ((x) == VAL_ZERO)
00185 #  endif
00186 
00187 #if !(IS_VAL_COMPLEX)
00188 
00189 #  if HAVE_C99_FPCLASSIFY
00190 
00191 #    define IS_VAL_ZERO(x)    (fpclassify(x) == FP_ZERO)
00192 
00193 #    define IS_VAL_ONE(x)     (fpclassify((x)-1.0) == FP_ZERO)
00194 
00195 #    define IS_VAL_NEG_ONE(x)     (fpclassify((x)+1.0) == FP_ZERO)
00196 #  else /* !HAVE_C99_FPCLASSIFY */
00197 
00198 #    define IS_VAL_ZERO(x)    ((x) == VAL_ZERO)
00199 
00200 #    define IS_VAL_ONE(x)     ((x) == VAL_ONE)
00201 
00202 #    define IS_VAL_NEG_ONE(x)  ((x) == VAL_NEG_ONE)
00203 #  endif
00204 
00206 #  define VAL_ABS(x)  fabs(x)
00207 
00209 #  define VAL_SET_ZERO(x)  (x) = 0.0
00210 
00212 #  define VAL_SET_ONE(x)  (x) = 1.0
00213 
00215 #  define VAL_CONJ(x)
00216 
00218 #  define VAL_ASSIGN(y, x)  (y) = (x)
00219 
00221 #  define VAL_ASSIGN_CONJ(y, x)  VAL_ASSIGN(y, x)
00222 
00224 #  define VAL_ASSIGN_NEG(y, x)  (y) = -(x)
00225 
00227 #  define VAL_ASSIGN_NEG_CONJ(y, x)  VAL_ASSIGN_NEG(y, x)
00228 
00230 #  define MAKE_VAL_COMPLEX(x, y)  (x)
00231 
00236 #  define VAL_SCALE(x, alpha)  (x) *= (alpha)
00237 
00242 #  define VAL_SCALE_CONJ(x, alpha)  VAL_SCALE(x, alpha)
00243 
00248 #  define VAL_MAC(y, alpha, x)  (y) += (alpha) * (x)
00249 
00254 #  define VAL_MAC_CONJ(y, alpha, x)  VAL_MAC(y, alpha, x)
00255 
00260 #  define VAL_MSUB(y, alpha, x)  (y) -= (alpha) * (x)
00261 
00266 #  define VAL_MSUB_CONJ(y, alpha, x)  VAL_MSUB(y, alpha, x)
00267 
00272 #  define VAL_DEC(x, a)   (x) -= (a)
00273 
00278 #  define VAL_DEC_CONJ(x, a)   VAL_DEC(x, a)
00279 
00284 #  define VAL_INC(x, a)   (x) += (a)
00285 
00290 #  define VAL_INC_CONJ(x, a)   VAL_INC(x, a)
00291 
00296 #  define VAL_MUL(z, x, y)  (z) = (x) * (y)
00297 
00302 #  define VAL_MUL_CONJ(z, x, y)  VAL_MUL(z, x, y)
00303 
00308 #  define VAL_TRIAD(z, y, alpha, x) (z) = (y) + (alpha) * (x)
00309 
00314 #  define VAL_TRIAD_CONJ(z, y, alpha, x)   VAL_TRIAD(z, y, alpha, x)
00315 
00320 #  define VAL_DIVEQ(x, a)  (x) /= (a)
00321 
00326 #  define VAL_DIVEQ_CONJ(x, a)  VAL_DIVEQ(x, a)
00327 
00332 #  define VAL_INV(y, x)  (y) = 1.0/(x)
00333 
00334 #else /* IS_VAL_COMPLEX */
00335 
00336 #  if HAVE_C99_FPCLASSIFY
00337 
00338 #    define IS_VAL_ZERO(x)    \
00339             (fpclassify(_RE(x)) == FP_ZERO && fpclassify(_IM(x)) == FP_ZERO)
00340 
00341 #    define IS_VAL_ONE(x)     \
00342             (fpclassify(_RE(x)-1.0) == FP_ZERO && fpclassify(_IM(x)) == FP_ZERO)
00343 
00344 #    define IS_VAL_NEG_ONE(x)  \
00345             (fpclassify(_RE(x)+1.0) == FP_ZERO && fpclassify(_IM(x)) == FP_ZERO)
00346 #  else /* !HAVE_C99_FPCLASSIFY */
00347 
00348 #    define IS_VAL_ZERO(x)    \
00349             ((_RE(x) == VAL_ZERO) && (_IM(x) == VAL_ZERO))
00350 
00351 #    define IS_VAL_ONE(x)     \
00352             ((_RE(x) == VAL_ONE) && (_IM(x) == VAL_ZERO))
00353 
00354 #    define IS_VAL_NEG_ONE(x)  \
00355             ((_RE(x) == VAL_NEG_ONE) && (_IM(x) == VAL_ZERO))
00356 #  endif
00357 
00359 #  define VAL_ABS(x)  sqrt(_RE(x)*_RE(x)+_IM(x)*_IM(x))
00360 
00362 #  define VAL_ASSIGN(y, x)  _RE(y) = _RE(x), _IM(y) = _IM(x)
00363 
00365 #  define VAL_ASSIGN_CONJ(y, x)  _RE(y) = _RE(x), _IM(y) = -_IM(x)
00366 
00368 #  define VAL_ASSIGN_NEG(y, x)  _RE(y) = -_RE(x), _IM(y) = -_IM(x)
00369 
00371 #  define VAL_ASSIGN_NEG_CONJ(y, x)  _RE(y) = -_RE(x), _IM(y) = _IM(x)
00372 
00374 #  define VAL_SET_ZERO(x)  _RE(x) = 0.0, _IM(x) = 0.0
00375 
00377 #  define VAL_SET_ONE(x)  _RE(x) = 1.0, _IM(x) = 0.0
00378 
00380 #  define VAL_CONJ(x)  _IM(x) = -_IM(x)
00381 
00383 #  define MAKE_VAL_COMPLEX(x, y)   {(x), (y)}
00384 
00386 #  define VAL_MUL_RE(x, a)  (_RE(x)*_RE(a) - _IM(x)*_IM(a))
00387 
00389 #  define VAL_MUL_CONJ_RE(x, a)  (_RE(x)*_RE(a) + _IM(x)*_IM(a))
00390 
00392 #  define VAL_MUL_IM(x, a)  (_RE(x)*_IM(a) + _IM(x)*_RE(a))
00393 
00395 #  define VAL_MUL_CONJ_IM(x, a)  (_RE(x)*_IM(a) - _IM(x)*_RE(a))
00396 
00401 #  define VAL_MUL(z, x, y)  \
00402         _RE(z) = VAL_MUL_RE(x, y), _IM(z) = VAL_MUL_IM(x, y)
00403 
00408 #  define VAL_MUL_CONJ(z, x, y)  \
00409         _RE(z) = VAL_MUL_CONJ_RE(x, y), _IM(z) = VAL_MUL_CONJ_IM(x, y)
00410 
00415 #  define VAL_SCALE(x, a)  { \
00416         oski_value_t y = x; \
00417         _RE(x) = VAL_MUL_RE(y, a); \
00418         _IM(x) = VAL_MUL_IM(y, a); \
00419         }
00420 
00425 #  define VAL_SCALE_CONJ(x, a)  { \
00426         oski_value_t y = x; \
00427         _RE(x) = VAL_MUL_CONJ_RE(a, y); \
00428         _IM(x) = VAL_MUL_CONJ_IM(a, y); \
00429         }
00430 
00435 #  define VAL_INC(x, a)   _RE(x) += _RE(a), _IM(x) += _IM(a)
00436 
00441 #  define VAL_INC_CONJ(x, a)   _RE(x) += _RE(a), _IM(x) -= _IM(a)
00442 
00447 #  define VAL_DEC(x, a)   _RE(x) -= _RE(a), _IM(x) -= _IM(a)
00448 
00453 #  define VAL_DEC_CONJ(x, a)   _RE(x) -= _RE(a), _IM(x) += _IM(a)
00454 
00459 #  define VAL_MAC(y, alpha, x)  \
00460         _RE(y) += VAL_MUL_RE(alpha, x), _IM(y) += VAL_MUL_IM(alpha, x)
00461 
00466 #  define VAL_MAC_CONJ(y, alpha, x)  \
00467         _RE(y) += VAL_MUL_CONJ_RE(alpha, x), _IM(y) += VAL_MUL_CONJ_IM(alpha, x)
00468 
00473 #  define VAL_MSUB(y, alpha, x)  \
00474         _RE(y) -= VAL_MUL_RE(alpha, x), \
00475         _IM(y) -= VAL_MUL_IM(alpha, x)
00476 
00481 #  define VAL_MSUB_CONJ(y, alpha, x)  \
00482         _RE(y) -= VAL_MUL_CONJ_RE(alpha, x), \
00483         _IM(y) -= VAL_MUL_CONJ_IM(alpha, x)
00484 
00489 #  define VAL_TRIAD(z, y, alpha, x) \
00490         _RE(z) = _RE(y), _IM(z) = _IM(y), VAL_MAC(z, alpha, x)
00491 
00496 #  define VAL_TRIAD_CONJ(z, y, alpha, x) \
00497         _RE(z) = _RE(y), _IM(z) = _IM(y), VAL_MAC_CONJ(z, alpha, x)
00498 
00507 #  define VAL_DIVEQ(x, a)  { \
00508         oski_value_t t = (x); \
00509         _RE(x) = _RE(t)*_RE(a) + _IM(t)*_IM(a); \
00510         _IM(x) = _IM(t)*_RE(a) - _RE(t)*_IM(a); \
00511         _RE(x) /= _RE(a)*_RE(a) + _IM(a)*_IM(a); \
00512         _IM(x) /= _RE(a)*_RE(a) + _IM(a)*_IM(a); \
00513     }
00514 
00523 #  define VAL_DIVEQ_CONJ(x, a)  { \
00524         oski_value_t t = (x); \
00525         _RE(x) = _RE(t)*_RE(a) - _IM(t)*_IM(a); \
00526         _IM(x) = _IM(t)*_RE(a) + _RE(t)*_IM(a); \
00527         _RE(x) /= _RE(a)*_RE(a) + _IM(a)*_IM(a); \
00528         _IM(x) /= _RE(a)*_RE(a) + _IM(a)*_IM(a); \
00529     }
00530 
00535 #  define VAL_INV(y, x)  \
00536         _RE(y) = _RE(x) / (_RE(x)*_RE(x) + _IM(x)*_IM(x)), \
00537         _IM(y) = -_IM(x) / (_RE(x)*_RE(x) + _IM(x)*_IM(x))
00538 
00539 #endif
00540 
00542 #define MAKE_VAL_REAL(x)   MAKE_VAL_COMPLEX((x), VAL_ZERO)
00543 
00549 #define MAKE_VAL_GENERAL   MAKE_VAL_COMPLEX(-9, -9)
00550 
00555 #define CATEGORIZE_VAL(alpha) ( \
00556         (IS_VAL_ONE(alpha) || IS_VAL_ZERO(alpha) || IS_VAL_NEG_ONE(alpha)) \
00557             ? (alpha) : MAKE_VAL_GENERAL \
00558     )
00559 
00560 #if !defined(MOD_NAME) && defined(OSKI_BUILD_TIME)
00561 #pragma WARNING "Should instantiate a module name explicitly."
00562 
00569 #define MOD_NAME self
00570 #endif
00571 
00572 
00588 #define MAKETYPENAME0(base, ind, val) base ## _T ## ind ## val
00589 
00601 #define MAKETYPENAME1(base, ind, val) MAKETYPENAME0(base, ind, val)
00602 
00615 #define MAKEMODNAME0(mod, base, ind, val) \
00616     mod ## _T ## ind ## val ## _LTX_ ## base
00617 
00627 #define MAKEMODNAME1(mod, base, ind, val) MAKEMODNAME0(mod, base, ind, val)
00628 
00647 #define MANGLE_(base) MAKETYPENAME1(base, IND_TAG, VAL_TAG)
00648 
00659 #define MANGLE_MOD_(base) MAKEMODNAME1(MOD_NAME, base, IND_TAG, VAL_TAG)
00660 
00666 #define MANGLE_CONCAT0(a, b)  a ## b
00667 
00675 #define MANGLE_CONCAT(a, b)   MANGLE_CONCAT0(a, b)
00676 
00678 #define OSKI_IND_ID  MANGLE_CONCAT(OSKI_SCALIND_, IND_TYPE_ID)
00679 
00681 #define OSKI_VAL_ID  MANGLE_CONCAT(OSKI_SCALVAL_, VAL_TYPE_ID)
00682 
00688 #define OSKI_MAKENAME_FUNCPT(name) oski_ ## name ## _funcpt
00689 
00690 #if 0
00691 #if defined(DO_NAME_MANGLING)
00692 #define oski_index_t  MANGLE_(oski_index_t)
00693 #define oski_value_t  MANGLE_(oski_value_t)
00694 #endif
00695 #endif
00696 #define oski_index_t IND_T
00697 #define oski_value_t VAL_T
00698 
00704 #if 0
00705 typedef IND_T oski_index_t; 
00706 typedef VAL_T oski_value_t; 
00707 #endif
00708 
00712 #define TVAL_ZERO  MANGLE_(TVAL_ZERO)
00713 #define TVAL_ONE   MANGLE_(TVAL_ONE)
00714 #define TVAL_NEG_ONE  MANGLE_(TVAL_NEG_ONE)
00715 #define TVAL_IMAG  MANGLE_(TVAL_IMAG)
00716 #define TVAL_NEG_IMAG  MANGLE_(TVAL_NEG_IMAG)
00717 
00718 extern const oski_value_t TVAL_ZERO;
00719 extern const oski_value_t TVAL_ONE;
00720 extern const oski_value_t TVAL_NEG_ONE;
00721 extern const oski_value_t TVAL_IMAG;
00722 extern const oski_value_t TVAL_NEG_IMAG;
00725 #endif /* !defined(INC_OSKI_MANGLE_H) */
00726 
00727 #if defined(OSKI_UNBIND)
00728 #  undef INC_OSKI_MANGLE_H
00729 #  undef IS_VAL_COMPLEX
00730 #  undef IS_VALPREC_SINGLE
00731 #  undef IS_VALPREC_DOUBLE
00732 #  undef VAL_EPS
00733 #  undef VAL_ZERO
00734 #  undef VAL_ONE
00735 #  undef VAL_NEG_ONE
00736 #  undef IS_VAL_ZERO
00737 #  undef IS_VAL_ONE
00738 #  undef IS_VAL_NEG_ONE
00739 #  undef IS_REAL_ZERO
00740 #  undef VAL_ABS
00741 #  undef VAL_SET_ZERO
00742 #  undef VAL_SET_ONE
00743 #  undef VAL_CONJ
00744 #  undef VAL_ASSIGN
00745 #  undef VAL_ASSIGN_CONJ
00746 #  undef VAL_ASSIGN_NEG
00747 #  undef VAL_ASSIGN_NEG_CONJ
00748 #  undef MAKE_VAL_COMPLEX
00749 #  undef VAL_SCALE
00750 #  undef VAL_SCALE_CONJ
00751 #  undef VAL_MAC
00752 #  undef VAL_MAC_CONJ
00753 #  undef VAL_MSUB
00754 #  undef VAL_MSUB_CONJ
00755 #  undef VAL_DEC
00756 #  undef VAL_DEC_CONJ
00757 #  undef VAL_INC
00758 #  undef VAL_INC_CONJ
00759 #  undef VAL_MUL
00760 #  undef VAL_MUL_CONJ
00761 #  undef VAL_TRIAD
00762 #  undef VAL_TRIAD_CONJ
00763 #  undef VAL_DIVEQ
00764 #  undef VAL_DIVEQ_CONJ
00765 #  undef VAL_INV
00766 #  undef MAKE_VAL_REAL
00767 #  undef MAKE_VAL_GENERAL
00768 #  undef CATEGORIZE_VAL
00769 #  undef MAKETYPENAME0
00770 #  undef MAKETYPENAME1
00771 #  undef MAKEMODNAME0
00772 #  undef MAKEMODNAME1
00773 #  undef MANGLE_
00774 #  undef MANGLE_MOD_
00775 #  undef MANGLE_CONCAT0
00776 #  undef MANGLE_CONCAT
00777 #  undef OSKI_IND_ID
00778 #  undef OSKI_VAL_ID
00779 #  undef OSKI_MAKENAME_FUNCPT
00780 #  undef TVAL_ZERO
00781 #  undef TVAL_ONE
00782 #  undef TVAL_NEG_ONE
00783 #  undef TVAL_IMAG
00784 #  undef TVAL_NEG_IMAG
00785 #endif
00786 
00787 /* eof */

Generated on Wed Sep 19 16:41:18 2007 for BeBOP Optimized Sparse Kernel Interface Library by  doxygen 1.4.6