Index: CMakeLists.txt =================================================================== --- CMakeLists.txt +++ CMakeLists.txt @@ -2,7 +2,6 @@ include(CheckSymbolExists) - project(test-suite C CXX) if("Fortran" IN_LIST TEST_SUITE_SUBDIRS) @@ -233,6 +232,8 @@ endif() endif() +include(HandleCompilerRT) + include(TestSuite) include(SingleMultiSource) # Needs by External/sollve_vv. Index: SingleSource/Benchmarks/BenchmarkGame/Large/fasta.c =================================================================== --- SingleSource/Benchmarks/BenchmarkGame/Large/fasta.c +++ SingleSource/Benchmarks/BenchmarkGame/Large/fasta.c @@ -7,7 +7,8 @@ #include #include #include -#ifndef _AIX + +#if !defined(_AIX) && !defined(_WIN32) #include #endif Index: SingleSource/Benchmarks/CMakeLists.txt =================================================================== --- SingleSource/Benchmarks/CMakeLists.txt +++ SingleSource/Benchmarks/CMakeLists.txt @@ -10,5 +10,7 @@ add_subdirectory(Polybench) add_subdirectory(Shootout) add_subdirectory(Shootout-C++) -add_subdirectory(SmallPT) add_subdirectory(Stanford) +if(NOT TARGET_OS STREQUAL "Windows") +add_subdirectory(SmallPT) # Depends on erand48 +endif() Index: SingleSource/Benchmarks/McGill/misr.c =================================================================== --- SingleSource/Benchmarks/McGill/misr.c +++ SingleSource/Benchmarks/McGill/misr.c @@ -40,9 +40,14 @@ #define TRUE 1 #define FALSE 0 -#ifdef __MINGW32__ -# define seed48(x) srand(x) -# define lrand48() ((rand() << 16) ^ (rand())) +#if defined(_WIN32) +#define seed48(seed) \ + do { \ + unsigned int combined_seed = ((seed)[0] << 16) ^ ((seed)[1] << 8) ^ (seed)[2]; \ + srand(combined_seed); \ + } while (0) + +#define lrand48() ((rand() << 16) ^ (rand())) #endif int reg_len; Index: SingleSource/Benchmarks/Misc-C++-EH/spirit.cpp =================================================================== --- SingleSource/Benchmarks/Misc-C++-EH/spirit.cpp +++ SingleSource/Benchmarks/Misc-C++-EH/spirit.cpp @@ -5241,7 +5241,12 @@ }; }} #include +#ifdef _WIN32 +#include +#include +#else #include +#endif namespace boost { namespace detail @@ -5259,34 +5264,54 @@ class lightweight_mutex { private: - pthread_mutex_t m_; +#ifdef _WIN32 + std::mutex m_; +#else + pthread_mutex_t m_; +#endif lightweight_mutex(lightweight_mutex const &); lightweight_mutex & operator=(lightweight_mutex const &); public: lightweight_mutex() { +#ifndef _WIN32 pthread_mutex_init(&m_, 0); +#endif } ~lightweight_mutex() { +#ifndef _WIN32 pthread_mutex_destroy(&m_); +#endif } class scoped_lock; friend class scoped_lock; class scoped_lock { private: - pthread_mutex_t & m_; +#ifdef _WIN32 + std::mutex &m_; +#else + pthread_mutex_t & m_; +#endif scoped_lock(scoped_lock const &); scoped_lock & operator=(scoped_lock const &); public: scoped_lock(lightweight_mutex & m): m_(m.m_) { - pthread_mutex_lock(&m_); +#ifdef _WIN32 + m_.lock(); +#else + pthread_mutex_lock(&m_); +#endif } ~scoped_lock() { - pthread_mutex_unlock(&m_); +#ifdef _WIN32 + m_.unlock(); +#else + pthread_mutex_unlock(&m_); +#endif } }; }; Index: SingleSource/Benchmarks/Misc-C++/Large/sphereflake.cpp =================================================================== --- SingleSource/Benchmarks/Misc-C++/Large/sphereflake.cpp +++ SingleSource/Benchmarks/Misc-C++/Large/sphereflake.cpp @@ -40,7 +40,7 @@ // Simplified Taylor series static double LLVMsin(double d) { - double sign = 1.0; + double sign = 1.0; /* move into 2PI area */ while (d < 0) @@ -228,6 +228,10 @@ } }; +#ifndef M_PI +#define M_PI 3.14159265358979323846264338327950288 +#endif + static node_t *create(node_t*n,const int lvl,int dist,v_t c,v_t d,double r) { n = 1 + new (n) node_t(sphere_t(c,2.*r),sphere_t(c,r), lvl > 1 ? dist : 1); if (lvl <= 1) Index: SingleSource/Benchmarks/Misc/CMakeLists.txt =================================================================== --- SingleSource/Benchmarks/Misc/CMakeLists.txt +++ SingleSource/Benchmarks/Misc/CMakeLists.txt @@ -1,4 +1,10 @@ -list(APPEND LDFLAGS -lm ) +if(TARGET_OS STREQUAL "Windows") + find_compiler_rt_library(COMPILER_RT_BUILTINS_LIBRARY) + list(APPEND LDFLAGS ${COMPILER_RT_BUILTINS_LIBRARY}) +else() + list(APPEND LDFLAGS -lm ) +endif() + list(APPEND CFLAGS -Wno-implicit-int) set(FP_TOLERANCE 0.001) set(Source @@ -18,7 +24,6 @@ fp-convert.c himenobmtxpa.c lowercase.c - mandel-2.c mandel.c matmul_f64_4x4.c oourafft.c @@ -29,6 +34,9 @@ salsa20.c whetstone.c ) +if(NOT TARGET_OS STREQUAL "Windows") + list(APPEND Source mandel-2.c) +endif() if(NOT ARCH STREQUAL "PowerPC" OR NOT TARGET_OS STREQUAL "Darwin") list(APPEND Source dt.c) endif() Index: SingleSource/Benchmarks/Misc/ReedSolomon.c =================================================================== --- SingleSource/Benchmarks/Misc/ReedSolomon.c +++ SingleSource/Benchmarks/Misc/ReedSolomon.c @@ -424,7 +424,7 @@ #define LENGTH 150000 #endif -#ifdef __MINGW32__ +#if defined(__MINGW32__) || defined(_WIN32) #define random() rand() #endif Index: SingleSource/Benchmarks/Misc/dt.c =================================================================== --- SingleSource/Benchmarks/Misc/dt.c +++ SingleSource/Benchmarks/Misc/dt.c @@ -31,8 +31,14 @@ double *dvec1, *dvec2; long i; +#ifdef _WIN32 + dvec1 = _aligned_malloc(size * sizeof(double), 16); + dvec2 = _aligned_malloc(size * sizeof(double), 16); +#else posix_memalign((void**)&dvec1, 16, size * sizeof(double)); posix_memalign((void**)&dvec2, 16, size * sizeof(double)); +#endif + printf( " %i iterations of each test. ", ITERATIONS ); printf( " inner loop / array size %i.\n", size ); @@ -46,6 +52,14 @@ double_array_divs_variable( dvec1, dvec2 ); printf("%f\n", dvec1[0]); + +#ifdef _WIN32 + _aligned_free(dvec1); + _aligned_free(dvec2); +#else + free(dvec1); + free(dvec2); +#endif return 0; } Index: SingleSource/Benchmarks/Misc/flops.c =================================================================== --- SingleSource/Benchmarks/Misc/flops.c +++ SingleSource/Benchmarks/Misc/flops.c @@ -980,7 +980,7 @@ /* Another UNIX timer using gettimeofday(). */ /* However, getrusage() is preferred. */ /********************************************/ -#if defined(GTODay) && !defined(__MINGW32__) +#if defined(GTODay) && !defined(__MINGW32__) && !defined(_WIN32) #include struct timeval tnow; Index: SingleSource/Benchmarks/Misc/himenobmtxpa.c =================================================================== --- SingleSource/Benchmarks/Misc/himenobmtxpa.c +++ SingleSource/Benchmarks/Misc/himenobmtxpa.c @@ -39,7 +39,12 @@ #include #include #include + +#ifndef _WIN32 #include +#else +#include +#endif #define MR(mt,n,r,c,d) mt->m[(n) * mt->mrows * mt->mcols * mt->mdeps + (r) * mt->mcols* mt->mdeps + (c) * mt->mdeps + (d)] @@ -300,8 +305,23 @@ static int base_sec = 0,base_usec = 0; +#ifndef _WIN32 gettimeofday(&tm, NULL); - +#else + FILETIME ft; + ULARGE_INTEGER uli; + + GetSystemTimeAsFileTime(&ft); + uli.LowPart = ft.dwLowDateTime; + uli.HighPart = ft.dwHighDateTime; + + // Convert to microseconds (1 microsecond = 10^-6 seconds) + uli.QuadPart /= 10ULL; // Divide by 10 to convert 100ns intervals to microseconds + + tm.tv_sec = (long)((uli.QuadPart - 11644473600000000ULL) / 1000000ULL); // Convert to Unix timestamp + tm.tv_usec = (long)(uli.QuadPart % 1000000ULL); +#endif + if(base_sec == 0 && base_usec == 0) { base_sec = tm.tv_sec; Index: SingleSource/Benchmarks/Misc/oourafft.c =================================================================== --- SingleSource/Benchmarks/Misc/oourafft.c +++ SingleSource/Benchmarks/Misc/oourafft.c @@ -4,7 +4,7 @@ #include /* memalign */ #if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__NetBSD__) && \ - !defined(__OpenBSD__) && !defined(_AIX) + !defined(__OpenBSD__) && !defined(_AIX) && !defined(_WIN32) #include #endif @@ -41,7 +41,7 @@ /* Prepare aux data */ /* Darwin always 16-byte aligns malloc data */ #if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__NetBSD__) && \ - !defined(__OpenBSD__) && !defined(_AIX) + !defined(__OpenBSD__) && !defined(_AIX) && !defined(_WIN32) ip = memalign(16, sqrt(N)*sizeof(int)); w = memalign(16, 2*N*5/4*sizeof(double)); #else @@ -53,7 +53,7 @@ /* Allocate buffers */ /* Darwin always 16-byte aligns malloc data */ #if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__NetBSD__) && \ - !defined(__OpenBSD__) && !defined(_AIX) + !defined(__OpenBSD__) && !defined(_AIX) && !defined(_WIN32) ref = memalign(16, 2*N*sizeof(double)); cmp = memalign(16, 2*N*sizeof(double)); src = memalign(16, 2*N*sizeof(double)); @@ -142,7 +142,8 @@ return err; } -#ifdef WIN32 +#ifdef _WIN32 +#undef N #include static LARGE_INTEGER t = {0, 0}; Index: SingleSource/Benchmarks/Polybench/datamining/correlation/correlation.c =================================================================== --- SingleSource/Benchmarks/Polybench/datamining/correlation/correlation.c +++ SingleSource/Benchmarks/Polybench/datamining/correlation/correlation.c @@ -6,7 +6,6 @@ * Web address: http://polybench.sourceforge.net */ #include -#include #include #include Index: SingleSource/Benchmarks/Polybench/datamining/covariance/covariance.c =================================================================== --- SingleSource/Benchmarks/Polybench/datamining/covariance/covariance.c +++ SingleSource/Benchmarks/Polybench/datamining/covariance/covariance.c @@ -6,7 +6,6 @@ * Web address: http://polybench.sourceforge.net */ #include -#include #include #include Index: SingleSource/Benchmarks/Polybench/linear-algebra/kernels/2mm/2mm.c =================================================================== --- SingleSource/Benchmarks/Polybench/linear-algebra/kernels/2mm/2mm.c +++ SingleSource/Benchmarks/Polybench/linear-algebra/kernels/2mm/2mm.c @@ -6,7 +6,6 @@ * Web address: http://polybench.sourceforge.net */ #include -#include #include #include Index: SingleSource/Benchmarks/Polybench/linear-algebra/kernels/3mm/3mm.c =================================================================== --- SingleSource/Benchmarks/Polybench/linear-algebra/kernels/3mm/3mm.c +++ SingleSource/Benchmarks/Polybench/linear-algebra/kernels/3mm/3mm.c @@ -6,7 +6,6 @@ * Web address: http://polybench.sourceforge.net */ #include -#include #include #include Index: SingleSource/Benchmarks/Polybench/linear-algebra/kernels/atax/atax.c =================================================================== --- SingleSource/Benchmarks/Polybench/linear-algebra/kernels/atax/atax.c +++ SingleSource/Benchmarks/Polybench/linear-algebra/kernels/atax/atax.c @@ -6,7 +6,6 @@ * Web address: http://polybench.sourceforge.net */ #include -#include #include #include @@ -17,6 +16,9 @@ /* Default data type is double, default size is 4000. */ #include "atax.h" +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif /* Array initialization. */ static Index: SingleSource/Benchmarks/Polybench/linear-algebra/kernels/bicg/bicg.c =================================================================== --- SingleSource/Benchmarks/Polybench/linear-algebra/kernels/bicg/bicg.c +++ SingleSource/Benchmarks/Polybench/linear-algebra/kernels/bicg/bicg.c @@ -6,7 +6,6 @@ * Web address: http://polybench.sourceforge.net */ #include -#include #include #include @@ -17,6 +16,9 @@ /* Default data type is double, default size is 4000. */ #include "bicg.h" +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif /* Array initialization. */ static Index: SingleSource/Benchmarks/Polybench/linear-algebra/kernels/cholesky/cholesky.c =================================================================== --- SingleSource/Benchmarks/Polybench/linear-algebra/kernels/cholesky/cholesky.c +++ SingleSource/Benchmarks/Polybench/linear-algebra/kernels/cholesky/cholesky.c @@ -6,7 +6,6 @@ * Web address: http://polybench.sourceforge.net */ #include -#include #include #include Index: SingleSource/Benchmarks/Polybench/linear-algebra/kernels/doitgen/doitgen.c =================================================================== --- SingleSource/Benchmarks/Polybench/linear-algebra/kernels/doitgen/doitgen.c +++ SingleSource/Benchmarks/Polybench/linear-algebra/kernels/doitgen/doitgen.c @@ -6,7 +6,6 @@ * Web address: http://polybench.sourceforge.net */ #include -#include #include #include Index: SingleSource/Benchmarks/Polybench/linear-algebra/kernels/gemm/gemm.c =================================================================== --- SingleSource/Benchmarks/Polybench/linear-algebra/kernels/gemm/gemm.c +++ SingleSource/Benchmarks/Polybench/linear-algebra/kernels/gemm/gemm.c @@ -6,7 +6,6 @@ * Web address: http://polybench.sourceforge.net */ #include -#include #include #include Index: SingleSource/Benchmarks/Polybench/linear-algebra/kernels/gemver/gemver.c =================================================================== --- SingleSource/Benchmarks/Polybench/linear-algebra/kernels/gemver/gemver.c +++ SingleSource/Benchmarks/Polybench/linear-algebra/kernels/gemver/gemver.c @@ -6,7 +6,6 @@ * Web address: http://polybench.sourceforge.net */ #include -#include #include #include Index: SingleSource/Benchmarks/Polybench/linear-algebra/kernels/gesummv/gesummv.c =================================================================== --- SingleSource/Benchmarks/Polybench/linear-algebra/kernels/gesummv/gesummv.c +++ SingleSource/Benchmarks/Polybench/linear-algebra/kernels/gesummv/gesummv.c @@ -6,7 +6,6 @@ * Web address: http://polybench.sourceforge.net */ #include -#include #include #include Index: SingleSource/Benchmarks/Polybench/linear-algebra/kernels/mvt/mvt.c =================================================================== --- SingleSource/Benchmarks/Polybench/linear-algebra/kernels/mvt/mvt.c +++ SingleSource/Benchmarks/Polybench/linear-algebra/kernels/mvt/mvt.c @@ -6,7 +6,6 @@ * Web address: http://polybench.sourceforge.net */ #include -#include #include #include Index: SingleSource/Benchmarks/Polybench/linear-algebra/kernels/symm/symm.c =================================================================== --- SingleSource/Benchmarks/Polybench/linear-algebra/kernels/symm/symm.c +++ SingleSource/Benchmarks/Polybench/linear-algebra/kernels/symm/symm.c @@ -6,7 +6,6 @@ * Web address: http://polybench.sourceforge.net */ #include -#include #include #include Index: SingleSource/Benchmarks/Polybench/linear-algebra/kernels/syr2k/syr2k.c =================================================================== --- SingleSource/Benchmarks/Polybench/linear-algebra/kernels/syr2k/syr2k.c +++ SingleSource/Benchmarks/Polybench/linear-algebra/kernels/syr2k/syr2k.c @@ -6,7 +6,6 @@ * Web address: http://polybench.sourceforge.net */ #include -#include #include #include Index: SingleSource/Benchmarks/Polybench/linear-algebra/kernels/syrk/syrk.c =================================================================== --- SingleSource/Benchmarks/Polybench/linear-algebra/kernels/syrk/syrk.c +++ SingleSource/Benchmarks/Polybench/linear-algebra/kernels/syrk/syrk.c @@ -6,7 +6,6 @@ * Web address: http://polybench.sourceforge.net */ #include -#include #include #include Index: SingleSource/Benchmarks/Polybench/linear-algebra/kernels/trisolv/trisolv.c =================================================================== --- SingleSource/Benchmarks/Polybench/linear-algebra/kernels/trisolv/trisolv.c +++ SingleSource/Benchmarks/Polybench/linear-algebra/kernels/trisolv/trisolv.c @@ -6,7 +6,6 @@ * Web address: http://polybench.sourceforge.net */ #include -#include #include #include Index: SingleSource/Benchmarks/Polybench/linear-algebra/kernels/trmm/trmm.c =================================================================== --- SingleSource/Benchmarks/Polybench/linear-algebra/kernels/trmm/trmm.c +++ SingleSource/Benchmarks/Polybench/linear-algebra/kernels/trmm/trmm.c @@ -6,7 +6,6 @@ * Web address: http://polybench.sourceforge.net */ #include -#include #include #include Index: SingleSource/Benchmarks/Polybench/linear-algebra/solvers/durbin/durbin.c =================================================================== --- SingleSource/Benchmarks/Polybench/linear-algebra/solvers/durbin/durbin.c +++ SingleSource/Benchmarks/Polybench/linear-algebra/solvers/durbin/durbin.c @@ -6,7 +6,6 @@ * Web address: http://polybench.sourceforge.net */ #include -#include #include #include Index: SingleSource/Benchmarks/Polybench/linear-algebra/solvers/dynprog/dynprog.c =================================================================== --- SingleSource/Benchmarks/Polybench/linear-algebra/solvers/dynprog/dynprog.c +++ SingleSource/Benchmarks/Polybench/linear-algebra/solvers/dynprog/dynprog.c @@ -6,7 +6,6 @@ * Web address: http://polybench.sourceforge.net */ #include -#include #include #include Index: SingleSource/Benchmarks/Polybench/linear-algebra/solvers/gramschmidt/gramschmidt.c =================================================================== --- SingleSource/Benchmarks/Polybench/linear-algebra/solvers/gramschmidt/gramschmidt.c +++ SingleSource/Benchmarks/Polybench/linear-algebra/solvers/gramschmidt/gramschmidt.c @@ -6,7 +6,6 @@ * Web address: http://polybench.sourceforge.net */ #include -#include #include #include Index: SingleSource/Benchmarks/Polybench/linear-algebra/solvers/lu/lu.c =================================================================== --- SingleSource/Benchmarks/Polybench/linear-algebra/solvers/lu/lu.c +++ SingleSource/Benchmarks/Polybench/linear-algebra/solvers/lu/lu.c @@ -6,7 +6,6 @@ * Web address: http://polybench.sourceforge.net */ #include -#include #include #include Index: SingleSource/Benchmarks/Polybench/medley/floyd-warshall/floyd-warshall.c =================================================================== --- SingleSource/Benchmarks/Polybench/medley/floyd-warshall/floyd-warshall.c +++ SingleSource/Benchmarks/Polybench/medley/floyd-warshall/floyd-warshall.c @@ -6,7 +6,6 @@ * Web address: http://polybench.sourceforge.net */ #include -#include #include #include Index: SingleSource/Benchmarks/Polybench/medley/reg_detect/reg_detect.c =================================================================== --- SingleSource/Benchmarks/Polybench/medley/reg_detect/reg_detect.c +++ SingleSource/Benchmarks/Polybench/medley/reg_detect/reg_detect.c @@ -6,7 +6,6 @@ * Web address: http://polybench.sourceforge.net */ #include -#include #include #include Index: SingleSource/Benchmarks/Polybench/stencils/adi/adi.c =================================================================== --- SingleSource/Benchmarks/Polybench/stencils/adi/adi.c +++ SingleSource/Benchmarks/Polybench/stencils/adi/adi.c @@ -6,7 +6,6 @@ * Web address: http://polybench.sourceforge.net */ #include -#include #include #include Index: SingleSource/Benchmarks/Polybench/stencils/fdtd-2d/fdtd-2d.c =================================================================== --- SingleSource/Benchmarks/Polybench/stencils/fdtd-2d/fdtd-2d.c +++ SingleSource/Benchmarks/Polybench/stencils/fdtd-2d/fdtd-2d.c @@ -6,7 +6,6 @@ * Web address: http://polybench.sourceforge.net */ #include -#include #include #include Index: SingleSource/Benchmarks/Polybench/stencils/fdtd-apml/fdtd-apml.c =================================================================== --- SingleSource/Benchmarks/Polybench/stencils/fdtd-apml/fdtd-apml.c +++ SingleSource/Benchmarks/Polybench/stencils/fdtd-apml/fdtd-apml.c @@ -6,7 +6,6 @@ * Web address: http://polybench.sourceforge.net */ #include -#include #include #include Index: SingleSource/Benchmarks/Polybench/stencils/seidel-2d/seidel-2d.c =================================================================== --- SingleSource/Benchmarks/Polybench/stencils/seidel-2d/seidel-2d.c +++ SingleSource/Benchmarks/Polybench/stencils/seidel-2d/seidel-2d.c @@ -6,7 +6,6 @@ * Web address: http://polybench.sourceforge.net */ #include -#include #include #include Index: SingleSource/Benchmarks/Polybench/utilities/polybench.h =================================================================== --- SingleSource/Benchmarks/Polybench/utilities/polybench.h +++ SingleSource/Benchmarks/Polybench/utilities/polybench.h @@ -213,12 +213,14 @@ #include #include #include -#include #include #include +#ifndef _WIN32 +#include #include #include #include +#endif #include #ifdef _OPENMP # include @@ -579,14 +581,21 @@ #endif } - +#ifdef _WIN32 +#include +#endif static void * xmalloc (size_t num) { void* new = NULL; - int ret = posix_memalign (&new, 32, num); + int ret = 0; +#ifdef _WIN32 + new = _aligned_malloc(num, 32); +#else + ret = posix_memalign (&new, 32, num); +#endif if (! new || ret) { fprintf (stderr, "[PolyBench] posix_memalign: cannot allocate memory"); Index: SingleSource/Benchmarks/Shootout-C++/hash.cpp =================================================================== --- SingleSource/Benchmarks/Shootout-C++/hash.cpp +++ SingleSource/Benchmarks/Shootout-C++/hash.cpp @@ -4,20 +4,29 @@ #include #include -#include #include using namespace std; -using namespace __gnu_cxx; -struct eqstr { - bool operator()(const char* s1, const char* s2) const { - return strcmp(s1, s2) == 0; +struct eqstr +{ + bool operator()(const char *s1, const char *s2) const + { + return strcmp(s1, s2) == 0; } }; -int -main(int argc, char *argv[]) { +#ifdef _MSC_VER +#include +typedef std::unordered_map, eqstr> HM; +#else +#include +using namespace __gnu_cxx; +typedef __gnu_cxx::hash_map, eqstr> HM; +#endif + +int main(int argc, char *argv[]) +{ #ifdef SMALL_PROBLEM_SIZE #define LENGTH 50000 #else @@ -25,18 +34,20 @@ #endif int n = ((argc == 2) ? atoi(argv[1]) : LENGTH); char buf[16]; - typedef __gnu_cxx::hash_map, eqstr> HM; HM X; - for (int i=1; i<=n; i++) { - sprintf(buf, "%x", i); - X[strdup(buf)] = i; + for (int i = 1; i <= n; i++) + { + sprintf(buf, "%x", i); + X[strdup(buf)] = i; } int c = 0; - for (int i=n; i>0; i--) { - sprintf(buf, "%d", i); - if (X[strdup(buf)]) c++; + for (int i = n; i > 0; i--) + { + sprintf(buf, "%d", i); + if (X[strdup(buf)]) + c++; } cout << c << endl; Index: SingleSource/Benchmarks/Shootout-C++/hash2.cpp =================================================================== --- SingleSource/Benchmarks/Shootout-C++/hash2.cpp +++ SingleSource/Benchmarks/Shootout-C++/hash2.cpp @@ -4,11 +4,9 @@ #include #include -#include #include using namespace std; -using namespace __gnu_cxx; struct eqstr { bool operator()(const char* s1, const char* s2) const { @@ -16,6 +14,15 @@ } }; +#ifdef _MSC_VER +#include +typedef std::unordered_map, eqstr> HM; +#else +#include +using namespace __gnu_cxx; +typedef __gnu_cxx::hash_map, eqstr> HM; +#endif + int main(int argc, char *argv[]) { #ifdef SMALL_PROBLEM_SIZE @@ -25,7 +32,6 @@ #endif int n = ((argc == 2) ? atoi(argv[1]) : LENGTH); char buf[16]; - typedef __gnu_cxx::hash_map, eqstr> HM; HM hash1, hash2; for (int i=0; i<10000; i++) { Index: SingleSource/Benchmarks/SmallPT/CMakeLists.txt =================================================================== --- SingleSource/Benchmarks/SmallPT/CMakeLists.txt +++ SingleSource/Benchmarks/SmallPT/CMakeLists.txt @@ -1,4 +1,9 @@ +if(TARGET_OS STREQUAL "Windows") + find_compiler_rt_library(COMPILER_RT_BUILTINS_LIBRARY) + list(APPEND LDFLAGS lidcmt.lib ${COMPILER_RT_BUILTINS_LIBRARY}) +else() + list(APPEND LDFLAGS -lm) +endif() list(APPEND CXXFLAGS -std=gnu++98) -list(APPEND LDFLAGS -lm) set(FP_TOLERANCE 0.001) llvm_singlesource() Index: SingleSource/Regression/C/2004-08-12-InlinerAndAllocas.c =================================================================== --- SingleSource/Regression/C/2004-08-12-InlinerAndAllocas.c +++ SingleSource/Regression/C/2004-08-12-InlinerAndAllocas.c @@ -1,12 +1,16 @@ // A compiler cannot inline Callee into main unless it is prepared to reclaim // the stack memory allocated in it. -#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) +#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(_WIN32) #include #else #include #endif + +#ifdef _WIN32 #include +#include +#endif static int Callee(int i) { if (i != 0) { Index: SingleSource/Regression/C/CMakeLists.txt =================================================================== --- SingleSource/Regression/C/CMakeLists.txt +++ SingleSource/Regression/C/CMakeLists.txt @@ -1,3 +1,10 @@ +if(TARGET_OS STREQUAL "Windows") + find_compiler_rt_library(COMPILER_RT_BUILTINS_LIBRARY) + list(APPEND LDFLAGS libcmt.lib ${COMPILER_RT_BUILTINS_LIBRARY}) +else() + list(APPEND LDFLAGS -lm) +endif() + if(ARCH MATCHES "x86" OR ARCH MATCHES "riscv" OR ARCH MATCHES "SystemZ" OR ARCH MATCHES "Mips" OR ARCH MATCHES "AArch64" OR ARCH MATCHES "ARM" OR @@ -5,6 +12,11 @@ add_subdirectory(gcc-c-torture) endif() -list(APPEND LDFLAGS -lm) +if(TARGET_OS STREQUAL "Windows") + file(GLOB Source RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.c *.cpp) + list(REMOVE_ITEM Source uint64_to_float.c) + list(REMOVE_ITEM Source casts.c) +endif() + list(APPEND CFLAGS -Wno-implicit-int) llvm_singlesource(PREFIX "Regression-C-") Index: SingleSource/Regression/C/gcc-c-torture/execute/20021120-3.c =================================================================== --- SingleSource/Regression/C/gcc-c-torture/execute/20021120-3.c +++ SingleSource/Regression/C/gcc-c-torture/execute/20021120-3.c @@ -1,6 +1,10 @@ /* Test whether a partly call-clobbered register will be moved over a call. Although the original test case didn't use any GNUisms, it proved difficult to reduce without the named register extension. */ +#ifdef _WIN32 +#include +#endif + #if __SH64__ == 32 #define LOC asm ("r10") #else Index: SingleSource/Regression/C/gcc-c-torture/execute/20030626-1.c =================================================================== --- SingleSource/Regression/C/gcc-c-torture/execute/20030626-1.c +++ SingleSource/Regression/C/gcc-c-torture/execute/20030626-1.c @@ -1,3 +1,6 @@ +#ifdef _WIN32 +#include +#endif char buf[10]; extern void abort (void); Index: SingleSource/Regression/C/gcc-c-torture/execute/20030626-2.c =================================================================== --- SingleSource/Regression/C/gcc-c-torture/execute/20030626-2.c +++ SingleSource/Regression/C/gcc-c-torture/execute/20030626-2.c @@ -1,3 +1,6 @@ +#ifdef _WIN32 +#include +#endif char buf[40]; extern int sprintf (char*, const char*, ...); Index: SingleSource/Regression/C/gcc-c-torture/execute/20041214-1.c =================================================================== --- SingleSource/Regression/C/gcc-c-torture/execute/20041214-1.c +++ SingleSource/Regression/C/gcc-c-torture/execute/20041214-1.c @@ -1,6 +1,7 @@ /* { dg-require-effective-target indirect_jumps } */ - +#ifndef _WIN32 typedef long unsigned int size_t; +#endif extern void abort (void); extern char *strcpy (char *, const char *); extern int strcmp (const char *, const char *); Index: SingleSource/Regression/C/gcc-c-torture/execute/20070201-1.c =================================================================== --- SingleSource/Regression/C/gcc-c-torture/execute/20070201-1.c +++ SingleSource/Regression/C/gcc-c-torture/execute/20070201-1.c @@ -1,7 +1,11 @@ /* PR middle-end/30473 */ +#ifdef _WIN32 +#include +#else extern int sprintf (char *, const char *, ...); extern void abort (void); +#endif char * foo (char *buf, char *p) Index: SingleSource/Regression/C/gcc-c-torture/execute/CMakeLists.txt =================================================================== --- SingleSource/Regression/C/gcc-c-torture/execute/CMakeLists.txt +++ SingleSource/Regression/C/gcc-c-torture/execute/CMakeLists.txt @@ -2,6 +2,10 @@ # GCC C Torture Suite is conventionally run without warnings list(APPEND CFLAGS -Wno-implicit-int -Wno-int-conversion -Wno-implicit-function-declaration -w) +if(TARGET_OS STREQUAL "Windows") + find_compiler_rt_library(COMPILER_RT_BUILTINS_LIBRARY) + list(APPEND LDFLAGS ${COMPILER_RT_BUILTINS_LIBRARY}) +endif() set(TestsToSkip) @@ -171,6 +175,15 @@ ) list(APPEND TestsToSkip ${FailingTests}) +file(GLOB WindowsFailures CONFIGURE_DEPENDS + + # Following tests do no compile with clang-cl on windows + fprintf-2.c + printf-2.c + user-printf.c +) +list(APPEND TestsToSkip ${WindowsFailures}) + ## ## Tests that require extra CFLAGS in Clang ## Index: SingleSource/Regression/C/gcc-c-torture/execute/pr78586.c =================================================================== --- SingleSource/Regression/C/gcc-c-torture/execute/pr78586.c +++ SingleSource/Regression/C/gcc-c-torture/execute/pr78586.c @@ -1,4 +1,7 @@ /* PR tree-optimization/78586 */ +#ifdef _WIN32 +#include +#endif void foo (unsigned long x) Index: SingleSource/Regression/C/gcc-c-torture/execute/pr79327.c =================================================================== --- SingleSource/Regression/C/gcc-c-torture/execute/pr79327.c +++ SingleSource/Regression/C/gcc-c-torture/execute/pr79327.c @@ -1,5 +1,8 @@ /* PR tree-optimization/79327 */ /* { dg-require-effective-target c99_runtime } */ +#ifdef _WIN32 +#include +#endif volatile int a; Index: SingleSource/UnitTests/CMakeLists.txt =================================================================== --- SingleSource/UnitTests/CMakeLists.txt +++ SingleSource/UnitTests/CMakeLists.txt @@ -4,7 +4,6 @@ add_subdirectory(Float) add_subdirectory(Matrix) add_subdirectory(SignlessTypes) -add_subdirectory(Threads) add_subdirectory(Vector) add_subdirectory(Vectorizer) add_subdirectory(X86) @@ -31,6 +30,13 @@ list(REMOVE_ITEM Source AtomicOps.c) endif() endif() +if(TARGET_OS STREQUAL "Windows") + list(APPEND LDFLAGS libcmt.lib) + list(REMOVE_ITEM Source 2004-11-28-GlobalBoolLayout.c) + list(REMOVE_ITEM Source 2005-05-11-Popcount-ffs-fls.c) +else() + add_subdirectory(Threads) +endif() if(ARCH STREQUAL "AArch64") list(REMOVE_ITEM Source blockstret.c) endif() Index: SingleSource/UnitTests/Vectorizer/gcc-loops.cpp =================================================================== --- SingleSource/UnitTests/Vectorizer/gcc-loops.cpp +++ SingleSource/UnitTests/Vectorizer/gcc-loops.cpp @@ -1,11 +1,31 @@ -#include #include #include -#include #include #include #include +#ifndef _WIN32 +#include +#include +#else +#include +void gettimeofday(struct timeval *tm, struct timezone *tz) +{ + FILETIME ft; + ULARGE_INTEGER uli; + + GetSystemTimeAsFileTime(&ft); + uli.LowPart = ft.dwLowDateTime; + uli.HighPart = ft.dwHighDateTime; + + // Convert to microseconds (1 microsecond = 10^-6 seconds) + uli.QuadPart /= 10ULL; // Divide by 10 to convert 100ns intervals to microseconds + + tm->tv_sec = (long)((uli.QuadPart - 11644473600000000ULL) / 1000000ULL); // Convert to Unix timestamp + tm->tv_usec = (long)(uli.QuadPart % 1000000ULL); +} +#endif + /// This test contains some of the loops from the GCC vectrorizer example page [1]. /// Dorit Nuzman who developed the gcc vectorizer said that we can use them in our test suite. /// @@ -50,23 +70,23 @@ __attribute__((noinline)) void example2a (int n, int x) { - int i; + int i; - /* feature: support for unknown loop bound */ - /* feature: support for loop invariants */ + /* feature: support for unknown loop bound */ + /* feature: support for loop invariants */ for (i=0; i MAX ? MAX : 0); - } + int j = a[i]; + b[i] = (j > MAX ? MAX : 0); + } } __attribute__((noinline)) @@ -121,12 +141,12 @@ __attribute__((noinline)) void example7 (int x) { - int i; + int i; - /* feature: support for read accesses with an unknown misalignment */ + /* feature: support for read accesses with an unknown misalignment */ for (i=0; i 1 (in the example, the stride is 2): */ __attribute__((noinline)) void example11() { - int i; + int i; for (i = 0; i < N/2; i++){ a[i] = b[2*i+1] * c[2*i+1] - b[2*i] * c[2*i]; d[i] = b[2*i] * c[2*i+1] + b[2*i+1] * c[2*i]; @@ -264,11 +284,11 @@ int i; char x, y; for (i = 0; i < N; i++) - { - x = (da[i] < db[i]); - y = (dc[i] < dd[i]); - dj[i] = x & y; - } + { + x = (da[i] < db[i]); + y = (dc[i] < dd[i]); + dj[i] = x & y; + } } void init_memory(void *start, void* end) { @@ -333,7 +353,7 @@ for (int i=0; i < (ITER); ++i) RUN_LINE;\ unsigned r = DIGEST_LINE;\ results.push_back(r);\ - } + } int main(int argc,char* argv[]){ Index: cmake/modules/HandleCompilerRT.cmake =================================================================== --- /dev/null +++ cmake/modules/HandleCompilerRT.cmake @@ -0,0 +1,43 @@ +# Find the path to compiler-rt builtins library for the current target and +# and return it in `variable`. +function(find_compiler_rt_library variable) + set(target "${CMAKE_CXX_COMPILER_TARGET}") + if(NOT DEFINED COMPILER_RT_LIBRARY_builtins_${target} OR NOT ${CMAKE_CXX_COMPILER_ID} MATCHES "Clang") + # If the cache variable is not defined, invoke Clang and then + # set it with cache_compiler_rt_library. + set(clang_command ${CMAKE_CXX_COMPILER} "${ARG_FLAGS}") + if(target) + list(APPEND clang_command "--target=${target}") + endif() + get_property(cxx_flags CACHE CMAKE_CXX_FLAGS PROPERTY VALUE) + string(REPLACE " " ";" cxx_flags "${cxx_flags}") + list(APPEND clang_command ${cxx_flags}) + set(cmd_prefix "") + if(MSVC) + set(cmd_prefix "/clang:") + endif() + execute_process( + COMMAND ${clang_command} "${cmd_prefix}--rtlib=compiler-rt" "${cmd_prefix}-print-libgcc-file-name" + RESULT_VARIABLE had_error + OUTPUT_VARIABLE library_file + ) + string(STRIP "${library_file}" library_file) + file(TO_CMAKE_PATH "${library_file}" library_file) + get_filename_component(basename ${library_file} NAME) + if(EXISTS "${library_file}" AND (basename MATCHES ".*clang_rt\.([a-z0-9_\-]+)\.(a|lib)")) + message(STATUS "Found compiler-rt library: ${basename}") + set(COMPILER_RT_LIBRARY_builtins_${target} "${basename}" CACHE INTERNAL + "compiler-rt library for ${target}") + else() + message(STATUS "Failed to find compiler-rt library for ${target}") + set(COMPILER_RT_LIBRARY_builtins_${target} "NOTFOUND" CACHE INTERNAL + "compiler-rt library for ${target}") + endif() + endif() + + if(NOT COMPILER_RT_LIBRARY_builtins_${target}) + set(${variable} "NOTFOUND" PARENT_SCOPE) + else() + set(${variable} "${COMPILER_RT_LIBRARY_builtins_${target}}" PARENT_SCOPE) + endif() +endfunction()