vxl_platform_tests.cxx
来自「DTMK软件开发包,此为开源软件,是一款很好的医学图像开发资源.」· CXX 代码 · 共 1,194 行 · 第 1/2 页
CXX
1,194 行
//-------------------------------------
#ifdef VCL_SUNPRO_CLASS_SCOPE_HACK
// VCL_SUNPRO_CLASS_SCOPE_HACK(A) is set to ", A" if this fails to compile, to "" otherwise
template < class T >
struct allocator
{
allocator() {}
allocator(const allocator<T>& ) {}
};
template < class T , class Allocator = allocator < T > >
struct vector
{
vector() {}
~vector() {}
};
template < class T >
struct spoof
{
void set_row( unsigned , vector < T /*, allocator<T>*/ > const & );
};
template < class T >
void spoof < T > :: set_row( unsigned , vector < T /*, allocator<T>*/ > const & )
{
}
template class spoof < double >;
// If the program compiles, we don't need the hack
int main() { return 0; }
#endif // VCL_SUNPRO_CLASS_SCOPE_HACK
//-------------------------------------
#ifdef VCL_HAS_EXCEPTIONS
struct bizop {};
int functionella(char const *a, char const *b)
{
if (!a && b)
throw "a is no good";
if ( a && !b)
throw "b is no better";
if (!a && !b)
throw bizop();
return *a - *b;
}
void monkeylette()
{
try {
functionella( 0, 0);
functionella("a", 0);
functionella( 0, "b");
functionella("a", "b");
}
catch (char const *s) {
// oops.
}
catch (bizop b) {
// outch
}
catch (...) {
// phew
}
}
int main() { return 0; }
#endif // VCL_HAS_EXCEPTIONS
//-------------------------------------
#ifdef VCL_HAS_NAMESPACES
namespace foo {
int hello() { return 10; }
};
// 7.3.1
namespace Outer {
int i;
namespace Inner {
void f() { i++; } // Outer::i
int i;
void g() { i++; } // Inner::i
}
}
// 7.3.1.1
namespace { int i; } // unique::i
void f() { i++; } // unique::i (gcc 2.7.2 fails here).
namespace A {
namespace {
int i; // A::unique::i
int j; // A::unique::j
}
void g() { i++; } // A::unique::i
}
using namespace A;
void h() {
//i++; // error: unique::i or A::unique::i
A::i++; // A::unique::i
j++; // A::unique::j
}
extern "C" double vxl_sqrt(double){return 0;}
namespace foo {
template <class T> struct complex { T re, im; };
template <class T> T abs(complex<T> const &z) { return T(::vxl_sqrt(double(z.re*z.re + z.im+z.im))); }
}
namespace bar {
int abs(int){return 0;}
long abs(long){return 0;}
float abs(float){return 0;}
double abs(double){return 0;}
}
namespace diced {
using foo::complex; // <-- I'm told vc60 fails here.
using foo::abs;
using bar::abs;
}
extern "C" int printf(char const *, ...);
void flegg() {
int a = -1;
long b = -2;
float c = -3;
double d = -4;
diced::complex<double> e = { 3, 4 };
printf("%d\n", diced::abs(a)); // 1
printf("%ld\n", diced::abs(b)); // 2
printf("%f\n", diced::abs(c)); // 3
printf("%lf\n", diced::abs(d)); // 4
printf("%lf\n", diced::abs(e)); // 5
}
int main() { return 0; }
#endif // VCL_HAS_NAMESPACES
//-------------------------------------
#ifdef VCL_ALLOWS_NAMESPACE_STD
#include <cmath>
#include <vector>
#include <iostream>
void function() {
std::vector<double> flaz;
flaz.push_back(std::sqrt(2.0));
flaz.push_back(std::fabs(1.0f));
std::cerr << "hello, std::world" << std::endl;
}
int main() { return 0; }
#endif // VCL_ALLOWS_NAMESPACE_STD
//-------------------------------------
#ifdef VCL_NEEDS_NAMESPACE_STD
// VCL_NEEDS_NAMESPACE_STD is set to 1 if this fails to compile
#include <cmath>
#include <vector>
//#include <iostream>
void function() {
vector<double> flaz; // correct should be: std::vector<double>
flaz.push_back(sqrt(2.0)); // should be: std::sqrt(2.0)
flaz.push_back(fabs(1.0f)); // should be: std::fabs(1.0)
//cerr << "hello, world" << endl;
}
int main() { return 0; }
#endif // VCL_NEEDS_NAMESPACE_STD
//-------------------------------------
#ifdef VXL_UNISTD_USLEEP_IS_VOID
// VXL_UNISTD_USLEEP_IS_VOID is set to 1 if this test fails
#include <unistd.h>
int main() { int x = usleep(0); return x*0; }
#endif // VXL_UNISTD_USLEEP_IS_VOID
//-------------------------------------
#ifdef VXL_STDLIB_HAS_QSORT
// This is not a C++ header, strictly speaking.
// Actually, it is normative but deprecated, strictly speaking :)
#include <stdlib.h>
int f(const void *a,const void *b) { return 1; }
int main() { int a[5]; qsort(a, 5, sizeof(int), f); return 0; }
#endif // VXL_STDLIB_HAS_QSORT
//-------------------------------------
#ifdef VCL_COMPLEX_POW_WORKS
// It appears several programmers have (independently)
// not realised their lack of knowledge of complex numbers.
// pow(complex(-1,0),0.5) should return (0,1) not (Nan,0), etc.
#include <complex>
int main()
{
const std::complex<double> neg1(-1.0, 0.0);
const std::complex<double> half(0.5,0.0);
const std::complex<double> i(0.0, 1.0);
std::complex<double> sqrt_neg1 = std::pow(neg1, 0.5);
double error = std::abs(sqrt_neg1-i);
// Need to be careful of quiet NANs, and dodgy behaviour on some platforms.
// It woud be much easier if I could just have a reliable test for NaNs
// which are produced by all the broken pow()s I've seen. IMS
if ( error >= 0 && -error > -1e-6)
{}
else
return 1;
if (error != error)
return 1;
sqrt_neg1 = std::pow(neg1, half);
error = std::abs(sqrt_neg1-i);
if ( error >= 0 && -error > -1e-6)
{}
else
return 1;
if (error != error)
return 1;
sqrt_neg1 = std::pow(-1.0, half);
error = std::abs(sqrt_neg1-i);
if ( error >= 0 && -error > -1e-6)
{}
else
return 1;
if (error != error)
return 1;
return 0; // success
}
#endif // VCL_COMPLEX_POW_WORKS
//-------------------------------------
#ifdef VCL_NUMERIC_LIMITS_HAS_INFINITY
// Does vcl_numeric_limits<float>::has_infinity == 1?
// Several versions of gcc (3.0, 3.1, and 3.2) come with a
// numeric_limits that reports that they have no infinity.
#include <limits>
int main() {
return std::numeric_limits<double>::has_infinity &&
std::numeric_limits<float>::has_infinity ? 0 : 1;
}
#endif // VCL_NUMERIC_LIMITS_HAS_INFINITY
//-------------------------------------
#ifdef VCL_PROCESSOR_HAS_INFINITY
// Does the processor actually have an infinity?
// The Borland 5.5 defines DBL_MAX as _max_dble but only declares
// _max_dble in the std namespace if we include <cfloag>. Including
// <float.h> moves _max_dble to the global namespace and allows the
// DBL_MAX macro to work.
#include <float.h>
union u { double d; unsigned char c[8]; };
int main()
{
if (sizeof(double) != 8) return 1; // If you have an odd machine, then add
// your own construction of infinity.
u v;
// Can we generate an IEEE infinity artifically on a big-endian machine?
v.c[0] = 0x7f; v.c[1] = 0xf0;
v.c[2] = v.c[3] = v.c[4] = v.c[5] = v.c[6] = v.c[7] = 0x00;
if (v.d > DBL_MAX)
return 0;
// Can we generate an IEEE infinity artifically on a little-endian machine?
v.c[7] = 0x7f; v.c[6] = 0xf0;
v.c[0] = v.c[1] = v.c[2] = v.c[3] = v.c[4] = v.c[5] = 0x00;
if (v.d > DBL_MAX)
return 0;
return 1;
}
#endif // VCL_PROCESSOR_HAS_INFINITY
//-------------------------------------
#ifdef VCL_CANNOT_SPECIALIZE_CV
// VCL_CANNOT_SPECIALIZE_CV is set to 1 if this fails to compile
// Some compilers do not distinguish between A<int> and A<int const>.
template <class T> struct A;
#if !defined(NOT_CONFORMING_SPECIALIZATION)
template <> struct A<int> {};
template <> struct A<int const> {};
#else
struct A<int> {};
struct A<int const> {};
#endif // VCL_CANNOT_SPECIALIZE_CV
int main() { return 0; }
#endif
//-------------------------------------
#ifdef VCL_TEMPLATE_MATCHES_TOO_OFTEN
// VCL_TEMPLATE_MATCHES_TOO_OFTEN is set to 1 if this fails to compile
// Some compilers will incorrectly choose the template over the
// non-template. This will not compile if the template is chosen,
// which will reveal the bug.
class A {};
template <class T> void f(T t) { t.compiler_selected_wrong_overload(); }
void f(const A&) {}
int main()
{
f(A());
return 0;
}
#endif // VCL_TEMPLATE_MATCHES_TOO_OFTEN
//-------------------------------------
#ifdef VCL_HAS_SLICED_DESTRUCTOR_BUG
// VCL_HAS_SLICED_DESTRUCTOR_BUG is set to 1 if this program exist(1)s
// Some compilers (at least Intel C++ 7) will create a B temporary on
// the f(c) line below and call both the A and B constructors, but
// then destroy the temporary by calling only ~A() and not calling
// ~B() first (or ever). This program will return 1 if the bug exists
// and 0 otherwise.
#include <stdlib.h>
struct A
{
A(): mark(0) {}
A(const A&): mark(0) {}
~A() { if (mark) { exit(1); } }
int mark;
};
struct B: public A
{
B(): A() {}
B(const B& b): A(b) { mark = 1; }
~B() { mark = 0; }
};
struct C
{
operator B () { return B(); }
};
void f(A) {}
int main()
{
C c;
f(c);
return 0;
}
#endif // VCL_HAS_SLICED_DESTRUCTOR_BUG
//-------------------------------------
#ifdef VCL_HAS_WORKING_STRINGSTREAM
// VCL_HAS_WORKING_STRINGSTREAM is set to 1 if a fully functional std::stringstream is found.
// Some compilers don't provide a fully functional std::stringstream.
// This program will return 0 whenever sufficient functionality is detected.
#include <sstream>
int main()
{
std::istringstream s1("text"); char c;
s1 >> c; if (c != 't') return 1;
s1 >> c; if (c != 'e') return 1;
s1 >> c; if (c != 'x') return 1;
std::ostringstream s2; s2 << "text";
if (s2.str() != "text") return 1;
std::ostringstream s3;
c = 't'; s3 << c;
c = 'e'; s3 << c;
c = 'x'; s3 << c;
c = 't'; s3 << c;
if (s3.str() != "text") return 1;
return 0; // success
}
#endif // VCL_HAS_WORKING_STRINGSTREAM
//-------------------------------------
#ifdef VXL_HAS_TYPE_OF_SIZE
// This is used to check if (1) a type exists, (2) is has the required
// size in bytes, and (3) it is functional. The last requirement is
// driven by MSCV 6 which has __int64, but it is not fully
// functional. (It can't be cast to a double, for example.)
// CHAR_BIT is the number of bits per char.
#include <limits.h>
#ifndef CHAR_BIT
# define CHAR_BIT 8
#endif
#include "config.h"
#if INTEGRAL_TYPE
double cast( THE_TYPE a, unsigned THE_TYPE b, signed THE_TYPE c )
{
return double( a ) + double( b ) + double( c );
}
#else // INTEGRAL_TYPE
double cast( THE_TYPE a )
{
return double( a );
}
#endif // INTEGRAL_TYPE
int main()
{
return sizeof(THE_TYPE) * CHAR_BIT == THE_SIZE ? 0 : 1;
}
#endif // VXL_HAS_TYPE_OF_SIZE
//-------------------------------------
#ifdef VCL_CHAR_IS_SIGNED
// Return 0 for char signed and 1 for char unsigned.
int main()
{
unsigned char uc = 255;
return (*reinterpret_cast<char*>(&uc) < 0)?0:1;
}
#endif // VCL_CHAR_IS_SIGNED
//-------------------------------------
#ifdef VXL_C_MATH_HAS_LROUND
// This C99 func is a much faster version of standard vnl_math_round
#include <cmath>
int main() { long c = lround(100.0); }
#endif // VXL_C_MATH_HAS_LROUND
//-------------------------------------
#ifdef VCL_HAS_LFS
// Return 1 if compiler has #define-switchable Large File Support
#define _LARGEFILE_SOURCE
#define _FILE_OFFSET_BITS 64
#include <fstream>
#include <iostream>
int main(int argc, char * argv[])
{
if( sizeof(std::streamoff)==8 )
return 0 ;
else
return 1;
}
#endif // VCL_HAS_LFS
//-------------------------------------
#ifdef VXL_HAS_DBGHELP_H
// This is a Windows header, and needs windows.h included first to make it compile properly.
#include <Windows.h>
#include <DbgHelp.h>
int main() { MINIDUMP_EXCEPTION_INFORMATION dummy; return 0; }
#endif // VXL_HAS_DBGHELP_H
//-------------------------------------
#ifdef VXL_APPLE_HAS_ISNAND
#include <math.h>
int main()
{
__isnand(0.0);
return 0;
}
#endif // VXL_APPLE_HAS_ISNAND
//-------------------------------------
#ifdef VXL_APPLE_HAS_INLINE_ISNAND
#include <math.h>
int main()
{
__inline_isnand(0.0);
return 0;
}
#endif // VXL_APPLE_HAS_INLINE_ISNAND
//-------------------------------------
#ifdef VXL_HAS_MM_MALLOC
#include <emmintrin.h>
int main()
{
void* x = _mm_malloc(4*sizeof(float),16);
_mm_free(x);
return 0;
}
#endif
//-------------------------------------
#ifdef VXL_HAS_ALIGNED_MALLOC
#include <malloc.h>
int main()
{
void* x = _aligned_malloc(4*sizeof(float),16);
_aligned_free(x);
return 0;
}
#endif
//-------------------------------------
#ifdef VXL_HAS_MINGW_ALIGNED_MALLOC
#include <malloc.h>
int main()
{
void* x = __mingw_aligned_malloc(4*sizeof(float),16);
__mingw_aligned_free(x);
return 0;
}
#endif
//-------------------------------------
#ifdef VXL_HAS_POSIX_MEMALIGN
#include <cstdlib>
int main()
{
void* x = memalign(16,4*sizeof(float));
free(x);
return 0;
}
#endif
//-------------------------------------
#ifdef VXL_HAS_SSE2_HARDWARE_SUPPORT
#include <emmintrin.h>
int main()
{
//try to do some sse2 calculations
double d_a[] = { 6.75, 3.42 };
double d_b[] = { 2.3, 9.2 };
double res[2] = {0.0};
__m128d z;
z = _mm_mul_pd(_mm_loadu_pd(d_a),_mm_loadu_pd(d_b));
_mm_storeu_pd(res,z);
return 0;
}
#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?