Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ Debug/
Release/
FeatureDetector.VC*
.vs/
/Linux
/Windows
/.vs
/.idea
9 changes: 9 additions & 0 deletions BuildLinuxInWsl.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@echo off
setlocal
cd /d "%~dp0"

wsl cmake -B Linux -G "Ninja Multi-Config" %* ^&^& ^
cmake --build Linux --config Release ||^
pause

endlocal
9 changes: 9 additions & 0 deletions BuildWindows.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@echo off
setlocal
cd /d "%~dp0"

cmake.exe -B Windows -G "Visual Studio 17 2022" -A x64 &&^
cmake.exe --build Windows --config Release ||^
pause

endlocal
7 changes: 4 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ cmake_minimum_required(VERSION 3.4)
project(FeatureDetector CXX)

add_subdirectory(src/x86)
target_include_directories(FeatureDetector PUBLIC src)
target_include_directories(FeatureDetectorLib PUBLIC src)

if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
add_executable(FeatureDetector_main src/Main.cpp)
target_link_libraries(FeatureDetector_main PUBLIC FeatureDetector)
add_executable(FeatureDetector src/Main.cpp)
target_link_libraries(FeatureDetector PUBLIC FeatureDetectorLib)
endif()
186 changes: 93 additions & 93 deletions FeatureDetector/FeatureDetector.vcxproj
Original file line number Diff line number Diff line change
@@ -1,94 +1,94 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\src\x86\cpu_x86.h" />
</ItemGroup>
<ItemGroup>
<None Include="..\src\x86\cpu_x86_Linux.ipp" />
<None Include="..\src\x86\cpu_x86_Windows.ipp" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\src\Main.cpp" />
<ClCompile Include="..\src\x86\cpu_x86.cpp" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{5AF4062D-386F-48AA-B824-2C10A4B1BA97}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>FeatureDetector</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\src\x86\cpu_x86.h" />
</ItemGroup>
<ItemGroup>
<None Include="..\src\x86\cpu_x86_Linux.ipp" />
<None Include="..\src\x86\cpu_x86_Windows.ipp" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\src\Main.cpp" />
<ClCompile Include="..\src\x86\cpu_x86.cpp" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{5AF4062D-386F-48AA-B824-2C10A4B1BA97}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>FeatureDetector</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>
</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
4 changes: 0 additions & 4 deletions FeatureDetector/FeatureDetector.vcxproj.user

This file was deleted.

148 changes: 122 additions & 26 deletions src/Main.cpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,122 @@
/* Main.cpp
*
* Author : Alexander J. Yee
* Date Created : 04/17/2015
* Last Modified : 04/17/2015
*
*/

#include <iostream>
using std::cout;
using std::endl;

#include "x86/cpu_x86.h"
using namespace FeatureDetector;

int main(){

cout << "CPU Vendor String: " << cpu_x86::get_vendor_string() << endl;
cout << endl;

cpu_x86::print_host();

#if _WIN32
system("pause");
#endif
}
/* Main.cpp
*
* Author : Alexander J. Yee
* Date Created : 04/17/2015
* Last Modified : 04/17/2015
*
*/

#include <iostream>
using std::cout;
using std::endl;

#include "x86/cpu_x86.h"
using namespace FeatureDetector;

bool case_insensitive_char_compare(char a, char b) {
return std::tolower(a) == std::tolower(b);
}

bool case_insensitive_compare(const std::string& s1, const std::string& s2) {
return s1.size() == s2.size() && std::equal(s1.begin(), s1.end(), s2.begin(), case_insensitive_char_compare);
}

int main(int argc, char* argv[]) {
cpu_x86 features;
features.detect_host();

if (argc == 1)
{
cout << "CPU Vendor String: " << cpu_x86::get_vendor_string() << endl;
cout << endl;

features.print();
#if _WIN32
system("pause");
#endif
return 0;
}

struct feature {
const char* name;
bool cpu_x86::* feature;
};

static feature featureList[] = {
{"AMD", &cpu_x86::Vendor_AMD},
{"Intel", &cpu_x86::Vendor_Intel},

{"OS AVX", &cpu_x86::OS_AVX},
{"OS AVX512", &cpu_x86::OS_AVX512},

{"MMX", &cpu_x86::HW_MMX},
{"x64", &cpu_x86::HW_x64},
{"ABM", &cpu_x86::HW_ABM},
{"RDRAND", &cpu_x86::HW_RDRAND},
{"RDSEED", &cpu_x86::HW_RDSEED},
{"BMI1", &cpu_x86::HW_BMI1},
{"BMI2", &cpu_x86::HW_BMI2},
{"ADX", &cpu_x86::HW_ADX},
{"MPX", &cpu_x86::HW_MPX},
{"PREFETCHW", &cpu_x86::HW_PREFETCHW},
{"PREFETCHWT1", &cpu_x86::HW_PREFETCHWT1},
{"RDPID", &cpu_x86::HW_RDPID},
{"GFNI", &cpu_x86::HW_GFNI},
{"VAES", &cpu_x86::HW_VAES},

{"SSE", &cpu_x86::HW_SSE},
{"SSE2", &cpu_x86::HW_SSE2},
{"SSE3", &cpu_x86::HW_SSE3},
{"SSSE3", &cpu_x86::HW_SSSE3},
{"SSE4a", &cpu_x86::HW_SSE4a},
{"SSE4.1", &cpu_x86::HW_SSE41},
{"SSE4.2", &cpu_x86::HW_SSE42},
{"AES-NI", &cpu_x86::HW_AES},
{"SHA", &cpu_x86::HW_SHA},

{"AVX", &cpu_x86::HW_AVX},
{"XOP", &cpu_x86::HW_XOP},
{"FMA3", &cpu_x86::HW_FMA3},
{"FMA4", &cpu_x86::HW_FMA4},
{"AVX2", &cpu_x86::HW_AVX2},

{"AVX512-F", &cpu_x86::HW_AVX512_F},
{"AVX512-CD", &cpu_x86::HW_AVX512_CD},
{"AVX512-PF", &cpu_x86::HW_AVX512_PF},
{"AVX512-ER", &cpu_x86::HW_AVX512_ER},
{"AVX512-VL", &cpu_x86::HW_AVX512_VL},
{"AVX512-BW", &cpu_x86::HW_AVX512_BW},
{"AVX512-DQ", &cpu_x86::HW_AVX512_DQ},
{"AVX512-IFMA", &cpu_x86::HW_AVX512_IFMA},
{"AVX512-VBMI", &cpu_x86::HW_AVX512_VBMI},
{"AVX512-VPOPCNTDQ", &cpu_x86::HW_AVX512_VPOPCNTDQ},
{"AVX512-4VNNIW", &cpu_x86::HW_AVX512_4VNNIW},
{"AVX512-4FMAPS", &cpu_x86::HW_AVX512_4FMAPS},
{"AVX512-VBMI2", &cpu_x86::HW_AVX512_VBMI2},
{"AVX512-VPCLMUL", &cpu_x86::HW_AVX512_VPCLMUL},
{"AVX512-VNNI", &cpu_x86::HW_AVX512_VNNI},
{"AVX512-BITALG", &cpu_x86::HW_AVX512_BITALG},
{"AVX512-BF16", &cpu_x86::HW_AVX512_BF16},
};

auto result = true;

for (auto argIndex = 1; argIndex < argc; argIndex++)
{
for (const auto& feature : featureList)
{
if (!case_insensitive_compare(argv[argIndex], feature.name))
continue;

auto supported = features.*(feature.feature);
if (!supported)
result = false;

cout << feature.name << " = " << (supported ? "Yes" : "No") << endl;
}
}

cout << "Final = " << (result ? "Yes" : "No") << endl;

return result ? 0 : 1;
}
2 changes: 1 addition & 1 deletion src/x86/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

add_library(FeatureDetector cpu_x86.cpp cpu_x86.h cpu_x86_Linux.ipp cpu_x86_Windows.ipp)
add_library(FeatureDetectorLib cpu_x86.cpp cpu_x86.h cpu_x86_Linux.ipp cpu_x86_Windows.ipp)
Loading