cOMS/Stdlib/SIMD/SIMD_Helper.h
Dennis Eichhorn 3cd7ada19e
Some checks failed
CI / code-tests: ${{ matrix.os }} / ${{ matrix.platform }} (ubuntu-latest, x64) (push) Has been cancelled
CI / code-tests: ${{ matrix.os }} / ${{ matrix.platform }} (ubuntu-latest, x86) (push) Has been cancelled
CI / general_module_workflow_c (push) Has been cancelled
improve
2024-05-26 02:18:15 +02:00

58 lines
1.3 KiB
C++

/**
* Karaka
*
* @package Stdlib
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://jingga.app
*/
#ifndef STDLIB_SIMD_HELPER_H
#define STDLIB_SIMD_HELPER_H
#include <immintrin.h>
#include <stdint.h>
#include <xmmintrin.h>
namespace Stdlib::SIMD
{
bool is_sse_supported()
{
uint32_t eax, ebx, ecx, edx;
eax = 1; // CPUID function 1
__asm__ __volatile__("cpuid;" : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) : "a"(eax));
// Check the AVX feature bit in ECX
return (ecx >> 28) & 1;
}
bool is_avx256_supported()
{
uint32_t eax, ebx, ecx, edx;
eax = 7; // CPUID function 7
ecx = 0; // Sub-function 0
__asm__ __volatile__("cpuid;" : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) : "a"(eax), "c"(ecx));
// Check the AVX-256 (AVX2) feature bit in EBX
return (ebx >> 5) & 1;
}
bool is_avx512_supported()
{
uint32_t eax, ebx, ecx, edx;
eax = 7; // CPUID function 7
ecx = 0; // Sub-function 0
__asm__ __volatile__("cpuid;" : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx) : "a"(eax), "c"(ecx));
// Check the AVX-512 feature bit in EBX
return (ebx >> 16) & 1;
}
} // namespace Stdlib::SIMD
#endif