Skip to content

Commit

Permalink
Provide stub for avx vnni architecture
Browse files Browse the repository at this point in the history
  • Loading branch information
serge-sans-paille committed Dec 4, 2023
1 parent c7413e5 commit c934e4c
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 6 deletions.
20 changes: 20 additions & 0 deletions include/xsimd/arch/xsimd_avxvnni.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/***************************************************************************
* Copyright (c) Johan Mabille, Sylvain Corlay, Wolf Vollprecht and *
* Martin Renou *
* Copyright (c) QuantStack *
* Copyright (c) Serge Guelton *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/

#ifndef XSIMD_AVXVNNI_HPP
#define XSIMD_AVXVNNI_HPP

#include <array>
#include <type_traits>

#include "../types/xsimd_avxvnni_register.hpp"

#endif
4 changes: 4 additions & 0 deletions include/xsimd/arch/xsimd_isa.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
#include "./xsimd_fma3_avx.hpp"
#endif

#if XSIMD_WITH_AVXVNNI
#include "./xsimd_avxvnni.hpp"
#endif

#if XSIMD_WITH_AVX2
#include "./xsimd_avx2.hpp"
#endif
Expand Down
13 changes: 12 additions & 1 deletion include/xsimd/config/xsimd_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@
#define XSIMD_WITH_AVX2 0
#endif

/**
* @ingroup xsimd_config_macro
*
* Set to 1 if AVXVNNI is available at compile-time, to 0 otherwise.
*/
#ifdef __AVXVNNI__
#define XSIMD_WITH_AVXVNNI 1
#else
#define XSIMD_WITH_AVXVNNI 0
#endif

/**
* @ingroup xsimd_config_macro
*
Expand Down Expand Up @@ -422,7 +433,7 @@

#endif

#if !XSIMD_WITH_SSE2 && !XSIMD_WITH_SSE3 && !XSIMD_WITH_SSSE3 && !XSIMD_WITH_SSE4_1 && !XSIMD_WITH_SSE4_2 && !XSIMD_WITH_AVX && !XSIMD_WITH_AVX2 && !XSIMD_WITH_FMA3_SSE && !XSIMD_WITH_FMA4 && !XSIMD_WITH_FMA3_AVX && !XSIMD_WITH_FMA3_AVX2 && !XSIMD_WITH_AVX512F && !XSIMD_WITH_AVX512CD && !XSIMD_WITH_AVX512DQ && !XSIMD_WITH_AVX512BW && !XSIMD_WITH_AVX512ER && !XSIMD_WITH_AVX512PF && !XSIMD_WITH_AVX512IFMA && !XSIMD_WITH_AVX512VBMI && !XSIMD_WITH_NEON && !XSIMD_WITH_NEON64 && !XSIMD_WITH_SVE && !XSIMD_WITH_RVV && !XSIMD_WITH_WASM
#if !XSIMD_WITH_SSE2 && !XSIMD_WITH_SSE3 && !XSIMD_WITH_SSSE3 && !XSIMD_WITH_SSE4_1 && !XSIMD_WITH_SSE4_2 && !XSIMD_WITH_AVX && !XSIMD_WITH_AVX2 && !XSIMD_WITH_AVXVNNI && !XSIMD_WITH_FMA3_SSE && !XSIMD_WITH_FMA4 && !XSIMD_WITH_FMA3_AVX && !XSIMD_WITH_FMA3_AVX2 && !XSIMD_WITH_AVX512F && !XSIMD_WITH_AVX512CD && !XSIMD_WITH_AVX512DQ && !XSIMD_WITH_AVX512BW && !XSIMD_WITH_AVX512ER && !XSIMD_WITH_AVX512PF && !XSIMD_WITH_AVX512IFMA && !XSIMD_WITH_AVX512VBMI && !XSIMD_WITH_NEON && !XSIMD_WITH_NEON64 && !XSIMD_WITH_SVE && !XSIMD_WITH_RVV && !XSIMD_WITH_WASM
#endif

#endif
16 changes: 11 additions & 5 deletions include/xsimd/config/xsimd_cpuid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ namespace xsimd
unsigned avx : 1;
unsigned fma3_avx : 1;
unsigned avx2 : 1;
unsigned avxvnni : 1;
unsigned fma3_avx2 : 1;
unsigned avx512f : 1;
unsigned avx512cd : 1;
Expand Down Expand Up @@ -104,14 +105,14 @@ namespace xsimd

best = ::xsimd::rvv::version() * rvv;
#elif defined(__x86_64__) || defined(__i386__) || defined(_M_AMD64) || defined(_M_IX86)
auto get_cpuid = [](int reg[4], int func_id) noexcept
auto get_cpuid = [](int reg[4], int level, int count = 0) noexcept
{

#if defined(_MSC_VER)
__cpuidex(reg, func_id, 0);
__cpuidex(reg, level, count);

#elif defined(__INTEL_COMPILER)
__cpuid(reg, func_id);
__cpuid(reg, level);

#elif defined(__GNUC__) || defined(__clang__)

Expand All @@ -122,13 +123,13 @@ namespace xsimd
"xchg{l}\t{%%}ebx, %1\n\t"
: "=a"(reg[0]), "=r"(reg[1]), "=c"(reg[2]),
"=d"(reg[3])
: "a"(func_id), "c"(0));
: "0"(level), "2"(count));

#else
__asm__("cpuid\n\t"
: "=a"(reg[0]), "=b"(reg[1]), "=c"(reg[2]),
"=d"(reg[3])
: "a"(func_id), "c"(0));
: "0"(level), "2"(count));
#endif

#else
Expand Down Expand Up @@ -181,6 +182,11 @@ namespace xsimd
avx2 = regs7[1] >> 5 & 1;
best = std::max(best, avx2::version() * avx2);

int regs7a[4];
get_cpuid(regs7a, 0x7, 0x1);
avxvnni = regs7a[0] >> 4 & 1;
best = std::max(best, avxvnni::version() * avxvnni * avx2);

fma3_avx2 = avx2 && fma3_sse;
best = std::max(best, fma3<xsimd::avx2>::version() * fma3_avx2);

Expand Down
1 change: 1 addition & 0 deletions include/xsimd/types/xsimd_all_registers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "xsimd_avx2_register.hpp"
#include "xsimd_avx_register.hpp"
#include "xsimd_avxvnni_register.hpp"
#include "xsimd_fma3_avx2_register.hpp"
#include "xsimd_fma3_avx_register.hpp"

Expand Down
40 changes: 40 additions & 0 deletions include/xsimd/types/xsimd_avxvnni_register.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/***************************************************************************
* Copyright (c) Johan Mabille, Sylvain Corlay, Wolf Vollprecht and *
* Martin Renou *
* Copyright (c) QuantStack *
* Copyright (c) Serge Guelton *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/

#ifndef XSIMD_AVXVNNI_REGISTER_HPP
#define XSIMD_AVXVNNI_REGISTER_HPP

#include "./xsimd_avx2_register.hpp"

namespace xsimd
{
/**
* @ingroup architectures
*
* AVXVNNI instructions
*/
struct avxvnni : avx2
{
static constexpr bool supported() noexcept { return XSIMD_WITH_AVXVNNI; }
static constexpr bool available() noexcept { return true; }
static constexpr unsigned version() noexcept { return generic::version(2, 3, 0); }
static constexpr char const* name() noexcept { return "avxvnni"; }
};

#if XSIMD_WITH_AVXVNNI
namespace types
{
XSIMD_DECLARE_SIMD_REGISTER_ALIAS(avxvnni, avx2);
}
#endif
}

#endif

0 comments on commit c934e4c

Please sign in to comment.