summaryrefslogtreecommitdiffhomepage
path: root/include/ocl/simd
diff options
context:
space:
mode:
Diffstat (limited to 'include/ocl/simd')
-rw-r--r--include/ocl/simd/basic_simd.hpp47
-rw-r--r--include/ocl/simd/simd.hpp61
2 files changed, 108 insertions, 0 deletions
diff --git a/include/ocl/simd/basic_simd.hpp b/include/ocl/simd/basic_simd.hpp
new file mode 100644
index 0000000..a401dbd
--- /dev/null
+++ b/include/ocl/simd/basic_simd.hpp
@@ -0,0 +1,47 @@
+/*
+ * File: simd/basic_simd.hpp
+ * Purpose: Basic SIMD backend C++ library.
+ * Author: Amlal El Mahrouss (amlal@nekernel.org)
+ * Copyright 2025, Amlal El Mahrouss, licensed under the BSL 1.0 license.
+ */
+
+#pragma once
+
+#include <core/includes.hpp>
+
+#ifdef __x86_64__
+#include <immintrin.h>
+using simd_type = __m256;
+#endif
+
+#ifdef __aarch64__
+#include <arm_neon.h>
+using simd_type = float32x4_t;
+#endif
+
+namespace ocl::simd
+{
+ struct basic_simd final
+ {
+ struct simd_traits final
+ {
+ simd_type __val;
+
+ private:
+ static bool bad;
+ friend class basic_simd;
+ };
+
+ using register_type = simd_traits;
+
+ const bool& is_bad() noexcept
+ {
+ return register_type::bad;
+ }
+
+ std::basic_string<char> isa()
+ {
+ return "basic_simd";
+ }
+ };
+} // namespace ocl::simd
diff --git a/include/ocl/simd/simd.hpp b/include/ocl/simd/simd.hpp
new file mode 100644
index 0000000..711bf31
--- /dev/null
+++ b/include/ocl/simd/simd.hpp
@@ -0,0 +1,61 @@
+/*
+ * File: simd/simd.hpp
+ * Purpose: SIMD C++ library.
+ * Author: Amlal El Mahrouss (amlal@nekernel.org)
+ * Copyright 2025, Amlal El Mahrouss, licensed under the BSL 1.0 license.
+ */
+
+#pragma once
+
+#include <core/includes.hpp>
+
+/// @author Amlal El Mahrouss
+/// @brief Basic SIMD processor.
+
+namespace ocl::simd
+{
+ template <typename backend_type>
+ class real_type
+ {
+ private:
+ backend_type backend_;
+
+ enum opcode
+ {
+ bad = 0,
+ add,
+ mul,
+ div,
+ invalid = 0xfff,
+ };
+
+ public:
+ real_type() = default;
+ virtual ~real_type() = default;
+
+ real_type& operator=(const real_type&) = delete;
+ real_type(const real_type&) = delete;
+
+ typename backend_type::register_type& call(const opcode& op, typename backend_type::register_type& lhs, typename backend_type::register_type& rhs)
+ {
+ switch (op)
+ {
+ case add:
+ return backend_.add(lhs, rhs);
+ case mul:
+ return backend_.mul(lhs, rhs);
+ case div:
+ return backend_.div(lhs, rhs);
+ default:
+ break;
+ }
+
+ return backend_.is_bad();
+ }
+
+ std::basic_string<char> isa()
+ {
+ return backend_.isa();
+ }
+ };
+} // namespace ocl::simd