Unverified Commit ea6a4177 authored by Peter Steinbach's avatar Peter Steinbach Committed by GitHub

Merge pull request #7 from psteinb/adding_cachlinesize

Adding cachlinesize
parents 2c213521 d643ab0d
......@@ -23,8 +23,9 @@ SET (COMPASS_VERSION "${COMPASS_VERSION_MAJOR}.${COMPASS_VERSION_MINOR}.${COMPAS
SET (COMPASS_VENDOR_ID "psteinb")
SET (COMPASS_ID "${COMPASS_VENDOR_ID}.${PROJECT_NAME}")
option(WITH_CXX11_ABI "enable _GLIBCXX_USE_CXX11_ABI in GCC 5.0+" ON)
option(WITH_TESTS "enable unit tests" ON)
option(WITH_CXX11_ABI "enable _GLIBCXX_USE_CXX11_ABI in GCC 5.0+" ON)
option(WITH_TESTS "enable unit tests" ON)
option(WITH_SINGLE_HEADER "produce single header file from include/" ON)
check_cxx_compiler_flag(-Wl,-Bsymbolic HAS_BSYMBOLIC_COMPILERFLAG)
check_cxx_compiler_flag("-Xclang -march=native" HAS_XCLANG_COMPILERFLAG)
......@@ -59,6 +60,8 @@ if(WITH_TESTS)
add_subdirectory(tests)
enable_testing()
include("CTestLists.txt")
endif()
################################ EXPORT/INSTALL ################################
......
#ifndef DETAIL_DETECT_ARCHITECTURE_H
#define DETAIL_DETECT_ARCHITECTURE_H
//for reference see: https://sourceforge.net/p/predef/wiki/Architectures/
#if !__PCPP_ALWAYS_TRUE__ // Always execute except on pcpp
#define COMPASS_CT_ARCH_UNSUPPORTED
#endif
//for reference see: https://sourceforge.net/p/predef/wiki/Architectures/
#if (defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64))
#define COMPASS_CT_ARCH_X86
#define COMPASS_CT_ARCH_64BITS
#undef COMPASS_CT_ARCH_UNSUPPORTED
#undef COMPASS_CT_ARCH_UNSUPPORTED
#endif
#if (defined(i386) || defined(__i386) || defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) || defined(__M_I86) || defined(_M_IX86))
#define COMPASS_CT_ARCH_X86
#undef COMPASS_CT_ARCH_UNSUPPORTED
#undef COMPASS_CT_ARCH_UNSUPPORTED
#endif
#if (defined(__powerpc64__) || defined(_ARCH_PPC64) || defined(__ppc64__))
#define COMPASS_CT_ARCH_POWER
#define COMPASS_CT_ARCH_64BITS
#undef COMPASS_CT_ARCH_UNSUPPORTED
#define COMPASS_CT_ARCH_UNSUPPORTED //undef if support comes in this library
#endif
#if (defined(__powerpc) || defined(__powerpc__) || defined(__POWERPC__) || defined(__PPC__) || defined(__ppc__))
#define COMPASS_CT_ARCH_POWER
#undef COMPASS_CT_ARCH_UNSUPPORTED
#define COMPASS_CT_ARCH_UNSUPPORTED //undef if support lands in this library
#endif
#include "detail/definitions.hpp"
#include <climits> //for CHAR_BIT
......
......@@ -25,8 +25,7 @@
#define COMPASS_HAS_SSE4
#endif
#include "../tags.hpp"
#include "detail/tags.hpp"
namespace compass {
......
......@@ -5,7 +5,6 @@
namespace compass {
namespace runtime {
static int extended_get_cpuid(std::uint32_t* regs,
......@@ -13,12 +12,12 @@ namespace compass {
std::uint32_t in_ecx = 0){
#ifdef __get_cpuid_count
return __get_cpuid_count(in_eax,
in_ecx,
&regs[ct::eax],
&regs[ct::ebx],
&regs[ct::ecx],
&regs[ct::edx]);
return __get_cpuid_count(in_eax,
in_ecx,
&regs[ct::eax],
&regs[ct::ebx],
&regs[ct::ecx],
&regs[ct::edx]);
#endif
......
......@@ -6,9 +6,8 @@
#define COMPASS_RT_X86_GNU_CPUID_H_
#include "detail/tags.hpp"
#include "detail/definitions.hpp"
#include "detail/rt/x86/cpuid_common.hpp"
//#include "detail/rt/x86/cpuid_common.hpp"
#include <array>
#include <cstdint>
......@@ -16,7 +15,6 @@
namespace compass {
namespace runtime {
static std::array<std::uint32_t,4> cpuid(std::uint32_t in_eax = 0,
......@@ -25,15 +23,17 @@ namespace compass {
std::uint32_t in_edx = 0){
std::array<std::uint32_t,4> regs = {in_eax,0,in_ecx,0};
int cpuid_rvalue = __get_cpuid_count(in_eax,
in_ecx,
&regs[ct::eax],
&regs[ct::ebx],
&regs[ct::ecx],
&regs[ct::edx]
);
if(cpuid_rvalue < 1){
// int cpuid_rvalue = __get_cpuid_count(in_eax,
// in_ecx,
// &regs[ct::eax],
// &regs[ct::ebx],
// &regs[ct::ecx],
// &regs[ct::edx]
// );
int gnu_cpuid_rvalue = compass::runtime::extended_get_cpuid(regs.data(),
in_eax,
in_ecx);
if(gnu_cpuid_rvalue < 1){
return {0,0,0,0};
}
......
......@@ -11,32 +11,14 @@
#include <bitset>
#include <cstdint>
#include "detail/tags.hpp"
#include "detail/definitions.hpp"
#include "detail/rt/x86/cpuid_common.hpp"
namespace compass {
namespace runtime {
static std::array<std::bitset<32>, 4> cpuid(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(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;
}
static std::array<std::uint32_t,4> cpuid_to_int(std::uint32_t in_eax = 0,
......@@ -46,7 +28,7 @@ namespace compass {
static std::array<std::uint32_t,4> value = {~0};
int cpuid_rvalue = extended_get_cpuid(&value[0],in_eax,in_ecx);
int cpuid_rvalue = compass::runtime::extended_get_cpuid(&value[0],in_eax,in_ecx);
if(cpuid_rvalue < 1){
value = {0,0,0,0};
......@@ -57,7 +39,23 @@ namespace compass {
}
static std::array<std::bitset<32>, 4> cpuid(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(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;
}
};
};
......
......@@ -5,9 +5,7 @@
#ifdef COMPASS_CT_COMP_CLANG
#include "detail/tags.hpp"
#include "detail/definitions.hpp"
#include "detail/rt/x86/cpuid_common.hpp"
#include <array>
#include <cstdint>
......
......@@ -12,8 +12,6 @@
#include <bitset>
#include <cstdint>
#include "detail/tags.hpp"
#include "detail/definitions.hpp"
namespace compass {
......@@ -26,17 +24,17 @@ namespace compass {
std::uint32_t in_ebx = 0,
std::uint32_t in_ecx = 0,
std::uint32_t in_edx = 0) {
std::array<std::uint32_t, 4> regs = { in_eax,in_ebx,in_ecx,in_edx };
std::int32_t* regs_ptr = reinterpret_cast<std::int32_t*>(regs.data());
std::array<std::uint32_t, 4> regs = { in_eax,in_ebx,in_ecx,in_edx };
std::int32_t* regs_ptr = reinterpret_cast<std::int32_t*>(regs.data());
__cpuidex(regs_ptr,
(std::int32_t)in_eax,
(std::int32_t)in_ecx
);
(std::int32_t)in_eax,
(std::int32_t)in_ecx
);
return regs;
}
......
......@@ -5,6 +5,8 @@
#ifdef COMPASS_CT_ARCH_X86
#define COMPASS_RT_X86_CPUID_H
#include "detail/rt/x86/cpuid_common.hpp"
#include "detail/rt/x86/llvm_cpuid.hpp"
#include "detail/rt/x86/gnu_cpuid.hpp"
#include "detail/rt/x86/msvc_cpuid.hpp"
......
......@@ -13,6 +13,7 @@
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
namespace compass {
......
......@@ -38,3 +38,24 @@ endif()
add_executable(test_bitview test_bitview.cpp $<TARGET_OBJECTS:catcho>)
target_include_directories(test_bitview PRIVATE ${PROJECT_SOURCE_DIR}/include ${CATCH2_HEADER_PATH})
### test single header
if(WITH_SINGLE_HEADER)
find_program(PCPP NAME pcpp HINT ${PCPP_PATH})
if(PCPP_FOUND OR EXISTS ${PCPP_PATH})
add_custom_target(sh
COMMAND pcpp -o ${PROJECT_BINARY_DIR}/tests/compass-sh.hpp --line-directive --passthru-defines --passthru-unfound-includes --passthru-unknown-exprs ${PROJECT_SOURCE_DIR}/include/compass.hpp
BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/compass-sh.hpp
COMMENT "Preprocessing ${PROJECT_SOURCE_DIR}/include/compass.hpp into ${CMAKE_CURRENT_BINARY_DIR}/tests/compass-sh.hpp ..."
USES_TERMINAL)
add_executable(test_single_header test_single_header.cpp $<TARGET_OBJECTS:catcho> ${CMAKE_CURRENT_BINARY_DIR}/compass-sh.hpp)
add_dependencies(test_single_header sh)
target_include_directories(test_single_header PRIVATE ${PROJECT_BINARY_DIR}/tests ${CATCH2_HEADER_PATH})
else()
message(WARNING "pcpp not found ${PCPP_PATH}")
endif()
endif()
#include "catch.hpp"
#include "compass-sh.hpp"
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
TEST_CASE( "compass_single_header" ){
SECTION( "compass_works_at_runtime" ){
auto value = compass::runtime::works();
REQUIRE(value);
}
SECTION( "compass_yields_vendor_name" ){
auto value = compass::runtime::vendor();
REQUIRE(value.size()!=0u);
}
}
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