From 3c5f5b01ba02974b172e6180aeda6eb7cdf0f91e Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 18 Nov 2025 09:18:08 +0100 Subject: fix: chunk_string: include print.hpp Signed-off-by: Amlal El Mahrouss --- dev/lib/core/chunk_string.hpp | 1 + 1 file changed, 1 insertion(+) (limited to 'dev') diff --git a/dev/lib/core/chunk_string.hpp b/dev/lib/core/chunk_string.hpp index 4fe5cc2..c99bfc8 100644 --- a/dev/lib/core/chunk_string.hpp +++ b/dev/lib/core/chunk_string.hpp @@ -9,6 +9,7 @@ #define OCL_UTILITY_CHUNK_STRING_HPP #include +#include namespace ocl { -- cgit v1.2.3 From 226bf12ca084705f47ed6aa66932f5efb4a7796b Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 18 Nov 2025 09:45:59 +0100 Subject: feat: chunk_string: `str()` performance improvements. Signed-off-by: Amlal El Mahrouss --- dev/lib/core/chunk_string.hpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'dev') diff --git a/dev/lib/core/chunk_string.hpp b/dev/lib/core/chunk_string.hpp index c99bfc8..77e6864 100644 --- a/dev/lib/core/chunk_string.hpp +++ b/dev/lib/core/chunk_string.hpp @@ -79,11 +79,14 @@ namespace ocl std::basic_string str() const noexcept { static std::basic_string ret; + const auto& sz = ret.size(); - if (ret.size() > 0) + if (chunk_total_ > sz) ret.clear(); + else + return ret; - ret += packed_chunks_; + ret = packed_chunks_; return ret; } -- cgit v1.2.3 From 34ffda2f0cc9d884f3f6062d4a264db5ba76180a Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 18 Nov 2025 09:49:47 +0100 Subject: feat: chunk_string: class` performance improvements. and new operator overload. Signed-off-by: Amlal El Mahrouss --- dev/lib/core/chunk_string.hpp | 14 ++++++++++++++ dev/tests/chunk_string/chunk_test.cc | 9 +++++---- 2 files changed, 19 insertions(+), 4 deletions(-) (limited to 'dev') diff --git a/dev/lib/core/chunk_string.hpp b/dev/lib/core/chunk_string.hpp index 77e6864..7e5360c 100644 --- a/dev/lib/core/chunk_string.hpp +++ b/dev/lib/core/chunk_string.hpp @@ -46,6 +46,19 @@ namespace ocl basic_chunk_string(const basic_chunk_string&) = delete; public: + /// @brief Append a std::basic_string to the chunk string. + basic_chunk_string& operator+=(const char_type* in) + { + if (in == nullptr || bad_) + return *this; + + const auto& sz = std::strlen(in); + + this->operator+=(std::basic_string(in, sz)); + + return *this; + } + basic_chunk_string& operator+=(const std::basic_string& in) { if (in.empty() || bad_) @@ -76,6 +89,7 @@ namespace ocl return *this; } + /// @brief Convert to basic_string or return from cache. std::basic_string str() const noexcept { static std::basic_string ret; diff --git a/dev/tests/chunk_string/chunk_test.cc b/dev/tests/chunk_string/chunk_test.cc index 973ce43..7d68ae2 100644 --- a/dev/tests/chunk_string/chunk_test.cc +++ b/dev/tests/chunk_string/chunk_test.cc @@ -11,12 +11,13 @@ TEST(ChunkTest, BasicChunkUsage) { - const std::string test_string = "HELLO, WORLD!"; - const unsigned iterations = 1024000; + const char* test_string = "HELLO, WORLD!\r\n"; + const auto iterations = 1024000; + const auto limit = 30; auto start = std::chrono::high_resolution_clock::now(); - ocl::basic_chunk_string optimized; + ocl::basic_chunk_string optimized; for (unsigned i = 0; i < iterations; ++i) { @@ -26,5 +27,5 @@ TEST(ChunkTest, BasicChunkUsage) auto end = std::chrono::high_resolution_clock::now(); auto optimized_time = std::chrono::duration_cast(end - start); - EXPECT_TRUE(optimized_time.count() < 30U); + EXPECT_TRUE(optimized_time.count() < limit); } -- cgit v1.2.3 From 54940e80e0a259f748d483291e0e7aef7dd98353 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 18 Nov 2025 14:12:16 +0100 Subject: fix: simd.hpp: better opcode enum. Signed-off-by: Amlal El Mahrouss --- dev/lib/simd/simd.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'dev') diff --git a/dev/lib/simd/simd.hpp b/dev/lib/simd/simd.hpp index e571b23..22650bb 100644 --- a/dev/lib/simd/simd.hpp +++ b/dev/lib/simd/simd.hpp @@ -22,10 +22,11 @@ namespace ocl::snu::simd enum opcode { - bad, + bad = 0, add, mul, div, + invalid = 0xfff, }; public: -- cgit v1.2.3