mirror of
https://github.com/ETLCPP/etl.git
synced 2026-06-28 21:38:44 +08:00
Work in progress
Start single element optimisations
This commit is contained in:
parent
42d272cae4
commit
dba681d94f
@ -1,100 +0,0 @@
|
||||
///\file
|
||||
|
||||
/******************************************************************************
|
||||
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.
|
||||
******************************************************************************/
|
||||
|
||||
//***************************************************************************
|
||||
/// Optimised specialisations.
|
||||
//***************************************************************************
|
||||
|
||||
namespace etl
|
||||
{
|
||||
namespace private_bitset
|
||||
{
|
||||
template <size_t Total_Bits, typename TElement, bool HasSingleElementMask>
|
||||
class bitset_fast;
|
||||
|
||||
template <size_t Total_Bits, typename TElement>
|
||||
class bitset_fast<Total_Bits, TElement, false>
|
||||
{
|
||||
public:
|
||||
|
||||
enum
|
||||
{
|
||||
npos = etl::integral_limits<size_t>::max
|
||||
};
|
||||
|
||||
typedef TElement element_type;
|
||||
|
||||
ETL_CONSTEXPR14 bitset_fast()
|
||||
: data(static_cast<element_type>(0))
|
||||
{
|
||||
}
|
||||
|
||||
ETL_CONSTEXPR14 bitset_fast(unsigned long long v)
|
||||
: data(static_cast<element_type>(v))
|
||||
{
|
||||
}
|
||||
|
||||
ETL_CONSTEXPR14 bitset_fast(const char* text)
|
||||
: data(0)
|
||||
{
|
||||
}
|
||||
|
||||
ETL_CONSTEXPR14 bitset_fast(const wchar_t* text)
|
||||
: data(0)
|
||||
{
|
||||
}
|
||||
|
||||
ETL_CONSTEXPR14 bitset_fast(const char16_t* text)
|
||||
: data(0)
|
||||
{
|
||||
}
|
||||
|
||||
ETL_CONSTEXPR14 bitset_fast(const char32_t* text)
|
||||
: data(0)
|
||||
{
|
||||
}
|
||||
|
||||
ETL_CONSTEXPR14 bitset_fast(const bitset_fast<Total_Bits, TElement, false>& other)
|
||||
: data(other.data)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR14 T value() const
|
||||
{
|
||||
return T(data);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
element_type data;
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -246,7 +246,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
size_t size() const
|
||||
{
|
||||
return Total_Bits;
|
||||
return Active_Bits;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -344,7 +344,7 @@ namespace etl
|
||||
{
|
||||
reset();
|
||||
|
||||
size_t i = etl::min(Total_Bits, etl::strlen(text));
|
||||
size_t i = etl::min(Active_Bits, etl::strlen(text));
|
||||
|
||||
while (i > 0)
|
||||
{
|
||||
@ -361,7 +361,7 @@ namespace etl
|
||||
{
|
||||
reset();
|
||||
|
||||
size_t i = etl::min(Total_Bits, etl::strlen(text));
|
||||
size_t i = etl::min(Active_Bits, etl::strlen(text));
|
||||
|
||||
while (i > 0)
|
||||
{
|
||||
@ -378,7 +378,7 @@ namespace etl
|
||||
{
|
||||
reset();
|
||||
|
||||
size_t i = etl::min(Total_Bits, etl::strlen(text));
|
||||
size_t i = etl::min(Active_Bits, etl::strlen(text));
|
||||
|
||||
while (i > 0)
|
||||
{
|
||||
@ -395,7 +395,7 @@ namespace etl
|
||||
{
|
||||
reset();
|
||||
|
||||
size_t i = etl::min(Total_Bits, etl::strlen(text));
|
||||
size_t i = etl::min(Active_Bits, etl::strlen(text));
|
||||
|
||||
while (i > 0)
|
||||
{
|
||||
@ -551,7 +551,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
ibitset& flip(size_t position)
|
||||
{
|
||||
if (position < Total_Bits)
|
||||
if (position < Active_Bits)
|
||||
{
|
||||
size_t index;
|
||||
element_t bit;
|
||||
@ -678,7 +678,7 @@ namespace etl
|
||||
(!state && (value != ALL_SET)))
|
||||
{
|
||||
// For each bit in the element...
|
||||
while ((bit < Bits_Per_Element) && (position < Total_Bits))
|
||||
while ((bit < Bits_Per_Element) && (position < Active_Bits))
|
||||
{
|
||||
// Equal to the required state?
|
||||
if (((value & mask) != 0) == state)
|
||||
@ -767,7 +767,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
ibitset& operator<<=(size_t shift)
|
||||
{
|
||||
if (shift >= Total_Bits)
|
||||
if (shift >= Active_Bits)
|
||||
{
|
||||
reset();
|
||||
}
|
||||
@ -846,7 +846,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
ibitset& operator>>=(size_t shift)
|
||||
{
|
||||
if (shift >= Total_Bits)
|
||||
if (shift >= Active_Bits)
|
||||
{
|
||||
reset();
|
||||
}
|
||||
@ -1016,12 +1016,12 @@ namespace etl
|
||||
/// Constructor.
|
||||
//*************************************************************************
|
||||
ibitset(size_t nbits_, size_t size_, element_t* pdata_)
|
||||
: Total_Bits(nbits_)
|
||||
: Active_Bits(nbits_)
|
||||
, Number_Of_Elements(size_)
|
||||
, pdata(pdata_)
|
||||
{
|
||||
const size_t allocated_bits = Number_Of_Elements * Bits_Per_Element;
|
||||
const size_t top_mask_shift = ((Bits_Per_Element - (allocated_bits - Total_Bits)) % Bits_Per_Element);
|
||||
const size_t top_mask_shift = ((Bits_Per_Element - (allocated_bits - Active_Bits)) % Bits_Per_Element);
|
||||
Top_Mask = element_t(top_mask_shift == 0 ? ALL_SET : ~(ALL_SET << top_mask_shift));
|
||||
}
|
||||
|
||||
@ -1048,7 +1048,7 @@ namespace etl
|
||||
// Disable copy construction.
|
||||
ibitset(const ibitset&);
|
||||
|
||||
const size_t Total_Bits;
|
||||
const size_t Active_Bits;
|
||||
const size_t Number_Of_Elements;
|
||||
element_t* pdata;
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user