35 #include "tbci/tbci_version.h"
37 #ifdef HAVE_TBCICONFIG_H
38 # include "tbci/tbciconfig.h"
40 # include "tbci/config_manual.h"
44 #if !defined(__GNUC_PATCHLEVEL__) && defined(__GNUC__SUBVER__)
45 # define __GNUC_PATCHLEVEL__ __GNUC_SUBVER__
58 # define HAVE_WIN_32 1
60 # pragma warning(disable: 4003)
64 #if defined(USE_SMP) && !defined(SMP)
69 #if !defined(NO_NS) && !defined(HAVE_BUGGY_NAMESPACE)
78 # define SIGNATURE signature
80 # define SIGNATURE class
84 #if defined(HAVE_RESTRICT) && !defined(NO_RESTRICT)
85 # define RESTRICT restrict
86 #elif defined (HAVE___RESTRICT__) && !defined(NO_RESTRICT)
87 # define RESTRICT __restrict__
96 #if defined(HAVE_BUILTIN_EXPECT) && !defined(NO_EXPECT)
97 # define LIKELY(expr) __builtin_expect((expr) != 0, 1)
98 # define UNLIKELY(expr) __builtin_expect((expr) != 0, 0)
100 # define LIKELY(expr) (expr)
101 # define UNLIKELY(expr) (expr)
105 #if defined(__cplusplus) && __cplusplus >= 201703L
108 # define REGISTER register
114 # define TBCI_DLLEXPORT __declspec(dllexport)
116 # define TBCI_DLLEXPORT __declspec(dllimport)
118 # define TBCI_DLLLOCAL
120 # ifdef HAVE_VISIBILITY_ATTR
121 # define TBCI_DLLEXPORT __attribute__ ((visibility("default")))
122 # define TBCI_DLLLOCAL __attribute__ ((visibility("hidden")))
124 # define TBCI_DLLEXPORT
125 # define TBCI_DLLLOCAL
130 #if defined(HAVE_PRAGMA_IFACE_IMPL) && !defined(NO_PRAGMA_I)
135 #ifdef HAVE_NEED_FOR_EXPL_TMPLPARM
139 # define FGDTD <T,dims>
140 # define FGDDT <dims,T>
141 # define FGDCT <cplx<T> >
156 #if defined(__BORLANDC__) && defined(__linux__)
157 # define __BEGIN_NAMESPACE_STD
158 # define __END_NAMESPACE_STD
159 # define __USING_NAMESPACE_STD(name)
160 # define __BEGIN_NAMESPACE_C99
161 # define __END_NAMESPACE_C99
162 # define __USING_NAMESPACE_C99(name)
170 #ifndef HAVE_NO_NEW_HEADERS_BUG
192 #if defined(C_MEMALLOC) && defined(HAVE_MEMALIGN)
197 #ifdef HAVE_MINMAX_IN_SYS_PARAM_H
198 # include <sys/param.h>
202 #if !defined(HAVE_SSTREAM) || defined(HAVE_BUGGY_SSTREAM)
204 # define ISTRINGSTREAM istrstream
205 # define OSTRINGSTREAM ostrstream
206 # define STRINGSTREAM strstream
209 # define ISTRINGSTREAM istringstream
210 # define OSTRINGSTREAM ostringstream
211 # define STRINGSTREAM stringstream
216 #ifdef HAVE_LONG_DOUBLE
217 # define LONG_DOUBLE long double
219 # define LONG_DOUBLE double
221 #ifdef HAVE_LONG_LONG
222 # define LONG_LONG long long
224 # define LONG_LONG long
229 # define INST(x) _instantiate x
230 # define INST2(x,y) _instantiate x,y
231 # define INST3(x,y,z) _instantiate x,y,z
232 # define INST4(x,y,z,a) _instantiate x,y,z,a
233 # define INST5(x,y,z,a,b) _instantiate x,y,z,a,b
234 # define INST6(x,y,z,a,b,c) _instantiate x,y,z,a,b,c
235 # define NOINST _noinstantiate
236 # define INSTCTL(x) _instfile x
240 # define INST3(x,y,z)
241 # define INST4(x,y,z,a)
242 # define INST5(x,y,z,a,b)
243 # define INST6(x,y,z,a,b,c)
262 # define NAMESPACE_TBCI
263 # define NAMESPACE_STD
264 # define NAMESPACE_CSTD
265 # define NAMESPACE_GRID
266 # define NAMESPACE_CPLX
267 # define NAMESPACE_END
268 # define NAMESPACE_STD_END
269 # define NAMESPACE_CSTD_END
270 # define NAMESPACE_CPLX_END
276 # define FRIEND_TBCI__
277 # define FRIEND_TBCI2__
288 #elif defined(NO_NS_TBCI)
289 # define NAMESPACE_TBCI
290 # define NAMESPACE_STD namespace std {
291 # define NAMESPACE_CSTD namespace std {
292 # define NAMESPACE_CPLX namespace std {
293 # define NAMESPACE_GRID
294 # define NAMESPACE_FD
295 # define NAMESPACE_END ;
296 # define NAMESPACE_STD_END }
297 # define NAMESPACE_CSTD_END }
298 # define NAMESPACE_CPLX_END }
302 # define USING_END using namespace std;
303 # define USING_STD using namespace std;
306 # define FRIEND_TBCI__
307 # define FRIEND_TCBI2__
311 # define MATH__ std::
312 # define CSTD__ std::
313 # define CPLX__ std::
317 # define NAMESPACE_TBCI namespace TBCI {
318 # define NAMESPACE_STD namespace std {
319 # define NAMESPACE_CSTD namespace std {
320 # define NAMESPACE_GRID namespace Grid {
321 # define NAMESPACE_FD namespace Finite_Difference {
322 # define NAMESPACE_CPLX namespace std {
323 # define NAMESPACE_END }
324 # define NAMESPACE_STD_END }
325 # define NAMESPACE_CSTD_END }
326 # define NAMESPACE_CPLX_END }
327 # define USING_TBCI using namespace TBCI;
328 # define USING_GRID using namespace Grid;
329 # define USING_FD using namespace Finite_Difference;
330 # define USING_END using namespace std;
331 # define USING_STD using namespace std;
332 # define TBCI__ TBCI::
333 # define __TBCI__ ::TBCI::
334 # define FRIEND_TBCI__
335 # define FRIEND_TBCI2__
336 # define GRID__ Grid::
339 # define MATH__ std::
340 # define CSTD__ std::
341 # define CPLX__ std::
353 # ifdef HAVE_LIBC_GLOBAL_NS_BUG
358 # undef NAMESPACE_CSTD
359 # define NAMESPACE_CSTD
360 # undef NAMESPACE_CSTD_END
361 # define NAMESPACE_CSTD_END
364 # ifdef HAVE_CPP_GLOBAL_NS_BUG
368 # define USING_STD using namespace;
369 # undef NAMESPACE_STD
370 # define NAMESPACE_STD
371 # undef NAMESPACE_STD_END
372 # define NAMESPACE_STD_END
375 # ifdef HAVE_CPLX_GLOBAL_NS_BUG
378 # undef NAMESPACE_CPLX
379 # define NAMESPACE_CPLX
380 # undef NAMESPACE_CPLX_END
381 # define NAMESPACE_CPLX_END
387 # if defined(HAVE_LIBC_GLOBAL_NS_BUG) && !defined(HAVE_CPP_GLOBAL_NS_BUG)
388 # define HAVE_LIBC_NEQ_CPP_BUG
390 # if defined(HAVE_LIBC_GLOBAL_NS_BUG) && !defined(HAVE_CPLX_GLOBAL_NS_BUG)
391 # define HAVE_LIBC_NEQ_CPLX_BUG
396 # if (HAVE_FRIEND_GLOBAL_NS_BUG || HAVE_NEED_FOR_FRIEND_SCOPE) && !defined(AUTO_DECL) && !defined(NO_NS_TBCI)
397 # undef FRIEND_TBCI__
398 # define FRIEND_TBCI__ TBCI::
399 # ifdef HAVE_FRIEND_GLOBAL_NS_BUG
400 # undef FRIEND_TBCI2__
401 # define FRIEND_TBCI2__ TBCI::
409 # define ABORT_RET(x) abort ()
410 # define ABORT_RET_NR abort ()
412 # define ABORT_RET(x) return x
413 # define ABORT_RET_NR do {} while (0)
424 # define MIN_ALIGN2 16
428 #if defined(HAVE_ALIGN_ATTR) || defined(HAVE_NEW_ALIGN_ATTR)
429 # ifdef HAVE_NEW_ALIGN_ATTR
430 # define ALIGN3(v,i,x) v __attribute__ ((aligned(x))) (i)
432 # define ALIGN3(v,i,x) v(i) __attribute__ ((aligned(x)))
434 # define ALIGN2(v,x) v __attribute__ ((aligned(x)))
435 # define ALIGN(x) __attribute__ ((aligned(x)))
437 # ifdef HAVE_DECLSPEC_ALIGN
438 # define ALIGN3(v,i,x) __declspec(align(x)) v(i)
439 # define ALIGN2(v,x) __declspec(align(x)) v
440 # define ALIGN(x) __attribute__ ((aligned(x)))
442 # define ALIGN3(v,i,x) v(i)
443 # define ALIGN2(v,x) v
447 #ifdef HAVE_TEMPL_ALIGN_ATTR
448 # define TALIGN(x) ALIGN(x)
453 #ifdef HAVE_CONST_ATTR
454 # define CONSTA __attribute__ ((const))
455 # define TBCI_CONST(x) x __attribute__ ((const)); x
458 # define TBCI_CONST(x) x
460 #ifdef HAVE_REGPARM_ATTR
461 # define REGPARMA(n) __attribute__ ((regparm(n)))
462 # define REGPARM(n,x) x __attribute__ ((regparm(n))); x
465 # define REGPARM(n,x) x
468 #ifdef HAVE_UNUSED_ATTR
469 # define UNUSED __attribute__((unused))
475 #ifdef HAVE_WEAK_ATTR
476 # define WEAKA __attribute__ ((weak))
477 # define WEAK(x) x __attribute__ ((weak)); x
478 #ifdef __INTEL_COMPILER // Does not like that attr in templ specializations
481 # define TWEAK(x) x __attribute__ ((weak)); x
489 #if defined(HAVE_HOT_ATTR) && defined(USE_HOT)
490 # define HOT __attribute__ ((hot))
491 # define COLD __attribute__ ((cold))
492 # define HOTDECL(x) x __attribute__ ((hot)); x
493 # define COLDDECL(x) x __attribute__ ((cold)); x
497 # define HOTDECL(x) x
498 # define COLDDECL(x) x
503 #if !defined(NO_EXCEPT) && !defined(HAVE_BUGGY_EXCEPTIONS)
504 # include "tbci/except.h"
506 # define TBCI_DISABLE_EXCEPT
511 #ifndef HAVE_PRETTY_FUNCTION
512 # if defined(HAVE_FUNC) || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L)
513 # define __PRETTY_FUNCTION__ __func__
515 # define __PRETTY_FUNCTION__ "<unknown>"
520 #define TBCIERRH1 __PRETTY_FUNCTION__
521 #define TBCIERRM(cond,exc,txt,ind) \
522 STD__ string(#exc) + " in " + TBCIERRH1 + ":\n " + #txt + " at "\
523 + __FILE__ + ":" + TBCI__ ltoa(__LINE__) + ":\n (" + #cond \
524 + ") == TRUE! (" + #ind + " = " + TBCI__ ltoa(ind) + ")"
525 #define TBCIERRS(cond,exc,txt,ind) \
526 #exc << " in " << TBCIERRH1 << ":\n " << #txt << " at " \
527 << __FILE__ << ":" << __LINE__ << ":\n (" << #cond \
528 << ") == TRUE! (" << #ind << " = " << ind << ")"
531 #ifndef TBCI_NO_ERRCHECK
575 #define BCHK(cond,exc,txt,ind,rtval) \
577 if (UNLIKELY(__TBCI__ do_errcheck() && (cond))) { \
578 if (__TBCI__ do_except()) \
579 throw exc ((TBCIERRM(cond,exc,txt,ind)).c_str(), ind); \
581 STD__ cerr << TBCIERRS(cond,exc,txt,ind) << STD__ endl; \
582 if (__TBCI__ do_abort()) \
586 #define BCHKNR(cond,exc,txt,ind) \
587 if (UNLIKELY(__TBCI__ do_errcheck() && (cond))) { \
588 if (__TBCI__ do_except()) \
589 throw exc ((TBCIERRM(cond,exc,txt,ind)).c_str(), ind); \
591 STD__ cerr << TBCIERRS(cond,exc,txt,ind) << STD__ endl; \
592 if (__TBCI__ do_abort()) \
597 # warning Error checking disabled
599 # define BCHK(cond,exc,txt,ind,rtval) do {} while(0)
600 # define BCHKNR(cond,exc,txt,ind) do {} while(0)
605 #define EXPCHK(cond,exc,txt,ind,rtval) \
607 if (UNLIKELY(__TBCI__ do_expcheck() && (cond) )) { \
608 if (__TBCI__ do_except()) \
609 throw exc ((TBCIERRM(cond,exc,txt,ind)).c_str(), ind); \
611 STD__ cerr << TBCIERRS(cond,exc,txt,ind) << STD__ endl; \
612 if (__TBCI__ do_abort()) \
616 #define EXPCHKNR(cond,exc,txt,ind) \
617 if (UNLIKELY(__TBCI__ do_expcheck() && (cond) )) { \
618 if (__TBCI__ do_except()) \
619 throw exc ((TBCIERRM(cond,exc,txt,ind)).c_str(), ind); \
621 STD__ cerr << TBCIERRS(cond,exc,txt,ind) << STD__ endl; \
622 if (__TBCI__ do_abort()) \
626 # warning Expensive error checking enabled
630 # define EXPCHK(cond,exc,txt,ind,rtval) do {} while(0)
631 # define EXPCHKNR(cond,exc,txt,ind) do {} while(0)
635 #if defined(HAVE_ALGORITHM) && defined(HAVE_STD_MINMAX) &&!defined(HAVE_GCC_MINMAX)
636 # include <algorithm>
644 # ifdef HAVE_GCC_MINMAX
645 # define MIN(a,b) ((a) <? (b))
646 # define MAX(a,b) ((a) >? (b))
647 # elif defined(HAVE_STD_MINMAX)
648 # define MIN(a,b) std::min(a,b)
649 # define MAX(a,b) std::max(a,b)
655 # define MIN(a,b) ((a) < (b)? (a) : (b))
656 # define MAX(a,b) ((a) > (b)? (a) : (b))
662 # define INFO(x) cout << x
670 #if defined(RETVAL_OPT) && defined(HAVE_NAMED_RETVAL)
671 # define RET(x) return(x);
679 #if defined(_MSC_VER)
680 # define _VOID (void*)
687 #ifndef HAVE_BCXX_TEMPL_INLINE_MFUNC_BUG
688 # define INLINE inline
695 #if defined(_OPENMP) && !defined(TBCI_NO_OMP)
698 # define OMP_FOR _Pragma("omp parallel for")
699 # define OMP_FOR_REDUCE_F2 _Pragma("omp parallel for reduction(+:f2)")
700 # define OMP_FOR_REDUCE_F1F2 _Pragma("omp parallel for reduction(+:f1,f2)")
702 # define NOSMP_VECVEC
704 # define NOSMP_MATVEC
709 # define OMP_FOR_REDUCE_F2
710 # define OMP_FOR_REDUCE_F1F2
721 #if defined(HAVE_BUILTIN_PREFETCH) && !defined(NO_PREFETCH)
722 # define PREFETCH_R(addr,loc) __builtin_prefetch(addr, 0, loc )
723 # define PREFETCH_W(addr,loc) __builtin_prefetch(addr, 1, loc )
724 # define USE_PREFETCH 1
733 # if defined(__alpha__) && defined(AXP_PREFETCH) && !defined(NO_PREFETCH) && defined(__GNUC__)
734 # define PREFETCH_R(addr,loc) asm (" lda $31,%0 \n" : : "m" (*(addr)) )
735 # define PREFETCH_W(addr,loc) asm (" lda $31,%0 \n" : : "m" (*(addr)) )
736 # define USE_PREFETCH 1
738 # if defined(__i386__) && defined(SSE_PREFETCH) && !defined(NO_PREFETCH) && (defined(__GNUC__) || defined(__INTEL_COMPILER))
739 # define PREFETCH_R(addr,loc) asm (" prefetcht0 %0 \n" : : "m" (*(addr)) )
740 # define PREFETCH_W(addr,loc) asm (" prefetcht0 %0 \n" : : "m" (*(addr)) )
741 # define USE_PREFETCH 1
743 # if defined(__i386__) && defined(AMD_PREFETCH) && !defined(NO_PREFETCH) && (defined(__GNUC__) || defined(__INTEL_COMPILER))
744 # define PREFETCH_R(addr,loc) asm (" prefetch %0 \n" : : "m" (*(addr)) )
745 # define PREFETCH_W(addr,loc) asm (" prefetchw %0 \n" : : "m" (*(addr)) )
746 # define USE_PREFETCH 1
748 # define PREFETCH_R(addr,loc) do {} while (0)
749 # define PREFETCH_W(addr,loc) do {} while (0)
757 # define PREFETCH_R_MANY(addr,loc) \
758 for (char* _prefaddr = (char*)addr; _prefaddr < (char*)addr+CACHELINE_SZ*PREFETCH_AHEAD; _prefaddr += CACHELINE_SZ) \
759 PREFETCH_R(_prefaddr,loc)
760 # define PREFETCH_W_MANY(addr,loc) \
761 for (char* _prefaddr = (char*)addr; _prefaddr < (char*)addr+CACHELINE_SZ*PREFETCH_AHEAD; _prefaddr += CACHELINE_SZ) \
762 PREFETCH_W(_prefaddr,loc)
764 # define PREFETCH_R_MANY(addr,loc) do {} while(0)
765 # define PREFETCH_W_MANY(addr,loc) do {} while(0)
770 # define THREAD__ __thread
771 #elif defined(HAVE_DTLS)
772 # define THREAD__ __declspec(thread)
781 # define MAIN_PID (getpid())
782 # define num_threads (0)
784 # define ismainthread (1)
789 # define TBCI_SIMD_ALIGN 16
792 #ifdef USE_PLAIN_VEC_KERNELS
794 #elif defined(USE_UNR_VEC_KERNELS2)
812 template <
typename T>
828 # if defined(__GNUC__) && !defined(C_MEMALLOC_WE_KNOW_WHAT_WE_DO)
829 # warning "Don't define C_MEMALLOC if you use containers with elements which need intitalization"
830 # warning " or take care yourself ! (Read basics.h:690)"
832 # ifdef HAVE_MEMALIGN
833 # define NEW(t,s) (t*) memalign (sizeof(t)*MIN(4,s>>1), sizeof(t)*(s))
835 # define NEW(t,s) (t*) CSTD__ malloc (sizeof(t)*s)
837 # define TBCIDELETE(t,v,sz) do { BCHKNR(!v,NumErr,free null ptr,0); CSTD__ free (v); v = 0; } while (0)
838 # define TBCIDELETE_RO(t,v,sz) do { BCHKNR(!v,NumErr,free null ptr,0); CSTD__ free (v); } while (0)
839 # define REALLOC(v,os,t,s) v = (t*) CSTD__ realloc ((v), sizeof(t)*(s))
840 #elif !defined(NO_MALLOC_CACHE) //&& !defined(SMP)
842 # if defined(PRAGMA_I) && defined(PRAGMA_IMPL_MALLOC_CACHE)
843 # pragma implementation "malloc_cache.h"
848 # define NEW(t,s) new t[s]
849 # define TBCIDELETE(t,v,sz) do { BCHKNR(!v,NumErr,delete[] null ptr,0); delete[] _VOID v; v = 0; } while (0)
850 # define TBCIDELETE_RO(t,v,sz) do { BCHKNR(!v,NumErr,delete[] null ptr,0); delete[] _VOID v; } while (0)
852 # define REALLOC(v,os,t,s) do { \
854 if (LIKELY(s)) (v) = new t[(s)]; else (v) = 0; \
855 if (LIKELY(_tmp != (v) && _tmp && (v) && (os) && (s))) \
856 CSTD__ memcpy ((v), _tmp, sizeof(t)*MIN((os),(s))); \
857 if (LIKELY(_tmp)) delete[] (_tmp); \
860 # define REALLOC(v,os,t,s) do { \
862 if (LIKELY(s)) (v) = new t[(s)]; else (v) = 0; \
863 if (LIKELY(_tmp != (v) && _tmp && (v) && (os) && (s))) { \
864 for (REGISTER unsigned long _i = 0; _i < MIN((s),(os)); _i++) \
865 (v)[_i] = _tmp[_i]; } \
866 if (LIKELY(_tmp)) delete[] (_tmp); \
881 #if defined(C_MEMALLOC) || defined(ALLOW_MEMCPY)
882 # if defined(__GNUC__) && !defined(C_MEMALLOC_WE_KNOW_WHAT_WE_DO)
883 # warning "Don't define C_MEMALLOC or ALLOW_MEMCPY if you use containers with elements which"
884 # warning " use dynamic memory allocation or handle with pointers somehow. Copying otherwise"
885 # warning " will break things. (Read basics.h:740)"
887 # define TBCICOPY(n,o,t,s) CSTD__ memcpy ((n),(o),(s)*sizeof(t))
889 # define VEC_INLINE inline
890 # define COPY2(res,v1,f1,f2) res = v1
893 template <
typename T>
895 # define TBCICOPY(n,o,t,s) _par_copy < t > (s,n,o)
897 # define TBCICOPY(n,o,t,s) _tbci_copy < t > (s,n,o)
903 #if defined(C_MEMALLOC) || defined(ALLOW_MEMSET)
904 # define TBCICLEAR(n,t,s) CSTD__ memset ((n), 0, (s)*sizeof(t))
907 # define FILL1(res,f1,f2) res = f2
910 template <
typename T>
911 void _par_fill (
const unsigned long,
T *
const,
typename tbci_traits<T>::loop_const_refval_type);
912 # define TBCIFILL(n,v,t,s) _par_fill < t > (s,n,v)
913 # define TBCICLEAR(n,t,s) _par_fill < t > (s,n,t(0))
915 # define TBCIFILL(n,v,t,s) _tbci_fill < t > (s,n,v)
916 # define TBCICLEAR(n,t,s) _tbci_fill < t > (s,n,t(0))
921 template <
typename T>
924 T (*fn)(
const unsigned long idx,
void* par);
929 template <
typename T>
933 vec[
i] = fn.
fn(
i, par);
944 #if defined(C_MEMALLOC) || defined(ALLOW_MEMCMP)
945 # define TBCICOMP(n,o,t,s) CSTD__ memcmp ((n),(o),(s)*sizeof(t))
947 # define TBCIFILL(n,v,t,s) \
948 do { for (REGISTER unsigned long _i = 0; _i < (s); _i++) \
949 (n)[_i] = (t)(v); } while (0)
951 # if defined(__GNUG__) && !defined(PEDANTIC)
952 # define _TBCICOMP(n,o,t,s) ({ \
953 REGISTER int _r; REGISTER unsigned long _i; \
954 for (_r=0, _i=0; _i<(s) && !_r; _i++) { \
955 _r = (int)((n)[_i] != (o)[_i]); \
963 inline int _tbci_comp (
const unsigned long s,
T const *n,
T const *o))
966 for (
REGISTER unsigned long _i = 0; _i < (s); _i++)
967 if (
UNLIKELY((n)[_i] != (o)[_i]))
return 1;
970 # define TBCICOMP(n,o,t,s) _tbci_comp ((s),(n),(o))
975 #define COMP2(r,v1,f1,f2) if (r != v1) { ++f2; i = sz; goto _fin; }
979 template <
typename T>
980 int _par_comp (
const unsigned long sz,
const T* v1,
const T* v2);
981 # define TBCICOMP(n,o,t,s) _par_comp< t > (s, n, o)
983 # define TBCICOMP(n,o,t,s) ({ long res; do_vv_comp<t>(s,n,o,res); res; })
993 template <
typename T>
994 unsigned long _bin_search(
const T* vec,
T el,
unsigned long start,
unsigned long end)
996 if (end == start || end-1 == start)
997 return (
unsigned long)-1;
998 unsigned long half = (end+start)/2;
1012 template <
typename T>
1013 unsigned long bin_search(
const T* vec,
T el,
unsigned long start,
unsigned long end)
1016 return (
unsigned long)-1;
1017 if (vec[start] == el)
1019 else if (vec[end-1] == el)
1021 if (vec[start] > el)
1022 return (
unsigned long)-1;
1023 if (vec[end-1] < el)
1024 return (
unsigned long)-1;
1025 BCHK(vec[end-1] < vec[start],
NumErr, unsorted vector in
bin_search, end-1, (
unsigned long)-1);
1075 #ifdef HAVE_LONG_DOUBLE
1080 #ifdef HAVE_LONG_LONG
1088 #ifdef _INCLUDE_CPLX_H
1092 #ifdef _INCLUDE_STDCPLX_H
1096 #ifdef _INCLUDE_BUILTINCPLX_H
1104 #if defined(__INTEL_COMPILER) && (__INTEL_COMPILER == 600)
1105 template <
typename T>
inline int sign (
const T&
x)
1151 #ifdef TEMPLATED_FABSSQR
1155 # define FABSSQR(T) \
1156 TBCI_CONST(inline double fabssqr (const T a)) \
1157 { return CPLX__ real(a * CPLX__ conj(a)); }
1163 # ifdef HAVE_LONG_DOUBLE
1166 # ifdef HAVE_LONG_LONG
1173 #if defined(__INTEL_COMPILER) && (__INTEL_COMPILER == 600)
1174 template <
typename T>
inline T sqr (
const T&
a)
1181 #if !defined(HAVE_WIN_32) && !defined (NO_NS) // Problems with other dot
1182 # if defined(__INTEL_COMPILER) && (__INTEL_COMPILER == 600)
1183 template <
typename T>
inline T dot (
const T& a1,
const T& a2)
1197 {
return a<(
T)0?(
double)-a:(double)a; }
1203 TBCI_CONST(inline double fabs (const T a)) \
1204 { return a<(T)0?(double)-a:(double)a; }
1207 TBCI_CONST(inline double sqrt (const T a)) \
1208 { return MATH__ sqrt ((double)a); }
1210 # ifdef HAVE_LONG_DOUBLE
1211 # if defined(__GNUC__) && __GNUC__ == 2 && __GNUC_MINOR__ < 97
1220 # ifdef HAVE_LONG_LONG
1226 {
return (
double)
a; }
1237 {
return a<(
T)0?-a:a; }
1242 TBCI_CONST(inline T abs (const T a)) \
1243 { return a<(T)0?-a:a; }
1245 # ifdef HAVE_MISS_CSTD_ABS_BUG
1246 # ifdef HAVE_LONG_DOUBLE
1251 # ifdef HAVE_LONG_LONG
1257 # if 1 //defined(__INTEL_COMPILER) && (__INTEL_COMPILER == 600)
1265 #ifdef INLINE_VEC_KERNELS
1266 # define VEC_INLINE inline
1282 #ifndef _NO_INCLUDE_COST_H
1286 #if !defined(NO_NS) && defined (USING_STD_NS)
1295 using std::setprecision;
1298 using std::ifstream;
1299 using std::ofstream;
1301 # if defined(HAVE_SSTREAM) && !defined(HAVE_BUGGY_SSTREAM)
1302 using std::istringstream;
1303 using std::ostringstream;
1305 using std::istrstream;
1306 using std::ostrstream;
macros for composing unrolled prefetching loops over arrays.
const Vector< T > const Vector< T > & x
int _par_comp(const unsigned long sz, const T *v1, const T *v2)
void _tbci_fill(const unsigned long sz, T *const res, register typename tbci_traits< T >::loop_const_refval_type f2)
Wrapper for GCC's builtin complex type plus compatibility features (helper class TBCI::hcplx) ...
unsigned long bin_search(const T *vec, T el, unsigned long start, unsigned long end)
Search for an element el in a sorted vector between start and end-1, returns (unsigned long)-1 if ele...
#define COMP2(r, v1, f1, f2)
Caches memory blocks to avoid calls to __builtin_free()/new() It performs very well for strictly recu...
exception base class for the TBCI NumLib
macros for composing plain loops over arrays.
#define COPY2(res, v1, f1, f2)
#define FILL1(res, f1, f2)
#define BCHK(cond, exc, txt, ind, rtval)
#define NAMESPACE_CSTD_END
Preprocessor macros for estimating the "cost" of operations.
void _par_copy(const unsigned long sz, T *v1, const T *v2)
#define VKERN_TEMPL_2V_T(FNAME, OP2, TYPE)
Operations of type TYPE = VEC OP VEC.
T arg(const TBCI__ cplx< T > &c)
void _par_fill(const unsigned long, T *const, typename tbci_traits< T >::loop_const_refval_type)
unsigned long _bin_search(const T *vec, T el, unsigned long start, unsigned long end)
Search for an element el in a sorted vector between start and end-1, returns (unsigned long)-1 if ele...
#define VKERN_TEMPL_2V(FNAME, OP2)
Operations of type vec OP= vec.
cplx< T > sqr(const cplx< T > &c)
int conj(const int arg)
conj for elementary types
int sign(const T &x)
Signum.
void SWAP(T &a, T &b)
SWAP function Note: We could implement a swap function without temporaries: a -= b b += a a -= b a = ...
T dot(const T &a1, const T &a2)
#define VKERN_TEMPL_1V_C(FNAME, OP1)
Operations of type VEC OP= VAL.
#define NAMESPACE_CPLX_END
Wrapper for C++ std library complex type plus compatibility features.
Rich implementation of complex numbers TBCI::cplx.
T(* fn)(const unsigned long idx, void *par)
_vararg
This is a helper type to identify and count varargs.
This provides some parameters that control the behavior of various functions in the TBCI library...
macros for composing unrolled prefetching loops over arrays.
double fabssqr(const double a)
const unsigned TMatrix< T > const Matrix< T > * a
void do_vv_comp(const unsigned long sz, const T *const v1, const T *const v2, volatile long &_f2)
f2 = number of differences vec, vec
#define LIKELY(expr)
branch prediction note that we sometimes on purpose mark the unlikely possibility likely and vice ver...
void _tbci_fill_fn(const unsigned long sz, T *vec, vec_fill_fn< T > fn, void *par)
void _tbci_copy(const unsigned long sz, T *const res, const T *const v1)