summaryrefslogtreecommitdiffhomepage
path: root/include/ocl/simd
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-11-23 20:16:02 -0500
committerGitHub <noreply@github.com>2025-11-23 20:16:02 -0500
commit85f89ee4bb137100cbeffcbc10168eb8ea52e6cc (patch)
treef6e2063319ceaaa02f523fb5c289e4f37411a2df /include/ocl/simd
parent9a70f32ddaec0eef99efbf7ff5597c2adf08f45a (diff)
parent65a8349aa5526d071b18cd4d42586c46faaa3823 (diff)
Merge pull request #18 from amlel-el-mahrouss/developv1.0.48
OCL v1.0.48
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