aboutsummaryrefslogtreecommitdiffstats
path: root/libblake_init.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2022-01-21 18:29:26 +0100
committerMattias Andrée <maandree@kth.se>2022-01-21 18:29:26 +0100
commit839a3d17d257e73be9bc99dfa90e56c0824050ba (patch)
tree6bb010351447edbb0ae8d910948b01837d2de9e5 /libblake_init.c
parentFix memory corruption bug in test.c and simplify message byte-length calculation (diff)
downloadlibblake-839a3d17d257e73be9bc99dfa90e56c0824050ba.tar.gz
libblake-839a3d17d257e73be9bc99dfa90e56c0824050ba.tar.bz2
libblake-839a3d17d257e73be9bc99dfa90e56c0824050ba.tar.xz
Initial work on optimising compression function; mm128 version is slower, mm256 version is barely faster
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'libblake_init.c')
-rw-r--r--libblake_init.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/libblake_init.c b/libblake_init.c
new file mode 100644
index 0000000..ebf0e34
--- /dev/null
+++ b/libblake_init.c
@@ -0,0 +1,27 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+#include <stdatomic.h>
+
+#if defined(__GNUC__)
+__attribute__((__constructor__)) /* ignored if statically linked, so this function shall
+ * by the application, we just use the constructor (init)
+ * attribute incase that is forgotten, as it will only
+ * improve performance, but the library with function
+ * perfectly fine even if it's not called */
+#endif
+void
+libblake_init(void)
+{
+ static volatile int initialised = 0;
+ static volatile atomic_flag spinlock = ATOMIC_FLAG_INIT;
+
+ while (atomic_flag_test_and_set(&spinlock));
+
+ if (!initialised) {
+ /* libblake_internal_blake2b_compress_mm128_init(); */
+ /* libblake_internal_blake2b_compress_mm256_init(); */
+ initialised = 1;
+ }
+
+ atomic_flag_clear(&spinlock);
+}