Skip to content

Commit

Permalink
Provide modeling and runtime detection of imm8 arm extension
Browse files Browse the repository at this point in the history
Some extra thoughts could be done on the way we model instruction set
extensions, I'm not happy with the way it's currently done.
  • Loading branch information
serge-sans-paille committed Feb 20, 2024
1 parent ead0742 commit 490d0f4
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 1 deletion.
17 changes: 17 additions & 0 deletions include/xsimd/arch/xsimd_i8mm_neon64.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/***************************************************************************
* 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_I8MM_NEON64_HPP
#define XSIMD_I8MM_NEON64_HPP

#include "../types/xsimd_i8mm_neon64_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 @@ -104,6 +104,10 @@
#include "./xsimd_neon64.hpp"
#endif

#if XSIMD_WITH_I8MM_NEON64
#include "./xsimd_i8mm_neon64.hpp"
#endif

#if XSIMD_WITH_SVE
#include "./xsimd_sve.hpp"
#endif
Expand Down
2 changes: 1 addition & 1 deletion include/xsimd/config/xsimd_arch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ namespace xsimd

using all_sve_architectures = arch_list<detail::sve<512>, detail::sve<256>, detail::sve<128>>;
using all_rvv_architectures = arch_list<detail::rvv<512>, detail::rvv<256>, detail::rvv<128>>;
using all_arm_architectures = typename detail::join<all_sve_architectures, arch_list<neon64, neon>>::type;
using all_arm_architectures = typename detail::join<all_sve_architectures, arch_list<i8mm<neon64>, neon64, neon>>::type;
using all_riscv_architectures = all_rvv_architectures;
using all_wasm_architectures = arch_list<wasm>;
using all_architectures = typename detail::join<all_riscv_architectures, all_wasm_architectures, all_arm_architectures, all_x86_architectures>::type;
Expand Down
11 changes: 11 additions & 0 deletions include/xsimd/config/xsimd_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,17 @@
#define XSIMD_WITH_NEON64 0
#endif

/**
* @ingroup xsimd_config_macro
*
* Set to 1 if i8mm neon64 extension is available at compile-time, to 0 otherwise.
*/
#if defined(__ARM_FEATURE_MATMUL_INT8)
#define XSIMD_WITH_I8MM_NEON64 1
#else
#define XSIMD_WITH_I8MM_NEON64 0
#endif

/**
* @ingroup xsimd_config_macro
*
Expand Down
9 changes: 9 additions & 0 deletions include/xsimd/config/xsimd_cpuid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
#if defined(__linux__) && (defined(__ARM_NEON) || defined(_M_ARM) || defined(__riscv_vector))
#include <asm/hwcap.h>
#include <sys/auxv.h>

#ifndef HWCAP2_I8MM
#define HWCAP2_I8MM (1 << 13)
#endif

#endif

#if defined(_MSC_VER)
Expand Down Expand Up @@ -66,6 +71,7 @@ namespace xsimd
ARCH_FIELD_EX(avx512vnni<::xsimd::avx512vbmi>, avx512vnni_vbmi)
ARCH_FIELD(neon)
ARCH_FIELD(neon64)
ARCH_FIELD_EX(i8mm<::xsimd::neon64>, i8mm_neon64)
ARCH_FIELD(sve)
ARCH_FIELD(rvv)
ARCH_FIELD(wasm)
Expand All @@ -83,6 +89,9 @@ namespace xsimd
#if defined(__aarch64__) || defined(_M_ARM64)
neon = 1;
neon64 = 1;
#if defined(__linux__) && (!defined(__ANDROID_API__) || __ANDROID_API__ >= 18)
i8mm_neon64 = bool(getauxval(AT_HWCAP2) & HWCAP2_I8MM);
#endif
#elif defined(__ARM_NEON) || defined(_M_ARM)

#if defined(__linux__) && (!defined(__ANDROID_API__) || __ANDROID_API__ >= 18)
Expand Down
2 changes: 2 additions & 0 deletions include/xsimd/types/xsimd_all_registers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#include "xsimd_avx512dq_register.hpp"
#include "xsimd_avx512f_register.hpp"

#include "xsimd_i8mm_neon64_register.hpp"

#include "xsimd_neon64_register.hpp"
#include "xsimd_neon_register.hpp"

Expand Down
46 changes: 46 additions & 0 deletions include/xsimd/types/xsimd_i8mm_neon64_register.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/***************************************************************************
* 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_I8MM_NEON64_REGISTER_HPP
#define XSIMD_I8MM_NEON64_REGISTER_HPP

#include "./xsimd_neon64_register.hpp"

namespace xsimd
{
template <typename arch>
struct i8mm;

/**
* @ingroup architectures
*
* Neon64 + i8mm instructions
*/
template <>
struct i8mm<neon64> : neon64
{
static constexpr bool supported() noexcept { return XSIMD_WITH_I8MM_NEON64; }
static constexpr bool available() noexcept { return true; }
static constexpr unsigned version() noexcept { return generic::version(8, 2, 0); }
static constexpr char const* name() noexcept { return "i8mm+neon64"; }
};

#if XSIMD_WITH_I8MM_NEON64
namespace types
{

XSIMD_DECLARE_SIMD_REGISTER_ALIAS(i8mm<neon64>, neon64);

}
#endif

}
#endif

0 comments on commit 490d0f4

Please sign in to comment.