summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-09-12 20:23:39 +0200
committerAmlal El Mahrouss <amlal@nekernel.org>2025-09-12 20:23:39 +0200
commitfa4748e414e9494442f9bcde9c659d3951af19c0 (patch)
tree435f5b6adb6889462640b1456e684360cd7e495f
parent3f9c5017abf3c4279780f685580a334574e6d760 (diff)
feat: dev/lib: new `basic_simd` class, better `error_handler` class.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
-rw-r--r--dev/lib/core/error_handler.hpp4
-rw-r--r--dev/lib/io/print.hpp2
-rw-r--r--dev/lib/simd/avx.hpp21
-rw-r--r--dev/lib/simd/basic_simd.hpp50
-rw-r--r--dev/lib/simd/simd.hpp9
5 files changed, 59 insertions, 27 deletions
diff --git a/dev/lib/core/error_handler.hpp b/dev/lib/core/error_handler.hpp
index 593e54a..1a1515d 100644
--- a/dev/lib/core/error_handler.hpp
+++ b/dev/lib/core/error_handler.hpp
@@ -9,6 +9,7 @@
#define _OCL_ERROR_HANDLER_HPP
#include <lib/core/includes.hpp>
+#include <lib/io/print.hpp>
#include <stdexcept>
namespace ocl
@@ -25,11 +26,12 @@ namespace ocl
virtual void operator()(const std::basic_string<char>& msg)
{
- ((void)msg);
+ ocl::io::print(msg);
}
};
using standard_error_handler = basic_error_handler;
+ using error_handler_type = basic_error_handler;
} // namespace ocl
#endif // ifndef _OCL_ERROR_HANDLER_HPP
diff --git a/dev/lib/io/print.hpp b/dev/lib/io/print.hpp
index 40ae1bb..307c06f 100644
--- a/dev/lib/io/print.hpp
+++ b/dev/lib/io/print.hpp
@@ -35,7 +35,7 @@ namespace ocl::io
inline void println(T... fmt) noexcept
{
print(fmt...);
- print();
+ print();
}
} // namespace ocl::io
diff --git a/dev/lib/simd/avx.hpp b/dev/lib/simd/avx.hpp
deleted file mode 100644
index 16e495e..0000000
--- a/dev/lib/simd/avx.hpp
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * File: simd/avx.hpp
- * Purpose: AVX C++ library.
- * Author: Amlal El Mahrouss (founder@snu.systems)
- * Copyright 2025, Amlal El Mahrouss, and SNU Systems, Corp, licensed under the BSL 1.0 license.
- */
-
-#pragma once
-
-#include <lib/core/includes.hpp>
-
-namespace ocl::snu::simd
-{
- struct avx_256_backend final
- {
- std::basic_string<char> isa()
- {
- return "AVX-256";
- }
- };
-} // namespace ocl::snu::simd
diff --git a/dev/lib/simd/basic_simd.hpp b/dev/lib/simd/basic_simd.hpp
new file mode 100644
index 0000000..d748d0c
--- /dev/null
+++ b/dev/lib/simd/basic_simd.hpp
@@ -0,0 +1,50 @@
+/*
+ * File: simd/basic_simd.hpp
+ * Purpose: Basic SIMD backend C++ library.
+ * Author: Amlal El Mahrouss (founder@snu.systems)
+ * Copyright 2025, Amlal El Mahrouss, and SNU Systems, Corp, licensed under the BSL 1.0 license.
+ */
+
+#pragma once
+
+#include <lib/core/includes.hpp>
+#include <cmath>
+
+#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::snu::simd
+{
+ struct basic_simd_backend final
+ {
+ struct simd_traits final
+ {
+ simd_type __val;
+
+ private:
+ static bool bad;
+ friend class basic_simd_backend;
+ };
+
+ using register_type = simd_traits;
+
+ const bool& is_bad() noexcept
+ {
+ return register_type::bad;
+ }
+
+ std::basic_string<char> isa()
+ {
+ return "basic-backend";
+ }
+ };
+} // namespace ocl::snu::simd
diff --git a/dev/lib/simd/simd.hpp b/dev/lib/simd/simd.hpp
index 0f8f451..779d020 100644
--- a/dev/lib/simd/simd.hpp
+++ b/dev/lib/simd/simd.hpp
@@ -14,11 +14,11 @@
namespace ocl::snu::simd
{
- template <typename SimdBackend>
+ template <typename backend_type>
class basic_simd_processor
{
private:
- SimdBackend processor_;
+ backend_type processor_;
enum opcode
{
@@ -35,7 +35,7 @@ namespace ocl::snu::simd
basic_simd_processor& operator=(const basic_simd_processor&) = delete;
basic_simd_processor(const basic_simd_processor&) = delete;
- typename SimdBackend::Register& call(const opcode& op, typename SimdBackend::Register& lhs, typename SimdBackend::Register& rhs)
+ typename backend_type::register_type& call(const opcode& op, typename backend_type::register_type& lhs, typename backend_type::register_type& rhs)
{
switch (op)
{
@@ -48,7 +48,8 @@ namespace ocl::snu::simd
default:
break;
}
- return SimdBackend::Register::bad;
+
+ return processor_.is_bad();
}
std::basic_string<char> isa()