diff --git a/shared/source/utilities/aarch64/CMakeLists.txt b/shared/source/utilities/aarch64/CMakeLists.txt new file mode 100644 index 0000000000..4a3017763c --- /dev/null +++ b/shared/source/utilities/aarch64/CMakeLists.txt @@ -0,0 +1,12 @@ +# +# Copyright (C) 2021 Intel Corporation +# +# SPDX-License-Identifier: MIT +# + +if(${NEO_TARGET_PROCESSOR} STREQUAL "aarch64") + set_property(GLOBAL APPEND PROPERTY NEO_CORE_UTILITIES + ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/cpu_info_aarch64.cpp + ) +endif() diff --git a/shared/source/utilities/aarch64/cpu_info_aarch64.cpp b/shared/source/utilities/aarch64/cpu_info_aarch64.cpp new file mode 100644 index 0000000000..cdaf73c0c7 --- /dev/null +++ b/shared/source/utilities/aarch64/cpu_info_aarch64.cpp @@ -0,0 +1,13 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/utilities/cpu_info.h" + +namespace NEO { +void CpuInfo::detect() const { +} +} // namespace NEO diff --git a/shared/source/utilities/cpu_info.h b/shared/source/utilities/cpu_info.h index 38bc07354e..ad7f54f0f8 100644 --- a/shared/source/utilities/cpu_info.h +++ b/shared/source/utilities/cpu_info.h @@ -67,136 +67,7 @@ struct CpuInfo { uint32_t functionId, uint32_t subfunctionId) const; - void detect() const { - uint32_t cpuInfo[4]; - - cpuid(cpuInfo, 0u); - auto numFunctionIds = cpuInfo[0]; - - if (numFunctionIds >= 1u) { - cpuid(cpuInfo, 1u); - { - features |= cpuInfo[3] & BIT(0) ? featureFpu : featureNone; - } - - { - features |= cpuInfo[3] & BIT(4) ? featureTsc : featureNone; - } - - { - features |= cpuInfo[3] & BIT(15) ? featureCmov : featureNone; - } - - { - features |= cpuInfo[3] & BIT(19) ? featureClflush : featureNone; - } - - { - features |= cpuInfo[3] & BIT(23) ? featureMmx : featureNone; - } - - { - features |= cpuInfo[3] & BIT(24) ? featureFxsave : featureNone; - } - - { - features |= cpuInfo[3] & BIT(25) ? featureSse : featureNone; - } - - { - features |= cpuInfo[3] & BIT(26) ? featureSsE2 : featureNone; - } - - { - features |= cpuInfo[2] & BIT(0) ? featureSsE3 : featureNone; - } - - { - features |= cpuInfo[2] & BIT(1) ? featurePclmulqdq : featureNone; - } - - { - features |= cpuInfo[2] & BIT(9) ? featureSssE3 : featureNone; - } - - { - features |= cpuInfo[2] & BIT(12) ? featureFma : featureNone; - } - - { - features |= cpuInfo[2] & BIT(19) ? featureSsE41 : featureNone; - } - - { - features |= cpuInfo[2] & BIT(20) ? featureSsE42 : featureNone; - } - - { - features |= cpuInfo[2] & BIT(22) ? featureMovbe : featureNone; - } - - { - features |= cpuInfo[2] & BIT(23) ? featurePopcnt : featureNone; - } - - { - features |= cpuInfo[2] & BIT(25) ? featureAes : featureNone; - } - - { - features |= cpuInfo[2] & BIT(28) ? featureAvx : featureNone; - } - - { - features |= cpuInfo[2] & BIT(29) ? featureF16C : featureNone; - } - - { - features |= cpuInfo[2] & BIT(30) ? featureRdrnd : featureNone; - } - } - - if (numFunctionIds >= 7u) { - cpuid(cpuInfo, 7u); - { - auto mask = BIT(5) | BIT(3) | BIT(8); - features |= (cpuInfo[1] & mask) == mask ? featureAvX2 : featureNone; - } - - { - auto mask = BIT(3) | BIT(8); - features |= (cpuInfo[1] & mask) == mask ? featureBmi : featureNone; - } - - { - features |= cpuInfo[1] & BIT(4) ? featureHle : featureNone; - } - - { - features |= cpuInfo[1] & BIT(11) ? featureRtm : featureNone; - } - } - - cpuid(cpuInfo, 0x80000000); - auto maxExtendedId = cpuInfo[0]; - if (maxExtendedId >= 0x80000001) { - cpuid(cpuInfo, 0x80000001); - { - features |= cpuInfo[2] & BIT(5) ? featureLzcnt : featureNone; - } - - { - features |= cpuInfo[3] & BIT(27) ? featureRdtscp : featureNone; - } - } - - if (maxExtendedId >= 0x80000008) { - cpuid(cpuInfo, 0x80000008); - { - virtualAddressSize = (cpuInfo[0] >> 8) & 0xFF; - } - } - } + void detect() const; bool isFeatureSupported(uint64_t feature) const { if (features == featureNone) { diff --git a/shared/source/utilities/x86_64/CMakeLists.txt b/shared/source/utilities/x86_64/CMakeLists.txt new file mode 100644 index 0000000000..53542eb7bc --- /dev/null +++ b/shared/source/utilities/x86_64/CMakeLists.txt @@ -0,0 +1,12 @@ +# +# Copyright (C) 2021 Intel Corporation +# +# SPDX-License-Identifier: MIT +# + +if(${NEO_TARGET_PROCESSOR} STREQUAL "x86_64") + set_property(GLOBAL APPEND PROPERTY NEO_CORE_UTILITIES + ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/cpu_info_x86_64.cpp + ) +endif() diff --git a/shared/source/utilities/x86_64/cpu_info_x86_64.cpp b/shared/source/utilities/x86_64/cpu_info_x86_64.cpp new file mode 100644 index 0000000000..9ef2f5c8e5 --- /dev/null +++ b/shared/source/utilities/x86_64/cpu_info_x86_64.cpp @@ -0,0 +1,145 @@ +/* + * Copyright (C) 2021 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "shared/source/utilities/cpu_info.h" + +#ifndef BIT +#define BIT(x) (1ull << (x)) +#endif + +namespace NEO { +void CpuInfo::detect() const { + uint32_t cpuInfo[4] = {}; + + cpuid(cpuInfo, 0u); + auto numFunctionIds = cpuInfo[0]; + + if (numFunctionIds >= 1u) { + cpuid(cpuInfo, 1u); + { + features |= cpuInfo[3] & BIT(0) ? featureFpu : featureNone; + } + + { + features |= cpuInfo[3] & BIT(4) ? featureTsc : featureNone; + } + + { + features |= cpuInfo[3] & BIT(15) ? featureCmov : featureNone; + } + + { + features |= cpuInfo[3] & BIT(19) ? featureClflush : featureNone; + } + + { + features |= cpuInfo[3] & BIT(23) ? featureMmx : featureNone; + } + + { + features |= cpuInfo[3] & BIT(24) ? featureFxsave : featureNone; + } + + { + features |= cpuInfo[3] & BIT(25) ? featureSse : featureNone; + } + + { + features |= cpuInfo[3] & BIT(26) ? featureSsE2 : featureNone; + } + + { + features |= cpuInfo[2] & BIT(0) ? featureSsE3 : featureNone; + } + + { + features |= cpuInfo[2] & BIT(1) ? featurePclmulqdq : featureNone; + } + + { + features |= cpuInfo[2] & BIT(9) ? featureSssE3 : featureNone; + } + + { + features |= cpuInfo[2] & BIT(12) ? featureFma : featureNone; + } + + { + features |= cpuInfo[2] & BIT(19) ? featureSsE41 : featureNone; + } + + { + features |= cpuInfo[2] & BIT(20) ? featureSsE42 : featureNone; + } + + { + features |= cpuInfo[2] & BIT(22) ? featureMovbe : featureNone; + } + + { + features |= cpuInfo[2] & BIT(23) ? featurePopcnt : featureNone; + } + + { + features |= cpuInfo[2] & BIT(25) ? featureAes : featureNone; + } + + { + features |= cpuInfo[2] & BIT(28) ? featureAvx : featureNone; + } + + { + features |= cpuInfo[2] & BIT(29) ? featureF16C : featureNone; + } + + { + features |= cpuInfo[2] & BIT(30) ? featureRdrnd : featureNone; + } + } + + if (numFunctionIds >= 7u) { + cpuid(cpuInfo, 7u); + { + auto mask = BIT(5) | BIT(3) | BIT(8); + features |= (cpuInfo[1] & mask) == mask ? featureAvX2 : featureNone; + } + + { + auto mask = BIT(3) | BIT(8); + features |= (cpuInfo[1] & mask) == mask ? featureBmi : featureNone; + } + + { + features |= cpuInfo[1] & BIT(4) ? featureHle : featureNone; + } + + { + features |= cpuInfo[1] & BIT(11) ? featureRtm : featureNone; + } + } + + cpuid(cpuInfo, 0x80000000); + auto maxExtendedId = cpuInfo[0]; + if (maxExtendedId >= 0x80000001) { + cpuid(cpuInfo, 0x80000001); + { + features |= cpuInfo[2] & BIT(5) ? featureLzcnt : featureNone; + } + + { + features |= cpuInfo[3] & BIT(27) ? featureRdtscp : featureNone; + } + } + + if (maxExtendedId >= 0x80000008) { + cpuid(cpuInfo, 0x80000008); + { + virtualAddressSize = (cpuInfo[0] >> 8) & 0xFF; + } + } +} +} // namespace NEO diff --git a/shared/test/unit_test/utilities/CMakeLists.txt b/shared/test/unit_test/utilities/CMakeLists.txt index 4259ea4e4a..52626ce83f 100644 --- a/shared/test/unit_test/utilities/CMakeLists.txt +++ b/shared/test/unit_test/utilities/CMakeLists.txt @@ -10,7 +10,6 @@ target_sources(${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/const_stringref_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/containers_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/containers_tests_helpers.h - ${CMAKE_CURRENT_SOURCE_DIR}/cpuinfo_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/cpuintrinsics_tests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/destructor_counted.h ${CMAKE_CURRENT_SOURCE_DIR}/heap_allocator_tests.cpp diff --git a/shared/test/unit_test/utilities/x86_64/CMakeLists.txt b/shared/test/unit_test/utilities/x86_64/CMakeLists.txt new file mode 100644 index 0000000000..01120cac50 --- /dev/null +++ b/shared/test/unit_test/utilities/x86_64/CMakeLists.txt @@ -0,0 +1,12 @@ +# +# Copyright (C) 2021 Intel Corporation +# +# SPDX-License-Identifier: MIT +# + +if(${NEO_TARGET_PROCESSOR} STREQUAL "x86_64") + target_sources(${TARGET_NAME} PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/cpuinfo_tests_x86_64.cpp + ) +endif() diff --git a/shared/test/unit_test/utilities/cpuinfo_tests.cpp b/shared/test/unit_test/utilities/x86_64/cpuinfo_tests_x86_64.cpp similarity index 100% rename from shared/test/unit_test/utilities/cpuinfo_tests.cpp rename to shared/test/unit_test/utilities/x86_64/cpuinfo_tests_x86_64.cpp