summaryrefslogtreecommitdiffhomepage
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
commit1a72c38631b775529ba63aeec1f35df7080be609 (patch)
tree3377c9e1fbe00dbd45d90d2eb22dc524443b816d /src/crypto/simd.h
parent9160aae97794bac985d8dcb644a12c944fb11d33 (diff)
crypto: move simd context to specific type
Suggested-by: Andy Lutomirski <luto@kernel.org> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
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 */