Created
December 23, 2014 12:37
-
-
Save oguna/06de1c7f3f3ce8e67918 to your computer and use it in GitHub Desktop.
C++/CLIでSIMDサポートを調べる
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "Simd.h" | |
| #include "Windows.h" | |
| using namespace SharpDX::SIMD; | |
| #pragma unmanaged | |
| void getCpuId(unsigned int* _ecx, unsigned int* _edx) | |
| { | |
| unsigned int output_ecx; | |
| unsigned int output_edx; | |
| __asm | |
| { | |
| mov eax, 1; | |
| cpuid; | |
| mov output_ecx, ecx; | |
| mov output_edx, edx; | |
| } | |
| *_ecx = output_ecx; | |
| *_edx = output_edx; | |
| } | |
| #pragma managed | |
| void Simd::check() | |
| { | |
| // by windows.h | |
| mmx = 1 == IsProcessorFeaturePresent(PF_MMX_INSTRUCTIONS_AVAILABLE); | |
| sse = 1 == IsProcessorFeaturePresent(PF_XMMI_INSTRUCTIONS_AVAILABLE); | |
| sse2 = 1 == IsProcessorFeaturePresent(PF_XMMI64_INSTRUCTIONS_AVAILABLE); | |
| sse3 = 1 == IsProcessorFeaturePresent(PF_SSE3_INSTRUCTIONS_AVAILABLE); | |
| // by cpuid | |
| unsigned int output_edx; | |
| unsigned int output_ecx; | |
| getCpuId(&output_ecx, &output_edx); | |
| mmx = (output_edx & 0x00800000) > 0; | |
| sse = (output_edx & 0x02000000) > 0; | |
| sse2 = (output_edx & 0x04000000) > 0; | |
| sse3 = (output_ecx & 0x00000001) > 0; | |
| sse4_1 = (output_ecx & 0x00080000) > 0; | |
| sse4_2 = (output_ecx & 0x00100000) > 0; | |
| } | |
| bool Simd::MmxAvailable::get() | |
| { | |
| if (!checked) | |
| { | |
| check(); | |
| } | |
| return mmx; | |
| } | |
| bool Simd::SseAvailable::get() | |
| { | |
| if (!checked) | |
| { | |
| check(); | |
| } | |
| return sse; | |
| } | |
| bool Simd::Sse2Available::get() | |
| { | |
| if (!checked) | |
| { | |
| check(); | |
| } | |
| return sse2; | |
| } | |
| bool Simd::Sse3Available::get() | |
| { | |
| if (!checked) | |
| { | |
| check(); | |
| } | |
| return sse3; | |
| } | |
| bool Simd::Sse4_1Available::get() | |
| { | |
| if (!checked) | |
| { | |
| check(); | |
| } | |
| return sse4_1; | |
| } | |
| bool Simd::Sse4_2Available::get() | |
| { | |
| if (!checked) | |
| { | |
| check(); | |
| } | |
| return sse4_2; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #pragma once | |
| #include "Windows.h" | |
| namespace SharpDX | |
| { | |
| namespace SIMD | |
| { | |
| public ref class Simd | |
| { | |
| internal: | |
| static bool mmx; | |
| static bool sse; | |
| static bool sse2; | |
| static bool sse3; | |
| static bool sse4_1; | |
| static bool sse4_2; | |
| static void check(); | |
| static bool checked; | |
| public: | |
| static property bool MmxAvailable | |
| { | |
| bool get(); | |
| } | |
| static property bool SseAvailable | |
| { | |
| bool get(); | |
| } | |
| static property bool Sse2Available | |
| { | |
| bool get(); | |
| } | |
| static property bool Sse3Available | |
| { | |
| bool get(); | |
| } | |
| static property bool Sse4_1Available | |
| { | |
| bool get(); | |
| } | |
| static property bool Sse4_2Available | |
| { | |
| bool get(); | |
| } | |
| }; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment