From e4ab79b243a3f38046e3eebb9525d3990a82ec43 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 24 Dec 2021 13:13:32 +0000 Subject: [PATCH 01/15] Initial code --- include/etl/experimental/bit_cast.h | 38 ++++++++---- include/etl/numeric.h | 90 ++++++++++++++++++++++++++++- 2 files changed, 115 insertions(+), 13 deletions(-) diff --git a/include/etl/experimental/bit_cast.h b/include/etl/experimental/bit_cast.h index 0add8d5e..7c38b875 100644 --- a/include/etl/experimental/bit_cast.h +++ b/include/etl/experimental/bit_cast.h @@ -1,20 +1,34 @@ #pragma once -template -etl::enable_if_t && etl::is_trivially_copyable_v, To> -//ETL_CONSTEXPR -bit_cast(const From& src) ETL_NOEXCEPT +#include "platform.h" + +template +ETL_CONSTEXPR +typename etl::enable_if<(sizeof(TDestination) == sizeof(TSource)) && + etl::is_trivially_copyable::value && + etl::is_trivially_copyable::value, TDestination>::type + bit_cast(const TSource& source) ETL_NOEXCEPT { - To dst; - memcpy(&dst, &src, sizeof(To)); + TDestination destination; - // __builtin_memcpy(&dst, &src, sizeof(To)); + memcpy(&destination, &source, sizeof(TDestination)); - return dst; + return destination; } -std::midpoint -// https://en.cppreference.com/w/cpp/numeric/midpoint +template +ETL_CONSTEXPR +typename etl::enable_if<(sizeof(TDestination) == sizeof(TSource)) && + etl::is_trivially_copyable::value && + etl::is_trivially_copyable::value, TDestination>::type + bit_cast(const TSource& source) ETL_NOEXCEPT +{ + TDestination destination; + + __builtin_memcpy(&destination, &source, sizeof(TDestination)); + + return destination; +} + + -std::lerp -// https://en.cppreference.com/w/cpp/numeric/lerp \ No newline at end of file diff --git a/include/etl/numeric.h b/include/etl/numeric.h index e30475bd..fde0876f 100644 --- a/include/etl/numeric.h +++ b/include/etl/numeric.h @@ -32,6 +32,7 @@ SOFTWARE. #define ETL_NUMERIC_INCLUDED #include "platform.h" +#include "type_traits.h" ///\defgroup numeric numeric ///\ingroup utilities @@ -54,7 +55,94 @@ namespace etl *first++ = value++; } } + + //*************************************************************************** + /// + //*************************************************************************** + template + ETL_CONSTEXPR14 typename etl::enable_if::value, T>::type + midpoint(T a, T b) ETL_NOEXCEPT + { + T lo = etl::numeric_limits::min() * T(2); + T hi = etl::numeric_limits::max() * T(2); + + return ((abs(a) <= hi) && (abs(b) <= hi)) ? + (a + b) / T(2) : + (abs(a) < lo) ? + a + (b / T(2)) : + (abs(b) < lo) ? + (a / T(2)) + b) : + (a / T(2)) + (b / T(2)); + } + + //*************************************************************************** + /// + //*************************************************************************** + template + ETL_CONSTEXPR14 typename etl::enable_if::value, T>::type + midpoint(T a, T b) ETL_NOEXCEPT + { + typedef typename etl::make_unsigned::type type; + + int sign; + type lo; + type hi; + + if (a > b) + { + sign = -1; + lo = type(b); + hi = type(a); + } + else + { + sign = 1; + lo = type(a); + hi = type(b); + } + + return a + sign * T(type(M - m) >> 1); + } + + //*************************************************************************** + /// + //*************************************************************************** + template + ETL_CONSTEXPR typename etl::enable_if::value, T>::type + midpoint(T a, T b) + { + return a + midpoint(ptrdiff_t{ 0 }, b - a); + } + + //*************************************************************************** + /// Linear interpolation + /// For floating point. + //*************************************************************************** + template + ETL_CONSTEXPR typename etl::enable_if::value, T>::type + lerp(T a, T b, T t) ETL_NOEXCEPT + { + return a + (t * (b ? a)); + } + + //*************************************************************************** + /// Linear interpolation + /// For when any parameter is not floating point. + //*************************************************************************** + template + ETL_CONSTEXPR typename etl::enable_if_t::value || + !etl::is_floating_point::value || + !etl::is_floating_point::value, typename etl::conditional::value || + etl::is_same::value || + etl::is_same::value, long double, double>::type> + lerp(TArithmetic1 a, TArithmetic2 b, TArithmetic3 t) ETL_NOEXCEPT + { + typename etl::conditional::value, double, TArithmetic1>::type typecast_a; + typename etl::conditional::value, double, TArithmetic2>::type typecast_b; + typename etl::conditional::value, double, TArithmetic3>::type typecast_t; + + return typecast_a(a) + (typecast_t(t) * (typecast_b(b) ? typecast_a(a)); + } } #endif - From 2643f8ef4b3648cf97b8da7cca573d878e1b245a Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 28 Dec 2021 18:42:17 +0000 Subject: [PATCH 02/15] Added etl::midpoint --- include/etl/numeric.h | 159 ++++++++++++++++++++++++++++++++++-------- test/test_numeric.cpp | 87 +++++++++++++++++++++++ 2 files changed, 216 insertions(+), 30 deletions(-) diff --git a/include/etl/numeric.h b/include/etl/numeric.h index fde0876f..015aec0b 100644 --- a/include/etl/numeric.h +++ b/include/etl/numeric.h @@ -33,6 +33,12 @@ SOFTWARE. #include "platform.h" #include "type_traits.h" +#include "limits.h" +#include "iterator.h" + +#if ETL_USING_STL + #include +#endif ///\defgroup numeric numeric ///\ingroup utilities @@ -57,63 +63,156 @@ namespace etl } //*************************************************************************** - /// + /// midpoint + /// For floating point. //*************************************************************************** template - ETL_CONSTEXPR14 typename etl::enable_if::value, T>::type + ETL_CONSTEXPR14 typename etl::enable_if::value && + !etl::is_integral::value && + etl::is_floating_point::value, T>::type midpoint(T a, T b) ETL_NOEXCEPT { T lo = etl::numeric_limits::min() * T(2); T hi = etl::numeric_limits::max() * T(2); return ((abs(a) <= hi) && (abs(b) <= hi)) ? - (a + b) / T(2) : - (abs(a) < lo) ? - a + (b / T(2)) : - (abs(b) < lo) ? - (a / T(2)) + b) : - (a / T(2)) + (b / T(2)); + (a + b) / T(2) : + (abs(a) < lo) ? + a + (b / T(2)) : + (abs(b) < lo) ? + ((a / T(2)) + b) : + (a / T(2)) + (b / T(2)); } //*************************************************************************** - /// + /// midpoint + /// For unsigned integrals. //*************************************************************************** template - ETL_CONSTEXPR14 typename etl::enable_if::value, T>::type + ETL_CONSTEXPR14 typename etl::enable_if::value && + etl::is_integral::value && + !etl::is_floating_point::value && + etl::is_unsigned::value, T>::type midpoint(T a, T b) ETL_NOEXCEPT { - typedef typename etl::make_unsigned::type type; - - int sign; - type lo; - type hi; - if (a > b) { - sign = -1; - lo = type(b); - hi = type(a); + return a - ((a - b) >> 1); } else { - sign = 1; - lo = type(a); - hi = type(b); + return a + ((b - a) >> 1); } - - return a + sign * T(type(M - m) >> 1); } //*************************************************************************** - /// + /// midpoint + /// For signed integrals. //*************************************************************************** template - ETL_CONSTEXPR typename etl::enable_if::value, T>::type - midpoint(T a, T b) + ETL_CONSTEXPR14 typename etl::enable_if::value&& + etl::is_integral::value && + !etl::is_floating_point::value&& + etl::is_signed::value, T>::type + midpoint(T a, T b) ETL_NOEXCEPT { - return a + midpoint(ptrdiff_t{ 0 }, b - a); + typedef typename etl::make_unsigned::type utype; + + if (a > b) + { + return a - T(utype(utype(a) - utype(b)) >> 1); + } + else + { + return a + T((utype(b) - utype(a)) >> 1); + } } + //*************************************************************************** + /// midpoint + /// For pointers. + //*************************************************************************** + template + ETL_CONSTEXPR typename etl::enable_if::value&& + !etl::is_integral::value && + !etl::is_floating_point::value, T>::type + midpoint(T a, T b) ETL_NOEXCEPT + { + if (a > b) + { + return b + (etl::distance(b, a) / 2U); + } + else + { + return a + (etl::distance(a, b) / 2U); + } + } + + //*************************************************************************** + /// midpoint + /// For ETL random access iterators. + //*************************************************************************** + template + ETL_CONSTEXPR typename etl::enable_if::value && + !etl::is_integral::value && + !etl::is_floating_point::value, T>::type + midpoint(T a, T b, typename etl::enable_if::iterator_category, etl::random_access_iterator_tag>::value, void>::type) + { + if (a > b) + { + return b + (etl::distance(b, a) / 2U); + } + else + { + return a + (etl::distance(a, b) / 2U); + } + } + + //*************************************************************************** + /// midpoint + /// For ETL forward and bidirectional iterators. + /// Parameter 'a' must be before 'b', otherwise the result is undefined. + //*************************************************************************** + template + ETL_CONSTEXPR T midpoint(T a, T b, typename etl::enable_if<(etl::is_same::iterator_category, std::forward_iterator_tag>::value || + etl::is_same::iterator_category, etl::bidirectional_iterator_tag>::value) && !etl::is_pointer::value, void>::type) + { + etl::advance(a, etl::distance(a, b) / 2U); + return a; + } + +#if ETL_USING_STL + //*************************************************************************** + /// midpoint + /// For STL random access iterators + //*************************************************************************** + template + ETL_CONSTEXPR T midpoint(T a, T b, typename etl::enable_if::iterator_category, std::random_access_iterator_tag>::value && !etl::is_pointer::value, int>::type = 0) + { + if (a > b) + { + return b + (etl::distance(b, a) / 2U); + } + else + { + return a + (etl::distance(a, b) / 2U); + } + } + + //*************************************************************************** + /// midpoint + /// For ETL forward and bidirectional iterators. + /// Parameter 'a' must be before 'b', otherwise the result is undefined. + //*************************************************************************** + template + ETL_CONSTEXPR T midpoint(T a, T b, typename etl::enable_if<(etl::is_same::iterator_category, std::forward_iterator_tag>::value || + etl::is_same::iterator_category, std::bidirectional_iterator_tag>::value) && !etl::is_pointer::value, int>::type = 0) + { + etl::advance(a, etl::distance(a, b) / 2U); + return a; + } +#endif + //*************************************************************************** /// Linear interpolation /// For floating point. @@ -122,7 +221,7 @@ namespace etl ETL_CONSTEXPR typename etl::enable_if::value, T>::type lerp(T a, T b, T t) ETL_NOEXCEPT { - return a + (t * (b ? a)); + return a + (etl::distance(a, b) / 2U); } //*************************************************************************** @@ -141,7 +240,7 @@ namespace etl typename etl::conditional::value, double, TArithmetic2>::type typecast_b; typename etl::conditional::value, double, TArithmetic3>::type typecast_t; - return typecast_a(a) + (typecast_t(t) * (typecast_b(b) ? typecast_a(a)); + return typecast_a(a) + (typecast_t(t) * (typecast_b(b) ? typecast_a(a))); } } diff --git a/test/test_numeric.cpp b/test/test_numeric.cpp index ea722cb3..6b1ea581 100644 --- a/test/test_numeric.cpp +++ b/test/test_numeric.cpp @@ -32,6 +32,9 @@ SOFTWARE. #include #include +#include +#include +#include namespace { @@ -49,5 +52,89 @@ namespace CHECK(are_same); } + + //************************************************************************* + TEST(test_midpoint_signed_integral) + { + CHECK_EQUAL(int32_t(0), (etl::midpoint(int32_t(0), int32_t(0)))); + CHECK_EQUAL(int32_t(0), (etl::midpoint(int32_t(0), int32_t(1)))); + CHECK_EQUAL(int32_t(1), (etl::midpoint(int32_t(1), int32_t(0)))); + + CHECK_EQUAL(std::numeric_limits::max() / 2, (etl::midpoint(0, std::numeric_limits::max()))); + CHECK_EQUAL((std::numeric_limits::max() / 2) + 1, (etl::midpoint(std::numeric_limits::max(), 0))); + + CHECK_EQUAL(int32_t(-1), (etl::midpoint(std::numeric_limits::min(), std::numeric_limits::max()))); + CHECK_EQUAL(int32_t(0), (etl::midpoint(std::numeric_limits::max(), std::numeric_limits::min()))); + } + + //************************************************************************* + TEST(test_midpoint_unsigned_integral) + { + CHECK_EQUAL(uint32_t(0), (etl::midpoint(uint32_t(0), uint32_t(0)))); + CHECK_EQUAL(uint32_t(0), (etl::midpoint(uint32_t(0), uint32_t(1)))); + CHECK_EQUAL(uint32_t(1), (etl::midpoint(uint32_t(1), uint32_t(0)))); + + CHECK_EQUAL((std::numeric_limits::max() / 2U), (etl::midpoint(std::numeric_limits::min(), std::numeric_limits::max()))); + CHECK_EQUAL((std::numeric_limits::max() / 2U) + 1, (etl::midpoint(std::numeric_limits::max(), std::numeric_limits::min()))); + } + + //************************************************************************* + TEST(test_midpoint_floating_point) + { + CHECK_CLOSE(0.0, (etl::midpoint(0.0, 0.0)), 0.001); + + CHECK_CLOSE(0.5, (etl::midpoint(0.0, 1.0)), 0.001); + CHECK_CLOSE(0.5, (etl::midpoint(1.0, 0.0)), 0.001); + + CHECK_CLOSE(0.0, (etl::midpoint(-std::numeric_limits::max(), std::numeric_limits::max())), 0.001); + CHECK_CLOSE(0.0, (etl::midpoint(std::numeric_limits::max(), -std::numeric_limits::max())), 0.001); + } + + //************************************************************************* + TEST(test_midpoint_pointer) + { + std::vector data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + + CHECK_EQUAL(data[5], (*etl::midpoint(data.data(), data.data() + data.size()))); + CHECK_EQUAL(data[5], (*etl::midpoint(data.data() + data.size(), data.data()))); + } + + //************************************************************************* + TEST(test_midpoint_random_access_iterator) + { + std::deque data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + + std::deque::iterator b = data.begin(); + std::deque::iterator e = data.end(); + + CHECK_EQUAL(data[5], (*etl::midpoint(b, e))); + CHECK_EQUAL(data[5], (*etl::midpoint(e, b))); + } + + //************************************************************************* + TEST(test_midpoint_bidirectional_iterator) + { + std::list data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + + std::list::iterator b = data.begin(); + std::list::iterator e = data.end(); + + std::list::iterator c = data.begin(); + std::advance(c, 5); + + CHECK_EQUAL(*c, *etl::midpoint(b, e)); + } + + //************************************************************************* + TEST(test_lerp_floating_point) + { + CHECK(false); + } + + //************************************************************************* + TEST(test_lerp_at_least_one_integral) + { + CHECK(false); + } }; } From 4f05600900e78d83d68e871b13fb125c72988977 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 30 Dec 2021 09:36:36 +0000 Subject: [PATCH 03/15] Added delegate test from std::function --- include/etl/buffer_descriptors.h | 4 ---- test/test_delegate.cpp | 15 +++++++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/include/etl/buffer_descriptors.h b/include/etl/buffer_descriptors.h index 4c58e407..d93d014e 100644 --- a/include/etl/buffer_descriptors.h +++ b/include/etl/buffer_descriptors.h @@ -196,11 +196,7 @@ namespace etl }; // The type of the callback function. -//#if ETL_CPP11_SUPPORTED & !defined(ETL_DELEGATE_FORCE_CPP03_IMPLEMENTATION) typedef etl::delegate callback_type; -//#else -// typedef etl::delegate callback_type; -//#endif //********************************* buffer_descriptors(TBuffer* pbuffers_, callback_type callback_ = callback_type()) diff --git a/test/test_delegate.cpp b/test/test_delegate.cpp index d5ee2acf..0e574d38 100644 --- a/test/test_delegate.cpp +++ b/test/test_delegate.cpp @@ -33,6 +33,8 @@ SOFTWARE. #if !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) +#include + namespace { //***************************************************************************** @@ -1103,6 +1105,19 @@ namespace CHECK(!function_called); CHECK(!parameter_correct); } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_construct_from_std_function_from_free_int) + { + std::function std_function(free_int); + + etl::delegate d(std_function); + + d(VALUE1, VALUE2); + + CHECK(function_called); + CHECK(parameter_correct); + } }; } From 7ad3b51308cf6d78eb7ca0deb4374d7d6ef826ea Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 31 Dec 2021 09:52:02 +0000 Subject: [PATCH 04/15] Added etl::lerp & initial reverse engineered header --- include/etl/binary.h | 11 ++ include/etl/bit.h | 208 ++++++++++++++++++++++++++++ include/etl/experimental/bit_cast.h | 1 - include/etl/numeric.h | 10 +- test/test_numeric.cpp | 34 ++++- test/vs2019/etl.vcxproj | 1 + test/vs2019/etl.vcxproj.filters | 3 + 7 files changed, 260 insertions(+), 8 deletions(-) create mode 100644 include/etl/bit.h diff --git a/include/etl/binary.h b/include/etl/binary.h index d4850155..630b847f 100644 --- a/include/etl/binary.h +++ b/include/etl/binary.h @@ -1306,6 +1306,17 @@ namespace etl return ((static_cast::type>(value) & 1U) == 0U); } + //*************************************************************************** + /// Checks if is power of 2. + ///\ingroup binary + //*************************************************************************** + template + ETL_CONSTEXPR typename etl::enable_if::value, bool>::type + is_power_of_2(const T value) + { + return (value & (value - 1)) == 0; + } + //*************************************************************************** /// 8 bit binary byte constants. ///\ingroup binary diff --git a/include/etl/bit.h b/include/etl/bit.h new file mode 100644 index 00000000..e31da3d0 --- /dev/null +++ b/include/etl/bit.h @@ -0,0 +1,208 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_BIT_CAST_INCLUDED +#define ETL_BIT_CAST_INCLUDED + +#include + +#include "platform.h" +#include "type_traits.h" +#include "binary.h" + +namespace etl +{ + //*************************************************************************** + /// bit_cast + //*************************************************************************** + template + typename etl::enable_if<(sizeof(TDestination) == sizeof(TSource)) && + etl::is_trivially_copyable::value && + etl::is_trivially_copyable::value, TDestination>::type + bit_cast(const TSource& source) ETL_NOEXCEPT + { + TDestination destination; + + memcpy(&destination, &source, sizeof(TDestination)); + + return destination; + } + + //template + //ETL_CONSTEXPR + //typename etl::enable_if<(sizeof(TDestination) == sizeof(TSource)) && + // etl::is_trivially_copyable::value && + // etl::is_trivially_copyable::value, TDestination>::type + // bit_cast(const TSource& source) ETL_NOEXCEPT + //{ + // TDestination destination; + // + // __builtin_memcpy(&destination, &source, sizeof(TDestination)); + // + // return destination; + //} + + //*************************************************************************** + /// byteswap + //*************************************************************************** + template + ETL_CONSTEXPR14 + typename etl::enable_if::value, T>::type + byteswap(T value) ETL_NOEXCEPT + { + return 0; + //return etl::reverse_bytes(value); + } + + //*************************************************************************** + /// has_single_bit + //*************************************************************************** + template + ETL_NODISCARD ETL_CONSTEXPR + typename etl::enable_if::value, bool>::type has_single_bit(T x) ETL_NOEXCEPT + { + return false; + //return etl::is_power_of_2(x); + } + + //*************************************************************************** + /// bit_ceil + //*************************************************************************** + template + ETL_NODISCARD ETL_CONSTEXPR + typename etl::enable_if::value, T>::type + bit_ceil(T x) + { + return 0; + } + + //*************************************************************************** + /// bit_floor + //*************************************************************************** + template + ETL_NODISCARD ETL_CONSTEXPR + typename etl::enable_if::value, T>::type + bit_floor(T x) ETL_NOEXCEPT + { + return 0; + } + + //*************************************************************************** + /// bit_width + //*************************************************************************** + template + ETL_CONSTEXPR + typename etl::enable_if::value, T>::type + bit_width(T x) ETL_NOEXCEPT + { + return 0; + } + + //*************************************************************************** + /// rotl + //*************************************************************************** + template + ETL_NODISCARD ETL_CONSTEXPR + typename etl::enable_if::value, T>::type + rotl(T x, int s) ETL_NOEXCEPT + { + return 0; + } + + //*************************************************************************** + /// rotr + //*************************************************************************** + template + ETL_NODISCARD ETL_CONSTEXPR + typename etl::enable_if::value, T>::type + rotr(T x, int s) ETL_NOEXCEPT + { + return 0; + } + + //*************************************************************************** + /// countl_zero + //*************************************************************************** + template + ETL_NODISCARD ETL_CONSTEXPR + typename etl::enable_if::value, int>::type + countl_zero(T x) ETL_NOEXCEPT + { + return 0; + } + + //*************************************************************************** + /// countl_one + //*************************************************************************** + template + ETL_NODISCARD ETL_CONSTEXPR + typename etl::enable_if::value, int>::type + countl_one(T x) ETL_NOEXCEPT + { + return 0; + } + + //*************************************************************************** + /// countr_zero + //*************************************************************************** + template + ETL_NODISCARD ETL_CONSTEXPR + typename etl::enable_if::value, int>::type + countr_zero(T x) ETL_NOEXCEPT + { + return 0; + //return etl::count_trailing_zeros(x); + } + + //*************************************************************************** + /// countr_one + //*************************************************************************** + template + ETL_NODISCARD ETL_CONSTEXPR + typename etl::enable_if::value, int>::type + countr_one(T x) ETL_NOEXCEPT + { + return 0; + } + + //*************************************************************************** + /// popcount + //*************************************************************************** + template + ETL_NODISCARD ETL_CONSTEXPR + typename etl::enable_if::value, int>::type + popcount(T x) ETL_NOEXCEPT + { + return 0; + //return etl::count_bits(x); + } +} + +#endif diff --git a/include/etl/experimental/bit_cast.h b/include/etl/experimental/bit_cast.h index 7c38b875..eefa3bbd 100644 --- a/include/etl/experimental/bit_cast.h +++ b/include/etl/experimental/bit_cast.h @@ -3,7 +3,6 @@ #include "platform.h" template -ETL_CONSTEXPR typename etl::enable_if<(sizeof(TDestination) == sizeof(TSource)) && etl::is_trivially_copyable::value && etl::is_trivially_copyable::value, TDestination>::type diff --git a/include/etl/numeric.h b/include/etl/numeric.h index 015aec0b..342c1b80 100644 --- a/include/etl/numeric.h +++ b/include/etl/numeric.h @@ -221,7 +221,7 @@ namespace etl ETL_CONSTEXPR typename etl::enable_if::value, T>::type lerp(T a, T b, T t) ETL_NOEXCEPT { - return a + (etl::distance(a, b) / 2U); + return a + (t * (b - a)); } //*************************************************************************** @@ -236,11 +236,11 @@ namespace etl etl::is_same::value, long double, double>::type> lerp(TArithmetic1 a, TArithmetic2 b, TArithmetic3 t) ETL_NOEXCEPT { - typename etl::conditional::value, double, TArithmetic1>::type typecast_a; - typename etl::conditional::value, double, TArithmetic2>::type typecast_b; - typename etl::conditional::value, double, TArithmetic3>::type typecast_t; + typedef typename etl::conditional::value, double, TArithmetic1>::type typecast_a; + typedef typename etl::conditional::value, double, TArithmetic2>::type typecast_b; + typedef typename etl::conditional::value, double, TArithmetic3>::type typecast_t; - return typecast_a(a) + (typecast_t(t) * (typecast_b(b) ? typecast_a(a))); + return typecast_a(a) + (typecast_t(t) * (typecast_b(b) - typecast_a(a))); } } diff --git a/test/test_numeric.cpp b/test/test_numeric.cpp index 6b1ea581..d26f2aed 100644 --- a/test/test_numeric.cpp +++ b/test/test_numeric.cpp @@ -128,13 +128,43 @@ namespace //************************************************************************* TEST(test_lerp_floating_point) { - CHECK(false); + CHECK_CLOSE(-10.0, etl::lerp(-10.0, 10.0, 0.0), 0.001); + CHECK_CLOSE( -8.0, etl::lerp(-10.0, 10.0, 0.1), 0.001); + CHECK_CLOSE( -6.0, etl::lerp(-10.0, 10.0, 0.2), 0.001); + CHECK_CLOSE( -4.0, etl::lerp(-10.0, 10.0, 0.3), 0.001); + CHECK_CLOSE( -2.0, etl::lerp(-10.0, 10.0, 0.4), 0.001); + CHECK_CLOSE( 0.0, etl::lerp(-10.0, 10.0, 0.5), 0.001); + CHECK_CLOSE( 2.0, etl::lerp(-10.0, 10.0, 0.6), 0.001); + CHECK_CLOSE( 4.0, etl::lerp(-10.0, 10.0, 0.7), 0.001); + CHECK_CLOSE( 6.0, etl::lerp(-10.0, 10.0, 0.8), 0.001); + CHECK_CLOSE( 8.0, etl::lerp(-10.0, 10.0, 0.9), 0.001); + CHECK_CLOSE( 10.0, etl::lerp(-10.0, 10.0, 1.0), 0.001); + + // Equal a & b + CHECK_CLOSE(10.0, etl::lerp(10.0, 10.0, 1.0), 0.001); } //************************************************************************* TEST(test_lerp_at_least_one_integral) { - CHECK(false); + CHECK_CLOSE(-10.0, etl::lerp(-10.0, 10.0, 0), 0.001); + CHECK_CLOSE( -8.0, etl::lerp(-10, 10.0, 0.1), 0.001); + CHECK_CLOSE( -6.0, etl::lerp(-10.0, 10, 0.2), 0.001); + CHECK_CLOSE( -4.0, etl::lerp(-10, 10, 0.3), 0.001); + CHECK_CLOSE( -2.0, etl::lerp(-10, 10.0, 0.4), 0.001); + CHECK_CLOSE( 0.0, etl::lerp(-10.0, 10, 0.5), 0.001); + CHECK_CLOSE( 2.0, etl::lerp(-10, 10, 0.6), 0.001); + CHECK_CLOSE( 4.0, etl::lerp(-10, 10.0, 0.7), 0.001); + CHECK_CLOSE( 6.0, etl::lerp(-10.0, 10, 0.8), 0.001); + CHECK_CLOSE( 8.0, etl::lerp(-10, 10, 0.9), 0.001); + CHECK_CLOSE( 10.0, etl::lerp(-10.0, 10.0, 1), 0.001); + + // Equal a & b + CHECK_CLOSE(10.0, etl::lerp(10.0, 10.0, 1.0), 0.001); + CHECK_CLOSE(10.0, etl::lerp(10, 10.0, 1.0), 0.001); + CHECK_CLOSE(10.0, etl::lerp(10.0, 10, 1.0), 0.001); + CHECK_CLOSE(10.0, etl::lerp(10.0, 10.0, 1), 0.001); + CHECK_CLOSE(10.0, etl::lerp(10, 10, 1), 0.001); } }; } diff --git a/test/vs2019/etl.vcxproj b/test/vs2019/etl.vcxproj index 4fe89a50..2152c79d 100644 --- a/test/vs2019/etl.vcxproj +++ b/test/vs2019/etl.vcxproj @@ -1720,6 +1720,7 @@ + diff --git a/test/vs2019/etl.vcxproj.filters b/test/vs2019/etl.vcxproj.filters index 6e3043e7..089811e6 100644 --- a/test/vs2019/etl.vcxproj.filters +++ b/test/vs2019/etl.vcxproj.filters @@ -1173,6 +1173,9 @@ ETL\Frameworks + + ETL\Utilities + From cf0b816bc1c52b26de9eaa2ea42641412151d38d Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 2 Jan 2022 14:20:10 +0000 Subject: [PATCH 05/15] Update to support C++20 --- include/etl/profiles/determine_compiler_language_support.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/etl/profiles/determine_compiler_language_support.h b/include/etl/profiles/determine_compiler_language_support.h index f2cbe9b1..d3ce9902 100644 --- a/include/etl/profiles/determine_compiler_language_support.h +++ b/include/etl/profiles/determine_compiler_language_support.h @@ -41,7 +41,7 @@ SOFTWARE. #define ETL_CPP11_SUPPORTED (_MSC_VER >= 1600) #define ETL_CPP14_SUPPORTED (_MSC_VER >= 1900) #define ETL_CPP17_SUPPORTED (_MSC_VER >= 1914) - #define ETL_CPP20_SUPPORTED 0 + #define ETL_CPP20_SUPPORTED (_MSC_VER >= 1929) #elif defined(ETL_COMPILER_ARM5) #define ETL_CPP11_SUPPORTED 0 #define ETL_CPP14_SUPPORTED 0 @@ -51,7 +51,7 @@ SOFTWARE. #define ETL_CPP11_SUPPORTED (__cplusplus >= 201103L) #define ETL_CPP14_SUPPORTED (__cplusplus >= 201402L) #define ETL_CPP17_SUPPORTED (__cplusplus >= 201703L) - #define ETL_CPP20_SUPPORTED 0 + #define ETL_CPP20_SUPPORTED (__cplusplus >= 202002L) #endif #else #define ETL_CPP11_SUPPORTED 0 From d4cc1155092ef44ac0aadbb4d6a908c74e4b4ff6 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 3 Jan 2022 18:20:14 +0000 Subject: [PATCH 06/15] Modified C++ language level detection --- .../determine_compiler_language_support.h | 76 +++++++++++++++---- 1 file changed, 63 insertions(+), 13 deletions(-) diff --git a/include/etl/profiles/determine_compiler_language_support.h b/include/etl/profiles/determine_compiler_language_support.h index d3ce9902..25e61ad0 100644 --- a/include/etl/profiles/determine_compiler_language_support.h +++ b/include/etl/profiles/determine_compiler_language_support.h @@ -35,29 +35,78 @@ SOFTWARE. #include "determine_compiler.h" -#if !defined(ETL_CPP11_SUPPORTED) && !defined(ETL_CPP14_SUPPORTED) && !defined(ETL_CPP17_SUPPORTED) +// Determine C++20 support +#if !defined(ETL_CPP20_SUPPORTED) +#if defined(__cplusplus) +#if defined(ETL_COMPILER_MICROSOFT) +#define ETL_CPP20_SUPPORTED (_MSC_VER >= 1929) +#elif defined(ETL_COMPILER_ARM5) +#define ETL_CPP20_SUPPORTED 0 +#else +#define ETL_CPP20_SUPPORTED (__cplusplus >= 202002L) +#endif +#else +#define ETL_CPP20_SUPPORTED 0 +#endif +#endif + +#if ETL_CPP20_SUPPORTED + #define ETL_CPP11_SUPPORTED 1 + #define ETL_CPP14_SUPPORTED 1 + #define ETL_CPP17_SUPPORTED 1 +#endif + +// Determine C++17 support +#if !defined(ETL_CPP17_SUPPORTED) + #if defined(__cplusplus) + #if defined(ETL_COMPILER_MICROSOFT) + #define ETL_CPP17_SUPPORTED (_MSC_VER >= 1914) + #elif defined(ETL_COMPILER_ARM5) + #define ETL_CPP17_SUPPORTED 0 + #else + #define ETL_CPP17_SUPPORTED (__cplusplus >= 201703L) + #endif + #else + #define ETL_CPP17_SUPPORTED 0 + #endif +#endif + +#if ETL_CPP17_SUPPORTED + #define ETL_CPP11_SUPPORTED 1 + #define ETL_CPP14_SUPPORTED 1 +#endif + +// Determine C++14 support +#if !defined(ETL_CPP14_SUPPORTED) + #if defined(__cplusplus) + #if defined(ETL_COMPILER_MICROSOFT) + #define ETL_CPP14_SUPPORTED (_MSC_VER >= 1900) + #elif defined(ETL_COMPILER_ARM5) + #define ETL_CPP14_SUPPORTED 0 + #else + #define ETL_CPP14_SUPPORTED (__cplusplus >= 201402L) + #endif + #else + #define ETL_CPP14_SUPPORTED 0 + #endif +#endif + +#if ETL_CPP14_SUPPORTED + #define ETL_CPP11_SUPPORTED 1 +#endif + +// Determine C++11 support +#if !defined(ETL_CPP11_SUPPORTED) #if defined(__cplusplus) #if defined(ETL_COMPILER_MICROSOFT) #define ETL_CPP11_SUPPORTED (_MSC_VER >= 1600) - #define ETL_CPP14_SUPPORTED (_MSC_VER >= 1900) - #define ETL_CPP17_SUPPORTED (_MSC_VER >= 1914) - #define ETL_CPP20_SUPPORTED (_MSC_VER >= 1929) #elif defined(ETL_COMPILER_ARM5) #define ETL_CPP11_SUPPORTED 0 - #define ETL_CPP14_SUPPORTED 0 - #define ETL_CPP17_SUPPORTED 0 - #define ETL_CPP20_SUPPORTED 0 #else #define ETL_CPP11_SUPPORTED (__cplusplus >= 201103L) - #define ETL_CPP14_SUPPORTED (__cplusplus >= 201402L) - #define ETL_CPP17_SUPPORTED (__cplusplus >= 201703L) - #define ETL_CPP20_SUPPORTED (__cplusplus >= 202002L) #endif #else #define ETL_CPP11_SUPPORTED 0 - #define ETL_CPP14_SUPPORTED 0 - #define ETL_CPP17_SUPPORTED 0 - #define ETL_CPP20_SUPPORTED 0 #endif #endif @@ -65,6 +114,7 @@ SOFTWARE. #define ETL_CPP11_NOT_SUPPORTED !ETL_CPP11_SUPPORTED #define ETL_CPP14_NOT_SUPPORTED !ETL_CPP14_SUPPORTED #define ETL_CPP17_NOT_SUPPORTED !ETL_CPP17_SUPPORTED +#define ETL_CPP20_NOT_SUPPORTED !ETL_CPP20_SUPPORTED #if !defined(ETL_NO_NULLPTR_SUPPORT) #define ETL_NO_NULLPTR_SUPPORT ETL_CPP11_NOT_SUPPORTED From dc563239e565b1beb23f8b94bed835813e551de6 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 3 Jan 2022 18:21:01 +0000 Subject: [PATCH 07/15] Added all permutations of leading/trailing bit tests --- include/etl/binary.h | 699 ++++++++++++++++++++++++++++++++++++++++++- test/test_binary.cpp | 518 ++++++++++++++++++++++++++++++++ 2 files changed, 1204 insertions(+), 13 deletions(-) diff --git a/include/etl/binary.h b/include/etl/binary.h index 630b847f..9d5fb080 100644 --- a/include/etl/binary.h +++ b/include/etl/binary.h @@ -1001,7 +1001,7 @@ namespace etl #if ETL_8BIT_SUPPORT //*************************************************************************** - /// Count trailing zeros. bit. + /// Count trailing zeros. /// Uses a binary search. ///\ingroup binary //*************************************************************************** @@ -1029,7 +1029,13 @@ namespace etl count += 2U; } - count -= value & 0x1U; + if ((value & 0x1U) == 0U) + { + value >>= 1U; + count += 1U; + } + + count -= (value & 0x1U); } return count; @@ -1076,6 +1082,12 @@ namespace etl count += 2U; } + if ((value & 0x1U) == 0U) + { + value >>= 1U; + count += 1U; + } + count -= value & 0x1U; } @@ -1128,6 +1140,12 @@ namespace etl count += 2U; } + if ((value & 0x1U) == 0U) + { + value >>= 1U; + count += 1U; + } + count -= value & 0x1UL; } @@ -1187,6 +1205,12 @@ namespace etl count += 2U; } + if ((value & 0x1U) == 0U) + { + value >>= 1U; + count += 1U; + } + count -= value & 0x1ULL; } @@ -1199,6 +1223,666 @@ namespace etl } #endif +#if ETL_8BIT_SUPPORT + //*************************************************************************** + /// Count trailing zeros. bit. + /// Uses a binary search. + ///\ingroup binary + //*************************************************************************** + inline ETL_CONSTEXPR14 uint_least8_t count_trailing_ones(uint8_t value) + { + uint_least8_t count = 0U; + + if ((value & 0x1U) == 0x0U) + { + count = 0U; + } + else + { + count = 1U; + + if ((value & 0xFU) == 0xFU) + { + value >>= 4U; + count += 4U; + } + + if ((value & 0x3U) == 0x3U) + { + value >>= 2U; + count += 2U; + } + + if ((value & 0x1U) == 0x1U) + { + value >>= 1U; + count += 1U; + } + + count -= ((value & 0x1U) == 0x0U); + } + + return count; + } + + inline ETL_CONSTEXPR14 uint_least8_t count_trailing_ones(int8_t value) + { + return count_trailing_ones(uint8_t(value)); + } +#endif + + //*************************************************************************** + /// Count trailing zeros. 16bit. + /// Uses a binary search. + ///\ingroup binary + //*************************************************************************** + inline ETL_CONSTEXPR14 uint_least8_t count_trailing_ones(uint16_t value) + { + uint_least8_t count = 0U; + + if ((value & 0x1U) == 0x0U) + { + count = 0U; + } + else + { + count = 1U; + + if ((value & 0xFFU) == 0xFFU) + { + value >>= 8U; + count += 8U; + } + + if ((value & 0xFU) == 0xFU) + { + value >>= 4U; + count += 4U; + } + + if ((value & 0x3U) == 0x3U) + { + value >>= 2U; + count += 2U; + } + + if ((value & 0x1U) == 0x1U) + { + value >>= 1U; + count += 1U; + } + + count -= ((value & 0x1U) == 0x0U); + } + + return count; + } + + inline ETL_CONSTEXPR14 uint_least8_t count_trailing_ones(int16_t value) + { + return count_trailing_ones(uint16_t(value)); + } + + //*************************************************************************** + /// Count trailing zeros. 32bit. + /// Uses a binary search. + ///\ingroup binary + //*************************************************************************** + inline ETL_CONSTEXPR14 uint_least8_t count_trailing_ones(uint32_t value) + { + uint_least8_t count = 0U; + + if ((value & 0x1UL) == 0x0UL) + { + count = 0U; + } + else + { + count = 1U; + + if ((value & 0xFFFFUL) == 0xFFFFUL) + { + value >>= 16U; + count += 16U; + } + + if ((value & 0xFFUL) == 0xFFUL) + { + value >>= 8U; + count += 8U; + } + + if ((value & 0xFUL) == 0xFUL) + { + value >>= 4U; + count += 4U; + } + + if ((value & 0x3UL) == 0x3UL) + { + value >>= 2U; + count += 2U; + } + + if ((value & 0x1UL) == 0x1UL) + { + value >>= 1U; + count += 1U; + } + + count -= ((value & 0x1UL) == 0x0UL); + } + + return count; + } + + inline ETL_CONSTEXPR14 uint_least8_t count_trailing_ones(int32_t value) + { + return count_trailing_ones(uint32_t(value)); + } + +#if ETL_USING_64BIT_TYPES + //*************************************************************************** + /// Count trailing zeros. 64bit. + /// Uses a binary search. + ///\ingroup binary + //*************************************************************************** + ETL_CONSTEXPR14 inline uint_least8_t count_trailing_ones(uint64_t value) + { + uint_least8_t count = 0U; + + if ((value & 0x1ULL) == 0x0ULL) + { + count = 0U; + } + else + { + count = 1U; + + if ((value & 0xFFFFULL) == 0xFFFFULL) + { + value >>= 16U; + count += 16U; + } + + if ((value & 0xFFULL) == 0xFFULL) + { + value >>= 8U; + count += 8U; + } + + if ((value & 0xFULL) == 0xFULL) + { + value >>= 4U; + count += 4U; + } + + if ((value & 0x3ULL) == 0x3ULL) + { + value >>= 2U; + count += 2U; + } + + if ((value & 0x1ULL) == 0x1ULL) + { + value >>= 1U; + count += 1U; + } + + count -= ((value & 0x1ULL) == 0x0ULL); + } + + return count; + } + + inline ETL_CONSTEXPR14 uint_least8_t count_trailing_ones(int64_t value) + { + return count_trailing_ones(uint64_t(value)); + } +#endif + +#if ETL_8BIT_SUPPORT + //*************************************************************************** + /// Count leading zeros. + /// Uses a binary search. + ///\ingroup binary + //*************************************************************************** + inline ETL_CONSTEXPR14 uint_least8_t count_leading_zeros(uint8_t value) + { + uint_least8_t count = 0U; + + if (value & 0x80U) + { + count = 0U; + } + else + { + count = 1U; + + if ((value & 0xF0U) == 0U) + { + value <<= 4U; + count += 4U; + } + + if ((value & 0xC0U) == 0U) + { + value <<= 2U; + count += 2U; + } + + if ((value & 0x80U) == 0U) + { + value <<= 1U; + count += 1U; + } + + count -= ((value & 0x80U) == 0x80U); + } + + return count; + } + + inline ETL_CONSTEXPR14 uint_least8_t count_leading_zeros(int8_t value) + { + return count_leading_zeros(uint8_t(value)); + } +#endif + + //*************************************************************************** + /// Count leading zeros. + /// Uses a binary search. + ///\ingroup binary + //*************************************************************************** + inline ETL_CONSTEXPR14 uint_least8_t count_leading_zeros(uint16_t value) + { + uint_least8_t count = 0U; + + if (value & 0x8000U) + { + count = 0U; + } + else + { + count = 1U; + + if ((value & 0xFF00U) == 0U) + { + value <<= 8U; + count += 8U; + } + + if ((value & 0xF000U) == 0U) + { + value <<= 4U; + count += 4U; + } + + if ((value & 0xC000U) == 0U) + { + value <<= 2U; + count += 2U; + } + + if ((value & 0x8000U) == 0U) + { + value <<= 1U; + count += 1U; + } + + count -= ((value & 0x8000U) == 0x8000U); + } + + return count; + } + + inline ETL_CONSTEXPR14 uint_least8_t count_leading_zeros(int16_t value) + { + return count_leading_zeros(uint16_t(value)); + } + + //*************************************************************************** + /// Count leading zeros. + /// Uses a binary search. + ///\ingroup binary + //*************************************************************************** + inline ETL_CONSTEXPR14 uint_least8_t count_leading_zeros(uint32_t value) + { + uint_least8_t count = 0U; + + if (value & 0x80000000UL) + { + count = 0U; + } + else + { + count = 1U; + + if ((value & 0xFFFF0000UL) == 0U) + { + value <<= 16U; + count += 16U; + } + + if ((value & 0xFF000000UL) == 0U) + { + value <<= 8U; + count += 8U; + } + + if ((value & 0xF0000000UL) == 0U) + { + value <<= 4U; + count += 4U; + } + + if ((value & 0xC0000000UL) == 0U) + { + value <<= 2U; + count += 2U; + } + + if ((value & 0x80000000UL) == 0U) + { + value <<= 1U; + count += 1U; + } + + count -= ((value & 0x80000000UL) == 0x80000000UL); + } + + return count; + } + + inline ETL_CONSTEXPR14 uint_least8_t count_leading_zeros(int32_t value) + { + return count_leading_zeros(uint32_t(value)); + } + +#if ETL_USING_64BIT_TYPES + //*************************************************************************** + /// Count leading zeros. + /// Uses a binary search. + ///\ingroup binary + //*************************************************************************** + inline ETL_CONSTEXPR14 uint_least8_t count_leading_zeros(uint64_t value) + { + uint_least8_t count = 0U; + + if (value & 0x8000000000000000ULL) + { + count = 0U; + } + else + { + count = 1U; + + if ((value & 0xFFFF000000000000ULL) == 0U) + { + value <<= 16U; + count += 16U; + } + + if ((value & 0xFF00000000000000ULL) == 0U) + { + value <<= 8U; + count += 8U; + } + + if ((value & 0xF000000000000000ULL) == 0U) + { + value <<= 4U; + count += 4U; + } + + if ((value & 0xC000000000000000ULL) == 0U) + { + value <<= 2U; + count += 2U; + } + + if ((value & 0x8000000000000000ULL) == 0U) + { + value <<= 1U; + count += 1U; + } + + count -= ((value & 0x8000000000000000ULL) == 0x8000000000000000ULL); + } + + return count; + } + + inline ETL_CONSTEXPR14 uint_least8_t count_leading_zeros(int64_t value) + { + return count_leading_zeros(uint64_t(value)); + } +#endif + +#if ETL_8BIT_SUPPORT + //*************************************************************************** + /// Count leading ones. + /// Uses a binary search. + ///\ingroup binary + //*************************************************************************** + inline ETL_CONSTEXPR14 uint_least8_t count_leading_ones(uint8_t value) + { + uint_least8_t count = 0U; + + if ((value & 0x80U) == 0U) + { + count = 0U; + } + else + { + count = 1U; + + if ((value & 0xF0U) == 0xF0U) + { + value <<= 4U; + count += 4U; + } + + if ((value & 0xC0U) == 0xC0U) + { + value <<= 2U; + count += 2U; + } + + if ((value & 0x80U) == 0x80U) + { + value <<= 1U; + count += 1U; + } + + count -= ((value & 0x80U) == 0x0U); + } + + return count; + } + + inline ETL_CONSTEXPR14 uint_least8_t count_leading_ones(int8_t value) + { + return count_leading_ones(uint8_t(value)); + } +#endif + + //*************************************************************************** + /// Count leading ones. + /// Uses a binary search. + ///\ingroup binary + //*************************************************************************** + inline ETL_CONSTEXPR14 uint_least8_t count_leading_ones(uint16_t value) + { + uint_least8_t count = 0U; + + if ((value & 0x8000U) == 0U) + { + count = 0U; + } + else + { + count = 1U; + + if ((value & 0xFF00U) == 0xFF00U) + { + value <<= 8U; + count += 8U; + } + + if ((value & 0xF000U) == 0xF000U) + { + value <<= 4U; + count += 4U; + } + + if ((value & 0xC000U) == 0xC000U) + { + value <<= 2U; + count += 2U; + } + + if ((value & 0x8000U) == 0x8000U) + { + value <<= 1U; + count += 1U; + } + + count -= ((value & 0x8000U) == 0U); + } + + return count; + } + + inline ETL_CONSTEXPR14 uint_least8_t count_leading_ones(int16_t value) + { + return count_leading_ones(uint16_t(value)); + } + + //*************************************************************************** + /// Count leading ones. + /// Uses a binary search. + ///\ingroup binary + //*************************************************************************** + inline ETL_CONSTEXPR14 uint_least8_t count_leading_ones(uint32_t value) + { + uint_least8_t count = 0U; + + if ((value & 0x80000000UL) == 0UL) + { + count = 0U; + } + else + { + count = 1U; + + if ((value & 0xFFFF0000UL) == 0xFFFF0000UL) + { + value <<= 8U; + count += 8U; + } + + if ((value & 0xFF000000UL) == 0xFF000000UL) + { + value <<= 8U; + count += 8U; + } + + if ((value & 0xF0000000UL) == 0xF0000000UL) + { + value <<= 4U; + count += 4U; + } + + if ((value & 0xC0000000UL) == 0xC0000000UL) + { + value <<= 2U; + count += 2U; + } + + if ((value & 0x80000000UL) == 0x80000000UL) + { + value <<= 1U; + count += 1U; + } + + count -= ((value & 0x80000000UL) == 0UL); + } + + return count; + } + + inline ETL_CONSTEXPR14 uint_least8_t count_leading_ones(int32_t value) + { + return count_leading_ones(uint32_t(value)); + } + +#if ETL_USING_64BIT_TYPES + //*************************************************************************** + /// Count leading ones. + /// Uses a binary search. + ///\ingroup binary + //*************************************************************************** + inline ETL_CONSTEXPR14 uint_least8_t count_leading_ones(uint64_t value) + { + uint_least8_t count = 0U; + + if ((value & 0x8000000000000000ULL) == 0ULL) + { + count = 0U; + } + else + { + count = 1U; + + if ((value & 0xFFFFFFFF00000000ULL) == 0xFFFFFFFF00000000ULL) + { + value <<= 8U; + count += 8U; + } + + if ((value & 0xFFFF000000000000ULL) == 0xFFFF000000000000ULL) + { + value <<= 8U; + count += 8U; + } + + if ((value & 0xFF00000000000000ULL) == 0xFF00000000000000ULL) + { + value <<= 8U; + count += 8U; + } + + if ((value & 0xF000000000000000ULL) == 0xF000000000000000ULL) + { + value <<= 4U; + count += 4U; + } + + if ((value & 0xC000000000000000ULL) == 0xC000000000000000ULL) + { + value <<= 2U; + count += 2U; + } + + if ((value & 0x8000000000000000ULL) == 0x8000000000000000ULL) + { + value <<= 1U; + count += 1U; + } + + count -= ((value & 0x8000000000000000ULL) == 0ULL); + } + + return count; + } + + inline ETL_CONSTEXPR14 uint_least8_t count_leading_ones(int64_t value) + { + return count_leading_ones(uint64_t(value)); + } +#endif + #if ETL_8BIT_SUPPORT //***************************************************************************** /// Binary interleave @@ -1306,17 +1990,6 @@ namespace etl return ((static_cast::type>(value) & 1U) == 0U); } - //*************************************************************************** - /// Checks if is power of 2. - ///\ingroup binary - //*************************************************************************** - template - ETL_CONSTEXPR typename etl::enable_if::value, bool>::type - is_power_of_2(const T value) - { - return (value & (value - 1)) == 0; - } - //*************************************************************************** /// 8 bit binary byte constants. ///\ingroup binary diff --git a/test/test_binary.cpp b/test/test_binary.cpp index d545684a..8a2f2f1d 100644 --- a/test/test_binary.cpp +++ b/test/test_binary.cpp @@ -40,6 +40,7 @@ SOFTWARE. namespace { + //*********************************** // Count bits the easy way. template size_t test_count(T value) @@ -57,6 +58,73 @@ namespace return count; } + //*********************************** + // Count trailing zeros the long way. + template + size_t test_trailing_zeros(T value) + { + size_t count = 0UL; + + for (int i = 0; i < etl::integral_limits::bits; ++i) + { + if ((value & 1) == 0) + { + ++count; + } + else + { + return count; + } + + value >>= 1; + } + + return count; + } + + //*********************************** + // Count leading zeros the long way. + template + size_t test_leading_zeros(T value) + { + value = etl::reverse_bits(value); + return test_trailing_zeros(value); + } + + //*********************************** + // Count trailing ones the long way. + template + size_t test_trailing_ones(T value) + { + size_t count = 0UL; + + for (int i = 0; i < etl::integral_limits::bits; ++i) + { + if ((value & 1) == 1) + { + ++count; + } + else + { + return count; + } + + value >>= 1; + } + + return count; + } + + //*********************************** + // Count leading ones the long way. + template + size_t test_leading_ones(T value) + { + value = etl::reverse_bits(value); + return test_trailing_ones(value); + } + + //*********************************** // Check parity the easy way. template size_t test_parity(T value) @@ -66,6 +134,7 @@ namespace return count & 1; } + //*********************************** // Power of 2. uint64_t test_power_of_2(int power) { @@ -79,6 +148,7 @@ namespace return result; } + //*********************************** // Fold bits. template TReturn test_fold_bits(uint64_t value, int size) @@ -99,6 +169,7 @@ namespace return result; } + //*********************************** // Slow gray to binary template T compare_gray_to_binary(T value_) @@ -1822,6 +1893,453 @@ namespace CHECK(!etl::is_even(1)); CHECK(etl::is_even(2)); } + + //************************************************************************* + TEST(test_count_trailing_zeros_8) + { + for (size_t i = 0; i < 256; ++i) + { + uint8_t value = uint8_t(i); + + CHECK_EQUAL(int(test_trailing_zeros(value)), int(etl::count_trailing_zeros(value))); + + if (test_trailing_zeros(value) != etl::count_trailing_zeros(value)) + { + break; + } + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_count_trailing_zeros_8_constexpr) + { + char temp[etl::count_trailing_zeros(uint8_t(0x08))]; + + CHECK_EQUAL(test_trailing_zeros(uint8_t(0x08)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_count_trailing_zeros_16) + { + for (size_t i = 0; i < 65536; ++i) + { + uint16_t value = uint16_t(i); + + CHECK_EQUAL(test_trailing_zeros(value), etl::count_trailing_zeros(value)); + + if (test_trailing_zeros(value) != etl::count_trailing_zeros(value)) + { + break; + } + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_count_trailing_zeros_16_constexpr) + { + char temp[etl::count_trailing_zeros(uint16_t(0x08))]; + + CHECK_EQUAL(test_trailing_zeros(uint16_t(0x08)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_count_trailing_zeros_32) + { + etl::fnv_1a_32 hash; + + for (size_t i = 0UL; i < 100000UL; ++i) + { + hash.add(1); + + uint32_t value = hash.value(); + + CHECK_EQUAL(test_trailing_zeros(value), etl::count_trailing_zeros(value)); + + if (test_trailing_zeros(value) != etl::count_trailing_zeros(value)) + { + break; + } + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_count_trailing_zeros_32_constexpr) + { + char temp[etl::count_trailing_zeros(uint32_t(0x08))]; + + CHECK_EQUAL(test_trailing_zeros(uint32_t(0x08)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_count_trailing_zeros_64) + { + etl::fnv_1a_64 hash; + + for (size_t i = 0UL; i < 100000UL; ++i) + { + hash.add(1); + + uint64_t value = hash.value(); + + CHECK_EQUAL(test_trailing_zeros(value), etl::count_trailing_zeros(value)); + + if (test_trailing_zeros(value) != etl::count_trailing_zeros(value)) + { + break; + } + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_count_trailing_zeros_64_constexpr) + { + char temp[etl::count_trailing_zeros(uint64_t(0x08))]; + + CHECK_EQUAL(etl::count_trailing_zeros(uint64_t(0x08)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_count_trailing_ones_8) + { + for (size_t i = 0; i < 256; ++i) + { + uint8_t value = uint8_t(i); + + CHECK_EQUAL(int(test_trailing_ones(value)), int(etl::count_trailing_ones(value))); + + if (test_trailing_ones(value) != etl::count_trailing_ones(value)) + { + break; + } + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_count_trailing_ones_8_constexpr) + { + char temp[etl::count_trailing_ones(uint8_t(0x0F))]; + + CHECK_EQUAL(test_trailing_ones(uint8_t(0x0F)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_count_trailing_ones_16) + { + for (size_t i = 0; i < 65536; ++i) + { + uint16_t value = uint16_t(i); + + CHECK_EQUAL(int(test_trailing_ones(value)), int(etl::count_trailing_ones(value))); + + if (test_trailing_ones(value) != etl::count_trailing_ones(value)) + { + break; + } + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_count_trailing_ones_16_constexpr) + { + char temp[etl::count_trailing_ones(uint16_t(0x000F))]; + + CHECK_EQUAL(test_trailing_ones(uint16_t(0x000F)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_count_trailing_ones_32) + { + etl::fnv_1a_32 hash; + + for (size_t i = 0UL; i < 100000UL; ++i) + { + hash.add(1); + + uint32_t value = hash.value(); + + CHECK_EQUAL(test_trailing_ones(value), etl::count_trailing_ones(value)); + + if (test_trailing_ones(value) != etl::count_trailing_ones(value)) + { + break; + } + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_count_trailing_ones_32_constexpr) + { + char temp[etl::count_trailing_ones(uint32_t(0x0000000F))]; + + CHECK_EQUAL(test_trailing_ones(uint32_t(0x0000000F)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_count_trailing_ones_64) + { + etl::fnv_1a_64 hash; + + for (size_t i = 0UL; i < 100000UL; ++i) + { + hash.add(1); + + uint64_t value = hash.value(); + + CHECK_EQUAL(test_trailing_ones(value), etl::count_trailing_ones(value)); + + if (test_trailing_ones(value) != etl::count_trailing_ones(value)) + { + break; + } + } + } +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_count_trailing_ones_64_constexpr) + { + char temp[etl::count_trailing_ones(uint64_t(0x000000000000000F))]; + + CHECK_EQUAL(test_trailing_ones(uint64_t(0x000000000000000F)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_count_leading_zeros_8) + { + for (size_t i = 0; i < 256; ++i) + { + uint8_t value = uint8_t(i); + + CHECK_EQUAL(int(test_leading_zeros(value)), int(etl::count_leading_zeros(value))); + + if (test_leading_zeros(value) != etl::count_leading_zeros(value)) + { + break; + } + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_count_leading_zeros_8_constexpr) + { + char temp[etl::count_leading_zeros(uint8_t(0x01U))]; + + CHECK_EQUAL(test_leading_zeros(uint8_t(0x01U)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_count_leading_zeros_16) + { + for (size_t i = 0; i < 65536; ++i) + { + uint16_t value = uint16_t(i); + + CHECK_EQUAL(int(test_leading_zeros(value)), int(etl::count_leading_zeros(value))); + + if (test_leading_zeros(value) != etl::count_leading_zeros(value)) + { + break; + } + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_count_leading_zeros_16_constexpr) + { + char temp[etl::count_leading_zeros(uint16_t(0x0800U))]; + + CHECK_EQUAL(test_leading_zeros(uint16_t(0x0800U)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_count_leading_zeros_32) + { + etl::fnv_1a_32 hash; + + for (size_t i = 0; i < 100000; ++i) + { + hash.add(1); + + uint32_t value = hash.value(); + + CHECK_EQUAL(int(test_leading_zeros(value)), int(etl::count_leading_zeros(value))); + + if (test_leading_zeros(value) != etl::count_leading_zeros(value)) + { + break; + } + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_count_leading_zeros_32_constexpr) + { + char temp[etl::count_leading_zeros(uint32_t(0x08000000U))]; + + CHECK_EQUAL(test_leading_zeros(uint32_t(0x08000000U)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_count_leading_zeros_64) + { + etl::fnv_1a_64 hash; + + for (size_t i = 0; i < 100000; ++i) + { + hash.add(1); + + uint64_t value = hash.value(); + + CHECK_EQUAL(int(test_leading_zeros(value)), int(etl::count_leading_zeros(value))); + + if (test_leading_zeros(value) != etl::count_leading_zeros(value)) + { + break; + } + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_count_leading_zeros_64_constexpr) + { + char temp[etl::count_leading_zeros(uint64_t(0x0800000000000000U))]; + + CHECK_EQUAL(test_leading_zeros(uint64_t(0x0800000000000000U)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_count_leading_ones_8) + { + for (size_t i = 0; i < 256; ++i) + { + uint8_t value = uint8_t(i); + + CHECK_EQUAL(int(test_leading_ones(value)), int(etl::count_leading_ones(value))); + + if (test_leading_ones(value) != etl::count_leading_ones(value)) + { + break; + } + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_count_leading_ones_8_constexpr) + { + char temp[etl::count_leading_ones(uint8_t(0xF0U))]; + + CHECK_EQUAL(test_leading_ones(uint8_t(0xF0U)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_count_leading_ones_16) + { + for (size_t i = 0; i < 65536; ++i) + { + uint16_t value = uint16_t(i); + + CHECK_EQUAL(int(test_leading_ones(value)), int(etl::count_leading_ones(value))); + + if (test_leading_ones(value) != etl::count_leading_ones(value)) + { + break; + } + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_count_leading_ones_16_constexpr) + { + char temp[etl::count_leading_ones(uint16_t(0xF000U))]; + + CHECK_EQUAL(test_leading_ones(uint16_t(0xF000U)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_count_leading_ones_32) + { + etl::fnv_1a_32 hash; + + for (size_t i = 0; i < 100000; ++i) + { + hash.add(1); + + uint32_t value = hash.value(); + + CHECK_EQUAL(int(test_leading_ones(value)), int(etl::count_leading_ones(value))); + + if (test_leading_ones(value) != etl::count_leading_ones(value)) + { + break; + } + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_count_leading_ones_32_constexpr) + { + char temp[etl::count_leading_ones(uint32_t(0xF0000000UL))]; + + CHECK_EQUAL(test_leading_ones(uint32_t(0xF0000000UL)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_count_leading_ones_64) + { + etl::fnv_1a_64 hash; + + for (size_t i = 0; i < 100000; ++i) + { + hash.add(1); + + uint64_t value = hash.value(); + + CHECK_EQUAL(int(test_leading_ones(value)), int(etl::count_leading_ones(value))); + + if (test_leading_ones(value) != etl::count_leading_ones(value)) + { + break; + } + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_count_leading_ones_64_constexpr) + { + char temp[etl::count_leading_ones(uint64_t(0xF000000000000000UL))]; + + CHECK_EQUAL(test_leading_ones(uint64_t(0xF000000000000000UL)), sizeof(temp)); + } +#endif }; } From b8579f0151fa6adc03b2da9671e50b40819c2b94 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 3 Jan 2022 18:21:45 +0000 Subject: [PATCH 08/15] Initial bit tests --- include/etl/bit.h | 98 ++--- test/test_bit.cpp | 896 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 953 insertions(+), 41 deletions(-) create mode 100644 test/test_bit.cpp diff --git a/include/etl/bit.h b/include/etl/bit.h index e31da3d0..d62047ac 100644 --- a/include/etl/bit.h +++ b/include/etl/bit.h @@ -28,14 +28,16 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************************/ -#ifndef ETL_BIT_CAST_INCLUDED -#define ETL_BIT_CAST_INCLUDED +#ifndef ETL_BIT_INCLUDED +#define ETL_BIT_INCLUDED #include #include "platform.h" #include "type_traits.h" #include "binary.h" +#include "integral_limits.h" +#include "endianness.h" namespace etl { @@ -56,7 +58,7 @@ namespace etl } //template - //ETL_CONSTEXPR + //ETL_CONSTEXPR14 //typename etl::enable_if<(sizeof(TDestination) == sizeof(TSource)) && // etl::is_trivially_copyable::value && // etl::is_trivially_copyable::value, TDestination>::type @@ -77,131 +79,145 @@ namespace etl typename etl::enable_if::value, T>::type byteswap(T value) ETL_NOEXCEPT { - return 0; - //return etl::reverse_bytes(value); + return etl::reverse_bytes(value); } //*************************************************************************** /// has_single_bit //*************************************************************************** template - ETL_NODISCARD ETL_CONSTEXPR - typename etl::enable_if::value, bool>::type has_single_bit(T x) ETL_NOEXCEPT + ETL_NODISCARD ETL_CONSTEXPR14 + typename etl::enable_if::value, bool>::type has_single_bit(T value) ETL_NOEXCEPT { - return false; - //return etl::is_power_of_2(x); + return (value & (value - 1)) == 0; } //*************************************************************************** /// bit_ceil //*************************************************************************** template - ETL_NODISCARD ETL_CONSTEXPR + ETL_NODISCARD ETL_CONSTEXPR14 typename etl::enable_if::value, T>::type - bit_ceil(T x) + bit_ceil(T value) { - return 0; + return 1; } //*************************************************************************** /// bit_floor //*************************************************************************** template - ETL_NODISCARD ETL_CONSTEXPR + ETL_NODISCARD ETL_CONSTEXPR14 typename etl::enable_if::value, T>::type - bit_floor(T x) ETL_NOEXCEPT + bit_floor(T value) ETL_NOEXCEPT { - return 0; + return 1; } //*************************************************************************** /// bit_width //*************************************************************************** template - ETL_CONSTEXPR + ETL_CONSTEXPR14 typename etl::enable_if::value, T>::type - bit_width(T x) ETL_NOEXCEPT + bit_width(T value) ETL_NOEXCEPT { - return 0; + return 1; } //*************************************************************************** /// rotl //*************************************************************************** template - ETL_NODISCARD ETL_CONSTEXPR + ETL_NODISCARD ETL_CONSTEXPR14 typename etl::enable_if::value, T>::type - rotl(T x, int s) ETL_NOEXCEPT + rotl(T value, int s) ETL_NOEXCEPT { - return 0; + ETL_CONSTANT size_t N = etl::integral_limits::bits; + + if (s < 0) + { + return etl::rotate_right(value, -s); + } + else + { + return etl::rotate_left(value, s); + } } //*************************************************************************** /// rotr //*************************************************************************** template - ETL_NODISCARD ETL_CONSTEXPR + ETL_NODISCARD ETL_CONSTEXPR14 typename etl::enable_if::value, T>::type - rotr(T x, int s) ETL_NOEXCEPT + rotr(T value, int s) ETL_NOEXCEPT { - return 0; + ETL_CONSTANT size_t N = etl::integral_limits::bits; + + if (s < 0) + { + return etl::rotate_left(value, -s); + } + else + { + return etl::rotate_right(value, s); + } } //*************************************************************************** /// countl_zero //*************************************************************************** template - ETL_NODISCARD ETL_CONSTEXPR + ETL_NODISCARD ETL_CONSTEXPR14 typename etl::enable_if::value, int>::type - countl_zero(T x) ETL_NOEXCEPT + countl_zero(T value) ETL_NOEXCEPT { - return 0; + return 1; } //*************************************************************************** /// countl_one //*************************************************************************** template - ETL_NODISCARD ETL_CONSTEXPR + ETL_NODISCARD ETL_CONSTEXPR14 typename etl::enable_if::value, int>::type - countl_one(T x) ETL_NOEXCEPT + countl_one(T value) ETL_NOEXCEPT { - return 0; + return 1; } //*************************************************************************** /// countr_zero //*************************************************************************** template - ETL_NODISCARD ETL_CONSTEXPR + ETL_NODISCARD ETL_CONSTEXPR14 typename etl::enable_if::value, int>::type - countr_zero(T x) ETL_NOEXCEPT + countr_zero(T value) ETL_NOEXCEPT { - return 0; - //return etl::count_trailing_zeros(x); + return etl::count_trailing_zeros(value); } //*************************************************************************** /// countr_one //*************************************************************************** template - ETL_NODISCARD ETL_CONSTEXPR + ETL_NODISCARD ETL_CONSTEXPR14 typename etl::enable_if::value, int>::type - countr_one(T x) ETL_NOEXCEPT + countr_one(T value) ETL_NOEXCEPT { - return 0; + return 1; } //*************************************************************************** /// popcount //*************************************************************************** template - ETL_NODISCARD ETL_CONSTEXPR + ETL_NODISCARD ETL_CONSTEXPR14 typename etl::enable_if::value, int>::type - popcount(T x) ETL_NOEXCEPT + popcount(T value) ETL_NOEXCEPT { - return 0; - //return etl::count_bits(x); + return etl::count_bits(value); } } diff --git a/test/test_bit.cpp b/test/test_bit.cpp new file mode 100644 index 00000000..c40ca37f --- /dev/null +++ b/test/test_bit.cpp @@ -0,0 +1,896 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include + +#include "etl/bit.h" +#include "etl/fnv_1.h" + +namespace +{ + // Count bits the long way. + template + size_t test_count(T value) + { + size_t count = 0UL; + + for (int i = 0; i < etl::integral_limits::bits; ++i) + { + if ((value & (T(1) << i)) != 0) + { + ++count; + } + } + + return count; + } + + // Count trailing zero the long way. + template + size_t test_trailing_zeros(T value) + { + size_t count = 0UL; + + for (int i = 0; i < etl::integral_limits::bits; ++i) + { + if ((value & 1) == 0) + { + ++count; + } + else + { + return count; + } + + value >>= 1; + } + + return count; + } + + // Count trailing ones the long way. + template + size_t test_trailing_ones(T value) + { + size_t count = 0UL; + + for (int i = 0; i < etl::integral_limits::bits; ++i) + { + if ((value & 1) == 1) + { + ++count; + } + + value >>= 1; + } + + return count; + } + + // Check parity the long way. + template + size_t test_parity(T value) + { + size_t count = test_count(value); + + return count & 1; + } + + // Power of 2. + uint64_t test_power_of_2(int power) + { + uint64_t result = 1ULL; + + for (int i = 0; i < power; ++i) + { + result *= 2; + } + + return result; + } + + SUITE(test_bit) + { + //************************************************************************* + TEST(test_rotl8) + { + uint8_t value; + + value = 0x00U; + value = etl::rotl(value, 1); + CHECK_EQUAL(0, int(value)); + + value = 0x21U; + value = etl::rotl(value, 1); + CHECK_EQUAL(0x42U, int(value)); + + value = 0x42U; + value = etl::rotl(value, 1); + CHECK_EQUAL(0x84U, int(value)); + + value = 0x84U; + value = etl::rotl(value, 1); + CHECK_EQUAL(0x09U, int(value)); + + value = 0xB7U; + value = etl::rotl(value, 2); + CHECK_EQUAL(0xDEU, int(value)); + + value = 0xB7U; + value = etl::rotl(value, 3); + CHECK_EQUAL(0xBDU, int(value)); + + value = 0xB7U; + value = etl::rotl(value, 4); + CHECK_EQUAL(0x7BU, int(value)); + + value = 0xB7U; + value = etl::rotl(value, 5); + CHECK_EQUAL(0xF6U, int(value)); + + value = 0xB7U; + value = etl::rotl(value, 6); + CHECK_EQUAL(0xEDU, int(value)); + + value = 0xB7U; + value = etl::rotl(value, 7); + CHECK_EQUAL(0xDBU, int(value)); + + value = 0xB7U; + value = etl::rotl(value, 8); + CHECK_EQUAL(0xB7U, int(value)); + + value = 0xB7U; + value = etl::rotl(value, 9); + CHECK_EQUAL(0x6FU, int(value)); + + value = 0xB7U; + value = etl::rotl(value, -1); + CHECK_EQUAL(0xDBU, int(value)); + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_rotl8_constexpr) + { + char temp[etl::rotl(uint8_t(0xAAU), 1)]; + + CHECK_EQUAL(etl::rotl(uint8_t(0xAAU), 1), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_rotl16) + { + uint16_t value; + + value = 0x0000U; + value = etl::rotl(value, 1); + CHECK_EQUAL(0, value); + + value = 0x8421U; + value = etl::rotl(value, 1); + CHECK_EQUAL(0x0843U, value); + + value = 0x0843U; + value = etl::rotl(value, 1); + CHECK_EQUAL(0x1086U, value); + + value = 0x1086U; + value = etl::rotl(value, 1); + CHECK_EQUAL(0x210CU, value); + + value = 0xB73CU; + value = etl::rotl(value, 2); + CHECK_EQUAL(0xDCF2U, int(value)); + + value = 0xB73CU; + value = etl::rotl(value, 3); + CHECK_EQUAL(0xB9E5U, int(value)); + + value = 0xB73CU; + value = etl::rotl(value, 4); + CHECK_EQUAL(0x73CBU, int(value)); + + value = 0xB73CU; + value = etl::rotl(value, 5); + CHECK_EQUAL(0xE796U, int(value)); + + value = 0xB73CU; + value = etl::rotl(value, 6); + CHECK_EQUAL(0xCF2DU, int(value)); + + value = 0xB73CU; + value = etl::rotl(value, 7); + CHECK_EQUAL(0x9E5BU, int(value)); + + value = 0xB73CU; + value = etl::rotl(value, 8); + CHECK_EQUAL(0x3CB7U, int(value)); + + value = 0xB73CU; + value = etl::rotl(value, 9); + CHECK_EQUAL(0x796EU, int(value)); + + value = 0xB73CU; + value = etl::rotl(value, 9); + CHECK_EQUAL(0x796EU, int(value)); + + value = 0xB73CU; + value = etl::rotl(value, 10); + CHECK_EQUAL(0xF2DCU, int(value)); + + value = 0xB73CU; + value = etl::rotl(value, 11); + CHECK_EQUAL(0xE5B9U, int(value)); + + value = 0xB73CU; + value = etl::rotl(value, 12); + CHECK_EQUAL(0xCB73U, int(value)); + + value = 0xB73CU; + value = etl::rotl(value, 13); + CHECK_EQUAL(0x96E7U, int(value)); + + value = 0xB73CU; + value = etl::rotl(value, 14); + CHECK_EQUAL(0x2DCFU, int(value)); + + value = 0xB73CU; + value = etl::rotl(value, 15); + CHECK_EQUAL(0x5B9EU, int(value)); + + value = 0xB73CU; + value = etl::rotl(value, 16); + CHECK_EQUAL(0xB73CU, int(value)); + + value = 0xB73CU; + value = etl::rotl(value, 17); + CHECK_EQUAL(0x6E79U, int(value)); + + value = 0xB73CU; + value = etl::rotl(value, -1); + CHECK_EQUAL(0x5B9EU, int(value)); + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_rotl16_constexpr) + { + char temp[etl::rotl(uint16_t(0xAAU), 1)]; + + CHECK_EQUAL(etl::rotl(uint16_t(0xAAU), 1), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_rotate_right8) + { + uint8_t value; + + value = 0x00U; + value = etl::rotate_right(value); + CHECK_EQUAL(0, int(value)); + + value = 0x21U; + value = etl::rotate_right(value); + CHECK_EQUAL(0x90U, int(value)); + + value = 0x42U; + value = etl::rotate_right(value); + CHECK_EQUAL(0x21U, int(value)); + + value = 0x84U; + value = etl::rotate_right(value); + CHECK_EQUAL(0x42U, int(value)); + + value = 0xB7U; + value = etl::rotate_right(value, 2); + CHECK_EQUAL(0xEDU, int(value)); + + value = 0xB7U; + value = etl::rotate_right(value, 3); + CHECK_EQUAL(0xF6U, int(value)); + + value = 0xB7U; + value = etl::rotate_right(value, 4); + CHECK_EQUAL(0x7BU, int(value)); + + value = 0xB7U; + value = etl::rotate_right(value, 5); + CHECK_EQUAL(0xBDU, int(value)); + + value = 0xB7U; + value = etl::rotate_right(value, 6); + CHECK_EQUAL(0xDEU, int(value)); + + value = 0xB7U; + value = etl::rotate_right(value, 7); + CHECK_EQUAL(0x6FU, int(value)); + + value = 0xB7U; + value = etl::rotate_right(value, 8); + CHECK_EQUAL(0xB7U, int(value)); + + value = 0xB7U; + value = etl::rotate_right(value, 9); + CHECK_EQUAL(0xDBU, int(value)); + + value = 0xB7U; + value = etl::rotate_right(value, -1); + CHECK_EQUAL(0x6FU, int(value)); + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_rotate_right8_constexpr) + { + char temp[etl::rotate_right(uint8_t(0xAAU))]; + + CHECK_EQUAL(etl::rotate_right(uint8_t(0xAAU)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_rotate_right16) + { + uint16_t value; + + value = 0x0000U; + value = etl::rotate_right(value); + CHECK_EQUAL(0, value); + + value = 0x8421U; + value = etl::rotate_right(value); + CHECK_EQUAL(0xC210U, value); + + value = 0xC210U; + value = etl::rotate_right(value); + CHECK_EQUAL(0x6108U, value); + + value = 0x6108U; + value = etl::rotate_right(value); + CHECK_EQUAL(0x3084U, value); + + value = 0xB73CU; + value = etl::rotate_right(value, 2); + CHECK_EQUAL(0x2DCFU, int(value)); + + value = 0xB73CU; + value = etl::rotate_right(value, 3); + CHECK_EQUAL(0x96E7U, int(value)); + + value = 0xB73CU; + value = etl::rotate_right(value, 4); + CHECK_EQUAL(0xCB73U, int(value)); + + value = 0xB73CU; + value = etl::rotate_right(value, 5); + CHECK_EQUAL(0xE5B9U, int(value)); + + value = 0xB73CU; + value = etl::rotate_right(value, 6); + CHECK_EQUAL(0xF2DCU, int(value)); + + value = 0xB73CU; + value = etl::rotate_right(value, 7); + CHECK_EQUAL(0x796EU, int(value)); + + value = 0xB73CU; + value = etl::rotate_right(value, 8); + CHECK_EQUAL(0x3CB7U, int(value)); + + value = 0xB73CU; + value = etl::rotate_right(value, 9); + CHECK_EQUAL(0x9E5BU, int(value)); + + value = 0xB73CU; + value = etl::rotate_right(value, 9); + CHECK_EQUAL(0x9E5BU, int(value)); + + value = 0xB73CU; + value = etl::rotate_right(value, 10); + CHECK_EQUAL(0xCF2DU, int(value)); + + value = 0xB73CU; + value = etl::rotate_right(value, 11); + CHECK_EQUAL(0xE796U, int(value)); + + value = 0xB73CU; + value = etl::rotate_right(value, 12); + CHECK_EQUAL(0x73CBU, int(value)); + + value = 0xB73CU; + value = etl::rotate_right(value, 13); + CHECK_EQUAL(0xB9E5U, int(value)); + + value = 0xB73CU; + value = etl::rotate_right(value, 14); + CHECK_EQUAL(0xDCF2U, int(value)); + + value = 0xB73CU; + value = etl::rotate_right(value, 15); + CHECK_EQUAL(0x6E79U, int(value)); + + value = 0xB73CU; + value = etl::rotate_right(value, 16); + CHECK_EQUAL(0xB73CU, int(value)); + + value = 0xB73CU; + value = etl::rotate_right(value, 17); + CHECK_EQUAL(0x5B9EU, int(value)); + + value = 0xB73CU; + value = etl::rotate_right(value, -1); + CHECK_EQUAL(0x6E79U, int(value)); + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_rotate_right16_constexpr) + { + char temp[etl::rotate_right(uint16_t(0xAAU))]; + + CHECK_EQUAL(etl::rotate_right(uint16_t(0xAAU)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_rotate16) + { + uint16_t value; + int offset; + + offset = 4; + value = 0xB73CU; + value = etl::rotate(value, offset); + CHECK_EQUAL(0x73CBU, int(value)); + + offset = -4; + value = 0xB73CU; + value = etl::rotate(value, offset); + CHECK_EQUAL(0xCB73U, int(value)); + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_rotate16_constexpr) + { + char temp[etl::rotate(uint16_t(0xAAU), 1)]; + + CHECK_EQUAL(etl::rotate(uint16_t(0xAAU), 1), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_reverse_bytes16) + { + uint16_t value; + + value = 0xFC5AU; + value = etl::byteswap(value); + CHECK_EQUAL(0x5AFCU, value); + + value = 0x5AA5U; + value = etl::byteswap(value); + CHECK_EQUAL(0xA55AU, value); + + value = 0xA55AU; + value = etl::byteswap(value); + CHECK_EQUAL(0x5AA5U, value); + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_reverse_bytes16_constexpr) + { + char temp[etl::byteswap(uint16_t(0xA500U))]; + + CHECK_EQUAL(etl::byteswap(uint16_t(0xA500U)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_reverse_bytes32) + { + uint32_t value; + + value = 0xF0C3A55AUL; + value = etl::byteswap(value); + CHECK_EQUAL(0x5AA5C3F0UL, value); + + value = 0xA5A55A5AUL; + value = etl::byteswap(value); + CHECK_EQUAL(0x5A5AA5A5UL, value); + + value = 0x5A5AA5A5UL; + value = etl::byteswap(value); + CHECK_EQUAL(0xA5A55A5AUL, value); + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_reverse_bytes32_constexpr) + { + char temp[etl::byteswap(uint32_t(0xA5000000UL))]; + + CHECK_EQUAL(etl::byteswap(uint32_t(0xA5000000UL)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_reverse_bytes64) + { + uint64_t value; + + value = 0x0123456789ABCDEFULL; + value = etl::byteswap(value); + CHECK_EQUAL(0xEFCDAB8967452301ULL, value); + + value = 0xA5A55A5AA5A55A5AULL; + value = etl::byteswap(value); + CHECK_EQUAL(0x5A5AA5A55A5AA5A5ULL, value); + + value = 0x5A5AA5A55A5AA5A5ULL; + value = etl::byteswap(value); + CHECK_EQUAL(0xA5A55A5AA5A55A5AULL, value); + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_reverse_bytes64_constexpr) + { + char temp[etl::byteswap(uint64_t(0xA500000000000000ULL))]; + + CHECK_EQUAL(etl::byteswap(uint64_t(0xA500000000000000ULL)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_count_bits_8) + { + for (size_t i = 1UL; i <= std::numeric_limits::max(); ++i) + { + CHECK_EQUAL(test_count(i), etl::popcount(uint8_t(i))); + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_count_bits_8_constexpr) + { + char temp[etl::popcount(uint8_t(0xFFU))]; + + CHECK_EQUAL(etl::popcount(uint8_t(0xFFU)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_count_bits_16) + { + for (size_t i = 1UL; i <= std::numeric_limits::max(); ++i) + { + CHECK_EQUAL(test_count(i), etl::popcount(uint16_t(i))); + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_count_bits_16_constexpr) + { + char temp[etl::popcount(uint16_t(0xFFU))]; + + CHECK_EQUAL(etl::popcount(uint16_t(0xFFU)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_count_bits_32) + { + etl::fnv_1a_32 hash; + + for (size_t i = 0UL; i < 1000000UL; ++i) + { + hash.add(1); + + uint32_t value = hash.value(); + + CHECK_EQUAL(test_count(value), etl::popcount(value)); + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_count_bits_32_constexpr) + { + char temp[etl::popcount(uint32_t(0xFFU))]; + + CHECK_EQUAL(etl::popcount(uint32_t(0xFFU)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_count_bits_64) + { + etl::fnv_1a_64 hash; + + for (size_t i = 0UL; i < 1000000UL; ++i) + { + hash.add(1); + + uint64_t value = hash.value(); + + CHECK_EQUAL(test_count(value), etl::popcount(value)); + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_count_bits_64_constexpr) + { + char temp[etl::popcount(uint64_t(0xFFU))]; + + CHECK_EQUAL(etl::popcount(uint64_t(0xFFU)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_count_trailing_zeros_8) + { + etl::fnv_1a_32 hash; + + for (size_t i = 0; i < 256; ++i) + { + uint8_t value = uint8_t(i); + + CHECK_EQUAL(test_trailing_zeros(value), etl::countr_zero(value)); + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_count_trailing_zeros_8_constexpr) + { + char temp[etl::countr_zero(uint8_t(0x08))]; + + CHECK_EQUAL(etl::countr_zero(uint8_t(0x08)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_count_trailing_zeros_16) + { + for (size_t i = 0; i < 65536; ++i) + { + uint16_t value = uint16_t(i); + + CHECK_EQUAL(test_trailing_zeros(value), etl::countr_zero(value)); + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_count_trailing_zeros_16_constexpr) + { + char temp[etl::countr_zero(uint16_t(0x08))]; + + CHECK_EQUAL(etl::countr_zero(uint16_t(0x08)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_count_trailing_zeros_32) + { + etl::fnv_1a_32 hash; + + for (size_t i = 0UL; i < 100000UL; ++i) + { + hash.add(1); + + uint32_t value = hash.value(); + + CHECK_EQUAL(test_trailing_zeros(value), etl::countr_zero(value)); + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_count_trailing_zeros_32_constexpr) + { + char temp[etl::countr_zero(uint32_t(0x08))]; + + CHECK_EQUAL(etl::countr_zero(uint32_t(0x08)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_count_trailing_zeros_64) + { + etl::fnv_1a_64 hash; + + for (size_t i = 0UL; i < 100000UL; ++i) + { + hash.add(1); + + uint64_t value = hash.value(); + + CHECK_EQUAL(test_trailing_zeros(value), etl::countr_zero(value)); + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_count_trailing_zeros_64_constexpr) + { + char temp[etl::countr_zero(uint64_t(0x08))]; + + CHECK_EQUAL(etl::countr_zero(uint64_t(0x08)), sizeof(temp)); + } +#endif +// //************************************************************************* +// TEST(test_max_value_for_bits) +// { +// // Check that the values are correct. +// //CHECK_EQUAL(0U, etl::max_value_for_nbits<0>::value); +// CHECK_EQUAL(1U, etl::max_value_for_nbits<1>::value); +// CHECK_EQUAL(3U, etl::max_value_for_nbits<2>::value); +// CHECK_EQUAL(7U, etl::max_value_for_nbits<3>::value); +// CHECK_EQUAL(15U, etl::max_value_for_nbits<4>::value); +// CHECK_EQUAL(31U, etl::max_value_for_nbits<5>::value); +// CHECK_EQUAL(63U, etl::max_value_for_nbits<6>::value); +// CHECK_EQUAL(127U, etl::max_value_for_nbits<7>::value); +// CHECK_EQUAL(255U, etl::max_value_for_nbits<8>::value); +// CHECK_EQUAL(511U, etl::max_value_for_nbits<9>::value); +// CHECK_EQUAL(1023U, etl::max_value_for_nbits<10>::value); +// CHECK_EQUAL(2047U, etl::max_value_for_nbits<11>::value); +// CHECK_EQUAL(4095U, etl::max_value_for_nbits<12>::value); +// CHECK_EQUAL(8191U, etl::max_value_for_nbits<13>::value); +// CHECK_EQUAL(16383U, etl::max_value_for_nbits<14>::value); +// CHECK_EQUAL(32767U, etl::max_value_for_nbits<15>::value); +// CHECK_EQUAL(65535U, etl::max_value_for_nbits<16>::value); +// CHECK_EQUAL(131071UL, etl::max_value_for_nbits<17>::value); +// CHECK_EQUAL(262143UL, etl::max_value_for_nbits<18>::value); +// CHECK_EQUAL(524287UL, etl::max_value_for_nbits<19>::value); +// CHECK_EQUAL(1048575UL, etl::max_value_for_nbits<20>::value); +// CHECK_EQUAL(2097151UL, etl::max_value_for_nbits<21>::value); +// CHECK_EQUAL(4194303UL, etl::max_value_for_nbits<22>::value); +// CHECK_EQUAL(8388607UL, etl::max_value_for_nbits<23>::value); +// CHECK_EQUAL(16777215UL, etl::max_value_for_nbits<24>::value); +// CHECK_EQUAL(33554431UL, etl::max_value_for_nbits<25>::value); +// CHECK_EQUAL(67108863UL, etl::max_value_for_nbits<26>::value); +// CHECK_EQUAL(134217727UL, etl::max_value_for_nbits<27>::value); +// CHECK_EQUAL(268435455UL, etl::max_value_for_nbits<28>::value); +// CHECK_EQUAL(536870911UL, etl::max_value_for_nbits<29>::value); +// CHECK_EQUAL(1073741823UL, etl::max_value_for_nbits<30>::value); +// CHECK_EQUAL(2147483647UL, etl::max_value_for_nbits<31>::value); +// CHECK_EQUAL(4294967295UL, etl::max_value_for_nbits<32>::value); +// CHECK_EQUAL(8589934591ULL, etl::max_value_for_nbits<33>::value); +// CHECK_EQUAL(17179869183ULL, etl::max_value_for_nbits<34>::value); +// CHECK_EQUAL(34359738367ULL, etl::max_value_for_nbits<35>::value); +// CHECK_EQUAL(68719476735ULL, etl::max_value_for_nbits<36>::value); +// CHECK_EQUAL(137438953471ULL, etl::max_value_for_nbits<37>::value); +// CHECK_EQUAL(274877906943ULL, etl::max_value_for_nbits<38>::value); +// CHECK_EQUAL(549755813887ULL, etl::max_value_for_nbits<39>::value); +// CHECK_EQUAL(1099511627775ULL, etl::max_value_for_nbits<40>::value); +// CHECK_EQUAL(2199023255551ULL, etl::max_value_for_nbits<41>::value); +// CHECK_EQUAL(4398046511103ULL, etl::max_value_for_nbits<42>::value); +// CHECK_EQUAL(8796093022207ULL, etl::max_value_for_nbits<43>::value); +// CHECK_EQUAL(17592186044415ULL, etl::max_value_for_nbits<44>::value); +// CHECK_EQUAL(35184372088831ULL, etl::max_value_for_nbits<45>::value); +// CHECK_EQUAL(70368744177663ULL, etl::max_value_for_nbits<46>::value); +// CHECK_EQUAL(140737488355327ULL, etl::max_value_for_nbits<47>::value); +// CHECK_EQUAL(281474976710655ULL, etl::max_value_for_nbits<48>::value); +// CHECK_EQUAL(562949953421311ULL, etl::max_value_for_nbits<49>::value); +// CHECK_EQUAL(1125899906842623ULL, etl::max_value_for_nbits<50>::value); +// CHECK_EQUAL(2251799813685247ULL, etl::max_value_for_nbits<51>::value); +// CHECK_EQUAL(4503599627370495ULL, etl::max_value_for_nbits<52>::value); +// CHECK_EQUAL(9007199254740991ULL, etl::max_value_for_nbits<53>::value); +// CHECK_EQUAL(18014398509481983ULL, etl::max_value_for_nbits<54>::value); +// CHECK_EQUAL(36028797018963967ULL, etl::max_value_for_nbits<55>::value); +// CHECK_EQUAL(72057594037927935ULL, etl::max_value_for_nbits<56>::value); +// CHECK_EQUAL(144115188075855871ULL, etl::max_value_for_nbits<57>::value); +// CHECK_EQUAL(288230376151711743ULL, etl::max_value_for_nbits<58>::value); +// CHECK_EQUAL(576460752303423487ULL, etl::max_value_for_nbits<59>::value); +// CHECK_EQUAL(1152921504606846975ULL, etl::max_value_for_nbits<60>::value); +// CHECK_EQUAL(2305843009213693951ULL, etl::max_value_for_nbits<61>::value); +// CHECK_EQUAL(4611686018427387903ULL, etl::max_value_for_nbits<62>::value); +// CHECK_EQUAL(9223372036854775807ULL, etl::max_value_for_nbits<63>::value); +// CHECK_EQUAL(18446744073709551615ULL, etl::max_value_for_nbits<64>::value); +// +// // Check that the value types are correct. +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// CHECK((etl::is_same::value_type>::value)); +// } + }; +} + From 9665ab21c1daebd60c6571f639fda3d0ed92d2e1 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 3 Jan 2022 18:22:08 +0000 Subject: [PATCH 09/15] Updated endianness for C++20 --- include/etl/endianness.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/include/etl/endianness.h b/include/etl/endianness.h index 99522171..14b48b8c 100644 --- a/include/etl/endianness.h +++ b/include/etl/endianness.h @@ -37,6 +37,10 @@ SOFTWARE. #include "enum_type.h" #include "binary.h" +#if ETL_CPP20_SUPPORTED && ETL_USING_STL + #include +#endif + ///\defgroup endian endian /// Constants & utilities for endianess ///\ingroup utilities @@ -49,12 +53,36 @@ namespace etl //*************************************************************************** struct endian { +#if ETL_CPP20_SUPPORTED && ETL_USING_STL + enum enum_type + { + little = static_cast(std::endian::little), + big = static_cast(std::endian::big), + native = static_cast(std::endian::native) + }; +#elif defined(__BYTE_ORDER__) + #if defined(__ORDER_LITTLE_ENDIAN__) + #defined ETL_LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__ + #defined ETL_BIG_ENDIAN __ORDER_BIG_ENDIAN__ + #elif defined(__LITTLE_ENDIAN__) + #defined ETL_LITTLE_ENDIAN __LITTLE_ENDIAN__ + #defined ETL_BIG_ENDIAN __BIG_ENDIAN__ + #endif + + enum enum_type + { + little = ETL_LITTLE_ENDIAN, + big = ETL_BIG_ENDIAN, + native = __BYTE_ORDER__ + }; +#else enum enum_type { little, big, native }; +#endif ETL_DECLARE_ENUM_TYPE(endian, int) ETL_ENUM_TYPE(little, "little") From dc2ad30294edb257a137b7f5289eb428c43928af Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 3 Jan 2022 18:23:04 +0000 Subject: [PATCH 10/15] Iterator is more SFINAE compatible --- include/etl/iterator.h | 31 +++++++++++++++------------ include/etl/numeric.h | 48 +++++++++--------------------------------- test/test_numeric.cpp | 40 ++++++++++++++++++++++++++++++++--- 3 files changed, 65 insertions(+), 54 deletions(-) diff --git a/include/etl/iterator.h b/include/etl/iterator.h index 5fb8c080..4724bb47 100644 --- a/include/etl/iterator.h +++ b/include/etl/iterator.h @@ -51,10 +51,13 @@ namespace etl struct forward_iterator_tag : public input_iterator_tag {}; struct bidirectional_iterator_tag : public forward_iterator_tag {}; struct random_access_iterator_tag : public bidirectional_iterator_tag {}; + struct contiguous_iterator_tag : public random_access_iterator_tag {}; //*************************************************************************** // iterator_traits - template + + // For anything not a fundamental type. + template ::value, void>::type> struct iterator_traits { typedef typename TIterator::iterator_category iterator_category; @@ -63,25 +66,27 @@ namespace etl typedef typename TIterator::pointer pointer; typedef typename TIterator::reference reference; }; - + + // For pointers. template - struct iterator_traits + struct iterator_traits { typedef ETL_OR_STD::random_access_iterator_tag iterator_category; - typedef T value_type; - typedef ptrdiff_t difference_type; - typedef T* pointer; - typedef T& reference; + typedef T value_type; + typedef ptrdiff_t difference_type; + typedef typename etl::remove_cv::type* pointer; + typedef T& reference; }; + // For const pointers. template - struct iterator_traits + struct iterator_traits { - typedef ETL_OR_STD::random_access_iterator_tag iterator_category; - typedef T value_type; - typedef ptrdiff_t difference_type; - typedef const T* pointer; - typedef const T& reference; + typedef ETL_OR_STD::random_access_iterator_tag iterator_category; + typedef T value_type; + typedef ptrdiff_t difference_type; + typedef const typename etl::remove_cv::type* pointer; + typedef const T& reference; }; //*************************************************************************** diff --git a/include/etl/numeric.h b/include/etl/numeric.h index 342c1b80..a72c6858 100644 --- a/include/etl/numeric.h +++ b/include/etl/numeric.h @@ -153,10 +153,10 @@ namespace etl /// For ETL random access iterators. //*************************************************************************** template - ETL_CONSTEXPR typename etl::enable_if::value && - !etl::is_integral::value && - !etl::is_floating_point::value, T>::type - midpoint(T a, T b, typename etl::enable_if::iterator_category, etl::random_access_iterator_tag>::value, void>::type) + ETL_CONSTEXPR T midpoint(T a, T b, typename etl::enable_if::value && + !etl::is_integral::value && + !etl::is_floating_point::value && + etl::is_same::iterator_category, ETL_OR_STD::random_access_iterator_tag>::value , int>::type = 0) { if (a > b) { @@ -174,45 +174,17 @@ namespace etl /// Parameter 'a' must be before 'b', otherwise the result is undefined. //*************************************************************************** template - ETL_CONSTEXPR T midpoint(T a, T b, typename etl::enable_if<(etl::is_same::iterator_category, std::forward_iterator_tag>::value || - etl::is_same::iterator_category, etl::bidirectional_iterator_tag>::value) && !etl::is_pointer::value, void>::type) + ETL_CONSTEXPR T midpoint(T a, T b, typename etl::enable_if<(!etl::is_pointer::value && + !etl::is_integral::value && + !etl::is_floating_point::value && + etl::is_same::iterator_category, ETL_OR_STD::forward_iterator_tag>::value || + etl::is_same::iterator_category, ETL_OR_STD::bidirectional_iterator_tag>::value) + , int>::type = 0) { etl::advance(a, etl::distance(a, b) / 2U); return a; } -#if ETL_USING_STL - //*************************************************************************** - /// midpoint - /// For STL random access iterators - //*************************************************************************** - template - ETL_CONSTEXPR T midpoint(T a, T b, typename etl::enable_if::iterator_category, std::random_access_iterator_tag>::value && !etl::is_pointer::value, int>::type = 0) - { - if (a > b) - { - return b + (etl::distance(b, a) / 2U); - } - else - { - return a + (etl::distance(a, b) / 2U); - } - } - - //*************************************************************************** - /// midpoint - /// For ETL forward and bidirectional iterators. - /// Parameter 'a' must be before 'b', otherwise the result is undefined. - //*************************************************************************** - template - ETL_CONSTEXPR T midpoint(T a, T b, typename etl::enable_if<(etl::is_same::iterator_category, std::forward_iterator_tag>::value || - etl::is_same::iterator_category, std::bidirectional_iterator_tag>::value) && !etl::is_pointer::value, int>::type = 0) - { - etl::advance(a, etl::distance(a, b) / 2U); - return a; - } -#endif - //*************************************************************************** /// Linear interpolation /// For floating point. diff --git a/test/test_numeric.cpp b/test/test_numeric.cpp index d26f2aed..aa0760ab 100644 --- a/test/test_numeric.cpp +++ b/test/test_numeric.cpp @@ -29,6 +29,8 @@ SOFTWARE. #include "unit_test_framework.h" #include "etl/numeric.h" +#include "etl/deque.h" +#include "etl/list.h" #include #include @@ -100,7 +102,36 @@ namespace } //************************************************************************* - TEST(test_midpoint_random_access_iterator) + TEST(test_midpoint_etl_random_access_iterator) + { + etl::deque data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + + etl::deque::iterator b = data.begin(); + etl::deque::iterator e = data.end(); + + CHECK_EQUAL(data[5], (*etl::midpoint(b, e))); + CHECK_EQUAL(data[5], (*etl::midpoint(e, b))); + } + + //************************************************************************* + TEST(test_midpoint_etl_bidirectional_iterator) + { + etl::list data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + + etl::list::iterator b = data.begin(); + etl::list::iterator e = data.end(); + + etl::list::iterator c = data.begin(); + etl::advance(c, 5); + + int v = *etl::midpoint(b, e); + + CHECK_EQUAL(*c, v); + } + +#if ETL_USING_STL + //************************************************************************* + TEST(test_midpoint_std_random_access_iterator) { std::deque data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; @@ -112,7 +143,7 @@ namespace } //************************************************************************* - TEST(test_midpoint_bidirectional_iterator) + TEST(test_midpoint_std_bidirectional_iterator) { std::list data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; @@ -122,8 +153,11 @@ namespace std::list::iterator c = data.begin(); std::advance(c, 5); - CHECK_EQUAL(*c, *etl::midpoint(b, e)); + int v = *etl::midpoint(b, e); + + CHECK_EQUAL(*c, v); } +#endif //************************************************************************* TEST(test_lerp_floating_point) From 4a6d6220e4e6d307805ae1ef760af1258843d398 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 3 Jan 2022 18:24:05 +0000 Subject: [PATCH 11/15] Added bit.h and test files --- test/vs2019/etl.vcxproj | 1 + test/vs2019/etl.vcxproj.filters | 3 +++ 2 files changed, 4 insertions(+) diff --git a/test/vs2019/etl.vcxproj b/test/vs2019/etl.vcxproj index 2152c79d..89c95188 100644 --- a/test/vs2019/etl.vcxproj +++ b/test/vs2019/etl.vcxproj @@ -7790,6 +7790,7 @@ + diff --git a/test/vs2019/etl.vcxproj.filters b/test/vs2019/etl.vcxproj.filters index 089811e6..5fabac2f 100644 --- a/test/vs2019/etl.vcxproj.filters +++ b/test/vs2019/etl.vcxproj.filters @@ -3086,6 +3086,9 @@ Tests + + Tests + From fdf3ee164f3eac579570e9a5c8d38b2c2f9243fa Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 3 Jan 2022 18:26:48 +0000 Subject: [PATCH 12/15] Disabled C++20 for test --- test/etl_profile.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/etl_profile.h b/test/etl_profile.h index 2ef4c5f1..8cac498b 100644 --- a/test/etl_profile.h +++ b/test/etl_profile.h @@ -73,6 +73,8 @@ SOFTWARE. #define ETL_POLYMORPHIC_VECTOR #define ETL_POLYMORPHIC_INDIRECT_VECTOR +#define ETL_CPP20_SUPPORTED 0 + //#define ETL_POLYMORPHIC_CONTAINERS //#define ETL_MESSAGES_ARE_VIRTUAL From c99d984453c1cc707ee220d96531772f9264b3b2 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 8 Jan 2022 11:38:04 +0000 Subject: [PATCH 13/15] Updates to bin.h, binary.h and endian.h --- .gitignore | 1 + include/etl/binary.h | 136 +++- include/etl/bit.h | 103 +-- include/etl/endianness.h | 91 ++- include/etl/private/minmax_pop.h | 14 +- include/etl/private/minmax_push.h | 15 +- test/test_binary.cpp | 270 ++++---- test/test_bit.cpp | 1011 +++++++++++++++++++++++------ test/vs2019/etl.sln | 6 + test/vs2019/etl.vcxproj | 339 ++++++++++ 10 files changed, 1555 insertions(+), 431 deletions(-) diff --git a/.gitignore b/.gitignore index 9f430d3d..d9727519 100644 --- a/.gitignore +++ b/.gitignore @@ -344,3 +344,4 @@ test/meson-logs test/meson-private test/build-make test/build-ninja +test/vs2019/Debug MSVC C++20 diff --git a/include/etl/binary.h b/include/etl/binary.h index 9d5fb080..fc253d12 100644 --- a/include/etl/binary.h +++ b/include/etl/binary.h @@ -46,6 +46,10 @@ SOFTWARE. #include "exception.h" #include "error_handler.h" +#if ETL_CPP20_SUPPORTED && ETL_USING_STL + #include +#endif + namespace etl { //*************************************************************************** @@ -111,11 +115,15 @@ namespace etl template ETL_CONSTEXPR14 T rotate_left(T value) { +#if ETL_CPP20_SUPPORTED && ETL_USING_STL + return std::rotl(value, 1); +#else ETL_STATIC_ASSERT(etl::is_integral::value, "Not an integral type"); const size_t SHIFT = etl::integral_limits::type>::bits - 1; return (value << 1U) | (value >> SHIFT); +#endif } //*************************************************************************** @@ -125,6 +133,9 @@ namespace etl template ETL_CONSTEXPR14 T rotate_left(T value, size_t distance) { +#if ETL_CPP20_SUPPORTED && ETL_USING_STL + return std::rotl(value, distance); +#else ETL_STATIC_ASSERT(etl::is_integral::value, "Not an integral type"); const size_t BITS = etl::integral_limits::type>::bits; @@ -132,6 +143,7 @@ namespace etl const size_t SHIFT = BITS - distance; return (value << distance) | (value >> SHIFT); +#endif } //*************************************************************************** @@ -141,11 +153,15 @@ namespace etl template ETL_CONSTEXPR14 T rotate_right(T value) { +#if ETL_CPP20_SUPPORTED && ETL_USING_STL + return std::rotr(value, 1); +#else ETL_STATIC_ASSERT(etl::is_integral::value, "Not an integral type"); const size_t SHIFT = etl::integral_limits::type>::bits - 1; return (value >> 1U) | (value << SHIFT); +#endif } //*************************************************************************** @@ -155,6 +171,9 @@ namespace etl template ETL_CONSTEXPR14 T rotate_right(T value, size_t distance) { +#if ETL_CPP20_SUPPORTED && ETL_USING_STL + return std::rotr(value, distance); +#else ETL_STATIC_ASSERT(etl::is_integral::value, "Not an integral type"); const size_t BITS = etl::integral_limits::type>::bits; @@ -162,6 +181,7 @@ namespace etl const size_t SHIFT = BITS - distance; return (value >> distance) | (value << SHIFT); +#endif } //*************************************************************************** @@ -209,7 +229,7 @@ namespace etl { ETL_STATIC_ASSERT(integral_limits::bits >= NBITS, "Return type too small to hold result"); - const TValue mask = etl::power<2, NBITS>::value - 1; + const TValue mask = etl::power<2, NBITS>::value - 1U; const size_t shift = NBITS; // Fold the value down to fit the width. @@ -707,7 +727,11 @@ namespace etl //*************************************************************************** inline ETL_CONSTEXPR uint16_t reverse_bytes(uint16_t value) { +#if ETL_CPP23_SUPPORTED && ETL_USING_STL + return std::byteswap(value); +#else return (value >> 8U) | (value << 8U); +#endif } inline ETL_CONSTEXPR int16_t reverse_bytes(int16_t value) @@ -721,10 +745,14 @@ namespace etl //*************************************************************************** inline ETL_CONSTEXPR14 uint32_t reverse_bytes(uint32_t value) { +#if ETL_CPP23_SUPPORTED && ETL_USING_STL + return std::byteswap(value); +#else value = ((value & 0xFF00FF00UL) >> 8U) | ((value & 0x00FF00FFUL) << 8U); value = (value >> 16U) | (value << 16U); return value; +#endif } inline ETL_CONSTEXPR14 int32_t reverse_bytes(int32_t value) @@ -739,11 +767,15 @@ namespace etl //*************************************************************************** inline ETL_CONSTEXPR14 uint64_t reverse_bytes(uint64_t value) { +#if ETL_CPP23_SUPPORTED && ETL_USING_STL + return std::byteswap(value); +#else value = ((value & 0xFF00FF00FF00FF00ULL) >> 8U) | ((value & 0x00FF00FF00FF00FFULL) << 8U); value = ((value & 0xFFFF0000FFFF0000ULL) >> 16U) | ((value & 0x0000FFFF0000FFFFULL) << 16U); value = (value >> 32U) | (value << 32U); return value; +#endif } inline ETL_CONSTEXPR14 int64_t reverse_bytes(int64_t value) @@ -759,11 +791,17 @@ namespace etl //*************************************************************************** inline ETL_CONSTEXPR14 uint8_t gray_to_binary(uint8_t value) { - value ^= (value >> 4U); - value ^= (value >> 2U); - value ^= (value >> 1U); + uint8_t value1 = value ^ (value >> 4U); + uint8_t value2 = value1 ^ (value1 >> 2U); + uint8_t value3 = value2 ^ (value2 >> 1U); - return value; + return value3; + + //value ^= (value >> 4U); + //value ^= (value >> 2U); + //value ^= (value >> 1U); + + //return value; } inline ETL_CONSTEXPR14 int8_t gray_to_binary(int8_t value) @@ -841,6 +879,9 @@ namespace etl //*************************************************************************** inline ETL_CONSTEXPR14 uint_least8_t count_bits(uint8_t value) { +#if ETL_CPP23_SUPPORTED && ETL_USING_STL + return std::popcount(value); +#else uint32_t count = 0U; count = value - ((value >> 1U) & 0x55U); @@ -848,6 +889,7 @@ namespace etl count = ((count >> 4U) + count) & 0x0FU; return uint_least8_t(count); +#endif } inline ETL_CONSTEXPR14 uint_least8_t count_bits(int8_t value) @@ -863,6 +905,9 @@ namespace etl //*************************************************************************** inline ETL_CONSTEXPR14 uint_least8_t count_bits(uint16_t value) { +#if ETL_CPP20_SUPPORTED && ETL_USING_STL + return std::popcount(value); +#else uint32_t count = 0U; count = value - ((value >> 1U) & 0x5555U); @@ -871,6 +916,7 @@ namespace etl count = ((count >> 8U) + count) & 0x00FFU; return static_cast(count); +#endif } inline ETL_CONSTEXPR14 uint_least8_t count_bits(int16_t value) @@ -884,6 +930,9 @@ namespace etl //*************************************************************************** inline ETL_CONSTEXPR14 uint_least8_t count_bits(uint32_t value) { +#if ETL_CPP20_SUPPORTED && ETL_USING_STL + return std::popcount(value); +#else uint32_t count = 0U; count = value - ((value >> 1U) & 0x55555555UL); @@ -892,7 +941,8 @@ namespace etl count = ((count >> 8U) + count) & 0x00FF00FFUL; count = ((count >> 16U) + count) & 0x0000FFUL; - return static_cast(count);; + return static_cast(count); +#endif } inline ETL_CONSTEXPR14 uint_least8_t count_bits(int32_t value) @@ -907,6 +957,9 @@ namespace etl //*************************************************************************** inline ETL_CONSTEXPR14 uint_least8_t count_bits(uint64_t value) { +#if ETL_CPP20_SUPPORTED && ETL_USING_STL + return std::popcount(value); +#else uint64_t count = 0U; count = value - ((value >> 1U) & 0x5555555555555555ULL); @@ -917,6 +970,7 @@ namespace etl count = ((count >> 32U) + count) & 0x00000000FFFFFFFFULL; return static_cast(count); +#endif } inline ETL_CONSTEXPR14 uint_least8_t count_bits(int64_t value) @@ -1007,6 +1061,9 @@ namespace etl //*************************************************************************** inline ETL_CONSTEXPR14 uint_least8_t count_trailing_zeros(uint8_t value) { +#if ETL_CPP20_SUPPORTED && ETL_USING_STL + return std::countr_zero(value); +#else uint_least8_t count = 0U; if (value & 0x1U) @@ -1039,6 +1096,7 @@ namespace etl } return count; +#endif } inline ETL_CONSTEXPR14 uint_least8_t count_trailing_zeros(int8_t value) @@ -1054,6 +1112,9 @@ namespace etl //*************************************************************************** inline ETL_CONSTEXPR14 uint_least8_t count_trailing_zeros(uint16_t value) { +#if ETL_CPP20_SUPPORTED && ETL_USING_STL + return std::countr_zero(value); +#else uint_least8_t count = 0U; if (value & 0x1U) @@ -1092,6 +1153,7 @@ namespace etl } return count; +#endif } inline ETL_CONSTEXPR14 uint_least8_t count_trailing_zeros(int16_t value) @@ -1106,6 +1168,9 @@ namespace etl //*************************************************************************** inline ETL_CONSTEXPR14 uint_least8_t count_trailing_zeros(uint32_t value) { +#if ETL_CPP20_SUPPORTED && ETL_USING_STL + return std::countr_zero(value); +#else uint_least8_t count = 0U; if (value & 0x1UL) @@ -1150,6 +1215,7 @@ namespace etl } return count; +#endif } inline ETL_CONSTEXPR14 uint_least8_t count_trailing_zeros(int32_t value) @@ -1165,6 +1231,9 @@ namespace etl //*************************************************************************** ETL_CONSTEXPR14 inline uint_least8_t count_trailing_zeros(uint64_t value) { +#if ETL_CPP20_SUPPORTED && ETL_USING_STL + return std::countr_zero(value); +#else uint_least8_t count = 0U; if (value & 0x1ULL) @@ -1215,6 +1284,7 @@ namespace etl } return count; +#endif } inline ETL_CONSTEXPR14 uint_least8_t count_trailing_zeros(int64_t value) @@ -1231,6 +1301,9 @@ namespace etl //*************************************************************************** inline ETL_CONSTEXPR14 uint_least8_t count_trailing_ones(uint8_t value) { +#if ETL_CPP20_SUPPORTED && ETL_USING_STL + return std::countr_one(value); +#else uint_least8_t count = 0U; if ((value & 0x1U) == 0x0U) @@ -1263,6 +1336,7 @@ namespace etl } return count; +#endif } inline ETL_CONSTEXPR14 uint_least8_t count_trailing_ones(int8_t value) @@ -1278,6 +1352,9 @@ namespace etl //*************************************************************************** inline ETL_CONSTEXPR14 uint_least8_t count_trailing_ones(uint16_t value) { +#if ETL_CPP20_SUPPORTED && ETL_USING_STL + return std::countr_one(value); +#else uint_least8_t count = 0U; if ((value & 0x1U) == 0x0U) @@ -1316,6 +1393,7 @@ namespace etl } return count; +#endif } inline ETL_CONSTEXPR14 uint_least8_t count_trailing_ones(int16_t value) @@ -1330,6 +1408,9 @@ namespace etl //*************************************************************************** inline ETL_CONSTEXPR14 uint_least8_t count_trailing_ones(uint32_t value) { +#if ETL_CPP20_SUPPORTED && ETL_USING_STL + return std::countr_one(value); +#else uint_least8_t count = 0U; if ((value & 0x1UL) == 0x0UL) @@ -1374,6 +1455,7 @@ namespace etl } return count; +#endif } inline ETL_CONSTEXPR14 uint_least8_t count_trailing_ones(int32_t value) @@ -1389,6 +1471,9 @@ namespace etl //*************************************************************************** ETL_CONSTEXPR14 inline uint_least8_t count_trailing_ones(uint64_t value) { +#if ETL_CPP20_SUPPORTED && ETL_USING_STL + return std::countr_one(value); +#else uint_least8_t count = 0U; if ((value & 0x1ULL) == 0x0ULL) @@ -1433,6 +1518,7 @@ namespace etl } return count; +#endif } inline ETL_CONSTEXPR14 uint_least8_t count_trailing_ones(int64_t value) @@ -1449,6 +1535,9 @@ namespace etl //*************************************************************************** inline ETL_CONSTEXPR14 uint_least8_t count_leading_zeros(uint8_t value) { +#if ETL_CPP20_SUPPORTED && ETL_USING_STL + return std::countl_zero(value); +#else uint_least8_t count = 0U; if (value & 0x80U) @@ -1481,6 +1570,7 @@ namespace etl } return count; +#endif } inline ETL_CONSTEXPR14 uint_least8_t count_leading_zeros(int8_t value) @@ -1496,6 +1586,9 @@ namespace etl //*************************************************************************** inline ETL_CONSTEXPR14 uint_least8_t count_leading_zeros(uint16_t value) { +#if ETL_CPP20_SUPPORTED && ETL_USING_STL + return std::countl_zero(value); +#else uint_least8_t count = 0U; if (value & 0x8000U) @@ -1534,6 +1627,7 @@ namespace etl } return count; +#endif } inline ETL_CONSTEXPR14 uint_least8_t count_leading_zeros(int16_t value) @@ -1548,6 +1642,9 @@ namespace etl //*************************************************************************** inline ETL_CONSTEXPR14 uint_least8_t count_leading_zeros(uint32_t value) { +#if ETL_CPP20_SUPPORTED && ETL_USING_STL + return std::countl_zero(value); +#else uint_least8_t count = 0U; if (value & 0x80000000UL) @@ -1592,6 +1689,7 @@ namespace etl } return count; +#endif } inline ETL_CONSTEXPR14 uint_least8_t count_leading_zeros(int32_t value) @@ -1607,6 +1705,9 @@ namespace etl //*************************************************************************** inline ETL_CONSTEXPR14 uint_least8_t count_leading_zeros(uint64_t value) { +#if ETL_CPP20_SUPPORTED && ETL_USING_STL + return std::countl_zero(value); +#else uint_least8_t count = 0U; if (value & 0x8000000000000000ULL) @@ -1617,6 +1718,12 @@ namespace etl { count = 1U; + if ((value & 0xFFFFFFFFF0000000ULL) == 0U) + { + value <<= 32U; + count += 32U; + } + if ((value & 0xFFFF000000000000ULL) == 0U) { value <<= 16U; @@ -1651,6 +1758,7 @@ namespace etl } return count; +#endif } inline ETL_CONSTEXPR14 uint_least8_t count_leading_zeros(int64_t value) @@ -1667,6 +1775,9 @@ namespace etl //*************************************************************************** inline ETL_CONSTEXPR14 uint_least8_t count_leading_ones(uint8_t value) { +#if ETL_CPP20_SUPPORTED && ETL_USING_STL + return std::countl_one(value); +#else uint_least8_t count = 0U; if ((value & 0x80U) == 0U) @@ -1699,6 +1810,7 @@ namespace etl } return count; +#endif } inline ETL_CONSTEXPR14 uint_least8_t count_leading_ones(int8_t value) @@ -1714,6 +1826,9 @@ namespace etl //*************************************************************************** inline ETL_CONSTEXPR14 uint_least8_t count_leading_ones(uint16_t value) { +#if ETL_CPP20_SUPPORTED && ETL_USING_STL + return std::countl_one(value); +#else uint_least8_t count = 0U; if ((value & 0x8000U) == 0U) @@ -1752,6 +1867,7 @@ namespace etl } return count; +#endif } inline ETL_CONSTEXPR14 uint_least8_t count_leading_ones(int16_t value) @@ -1766,6 +1882,9 @@ namespace etl //*************************************************************************** inline ETL_CONSTEXPR14 uint_least8_t count_leading_ones(uint32_t value) { +#if ETL_CPP20_SUPPORTED && ETL_USING_STL + return std::countl_one(value); +#else uint_least8_t count = 0U; if ((value & 0x80000000UL) == 0UL) @@ -1810,6 +1929,7 @@ namespace etl } return count; +#endif } inline ETL_CONSTEXPR14 uint_least8_t count_leading_ones(int32_t value) @@ -1825,6 +1945,9 @@ namespace etl //*************************************************************************** inline ETL_CONSTEXPR14 uint_least8_t count_leading_ones(uint64_t value) { +#if ETL_CPP20_SUPPORTED && ETL_USING_STL + return std::countl_one(value); +#else uint_least8_t count = 0U; if ((value & 0x8000000000000000ULL) == 0ULL) @@ -1875,6 +1998,7 @@ namespace etl } return count; +#endif } inline ETL_CONSTEXPR14 uint_least8_t count_leading_ones(int64_t value) diff --git a/include/etl/bit.h b/include/etl/bit.h index d62047ac..eea7510c 100644 --- a/include/etl/bit.h +++ b/include/etl/bit.h @@ -38,6 +38,11 @@ SOFTWARE. #include "binary.h" #include "integral_limits.h" #include "endianness.h" +#include "type_traits.h" + +#if ETL_CPP20_SUPPORTED && ETL_USING_STL + #include +#endif namespace etl { @@ -45,6 +50,7 @@ namespace etl /// bit_cast //*************************************************************************** template + ETL_CONSTEXPR14 typename etl::enable_if<(sizeof(TDestination) == sizeof(TSource)) && etl::is_trivially_copyable::value && etl::is_trivially_copyable::value, TDestination>::type @@ -52,25 +58,18 @@ namespace etl { TDestination destination; - memcpy(&destination, &source, sizeof(TDestination)); + const char* s = &source; + char* d = &destination; + char* const de = d + sizeof(TDestination); + + while (d != de) + { + *d++ = *s++; + } return destination; } - //template - //ETL_CONSTEXPR14 - //typename etl::enable_if<(sizeof(TDestination) == sizeof(TSource)) && - // etl::is_trivially_copyable::value && - // etl::is_trivially_copyable::value, TDestination>::type - // bit_cast(const TSource& source) ETL_NOEXCEPT - //{ - // TDestination destination; - // - // __builtin_memcpy(&destination, &source, sizeof(TDestination)); - // - // return destination; - //} - //*************************************************************************** /// byteswap //*************************************************************************** @@ -92,6 +91,21 @@ namespace etl return (value & (value - 1)) == 0; } + //*************************************************************************** + /// bit_width + //*************************************************************************** + template + ETL_CONSTEXPR14 + typename etl::enable_if::value, T>::type + bit_width(T value) ETL_NOEXCEPT + { +#if ETL_CPP20_SUPPORTED && ETL_USING_STL + return std::bit_width(value); +#else + return etl::integral_limits::bits - etl::countl_zero(value); +#endif + } + //*************************************************************************** /// bit_ceil //*************************************************************************** @@ -100,7 +114,18 @@ namespace etl typename etl::enable_if::value, T>::type bit_ceil(T value) { - return 1; +#if ETL_CPP20_SUPPORTED && ETL_USING_STL + return std::bit_ceil(value); +#else + if (value == T(0)) + { + return T(1); + } + else + { + return T(1) << etl::bit_width(T(value - T(1))); + } +#endif } //*************************************************************************** @@ -111,18 +136,18 @@ namespace etl typename etl::enable_if::value, T>::type bit_floor(T value) ETL_NOEXCEPT { - return 1; - } - - //*************************************************************************** - /// bit_width - //*************************************************************************** - template - ETL_CONSTEXPR14 - typename etl::enable_if::value, T>::type - bit_width(T value) ETL_NOEXCEPT - { - return 1; +#if ETL_CPP20_SUPPORTED && ETL_USING_STL + return std::bit_floor(value); +#else + if (value == T(0)) + { + return T(0); + } + else + { + return T(1) << (etl::bit_width(value) - T(1)); + } +#endif } //*************************************************************************** @@ -131,17 +156,17 @@ namespace etl template ETL_NODISCARD ETL_CONSTEXPR14 typename etl::enable_if::value, T>::type - rotl(T value, int s) ETL_NOEXCEPT + rotl(T value, int n) ETL_NOEXCEPT { ETL_CONSTANT size_t N = etl::integral_limits::bits; - if (s < 0) + if (n < 0) { - return etl::rotate_right(value, -s); + return etl::rotate_right(value, -n); } else { - return etl::rotate_left(value, s); + return etl::rotate_left(value, n); } } @@ -151,17 +176,17 @@ namespace etl template ETL_NODISCARD ETL_CONSTEXPR14 typename etl::enable_if::value, T>::type - rotr(T value, int s) ETL_NOEXCEPT + rotr(T value, int n) ETL_NOEXCEPT { ETL_CONSTANT size_t N = etl::integral_limits::bits; - if (s < 0) + if (n < 0) { - return etl::rotate_left(value, -s); + return etl::rotate_left(value, -n); } else { - return etl::rotate_right(value, s); + return etl::rotate_right(value, n); } } @@ -173,7 +198,7 @@ namespace etl typename etl::enable_if::value, int>::type countl_zero(T value) ETL_NOEXCEPT { - return 1; + return etl::count_leading_zeros(value); } //*************************************************************************** @@ -184,7 +209,7 @@ namespace etl typename etl::enable_if::value, int>::type countl_one(T value) ETL_NOEXCEPT { - return 1; + return etl::count_leading_ones(value); } //*************************************************************************** @@ -206,7 +231,7 @@ namespace etl typename etl::enable_if::value, int>::type countr_one(T value) ETL_NOEXCEPT { - return 1; + return etl::count_trailing_ones(value);; } //*************************************************************************** diff --git a/include/etl/endianness.h b/include/etl/endianness.h index 14b48b8c..f2c5479a 100644 --- a/include/etl/endianness.h +++ b/include/etl/endianness.h @@ -45,6 +45,38 @@ SOFTWARE. /// Constants & utilities for endianess ///\ingroup utilities +#if !((!defined(ETL_ENDIAN_LITTLE) && !defined(ETL_ENDIAN_BIG) && !defined(ETL_ENDIAN_NATIVE)) || ((defined(ETL_ENDIAN_LITTLE) && defined(ETL_ENDIAN_BIG) && defined(ETL_ENDIAN_NATIVE)))) + #error All three of ETL_ENDIAN_LITTLE, ETL_ENDIAN_BIG and ETL_ENDIAN_NATIVE must be defined +#endif + +// Have we not already defined all of the macros? +#if !defined(ETL_ENDIAN_LITTLE) || !defined(ETL_ENDIAN_BIG) || !defined(ETL_ENDIAN_NATIVE) + #undef ETL_ENDIAN_LITTLE + #undef ETL_ENDIAN_BIG + #undef ETL_ENDIAN_NATIVE + // Can we use the C++20 definitions? + #if ETL_CPP20_SUPPORTED && ETL_USING_STL + #define ETL_ENDIAN_LITTLE std::endian::little + #define ETL_ENDIAN_BIG std::endian::big + #define ETL_ENDIAN_NATIVE std::endian::native + // If not can we use the compiler macros? + #elif defined(__BYTE_ORDER__) + // Test the two versions of the macro we are likely to see. + #if defined(__ORDER_LITTLE_ENDIAN__) + #define ETL_ENDIAN_LITTLE __ORDER_LITTLE_ENDIAN__ + #define ETL_ENDIAN_BIG __ORDER_BIG_ENDIAN__ + #define ETL_ENDIAN_NATIVE __BYTE_ORDER__ + #elif defined(__LITTLE_ENDIAN__) + #define ETL_ENDIAN_LITTLE __LITTLE_ENDIAN__ + #define ETL_ENDIAN_BIG __BIG_ENDIAN__ + #define ETL_ENDIAN_NATIVE __BYTE_ORDER__ + #endif + #endif +#endif + +// If true, then the endianness of the platform can be constexpr. +#define ETL_ENDIANNESS_IS_CONSTEXPR (ETL_CPP11_SUPPORTED && defined(ETL_ENDIAN_NATIVE)) + namespace etl { //*************************************************************************** @@ -53,41 +85,28 @@ namespace etl //*************************************************************************** struct endian { -#if ETL_CPP20_SUPPORTED && ETL_USING_STL +#if defined(ETL_ENDIAN_NATIVE) enum enum_type { - little = static_cast(std::endian::little), - big = static_cast(std::endian::big), - native = static_cast(std::endian::native) - }; -#elif defined(__BYTE_ORDER__) - #if defined(__ORDER_LITTLE_ENDIAN__) - #defined ETL_LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__ - #defined ETL_BIG_ENDIAN __ORDER_BIG_ENDIAN__ - #elif defined(__LITTLE_ENDIAN__) - #defined ETL_LITTLE_ENDIAN __LITTLE_ENDIAN__ - #defined ETL_BIG_ENDIAN __BIG_ENDIAN__ - #endif - - enum enum_type - { - little = ETL_LITTLE_ENDIAN, - big = ETL_BIG_ENDIAN, - native = __BYTE_ORDER__ + little = static_cast(ETL_ENDIAN_LITTLE), + big = static_cast(ETL_ENDIAN_BIG), + native = static_cast(ETL_ENDIAN_NATIVE), + unknown = INT_MAX }; #else enum enum_type { little, big, - native + native, + unknown = native }; #endif ETL_DECLARE_ENUM_TYPE(endian, int) - ETL_ENUM_TYPE(little, "little") - ETL_ENUM_TYPE(big, "big") - ETL_ENUM_TYPE(native, "native") + ETL_ENUM_TYPE(little, "little") + ETL_ENUM_TYPE(big, "big") + ETL_ENUM_TYPE(unknown, "unknown") ETL_END_ENUM_TYPE }; @@ -102,11 +121,17 @@ namespace etl return etl::endian(*this); } +#if ETL_ENDIANNESS_IS_CONSTEXPR + ETL_CONSTEXPR +#endif operator etl::endian() const { return get(); } +#if ETL_ENDIANNESS_IS_CONSTEXPR + ETL_CONSTEXPR +#endif static etl::endian value() { return get(); @@ -114,21 +139,19 @@ namespace etl private: +#if ETL_ENDIANNESS_IS_CONSTEXPR + ETL_CONSTEXPR static etl::endian get() + { + return etl::endian::native; + } +#else static etl::endian get() { - static const union U - { - U() - : ui32(0x12345678UL) - { - } + static const uint32_t i = 0xFFFF0000; - uint32_t ui32; - uint16_t ui16[2]; - } u; - - return (u.ui16[0] == 0x5678U) ? etl::endian::little : etl::endian::big; + return (*reinterpret_cast(&i) == 0) ? etl::endian::little : etl::endian::big; } +#endif }; //*************************************************************************** diff --git a/include/etl/private/minmax_pop.h b/include/etl/private/minmax_pop.h index e25d0a93..be65d9c1 100644 --- a/include/etl/private/minmax_pop.h +++ b/include/etl/private/minmax_pop.h @@ -32,11 +32,13 @@ SOFTWARE. * The header include guard has been intentionally omitted. * This file is intended to evaluated multiple times by design. */ -#if !defined(ETL_COMPILER_ARM5) && !defined(ETL_COMPILER_GREEN_HILLS) - #pragma pop_macro("min") - #pragma pop_macro("max") -#else - #define min(a,b) ((a)<(b)?(a):(b)) - #define max(a,b) ((a)<(b)?(b):(a)) +#if !defined(ETL_COMPILER_GREEN_HILLS) + #if !defined(ETL_COMPILER_ARM5) + #pragma pop_macro("min") + #pragma pop_macro("max") + #else + #define min(a,b) ((a)<(b)?(a):(b)) + #define max(a,b) ((a)<(b)?(b):(a)) + #endif #endif diff --git a/include/etl/private/minmax_push.h b/include/etl/private/minmax_push.h index ef71439c..75dc34a4 100644 --- a/include/etl/private/minmax_push.h +++ b/include/etl/private/minmax_push.h @@ -32,10 +32,13 @@ SOFTWARE. * The header include guard has been intentionally omitted. * This file is intended to evaluated multiple times by design. */ -#if !defined(ETL_COMPILER_ARM5) && !defined(ETL_COMPILER_GREEN_HILLS) - #pragma push_macro("min") - #pragma push_macro("max") -#endif -#undef min -#undef max +#if !defined(ETL_COMPILER_GREEN_HILLS) + #if !defined(ETL_COMPILER_ARM5) + #pragma push_macro("min") + #pragma push_macro("max") + #endif + + #undef min + #undef max +#endif diff --git a/test/test_binary.cpp b/test/test_binary.cpp index 8a2f2f1d..4741f46a 100644 --- a/test/test_binary.cpp +++ b/test/test_binary.cpp @@ -811,7 +811,7 @@ namespace //************************************************************************* TEST(test_binary_to_gray32) { - etl::fnv_1a_32 hash; + etl::fnv_1_32 hash; hash.add(1); @@ -1233,139 +1233,143 @@ namespace //************************************************************************* TEST(test_max_value_for_bits) { - // Check that the values are correct. - //CHECK_EQUAL(0U, etl::max_value_for_nbits<0>::value); - CHECK_EQUAL(1U, etl::max_value_for_nbits<1>::value); - CHECK_EQUAL(3U, etl::max_value_for_nbits<2>::value); - CHECK_EQUAL(7U, etl::max_value_for_nbits<3>::value); - CHECK_EQUAL(15U, etl::max_value_for_nbits<4>::value); - CHECK_EQUAL(31U, etl::max_value_for_nbits<5>::value); - CHECK_EQUAL(63U, etl::max_value_for_nbits<6>::value); - CHECK_EQUAL(127U, etl::max_value_for_nbits<7>::value); - CHECK_EQUAL(255U, etl::max_value_for_nbits<8>::value); - CHECK_EQUAL(511U, etl::max_value_for_nbits<9>::value); - CHECK_EQUAL(1023U, etl::max_value_for_nbits<10>::value); - CHECK_EQUAL(2047U, etl::max_value_for_nbits<11>::value); - CHECK_EQUAL(4095U, etl::max_value_for_nbits<12>::value); - CHECK_EQUAL(8191U, etl::max_value_for_nbits<13>::value); - CHECK_EQUAL(16383U, etl::max_value_for_nbits<14>::value); - CHECK_EQUAL(32767U, etl::max_value_for_nbits<15>::value); - CHECK_EQUAL(65535U, etl::max_value_for_nbits<16>::value); - CHECK_EQUAL(131071UL, etl::max_value_for_nbits<17>::value); - CHECK_EQUAL(262143UL, etl::max_value_for_nbits<18>::value); - CHECK_EQUAL(524287UL, etl::max_value_for_nbits<19>::value); - CHECK_EQUAL(1048575UL, etl::max_value_for_nbits<20>::value); - CHECK_EQUAL(2097151UL, etl::max_value_for_nbits<21>::value); - CHECK_EQUAL(4194303UL, etl::max_value_for_nbits<22>::value); - CHECK_EQUAL(8388607UL, etl::max_value_for_nbits<23>::value); - CHECK_EQUAL(16777215UL, etl::max_value_for_nbits<24>::value); - CHECK_EQUAL(33554431UL, etl::max_value_for_nbits<25>::value); - CHECK_EQUAL(67108863UL, etl::max_value_for_nbits<26>::value); - CHECK_EQUAL(134217727UL, etl::max_value_for_nbits<27>::value); - CHECK_EQUAL(268435455UL, etl::max_value_for_nbits<28>::value); - CHECK_EQUAL(536870911UL, etl::max_value_for_nbits<29>::value); - CHECK_EQUAL(1073741823UL, etl::max_value_for_nbits<30>::value); - CHECK_EQUAL(2147483647UL, etl::max_value_for_nbits<31>::value); - CHECK_EQUAL(4294967295UL, etl::max_value_for_nbits<32>::value); - CHECK_EQUAL(8589934591ULL, etl::max_value_for_nbits<33>::value); - CHECK_EQUAL(17179869183ULL, etl::max_value_for_nbits<34>::value); - CHECK_EQUAL(34359738367ULL, etl::max_value_for_nbits<35>::value); - CHECK_EQUAL(68719476735ULL, etl::max_value_for_nbits<36>::value); - CHECK_EQUAL(137438953471ULL, etl::max_value_for_nbits<37>::value); - CHECK_EQUAL(274877906943ULL, etl::max_value_for_nbits<38>::value); - CHECK_EQUAL(549755813887ULL, etl::max_value_for_nbits<39>::value); - CHECK_EQUAL(1099511627775ULL, etl::max_value_for_nbits<40>::value); - CHECK_EQUAL(2199023255551ULL, etl::max_value_for_nbits<41>::value); - CHECK_EQUAL(4398046511103ULL, etl::max_value_for_nbits<42>::value); - CHECK_EQUAL(8796093022207ULL, etl::max_value_for_nbits<43>::value); - CHECK_EQUAL(17592186044415ULL, etl::max_value_for_nbits<44>::value); - CHECK_EQUAL(35184372088831ULL, etl::max_value_for_nbits<45>::value); - CHECK_EQUAL(70368744177663ULL, etl::max_value_for_nbits<46>::value); - CHECK_EQUAL(140737488355327ULL, etl::max_value_for_nbits<47>::value); - CHECK_EQUAL(281474976710655ULL, etl::max_value_for_nbits<48>::value); - CHECK_EQUAL(562949953421311ULL, etl::max_value_for_nbits<49>::value); - CHECK_EQUAL(1125899906842623ULL, etl::max_value_for_nbits<50>::value); - CHECK_EQUAL(2251799813685247ULL, etl::max_value_for_nbits<51>::value); - CHECK_EQUAL(4503599627370495ULL, etl::max_value_for_nbits<52>::value); - CHECK_EQUAL(9007199254740991ULL, etl::max_value_for_nbits<53>::value); - CHECK_EQUAL(18014398509481983ULL, etl::max_value_for_nbits<54>::value); - CHECK_EQUAL(36028797018963967ULL, etl::max_value_for_nbits<55>::value); - CHECK_EQUAL(72057594037927935ULL, etl::max_value_for_nbits<56>::value); - CHECK_EQUAL(144115188075855871ULL, etl::max_value_for_nbits<57>::value); - CHECK_EQUAL(288230376151711743ULL, etl::max_value_for_nbits<58>::value); - CHECK_EQUAL(576460752303423487ULL, etl::max_value_for_nbits<59>::value); - CHECK_EQUAL(1152921504606846975ULL, etl::max_value_for_nbits<60>::value); - CHECK_EQUAL(2305843009213693951ULL, etl::max_value_for_nbits<61>::value); - CHECK_EQUAL(4611686018427387903ULL, etl::max_value_for_nbits<62>::value); - CHECK_EQUAL(9223372036854775807ULL, etl::max_value_for_nbits<63>::value); - CHECK_EQUAL(18446744073709551615ULL, etl::max_value_for_nbits<64>::value); + // Check that the values are correct. + //CHECK_EQUAL(0U, etl::max_value_for_nbits<0>::value); + CHECK_EQUAL(1U, etl::max_value_for_nbits<1>::value); + CHECK_EQUAL(3U, etl::max_value_for_nbits<2>::value); + CHECK_EQUAL(7U, etl::max_value_for_nbits<3>::value); + CHECK_EQUAL(15U, etl::max_value_for_nbits<4>::value); + CHECK_EQUAL(31U, etl::max_value_for_nbits<5>::value); + CHECK_EQUAL(63U, etl::max_value_for_nbits<6>::value); + CHECK_EQUAL(127U, etl::max_value_for_nbits<7>::value); + CHECK_EQUAL(255U, etl::max_value_for_nbits<8>::value); + CHECK_EQUAL(511U, etl::max_value_for_nbits<9>::value); + CHECK_EQUAL(1023U, etl::max_value_for_nbits<10>::value); + CHECK_EQUAL(2047U, etl::max_value_for_nbits<11>::value); + CHECK_EQUAL(4095U, etl::max_value_for_nbits<12>::value); + CHECK_EQUAL(8191U, etl::max_value_for_nbits<13>::value); + CHECK_EQUAL(16383U, etl::max_value_for_nbits<14>::value); + CHECK_EQUAL(32767U, etl::max_value_for_nbits<15>::value); + CHECK_EQUAL(65535U, etl::max_value_for_nbits<16>::value); + CHECK_EQUAL(131071UL, etl::max_value_for_nbits<17>::value); + CHECK_EQUAL(262143UL, etl::max_value_for_nbits<18>::value); + CHECK_EQUAL(524287UL, etl::max_value_for_nbits<19>::value); + CHECK_EQUAL(1048575UL, etl::max_value_for_nbits<20>::value); + CHECK_EQUAL(2097151UL, etl::max_value_for_nbits<21>::value); + CHECK_EQUAL(4194303UL, etl::max_value_for_nbits<22>::value); + CHECK_EQUAL(8388607UL, etl::max_value_for_nbits<23>::value); + CHECK_EQUAL(16777215UL, etl::max_value_for_nbits<24>::value); + CHECK_EQUAL(33554431UL, etl::max_value_for_nbits<25>::value); + CHECK_EQUAL(67108863UL, etl::max_value_for_nbits<26>::value); + CHECK_EQUAL(134217727UL, etl::max_value_for_nbits<27>::value); + CHECK_EQUAL(268435455UL, etl::max_value_for_nbits<28>::value); + CHECK_EQUAL(536870911UL, etl::max_value_for_nbits<29>::value); + CHECK_EQUAL(1073741823UL, etl::max_value_for_nbits<30>::value); + CHECK_EQUAL(2147483647UL, etl::max_value_for_nbits<31>::value); + CHECK_EQUAL(4294967295UL, etl::max_value_for_nbits<32>::value); + CHECK_EQUAL(8589934591ULL, etl::max_value_for_nbits<33>::value); + CHECK_EQUAL(17179869183ULL, etl::max_value_for_nbits<34>::value); + CHECK_EQUAL(34359738367ULL, etl::max_value_for_nbits<35>::value); + CHECK_EQUAL(68719476735ULL, etl::max_value_for_nbits<36>::value); + CHECK_EQUAL(137438953471ULL, etl::max_value_for_nbits<37>::value); + CHECK_EQUAL(274877906943ULL, etl::max_value_for_nbits<38>::value); + CHECK_EQUAL(549755813887ULL, etl::max_value_for_nbits<39>::value); + CHECK_EQUAL(1099511627775ULL, etl::max_value_for_nbits<40>::value); + CHECK_EQUAL(2199023255551ULL, etl::max_value_for_nbits<41>::value); + CHECK_EQUAL(4398046511103ULL, etl::max_value_for_nbits<42>::value); + CHECK_EQUAL(8796093022207ULL, etl::max_value_for_nbits<43>::value); + CHECK_EQUAL(17592186044415ULL, etl::max_value_for_nbits<44>::value); + CHECK_EQUAL(35184372088831ULL, etl::max_value_for_nbits<45>::value); + CHECK_EQUAL(70368744177663ULL, etl::max_value_for_nbits<46>::value); + CHECK_EQUAL(140737488355327ULL, etl::max_value_for_nbits<47>::value); + CHECK_EQUAL(281474976710655ULL, etl::max_value_for_nbits<48>::value); + CHECK_EQUAL(562949953421311ULL, etl::max_value_for_nbits<49>::value); + CHECK_EQUAL(1125899906842623ULL, etl::max_value_for_nbits<50>::value); + CHECK_EQUAL(2251799813685247ULL, etl::max_value_for_nbits<51>::value); + CHECK_EQUAL(4503599627370495ULL, etl::max_value_for_nbits<52>::value); + CHECK_EQUAL(9007199254740991ULL, etl::max_value_for_nbits<53>::value); + CHECK_EQUAL(18014398509481983ULL, etl::max_value_for_nbits<54>::value); + CHECK_EQUAL(36028797018963967ULL, etl::max_value_for_nbits<55>::value); + CHECK_EQUAL(72057594037927935ULL, etl::max_value_for_nbits<56>::value); + CHECK_EQUAL(144115188075855871ULL, etl::max_value_for_nbits<57>::value); + CHECK_EQUAL(288230376151711743ULL, etl::max_value_for_nbits<58>::value); + CHECK_EQUAL(576460752303423487ULL, etl::max_value_for_nbits<59>::value); + CHECK_EQUAL(1152921504606846975ULL, etl::max_value_for_nbits<60>::value); + CHECK_EQUAL(2305843009213693951ULL, etl::max_value_for_nbits<61>::value); + CHECK_EQUAL(4611686018427387903ULL, etl::max_value_for_nbits<62>::value); + CHECK_EQUAL(9223372036854775807ULL, etl::max_value_for_nbits<63>::value); + CHECK_EQUAL(18446744073709551615ULL, etl::max_value_for_nbits<64>::value); + } - // Check that the value types are correct. - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); - CHECK((etl::is_same::value_type>::value)); + //************************************************************************* + TEST(test_max_value_for_bits_types) + { + // Check that the value types are correct. + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); + CHECK((etl::is_same::value_type>::value)); } //************************************************************************* diff --git a/test/test_bit.cpp b/test/test_bit.cpp index c40ca37f..7be8d51d 100644 --- a/test/test_bit.cpp +++ b/test/test_bit.cpp @@ -30,11 +30,13 @@ SOFTWARE. #include +#include "etl/binary.h" #include "etl/bit.h" #include "etl/fnv_1.h" namespace { + //*********************************** // Count bits the long way. template size_t test_count(T value) @@ -52,7 +54,8 @@ namespace return count; } - // Count trailing zero the long way. + //*********************************** + // Count trailing zeros the long way. template size_t test_trailing_zeros(T value) { @@ -75,6 +78,16 @@ namespace return count; } + //*********************************** + // Count leading zeros the long way. + template + size_t test_leading_zeros(T value) + { + value = etl::reverse_bits(value); + return test_trailing_zeros(value); + } + + //*********************************** // Count trailing ones the long way. template size_t test_trailing_ones(T value) @@ -87,6 +100,10 @@ namespace { ++count; } + else + { + return count; + } value >>= 1; } @@ -94,6 +111,16 @@ namespace return count; } + //*********************************** + // Count leading ones the long way. + template + size_t test_leading_ones(T value) + { + value = etl::reverse_bits(value); + return test_trailing_ones(value); + } + + //*********************************** // Check parity the long way. template size_t test_parity(T value) @@ -103,6 +130,7 @@ namespace return count & 1; } + //*********************************** // Power of 2. uint64_t test_power_of_2(int power) { @@ -116,10 +144,73 @@ namespace return result; } + //*********************************** + // Count the bit width the long way. + template + T test_bit_width(T value) + { + value = etl::reverse_bits(value); + + size_t width = 0U; + + for (int i = 0; i < etl::integral_limits::bits; ++i) + { + if ((value & T(T(1) << i)) == 0) + { + ++width; + } + else + { + break; + } + } + + return T(etl::integral_limits::bits - width); + } + + //*********************************** + // Count the bit ceil the long way. + template + T test_bit_ceil(T value) + { + T ceil; + + if (value == T(0)) + { + ceil = T(1); + } + else + { + ceil = T(1) << test_bit_width(T(value - T(1))); + } + + return ceil; + } + + //*********************************** + // Count the bit floor the long way. + template + T test_bit_floor(T value) + { + if (value == 0) + { + return 0; + } + + T floor = T(T(1) << (etl::integral_limits::bits - T(1))); + + for (int i = etl::integral_limits::bits - 1U; (i > 0) && (floor > value); ++i) + { + floor >>= 1; + } + + return floor; + } + SUITE(test_bit) { //************************************************************************* - TEST(test_rotl8) + TEST(test_rotl_8) { uint8_t value; @@ -178,7 +269,7 @@ namespace #if !defined(ETL_FORCE_NO_ADVANCED_CPP) //************************************************************************* - TEST(test_rotl8_constexpr) + TEST(test_rotl_8_constexpr) { char temp[etl::rotl(uint8_t(0xAAU), 1)]; @@ -187,7 +278,7 @@ namespace #endif //************************************************************************* - TEST(test_rotl16) + TEST(test_rotl_16) { uint16_t value; @@ -282,7 +373,7 @@ namespace #if !defined(ETL_FORCE_NO_ADVANCED_CPP) //************************************************************************* - TEST(test_rotl16_constexpr) + TEST(test_rotl_16_constexpr) { char temp[etl::rotl(uint16_t(0xAAU), 1)]; @@ -291,174 +382,174 @@ namespace #endif //************************************************************************* - TEST(test_rotate_right8) + TEST(test_test_rotr_8) { uint8_t value; value = 0x00U; - value = etl::rotate_right(value); + value = etl::rotr(value, 1); CHECK_EQUAL(0, int(value)); value = 0x21U; - value = etl::rotate_right(value); + value = etl::rotr(value, 1); CHECK_EQUAL(0x90U, int(value)); value = 0x42U; - value = etl::rotate_right(value); + value = etl::rotr(value, 1); CHECK_EQUAL(0x21U, int(value)); value = 0x84U; - value = etl::rotate_right(value); + value = etl::rotr(value, 1); CHECK_EQUAL(0x42U, int(value)); value = 0xB7U; - value = etl::rotate_right(value, 2); + value = etl::rotr(value, 2); CHECK_EQUAL(0xEDU, int(value)); value = 0xB7U; - value = etl::rotate_right(value, 3); + value = etl::rotr(value, 3); CHECK_EQUAL(0xF6U, int(value)); value = 0xB7U; - value = etl::rotate_right(value, 4); + value = etl::rotr(value, 4); CHECK_EQUAL(0x7BU, int(value)); value = 0xB7U; - value = etl::rotate_right(value, 5); + value = etl::rotr(value, 5); CHECK_EQUAL(0xBDU, int(value)); value = 0xB7U; - value = etl::rotate_right(value, 6); + value = etl::rotr(value, 6); CHECK_EQUAL(0xDEU, int(value)); value = 0xB7U; - value = etl::rotate_right(value, 7); + value = etl::rotr(value, 7); CHECK_EQUAL(0x6FU, int(value)); value = 0xB7U; - value = etl::rotate_right(value, 8); + value = etl::rotr(value, 8); CHECK_EQUAL(0xB7U, int(value)); value = 0xB7U; - value = etl::rotate_right(value, 9); + value = etl::rotr(value, 9); CHECK_EQUAL(0xDBU, int(value)); value = 0xB7U; - value = etl::rotate_right(value, -1); + value = etl::rotr(value, -1); CHECK_EQUAL(0x6FU, int(value)); } #if !defined(ETL_FORCE_NO_ADVANCED_CPP) //************************************************************************* - TEST(test_rotate_right8_constexpr) + TEST(test_rotr_8_constexpr) { - char temp[etl::rotate_right(uint8_t(0xAAU))]; + char temp[etl::rotr(uint8_t(0xAAU), 1)]; - CHECK_EQUAL(etl::rotate_right(uint8_t(0xAAU)), sizeof(temp)); + CHECK_EQUAL(etl::rotr(uint8_t(0xAAU), 1), sizeof(temp)); } #endif //************************************************************************* - TEST(test_rotate_right16) + TEST(test_rotr_16) { uint16_t value; value = 0x0000U; - value = etl::rotate_right(value); + value = etl::rotr(value, 1); CHECK_EQUAL(0, value); value = 0x8421U; - value = etl::rotate_right(value); + value = etl::rotr(value, 1); CHECK_EQUAL(0xC210U, value); value = 0xC210U; - value = etl::rotate_right(value); + value = etl::rotr(value, 1); CHECK_EQUAL(0x6108U, value); value = 0x6108U; - value = etl::rotate_right(value); + value = etl::rotr(value, 1); CHECK_EQUAL(0x3084U, value); value = 0xB73CU; - value = etl::rotate_right(value, 2); + value = etl::rotr(value, 2); CHECK_EQUAL(0x2DCFU, int(value)); value = 0xB73CU; - value = etl::rotate_right(value, 3); + value = etl::rotr(value, 3); CHECK_EQUAL(0x96E7U, int(value)); value = 0xB73CU; - value = etl::rotate_right(value, 4); + value = etl::rotr(value, 4); CHECK_EQUAL(0xCB73U, int(value)); value = 0xB73CU; - value = etl::rotate_right(value, 5); + value = etl::rotr(value, 5); CHECK_EQUAL(0xE5B9U, int(value)); value = 0xB73CU; - value = etl::rotate_right(value, 6); + value = etl::rotr(value, 6); CHECK_EQUAL(0xF2DCU, int(value)); value = 0xB73CU; - value = etl::rotate_right(value, 7); + value = etl::rotr(value, 7); CHECK_EQUAL(0x796EU, int(value)); value = 0xB73CU; - value = etl::rotate_right(value, 8); + value = etl::rotr(value, 8); CHECK_EQUAL(0x3CB7U, int(value)); value = 0xB73CU; - value = etl::rotate_right(value, 9); + value = etl::rotr(value, 9); CHECK_EQUAL(0x9E5BU, int(value)); value = 0xB73CU; - value = etl::rotate_right(value, 9); + value = etl::rotr(value, 9); CHECK_EQUAL(0x9E5BU, int(value)); value = 0xB73CU; - value = etl::rotate_right(value, 10); + value = etl::rotr(value, 10); CHECK_EQUAL(0xCF2DU, int(value)); value = 0xB73CU; - value = etl::rotate_right(value, 11); + value = etl::rotr(value, 11); CHECK_EQUAL(0xE796U, int(value)); value = 0xB73CU; - value = etl::rotate_right(value, 12); + value = etl::rotr(value, 12); CHECK_EQUAL(0x73CBU, int(value)); value = 0xB73CU; - value = etl::rotate_right(value, 13); + value = etl::rotr(value, 13); CHECK_EQUAL(0xB9E5U, int(value)); value = 0xB73CU; - value = etl::rotate_right(value, 14); + value = etl::rotr(value, 14); CHECK_EQUAL(0xDCF2U, int(value)); value = 0xB73CU; - value = etl::rotate_right(value, 15); + value = etl::rotr(value, 15); CHECK_EQUAL(0x6E79U, int(value)); value = 0xB73CU; - value = etl::rotate_right(value, 16); + value = etl::rotr(value, 16); CHECK_EQUAL(0xB73CU, int(value)); value = 0xB73CU; - value = etl::rotate_right(value, 17); + value = etl::rotr(value, 17); CHECK_EQUAL(0x5B9EU, int(value)); value = 0xB73CU; - value = etl::rotate_right(value, -1); + value = etl::rotr(value, -1); CHECK_EQUAL(0x6E79U, int(value)); } #if !defined(ETL_FORCE_NO_ADVANCED_CPP) //************************************************************************* - TEST(test_rotate_right16_constexpr) + TEST(test_rotr_16_constexpr) { - char temp[etl::rotate_right(uint16_t(0xAAU))]; + char temp[etl::rotr(uint16_t(0xAAU), 1)]; - CHECK_EQUAL(etl::rotate_right(uint16_t(0xAAU)), sizeof(temp)); + CHECK_EQUAL(etl::rotr(uint16_t(0xAAU), 1), sizeof(temp)); } #endif @@ -490,7 +581,7 @@ namespace #endif //************************************************************************* - TEST(test_reverse_bytes16) + TEST(test_byteswap_16) { uint16_t value; @@ -509,7 +600,7 @@ namespace #if !defined(ETL_FORCE_NO_ADVANCED_CPP) //************************************************************************* - TEST(test_reverse_bytes16_constexpr) + TEST(test_byteswap_16_constexpr) { char temp[etl::byteswap(uint16_t(0xA500U))]; @@ -518,7 +609,7 @@ namespace #endif //************************************************************************* - TEST(test_reverse_bytes32) + TEST(test_byteswap_32) { uint32_t value; @@ -537,7 +628,7 @@ namespace #if !defined(ETL_FORCE_NO_ADVANCED_CPP) //************************************************************************* - TEST(test_reverse_bytes32_constexpr) + TEST(test_byteswap_32_constexpr) { char temp[etl::byteswap(uint32_t(0xA5000000UL))]; @@ -546,7 +637,7 @@ namespace #endif //************************************************************************* - TEST(test_reverse_bytes64) + TEST(test_byteswap_64) { uint64_t value; @@ -565,7 +656,7 @@ namespace #if !defined(ETL_FORCE_NO_ADVANCED_CPP) //************************************************************************* - TEST(test_reverse_bytes64_constexpr) + TEST(test_byteswap_64_constexpr) { char temp[etl::byteswap(uint64_t(0xA500000000000000ULL))]; @@ -574,7 +665,7 @@ namespace #endif //************************************************************************* - TEST(test_count_bits_8) + TEST(test_popcount_8) { for (size_t i = 1UL; i <= std::numeric_limits::max(); ++i) { @@ -584,7 +675,7 @@ namespace #if !defined(ETL_FORCE_NO_ADVANCED_CPP) //************************************************************************* - TEST(test_count_bits_8_constexpr) + TEST(test_popcount_8_constexpr) { char temp[etl::popcount(uint8_t(0xFFU))]; @@ -593,7 +684,7 @@ namespace #endif //************************************************************************* - TEST(test_count_bits_16) + TEST(test_popcount_16) { for (size_t i = 1UL; i <= std::numeric_limits::max(); ++i) { @@ -603,7 +694,7 @@ namespace #if !defined(ETL_FORCE_NO_ADVANCED_CPP) //************************************************************************* - TEST(test_count_bits_16_constexpr) + TEST(test_popcount_16_constexpr) { char temp[etl::popcount(uint16_t(0xFFU))]; @@ -612,7 +703,7 @@ namespace #endif //************************************************************************* - TEST(test_count_bits_32) + TEST(test_popcount_32) { etl::fnv_1a_32 hash; @@ -628,7 +719,7 @@ namespace #if !defined(ETL_FORCE_NO_ADVANCED_CPP) //************************************************************************* - TEST(test_count_bits_32_constexpr) + TEST(test_popcount_32_constexpr) { char temp[etl::popcount(uint32_t(0xFFU))]; @@ -637,7 +728,7 @@ namespace #endif //************************************************************************* - TEST(test_count_bits_64) + TEST(test_popcount_64) { etl::fnv_1a_64 hash; @@ -653,7 +744,7 @@ namespace #if !defined(ETL_FORCE_NO_ADVANCED_CPP) //************************************************************************* - TEST(test_count_bits_64_constexpr) + TEST(test_popcount_64_constexpr) { char temp[etl::popcount(uint64_t(0xFFU))]; @@ -662,7 +753,7 @@ namespace #endif //************************************************************************* - TEST(test_count_trailing_zeros_8) + TEST(test_countr_zero_8) { etl::fnv_1a_32 hash; @@ -676,7 +767,7 @@ namespace #if !defined(ETL_FORCE_NO_ADVANCED_CPP) //************************************************************************* - TEST(test_count_trailing_zeros_8_constexpr) + TEST(test_countr_zero_8_constexpr) { char temp[etl::countr_zero(uint8_t(0x08))]; @@ -685,7 +776,7 @@ namespace #endif //************************************************************************* - TEST(test_count_trailing_zeros_16) + TEST(test_countr_zero_16) { for (size_t i = 0; i < 65536; ++i) { @@ -697,7 +788,7 @@ namespace #if !defined(ETL_FORCE_NO_ADVANCED_CPP) //************************************************************************* - TEST(test_count_trailing_zeros_16_constexpr) + TEST(test_countr_zero_16_constexpr) { char temp[etl::countr_zero(uint16_t(0x08))]; @@ -706,7 +797,7 @@ namespace #endif //************************************************************************* - TEST(test_count_trailing_zeros_32) + TEST(test_countr_zero_32) { etl::fnv_1a_32 hash; @@ -722,7 +813,7 @@ namespace #if !defined(ETL_FORCE_NO_ADVANCED_CPP) //************************************************************************* - TEST(test_count_trailing_zeros_32_constexpr) + TEST(test_countr_zero_32_constexpr) { char temp[etl::countr_zero(uint32_t(0x08))]; @@ -731,7 +822,7 @@ namespace #endif //************************************************************************* - TEST(test_count_trailing_zeros_64) + TEST(test_countr_zero_64) { etl::fnv_1a_64 hash; @@ -747,150 +838,656 @@ namespace #if !defined(ETL_FORCE_NO_ADVANCED_CPP) //************************************************************************* - TEST(test_count_trailing_zeros_64_constexpr) + TEST(test_countr_zero_64_constexpr) { char temp[etl::countr_zero(uint64_t(0x08))]; CHECK_EQUAL(etl::countr_zero(uint64_t(0x08)), sizeof(temp)); } #endif -// //************************************************************************* -// TEST(test_max_value_for_bits) -// { -// // Check that the values are correct. -// //CHECK_EQUAL(0U, etl::max_value_for_nbits<0>::value); -// CHECK_EQUAL(1U, etl::max_value_for_nbits<1>::value); -// CHECK_EQUAL(3U, etl::max_value_for_nbits<2>::value); -// CHECK_EQUAL(7U, etl::max_value_for_nbits<3>::value); -// CHECK_EQUAL(15U, etl::max_value_for_nbits<4>::value); -// CHECK_EQUAL(31U, etl::max_value_for_nbits<5>::value); -// CHECK_EQUAL(63U, etl::max_value_for_nbits<6>::value); -// CHECK_EQUAL(127U, etl::max_value_for_nbits<7>::value); -// CHECK_EQUAL(255U, etl::max_value_for_nbits<8>::value); -// CHECK_EQUAL(511U, etl::max_value_for_nbits<9>::value); -// CHECK_EQUAL(1023U, etl::max_value_for_nbits<10>::value); -// CHECK_EQUAL(2047U, etl::max_value_for_nbits<11>::value); -// CHECK_EQUAL(4095U, etl::max_value_for_nbits<12>::value); -// CHECK_EQUAL(8191U, etl::max_value_for_nbits<13>::value); -// CHECK_EQUAL(16383U, etl::max_value_for_nbits<14>::value); -// CHECK_EQUAL(32767U, etl::max_value_for_nbits<15>::value); -// CHECK_EQUAL(65535U, etl::max_value_for_nbits<16>::value); -// CHECK_EQUAL(131071UL, etl::max_value_for_nbits<17>::value); -// CHECK_EQUAL(262143UL, etl::max_value_for_nbits<18>::value); -// CHECK_EQUAL(524287UL, etl::max_value_for_nbits<19>::value); -// CHECK_EQUAL(1048575UL, etl::max_value_for_nbits<20>::value); -// CHECK_EQUAL(2097151UL, etl::max_value_for_nbits<21>::value); -// CHECK_EQUAL(4194303UL, etl::max_value_for_nbits<22>::value); -// CHECK_EQUAL(8388607UL, etl::max_value_for_nbits<23>::value); -// CHECK_EQUAL(16777215UL, etl::max_value_for_nbits<24>::value); -// CHECK_EQUAL(33554431UL, etl::max_value_for_nbits<25>::value); -// CHECK_EQUAL(67108863UL, etl::max_value_for_nbits<26>::value); -// CHECK_EQUAL(134217727UL, etl::max_value_for_nbits<27>::value); -// CHECK_EQUAL(268435455UL, etl::max_value_for_nbits<28>::value); -// CHECK_EQUAL(536870911UL, etl::max_value_for_nbits<29>::value); -// CHECK_EQUAL(1073741823UL, etl::max_value_for_nbits<30>::value); -// CHECK_EQUAL(2147483647UL, etl::max_value_for_nbits<31>::value); -// CHECK_EQUAL(4294967295UL, etl::max_value_for_nbits<32>::value); -// CHECK_EQUAL(8589934591ULL, etl::max_value_for_nbits<33>::value); -// CHECK_EQUAL(17179869183ULL, etl::max_value_for_nbits<34>::value); -// CHECK_EQUAL(34359738367ULL, etl::max_value_for_nbits<35>::value); -// CHECK_EQUAL(68719476735ULL, etl::max_value_for_nbits<36>::value); -// CHECK_EQUAL(137438953471ULL, etl::max_value_for_nbits<37>::value); -// CHECK_EQUAL(274877906943ULL, etl::max_value_for_nbits<38>::value); -// CHECK_EQUAL(549755813887ULL, etl::max_value_for_nbits<39>::value); -// CHECK_EQUAL(1099511627775ULL, etl::max_value_for_nbits<40>::value); -// CHECK_EQUAL(2199023255551ULL, etl::max_value_for_nbits<41>::value); -// CHECK_EQUAL(4398046511103ULL, etl::max_value_for_nbits<42>::value); -// CHECK_EQUAL(8796093022207ULL, etl::max_value_for_nbits<43>::value); -// CHECK_EQUAL(17592186044415ULL, etl::max_value_for_nbits<44>::value); -// CHECK_EQUAL(35184372088831ULL, etl::max_value_for_nbits<45>::value); -// CHECK_EQUAL(70368744177663ULL, etl::max_value_for_nbits<46>::value); -// CHECK_EQUAL(140737488355327ULL, etl::max_value_for_nbits<47>::value); -// CHECK_EQUAL(281474976710655ULL, etl::max_value_for_nbits<48>::value); -// CHECK_EQUAL(562949953421311ULL, etl::max_value_for_nbits<49>::value); -// CHECK_EQUAL(1125899906842623ULL, etl::max_value_for_nbits<50>::value); -// CHECK_EQUAL(2251799813685247ULL, etl::max_value_for_nbits<51>::value); -// CHECK_EQUAL(4503599627370495ULL, etl::max_value_for_nbits<52>::value); -// CHECK_EQUAL(9007199254740991ULL, etl::max_value_for_nbits<53>::value); -// CHECK_EQUAL(18014398509481983ULL, etl::max_value_for_nbits<54>::value); -// CHECK_EQUAL(36028797018963967ULL, etl::max_value_for_nbits<55>::value); -// CHECK_EQUAL(72057594037927935ULL, etl::max_value_for_nbits<56>::value); -// CHECK_EQUAL(144115188075855871ULL, etl::max_value_for_nbits<57>::value); -// CHECK_EQUAL(288230376151711743ULL, etl::max_value_for_nbits<58>::value); -// CHECK_EQUAL(576460752303423487ULL, etl::max_value_for_nbits<59>::value); -// CHECK_EQUAL(1152921504606846975ULL, etl::max_value_for_nbits<60>::value); -// CHECK_EQUAL(2305843009213693951ULL, etl::max_value_for_nbits<61>::value); -// CHECK_EQUAL(4611686018427387903ULL, etl::max_value_for_nbits<62>::value); -// CHECK_EQUAL(9223372036854775807ULL, etl::max_value_for_nbits<63>::value); -// CHECK_EQUAL(18446744073709551615ULL, etl::max_value_for_nbits<64>::value); -// -// // Check that the value types are correct. -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// CHECK((etl::is_same::value_type>::value)); -// } + + //************************************************************************* + TEST(test_countr_one_8) + { + for (size_t i = 0; i < 256; ++i) + { + uint8_t value = uint8_t(i); + + CHECK_EQUAL(int(test_trailing_ones(value)), int(etl::countr_one(value))); + + if (test_trailing_ones(value) != etl::countr_one(value)) + { + break; + } + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_countr_one_8_constexpr) + { + char temp[etl::countr_one(uint8_t(0x0F))]; + + CHECK_EQUAL(test_trailing_ones(uint8_t(0x0F)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_countr_one_16) + { + for (size_t i = 0; i < 65536; ++i) + { + uint16_t value = uint16_t(i); + + CHECK_EQUAL(int(test_trailing_ones(value)), int(etl::countr_one(value))); + + if (test_trailing_ones(value) != etl::countr_one(value)) + { + break; + } + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_countr_one_16_constexpr) + { + char temp[etl::countr_one(uint16_t(0x000F))]; + + CHECK_EQUAL(test_trailing_ones(uint16_t(0x000F)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_countr_one_32) + { + etl::fnv_1a_32 hash; + + for (size_t i = 0UL; i < 100000UL; ++i) + { + hash.add(1); + + uint32_t value = hash.value(); + + CHECK_EQUAL(test_trailing_ones(value), etl::countr_one(value)); + + if (test_trailing_ones(value) != etl::countr_one(value)) + { + break; + } + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_countr_one_32_constexpr) + { + char temp[etl::countr_one(uint32_t(0x0000000F))]; + + CHECK_EQUAL(test_trailing_ones(uint32_t(0x0000000F)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_countr_one_64) + { + etl::fnv_1a_64 hash; + + for (size_t i = 0UL; i < 100000UL; ++i) + { + hash.add(1); + + uint64_t value = hash.value(); + + CHECK_EQUAL(test_trailing_ones(value), etl::countr_one(value)); + + if (test_trailing_ones(value) != etl::countr_one(value)) + { + break; + } + } + } +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_countr_one_64_constexpr) + { + char temp[etl::countr_one(uint64_t(0x000000000000000F))]; + + CHECK_EQUAL(test_trailing_ones(uint64_t(0x000000000000000F)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_countl_zero_8) + { + for (size_t i = 0; i < 256; ++i) + { + uint8_t value = uint8_t(i); + + CHECK_EQUAL(int(test_leading_zeros(value)), int(etl::countl_zero(value))); + + if (test_leading_zeros(value) != etl::countl_zero(value)) + { + break; + } + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_countl_zero_8_constexpr) + { + char temp[etl::countl_zero(uint8_t(0x01U))]; + + CHECK_EQUAL(test_leading_zeros(uint8_t(0x01U)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_countl_zero_16) + { + for (size_t i = 0; i < 65536; ++i) + { + uint16_t value = uint16_t(i); + + CHECK_EQUAL(int(test_leading_zeros(value)), int(etl::countl_zero(value))); + + if (test_leading_zeros(value) != etl::countl_zero(value)) + { + break; + } + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_countl_zero_16_constexpr) + { + char temp[etl::countl_zero(uint16_t(0x0800U))]; + + CHECK_EQUAL(test_leading_zeros(uint16_t(0x0800U)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_countl_zero_32) + { + etl::fnv_1a_32 hash; + + for (size_t i = 0; i < 100000; ++i) + { + hash.add(1); + + uint32_t value = hash.value(); + + CHECK_EQUAL(int(test_leading_zeros(value)), int(etl::countl_zero(value))); + + if (test_leading_zeros(value) != etl::countl_zero(value)) + { + break; + } + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_countl_zero_32_constexpr) + { + char temp[etl::countl_zero(uint32_t(0x08000000U))]; + + CHECK_EQUAL(test_leading_zeros(uint32_t(0x08000000U)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_countl_zero_64) + { + etl::fnv_1a_64 hash; + + for (size_t i = 0; i < 100000; ++i) + { + hash.add(1); + + uint64_t value = hash.value(); + + CHECK_EQUAL(int(test_leading_zeros(value)), int(etl::countl_zero(value))); + + if (test_leading_zeros(value) != etl::countl_zero(value)) + { + break; + } + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_countl_zero_64_constexpr) + { + char temp[etl::countl_zero(uint64_t(0x0800000000000000U))]; + + CHECK_EQUAL(test_leading_zeros(uint64_t(0x0800000000000000U)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_countl_one_8) + { + for (size_t i = 0; i < 256; ++i) + { + uint8_t value = uint8_t(i); + + CHECK_EQUAL(int(test_leading_ones(value)), int(etl::countl_one(value))); + + if (test_leading_ones(value) != etl::countl_one(value)) + { + break; + } + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_countl_one_8_constexpr) + { + char temp[etl::countl_one(uint8_t(0xF0U))]; + + CHECK_EQUAL(test_leading_ones(uint8_t(0xF0U)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_countl_one_16) + { + for (size_t i = 0; i < 65536; ++i) + { + uint16_t value = uint16_t(i); + + CHECK_EQUAL(int(test_leading_ones(value)), int(etl::countl_one(value))); + + if (test_leading_ones(value) != etl::countl_one(value)) + { + break; + } + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_countl_one_16_constexpr) + { + char temp[etl::countl_one(uint16_t(0xF000U))]; + + CHECK_EQUAL(test_leading_ones(uint16_t(0xF000U)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_countl_one_32) + { + etl::fnv_1a_32 hash; + + for (size_t i = 0; i < 100000; ++i) + { + hash.add(1); + + uint32_t value = hash.value(); + + CHECK_EQUAL(int(test_leading_ones(value)), int(etl::countl_one(value))); + + if (test_leading_ones(value) != etl::countl_one(value)) + { + break; + } + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_countl_one_32_constexpr) + { + char temp[etl::countl_one(uint32_t(0xF0000000UL))]; + + CHECK_EQUAL(test_leading_ones(uint32_t(0xF0000000UL)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_countl_one_64) + { + etl::fnv_1a_64 hash; + + for (size_t i = 0; i < 100000; ++i) + { + hash.add(1); + + uint64_t value = hash.value(); + + CHECK_EQUAL(int(test_leading_ones(value)), int(etl::countl_one(value))); + + if (test_leading_ones(value) != etl::countl_one(value)) + { + break; + } + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_countl_one_64_constexpr) + { + char temp[etl::countl_one(uint64_t(0xF000000000000000UL))]; + + CHECK_EQUAL(test_leading_ones(uint64_t(0xF000000000000000UL)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_bit_ceil_8) + { + for (size_t i = 0; i < 256; ++i) + { + uint8_t value = uint8_t(i); + + CHECK_EQUAL(int(test_bit_ceil(value)), int(etl::bit_ceil(value))); + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_bit_ceil_8_constexpr) + { + char temp[etl::bit_ceil(uint8_t(1))]; + + CHECK_EQUAL(test_bit_ceil(uint8_t(1)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_bit_ceil_16) + { + etl::fnv_1a_32 hash; + + for (size_t i = 0; i < 100000; ++i) + { + hash.add(1); + + uint16_t value = hash.value(); + + CHECK_EQUAL(test_bit_ceil(value), etl::bit_ceil(value)); + + if (test_bit_ceil(value) != etl::bit_ceil(value)) + { + break; + } + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_bit_ceil_16_constexpr) + { + char temp[etl::bit_ceil(uint16_t(1))]; + + CHECK_EQUAL(test_bit_ceil(uint16_t(1)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_bit_ceil_32) + { + etl::fnv_1a_32 hash; + + for (size_t i = 0; i < 100000; ++i) + { + hash.add(1); + + uint32_t value = hash.value(); + + CHECK_EQUAL(test_bit_ceil(value), etl::bit_ceil(value)); + + if (test_bit_ceil(value) != etl::bit_ceil(value)) + { + break; + } + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_bit_ceil_32_constexpr) + { + char temp[etl::bit_ceil(uint32_t(1))]; + + CHECK_EQUAL(test_bit_ceil(uint32_t(1)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_bit_ceil_64) + { + etl::fnv_1a_64 hash; + + for (size_t i = 0; i < 100000; ++i) + { + hash.add(1); + + uint64_t value = hash.value(); + + CHECK_EQUAL(test_bit_ceil(value), etl::bit_ceil(value)); + + if (test_bit_ceil(value) != etl::bit_ceil(value)) + { + break; + } + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_bit_ceil_64_constexpr) + { + char temp[etl::bit_ceil(uint64_t(1))]; + + CHECK_EQUAL(test_bit_ceil(uint64_t(1)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_bit_floor_8) + { + for (size_t i = 0; i < 256; ++i) + { + uint8_t value = uint8_t(i); + + CHECK_EQUAL(int(test_bit_floor(value)), int(etl::bit_floor(value))); + } + } + + //************************************************************************* + TEST(test_bit_floor_16) + { + etl::fnv_1a_32 hash; + + for (size_t i = 0; i < 100000; ++i) + { + hash.add(1); + + uint16_t value = hash.value(); + + CHECK_EQUAL(test_bit_floor(value), etl::bit_floor(value)); + + if (test_bit_floor(value) != etl::bit_floor(value)) + { + break; + } + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_bit_floor_16_constexpr) + { + char temp[etl::bit_floor(uint16_t(1))]; + + CHECK_EQUAL(test_bit_floor(uint16_t(1)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_bit_floor_32) + { + etl::fnv_1a_32 hash; + + for (size_t i = 0; i < 100000; ++i) + { + hash.add(1); + + uint32_t value = hash.value(); + + CHECK_EQUAL(test_bit_floor(value), etl::bit_floor(value)); + + if (test_bit_floor(value) != etl::bit_floor(value)) + { + break; + } + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_bit_floor_32_constexpr) + { + char temp[etl::bit_floor(uint32_t(1))]; + + CHECK_EQUAL(test_bit_floor(uint32_t(1)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_bit_floor_64) + { + etl::fnv_1a_64 hash; + + for (size_t i = 0; i < 100000; ++i) + { + hash.add(1); + + uint64_t value = hash.value(); + + CHECK_EQUAL(test_bit_floor(value), etl::bit_floor(value)); + + if (test_bit_floor(value) != etl::bit_floor(value)) + { + break; + } + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_bit_floor_64_constexpr) + { + char temp[etl::bit_floor(uint64_t(1))]; + + CHECK_EQUAL(test_bit_floor(uint64_t(1)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_bit_width_8) + { + for (size_t i = 0; i < 256; ++i) + { + uint8_t value = uint8_t(i); + + CHECK_EQUAL(int(test_bit_width(value)), int(etl::bit_width(value))); + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_bit_width_8_constexpr) + { + char temp[etl::bit_width(uint8_t(0xAU))]; + + CHECK_EQUAL(test_bit_width(uint8_t(0xAU)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_bit_width_16) + { + etl::fnv_1a_32 hash; + + for (size_t i = 0; i < 100000; ++i) + { + hash.add(1); + + uint16_t value = hash.value(); + + CHECK_EQUAL(test_bit_width(value), etl::bit_width(value)); + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_bit_width_16_constexpr) + { + char temp[etl::bit_width(uint16_t(0xAU))]; + + CHECK_EQUAL(test_bit_width(uint16_t(0xAU)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_bit_width_32) + { + etl::fnv_1a_32 hash; + + for (size_t i = 0; i < 100000; ++i) + { + hash.add(1); + + uint32_t value = hash.value(); + + CHECK_EQUAL(test_bit_width(value), etl::bit_width(value)); + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_bit_width_32_constexpr) + { + char temp[etl::bit_width(uint32_t(0xAU))]; + + CHECK_EQUAL(test_bit_width(uint32_t(0xAU)), sizeof(temp)); + } +#endif + + //************************************************************************* + TEST(test_bit_width_64) + { + etl::fnv_1a_64 hash; + + for (size_t i = 0; i < 100000; ++i) + { + hash.add(1); + + uint64_t value = hash.value(); + + CHECK_EQUAL(test_bit_width(value), etl::bit_width(value)); + } + } + +#if !defined(ETL_FORCE_NO_ADVANCED_CPP) + //************************************************************************* + TEST(test_bit_width_64_constexpr) + { + char temp[etl::bit_width(uint64_t(0xAU))]; + + CHECK_EQUAL(test_bit_width(uint64_t(0xAU)), sizeof(temp)); + } +#endif }; } diff --git a/test/vs2019/etl.sln b/test/vs2019/etl.sln index b35ce12b..f1035dd7 100644 --- a/test/vs2019/etl.sln +++ b/test/vs2019/etl.sln @@ -29,6 +29,8 @@ Global Debug MSVC - String Truncation Is Error|x64 = Debug MSVC - String Truncation Is Error|x64 Debug MSVC 64|Win32 = Debug MSVC 64|Win32 Debug MSVC 64|x64 = Debug MSVC 64|x64 + Debug MSVC C++20|Win32 = Debug MSVC C++20|Win32 + Debug MSVC C++20|x64 = Debug MSVC C++20|x64 Debug MSVC No Checks|Win32 = Debug MSVC No Checks|Win32 Debug MSVC No Checks|x64 = Debug MSVC No Checks|x64 Debug MSVC|Win32 = Debug MSVC|Win32 @@ -85,6 +87,10 @@ Global {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC 64|Win32.Build.0 = Debug No Unit Tests|Win32 {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC 64|x64.ActiveCfg = Debug64|x64 {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC 64|x64.Build.0 = Debug64|x64 + {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++20|Win32.ActiveCfg = Debug MSVC C++20|Win32 + {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++20|Win32.Build.0 = Debug MSVC C++20|Win32 + {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++20|x64.ActiveCfg = Debug MSVC C++20|x64 + {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++20|x64.Build.0 = Debug MSVC C++20|x64 {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC No Checks|Win32.ActiveCfg = Debug MSVC No Checks|Win32 {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC No Checks|Win32.Build.0 = Debug MSVC No Checks|Win32 {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC No Checks|x64.ActiveCfg = Debug MSVC No Checks|x64 diff --git a/test/vs2019/etl.vcxproj b/test/vs2019/etl.vcxproj index 89c95188..666be5f3 100644 --- a/test/vs2019/etl.vcxproj +++ b/test/vs2019/etl.vcxproj @@ -65,6 +65,14 @@ Debug MSVC - No Checks x64 + + Debug MSVC C++20 + Win32 + + + Debug MSVC C++20 + x64 + Debug64 Win32 @@ -161,6 +169,13 @@ Unicode false + + Application + true + v142 + Unicode + false + Application true @@ -273,6 +288,12 @@ v142 Unicode + + Application + true + v142 + Unicode + Application true @@ -425,6 +446,9 @@ + + + @@ -479,6 +503,9 @@ + + + @@ -554,6 +581,11 @@ true $(Configuration)\ + + true + true + $(Configuration)\ + true true @@ -649,6 +681,10 @@ true true + + true + true + true true @@ -768,6 +804,28 @@ "$(OutDir)\etl.exe" + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + ../../../unittest-cpp/;../../include;../../test + + + true + stdcpp20 + EditAndContinue + + + Console + true + + + "$(OutDir)\etl.exe" + + @@ -1192,6 +1250,27 @@ $(OutDir)\etl.exe + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + ../../unittest-cpp/UnitTest++/;../../include/etl;../../test + + + false + stdcpp14 + + + Console + true + + + $(OutDir)\etl.exe + + @@ -2066,6 +2145,7 @@ true true true + true true true true @@ -2090,6 +2170,7 @@ true true true + true true true true @@ -2114,6 +2195,7 @@ true true true + true true true true @@ -2138,6 +2220,7 @@ true true true + true true true true @@ -2162,6 +2245,7 @@ true true true + true true true true @@ -2186,6 +2270,7 @@ true true true + true true true true @@ -2210,6 +2295,7 @@ true true true + true true true true @@ -2234,6 +2320,7 @@ true true true + true true true true @@ -2258,6 +2345,7 @@ true true true + true true true true @@ -2282,6 +2370,7 @@ true true true + true true true true @@ -2306,6 +2395,7 @@ true true true + true true true true @@ -2319,6 +2409,7 @@ true + true true true true @@ -2351,6 +2442,7 @@ true true true + true true true true @@ -2375,6 +2467,7 @@ true true true + true true true true @@ -2399,6 +2492,7 @@ true true true + true true true true @@ -2423,6 +2517,7 @@ true true true + true true true true @@ -2447,6 +2542,7 @@ true true true + true true true true @@ -2460,6 +2556,7 @@ true + true true true true @@ -2491,6 +2588,7 @@ true true true + true true true true @@ -2515,6 +2613,7 @@ true true true + true true true true @@ -2539,6 +2638,7 @@ true true true + true true true true @@ -2552,6 +2652,7 @@ true + true true true true @@ -2583,6 +2684,7 @@ true true true + true true true true @@ -2607,6 +2709,7 @@ true true true + true true true true @@ -2631,6 +2734,7 @@ true true true + true true true true @@ -2655,6 +2759,7 @@ true true true + true true true true @@ -2679,6 +2784,7 @@ true true true + true true true true @@ -2703,6 +2809,7 @@ true true true + true true true true @@ -2727,6 +2834,7 @@ true true true + true true true true @@ -2751,6 +2859,7 @@ true true true + true true true true @@ -2775,6 +2884,7 @@ true true true + true true true true @@ -2799,6 +2909,7 @@ true true true + true true true true @@ -2823,6 +2934,7 @@ true true true + true true true true @@ -2847,6 +2959,7 @@ true true true + true true true true @@ -2871,6 +2984,7 @@ true true true + true true true true @@ -2895,6 +3009,7 @@ true true true + true true true true @@ -2919,6 +3034,7 @@ true true true + true true true true @@ -2943,6 +3059,7 @@ true true true + true true true true @@ -2967,6 +3084,7 @@ true true true + true true true true @@ -2991,6 +3109,7 @@ true true true + true true true true @@ -3015,6 +3134,7 @@ true true true + true true true true @@ -3039,6 +3159,7 @@ true true true + true true true true @@ -3063,6 +3184,7 @@ true true true + true true true true @@ -3087,6 +3209,7 @@ true true true + true true true true @@ -3111,6 +3234,7 @@ true true true + true true true true @@ -3135,6 +3259,7 @@ true true true + true true true true @@ -3159,6 +3284,7 @@ true true true + true true true true @@ -3183,6 +3309,7 @@ true true true + true true true true @@ -3207,6 +3334,7 @@ true true true + true true true true @@ -3231,6 +3359,7 @@ true true true + true true true true @@ -3255,6 +3384,7 @@ true true true + true true true true @@ -3279,6 +3409,7 @@ true true true + true true true true @@ -3303,6 +3434,7 @@ true true true + true true true true @@ -3327,6 +3459,7 @@ true true true + true true true true @@ -3351,6 +3484,7 @@ true true true + true true true true @@ -3375,6 +3509,7 @@ true true true + true true true true @@ -3399,6 +3534,7 @@ true true true + true true true true @@ -3423,6 +3559,7 @@ true true true + true true true true @@ -3447,6 +3584,7 @@ true true true + true true true true @@ -3471,6 +3609,7 @@ true true true + true true true true @@ -3495,6 +3634,7 @@ true true true + true true true true @@ -3519,6 +3659,7 @@ true true true + true true true true @@ -3543,6 +3684,7 @@ true true true + true true true true @@ -3567,6 +3709,7 @@ true true true + true true true true @@ -3591,6 +3734,7 @@ true true true + true true true true @@ -3615,6 +3759,7 @@ true true true + true true true true @@ -3639,6 +3784,7 @@ true true true + true true true true @@ -3663,6 +3809,7 @@ true true true + true true true true @@ -3687,6 +3834,7 @@ true true true + true true true true @@ -3711,6 +3859,7 @@ true true true + true true true true @@ -3735,6 +3884,7 @@ true true true + true true true true @@ -3759,6 +3909,7 @@ true true true + true true true true @@ -3783,6 +3934,7 @@ true true true + true true true true @@ -3807,6 +3959,7 @@ true true true + true true true true @@ -3831,6 +3984,7 @@ true true true + true true true true @@ -3855,6 +4009,7 @@ true true true + true true true true @@ -3879,6 +4034,7 @@ true true true + true true true true @@ -3903,6 +4059,7 @@ true true true + true true true true @@ -3927,6 +4084,7 @@ true true true + true true true true @@ -3951,6 +4109,7 @@ true true true + true true true true @@ -3975,6 +4134,7 @@ true true true + true true true true @@ -3999,6 +4159,7 @@ true true true + true true true true @@ -4023,6 +4184,7 @@ true true true + true true true true @@ -4047,6 +4209,7 @@ true true true + true true true true @@ -4071,6 +4234,7 @@ true true true + true true true true @@ -4095,6 +4259,7 @@ true true true + true true true true @@ -4119,6 +4284,7 @@ true true true + true true true true @@ -4143,6 +4309,7 @@ true true true + true true true true @@ -4167,6 +4334,7 @@ true true true + true true true true @@ -4191,6 +4359,7 @@ true true true + true true true true @@ -4215,6 +4384,7 @@ true true true + true true true true @@ -4239,6 +4409,7 @@ true true true + true true true true @@ -4263,6 +4434,7 @@ true true true + true true true true @@ -4287,6 +4459,7 @@ true true true + true true true true @@ -4311,6 +4484,7 @@ true true true + true true true true @@ -4335,6 +4509,7 @@ true true true + true true true true @@ -4359,6 +4534,7 @@ true true true + true true true true @@ -4383,6 +4559,7 @@ true true true + true true true true @@ -4407,6 +4584,7 @@ true true true + true true true true @@ -4431,6 +4609,7 @@ true true true + true true true true @@ -4455,6 +4634,7 @@ true true true + true true true true @@ -4479,6 +4659,7 @@ true true true + true true true true @@ -4503,6 +4684,7 @@ true true true + true true true true @@ -4527,6 +4709,7 @@ true true true + true true true true @@ -4551,6 +4734,7 @@ true true true + true true true true @@ -4575,6 +4759,7 @@ true true true + true true true true @@ -4599,6 +4784,7 @@ true true true + true true true true @@ -4623,6 +4809,7 @@ true true true + true true true true @@ -4647,6 +4834,7 @@ true true true + true true true true @@ -4671,6 +4859,7 @@ true true true + true true true true @@ -4695,6 +4884,7 @@ true true true + true true true true @@ -4719,6 +4909,7 @@ true true true + true true true true @@ -4743,6 +4934,7 @@ true true true + true true true true @@ -4767,6 +4959,7 @@ true true true + true true true true @@ -4791,6 +4984,7 @@ true true true + true true true true @@ -4815,6 +5009,7 @@ true true true + true true true true @@ -4839,6 +5034,7 @@ true true true + true true true true @@ -4863,6 +5059,7 @@ true true true + true true true true @@ -4887,6 +5084,7 @@ true true true + true true true true @@ -4911,6 +5109,7 @@ true true true + true true true true @@ -4935,6 +5134,7 @@ true true true + true true true true @@ -4959,6 +5159,7 @@ true true true + true true true true @@ -4983,6 +5184,7 @@ true true true + true true true true @@ -5007,6 +5209,7 @@ true true true + true true true true @@ -5031,6 +5234,7 @@ true true true + true true true true @@ -5055,6 +5259,7 @@ true true true + true true true true @@ -5079,6 +5284,7 @@ true true true + true true true true @@ -5103,6 +5309,7 @@ true true true + true true true true @@ -5127,6 +5334,7 @@ true true true + true true true true @@ -5151,6 +5359,7 @@ true true true + true true true true @@ -5175,6 +5384,7 @@ true true true + true true true true @@ -5199,6 +5409,7 @@ true true true + true true true true @@ -5223,6 +5434,7 @@ true true true + true true true true @@ -5247,6 +5459,7 @@ true true true + true true true true @@ -5271,6 +5484,7 @@ true true true + true true true true @@ -5295,6 +5509,7 @@ true true true + true true true true @@ -5319,6 +5534,7 @@ true true true + true true true true @@ -5343,6 +5559,7 @@ true true true + true true true true @@ -5367,6 +5584,7 @@ true true true + true true true true @@ -5391,6 +5609,7 @@ true true true + true true true true @@ -5415,6 +5634,7 @@ true true true + true true true true @@ -5439,6 +5659,7 @@ true true true + true true true true @@ -5452,6 +5673,7 @@ true + true true true true @@ -5483,6 +5705,7 @@ true true true + true true true true @@ -5507,6 +5730,7 @@ true true true + true true true true @@ -5531,6 +5755,7 @@ true true true + true true true true @@ -5555,6 +5780,7 @@ true true true + true true true true @@ -5579,6 +5805,7 @@ true true true + true true true true @@ -5592,6 +5819,7 @@ true + true true true true @@ -5612,6 +5840,7 @@ true + true true true true @@ -5643,6 +5872,7 @@ true true true + true true true true @@ -5667,6 +5897,7 @@ true true true + true true true true @@ -5691,6 +5922,7 @@ true true true + true true true true @@ -5704,6 +5936,7 @@ true + true true true true @@ -5735,6 +5968,7 @@ true true true + true true true true @@ -5759,6 +5993,7 @@ true true true + true true true true @@ -5783,6 +6018,7 @@ true true true + true true true true @@ -5807,6 +6043,7 @@ true true true + true true true true @@ -5831,6 +6068,7 @@ true true true + true true true true @@ -5855,6 +6093,7 @@ true true true + true true true true @@ -5879,6 +6118,7 @@ true true true + true true true true @@ -5903,6 +6143,7 @@ true true true + true true true true @@ -5927,6 +6168,7 @@ true true true + true true true true @@ -5951,6 +6193,7 @@ true true true + true true true true @@ -5975,6 +6218,7 @@ true true true + true true true true @@ -5999,6 +6243,7 @@ true true true + true true true true @@ -6023,6 +6268,7 @@ true true true + true true true true @@ -6047,6 +6293,7 @@ true true true + true true true true @@ -6071,6 +6318,7 @@ true true true + true true true true @@ -6095,6 +6343,7 @@ true true true + true true true true @@ -6119,6 +6368,7 @@ true true true + true true true true @@ -6143,6 +6393,7 @@ true true true + true true true true @@ -6167,6 +6418,7 @@ true true true + true true true true @@ -6191,6 +6443,7 @@ true true true + true true true true @@ -6215,6 +6468,7 @@ true true true + true true true true @@ -6239,6 +6493,7 @@ true true true + true true true true @@ -6263,6 +6518,7 @@ true true true + true true true true @@ -6287,6 +6543,7 @@ true true true + true true true true @@ -6311,6 +6568,7 @@ true true true + true true true true @@ -6335,6 +6593,7 @@ true true true + true true true true @@ -6359,6 +6618,7 @@ true true true + true true true true @@ -6383,6 +6643,7 @@ true true true + true true true true @@ -6407,6 +6668,7 @@ true true true + true true true true @@ -6431,6 +6693,7 @@ true true true + true true true true @@ -6455,6 +6718,7 @@ true true true + true true true true @@ -6479,6 +6743,7 @@ true true true + true true true true @@ -6503,6 +6768,7 @@ true true true + true true true true @@ -6527,6 +6793,7 @@ true true true + true true true true @@ -6551,6 +6818,7 @@ true true true + true true true true @@ -6575,6 +6843,7 @@ true true true + true true true true @@ -6599,6 +6868,7 @@ true true true + true true true true @@ -6623,6 +6893,7 @@ true true true + true true true true @@ -6647,6 +6918,7 @@ true true true + true true true true @@ -6671,6 +6943,7 @@ true true true + true true true true @@ -6695,6 +6968,7 @@ true true true + true true true true @@ -6719,6 +6993,7 @@ true true true + true true true true @@ -6743,6 +7018,7 @@ true true true + true true true true @@ -6767,6 +7043,7 @@ true true true + true true true true @@ -6791,6 +7068,7 @@ true true true + true true true true @@ -6815,6 +7093,7 @@ true true true + true true true true @@ -6839,6 +7118,7 @@ true true true + true true true true @@ -6863,6 +7143,7 @@ true true true + true true true true @@ -6887,6 +7168,7 @@ true true true + true true true true @@ -6911,6 +7193,7 @@ true true true + true true true true @@ -6935,6 +7218,7 @@ true true true + true true true true @@ -6959,6 +7243,7 @@ true true true + true true true true @@ -6983,6 +7268,7 @@ true true true + true true true true @@ -7007,6 +7293,7 @@ true true true + true true true true @@ -7031,6 +7318,7 @@ true true true + true true true true @@ -7055,6 +7343,7 @@ true true true + true true true true @@ -7079,6 +7368,7 @@ true true true + true true true true @@ -7103,6 +7393,7 @@ true true true + true true true true @@ -7127,6 +7418,7 @@ true true true + true true true true @@ -7151,6 +7443,7 @@ true true true + true true true true @@ -7175,6 +7468,7 @@ true true true + true true true true @@ -7199,6 +7493,7 @@ true true true + true true true true @@ -7223,6 +7518,7 @@ true true true + true true true true @@ -7247,6 +7543,7 @@ true true true + true true true true @@ -7271,6 +7568,7 @@ true true true + true true true true @@ -7295,6 +7593,7 @@ true true true + true true true true @@ -7319,6 +7618,7 @@ true true true + true true true true @@ -7343,6 +7643,7 @@ true true true + true true true true @@ -7367,6 +7668,7 @@ true true true + true true true true @@ -7391,6 +7693,7 @@ true true true + true true true true @@ -7415,6 +7718,7 @@ true true true + true true true true @@ -7439,6 +7743,7 @@ true true true + true true true true @@ -7463,6 +7768,7 @@ true true true + true true true true @@ -7487,6 +7793,7 @@ true true true + true true true true @@ -7511,6 +7818,7 @@ true true true + true true true true @@ -7535,6 +7843,7 @@ true true true + true true true true @@ -7559,6 +7868,7 @@ true true true + true true true true @@ -7583,6 +7893,7 @@ true true true + true true true true @@ -7607,6 +7918,7 @@ true true true + true true true true @@ -7631,6 +7943,7 @@ true true true + true true true true @@ -7655,6 +7968,7 @@ true true true + true true true true @@ -7679,6 +7993,7 @@ true true true + true true true true @@ -7703,6 +8018,7 @@ true true true + true true true true @@ -7727,6 +8043,7 @@ true true true + true true true true @@ -7751,6 +8068,7 @@ true true true + true true true true @@ -7775,6 +8093,7 @@ true true true + true true true true @@ -7901,6 +8220,7 @@ false false false + false false false false @@ -7921,6 +8241,7 @@ false false false + false false false false @@ -7960,6 +8281,7 @@ false + false false false false @@ -7980,6 +8302,7 @@ false false false + false false false false @@ -8014,6 +8337,7 @@ false + false false false false @@ -8034,6 +8358,7 @@ false false false + false false false false @@ -8058,6 +8383,7 @@ false + false false false false @@ -8078,6 +8404,7 @@ false false false + false false false false @@ -8102,6 +8429,7 @@ false + false false false false @@ -8122,6 +8450,7 @@ false false false + false false false false @@ -8146,6 +8475,7 @@ false + false false false false @@ -8166,6 +8496,7 @@ false false false + false false false false @@ -8190,6 +8521,7 @@ false + false false false false @@ -8210,6 +8542,7 @@ false false false + false false false false @@ -8239,6 +8572,7 @@ false + false false false false @@ -8259,6 +8593,7 @@ false false false + false false false false @@ -8287,6 +8622,7 @@ true true false + false false false false @@ -8307,6 +8643,7 @@ false false false + false false false false @@ -8343,6 +8680,7 @@ false + false false false false @@ -8363,6 +8701,7 @@ false false false + false false false false From a0023aa9aa00631254017edfcc28822815fa321c Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 8 Jan 2022 12:25:18 +0000 Subject: [PATCH 14/15] Updated tests to support C++20 STL --- test/etl_profile.h | 7 ++++++- test/test_numeric.cpp | 7 +++++-- test/test_string_stream_u16.cpp | 2 +- test/test_string_stream_u32.cpp | 2 +- test/test_string_stream_wchar_t.cpp | 2 +- test/test_string_u16.cpp | 16 ++++++++++++++++ test/test_string_u16_external_buffer.cpp | 16 ++++++++++++++++ test/test_string_u32.cpp | 16 ++++++++++++++++ test/test_string_u32_external_buffer.cpp | 16 ++++++++++++++++ test/test_string_utilities_std_u16.cpp | 8 ++++++++ test/test_string_utilities_std_u32.cpp | 8 ++++++++ test/test_string_utilities_std_wchar_t.cpp | 8 ++++++++ test/test_string_utilities_u16.cpp | 8 ++++++++ test/test_string_utilities_u32.cpp | 8 ++++++++ test/test_string_utilities_wchar_t.cpp | 10 +++++++++- test/test_string_wchar_t.cpp | 17 ++++++++++++++++- test/test_string_wchar_t_external_buffer.cpp | 16 ++++++++++++++++ test/vs2019/etl.vcxproj | 2 +- 18 files changed, 160 insertions(+), 9 deletions(-) diff --git a/test/etl_profile.h b/test/etl_profile.h index 8cac498b..0f050628 100644 --- a/test/etl_profile.h +++ b/test/etl_profile.h @@ -73,7 +73,12 @@ SOFTWARE. #define ETL_POLYMORPHIC_VECTOR #define ETL_POLYMORPHIC_INDIRECT_VECTOR -#define ETL_CPP20_SUPPORTED 0 +#if defined(ETL_CPP20_ENABLED) + #define ETL_CPP20_SUPPORTED 1 +#else + #define ETL_CPP20_SUPPORTED 0 +#endif + //#define ETL_POLYMORPHIC_CONTAINERS diff --git a/test/test_numeric.cpp b/test/test_numeric.cpp index aa0760ab..86e0e9d5 100644 --- a/test/test_numeric.cpp +++ b/test/test_numeric.cpp @@ -37,6 +37,7 @@ SOFTWARE. #include #include #include +#include namespace { @@ -104,7 +105,8 @@ namespace //************************************************************************* TEST(test_midpoint_etl_random_access_iterator) { - etl::deque data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + std::array initial = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + etl::deque data(initial.begin(), initial.end()); etl::deque::iterator b = data.begin(); etl::deque::iterator e = data.end(); @@ -116,7 +118,8 @@ namespace //************************************************************************* TEST(test_midpoint_etl_bidirectional_iterator) { - etl::list data = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + std::array initial = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + etl::list data(initial.begin(), initial.end()); etl::list::iterator b = data.begin(); etl::list::iterator e = data.end(); diff --git a/test/test_string_stream_u16.cpp b/test/test_string_stream_u16.cpp index cb548697..fbe60600 100644 --- a/test/test_string_stream_u16.cpp +++ b/test/test_string_stream_u16.cpp @@ -68,7 +68,7 @@ namespace etl { for (auto c : str) { - os << c; + os << uint16_t(c); } return os; diff --git a/test/test_string_stream_u32.cpp b/test/test_string_stream_u32.cpp index 58d174b7..451bb137 100644 --- a/test/test_string_stream_u32.cpp +++ b/test/test_string_stream_u32.cpp @@ -68,7 +68,7 @@ namespace etl { for (auto c : str) { - os << c; + os << uint32_t(c); } return os; diff --git a/test/test_string_stream_wchar_t.cpp b/test/test_string_stream_wchar_t.cpp index af69a80e..8ea2ce82 100644 --- a/test/test_string_stream_wchar_t.cpp +++ b/test/test_string_stream_wchar_t.cpp @@ -68,7 +68,7 @@ namespace etl { for (auto c : str) { - os << c; + os << uint16_t(c); } return os; diff --git a/test/test_string_u16.cpp b/test/test_string_u16.cpp index 34b96484..56a34464 100644 --- a/test/test_string_u16.cpp +++ b/test/test_string_u16.cpp @@ -46,6 +46,22 @@ namespace ((result1 > 0) && (result2 > 0)); } + //*********************************** + std::ostream& operator << (std::ostream& os, const etl::iu16string::value_type& c) + { + os << uint16_t(c); + + return os; + } + + //*********************************** + std::ostream& operator << (std::ostream& os, const etl::iu16string::value_type* c) + { + os << (void*)c; + + return os; + } + SUITE(test_string_char) { static const size_t SIZE = 11; diff --git a/test/test_string_u16_external_buffer.cpp b/test/test_string_u16_external_buffer.cpp index bbde373c..4d6e9b30 100644 --- a/test/test_string_u16_external_buffer.cpp +++ b/test/test_string_u16_external_buffer.cpp @@ -47,6 +47,22 @@ namespace ((result1 > 0) && (result2 > 0)); } + //*********************************** + std::ostream& operator << (std::ostream& os, const etl::iu16string::value_type& c) + { + os << uint16_t(c); + + return os; + } + + //*********************************** + std::ostream& operator << (std::ostream& os, const etl::iu16string::value_type* c) + { + os << (void*)c; + + return os; + } + SUITE(test_string_char) { static constexpr size_t SIZE = 11; diff --git a/test/test_string_u32.cpp b/test/test_string_u32.cpp index 3058afdb..ccbfac21 100644 --- a/test/test_string_u32.cpp +++ b/test/test_string_u32.cpp @@ -46,6 +46,22 @@ namespace ((result1 > 0) && (result2 > 0)); } + //*********************************** + std::ostream& operator << (std::ostream& os, const etl::iu32string::value_type& c) + { + os << uint32_t(c); + + return os; + } + + //*********************************** + std::ostream& operator << (std::ostream& os, const etl::iu32string::value_type* c) + { + os << (void*)c; + + return os; + } + SUITE(test_string_char) { static const size_t SIZE = 11; diff --git a/test/test_string_u32_external_buffer.cpp b/test/test_string_u32_external_buffer.cpp index d0592438..e7e8525e 100644 --- a/test/test_string_u32_external_buffer.cpp +++ b/test/test_string_u32_external_buffer.cpp @@ -47,6 +47,22 @@ namespace ((result1 > 0) && (result2 > 0)); } + //*********************************** + std::ostream& operator << (std::ostream& os, const etl::u32string_ext::value_type& c) + { + os << uint32_t(c); + + return os; + } + + //*********************************** + std::ostream& operator << (std::ostream& os, const etl::u32string_ext::value_type* c) + { + os << (void*)c; + + return os; + } + SUITE(test_string_char) { static constexpr size_t SIZE = 11; diff --git a/test/test_string_utilities_std_u16.cpp b/test/test_string_utilities_std_u16.cpp index 3c2d1d14..b57858f5 100644 --- a/test/test_string_utilities_std_u16.cpp +++ b/test/test_string_utilities_std_u16.cpp @@ -40,6 +40,14 @@ SOFTWARE. namespace { + //*********************************** + std::ostream& operator << (std::ostream& os, const std::wstring::value_type& c) + { + os << uint16_t(c); + + return os; + } + SUITE(test_string_utilities_std_u16) { using String = std::wstring; diff --git a/test/test_string_utilities_std_u32.cpp b/test/test_string_utilities_std_u32.cpp index b56ed472..1e0ee509 100644 --- a/test/test_string_utilities_std_u32.cpp +++ b/test/test_string_utilities_std_u32.cpp @@ -40,6 +40,14 @@ SOFTWARE. namespace { + //*********************************** + std::ostream& operator << (std::ostream& os, const std::u32string::value_type& c) + { + os << uint32_t(c); + + return os; + } + SUITE(test_string_utilities_std_u32) { using String = std::u32string; diff --git a/test/test_string_utilities_std_wchar_t.cpp b/test/test_string_utilities_std_wchar_t.cpp index 6ef1e6df..fcd17722 100644 --- a/test/test_string_utilities_std_wchar_t.cpp +++ b/test/test_string_utilities_std_wchar_t.cpp @@ -40,6 +40,14 @@ SOFTWARE. namespace { + //*********************************** + std::ostream& operator << (std::ostream& os, const std::wstring::value_type& c) + { + os << uint16_t(c); + + return os; + } + SUITE(test_string_utilities_std_wchar_t) { using String = std::wstring; diff --git a/test/test_string_utilities_u16.cpp b/test/test_string_utilities_u16.cpp index 9d26a3fa..1e3eecf2 100644 --- a/test/test_string_utilities_u16.cpp +++ b/test/test_string_utilities_u16.cpp @@ -38,6 +38,14 @@ SOFTWARE. namespace { + //*********************************** + std::ostream& operator << (std::ostream& os, const std::u16string::value_type& c) + { + os << uint16_t(c); + + return os; + } + SUITE(test_string_utilities_u16) { static const size_t SIZE = 50; diff --git a/test/test_string_utilities_u32.cpp b/test/test_string_utilities_u32.cpp index d71f543d..7e32498f 100644 --- a/test/test_string_utilities_u32.cpp +++ b/test/test_string_utilities_u32.cpp @@ -38,6 +38,14 @@ SOFTWARE. namespace { + //*********************************** + std::ostream& operator << (std::ostream& os, const etl::iu32string::value_type& c) + { + os << uint32_t(c); + + return os; + } + SUITE(test_string_utilities_u32) { static const size_t SIZE = 50; diff --git a/test/test_string_utilities_wchar_t.cpp b/test/test_string_utilities_wchar_t.cpp index c4a55833..39962da8 100644 --- a/test/test_string_utilities_wchar_t.cpp +++ b/test/test_string_utilities_wchar_t.cpp @@ -38,11 +38,19 @@ SOFTWARE. namespace { + //*********************************** + std::ostream& operator << (std::ostream& os, const std::wstring::value_type& c) + { + os << uint16_t(c); + + return os; + } + SUITE(test_string_utilities_wchar_t) { static const size_t SIZE = 50; - using String = etl::wstring; + using String = etl::wstring; using IString = etl::iwstring; using StringView = etl::wstring_view; using Char = etl::iwstring::value_type; diff --git a/test/test_string_wchar_t.cpp b/test/test_string_wchar_t.cpp index 77af504c..394173d5 100644 --- a/test/test_string_wchar_t.cpp +++ b/test/test_string_wchar_t.cpp @@ -46,6 +46,22 @@ namespace ((result1 > 0) && (result2 > 0)); } + //*********************************** + std::ostream& operator << (std::ostream& os, const etl::iwstring::value_type& c) + { + os << uint16_t(c); + + return os; + } + + //*********************************** + std::ostream& operator << (std::ostream& os, const etl::iwstring::value_type* c) + { + os << (void*)c; + + return os; + } + SUITE(test_string_wchar_t) { static const size_t SIZE = 11; @@ -581,7 +597,6 @@ namespace CHECK_EQUAL(&constText[0], constText.begin()); } - //************************************************************************* TEST_FIXTURE(SetupFixture, test_end) { diff --git a/test/test_string_wchar_t_external_buffer.cpp b/test/test_string_wchar_t_external_buffer.cpp index d8ebde05..2aa20394 100644 --- a/test/test_string_wchar_t_external_buffer.cpp +++ b/test/test_string_wchar_t_external_buffer.cpp @@ -47,6 +47,22 @@ namespace ((result1 > 0) && (result2 > 0)); } + //*********************************** + std::ostream& operator << (std::ostream& os, const etl::iwstring::value_type& c) + { + os << uint16_t(c); + + return os; + } + + //*********************************** + std::ostream& operator << (std::ostream& os, const etl::iwstring::value_type* c) + { + os << (void*)c; + + return os; + } + SUITE(test_string_char) { static constexpr size_t SIZE = 11; diff --git a/test/vs2019/etl.vcxproj b/test/vs2019/etl.vcxproj index 666be5f3..e19e5ae9 100644 --- a/test/vs2019/etl.vcxproj +++ b/test/vs2019/etl.vcxproj @@ -810,7 +810,7 @@ Level3 Disabled - WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;ETL_CPP20_ENABLED;%(PreprocessorDefinitions) ../../../unittest-cpp/;../../include;../../test From e6736404ed82654f4fff04c90ebf2f7da25a9af1 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 8 Jan 2022 18:51:35 +0000 Subject: [PATCH 15/15] Final code after local CI tests --- .gitignore | 1 + include/etl/bit.h | 90 +-- include/etl/functional.h | 62 +- include/etl/numeric.h | 10 +- test/CMakeLists.txt | 2 + test/etl_profile.h | 1 - test/sanity-check/bit.h.t.cpp | 29 + test/sanity-check/c++03/CMakeLists.txt | 2 + test/sanity-check/c++03/etl_profile.h | 1 + test/sanity-check/c++11/CMakeLists.txt | 2 + test/sanity-check/c++11/etl_profile.h | 1 + test/sanity-check/c++14/CMakeLists.txt | 2 + test/sanity-check/c++14/etl_profile.h | 1 + test/sanity-check/c++17/CMakeLists.txt | 2 + test/sanity-check/c++17/etl_profile.h | 1 + test/sanity-check/unaligned_type.h.t.cpp | 29 + test/test_algorithm.cpp | 8 +- test/vs2019/etl.sln | 6 + test/vs2019/etl.vcxproj | 685 +++++++++++++++++++++++ test/vs2019/etl.vcxproj.filters | 6 + 20 files changed, 853 insertions(+), 88 deletions(-) create mode 100644 test/sanity-check/bit.h.t.cpp create mode 100644 test/sanity-check/unaligned_type.h.t.cpp diff --git a/.gitignore b/.gitignore index d9727519..60f1643d 100644 --- a/.gitignore +++ b/.gitignore @@ -345,3 +345,4 @@ test/meson-private test/build-make test/build-ninja test/vs2019/Debug MSVC C++20 +test/vs2019/Debug MSVC C++20 - No STL diff --git a/include/etl/bit.h b/include/etl/bit.h index eea7510c..844456d0 100644 --- a/include/etl/bit.h +++ b/include/etl/bit.h @@ -90,6 +90,50 @@ namespace etl { return (value & (value - 1)) == 0; } + //*************************************************************************** + /// countl_zero + //*************************************************************************** + template + ETL_NODISCARD ETL_CONSTEXPR14 + typename etl::enable_if::value, int>::type + countl_zero(T value) ETL_NOEXCEPT + { + return etl::count_leading_zeros(value); + } + + //*************************************************************************** + /// countl_one + //*************************************************************************** + template + ETL_NODISCARD ETL_CONSTEXPR14 + typename etl::enable_if::value, int>::type + countl_one(T value) ETL_NOEXCEPT + { + return etl::count_leading_ones(value); + } + + //*************************************************************************** + /// countr_zero + //*************************************************************************** + template + ETL_NODISCARD ETL_CONSTEXPR14 + typename etl::enable_if::value, int>::type + countr_zero(T value) ETL_NOEXCEPT + { + return etl::count_trailing_zeros(value); + } + + //*************************************************************************** + /// countr_one + //*************************************************************************** + template + ETL_NODISCARD ETL_CONSTEXPR14 + typename etl::enable_if::value, int>::type + countr_one(T value) ETL_NOEXCEPT + { + return etl::count_trailing_ones(value);; + } + //*************************************************************************** /// bit_width @@ -189,51 +233,7 @@ namespace etl return etl::rotate_right(value, n); } } - - //*************************************************************************** - /// countl_zero - //*************************************************************************** - template - ETL_NODISCARD ETL_CONSTEXPR14 - typename etl::enable_if::value, int>::type - countl_zero(T value) ETL_NOEXCEPT - { - return etl::count_leading_zeros(value); - } - - //*************************************************************************** - /// countl_one - //*************************************************************************** - template - ETL_NODISCARD ETL_CONSTEXPR14 - typename etl::enable_if::value, int>::type - countl_one(T value) ETL_NOEXCEPT - { - return etl::count_leading_ones(value); - } - - //*************************************************************************** - /// countr_zero - //*************************************************************************** - template - ETL_NODISCARD ETL_CONSTEXPR14 - typename etl::enable_if::value, int>::type - countr_zero(T value) ETL_NOEXCEPT - { - return etl::count_trailing_zeros(value); - } - - //*************************************************************************** - /// countr_one - //*************************************************************************** - template - ETL_NODISCARD ETL_CONSTEXPR14 - typename etl::enable_if::value, int>::type - countr_one(T value) ETL_NOEXCEPT - { - return etl::count_trailing_ones(value);; - } - + //*************************************************************************** /// popcount //*************************************************************************** diff --git a/include/etl/functional.h b/include/etl/functional.h index 1559161e..ce7300c2 100644 --- a/include/etl/functional.h +++ b/include/etl/functional.h @@ -106,9 +106,26 @@ namespace etl return reference_wrapper(t.get()); } + //*************************************************************************** + template + struct unary_function + { + typedef TArgumentType argument_type; + typedef TResultType result_type; + }; + + //*************************************************************************** + template + struct binary_function + { + typedef TFirstArgumentType first_argument_type; + typedef TSecondArgumentType second_argument_type; + typedef TResultType result_type; + }; + //*************************************************************************** template - struct less + struct less : public etl::binary_function { typedef T value_type; @@ -120,7 +137,7 @@ namespace etl #if ETL_CPP11_SUPPORTED template <> - struct less + struct less : public etl::binary_function { typedef int is_transparent; @@ -134,7 +151,7 @@ namespace etl //*************************************************************************** template - struct less_equal + struct less_equal : public etl::binary_function { typedef T value_type; @@ -144,10 +161,9 @@ namespace etl } }; - #if ETL_CPP11_SUPPORTED template <> - struct less_equal + struct less_equal : public etl::binary_function { typedef int is_transparent; @@ -161,7 +177,7 @@ namespace etl //*************************************************************************** template - struct greater + struct greater : public etl::binary_function { typedef T value_type; @@ -173,7 +189,7 @@ namespace etl #if ETL_CPP11_SUPPORTED template <> - struct greater + struct greater : public etl::binary_function { typedef int is_transparent; @@ -187,7 +203,7 @@ namespace etl //*************************************************************************** template - struct greater_equal + struct greater_equal : public etl::binary_function { typedef T value_type; @@ -199,7 +215,7 @@ namespace etl #if ETL_CPP11_SUPPORTED template <> - struct greater_equal + struct greater_equal : public etl::binary_function { typedef int is_transparent; @@ -213,7 +229,7 @@ namespace etl //*************************************************************************** template - struct equal_to + struct equal_to : public etl::binary_function { typedef T value_type; @@ -225,7 +241,7 @@ namespace etl #if ETL_CPP11_SUPPORTED template <> - struct equal_to + struct equal_to : public etl::binary_function { typedef void value_type; typedef int is_transparent; @@ -240,7 +256,7 @@ namespace etl //*************************************************************************** template - struct not_equal_to + struct not_equal_to : public etl::binary_function { typedef T value_type; @@ -252,7 +268,7 @@ namespace etl #if ETL_CPP11_SUPPORTED template <> - struct not_equal_to + struct not_equal_to : public etl::binary_function { typedef int is_transparent; @@ -265,26 +281,6 @@ namespace etl #endif //*************************************************************************** - - template - struct unary_function - { - typedef TArgumentType argument_type; - typedef TResultType result_type; - }; - - //*************************************************************************** - - template - struct binary_function - { - typedef TFirstArgumentType first_argument_type; - typedef TSecondArgumentType second_argument_type; - typedef TResultType result_type; - }; - - //*************************************************************************** - template class binder1st : public etl::unary_function { diff --git a/include/etl/numeric.h b/include/etl/numeric.h index a72c6858..f274635c 100644 --- a/include/etl/numeric.h +++ b/include/etl/numeric.h @@ -201,11 +201,11 @@ namespace etl /// For when any parameter is not floating point. //*************************************************************************** template - ETL_CONSTEXPR typename etl::enable_if_t::value || - !etl::is_floating_point::value || - !etl::is_floating_point::value, typename etl::conditional::value || - etl::is_same::value || - etl::is_same::value, long double, double>::type> + ETL_CONSTEXPR typename etl::enable_if::value || + !etl::is_floating_point::value || + !etl::is_floating_point::value, typename etl::conditional::value || + etl::is_same::value || + etl::is_same::value, long double, double>::type>::type lerp(TArithmetic1 a, TArithmetic2 b, TArithmetic3 t) ETL_NOEXCEPT { typedef typename etl::conditional::value, double, TArithmetic1>::type typecast_a; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 43b9c5f3..f8a755c8 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -48,6 +48,7 @@ set(TEST_SOURCE_FILES test_atomic_std.cpp test_binary.cpp test_bip_buffer_spsc_atomic.cpp + test_bit.cpp test_bitset.cpp test_bit_stream.cpp test_byte_stream.cpp @@ -254,6 +255,7 @@ set(TEST_SOURCE_FILES test_type_lookup.cpp test_type_select.cpp test_type_traits.cpp +# test_unaligned_type.cpp test_unordered_map.cpp test_unordered_multimap.cpp test_unordered_multiset.cpp diff --git a/test/etl_profile.h b/test/etl_profile.h index 0f050628..bde20732 100644 --- a/test/etl_profile.h +++ b/test/etl_profile.h @@ -79,7 +79,6 @@ SOFTWARE. #define ETL_CPP20_SUPPORTED 0 #endif - //#define ETL_POLYMORPHIC_CONTAINERS //#define ETL_MESSAGES_ARE_VIRTUAL diff --git a/test/sanity-check/bit.h.t.cpp b/test/sanity-check/bit.h.t.cpp new file mode 100644 index 00000000..74493814 --- /dev/null +++ b/test/sanity-check/bit.h.t.cpp @@ -0,0 +1,29 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2022 John Wellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include diff --git a/test/sanity-check/c++03/CMakeLists.txt b/test/sanity-check/c++03/CMakeLists.txt index 66e5ec06..9f761199 100644 --- a/test/sanity-check/c++03/CMakeLists.txt +++ b/test/sanity-check/c++03/CMakeLists.txt @@ -49,6 +49,7 @@ target_sources(t98 PRIVATE etl_profile.h ../basic_string_stream.h.t.cpp ../binary.h.t.cpp ../bip_buffer_spsc_atomic.h.t.cpp + ../bit.h.t.cpp ../bitset.h.t.cpp ../bit_stream.h.t.cpp ../byte_stream.h.t.cpp @@ -258,6 +259,7 @@ target_sources(t98 PRIVATE etl_profile.h ../u32format_spec.h.t.cpp ../u32string.h.t.cpp ../u32string_stream.h.t.cpp + #../unaligned_type.h.t.cpp ../unordered_map.h.t.cpp ../unordered_multimap.h.t.cpp ../unordered_multiset.h.t.cpp diff --git a/test/sanity-check/c++03/etl_profile.h b/test/sanity-check/c++03/etl_profile.h index a16d2298..683af364 100644 --- a/test/sanity-check/c++03/etl_profile.h +++ b/test/sanity-check/c++03/etl_profile.h @@ -34,6 +34,7 @@ SOFTWARE. #define ETL_CPP11_SUPPORTED 0 #define ETL_CPP14_SUPPORTED 0 #define ETL_CPP17_SUPPORTED 0 +#define ETL_CPP20_SUPPORTED 0 #define ETL_IN_UNIT_TEST #define ETL_CALLBACK_TIMER_USE_INTERRUPT_LOCK #define ETL_CALLBACK_TIMER_DISABLE_INTERRUPTS diff --git a/test/sanity-check/c++11/CMakeLists.txt b/test/sanity-check/c++11/CMakeLists.txt index a914b437..19c7a565 100644 --- a/test/sanity-check/c++11/CMakeLists.txt +++ b/test/sanity-check/c++11/CMakeLists.txt @@ -49,6 +49,7 @@ target_sources(t11 PRIVATE etl_profile.h ../basic_string_stream.h.t.cpp ../binary.h.t.cpp ../bip_buffer_spsc_atomic.h.t.cpp + ../bit.h.t.cpp ../bitset.h.t.cpp ../bit_stream.h.t.cpp ../byte_stream.h.t.cpp @@ -258,6 +259,7 @@ target_sources(t11 PRIVATE etl_profile.h ../u32format_spec.h.t.cpp ../u32string.h.t.cpp ../u32string_stream.h.t.cpp + #../unaligned_type.h.t.cpp ../unordered_map.h.t.cpp ../unordered_multimap.h.t.cpp ../unordered_multiset.h.t.cpp diff --git a/test/sanity-check/c++11/etl_profile.h b/test/sanity-check/c++11/etl_profile.h index 54a6f1e1..729ddaa2 100644 --- a/test/sanity-check/c++11/etl_profile.h +++ b/test/sanity-check/c++11/etl_profile.h @@ -34,6 +34,7 @@ SOFTWARE. #define ETL_CPP11_SUPPORTED 1 #define ETL_CPP14_SUPPORTED 0 #define ETL_CPP17_SUPPORTED 0 +#define ETL_CPP20_SUPPORTED 0 #define ETL_IN_UNIT_TEST #define ETL_CALLBACK_TIMER_USE_INTERRUPT_LOCK #define ETL_CALLBACK_TIMER_DISABLE_INTERRUPTS diff --git a/test/sanity-check/c++14/CMakeLists.txt b/test/sanity-check/c++14/CMakeLists.txt index 0fba265c..35131435 100644 --- a/test/sanity-check/c++14/CMakeLists.txt +++ b/test/sanity-check/c++14/CMakeLists.txt @@ -49,6 +49,7 @@ target_sources(t14 PRIVATE etl_profile.h ../basic_string_stream.h.t.cpp ../binary.h.t.cpp ../bip_buffer_spsc_atomic.h.t.cpp + ../bit.h.t.cpp ../bitset.h.t.cpp ../bit_stream.h.t.cpp ../byte_stream.h.t.cpp @@ -258,6 +259,7 @@ target_sources(t14 PRIVATE etl_profile.h ../u32format_spec.h.t.cpp ../u32string.h.t.cpp ../u32string_stream.h.t.cpp + #../unaligned_type.h.t.cpp ../unordered_map.h.t.cpp ../unordered_multimap.h.t.cpp ../unordered_multiset.h.t.cpp diff --git a/test/sanity-check/c++14/etl_profile.h b/test/sanity-check/c++14/etl_profile.h index 652b501c..51205160 100644 --- a/test/sanity-check/c++14/etl_profile.h +++ b/test/sanity-check/c++14/etl_profile.h @@ -34,6 +34,7 @@ SOFTWARE. #define ETL_CPP11_SUPPORTED 1 #define ETL_CPP14_SUPPORTED 1 #define ETL_CPP17_SUPPORTED 0 +#define ETL_CPP20_SUPPORTED 0 #define ETL_IN_UNIT_TEST #define ETL_CALLBACK_TIMER_USE_INTERRUPT_LOCK #define ETL_CALLBACK_TIMER_DISABLE_INTERRUPTS diff --git a/test/sanity-check/c++17/CMakeLists.txt b/test/sanity-check/c++17/CMakeLists.txt index eb0b4679..77f3f6e6 100644 --- a/test/sanity-check/c++17/CMakeLists.txt +++ b/test/sanity-check/c++17/CMakeLists.txt @@ -49,6 +49,7 @@ target_sources(t17 PRIVATE etl_profile.h ../basic_string_stream.h.t.cpp ../binary.h.t.cpp ../bip_buffer_spsc_atomic.h.t.cpp + ../bit.h.t.cpp ../bitset.h.t.cpp ../bit_stream.h.t.cpp ../byte_stream.h.t.cpp @@ -258,6 +259,7 @@ target_sources(t17 PRIVATE etl_profile.h ../u32format_spec.h.t.cpp ../u32string.h.t.cpp ../u32string_stream.h.t.cpp + #../unaligned_type.h.t.cpp ../unordered_map.h.t.cpp ../unordered_multimap.h.t.cpp ../unordered_multiset.h.t.cpp diff --git a/test/sanity-check/c++17/etl_profile.h b/test/sanity-check/c++17/etl_profile.h index cc9973f1..624065dc 100644 --- a/test/sanity-check/c++17/etl_profile.h +++ b/test/sanity-check/c++17/etl_profile.h @@ -34,6 +34,7 @@ SOFTWARE. #define ETL_CPP11_SUPPORTED 1 #define ETL_CPP14_SUPPORTED 1 #define ETL_CPP17_SUPPORTED 1 +#define ETL_CPP20_SUPPORTED 0 #define ETL_IN_UNIT_TEST #define ETL_CALLBACK_TIMER_USE_INTERRUPT_LOCK #define ETL_CALLBACK_TIMER_DISABLE_INTERRUPTS diff --git a/test/sanity-check/unaligned_type.h.t.cpp b/test/sanity-check/unaligned_type.h.t.cpp new file mode 100644 index 00000000..841f0d81 --- /dev/null +++ b/test/sanity-check/unaligned_type.h.t.cpp @@ -0,0 +1,29 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2022 John Wellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include diff --git a/test/test_algorithm.cpp b/test/test_algorithm.cpp index 8c30281a..604feca0 100644 --- a/test/test_algorithm.cpp +++ b/test/test_algorithm.cpp @@ -1203,10 +1203,10 @@ namespace is_permutation = etl::is_permutation(std::begin(data1), std::end(data1), std::begin(not_permutation)); CHECK(!is_permutation); - is_permutation = etl::is_permutation(std::begin(data1), std::end(data1), std::begin(permutation), std::equal_to()); + is_permutation = etl::is_permutation(std::begin(data1), std::end(data1), std::begin(permutation), etl::equal_to()); CHECK(is_permutation); - is_permutation = etl::is_permutation(std::begin(data1), std::end(data1), std::begin(not_permutation), std::equal_to()); + is_permutation = etl::is_permutation(std::begin(data1), std::end(data1), std::begin(not_permutation), etl::equal_to()); CHECK(!is_permutation); is_permutation = etl::is_permutation(std::begin(data1), std::end(data1), std::begin(permutation), std::end(permutation)); @@ -1215,10 +1215,10 @@ namespace is_permutation = etl::is_permutation(std::begin(data1), std::end(data1), std::begin(not_permutation), std::end(not_permutation)); CHECK(!is_permutation); - is_permutation = etl::is_permutation(std::begin(data1), std::end(data1), std::begin(permutation), std::end(permutation), std::equal_to()); + is_permutation = etl::is_permutation(std::begin(data1), std::end(data1), std::begin(permutation), std::end(permutation), etl::equal_to()); CHECK(is_permutation); - is_permutation = etl::is_permutation(std::begin(data1), std::end(data1), std::begin(not_permutation), std::end(not_permutation), std::equal_to()); + is_permutation = etl::is_permutation(std::begin(data1), std::end(data1), std::begin(not_permutation), std::end(not_permutation), etl::equal_to()); CHECK(!is_permutation); } diff --git a/test/vs2019/etl.sln b/test/vs2019/etl.sln index f1035dd7..4a418323 100644 --- a/test/vs2019/etl.sln +++ b/test/vs2019/etl.sln @@ -29,6 +29,8 @@ Global Debug MSVC - String Truncation Is Error|x64 = Debug MSVC - String Truncation Is Error|x64 Debug MSVC 64|Win32 = Debug MSVC 64|Win32 Debug MSVC 64|x64 = Debug MSVC 64|x64 + Debug MSVC C++20 - No STL|Win32 = Debug MSVC C++20 - No STL|Win32 + Debug MSVC C++20 - No STL|x64 = Debug MSVC C++20 - No STL|x64 Debug MSVC C++20|Win32 = Debug MSVC C++20|Win32 Debug MSVC C++20|x64 = Debug MSVC C++20|x64 Debug MSVC No Checks|Win32 = Debug MSVC No Checks|Win32 @@ -87,6 +89,10 @@ Global {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC 64|Win32.Build.0 = Debug No Unit Tests|Win32 {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC 64|x64.ActiveCfg = Debug64|x64 {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC 64|x64.Build.0 = Debug64|x64 + {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++20 - No STL|Win32.ActiveCfg = Debug MSVC C++20 - No STL|Win32 + {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++20 - No STL|Win32.Build.0 = Debug MSVC C++20 - No STL|Win32 + {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++20 - No STL|x64.ActiveCfg = Debug MSVC C++20 - No STL|x64 + {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++20 - No STL|x64.Build.0 = Debug MSVC C++20 - No STL|x64 {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++20|Win32.ActiveCfg = Debug MSVC C++20|Win32 {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++20|Win32.Build.0 = Debug MSVC C++20|Win32 {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++20|x64.ActiveCfg = Debug MSVC C++20|x64 diff --git a/test/vs2019/etl.vcxproj b/test/vs2019/etl.vcxproj index e19e5ae9..2e11d28d 100644 --- a/test/vs2019/etl.vcxproj +++ b/test/vs2019/etl.vcxproj @@ -17,6 +17,14 @@ Debug LLVM - No STL - Built-ins x64 + + Debug LLVM C++20 + Win32 + + + Debug LLVM C++20 + x64 + Debug LLVM Win32 @@ -65,6 +73,14 @@ Debug MSVC - No Checks x64 + + Debug MSVC C++20 - No STL + Win32 + + + Debug MSVC C++20 - No STL + x64 + Debug MSVC C++20 Win32 @@ -176,6 +192,13 @@ Unicode false + + Application + true + v142 + Unicode + false + Application true @@ -252,6 +275,12 @@ ClangCL Unicode + + Application + true + ClangCL + Unicode + Application true @@ -294,6 +323,12 @@ v142 Unicode + + Application + true + v142 + Unicode + Application true @@ -366,6 +401,12 @@ v142 Unicode + + Application + true + v142 + Unicode + Application true @@ -449,6 +490,9 @@ + + + @@ -485,6 +529,9 @@ + + + @@ -506,6 +553,9 @@ + + + @@ -542,6 +592,9 @@ + + + @@ -586,6 +639,11 @@ true $(Configuration)\ + + true + true + $(Configuration)\ + true true @@ -652,6 +710,11 @@ true $(Configuration)\ + + false + true + $(Configuration)\ + false true @@ -685,6 +748,10 @@ true true + + true + true + true true @@ -737,6 +804,10 @@ true true + + true + true + true true @@ -826,6 +897,28 @@ "$(OutDir)\etl.exe" + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;ETL_CPP20_ENABLED;ETL_NO_STL;%(PreprocessorDefinitions) + ../../../unittest-cpp/;../../include;../../test + + + true + stdcpp20 + EditAndContinue + + + Console + true + + + "$(OutDir)\etl.exe" + + @@ -1085,6 +1178,30 @@ "$(OutDir)etl.exe" + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;__clang__;ETL_CPP20_ENABLED;%(PreprocessorDefinitions) + ../../../unittest-cpp/;../../include;../../test + + + false + stdcpp20 + false + ProgramDatabase + -Wno-self-assign /Zc:__cplusplus %(AdditionalOptions) + + + Console + false + + + "$(OutDir)etl.exe" + + @@ -1271,6 +1388,27 @@ $(OutDir)\etl.exe + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + ../../unittest-cpp/UnitTest++/;../../include/etl;../../test + + + false + stdcpp14 + + + Console + true + + + $(OutDir)\etl.exe + + @@ -1523,6 +1661,27 @@ $(OutDir)\etl.exe + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + ../../unittest-cpp/UnitTest++/;../../include/etl;../../test + + + false + stdcpp14 + + + Console + true + + + $(OutDir)\etl.exe + + @@ -2135,6 +2294,7 @@ true true + true true true true @@ -2146,6 +2306,7 @@ true true true + true true true true @@ -2160,6 +2321,7 @@ true true + true true true true @@ -2171,6 +2333,7 @@ true true true + true true true true @@ -2185,6 +2348,7 @@ true true + true true true true @@ -2196,6 +2360,7 @@ true true true + true true true true @@ -2210,6 +2375,7 @@ true true + true true true true @@ -2221,6 +2387,7 @@ true true true + true true true true @@ -2235,6 +2402,7 @@ true true + true true true true @@ -2246,6 +2414,7 @@ true true true + true true true true @@ -2260,6 +2429,7 @@ true true + true true true true @@ -2271,6 +2441,7 @@ true true true + true true true true @@ -2285,6 +2456,7 @@ true true + true true true true @@ -2296,6 +2468,7 @@ true true true + true true true true @@ -2310,6 +2483,7 @@ true true + true true true true @@ -2321,6 +2495,7 @@ true true true + true true true true @@ -2335,6 +2510,7 @@ true true + true true true true @@ -2346,6 +2522,7 @@ true true true + true true true true @@ -2360,6 +2537,7 @@ true true + true true true true @@ -2371,6 +2549,7 @@ true true true + true true true true @@ -2385,6 +2564,7 @@ true true + true true true true @@ -2396,6 +2576,7 @@ true true true + true true true true @@ -2410,6 +2591,7 @@ true true + true true true true @@ -2420,6 +2602,7 @@ true true true + true true true true @@ -2429,9 +2612,13 @@ true true + + true + true true + true true true true @@ -2443,6 +2630,7 @@ true true true + true true true true @@ -2457,6 +2645,7 @@ true true + true true true true @@ -2468,6 +2657,7 @@ true true true + true true true true @@ -2482,6 +2672,7 @@ true true + true true true true @@ -2493,6 +2684,7 @@ true true true + true true true true @@ -2507,6 +2699,7 @@ true true + true true true true @@ -2518,6 +2711,7 @@ true true true + true true true true @@ -2532,6 +2726,7 @@ true true + true true true true @@ -2543,6 +2738,7 @@ true true true + true true true true @@ -2557,12 +2753,14 @@ true true + true true true true true true true + true true true true @@ -2578,6 +2776,7 @@ true true + true true true true @@ -2589,6 +2788,7 @@ true true true + true true true true @@ -2603,6 +2803,7 @@ true true + true true true true @@ -2614,6 +2815,7 @@ true true true + true true true true @@ -2628,6 +2830,7 @@ true true + true true true true @@ -2639,6 +2842,7 @@ true true true + true true true true @@ -2653,12 +2857,14 @@ true true + true true true true true true true + true true true true @@ -2674,6 +2880,7 @@ true true + true true true true @@ -2685,6 +2892,7 @@ true true true + true true true true @@ -2699,6 +2907,7 @@ true true + true true true true @@ -2710,6 +2919,7 @@ true true true + true true true true @@ -2724,6 +2934,7 @@ true true + true true true true @@ -2735,6 +2946,7 @@ true true true + true true true true @@ -2749,6 +2961,7 @@ true true + true true true true @@ -2760,6 +2973,7 @@ true true true + true true true true @@ -2774,6 +2988,7 @@ true true + true true true true @@ -2785,6 +3000,7 @@ true true true + true true true true @@ -2799,6 +3015,7 @@ true true + true true true true @@ -2810,6 +3027,7 @@ true true true + true true true true @@ -2824,6 +3042,7 @@ true true + true true true true @@ -2835,6 +3054,7 @@ true true true + true true true true @@ -2849,6 +3069,7 @@ true true + true true true true @@ -2860,6 +3081,7 @@ true true true + true true true true @@ -2874,6 +3096,7 @@ true true + true true true true @@ -2885,6 +3108,7 @@ true true true + true true true true @@ -2899,6 +3123,7 @@ true true + true true true true @@ -2910,6 +3135,7 @@ true true true + true true true true @@ -2924,6 +3150,7 @@ true true + true true true true @@ -2935,6 +3162,7 @@ true true true + true true true true @@ -2949,6 +3177,7 @@ true true + true true true true @@ -2960,6 +3189,7 @@ true true true + true true true true @@ -2974,6 +3204,7 @@ true true + true true true true @@ -2985,6 +3216,7 @@ true true true + true true true true @@ -2999,6 +3231,7 @@ true true + true true true true @@ -3010,6 +3243,7 @@ true true true + true true true true @@ -3024,6 +3258,7 @@ true true + true true true true @@ -3035,6 +3270,7 @@ true true true + true true true true @@ -3049,6 +3285,7 @@ true true + true true true true @@ -3060,6 +3297,7 @@ true true true + true true true true @@ -3074,6 +3312,7 @@ true true + true true true true @@ -3085,6 +3324,7 @@ true true true + true true true true @@ -3099,6 +3339,7 @@ true true + true true true true @@ -3110,6 +3351,7 @@ true true true + true true true true @@ -3124,6 +3366,7 @@ true true + true true true true @@ -3135,6 +3378,7 @@ true true true + true true true true @@ -3149,6 +3393,7 @@ true true + true true true true @@ -3160,6 +3405,7 @@ true true true + true true true true @@ -3174,6 +3420,7 @@ true true + true true true true @@ -3185,6 +3432,7 @@ true true true + true true true true @@ -3199,6 +3447,7 @@ true true + true true true true @@ -3210,6 +3459,7 @@ true true true + true true true true @@ -3224,6 +3474,7 @@ true true + true true true true @@ -3235,6 +3486,7 @@ true true true + true true true true @@ -3249,6 +3501,7 @@ true true + true true true true @@ -3260,6 +3513,7 @@ true true true + true true true true @@ -3274,6 +3528,7 @@ true true + true true true true @@ -3285,6 +3540,7 @@ true true true + true true true true @@ -3299,6 +3555,7 @@ true true + true true true true @@ -3310,6 +3567,7 @@ true true true + true true true true @@ -3324,6 +3582,7 @@ true true + true true true true @@ -3335,6 +3594,7 @@ true true true + true true true true @@ -3349,6 +3609,7 @@ true true + true true true true @@ -3360,6 +3621,7 @@ true true true + true true true true @@ -3374,6 +3636,7 @@ true true + true true true true @@ -3385,6 +3648,7 @@ true true true + true true true true @@ -3399,6 +3663,7 @@ true true + true true true true @@ -3410,6 +3675,7 @@ true true true + true true true true @@ -3424,6 +3690,7 @@ true true + true true true true @@ -3435,6 +3702,7 @@ true true true + true true true true @@ -3449,6 +3717,7 @@ true true + true true true true @@ -3460,6 +3729,7 @@ true true true + true true true true @@ -3474,6 +3744,7 @@ true true + true true true true @@ -3485,6 +3756,7 @@ true true true + true true true true @@ -3499,6 +3771,7 @@ true true + true true true true @@ -3510,6 +3783,7 @@ true true true + true true true true @@ -3524,6 +3798,7 @@ true true + true true true true @@ -3535,6 +3810,7 @@ true true true + true true true true @@ -3549,6 +3825,7 @@ true true + true true true true @@ -3560,6 +3837,7 @@ true true true + true true true true @@ -3574,6 +3852,7 @@ true true + true true true true @@ -3585,6 +3864,7 @@ true true true + true true true true @@ -3599,6 +3879,7 @@ true true + true true true true @@ -3610,6 +3891,7 @@ true true true + true true true true @@ -3624,6 +3906,7 @@ true true + true true true true @@ -3635,6 +3918,7 @@ true true true + true true true true @@ -3649,6 +3933,7 @@ true true + true true true true @@ -3660,6 +3945,7 @@ true true true + true true true true @@ -3674,6 +3960,7 @@ true true + true true true true @@ -3685,6 +3972,7 @@ true true true + true true true true @@ -3699,6 +3987,7 @@ true true + true true true true @@ -3710,6 +3999,7 @@ true true true + true true true true @@ -3724,6 +4014,7 @@ true true + true true true true @@ -3735,6 +4026,7 @@ true true true + true true true true @@ -3749,6 +4041,7 @@ true true + true true true true @@ -3760,6 +4053,7 @@ true true true + true true true true @@ -3774,6 +4068,7 @@ true true + true true true true @@ -3785,6 +4080,7 @@ true true true + true true true true @@ -3799,6 +4095,7 @@ true true + true true true true @@ -3810,6 +4107,7 @@ true true true + true true true true @@ -3824,6 +4122,7 @@ true true + true true true true @@ -3835,6 +4134,7 @@ true true true + true true true true @@ -3849,6 +4149,7 @@ true true + true true true true @@ -3860,6 +4161,7 @@ true true true + true true true true @@ -3874,6 +4176,7 @@ true true + true true true true @@ -3885,6 +4188,7 @@ true true true + true true true true @@ -3899,6 +4203,7 @@ true true + true true true true @@ -3910,6 +4215,7 @@ true true true + true true true true @@ -3924,6 +4230,7 @@ true true + true true true true @@ -3935,6 +4242,7 @@ true true true + true true true true @@ -3949,6 +4257,7 @@ true true + true true true true @@ -3960,6 +4269,7 @@ true true true + true true true true @@ -3974,6 +4284,7 @@ true true + true true true true @@ -3985,6 +4296,7 @@ true true true + true true true true @@ -3999,6 +4311,7 @@ true true + true true true true @@ -4010,6 +4323,7 @@ true true true + true true true true @@ -4024,6 +4338,7 @@ true true + true true true true @@ -4035,6 +4350,7 @@ true true true + true true true true @@ -4049,6 +4365,7 @@ true true + true true true true @@ -4060,6 +4377,7 @@ true true true + true true true true @@ -4074,6 +4392,7 @@ true true + true true true true @@ -4085,6 +4404,7 @@ true true true + true true true true @@ -4099,6 +4419,7 @@ true true + true true true true @@ -4110,6 +4431,7 @@ true true true + true true true true @@ -4124,6 +4446,7 @@ true true + true true true true @@ -4135,6 +4458,7 @@ true true true + true true true true @@ -4149,6 +4473,7 @@ true true + true true true true @@ -4160,6 +4485,7 @@ true true true + true true true true @@ -4174,6 +4500,7 @@ true true + true true true true @@ -4185,6 +4512,7 @@ true true true + true true true true @@ -4199,6 +4527,7 @@ true true + true true true true @@ -4210,6 +4539,7 @@ true true true + true true true true @@ -4224,6 +4554,7 @@ true true + true true true true @@ -4235,6 +4566,7 @@ true true true + true true true true @@ -4249,6 +4581,7 @@ true true + true true true true @@ -4260,6 +4593,7 @@ true true true + true true true true @@ -4274,6 +4608,7 @@ true true + true true true true @@ -4285,6 +4620,7 @@ true true true + true true true true @@ -4299,6 +4635,7 @@ true true + true true true true @@ -4310,6 +4647,7 @@ true true true + true true true true @@ -4324,6 +4662,7 @@ true true + true true true true @@ -4335,6 +4674,7 @@ true true true + true true true true @@ -4349,6 +4689,7 @@ true true + true true true true @@ -4360,6 +4701,7 @@ true true true + true true true true @@ -4374,6 +4716,7 @@ true true + true true true true @@ -4385,6 +4728,7 @@ true true true + true true true true @@ -4399,6 +4743,7 @@ true true + true true true true @@ -4410,6 +4755,7 @@ true true true + true true true true @@ -4424,6 +4770,7 @@ true true + true true true true @@ -4435,6 +4782,7 @@ true true true + true true true true @@ -4449,6 +4797,7 @@ true true + true true true true @@ -4460,6 +4809,7 @@ true true true + true true true true @@ -4474,6 +4824,7 @@ true true + true true true true @@ -4485,6 +4836,7 @@ true true true + true true true true @@ -4499,6 +4851,7 @@ true true + true true true true @@ -4510,6 +4863,7 @@ true true true + true true true true @@ -4524,6 +4878,7 @@ true true + true true true true @@ -4535,6 +4890,7 @@ true true true + true true true true @@ -4549,6 +4905,7 @@ true true + true true true true @@ -4560,6 +4917,7 @@ true true true + true true true true @@ -4574,6 +4932,7 @@ true true + true true true true @@ -4585,6 +4944,7 @@ true true true + true true true true @@ -4599,6 +4959,7 @@ true true + true true true true @@ -4610,6 +4971,7 @@ true true true + true true true true @@ -4624,6 +4986,7 @@ true true + true true true true @@ -4635,6 +4998,7 @@ true true true + true true true true @@ -4649,6 +5013,7 @@ true true + true true true true @@ -4660,6 +5025,7 @@ true true true + true true true true @@ -4674,6 +5040,7 @@ true true + true true true true @@ -4685,6 +5052,7 @@ true true true + true true true true @@ -4699,6 +5067,7 @@ true true + true true true true @@ -4710,6 +5079,7 @@ true true true + true true true true @@ -4724,6 +5094,7 @@ true true + true true true true @@ -4735,6 +5106,7 @@ true true true + true true true true @@ -4749,6 +5121,7 @@ true true + true true true true @@ -4760,6 +5133,7 @@ true true true + true true true true @@ -4774,6 +5148,7 @@ true true + true true true true @@ -4785,6 +5160,7 @@ true true true + true true true true @@ -4799,6 +5175,7 @@ true true + true true true true @@ -4810,6 +5187,7 @@ true true true + true true true true @@ -4824,6 +5202,7 @@ true true + true true true true @@ -4835,6 +5214,7 @@ true true true + true true true true @@ -4849,6 +5229,7 @@ true true + true true true true @@ -4860,6 +5241,7 @@ true true true + true true true true @@ -4874,6 +5256,7 @@ true true + true true true true @@ -4885,6 +5268,7 @@ true true true + true true true true @@ -4899,6 +5283,7 @@ true true + true true true true @@ -4910,6 +5295,7 @@ true true true + true true true true @@ -4924,6 +5310,7 @@ true true + true true true true @@ -4935,6 +5322,7 @@ true true true + true true true true @@ -4949,6 +5337,7 @@ true true + true true true true @@ -4960,6 +5349,7 @@ true true true + true true true true @@ -4974,6 +5364,7 @@ true true + true true true true @@ -4985,6 +5376,7 @@ true true true + true true true true @@ -4999,6 +5391,7 @@ true true + true true true true @@ -5010,6 +5403,7 @@ true true true + true true true true @@ -5024,6 +5418,7 @@ true true + true true true true @@ -5035,6 +5430,7 @@ true true true + true true true true @@ -5049,6 +5445,7 @@ true true + true true true true @@ -5060,6 +5457,7 @@ true true true + true true true true @@ -5074,6 +5472,7 @@ true true + true true true true @@ -5085,6 +5484,7 @@ true true true + true true true true @@ -5099,6 +5499,7 @@ true true + true true true true @@ -5110,6 +5511,7 @@ true true true + true true true true @@ -5124,6 +5526,7 @@ true true + true true true true @@ -5135,6 +5538,7 @@ true true true + true true true true @@ -5149,6 +5553,7 @@ true true + true true true true @@ -5160,6 +5565,7 @@ true true true + true true true true @@ -5174,6 +5580,7 @@ true true + true true true true @@ -5185,6 +5592,7 @@ true true true + true true true true @@ -5199,6 +5607,7 @@ true true + true true true true @@ -5210,6 +5619,7 @@ true true true + true true true true @@ -5224,6 +5634,7 @@ true true + true true true true @@ -5235,6 +5646,7 @@ true true true + true true true true @@ -5249,6 +5661,7 @@ true true + true true true true @@ -5260,6 +5673,7 @@ true true true + true true true true @@ -5274,6 +5688,7 @@ true true + true true true true @@ -5285,6 +5700,7 @@ true true true + true true true true @@ -5299,6 +5715,7 @@ true true + true true true true @@ -5310,6 +5727,7 @@ true true true + true true true true @@ -5324,6 +5742,7 @@ true true + true true true true @@ -5335,6 +5754,7 @@ true true true + true true true true @@ -5349,6 +5769,7 @@ true true + true true true true @@ -5360,6 +5781,7 @@ true true true + true true true true @@ -5374,6 +5796,7 @@ true true + true true true true @@ -5385,6 +5808,7 @@ true true true + true true true true @@ -5399,6 +5823,7 @@ true true + true true true true @@ -5410,6 +5835,7 @@ true true true + true true true true @@ -5424,6 +5850,7 @@ true true + true true true true @@ -5435,6 +5862,7 @@ true true true + true true true true @@ -5449,6 +5877,7 @@ true true + true true true true @@ -5460,6 +5889,7 @@ true true true + true true true true @@ -5474,6 +5904,7 @@ true true + true true true true @@ -5485,6 +5916,7 @@ true true true + true true true true @@ -5499,6 +5931,7 @@ true true + true true true true @@ -5510,6 +5943,7 @@ true true true + true true true true @@ -5524,6 +5958,7 @@ true true + true true true true @@ -5535,6 +5970,7 @@ true true true + true true true true @@ -5549,6 +5985,7 @@ true true + true true true true @@ -5560,6 +5997,7 @@ true true true + true true true true @@ -5574,6 +6012,7 @@ true true + true true true true @@ -5585,6 +6024,7 @@ true true true + true true true true @@ -5599,6 +6039,7 @@ true true + true true true true @@ -5610,6 +6051,7 @@ true true true + true true true true @@ -5624,6 +6066,7 @@ true true + true true true true @@ -5635,6 +6078,7 @@ true true true + true true true true @@ -5649,6 +6093,7 @@ true true + true true true true @@ -5660,6 +6105,7 @@ true true true + true true true true @@ -5674,12 +6120,14 @@ true true + true true true true true true true + true true true true @@ -5695,6 +6143,7 @@ true true + true true true true @@ -5706,6 +6155,7 @@ true true true + true true true true @@ -5720,6 +6170,7 @@ true true + true true true true @@ -5731,6 +6182,7 @@ true true true + true true true true @@ -5745,6 +6197,7 @@ true true + true true true true @@ -5756,6 +6209,7 @@ true true true + true true true true @@ -5770,6 +6224,7 @@ true true + true true true true @@ -5781,6 +6236,7 @@ true true true + true true true true @@ -5795,6 +6251,7 @@ true true + true true true true @@ -5806,6 +6263,7 @@ true true true + true true true true @@ -5820,12 +6278,14 @@ true true + true true true true true true true + true true true true @@ -5841,12 +6301,14 @@ true true + true true true true true true true + true true true true @@ -5862,6 +6324,7 @@ true true + true true true true @@ -5873,6 +6336,7 @@ true true true + true true true true @@ -5887,6 +6351,7 @@ true true + true true true true @@ -5898,6 +6363,7 @@ true true true + true true true true @@ -5912,6 +6378,7 @@ true true + true true true true @@ -5923,6 +6390,7 @@ true true true + true true true true @@ -5937,12 +6405,14 @@ true true + true true true true true true true + true true true true @@ -5958,6 +6428,7 @@ true true + true true true true @@ -5969,6 +6440,7 @@ true true true + true true true true @@ -5983,6 +6455,7 @@ true true + true true true true @@ -5994,6 +6467,7 @@ true true true + true true true true @@ -6008,6 +6482,7 @@ true true + true true true true @@ -6019,6 +6494,7 @@ true true true + true true true true @@ -6033,6 +6509,7 @@ true true + true true true true @@ -6044,6 +6521,7 @@ true true true + true true true true @@ -6058,6 +6536,7 @@ true true + true true true true @@ -6069,6 +6548,7 @@ true true true + true true true true @@ -6083,6 +6563,7 @@ true true + true true true true @@ -6094,6 +6575,7 @@ true true true + true true true true @@ -6108,6 +6590,7 @@ true true + true true true true @@ -6119,6 +6602,7 @@ true true true + true true true true @@ -6133,6 +6617,7 @@ true true + true true true true @@ -6144,6 +6629,7 @@ true true true + true true true true @@ -6158,6 +6644,7 @@ true true + true true true true @@ -6169,6 +6656,7 @@ true true true + true true true true @@ -6183,6 +6671,7 @@ true true + true true true true @@ -6194,6 +6683,7 @@ true true true + true true true true @@ -6208,6 +6698,7 @@ true true + true true true true @@ -6219,6 +6710,7 @@ true true true + true true true true @@ -6233,6 +6725,7 @@ true true + true true true true @@ -6244,6 +6737,7 @@ true true true + true true true true @@ -6258,6 +6752,7 @@ true true + true true true true @@ -6269,6 +6764,7 @@ true true true + true true true true @@ -6283,6 +6779,7 @@ true true + true true true true @@ -6294,6 +6791,7 @@ true true true + true true true true @@ -6308,6 +6806,7 @@ true true + true true true true @@ -6319,6 +6818,7 @@ true true true + true true true true @@ -6333,6 +6833,7 @@ true true + true true true true @@ -6344,6 +6845,7 @@ true true true + true true true true @@ -6358,6 +6860,7 @@ true true + true true true true @@ -6369,6 +6872,7 @@ true true true + true true true true @@ -6383,6 +6887,7 @@ true true + true true true true @@ -6394,6 +6899,7 @@ true true true + true true true true @@ -6408,6 +6914,7 @@ true true + true true true true @@ -6419,6 +6926,7 @@ true true true + true true true true @@ -6433,6 +6941,7 @@ true true + true true true true @@ -6444,6 +6953,7 @@ true true true + true true true true @@ -6458,6 +6968,7 @@ true true + true true true true @@ -6469,6 +6980,7 @@ true true true + true true true true @@ -6483,6 +6995,7 @@ true true + true true true true @@ -6494,6 +7007,7 @@ true true true + true true true true @@ -6508,6 +7022,7 @@ true true + true true true true @@ -6519,6 +7034,7 @@ true true true + true true true true @@ -6533,6 +7049,7 @@ true true + true true true true @@ -6544,6 +7061,7 @@ true true true + true true true true @@ -6558,6 +7076,7 @@ true true + true true true true @@ -6569,6 +7088,7 @@ true true true + true true true true @@ -6583,6 +7103,7 @@ true true + true true true true @@ -6594,6 +7115,7 @@ true true true + true true true true @@ -6608,6 +7130,7 @@ true true + true true true true @@ -6619,6 +7142,7 @@ true true true + true true true true @@ -6633,6 +7157,7 @@ true true + true true true true @@ -6644,6 +7169,7 @@ true true true + true true true true @@ -6658,6 +7184,7 @@ true true + true true true true @@ -6669,6 +7196,7 @@ true true true + true true true true @@ -6683,6 +7211,7 @@ true true + true true true true @@ -6694,6 +7223,7 @@ true true true + true true true true @@ -6708,6 +7238,7 @@ true true + true true true true @@ -6719,6 +7250,7 @@ true true true + true true true true @@ -6733,6 +7265,7 @@ true true + true true true true @@ -6744,6 +7277,7 @@ true true true + true true true true @@ -6758,6 +7292,7 @@ true true + true true true true @@ -6769,6 +7304,7 @@ true true true + true true true true @@ -6783,6 +7319,7 @@ true true + true true true true @@ -6794,6 +7331,7 @@ true true true + true true true true @@ -6808,6 +7346,7 @@ true true + true true true true @@ -6819,6 +7358,7 @@ true true true + true true true true @@ -6833,6 +7373,7 @@ true true + true true true true @@ -6844,6 +7385,7 @@ true true true + true true true true @@ -6858,6 +7400,7 @@ true true + true true true true @@ -6869,6 +7412,7 @@ true true true + true true true true @@ -6883,6 +7427,7 @@ true true + true true true true @@ -6894,6 +7439,7 @@ true true true + true true true true @@ -6908,6 +7454,7 @@ true true + true true true true @@ -6919,6 +7466,7 @@ true true true + true true true true @@ -6933,6 +7481,7 @@ true true + true true true true @@ -6944,6 +7493,7 @@ true true true + true true true true @@ -6958,6 +7508,7 @@ true true + true true true true @@ -6969,6 +7520,7 @@ true true true + true true true true @@ -6983,6 +7535,7 @@ true true + true true true true @@ -6994,6 +7547,7 @@ true true true + true true true true @@ -7008,6 +7562,7 @@ true true + true true true true @@ -7019,6 +7574,7 @@ true true true + true true true true @@ -7033,6 +7589,7 @@ true true + true true true true @@ -7044,6 +7601,7 @@ true true true + true true true true @@ -7058,6 +7616,7 @@ true true + true true true true @@ -7069,6 +7628,7 @@ true true true + true true true true @@ -7083,6 +7643,7 @@ true true + true true true true @@ -7094,6 +7655,7 @@ true true true + true true true true @@ -7108,6 +7670,7 @@ true true + true true true true @@ -7119,6 +7682,7 @@ true true true + true true true true @@ -7133,6 +7697,7 @@ true true + true true true true @@ -7144,6 +7709,7 @@ true true true + true true true true @@ -7158,6 +7724,7 @@ true true + true true true true @@ -7169,6 +7736,7 @@ true true true + true true true true @@ -7183,6 +7751,7 @@ true true + true true true true @@ -7194,6 +7763,7 @@ true true true + true true true true @@ -7208,6 +7778,7 @@ true true + true true true true @@ -7219,6 +7790,7 @@ true true true + true true true true @@ -7233,6 +7805,7 @@ true true + true true true true @@ -7244,6 +7817,7 @@ true true true + true true true true @@ -7258,6 +7832,7 @@ true true + true true true true @@ -7269,6 +7844,7 @@ true true true + true true true true @@ -7283,6 +7859,7 @@ true true + true true true true @@ -7294,6 +7871,7 @@ true true true + true true true true @@ -7308,6 +7886,7 @@ true true + true true true true @@ -7319,6 +7898,7 @@ true true true + true true true true @@ -7333,6 +7913,7 @@ true true + true true true true @@ -7344,6 +7925,7 @@ true true true + true true true true @@ -7358,6 +7940,7 @@ true true + true true true true @@ -7369,6 +7952,7 @@ true true true + true true true true @@ -7383,6 +7967,7 @@ true true + true true true true @@ -7394,6 +7979,7 @@ true true true + true true true true @@ -7408,6 +7994,7 @@ true true + true true true true @@ -7419,6 +8006,7 @@ true true true + true true true true @@ -7433,6 +8021,7 @@ true true + true true true true @@ -7444,6 +8033,7 @@ true true true + true true true true @@ -7458,6 +8048,7 @@ true true + true true true true @@ -7469,6 +8060,7 @@ true true true + true true true true @@ -7483,6 +8075,7 @@ true true + true true true true @@ -7494,6 +8087,7 @@ true true true + true true true true @@ -7508,6 +8102,7 @@ true true + true true true true @@ -7519,6 +8114,7 @@ true true true + true true true true @@ -7533,6 +8129,7 @@ true true + true true true true @@ -7544,6 +8141,7 @@ true true true + true true true true @@ -7558,6 +8156,7 @@ true true + true true true true @@ -7569,6 +8168,7 @@ true true true + true true true true @@ -7583,6 +8183,7 @@ true true + true true true true @@ -7594,6 +8195,7 @@ true true true + true true true true @@ -7608,6 +8210,7 @@ true true + true true true true @@ -7619,6 +8222,7 @@ true true true + true true true true @@ -7633,6 +8237,7 @@ true true + true true true true @@ -7644,6 +8249,7 @@ true true true + true true true true @@ -7655,9 +8261,13 @@ true true + + true + true true + true true true true @@ -7669,6 +8279,7 @@ true true true + true true true true @@ -7683,6 +8294,7 @@ true true + true true true true @@ -7694,6 +8306,7 @@ true true true + true true true true @@ -7708,6 +8321,7 @@ true true + true true true true @@ -7719,6 +8333,7 @@ true true true + true true true true @@ -7733,6 +8348,7 @@ true true + true true true true @@ -7744,6 +8360,7 @@ true true true + true true true true @@ -7758,6 +8375,7 @@ true true + true true true true @@ -7769,6 +8387,7 @@ true true true + true true true true @@ -7783,6 +8402,7 @@ true true + true true true true @@ -7794,6 +8414,7 @@ true true true + true true true true @@ -7808,6 +8429,7 @@ true true + true true true true @@ -7819,6 +8441,7 @@ true true true + true true true true @@ -7833,6 +8456,7 @@ true true + true true true true @@ -7844,6 +8468,7 @@ true true true + true true true true @@ -7858,6 +8483,7 @@ true true + true true true true @@ -7869,6 +8495,7 @@ true true true + true true true true @@ -7883,6 +8510,7 @@ true true + true true true true @@ -7894,6 +8522,7 @@ true true true + true true true true @@ -7908,6 +8537,7 @@ true true + true true true true @@ -7919,6 +8549,7 @@ true true true + true true true true @@ -7933,6 +8564,7 @@ true true + true true true true @@ -7944,6 +8576,7 @@ true true true + true true true true @@ -7958,6 +8591,7 @@ true true + true true true true @@ -7969,6 +8603,7 @@ true true true + true true true true @@ -7983,6 +8618,7 @@ true true + true true true true @@ -7994,6 +8630,7 @@ true true true + true true true true @@ -8008,6 +8645,7 @@ true true + true true true true @@ -8019,6 +8657,7 @@ true true true + true true true true @@ -8033,6 +8672,7 @@ true true + true true true true @@ -8044,6 +8684,7 @@ true true true + true true true true @@ -8058,6 +8699,7 @@ true true + true true true true @@ -8069,6 +8711,7 @@ true true true + true true true true @@ -8083,6 +8726,7 @@ true true + true true true true @@ -8094,6 +8738,7 @@ true true true + true true true true @@ -8221,6 +8866,7 @@ false false false + false false false false @@ -8235,6 +8881,7 @@ false false false + false false false false @@ -8242,6 +8889,7 @@ false false false + false false false false @@ -8256,6 +8904,7 @@ false false false + false false false false @@ -8282,6 +8931,7 @@ false false + false false false false @@ -8296,6 +8946,7 @@ false false false + false false false false @@ -8303,6 +8954,7 @@ false false false + false false false false @@ -8317,6 +8969,7 @@ false false false + false false false false @@ -8338,6 +8991,7 @@ false false + false false false false @@ -8352,6 +9006,7 @@ false false false + false false false false @@ -8359,6 +9014,7 @@ false false false + false false false false @@ -8373,6 +9029,7 @@ false false false + false false false false @@ -8384,6 +9041,7 @@ false false + false false false false @@ -8398,6 +9056,7 @@ false false false + false false false false @@ -8405,6 +9064,7 @@ false false false + false false false false @@ -8419,6 +9079,7 @@ false false false + false false false false @@ -8430,6 +9091,7 @@ false false + false false false false @@ -8444,6 +9106,7 @@ false false false + false false false false @@ -8451,6 +9114,7 @@ false false false + false false false false @@ -8465,6 +9129,7 @@ false false false + false false false false @@ -8476,6 +9141,7 @@ false false + false false false false @@ -8490,6 +9156,7 @@ false false false + false false false false @@ -8497,6 +9164,7 @@ false false false + false false false false @@ -8511,6 +9179,7 @@ false false false + false false false false @@ -8522,6 +9191,7 @@ false false + false false false false @@ -8536,6 +9206,7 @@ false false false + false false false false @@ -8543,6 +9214,7 @@ false false false + false false false false @@ -8557,6 +9229,7 @@ false false false + false false false false @@ -8573,6 +9246,7 @@ false false + false false false false @@ -8587,6 +9261,7 @@ false false false + false false false false @@ -8594,6 +9269,7 @@ false false false + false false false false @@ -8608,6 +9284,7 @@ false false false + false false false false @@ -8623,6 +9300,7 @@ true false false + false false false false @@ -8637,6 +9315,7 @@ false false false + false false false false @@ -8644,6 +9323,7 @@ false false false + false false false false @@ -8658,6 +9338,7 @@ false false false + false false false false @@ -8681,6 +9362,7 @@ false false + false false false false @@ -8695,6 +9377,7 @@ false false false + false false false false @@ -8702,6 +9385,7 @@ false false false + false false false false @@ -8716,6 +9400,7 @@ false false false + false false false false diff --git a/test/vs2019/etl.vcxproj.filters b/test/vs2019/etl.vcxproj.filters index 5fabac2f..b9b976f6 100644 --- a/test/vs2019/etl.vcxproj.filters +++ b/test/vs2019/etl.vcxproj.filters @@ -3089,6 +3089,12 @@ Tests + + Tests\Sanity Checks + + + Tests\Sanity Checks +