Commit d14fa2bf authored by steinbac's avatar steinbac

Merge branch 'master' of github.com:psteinb/compass

parents 78bc6b47 7b09dd80
......@@ -41,14 +41,20 @@ IF(NOT WIN32)
check_symbol_exists(__get_cpuid "cpuid.h" GET_CPUID_INSTRINSIC_EXISTS)
ELSE()
check_symbol_exists(__cpuid "intrin.h" GET_CPUID_INSTRINSIC_EXISTS)
add_definitions(-DBOOST_ALL_NO_LIB)
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
ENDIF()
#list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake )
FIND_PACKAGE (Boost 1.50 COMPONENTS system filesystem unit_test_framework QUIET)
IF(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
IF(DEFINED Boost_FOUND)
include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIR})
MESSAGE("++ Boost libraries found : ${Boost_LIBRARIES}")
ADD_SUBDIRECTORY(tests)
enable_testing()
......
......@@ -18,9 +18,18 @@ You have 2 options:
$ make && ctest
$ make install #depending on the contents of CMAKE_INSTALL_PREFIX, you may use sudo
```
(3.) in case you have access to the test machines, you can build the compass tests (requires boost to be installed)
- on Windows platforms (assuming that `cmake` and `boost\lib` are in your `PATH`)
```
> cd repo
> mkdir build
> cd build
> cmake.exe -G "Visual Studio 14 2015 Win64" -DBOOST_ROOT=C:\path\to\boost\1_59_0 ..
> cmake.exe --build . --target ALL_BUILD --config Release
> ctest.exe -C Release
```
(3.) tests can only be run if you have access to the test machines and it requires boost to be installed (if boost is not detected, the tests are skipped and a warning is issued)
## Compass API
......
......@@ -3,12 +3,14 @@
//for reference see: https://sourceforge.net/p/predef/wiki/Compilers/
#ifdef __clang__
#define COMPASS_CT_COMP_CLANG
#else
#ifdef __GNUC__
#define COMPASS_CT_COMP_GCC
#endif
#ifdef __clang__
#define COMPASS_CT_COMP_CLANG
#endif
#if (defined(_MSC_VER) || defined(_MSC_FULL_VER) || defined(_MSC_BUILD))
......
......@@ -45,24 +45,7 @@ namespace compass {
}
static std::array<std::bitset<32>,4> cpuid(std::uint32_t level,
std::uint32_t in_eax = 0,
std::uint32_t in_ebx = 0,
std::uint32_t in_ecx = 0,
std::uint32_t in_edx = 0){
auto regs = cpuid_to_int(level, in_eax, in_ebx, in_ecx, in_edx);
static std::array<std::bitset<32>,4> value;
value[ct::eax] = regs[ct::eax];
value[ct::ebx] = regs[ct::ebx];
value[ct::ecx] = regs[ct::ecx];
value[ct::edx] = regs[ct::edx];
return value;
}
};
......
......@@ -14,6 +14,8 @@
#include "detail/tags.hpp"
#include "detail/definitions.hpp"
namespace compass {
......@@ -21,55 +23,45 @@ namespace compass {
namespace runtime {
static std::array<std::bitset<32>,4> cpuid(std::uint32_t level,
std::uint32_t in_eax = 0,
std::uint32_t in_ebx = 0,
std::uint32_t in_ecx = 0,
std::uint32_t in_edx = 0){
std::uint32_t regs[4] = {in_eax,in_ebx,in_ecx,in_edx};
int cpuid_rvalue = __get_cpuid(level,
&regs[eax],
&regs[ebx],
&regs[ecx],
&regs[edx]
);
static std::array<std::uint32_t,4> cpuid_to_int(std::uint32_t level,
std::uint32_t in_eax = 0,
std::uint32_t in_ebx = 0,
std::uint32_t in_ecx = 0,
std::uint32_t in_edx = 0){
static std::array<std::bitset<32>,4> value;
static std::array<std::uint32_t,4> value = {in_eax,in_ebx,in_ecx,in_edx};
int cpuid_rvalue = __get_cpuid(level,
&value[ct::eax],
&value[ct::ebx],
&value[ct::ecx],
&value[ct::edx]);
if(cpuid_rvalue < 1){
value = {0,0,0,0};
return value;
} else {
return value;
}
}
/*static std::array<std::bitset<32>,4> cpuid(std::uint32_t level,
std::uint32_t in_eax = 0,
std::uint32_t in_ebx = 0,
std::uint32_t in_ecx = 0,
std::uint32_t in_edx = 0){
value[eax] = regs[eax];
value[ebx] = regs[ebx];
value[ecx] = regs[ecx];
value[edx] = regs[edx];
return value;
}
static std::array<std::uint32_t,4> cpuid_to_int(std::uint32_t level,
std::uint32_t in_eax = 0,
std::uint32_t in_ebx = 0,
std::uint32_t in_ecx = 0,
std::uint32_t in_edx = 0){
auto regs = cpuid_to_int(level, in_eax, in_ebx, in_ecx, in_edx);
static std::array<std::bitset<32>,4> temp = cpuid(level,
in_eax,
in_ebx,
in_ecx,
in_edx);
static std::array<std::bitset<32>,4> value;
static std::array<std::uint32_t,4> value;
for(std::uint32_t i = 0 ; i < temp.size();++i)
value[i] = temp[i].to_ulong();
value[ct::eax] = regs[ct::eax];
value[ct::ebx] = regs[ct::ebx];
value[ct::ecx] = regs[ct::ecx];
value[ct::edx] = regs[ct::edx];
return value;
}
}*/
};
......
......@@ -14,61 +14,30 @@
#include "detail/tags.hpp"
#include "detail/definitions.hpp"
namespace compass {
namespace compiletime {
namespace runtime {
static std::array<std::bitset<32>, 4> cpuid(std::uint32_t level,
std::uint32_t in_eax = 0,
std::uint32_t in_ebx = 0,
std::uint32_t in_ecx = 0,
std::uint32_t in_edx = 0) {
std::int32_t regs[4] = { static_cast<std::int32_t>(in_eax),
static_cast<std::int32_t>(in_ebx),
static_cast<std::int32_t>(in_ecx),
static_cast<std::int32_t>(in_edx)
};
__cpuid(regs,
(std::int32_t)level);
static std::array<std::bitset<32>, 4> value;
if (!(regs[eax] || regs[ebx] || regs[ecx] || regs[edx])) {
return value;
}
value[eax] = regs[eax];
value[ebx] = regs[ebx];
value[ecx] = regs[ecx];
value[edx] = regs[edx];
return value;
}
static std::array<std::uint32_t,4> cpuid_to_int(std::uint32_t level,
std::uint32_t in_eax = 0,
std::uint32_t in_ebx = 0,
std::uint32_t in_ecx = 0,
std::uint32_t in_edx = 0){
static std::array<std::bitset<32>,4> temp = cpuid(level,
in_eax,
in_ebx,
in_ecx,
in_edx);
static std::array<std::uint32_t,4> value;
for(std::uint32_t i = 0 ; i < temp.size();++i)
value[i] = temp[i].to_ulong();
return value;
std::array<std::uint32_t, 4> regs = { in_eax,
in_ebx,
in_ecx,
in_edx
};
std::int32_t* converted_regs = reinterpret_cast<std::int32_t*>(&regs[0]);
__cpuid(converted_regs,
(std::int32_t)level);
return regs;
}
};
......
......@@ -9,6 +9,34 @@
#include "detail/rt/x86/gnu_cpuid.hpp"
#include "detail/rt/x86/msvc_cpuid.hpp"
namespace compass {
namespace runtime {
static std::array<std::bitset<32>, 4> cpuid(std::uint32_t level,
std::uint32_t in_eax = 0,
std::uint32_t in_ebx = 0,
std::uint32_t in_ecx = 0,
std::uint32_t in_edx = 0) {
auto regs = cpuid_to_int(level, in_eax, in_ebx, in_ecx, in_edx);
static std::array<std::bitset<32>, 4> value;
value[ct::eax] = regs[ct::eax];
value[ct::ebx] = regs[ct::ebx];
value[ct::ecx] = regs[ct::ecx];
value[ct::edx] = regs[ct::edx];
return value;
}
};
};
#endif /* COMPASS_CT_ARCH_X86 */
#endif /* X86_CPUID_H */
......@@ -86,7 +86,7 @@ struct host_reference
expected_has_sse3 = true;
expected_has_sse4 = true;
expected_has_avx = true;
expected_has_avx2 = true;
expected_has_avx2 = false;
expected_ncores = 4;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment