aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/compat/compat.h
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-09-28 16:06:49 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-10-02 03:41:49 +0200
commit7a49918c35b389166943f48d88a8ff9b2a78e9e4 (patch)
tree6c3857fd4fa8fab6cdaf0f1531eaa8e6727b5bed /src/compat/compat.h
parentsimd: return a bool from simd_relax (diff)
downloadwireguard-monolithic-historical-7a49918c35b389166943f48d88a8ff9b2a78e9e4.tar.xz
wireguard-monolithic-historical-7a49918c35b389166943f48d88a8ff9b2a78e9e4.zip
simd: refactor simd availability handling
Diffstat (limited to 'src/compat/compat.h')
-rw-r--r--src/compat/compat.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/compat/compat.h b/src/compat/compat.h
index 2e67edb..8c679a1 100644
--- a/src/compat/compat.h
+++ b/src/compat/compat.h
@@ -737,6 +737,24 @@ static inline void crypto_xor_cpy(u8 *dst, const u8 *src1, const u8 *src2,
#define read_cpuid_part() read_cpuid_part_number()
#endif
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 13, 0) || (!defined(CONFIG_X86_64) && !defined(CONFIG_ARM64) && !defined(CONFIG_ARM))
+#if defined(CONFIG_X86_64)
+#include <asm/fpu/api.h>
+#endif
+static __must_check inline bool may_use_simd(void)
+{
+#if defined(CONFIG_X86_64)
+ return irq_fpu_usable();
+#elif defined(CONFIG_ARM64) && defined(CONFIG_KERNEL_MODE_NEON)
+ return true;
+#elif defined(CONFIG_ARM) && defined(CONFIG_KERNEL_MODE_NEON)
+ return !in_nmi() && !in_irq() && !in_serving_softirq();
+#else
+ return false;
+#endif
+}
+#endif
+
/* https://lkml.kernel.org/r/20170624021727.17835-1-Jason@zx2c4.com */
#if IS_ENABLED(CONFIG_NF_CONNTRACK)
#include <linux/ip.h>