aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/crypto/simd.h
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-08-06 18:31:18 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-08-06 19:25:29 +0200
commit5856479cdaf7e87f2bc46881246607ec3b887dae (patch)
treebfff84bd6d34cfefa014681629b55a5081d0ed54 /src/crypto/simd.h
parentcompat: better atomic acquire/release backport (diff)
downloadwireguard-monolithic-historical-5856479cdaf7e87f2bc46881246607ec3b887dae.tar.xz
wireguard-monolithic-historical-5856479cdaf7e87f2bc46881246607ec3b887dae.zip
crypto: move simd context to specific type
Suggested-by: Andy Lutomirski <luto@kernel.org>
Diffstat (limited to 'src/crypto/simd.h')
-rw-r--r--src/crypto/simd.h23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/crypto/simd.h b/src/crypto/simd.h
index 007f66e..6adf0c3 100644
--- a/src/crypto/simd.h
+++ b/src/crypto/simd.h
@@ -16,7 +16,12 @@
#include <asm/simd.h>
#endif
-static inline bool simd_get(void)
+typedef enum {
+ HAVE_NO_SIMD,
+ HAVE_FULL_SIMD
+} simd_context_t;
+
+static inline simd_context_t simd_get(void)
{
bool have_simd = false;
#if defined(CONFIG_X86_64) && !defined(CONFIG_UML) && !defined(CONFIG_PREEMPT_RT_BASE)
@@ -32,29 +37,29 @@ static inline bool simd_get(void)
if (have_simd)
kernel_neon_begin();
#endif
- return have_simd;
+ return have_simd ? HAVE_FULL_SIMD : HAVE_NO_SIMD;
}
-static inline void simd_put(bool was_on)
+static inline void simd_put(simd_context_t prior_context)
{
#if defined(CONFIG_X86_64) && !defined(CONFIG_UML) && !defined(CONFIG_PREEMPT_RT_BASE)
- if (was_on)
+ if (prior_context != HAVE_NO_SIMD)
kernel_fpu_end();
#elif IS_ENABLED(CONFIG_KERNEL_MODE_NEON) && !defined(CONFIG_PREEMPT_RT_BASE)
- if (was_on)
+ if (prior_context != HAVE_NO_SIMD)
kernel_neon_end();
#endif
}
-static inline bool simd_relax(bool was_on)
+static inline simd_context_t simd_relax(simd_context_t prior_context)
{
#ifdef CONFIG_PREEMPT
- if (was_on && need_resched()) {
- simd_put(true);
+ if (prior_context != HAVE_NO_SIMD && need_resched()) {
+ simd_put(prior_context);
return simd_get();
}
#endif
- return was_on;
+ return prior_context;
}
#endif /* _WG_SIMD_H */