From 850923b543cdb275e6a95ebf145c8c2ec4400a91 Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Sat, 27 Jul 2024 09:05:16 -0400 Subject: [PATCH 1/9] ENH: Fix compile warnings in FilterUtilities. Init array in DataStore when resizing Signed-off-by: Michael Jackson --- src/simplnx/DataStructure/DataStore.hpp | 60 ++++++++++++++++++++++- src/simplnx/Utilities/FilterUtilities.hpp | 4 ++ 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/src/simplnx/DataStructure/DataStore.hpp b/src/simplnx/DataStructure/DataStore.hpp index 4aabe5ec44..1178da61b3 100644 --- a/src/simplnx/DataStructure/DataStore.hpp +++ b/src/simplnx/DataStructure/DataStore.hpp @@ -60,11 +60,12 @@ class DataStore : public AbstractDataStore , m_TupleShape(tupleShape) , m_NumComponents(std::accumulate(m_ComponentShape.cbegin(), m_ComponentShape.cend(), static_cast(1), std::multiplies<>())) , m_NumTuples(std::accumulate(m_TupleShape.cbegin(), m_TupleShape.cend(), static_cast(1), std::multiplies<>())) + , m_InitValue(initValue) { resizeTuples(m_TupleShape); - if(initValue.has_value()) + if(m_InitValue.has_value()) { - std::fill_n(data(), this->getSize(), *initValue); + std::fill_n(data(), this->getSize(), *m_InitValue); } } @@ -82,6 +83,47 @@ class DataStore : public AbstractDataStore , m_NumComponents(std::accumulate(m_ComponentShape.cbegin(), m_ComponentShape.cend(), static_cast(1), std::multiplies<>())) , m_NumTuples(std::accumulate(m_TupleShape.cbegin(), m_TupleShape.cend(), static_cast(1), std::multiplies<>())) { + // Because no init value is passed into the constructor, we will use a "mudflap" style value that is easy to debug. + if constexpr(sizeof(T) == 1) + { + m_InitValue = 0xAB; + } + if constexpr(sizeof(T) == 2) + { + m_InitValue = 0xABAB; + } + if constexpr(sizeof(T) == 4) + { + union InitValue { + uint32 i32; + float32 f32; + } initValue; + initValue.i32 = 0xABABABAB; + if constexpr(std::is_floating_point_v) + { + m_InitValue = initValue.f32; + } + else + { + m_InitValue = initValue.i32; + } + } + if constexpr(sizeof(T) == 8) + { + union InitValue { + uint64 i64; + float64 f64; + } initValue; + initValue.i64 = 0xABABABABABABABAB; + if constexpr(std::is_floating_point_v) + { + m_InitValue = initValue.f64; + } + else + { + m_InitValue = initValue.i64; + } + } } /** @@ -94,6 +136,7 @@ class DataStore : public AbstractDataStore , m_TupleShape(other.m_TupleShape) , m_NumComponents(other.m_NumComponents) , m_NumTuples(other.m_NumTuples) + , m_InitValue(other.m_InitValue) { const usize count = other.getSize(); auto* data = new value_type[count]; @@ -112,6 +155,7 @@ class DataStore : public AbstractDataStore , m_Data(std::move(other.m_Data)) , m_NumComponents(std::move(other.m_NumComponents)) , m_NumTuples(std::move(other.m_NumTuples)) + , m_InitValue(other.m_InitValue) { } @@ -244,6 +288,17 @@ class DataStore : public AbstractDataStore { data[i] = m_Data.get()[i]; } + + // If we are sizing to a larger number of tuples, initialize the leftover array with the init + // value that was passed in during construction. + if(m_InitValue.has_value()) + { + for(usize i = oldSize; i < newSize; i++) + { + data[i] = *m_InitValue; + } + } + m_Data.reset(data); } @@ -364,6 +419,7 @@ class DataStore : public AbstractDataStore std::unique_ptr m_Data = nullptr; size_t m_NumComponents = {0}; size_t m_NumTuples = {0}; + std::optional m_InitValue; }; // Declare aliases diff --git a/src/simplnx/Utilities/FilterUtilities.hpp b/src/simplnx/Utilities/FilterUtilities.hpp index b99110de1d..682a0042a9 100644 --- a/src/simplnx/Utilities/FilterUtilities.hpp +++ b/src/simplnx/Utilities/FilterUtilities.hpp @@ -2,6 +2,7 @@ #include "ParallelAlgorithmUtilities.hpp" #include "simplnx/Common/Result.hpp" +#include "simplnx/Common/TypeTraits.hpp" #include "simplnx/Common/Types.hpp" #include "simplnx/Filter/IFilter.hpp" #include "simplnx/Filter/Output.hpp" @@ -94,6 +95,9 @@ auto RunTemplateClass(DataType dataType, ArgsT&&... args) return ClassT(std::forward(args)...)(); } } + std::stringstream ss; + ss << "FilterUtilities::RunTemplateClass<> Error: dataType did not match any known type. DataType was " << to_underlying(dataType); + throw std::runtime_error(ss.str()); } template From 512e2fcf9c6c7d537b992ca119484b3069042757 Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Mon, 29 Jul 2024 12:01:48 -0400 Subject: [PATCH 2/9] Optimize code based on feedback. Signed-off-by: Michael Jackson --- src/simplnx/Common/TypesUtility.hpp | 27 ++++++++++++++ src/simplnx/DataStructure/DataStore.hpp | 49 ++----------------------- 2 files changed, 31 insertions(+), 45 deletions(-) diff --git a/src/simplnx/Common/TypesUtility.hpp b/src/simplnx/Common/TypesUtility.hpp index 6713ef5af0..68f82c8edc 100644 --- a/src/simplnx/Common/TypesUtility.hpp +++ b/src/simplnx/Common/TypesUtility.hpp @@ -10,6 +10,33 @@ namespace nx::core { + +/** + * @brief Returns the templated value for the byte pattern 0xAB based on the byte count of the template parameter + * @tparam T + * @return + */ +template +constexpr T GetMudflap() noexcept +{ + if constexpr(sizeof(T) == 1) + { + return std::bit_cast(static_cast(0xAB)); + } + if constexpr(sizeof(T) == 2) + { + return std::bit_cast(static_cast(0xABAB)); + } + if constexpr(sizeof(T) == 4) + { + return std::bit_cast(static_cast(0xABABABAB)); + } + if constexpr(sizeof(T) == 8) + { + return std::bit_cast(static_cast(0xABABABABABABABAB)); + } +} + /** * @brief Returns the NumericType associated with T. * @tparam T diff --git a/src/simplnx/DataStructure/DataStore.hpp b/src/simplnx/DataStructure/DataStore.hpp index 1178da61b3..64dbcaab13 100644 --- a/src/simplnx/DataStructure/DataStore.hpp +++ b/src/simplnx/DataStructure/DataStore.hpp @@ -84,46 +84,7 @@ class DataStore : public AbstractDataStore , m_NumTuples(std::accumulate(m_TupleShape.cbegin(), m_TupleShape.cend(), static_cast(1), std::multiplies<>())) { // Because no init value is passed into the constructor, we will use a "mudflap" style value that is easy to debug. - if constexpr(sizeof(T) == 1) - { - m_InitValue = 0xAB; - } - if constexpr(sizeof(T) == 2) - { - m_InitValue = 0xABAB; - } - if constexpr(sizeof(T) == 4) - { - union InitValue { - uint32 i32; - float32 f32; - } initValue; - initValue.i32 = 0xABABABAB; - if constexpr(std::is_floating_point_v) - { - m_InitValue = initValue.f32; - } - else - { - m_InitValue = initValue.i32; - } - } - if constexpr(sizeof(T) == 8) - { - union InitValue { - uint64 i64; - float64 f64; - } initValue; - initValue.i64 = 0xABABABABABABABAB; - if constexpr(std::is_floating_point_v) - { - m_InitValue = initValue.f64; - } - else - { - m_InitValue = initValue.i64; - } - } + m_InitValue = GetMudflap(); } /** @@ -291,12 +252,10 @@ class DataStore : public AbstractDataStore // If we are sizing to a larger number of tuples, initialize the leftover array with the init // value that was passed in during construction. - if(m_InitValue.has_value()) + T initValue = m_InitValue.has_value() ? *m_InitValue : GetMudflap(); + for(usize i = oldSize; i < newSize; i++) { - for(usize i = oldSize; i < newSize; i++) - { - data[i] = *m_InitValue; - } + data[i] = initValue; } m_Data.reset(data); From f40a8b745737ba7d53948b08a2e7378d9e0ca1b7 Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Mon, 29 Jul 2024 12:02:29 -0400 Subject: [PATCH 3/9] Update src/simplnx/Utilities/FilterUtilities.hpp Co-authored-by: Jared Duffey --- src/simplnx/Utilities/FilterUtilities.hpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/simplnx/Utilities/FilterUtilities.hpp b/src/simplnx/Utilities/FilterUtilities.hpp index 682a0042a9..332739da9e 100644 --- a/src/simplnx/Utilities/FilterUtilities.hpp +++ b/src/simplnx/Utilities/FilterUtilities.hpp @@ -95,9 +95,7 @@ auto RunTemplateClass(DataType dataType, ArgsT&&... args) return ClassT(std::forward(args)...)(); } } - std::stringstream ss; - ss << "FilterUtilities::RunTemplateClass<> Error: dataType did not match any known type. DataType was " << to_underlying(dataType); - throw std::runtime_error(ss.str()); + throw std::runtime_error(fmt::format("FilterUtilities::RunTemplateClass<> Error: dataType did not match any known type. DataType was {}", DataTypeToString(dataType))); } template From 3396bb942c95762d4d7106ff558e7967dcf8b03c Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Tue, 30 Jul 2024 08:34:54 -0400 Subject: [PATCH 4/9] Fix missing include Signed-off-by: Michael Jackson --- src/simplnx/Utilities/FilterUtilities.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/simplnx/Utilities/FilterUtilities.hpp b/src/simplnx/Utilities/FilterUtilities.hpp index 332739da9e..f34e0d0c0f 100644 --- a/src/simplnx/Utilities/FilterUtilities.hpp +++ b/src/simplnx/Utilities/FilterUtilities.hpp @@ -4,6 +4,7 @@ #include "simplnx/Common/Result.hpp" #include "simplnx/Common/TypeTraits.hpp" #include "simplnx/Common/Types.hpp" +#include "simplnx/Common/TypesUtility.hpp" #include "simplnx/Filter/IFilter.hpp" #include "simplnx/Filter/Output.hpp" #include "simplnx/simplnx_export.hpp" From 3eabf18370d09b4a03840757c5972db5baf35dc0 Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Wed, 31 Jul 2024 11:05:04 -0400 Subject: [PATCH 5/9] Update src/simplnx/Utilities/FilterUtilities.hpp Co-authored-by: Nathan Young --- src/simplnx/Utilities/FilterUtilities.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/simplnx/Utilities/FilterUtilities.hpp b/src/simplnx/Utilities/FilterUtilities.hpp index f34e0d0c0f..9bc5cf1dde 100644 --- a/src/simplnx/Utilities/FilterUtilities.hpp +++ b/src/simplnx/Utilities/FilterUtilities.hpp @@ -3,6 +3,7 @@ #include "ParallelAlgorithmUtilities.hpp" #include "simplnx/Common/Result.hpp" #include "simplnx/Common/TypeTraits.hpp" +#include "simplnx/Common/TypeUtilities.hpp" #include "simplnx/Common/Types.hpp" #include "simplnx/Common/TypesUtility.hpp" #include "simplnx/Filter/IFilter.hpp" From 4bf6d70dd94db81fc634e7d52919db79b1ea3530 Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Wed, 31 Jul 2024 11:05:09 -0400 Subject: [PATCH 6/9] Update src/simplnx/Common/TypesUtility.hpp Co-authored-by: Nathan Young --- src/simplnx/Common/TypesUtility.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/simplnx/Common/TypesUtility.hpp b/src/simplnx/Common/TypesUtility.hpp index 68f82c8edc..e2bea3ae3d 100644 --- a/src/simplnx/Common/TypesUtility.hpp +++ b/src/simplnx/Common/TypesUtility.hpp @@ -7,6 +7,7 @@ #include #include #include +#include namespace nx::core { From 8925498e52db3e1bb7f8499c61ba5e893a18abdf Mon Sep 17 00:00:00 2001 From: Jared Duffey Date: Wed, 31 Jul 2024 17:12:57 -0400 Subject: [PATCH 7/9] Fixed clang format Signed-off-by: Jared Duffey --- src/simplnx/Common/TypesUtility.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/simplnx/Common/TypesUtility.hpp b/src/simplnx/Common/TypesUtility.hpp index e2bea3ae3d..4d07bf22a4 100644 --- a/src/simplnx/Common/TypesUtility.hpp +++ b/src/simplnx/Common/TypesUtility.hpp @@ -4,14 +4,13 @@ #include "simplnx/Common/TypeTraits.hpp" #include "simplnx/Common/Types.hpp" +#include #include #include #include -#include namespace nx::core { - /** * @brief Returns the templated value for the byte pattern 0xAB based on the byte count of the template parameter * @tparam T From 578f83d66e5a26f3f3105c59a848ba9bae153ddd Mon Sep 17 00:00:00 2001 From: Jared Duffey Date: Wed, 31 Jul 2024 17:13:06 -0400 Subject: [PATCH 8/9] Fixed include Signed-off-by: Jared Duffey --- src/simplnx/Utilities/FilterUtilities.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/simplnx/Utilities/FilterUtilities.hpp b/src/simplnx/Utilities/FilterUtilities.hpp index 9bc5cf1dde..f34e0d0c0f 100644 --- a/src/simplnx/Utilities/FilterUtilities.hpp +++ b/src/simplnx/Utilities/FilterUtilities.hpp @@ -3,7 +3,6 @@ #include "ParallelAlgorithmUtilities.hpp" #include "simplnx/Common/Result.hpp" #include "simplnx/Common/TypeTraits.hpp" -#include "simplnx/Common/TypeUtilities.hpp" #include "simplnx/Common/Types.hpp" #include "simplnx/Common/TypesUtility.hpp" #include "simplnx/Filter/IFilter.hpp" From 714d1b843a5b3c6700be6a85053aa4e6fdb23a8d Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Thu, 1 Aug 2024 13:21:53 -0400 Subject: [PATCH 9/9] Changes to compile under Xcode 14.2. #include with bit_cast<> was not instroduced until Xcode 14.3 which requires macOS 13.x (Ventura) Signed-off-by: Michael Jackson --- src/simplnx/Common/TypesUtility.hpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/simplnx/Common/TypesUtility.hpp b/src/simplnx/Common/TypesUtility.hpp index 4d07bf22a4..93d196048a 100644 --- a/src/simplnx/Common/TypesUtility.hpp +++ b/src/simplnx/Common/TypesUtility.hpp @@ -4,7 +4,19 @@ #include "simplnx/Common/TypeTraits.hpp" #include "simplnx/Common/Types.hpp" +#if defined(__clang__) && defined(__clang_major__) && defined(__APPLE__) +#if __clang_major__ > 14 #include +namespace bs = std; +#else +#include "Bit.hpp" +namespace bs = nx::core; +#endif +#else +#include +namespace bs = std; +#endif + #include #include #include @@ -21,19 +33,19 @@ constexpr T GetMudflap() noexcept { if constexpr(sizeof(T) == 1) { - return std::bit_cast(static_cast(0xAB)); + return bs::bit_cast(static_cast(0xAB)); } if constexpr(sizeof(T) == 2) { - return std::bit_cast(static_cast(0xABAB)); + return bs::bit_cast(static_cast(0xABAB)); } if constexpr(sizeof(T) == 4) { - return std::bit_cast(static_cast(0xABABABAB)); + return bs::bit_cast(static_cast(0xABABABAB)); } if constexpr(sizeof(T) == 8) { - return std::bit_cast(static_cast(0xABABABABABABABAB)); + return bs::bit_cast(static_cast(0xABABABABABABABAB)); } }