Merge remote-tracking branch 'origin/development' into feature/emplace_var_arg

This commit is contained in:
John Wellbelove 2018-12-08 16:01:35 +00:00
parent 8e9eaf4f7c
commit b7cc17f84a
41 changed files with 4161 additions and 2599 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,28 @@
///\file
/******************************************************************************
The MIT License(MIT)
Embedded Template Library.
https://github.com/ETLCPP/etl
https://www.etlcpp.com
Copyright(c) 2018 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_STREAM_INCLUDED
#define ETL_BIT_STREAM_INCLUDED
@ -53,7 +78,7 @@ namespace etl
//***************************************************************************
bit_stream(unsigned char* begin_, unsigned char* end_)
: pdata(begin_),
length(std::distance(begin_, end_))
length(std::distance(begin_, end_))
{
restart();
}

View File

@ -47,12 +47,6 @@ SOFTWARE.
namespace etl
{
//***************************************************************************
/// CRC16 table
/// \ingroup crc16
//***************************************************************************
extern const uint16_t ETL_CRC16[];
//***************************************************************************
/// CRC16 policy.
/// Calculates CRC16 using polynomial 0x8005.
@ -68,7 +62,27 @@ namespace etl
inline uint16_t add(uint16_t crc, uint8_t value) const
{
return (crc >> 8) ^ ETL_CRC16[(crc ^ value) & 0xFF];
const uint16_t CRC16[256] =
{
0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241, 0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440,
0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40, 0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841,
0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40, 0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41,
0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641, 0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040,
0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1, 0xF281, 0x3240, 0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441,
0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0, 0x3E80, 0xFE41, 0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840,
0x2800, 0xE8C1, 0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41, 0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40,
0xE401, 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640, 0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0, 0x2080, 0xE041,
0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240, 0x6600, 0xA6C1, 0xA781, 0x6740, 0xA501, 0x65C0, 0x6480, 0xA441,
0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41, 0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840,
0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80, 0xBA41, 0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40,
0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640, 0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041,
0x5000, 0x90C1, 0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241, 0x9601, 0x56C0, 0x5780, 0x9741, 0x5500, 0x95C1, 0x9481, 0x5440,
0x9C01, 0x5CC0, 0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40, 0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841,
0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 0x8A81, 0x4A40, 0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41,
0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641, 0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040
};
return (crc >> 8) ^ CRC16[(crc ^ value) & 0xFF];
}
inline uint16_t final(uint16_t crc) const

View File

@ -47,12 +47,6 @@ SOFTWARE.
namespace etl
{
//***************************************************************************
/// CRC-CCITT table
/// \ingroup crc16_ccitt
//***************************************************************************
extern const uint16_t ETL_CRC_CCITT[];
//***************************************************************************
/// CRC16 CCITT policy.
/// Calculates CRC16 CCITT using polynomial 0x1021
@ -68,7 +62,27 @@ namespace etl
inline uint16_t add(uint16_t crc, uint8_t value) const
{
return (crc << 8) ^ ETL_CRC_CCITT[((crc >> 8) ^ value) & 0xFF];
static const uint16_t CRC_CCITT[] =
{
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7, 0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF,
0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6, 0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE,
0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485, 0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D,
0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4, 0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC,
0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823, 0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B,
0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12, 0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A,
0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41, 0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49,
0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70, 0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78,
0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F, 0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067,
0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E, 0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256,
0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D, 0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C, 0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634,
0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB, 0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3,
0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A, 0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92,
0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9, 0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1,
0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8, 0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0
};
return (crc << 8) ^ CRC_CCITT[((crc >> 8) ^ value) & 0xFF];
}
inline uint16_t final(uint16_t crc) const

View File

@ -47,12 +47,6 @@ SOFTWARE.
namespace etl
{
//***************************************************************************
/// CRC Kermit table
/// \ingroup crc
//***************************************************************************
extern const uint16_t ETL_CRC_KERMIT[];
//***************************************************************************
/// CRC16 Kermit policy.
/// Calculates CRC16 Kermit using polynomial 0x1021
@ -68,7 +62,27 @@ namespace etl
inline uint16_t add(uint16_t crc, uint8_t value) const
{
return (crc >> 8) ^ ETL_CRC_KERMIT[(crc ^ value) & 0xFF];
static const uint16_t CRC_KERMIT[] =
{
0x0000, 0x1189, 0x2312, 0x329B, 0x4624, 0x57AD, 0x6536, 0x74BF, 0x8C48, 0x9DC1, 0xAF5A, 0xBED3, 0xCA6C, 0xDBE5, 0xE97E, 0xF8F7,
0x1081, 0x0108, 0x3393, 0x221A, 0x56A5, 0x472C, 0x75B7, 0x643E, 0x9CC9, 0x8D40, 0xBFDB, 0xAE52, 0xDAED, 0xCB64, 0xF9FF, 0xE876,
0x2102, 0x308B, 0x0210, 0x1399, 0x6726, 0x76AF, 0x4434, 0x55BD, 0xAD4A, 0xBCC3, 0x8E58, 0x9FD1, 0xEB6E, 0xFAE7, 0xC87C, 0xD9F5,
0x3183, 0x200A, 0x1291, 0x0318, 0x77A7, 0x662E, 0x54B5, 0x453C, 0xBDCB, 0xAC42, 0x9ED9, 0x8F50, 0xFBEF, 0xEA66, 0xD8FD, 0xC974,
0x4204, 0x538D, 0x6116, 0x709F, 0x0420, 0x15A9, 0x2732, 0x36BB, 0xCE4C, 0xDFC5, 0xED5E, 0xFCD7, 0x8868, 0x99E1, 0xAB7A, 0xBAF3,
0x5285, 0x430C, 0x7197, 0x601E, 0x14A1, 0x0528, 0x37B3, 0x263A, 0xDECD, 0xCF44, 0xFDDF, 0xEC56, 0x98E9, 0x8960, 0xBBFB, 0xAA72,
0x6306, 0x728F, 0x4014, 0x519D, 0x2522, 0x34AB, 0x0630, 0x17B9, 0xEF4E, 0xFEC7, 0xCC5C, 0xDDD5, 0xA96A, 0xB8E3, 0x8A78, 0x9BF1,
0x7387, 0x620E, 0x5095, 0x411C, 0x35A3, 0x242A, 0x16B1, 0x0738, 0xFFCF, 0xEE46, 0xDCDD, 0xCD54, 0xB9EB, 0xA862, 0x9AF9, 0x8B70,
0x8408, 0x9581, 0xA71A, 0xB693, 0xC22C, 0xD3A5, 0xE13E, 0xF0B7, 0x0840, 0x19C9, 0x2B52, 0x3ADB, 0x4E64, 0x5FED, 0x6D76, 0x7CFF,
0x9489, 0x8500, 0xB79B, 0xA612, 0xD2AD, 0xC324, 0xF1BF, 0xE036, 0x18C1, 0x0948, 0x3BD3, 0x2A5A, 0x5EE5, 0x4F6C, 0x7DF7, 0x6C7E,
0xA50A, 0xB483, 0x8618, 0x9791, 0xE32E, 0xF2A7, 0xC03C, 0xD1B5, 0x2942, 0x38CB, 0x0A50, 0x1BD9, 0x6F66, 0x7EEF, 0x4C74, 0x5DFD,
0xB58B, 0xA402, 0x9699, 0x8710, 0xF3AF, 0xE226, 0xD0BD, 0xC134, 0x39C3, 0x284A, 0x1AD1, 0x0B58, 0x7FE7, 0x6E6E, 0x5CF5, 0x4D7C,
0xC60C, 0xD785, 0xE51E, 0xF497, 0x8028, 0x91A1, 0xA33A, 0xB2B3, 0x4A44, 0x5BCD, 0x6956, 0x78DF, 0x0C60, 0x1DE9, 0x2F72, 0x3EFB,
0xD68D, 0xC704, 0xF59F, 0xE416, 0x90A9, 0x8120, 0xB3BB, 0xA232, 0x5AC5, 0x4B4C, 0x79D7, 0x685E, 0x1CE1, 0x0D68, 0x3FF3, 0x2E7A,
0xE70E, 0xF687, 0xC41C, 0xD595, 0xA12A, 0xB0A3, 0x8238, 0x93B1, 0x6B46, 0x7ACF, 0x4854, 0x59DD, 0x2D62, 0x3CEB, 0x0E70, 0x1FF9,
0xF78F, 0xE606, 0xD49D, 0xC514, 0xB1AB, 0xA022, 0x92B9, 0x8330, 0x7BC7, 0x6A4E, 0x58D5, 0x495C, 0x3DE3, 0x2C6A, 0x1EF1, 0x0F78
};
return (crc >> 8) ^ CRC_KERMIT[(crc ^ value) & 0xFF];
}
inline uint16_t final(uint16_t crc) const

View File

@ -47,12 +47,6 @@ SOFTWARE.
namespace etl
{
//***************************************************************************
/// CRC-MODBUS table
/// \ingroup crc16_modbus
//***************************************************************************
extern const uint16_t ETL_CRC_MODBUS[];
//***************************************************************************
/// CRC16 MODBUS policy.
/// Calculates CRC16 MODBUS using polynomial 0x
@ -68,6 +62,42 @@ namespace etl
inline uint16_t add(uint16_t crc, uint8_t value) const
{
static const uint16_t ETL_CRC_MODBUS[] =
{
0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241,
0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440,
0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40,
0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841,
0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40,
0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41,
0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641,
0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040,
0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1, 0xF281, 0x3240,
0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441,
0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0, 0x3E80, 0xFE41,
0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840,
0x2800, 0xE8C1, 0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41,
0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40,
0xE401, 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640,
0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0, 0x2080, 0xE041,
0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240,
0x6600, 0xA6C1, 0xA781, 0x6740, 0xA501, 0x65C0, 0x6480, 0xA441,
0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41,
0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840,
0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80, 0xBA41,
0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40,
0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640,
0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041,
0x5000, 0x90C1, 0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241,
0x9601, 0x56C0, 0x5780, 0x9741, 0x5500, 0x95C1, 0x9481, 0x5440,
0x9C01, 0x5CC0, 0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40,
0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841,
0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 0x8A81, 0x4A40,
0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41,
0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641,
0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040
};
return (crc >> 8) ^ ETL_CRC_MODBUS[(crc ^ value) & 0xFF];
}

View File

@ -47,12 +47,6 @@ SOFTWARE.
namespace etl
{
//***************************************************************************
/// CRC32 table
/// \ingroup crc32
//***************************************************************************
extern const uint32_t ETL_CRC32[];
//***************************************************************************
/// CRC32 policy.
/// Calculates CRC32 using polynomial 0x04C11DB7.
@ -68,7 +62,43 @@ namespace etl
inline uint32_t add(uint32_t crc, uint8_t value) const
{
return (crc >> 8) ^ ETL_CRC32[(crc ^ value) & 0xFF];
static const uint32_t CRC32[] =
{
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91,
0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,
0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5,
0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,
0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59,
0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F,
0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D,
0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,
0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,
0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457,
0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,
0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB,
0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,
0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD,
0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683,
0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,
0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7,
0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,
0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,
0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79,
0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F,
0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,
0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,
0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21,
0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,
0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45,
0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB,
0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF,
0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D
};
return (crc >> 8) ^ CRC32[(crc ^ value) & 0xFF];
}
inline uint32_t final(uint32_t crc) const

View File

@ -68,6 +68,42 @@ namespace etl
inline uint32_t add(uint32_t crc, uint8_t value) const
{
static const uint32_t CRC32_C[] =
{
0x00000000L, 0xF26B8303L, 0xE13B70F7L, 0x1350F3F4L, 0xC79A971FL, 0x35F1141CL, 0x26A1E7E8L, 0xD4CA64EBL,
0x8AD958CFL, 0x78B2DBCCL, 0x6BE22838L, 0x9989AB3BL, 0x4D43CFD0L, 0xBF284CD3L, 0xAC78BF27L, 0x5E133C24L,
0x105EC76FL, 0xE235446CL, 0xF165B798L, 0x030E349BL, 0xD7C45070L, 0x25AFD373L, 0x36FF2087L, 0xC494A384L,
0x9A879FA0L, 0x68EC1CA3L, 0x7BBCEF57L, 0x89D76C54L, 0x5D1D08BFL, 0xAF768BBCL, 0xBC267848L, 0x4E4DFB4BL,
0x20BD8EDEL, 0xD2D60DDDL, 0xC186FE29L, 0x33ED7D2AL, 0xE72719C1L, 0x154C9AC2L, 0x061C6936L, 0xF477EA35L,
0xAA64D611L, 0x580F5512L, 0x4B5FA6E6L, 0xB93425E5L, 0x6DFE410EL, 0x9F95C20DL, 0x8CC531F9L, 0x7EAEB2FAL,
0x30E349B1L, 0xC288CAB2L, 0xD1D83946L, 0x23B3BA45L, 0xF779DEAEL, 0x05125DADL, 0x1642AE59L, 0xE4292D5AL,
0xBA3A117EL, 0x4851927DL, 0x5B016189L, 0xA96AE28AL, 0x7DA08661L, 0x8FCB0562L, 0x9C9BF696L, 0x6EF07595L,
0x417B1DBCL, 0xB3109EBFL, 0xA0406D4BL, 0x522BEE48L, 0x86E18AA3L, 0x748A09A0L, 0x67DAFA54L, 0x95B17957L,
0xCBA24573L, 0x39C9C670L, 0x2A993584L, 0xD8F2B687L, 0x0C38D26CL, 0xFE53516FL, 0xED03A29BL, 0x1F682198L,
0x5125DAD3L, 0xA34E59D0L, 0xB01EAA24L, 0x42752927L, 0x96BF4DCCL, 0x64D4CECFL, 0x77843D3BL, 0x85EFBE38L,
0xDBFC821CL, 0x2997011FL, 0x3AC7F2EBL, 0xC8AC71E8L, 0x1C661503L, 0xEE0D9600L, 0xFD5D65F4L, 0x0F36E6F7L,
0x61C69362L, 0x93AD1061L, 0x80FDE395L, 0x72966096L, 0xA65C047DL, 0x5437877EL, 0x4767748AL, 0xB50CF789L,
0xEB1FCBADL, 0x197448AEL, 0x0A24BB5AL, 0xF84F3859L, 0x2C855CB2L, 0xDEEEDFB1L, 0xCDBE2C45L, 0x3FD5AF46L,
0x7198540DL, 0x83F3D70EL, 0x90A324FAL, 0x62C8A7F9L, 0xB602C312L, 0x44694011L, 0x5739B3E5L, 0xA55230E6L,
0xFB410CC2L, 0x092A8FC1L, 0x1A7A7C35L, 0xE811FF36L, 0x3CDB9BDDL, 0xCEB018DEL, 0xDDE0EB2AL, 0x2F8B6829L,
0x82F63B78L, 0x709DB87BL, 0x63CD4B8FL, 0x91A6C88CL, 0x456CAC67L, 0xB7072F64L, 0xA457DC90L, 0x563C5F93L,
0x082F63B7L, 0xFA44E0B4L, 0xE9141340L, 0x1B7F9043L, 0xCFB5F4A8L, 0x3DDE77ABL, 0x2E8E845FL, 0xDCE5075CL,
0x92A8FC17L, 0x60C37F14L, 0x73938CE0L, 0x81F80FE3L, 0x55326B08L, 0xA759E80BL, 0xB4091BFFL, 0x466298FCL,
0x1871A4D8L, 0xEA1A27DBL, 0xF94AD42FL, 0x0B21572CL, 0xDFEB33C7L, 0x2D80B0C4L, 0x3ED04330L, 0xCCBBC033L,
0xA24BB5A6L, 0x502036A5L, 0x4370C551L, 0xB11B4652L, 0x65D122B9L, 0x97BAA1BAL, 0x84EA524EL, 0x7681D14DL,
0x2892ED69L, 0xDAF96E6AL, 0xC9A99D9EL, 0x3BC21E9DL, 0xEF087A76L, 0x1D63F975L, 0x0E330A81L, 0xFC588982L,
0xB21572C9L, 0x407EF1CAL, 0x532E023EL, 0xA145813DL, 0x758FE5D6L, 0x87E466D5L, 0x94B49521L, 0x66DF1622L,
0x38CC2A06L, 0xCAA7A905L, 0xD9F75AF1L, 0x2B9CD9F2L, 0xFF56BD19L, 0x0D3D3E1AL, 0x1E6DCDEEL, 0xEC064EEDL,
0xC38D26C4L, 0x31E6A5C7L, 0x22B65633L, 0xD0DDD530L, 0x0417B1DBL, 0xF67C32D8L, 0xE52CC12CL, 0x1747422FL,
0x49547E0BL, 0xBB3FFD08L, 0xA86F0EFCL, 0x5A048DFFL, 0x8ECEE914L, 0x7CA56A17L, 0x6FF599E3L, 0x9D9E1AE0L,
0xD3D3E1ABL, 0x21B862A8L, 0x32E8915CL, 0xC083125FL, 0x144976B4L, 0xE622F5B7L, 0xF5720643L, 0x07198540L,
0x590AB964L, 0xAB613A67L, 0xB831C993L, 0x4A5A4A90L, 0x9E902E7BL, 0x6CFBAD78L, 0x7FAB5E8CL, 0x8DC0DD8FL,
0xE330A81AL, 0x115B2B19L, 0x020BD8EDL, 0xF0605BEEL, 0x24AA3F05L, 0xD6C1BC06L, 0xC5914FF2L, 0x37FACCF1L,
0x69E9F0D5L, 0x9B8273D6L, 0x88D28022L, 0x7AB90321L, 0xAE7367CAL, 0x5C18E4C9L, 0x4F48173DL, 0xBD23943EL,
0xF36E6F75L, 0x0105EC76L, 0x12551F82L, 0xE03E9C81L, 0x34F4F86AL, 0xC69F7B69L, 0xD5CF889DL, 0x27A40B9EL,
0x79B737BAL, 0x8BDCB4B9L, 0x988C474DL, 0x6AE7C44EL, 0xBE2DA0A5L, 0x4C4623A6L, 0x5F16D052L, 0xAD7D5351L
};
return (crc >> 8) ^ CRC32_C[(crc ^ value) & 0xFF];
}

View File

@ -47,12 +47,6 @@ SOFTWARE.
namespace etl
{
//***************************************************************************
/// CRC64_ECMA table
/// \ingroup crc64_ecma
//***************************************************************************
extern const uint64_t CRC64_ECMA[];
//***************************************************************************
/// CRC64 policy.
/// Calculates CRC64 ECMA using polynomial 0x42F0E1EBA9EA3693.
@ -68,6 +62,74 @@ namespace etl
inline uint64_t add(uint64_t crc, uint8_t value) const
{
static const uint64_t CRC64_ECMA[] =
{
0x0000000000000000, 0x42F0E1EBA9EA3693, 0x85E1C3D753D46D26, 0xC711223CFA3E5BB5,
0x493366450E42ECDF, 0x0BC387AEA7A8DA4C, 0xCCD2A5925D9681F9, 0x8E224479F47CB76A,
0x9266CC8A1C85D9BE, 0xD0962D61B56FEF2D, 0x17870F5D4F51B498, 0x5577EEB6E6BB820B,
0xDB55AACF12C73561, 0x99A54B24BB2D03F2, 0x5EB4691841135847, 0x1C4488F3E8F96ED4,
0x663D78FF90E185EF, 0x24CD9914390BB37C, 0xE3DCBB28C335E8C9, 0xA12C5AC36ADFDE5A,
0x2F0E1EBA9EA36930, 0x6DFEFF5137495FA3, 0xAAEFDD6DCD770416, 0xE81F3C86649D3285,
0xF45BB4758C645C51, 0xB6AB559E258E6AC2, 0x71BA77A2DFB03177, 0x334A9649765A07E4,
0xBD68D2308226B08E, 0xFF9833DB2BCC861D, 0x388911E7D1F2DDA8, 0x7A79F00C7818EB3B,
0xCC7AF1FF21C30BDE, 0x8E8A101488293D4D, 0x499B3228721766F8, 0x0B6BD3C3DBFD506B,
0x854997BA2F81E701, 0xC7B97651866BD192, 0x00A8546D7C558A27, 0x4258B586D5BFBCB4,
0x5E1C3D753D46D260, 0x1CECDC9E94ACE4F3, 0xDBFDFEA26E92BF46, 0x990D1F49C77889D5,
0x172F5B3033043EBF, 0x55DFBADB9AEE082C, 0x92CE98E760D05399, 0xD03E790CC93A650A,
0xAA478900B1228E31, 0xE8B768EB18C8B8A2, 0x2FA64AD7E2F6E317, 0x6D56AB3C4B1CD584,
0xE374EF45BF6062EE, 0xA1840EAE168A547D, 0x66952C92ECB40FC8, 0x2465CD79455E395B,
0x3821458AADA7578F, 0x7AD1A461044D611C, 0xBDC0865DFE733AA9, 0xFF3067B657990C3A,
0x711223CFA3E5BB50, 0x33E2C2240A0F8DC3, 0xF4F3E018F031D676, 0xB60301F359DBE0E5,
0xDA050215EA6C212F, 0x98F5E3FE438617BC, 0x5FE4C1C2B9B84C09, 0x1D14202910527A9A,
0x93366450E42ECDF0, 0xD1C685BB4DC4FB63, 0x16D7A787B7FAA0D6, 0x5427466C1E109645,
0x4863CE9FF6E9F891, 0x0A932F745F03CE02, 0xCD820D48A53D95B7, 0x8F72ECA30CD7A324,
0x0150A8DAF8AB144E, 0x43A04931514122DD, 0x84B16B0DAB7F7968, 0xC6418AE602954FFB,
0xBC387AEA7A8DA4C0, 0xFEC89B01D3679253, 0x39D9B93D2959C9E6, 0x7B2958D680B3FF75,
0xF50B1CAF74CF481F, 0xB7FBFD44DD257E8C, 0x70EADF78271B2539, 0x321A3E938EF113AA,
0x2E5EB66066087D7E, 0x6CAE578BCFE24BED, 0xABBF75B735DC1058, 0xE94F945C9C3626CB,
0x676DD025684A91A1, 0x259D31CEC1A0A732, 0xE28C13F23B9EFC87, 0xA07CF2199274CA14,
0x167FF3EACBAF2AF1, 0x548F120162451C62, 0x939E303D987B47D7, 0xD16ED1D631917144,
0x5F4C95AFC5EDC62E, 0x1DBC74446C07F0BD, 0xDAAD56789639AB08, 0x985DB7933FD39D9B,
0x84193F60D72AF34F, 0xC6E9DE8B7EC0C5DC, 0x01F8FCB784FE9E69, 0x43081D5C2D14A8FA,
0xCD2A5925D9681F90, 0x8FDAB8CE70822903, 0x48CB9AF28ABC72B6, 0x0A3B7B1923564425,
0x70428B155B4EAF1E, 0x32B26AFEF2A4998D, 0xF5A348C2089AC238, 0xB753A929A170F4AB,
0x3971ED50550C43C1, 0x7B810CBBFCE67552, 0xBC902E8706D82EE7, 0xFE60CF6CAF321874,
0xE224479F47CB76A0, 0xA0D4A674EE214033, 0x67C58448141F1B86, 0x253565A3BDF52D15,
0xAB1721DA49899A7F, 0xE9E7C031E063ACEC, 0x2EF6E20D1A5DF759, 0x6C0603E6B3B7C1CA,
0xF6FAE5C07D3274CD, 0xB40A042BD4D8425E, 0x731B26172EE619EB, 0x31EBC7FC870C2F78,
0xBFC9838573709812, 0xFD39626EDA9AAE81, 0x3A28405220A4F534, 0x78D8A1B9894EC3A7,
0x649C294A61B7AD73, 0x266CC8A1C85D9BE0, 0xE17DEA9D3263C055, 0xA38D0B769B89F6C6,
0x2DAF4F0F6FF541AC, 0x6F5FAEE4C61F773F, 0xA84E8CD83C212C8A, 0xEABE6D3395CB1A19,
0x90C79D3FEDD3F122, 0xD2377CD44439C7B1, 0x15265EE8BE079C04, 0x57D6BF0317EDAA97,
0xD9F4FB7AE3911DFD, 0x9B041A914A7B2B6E, 0x5C1538ADB04570DB, 0x1EE5D94619AF4648,
0x02A151B5F156289C, 0x4051B05E58BC1E0F, 0x87409262A28245BA, 0xC5B073890B687329,
0x4B9237F0FF14C443, 0x0962D61B56FEF2D0, 0xCE73F427ACC0A965, 0x8C8315CC052A9FF6,
0x3A80143F5CF17F13, 0x7870F5D4F51B4980, 0xBF61D7E80F251235, 0xFD913603A6CF24A6,
0x73B3727A52B393CC, 0x31439391FB59A55F, 0xF652B1AD0167FEEA, 0xB4A25046A88DC879,
0xA8E6D8B54074A6AD, 0xEA16395EE99E903E, 0x2D071B6213A0CB8B, 0x6FF7FA89BA4AFD18,
0xE1D5BEF04E364A72, 0xA3255F1BE7DC7CE1, 0x64347D271DE22754, 0x26C49CCCB40811C7,
0x5CBD6CC0CC10FAFC, 0x1E4D8D2B65FACC6F, 0xD95CAF179FC497DA, 0x9BAC4EFC362EA149,
0x158E0A85C2521623, 0x577EEB6E6BB820B0, 0x906FC95291867B05, 0xD29F28B9386C4D96,
0xCEDBA04AD0952342, 0x8C2B41A1797F15D1, 0x4B3A639D83414E64, 0x09CA82762AAB78F7,
0x87E8C60FDED7CF9D, 0xC51827E4773DF90E, 0x020905D88D03A2BB, 0x40F9E43324E99428,
0x2CFFE7D5975E55E2, 0x6E0F063E3EB46371, 0xA91E2402C48A38C4, 0xEBEEC5E96D600E57,
0x65CC8190991CB93D, 0x273C607B30F68FAE, 0xE02D4247CAC8D41B, 0xA2DDA3AC6322E288,
0xBE992B5F8BDB8C5C, 0xFC69CAB42231BACF, 0x3B78E888D80FE17A, 0x7988096371E5D7E9,
0xF7AA4D1A85996083, 0xB55AACF12C735610, 0x724B8ECDD64D0DA5, 0x30BB6F267FA73B36,
0x4AC29F2A07BFD00D, 0x08327EC1AE55E69E, 0xCF235CFD546BBD2B, 0x8DD3BD16FD818BB8,
0x03F1F96F09FD3CD2, 0x41011884A0170A41, 0x86103AB85A2951F4, 0xC4E0DB53F3C36767,
0xD8A453A01B3A09B3, 0x9A54B24BB2D03F20, 0x5D45907748EE6495, 0x1FB5719CE1045206,
0x919735E51578E56C, 0xD367D40EBC92D3FF, 0x1476F63246AC884A, 0x568617D9EF46BED9,
0xE085162AB69D5E3C, 0xA275F7C11F7768AF, 0x6564D5FDE549331A, 0x279434164CA30589,
0xA9B6706FB8DFB2E3, 0xEB46918411358470, 0x2C57B3B8EB0BDFC5, 0x6EA7525342E1E956,
0x72E3DAA0AA188782, 0x30133B4B03F2B111, 0xF7021977F9CCEAA4, 0xB5F2F89C5026DC37,
0x3BD0BCE5A45A6B5D, 0x79205D0E0DB05DCE, 0xBE317F32F78E067B, 0xFCC19ED95E6430E8,
0x86B86ED5267CDBD3, 0xC4488F3E8F96ED40, 0x0359AD0275A8B6F5, 0x41A94CE9DC428066,
0xCF8B0890283E370C, 0x8D7BE97B81D4019F, 0x4A6ACB477BEA5A2A, 0x089A2AACD2006CB9,
0x14DEA25F3AF9026D, 0x562E43B4931334FE, 0x913F6188692D6F4B, 0xD3CF8063C0C759D8,
0x5DEDC41A34BBEEB2, 0x1F1D25F19D51D821, 0xD80C07CD676F8394, 0x9AFCE626CE85B507
};
return (crc << 8) ^ CRC64_ECMA[((crc >> 56) ^ value) & 0xFF];
}

View File

@ -48,12 +48,6 @@ SOFTWARE.
namespace etl
{
//***************************************************************************
/// CRC8 table
/// \ingroup crc8_ccitt
//***************************************************************************
extern const uint8_t CRC8_CCITT[];
//***************************************************************************
/// CRC8 CCITT policy.
/// Calculates CRC8 CCITT using polynomial 0x07.
@ -69,7 +63,27 @@ namespace etl
inline uint8_t add(uint8_t crc, uint8_t value) const
{
return CRC8_CCITT[crc ^ value];
static const uint8_t CRC8_CCITT[256] =
{
0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15, 0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D,
0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65, 0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D,
0xE0, 0xE7, 0xEE, 0xE9, 0xFC, 0xFB, 0xF2, 0xF5, 0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD,
0x90, 0x97, 0x9E, 0x99, 0x8C, 0x8B, 0x82, 0x85, 0xA8, 0xAF, 0xA6, 0xA1, 0xB4, 0xB3, 0xBA, 0xBD,
0xC7, 0xC0, 0xC9, 0xCE, 0xDB, 0xDC, 0xD5, 0xD2, 0xFF, 0xF8, 0xF1, 0xF6, 0xE3, 0xE4, 0xED, 0xEA,
0xB7, 0xB0, 0xB9, 0xBE, 0xAB, 0xAC, 0xA5, 0xA2, 0x8F, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9D, 0x9A,
0x27, 0x20, 0x29, 0x2E, 0x3B, 0x3C, 0x35, 0x32, 0x1F, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0D, 0x0A,
0x57, 0x50, 0x59, 0x5E, 0x4B, 0x4C, 0x45, 0x42, 0x6F, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7D, 0x7A,
0x89, 0x8E, 0x87, 0x80, 0x95, 0x92, 0x9B, 0x9C, 0xB1, 0xB6, 0xBF, 0xB8, 0xAD, 0xAA, 0xA3, 0xA4,
0xF9, 0xFE, 0xF7, 0xF0, 0xE5, 0xE2, 0xEB, 0xEC, 0xC1, 0xC6, 0xCF, 0xC8, 0xDD, 0xDA, 0xD3, 0xD4,
0x69, 0x6E, 0x67, 0x60, 0x75, 0x72, 0x7B, 0x7C, 0x51, 0x56, 0x5F, 0x58, 0x4D, 0x4A, 0x43, 0x44,
0x19, 0x1E, 0x17, 0x10, 0x05, 0x02, 0x0B, 0x0C, 0x21, 0x26, 0x2F, 0x28, 0x3D, 0x3A, 0x33, 0x34,
0x4E, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5C, 0x5B, 0x76, 0x71, 0x78, 0x7F, 0x6A, 0x6D, 0x64, 0x63,
0x3E, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2C, 0x2B, 0x06, 0x01, 0x08, 0x0F, 0x1A, 0x1D, 0x14, 0x13,
0xAE, 0xA9, 0xA0, 0xA7, 0xB2, 0xB5, 0xBC, 0xBB, 0x96, 0x91, 0x98, 0x9F, 0x8A, 0x8D, 0x84, 0x83,
0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB, 0xE6, 0xE1, 0xE8, 0xEF, 0xFA, 0xFD, 0xF4, 0xF3
};
return CRC8_CCITT[crc ^ value];
}
inline uint8_t final(uint8_t crc) const

View File

@ -44,6 +44,18 @@ SOFTWARE.
namespace etl
{
namespace private_error_handler
{
template <class dummy>
struct wrapper
{
static etl::ifunction<const etl::exception&>* p_ifunction;
};
template <class dummy>
etl::ifunction<const etl::exception&>* wrapper<dummy>::p_ifunction = nullptr;
}
//***************************************************************************
/// Error handler for when throwing exceptions is not required.
///\ingroup error_handler
@ -75,12 +87,26 @@ namespace etl
}
};
static void set_callback(ifunction<const etl::exception&>& f);
static void error(const etl::exception& e);
//*****************************************************************************
/// Sets the error callback function.
///\param f A reference to an etl::function object that will handler errors.
//*****************************************************************************
static void set_callback(ifunction<const etl::exception&>& f)
{
private_error_handler::wrapper<void>::p_ifunction = &f;
}
private:
static ifunction<const etl::exception&>* p_ifunction;
//*****************************************************************************
/// Sends the exception error to the user's handler function.
///\param e The exception error.
//*****************************************************************************
static void error(const etl::exception& e)
{
if (private_error_handler::wrapper<void>::p_ifunction != nullptr)
{
(*private_error_handler::wrapper<void>::p_ifunction)(e);
}
}
};
}
@ -95,12 +121,12 @@ namespace etl
///\ingroup error_handler
//***************************************************************************
#if defined(ETL_NO_CHECKS)
#define ETL_ASSERT(b, e) // Does nothing.
#define ETL_ASSERT(b, e) // Does nothing.
#elif defined(ETL_THROW_EXCEPTIONS)
#if defined(ETL_LOG_ERRORS)
#define ETL_ASSERT(b, e) {if (!(b)) {etl::error_handler::error((e)); throw((e);)}} // If the condition fails, calls the error handler then throws an exception.
#define ETL_ASSERT(b, e) {if (!(b)) {etl::error_handler::error((e)); throw((e);)}} // If the condition fails, calls the error handler then throws an exception.
#else
#define ETL_ASSERT(b, e) {if (!(b)) {throw((e));}} // If the condition fails, throws an exception.
#define ETL_ASSERT(b, e) {if (!(b)) {throw((e));}} // If the condition fails, throws an exception.
#endif
#else
#if defined(ETL_LOG_ERRORS)
@ -111,9 +137,9 @@ namespace etl
#endif
#else
#if defined(NDEBUG)
#define ETL_ASSERT(b, e) // Does nothing.
#define ETL_ASSERT(b, e) // Does nothing.
#else
#define ETL_ASSERT(b, e) assert((b)) // If the condition fails, asserts.
#define ETL_ASSERT(b, e) assert((b)) // If the condition fails, asserts.
#endif
#endif
#endif

View File

@ -121,6 +121,20 @@ namespace etl
}
};
//***************************************************************************
/// Unsorted exception for the list.
///\ingroup list
//***************************************************************************
class forward_list_no_pool : public forward_list_exception
{
public:
forward_list_no_pool(string_type file_name_, numeric_type line_number_)
: forward_list_exception(ETL_ERROR_TEXT("list:no pool", ETL_FILE"D"), file_name_, line_number_)
{
}
};
//***************************************************************************
/// The base class for all forward_lists.
///\ingroup forward_list
@ -146,12 +160,39 @@ namespace etl
typedef size_t size_type; ///< The type used for determining the size of forward_list.
//*************************************************************************
/// <b>true</b> if the list has a shared pool.
//*************************************************************************
bool has_shared_pool() const
{
return pool_is_shared;
}
//*************************************************************************
/// Gets the size of the forward_list.
//*************************************************************************
size_type size() const
{
return p_node_pool->size();
if (has_shared_pool())
{
// We have to count what we actually own.
size_type count = 0;
node_t* p_node = start_node.next;
while (p_node != nullptr)
{
++count;
p_node = p_node->next;
}
return count;
}
else
{
ETL_ASSERT(p_node_pool != nullptr, ETL_ERROR(forward_list_no_pool));
return p_node_pool->size();
}
}
//*************************************************************************
@ -167,7 +208,15 @@ namespace etl
//*************************************************************************
bool empty() const
{
return p_node_pool->empty();
if (has_shared_pool())
{
return (size() == 0);
}
else
{
ETL_ASSERT(p_node_pool != nullptr, ETL_ERROR(forward_list_no_pool));
return p_node_pool->empty();
}
}
//*************************************************************************
@ -175,6 +224,7 @@ namespace etl
//*************************************************************************
bool full() const
{
ETL_ASSERT(p_node_pool != nullptr, ETL_ERROR(forward_list_no_pool));
return p_node_pool->full();
}
@ -184,6 +234,7 @@ namespace etl
//*************************************************************************
size_t available() const
{
ETL_ASSERT(p_node_pool != nullptr, ETL_ERROR(forward_list_no_pool));
return p_node_pool->available();
}
@ -220,9 +271,20 @@ namespace etl
//*************************************************************************
/// The constructor that is called from derived classes.
//*************************************************************************
forward_list_base(etl::ipool& node_pool_, size_type max_size_)
forward_list_base(bool pool_is_shared_)
: p_node_pool(nullptr),
MAX_SIZE(0),
pool_is_shared(pool_is_shared_)
{
}
//*************************************************************************
/// The constructor that is called from derived classes.
//*************************************************************************
forward_list_base(etl::ipool& node_pool_, size_type max_size_, bool pool_is_shared_)
: p_node_pool(&node_pool_),
MAX_SIZE(max_size_)
MAX_SIZE(max_size_),
pool_is_shared(pool_is_shared_)
{
}
@ -275,10 +337,28 @@ namespace etl
left->next = right;
}
node_t start_node; ///< The node that acts as the forward_list start.
etl::ipool* p_node_pool; ///< The pool of data nodes used in the list.
const size_type MAX_SIZE; ///< The maximum size of the forward_list.
ETL_DECLARE_DEBUG_COUNT ///< Internal debugging.
//*************************************************************************
/// Set the node pool instance.
//*************************************************************************
void set_node_pool(etl::ipool& node_pool_)
{
p_node_pool = &node_pool_;
MAX_SIZE = p_node_pool->max_size();
}
//*************************************************************************
/// Get the node pool instance.
//*************************************************************************
etl::ipool* get_node_pool()
{
return p_node_pool;
}
node_t start_node; ///< The node that acts as the forward_list start.
etl::ipool* p_node_pool; ///< The pool of data nodes used in the list.
size_type MAX_SIZE; ///< The maximum size of the forward_list.
bool pool_is_shared; ///< If <b>true</b> then the pool is shared between lists.
ETL_DECLARE_DEBUG_COUNT ///< Internal debugging.
};
//***************************************************************************
@ -1235,8 +1315,16 @@ namespace etl
//*************************************************************************
/// Constructor.
//*************************************************************************
iforward_list(etl::ipool& node_pool, size_t max_size_)
: forward_list_base(node_pool, max_size_)
iforward_list(bool pool_is_shared_)
: forward_list_base(pool_is_shared_)
{
}
//*************************************************************************
/// Constructor.
//*************************************************************************
iforward_list(etl::ipool& node_pool, size_t max_size_, bool pool_is_shared_)
: forward_list_base(node_pool, max_size_, pool_is_shared_)
{
}
@ -1247,8 +1335,9 @@ namespace etl
{
if (!empty())
{
if ETL_IF_CONSTEXPR(etl::is_trivially_destructible<T>::value)
if (etl::is_trivially_destructible<T>::value && !has_shared_pool())
{
ETL_ASSERT(p_node_pool != nullptr, ETL_ERROR(forward_list_no_pool));
p_node_pool->release_all();
ETL_RESET_DEBUG_COUNT
}
@ -1387,7 +1476,7 @@ namespace etl
/// Default constructor.
//*************************************************************************
forward_list()
: etl::iforward_list<T>(node_pool, MAX_SIZE)
: etl::iforward_list<T>(node_pool, MAX_SIZE, false)
{
this->initialise();
}
@ -1396,7 +1485,7 @@ namespace etl
/// Construct from size and value.
//*************************************************************************
explicit forward_list(size_t initial_size, typename etl::iforward_list<T>::parameter_t value = T())
: etl::iforward_list<T>(node_pool, MAX_SIZE)
: etl::iforward_list<T>(node_pool, MAX_SIZE, false)
{
this->assign(initial_size, value);
}
@ -1405,7 +1494,7 @@ namespace etl
/// Copy constructor.
//*************************************************************************
forward_list(const forward_list& other)
: etl::iforward_list<T>(node_pool, MAX_SIZE)
: etl::iforward_list<T>(node_pool, MAX_SIZE, false)
{
this->assign(other.cbegin(), other.cend());
}
@ -1415,7 +1504,7 @@ namespace etl
//*************************************************************************
template <typename TIterator>
forward_list(TIterator first, TIterator last)
: etl::iforward_list<T>(node_pool, MAX_SIZE)
: etl::iforward_list<T>(node_pool, MAX_SIZE, false)
{
this->assign(first, last);
}
@ -1425,7 +1514,7 @@ namespace etl
/// Construct from initializer_list.
//*************************************************************************
forward_list(std::initializer_list<T> init)
: etl::iforward_list<T>(node_pool, MAX_SIZE)
: etl::iforward_list<T>(node_pool, MAX_SIZE, false)
{
this->assign(init.begin(), init.end());
}
@ -1457,6 +1546,125 @@ namespace etl
/// The pool of nodes used in the list.
etl::pool<typename etl::iforward_list<T>::data_node_t, MAX_SIZE> node_pool;
};
//*************************************************************************
/// A templated forward_list implementation that uses a fixed size pool.
///\note 'merge' and 'splice_after' and are not supported.
//*************************************************************************
template <typename T>
class forward_list<T, 0> : public etl::iforward_list<T>
{
public:
typedef T value_type;
typedef T* pointer;
typedef const T* const_pointer;
typedef T& reference;
typedef const T& const_reference;
typedef size_t size_type;
typedef typename etl::iforward_list<T>::data_node_t pool_type;
//*************************************************************************
/// Default constructor.
//*************************************************************************
forward_list()
: etl::iforward_list<T>(true)
{
}
//*************************************************************************
/// Default constructor.
//*************************************************************************
explicit forward_list(etl::ipool& node_pool)
: etl::iforward_list<T>(node_pool, node_pool.max_size(), true)
{
this->initialise();
}
//*************************************************************************
/// Construct from size.
//*************************************************************************
explicit forward_list(size_t initial_size, etl::ipool& node_pool)
: etl::iforward_list<T>(node_pool, node_pool.max_size(), true)
{
this->assign(initial_size, T());
}
//*************************************************************************
/// Construct from size and value.
//*************************************************************************
explicit forward_list(size_t initial_size, typename etl::iforward_list<T>::parameter_t value, etl::ipool& node_pool)
: etl::iforward_list<T>(node_pool, node_pool.max_size(), true)
{
this->assign(initial_size, value);
}
//*************************************************************************
/// Copy constructor.
//*************************************************************************
forward_list(const forward_list& other)
: etl::iforward_list<T>(*other.p_node_pool, other.p_node_pool->max_size(), true)
{
this->assign(other.cbegin(), other.cend());
}
//*************************************************************************
/// Construct from range.
//*************************************************************************
template <typename TIterator>
forward_list(TIterator first, TIterator last, etl::ipool& node_pool)
: etl::iforward_list<T>(node_pool, node_pool.max_size(), true)
{
this->assign(first, last);
}
#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL)
//*************************************************************************
/// Construct from initializer_list.
//*************************************************************************
forward_list(std::initializer_list<T> init, etl::ipool& node_pool)
: etl::iforward_list<T>(node_pool, node_pool.max_size(), true)
{
this->assign(init.begin(), init.end());
}
#endif
//*************************************************************************
/// Destructor.
//*************************************************************************
~forward_list()
{
this->initialise();
}
//*************************************************************************
/// Assignment operator.
//*************************************************************************
forward_list& operator = (const forward_list& rhs)
{
if (&rhs != this)
{
this->assign(rhs.cbegin(), rhs.cend());
}
return *this;
}
//*************************************************************************
/// Set the pool instance.
//*************************************************************************
void set_pool(etl::ipool& pool)
{
// Clear the list of any current elements.
if (this->get_node_pool() != nullptr)
{
this->clear();
}
this->set_node_pool(pool);
}
};
}
//*************************************************************************

View File

@ -382,6 +382,14 @@ namespace etl
MAX_SIZE = p_node_pool->max_size();
}
//*************************************************************************
/// Get the node pool instance.
//*************************************************************************
etl::ipool* get_node_pool()
{
return p_node_pool;
}
//*************************************************************************
/// Destructor.
//*************************************************************************
@ -1910,6 +1918,12 @@ namespace etl
//*************************************************************************
void set_pool(etl::ipool& pool)
{
// Clear the list of any current elements.
if (this->get_node_pool() != nullptr)
{
this->clear();
}
this->set_node_pool(pool);
}
};
@ -1994,7 +2008,6 @@ bool operator >=(const etl::ilist<T>& lhs, const etl::ilist<T>& rhs)
return !(lhs < rhs);
}
#include "private/minmax_pop.h"
#undef ETL_FILE

View File

@ -5,9 +5,9 @@ The MIT License(MIT)
Embedded Template Library.
https://github.com/ETLCPP/etl
http://www.etlcpp.com
https://www.etlcpp.com
Copyright(c) 2014 jwellbelove
Copyright(c) 2018 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
@ -28,33 +28,16 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
******************************************************************************/
#include "etl/platform.h"
#include "etl/error_handler.h"
#include "etl/nullptr.h"
#ifndef ETL_MACROS_INCLUDED
#define ETL_MACROS_INCLUDED
//*****************************************************************************
/// The error function callback pointer.
//*****************************************************************************
etl::ifunction<const etl::exception&>* etl::error_handler::p_ifunction = nullptr;
#define ETL_CONCAT2(X, Y) X##Y
#define ETL_CONCAT(X, Y) ETL_CONCAT2(X, Y)
#define ETL_STRINGIFY2(X) #X
#define ETL_STRINGIFY(X) ETL_STRINGIFY2(X)
#define ETL_WIDE_STRING(X) ETL_CONCAT(L, ETL_STRINGIFY(X))
#define ETL_U16_STRING(X) ETL_CONCAT(u, ETL_STRINGIFY(X))
#define ETL_U32_STRING(X) ETL_CONCAT(U, ETL_STRINGIFY(X))
//*****************************************************************************
/// Sets the error callback function.
///\param f A reference to an etl::function object that will handler errors.
//*****************************************************************************
void etl::error_handler::set_callback(ifunction<const etl::exception&>& f)
{
p_ifunction = &f;
}
//*****************************************************************************
/// Sends the exception error to the user's handler function.
///\param e The exception error.
//*****************************************************************************
void etl::error_handler::error(const etl::exception& e)
{
if (p_ifunction != nullptr)
{
(*p_ifunction)(e);
}
}
#endif

View File

@ -51,12 +51,6 @@ ETL_STATIC_ASSERT(ETL_8BIT_SUPPORT, "This file does not currently support target
namespace etl
{
//***************************************************************************
/// Pearson lookup table
/// \ingroup pearson
//***************************************************************************
extern const uint8_t PEARSON_LOOKUP[];
//***************************************************************************
/// Calculates a Pearson hash
///\tparam HASH_LENGTH The number of elements in the hash.
@ -122,6 +116,26 @@ namespace etl
//*************************************************************************
void add(uint8_t value_)
{
static const uint8_t PEARSON_LOOKUP[] =
{
228, 39, 61, 95, 227, 187, 0, 197, 31, 189, 161, 222, 34, 15, 221, 246,
19, 234, 6, 50, 113, 3, 91, 63, 77, 245, 144, 2, 183, 196, 25, 226,
97, 126, 48, 59, 217, 4, 100, 145, 12, 88, 203, 149, 80, 154, 38, 27,
224, 218, 158, 115, 202, 79, 53, 83, 242, 36, 139, 131, 136, 191, 42, 170,
23, 99, 156, 51, 143, 60, 233, 206, 62, 108, 17, 67, 81, 71, 93, 195,
26, 231, 247, 96, 24, 200, 176, 209, 152, 212, 138, 165, 75, 185, 130, 248,
125, 110, 10, 116, 201, 90, 69, 204, 85, 251, 78, 157, 47, 184, 169, 141,
134, 230, 89, 21, 146, 46, 55, 128, 148, 207, 216, 11, 114, 199, 103, 102,
166, 244, 5, 104, 225, 160, 132, 28, 172, 65, 121, 140, 153, 119, 198, 210,
58, 87, 117, 177, 33, 22, 13, 37, 49, 174, 109, 40, 73, 211, 18, 167,
164, 252, 168, 74, 30, 173, 35, 98, 66, 193, 94, 175, 86, 54, 179, 122,
220, 151, 192, 29, 133, 254, 155, 127, 240, 232, 190, 180, 8, 68, 236, 20,
137, 92, 219, 208, 52, 250, 147, 142, 111, 112, 120, 45, 135, 255, 123, 229,
57, 182, 243, 124, 186, 253, 7, 237, 9, 16, 70, 171, 235, 107, 223, 118,
215, 178, 194, 181, 43, 188, 106, 105, 64, 241, 84, 238, 159, 44, 32, 76,
213, 163, 150, 101, 129, 14, 249, 205, 214, 1, 41, 56, 162, 72, 239, 82
};
if (first)
{
for (size_t i = 0; i < HASH_LENGTH; ++i)

View File

@ -75,41 +75,246 @@ namespace etl
public:
iterator begin();
const_iterator begin() const;
//*********************************************************************
/// Returns an iterator to the beginning of the vector.
///\return An iterator to the beginning of the vector.
//*********************************************************************
iterator begin()
{
return p_buffer;
}
iterator end();
const_iterator end() const;
//*********************************************************************
/// Returns a const_iterator to the beginning of the vector.
///\return A const iterator to the beginning of the vector.
//*********************************************************************
const_iterator begin() const
{
return const_iterator(p_buffer);
}
const_iterator cbegin() const;
const_iterator cend() const;
//*********************************************************************
/// Returns an iterator to the end of the vector.
///\return An iterator to the end of the vector.
//*********************************************************************
iterator end()
{
return p_end;
}
reverse_iterator rbegin();
const_reverse_iterator rbegin() const;
//*********************************************************************
/// Returns a const_iterator to the end of the vector.
///\return A const iterator to the end of the vector.
//*********************************************************************
const_iterator end() const
{
return const_iterator(p_end);
}
reverse_iterator rend();
const_reverse_iterator rend() const;
//*********************************************************************
/// Returns a const_iterator to the beginning of the vector.
///\return A const iterator to the beginning of the vector.
//*********************************************************************
const_iterator cbegin() const
{
return const_iterator(p_buffer);
}
const_reverse_iterator crbegin() const;
const_reverse_iterator crend() const;
//*********************************************************************
/// Returns a const_iterator to the end of the vector.
///\return A const iterator to the end of the vector.
//*********************************************************************
const_iterator cend() const
{
return const_iterator(p_end);
}
void resize(size_t new_size);
void resize(size_t new_size, value_type value);
//*********************************************************************
/// Returns an reverse iterator to the reverse beginning of the vector.
///\return Iterator to the reverse beginning of the vector.
//*********************************************************************
reverse_iterator rbegin()
{
return reverse_iterator(end());
}
reference operator [](size_t i);
const_reference operator [](size_t i) const;
//*********************************************************************
/// Returns a const reverse iterator to the reverse beginning of the vector.
///\return Const iterator to the reverse beginning of the vector.
//*********************************************************************
const_reverse_iterator rbegin() const
{
return const_reverse_iterator(end());
}
reference at(size_t i);
const_reference at(size_t i) const;
//*********************************************************************
/// Returns a reverse iterator to the end + 1 of the vector.
///\return Reverse iterator to the end + 1 of the vector.
//*********************************************************************
reverse_iterator rend()
{
return reverse_iterator(begin());
}
reference front();
const_reference front() const;
//*********************************************************************
/// Returns a const reverse iterator to the end + 1 of the vector.
///\return Const reverse iterator to the end + 1 of the vector.
//*********************************************************************
const_reverse_iterator rend() const
{
return const_reverse_iterator(begin());
}
reference back();
const_reference back() const;
//*********************************************************************
/// Returns a const reverse iterator to the reverse beginning of the vector.
///\return Const reverse iterator to the reverse beginning of the vector.
//*********************************************************************
const_reverse_iterator crbegin() const
{
return const_reverse_iterator(cend());
}
pointer data();
const_pointer data() const;
//*********************************************************************
/// Returns a const reverse iterator to the end + 1 of the vector.
///\return Const reverse iterator to the end + 1 of the vector.
//*********************************************************************
const_reverse_iterator crend() const
{
return const_reverse_iterator(cbegin());
}
//*********************************************************************
/// Resizes the vector.
/// If asserts or exceptions are enabled and the new size is larger than the
/// maximum then a vector_full is thrown.
///\param new_size The new size.
//*********************************************************************
void resize(size_t new_size)
{
ETL_ASSERT(new_size <= CAPACITY, ETL_ERROR(vector_full));
p_end = p_buffer + new_size;
}
//*********************************************************************
/// Resizes the vector.
/// If asserts or exceptions are enabled and the new size is larger than the
/// maximum then a vector_full is thrown.
///\param new_size The new size.
///\param value The value to fill new elements with. Default = default constructed value.
//*********************************************************************
void resize(size_t new_size, value_type value)
{
ETL_ASSERT(new_size <= CAPACITY, ETL_ERROR(vector_full));
pointer p_new_end = p_buffer + new_size;
// Size up if necessary.
if (p_end < p_new_end)
{
std::fill(p_end, p_new_end, value);
}
p_end = p_new_end;
}
//*********************************************************************
/// Returns a reference to the value at index 'i'
///\param i The index.
///\return A reference to the value at index 'i'
//*********************************************************************
reference operator [](size_t i)
{
return reference(p_buffer[i]);
}
//*********************************************************************
/// Returns a const reference to the value at index 'i'
///\param i The index.
///\return A const reference to the value at index 'i'
//*********************************************************************
const_reference operator [](size_t i) const
{
return const_reference(p_buffer[i]);
}
//*********************************************************************
/// Returns a reference to the value at index 'i'
/// If asserts or exceptions are enabled, emits an etl::vector_out_of_bounds if the index is out of range.
///\param i The index.
///\return A reference to the value at index 'i'
//*********************************************************************
reference at(size_t i)
{
ETL_ASSERT(i < size(), ETL_ERROR(vector_out_of_bounds));
return reference(p_buffer[i]);
}
//*********************************************************************
/// Returns a const reference to the value at index 'i'
/// If asserts or exceptions are enabled, emits an etl::vector_out_of_bounds if the index is out of range.
///\param i The index.
///\return A const reference to the value at index 'i'
//*********************************************************************
const_reference at(size_t i) const
{
ETL_ASSERT(i < size(), ETL_ERROR(vector_out_of_bounds));
return const_reference(p_buffer[i]);
}
//*********************************************************************
/// Returns a reference to the first element.
///\return A reference to the first element.
//*********************************************************************
reference front()
{
return reference(p_buffer[0]);
}
//*********************************************************************
/// Returns a const reference to the first element.
///\return A const reference to the first element.
//*********************************************************************
const_reference front() const
{
return const_reference(p_buffer[0]);
}
//*********************************************************************
/// Returns a reference to the last element.
///\return A reference to the last element.
//*********************************************************************
reference back()
{
return reference(*(p_end - 1));
}
//*********************************************************************
/// Returns a const reference to the last element.
///\return A const reference to the last element.
//*********************************************************************
const_reference back() const
{
return const_reference(*(p_end - 1));
}
//*********************************************************************
/// Returns a pointer to the beginning of the vector data.
///\return A pointer to the beginning of the vector data.
//*********************************************************************
pointer data()
{
return pointer(p_buffer);
}
//*********************************************************************
/// Returns a const pointer to the beginning of the vector data.
///\return A const pointer to the beginning of the vector data.
//*********************************************************************
const_pointer data() const
{
return const_pointer(p_buffer);
}
//*********************************************************************
/// Assigns values to the vector.
@ -134,16 +339,97 @@ namespace etl
}
}
void assign(size_t n, value_type value);
//*********************************************************************
/// Assigns values to the vector.
/// If asserts or exceptions are enabled, emits vector_full if the vector does not have enough free space.
///\param n The number of elements to add.
///\param value The value to insert for each element.
//*********************************************************************
void assign(size_t n, value_type value)
{
initialise();
void clear();
ETL_ASSERT(n <= CAPACITY, ETL_ERROR(vector_full));
void push_back(value_type value);
for (size_t current_size = 0; current_size < n; ++current_size)
{
*p_end++ = value;
}
}
void pop_back();
//*************************************************************************
/// Clears the vector.
//*************************************************************************
void clear()
{
initialise();
}
iterator insert(iterator position, value_type value);
void insert(iterator position, size_t n, value_type value);
//*********************************************************************
/// Inserts a value at the end of the vector.
/// If asserts or exceptions are enabled, emits vector_full if the vector is already full.
///\param value The value to add.
//*********************************************************************
void push_back(value_type value)
{
#if defined(ETL_CHECK_PUSH_POP)
ETL_ASSERT(size() != CAPACITY, ETL_ERROR(vector_full));
#endif
*p_end++ = value;
}
//*************************************************************************
/// Removes an element from the end of the vector.
/// Does nothing if the vector is empty.
//*************************************************************************
void pop_back()
{
#if defined(ETL_CHECK_PUSH_POP)
ETL_ASSERT(size() > 0, ETL_ERROR(vector_empty));
#endif
--p_end;
}
//*********************************************************************
/// Inserts a value to the vector.
/// If asserts or exceptions are enabled, emits vector_full if the vector is already full.
///\param position The position to insert before.
///\param value The value to insert.
//*********************************************************************
iterator insert(iterator position, value_type value)
{
ETL_ASSERT(size() + 1 <= CAPACITY, ETL_ERROR(vector_full));
if (position != end())
{
++p_end;
std::copy_backward(position, end() - 1, end());
*position = value;
}
else
{
*p_end++ = value;
}
return position;
}
//*********************************************************************
/// Inserts 'n' values to the vector.
/// If asserts or exceptions are enabled, emits vector_full if the vector does not have enough free space.
///\param position The position to insert before.
///\param n The number of elements to add.
///\param value The value to insert.
//*********************************************************************
void insert(iterator position, size_t n, value_type value)
{
ETL_ASSERT((size() + 1) <= CAPACITY, ETL_ERROR(vector_full));
std::copy_backward(position, p_end, p_end + n);
std::fill_n(position, n, value);
p_end += n;
}
//*********************************************************************
/// Inserts a range of values to the vector.
@ -165,26 +451,117 @@ namespace etl
p_end += count;
}
iterator erase(iterator i_element);
iterator erase(iterator first, iterator last);
//*********************************************************************
/// Erases an element.
///\param i_element Iterator to the element.
///\return An iterator pointing to the element that followed the erased element.
//*********************************************************************
iterator erase(iterator i_element)
{
std::copy(i_element + 1, end(), i_element);
--p_end;
pvoidvector& operator = (const pvoidvector& rhs);
return i_element;
}
size_type size() const;
//*********************************************************************
/// Erases a range of elements.
/// The range includes all the elements between first and last, including the
/// element pointed by first, but not the one pointed by last.
///\param first Iterator to the first element.
///\param last Iterator to the last element.
///\return An iterator pointing to the element that followed the erased element.
//*********************************************************************
iterator erase(iterator first, iterator last)
{
std::copy(last, end(), first);
size_t n_delete = std::distance(first, last);
bool empty() const;
// Just adjust the count.
p_end -= n_delete;
bool full() const;
return first;
}
size_t available() const;
//*************************************************************************
/// Assignment operator.
//*************************************************************************
etl::pvoidvector& operator = (const etl::pvoidvector& rhs)
{
if (&rhs != this)
{
assign(rhs.cbegin(), rhs.cend());
}
return *this;
}
//*************************************************************************
/// Gets the current size of the vector.
///\return The current size of the vector.
//*************************************************************************
size_type size() const
{
return size_t(p_end - p_buffer);
}
//*************************************************************************
/// Checks the 'empty' state of the vector.
///\return <b>true</b> if empty.
//*************************************************************************
bool empty() const
{
return (p_end == p_buffer);
}
//*************************************************************************
/// Checks the 'full' state of the vector.
///\return <b>true</b> if full.
//*************************************************************************
bool full() const
{
return size() == CAPACITY;
}
//*************************************************************************
/// Returns the remaining capacity.
///\return The remaining capacity.
//*************************************************************************
size_t available() const
{
return max_size() - size();
}
protected:
pvoidvector(void** p_buffer_, size_t MAX_SIZE);
//*********************************************************************
/// Constructor.
//*********************************************************************
pvoidvector(void** p_buffer_, size_t MAX_SIZE)
: vector_base(MAX_SIZE),
p_buffer(p_buffer_),
p_end(p_buffer_)
{
}
void initialise();
//*********************************************************************
/// Initialise the vector.
//*********************************************************************
void initialise()
{
p_end = p_buffer;
}
void repair_buffer(void** p_buffer_);
//*************************************************************************
/// Fix the internal pointers after a low level memory copy.
//*************************************************************************
void repair_buffer(void** p_buffer_)
{
uintptr_t length = p_end - p_buffer;
p_buffer = p_buffer_;
p_end = p_buffer_ + length;
}
void** p_buffer;
void** p_end;
@ -195,12 +572,77 @@ namespace etl
pvoidvector(const pvoidvector&);
};
bool operator ==(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs);
bool operator !=(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs);
bool operator <(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs);
bool operator >(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs);
bool operator <=(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs);
bool operator >=(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs);
//***************************************************************************
/// Equal operator.
///\param lhs Reference to the first vector.
///\param rhs Reference to the second vector.
///\return <b>true</b> if the arrays are equal, otherwise <b>false</b>
///\ingroup vector
//***************************************************************************
inline bool operator ==(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs)
{
return (lhs.size() == rhs.size()) && std::equal(lhs.begin(), lhs.end(), rhs.begin());
}
//***************************************************************************
/// Not equal operator.
///\param lhs Reference to the first vector.
///\param rhs Reference to the second vector.
///\return <b>true</b> if the arrays are not equal, otherwise <b>false</b>
///\ingroup vector
//***************************************************************************
inline bool operator !=(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs)
{
return !(lhs == rhs);
}
//***************************************************************************
/// Less than operator.
///\param lhs Reference to the first vector.
///\param rhs Reference to the second vector.
///\return <b>true</b> if the first vector is lexicographically less than the second, otherwise <b>false</b>
///\ingroup vector
//***************************************************************************
inline bool operator <(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs)
{
return std::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
}
//***************************************************************************
/// Greater than operator.
///\param lhs Reference to the first vector.
///\param rhs Reference to the second vector.
///\return <b>true</b> if the first vector is lexicographically greater than the second, otherwise <b>false</b>
///\ingroup vector
//***************************************************************************
inline bool operator >(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs)
{
return (rhs < lhs);
}
//***************************************************************************
/// Less than or equal operator.
///\param lhs Reference to the first vector.
///\param rhs Reference to the second vector.
///\return <b>true</b> if the first vector is lexicographically less than or equal to the second, otherwise <b>false</b>
///\ingroup vector
//***************************************************************************
inline bool operator <=(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs)
{
return !(lhs > rhs);
}
//***************************************************************************
/// Greater than or equal operator.
///\param lhs Reference to the first vector.
///\param rhs Reference to the second vector.
///\return <b>true</b> if the first vector is lexicographically greater than or equal to the second, otherwise <b>false</b>
///\ingroup vector
//***************************************************************************
inline bool operator >=(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs)
{
return !(lhs < rhs);
}
}
#include "minmax_pop.h"

View File

@ -1,4 +1,4 @@
///\file
///\file
/******************************************************************************
The MIT License(MIT)
@ -34,6 +34,7 @@ SOFTWARE.
#include <stdint.h>
#include "platform.h"
#include "binary.h"
namespace etl
{
@ -62,11 +63,71 @@ namespace etl
{
public:
random_xorshift();
explicit random_xorshift(uint32_t seed);
void initialise(uint32_t seed);
uint32_t operator()();
uint32_t range(uint32_t low, uint32_t high);
//***************************************************************************
/// Default constructor.
/// Attempts to come up with a unique non-zero seed.
//***************************************************************************
random_xorshift()
{
// An attempt to come up with a unique non-zero seed,
// based on the address of the instance.
uintptr_t n = reinterpret_cast<uintptr_t>(this);
uint32_t seed = static_cast<uint32_t>(n);
initialise(seed);
}
//***************************************************************************
/// Constructor with seed value.
///\param seed The new seed value.
//***************************************************************************
random_xorshift(uint32_t seed)
{
initialise(seed);
}
//***************************************************************************
/// Initialises the sequence with a new seed value.
///\param seed The new seed value.
//***************************************************************************
void initialise(uint32_t seed)
{
// Add the first four primes to ensure that the seed isn't zero.
state[0] = seed + 3;
state[1] = seed + 5;
state[2] = seed + 7;
state[3] = seed + 11;
}
//***************************************************************************
/// Get the next random_xorshift number.
//***************************************************************************
uint32_t operator()()
{
uint32_t n = state[3];
n ^= n << 11;
n ^= n >> 8;
state[3] = state[2];
state[2] = state[1];
state[1] = state[0];
n ^= state[0];
n ^= state[0] >> 19;
state[0] = n;
return n;
}
//***************************************************************************
/// Get the next random_xorshift number in a specified inclusive range.
//***************************************************************************
uint32_t range(uint32_t low, uint32_t high)
{
uint32_t r = high - low + 1;
uint32_t n = operator()();
n %= r;
n += low;
return n;
}
private:
@ -82,11 +143,60 @@ namespace etl
{
public:
random_lcg();
explicit random_lcg(uint32_t seed);
void initialise(uint32_t seed);
uint32_t operator()();
uint32_t range(uint32_t low, uint32_t high);
//***************************************************************************
/// Default constructor.
/// Attempts to come up with a unique non-zero seed.
//***************************************************************************
random_lcg()
{
// An attempt to come up with a unique non-zero seed,
// based on the address of the instance.
uintptr_t n = reinterpret_cast<uintptr_t>(this);
uint32_t seed = static_cast<uint32_t>(n);
initialise(seed);
}
//***************************************************************************
/// Constructor with seed value.
///\param seed The new seed value.
//***************************************************************************
random_lcg(uint32_t seed)
{
initialise(seed);
}
//***************************************************************************
/// Initialises the sequence with a new seed value.
///\param seed The new seed value.
//***************************************************************************
void initialise(uint32_t seed)
{
seed = (seed == 0) ? 1 : seed;
value = (seed > m) ? m : seed;
}
//***************************************************************************
/// Get the next random_clcg number.
//***************************************************************************
uint32_t operator()()
{
value = (a * value) % m;
return value;
}
//***************************************************************************
/// Get the next random_clcg number in a specified inclusive range.
//***************************************************************************
uint32_t range(uint32_t low, uint32_t high)
{
uint32_t r = high - low + 1;
uint32_t n = operator()();
n %= r;
n += low;
return n;
}
private:
@ -105,11 +215,64 @@ namespace etl
{
public:
random_clcg();
explicit random_clcg(uint32_t seed);
void initialise(uint32_t seed);
uint32_t operator()();
uint32_t range(uint32_t low, uint32_t high);
//***************************************************************************
/// Default constructor.
/// Attempts to come up with a unique non-zero seed.
//***************************************************************************
random_clcg()
{
// An attempt to come up with a unique non-zero seed,
// based on the address of the instance.
uintptr_t n = reinterpret_cast<uintptr_t>(this);
uint32_t seed = static_cast<uint32_t>(n);
initialise(seed);
}
//***************************************************************************
/// Constructor with seed value.
///\param seed The new seed value.
//***************************************************************************
random_clcg(uint32_t seed)
{
initialise(seed);
}
//***************************************************************************
/// Initialises the sequence with a new seed value.
///\param seed The new seed value.
//***************************************************************************
void initialise(uint32_t seed)
{
seed = (seed == 0) ? 1 : seed;
value1 = (seed > m1) ? m1 : seed;
value2 = (seed > m1) ? m1 : seed;
}
//***************************************************************************
/// Get the next random_clcg number.
//***************************************************************************
uint32_t operator()()
{
static const uint32_t m = ((m1 > m2) ? m1 : m2);
value1 = (a1 * value1) % m1;
value2 = (a2 * value2) % m2;
return (value1 + value2) % m;
}
//***************************************************************************
/// Get the next random_clcg number in a specified inclusive range.
//***************************************************************************
uint32_t range(uint32_t low, uint32_t high)
{
uint32_t r = high - low + 1;
uint32_t n = operator()();
n %= r;
n += low;
return n;
}
private:
@ -126,17 +289,73 @@ namespace etl
//***************************************************************************
/// A 32 bit random number generator.
/// Uses a linear shift feedback register.
/// Polynomial 0x80200003
/// https://en.wikipedia.org/wiki/Linear-feedback_shift_register
//***************************************************************************
class random_lsfr : public random
{
public:
random_lsfr();
explicit random_lsfr(uint32_t seed);
void initialise(uint32_t seed);
uint32_t operator()();
uint32_t range(uint32_t low, uint32_t high);
//***************************************************************************
/// Default constructor.
/// Attempts to come up with a unique non-zero seed.
//***************************************************************************
random_lsfr()
{
// An attempt to come up with a unique non-zero seed,
// based on the address of the instance.
uintptr_t n = reinterpret_cast<uintptr_t>(this);
uint32_t seed = static_cast<uint32_t>(n);
initialise(seed);
}
//***************************************************************************
/// Constructor with seed value.
///\param seed The new seed value.
//***************************************************************************
random_lsfr(uint32_t seed)
{
initialise(seed);
}
//***************************************************************************
/// Initialises the sequence with a new seed value.
///\param seed The new seed value.
//***************************************************************************
void initialise(uint32_t seed)
{
value = seed;
}
//***************************************************************************
/// Get the next random_lsfr number.
//***************************************************************************
uint32_t operator()()
{
static const uint32_t polynomial = 0x80200003;
value >>= 1;
if ((value & 1) == 1)
{
value ^= polynomial;
}
return value;
}
//***************************************************************************
/// Get the next random_lsfr number in a specified inclusive range.
//***************************************************************************
uint32_t range(uint32_t low, uint32_t high)
{
uint32_t r = high - low + 1;
uint32_t n = operator()();
n %= r;
n += low;
return n;
}
private:
@ -151,11 +370,61 @@ namespace etl
{
public:
random_mwc();
explicit random_mwc(uint32_t seed);
void initialise(uint32_t seed);
uint32_t operator()();
uint32_t range(uint32_t low, uint32_t high);
//***************************************************************************
/// Default constructor.
/// Attempts to come up with a unique non-zero seed.
//***************************************************************************
random_mwc()
{
// An attempt to come up with a unique non-zero seed,
// based on the address of the instance.
uintptr_t n = reinterpret_cast<uintptr_t>(this);
uint32_t seed = static_cast<uint32_t>(n);
initialise(seed);
}
//***************************************************************************
/// Constructor with seed value.
///\param seed The new seed value.
//***************************************************************************
random_mwc(uint32_t seed)
{
initialise(seed);
}
//***************************************************************************
/// Initialises the sequence with a new seed value.
///\param seed The new seed value.
//***************************************************************************
void initialise(uint32_t seed)
{
value1 = seed;
value2 = seed;
}
//***************************************************************************
/// Get the next random_lsfr number.
//***************************************************************************
uint32_t operator()()
{
value1 = 36969 * (value1 & 0xFFFF) + (value1 >> 16);
value2 = 18000 * (value2 & 0xFFFF) + (value2 >> 16);
return (value1 << 16) + value2;
}
//***************************************************************************
/// Get the next random_lsfr number in a specified inclusive range.
//***************************************************************************
uint32_t range(uint32_t low, uint32_t high)
{
uint32_t r = high - low + 1;
uint32_t n = operator()();
n %= r;
n += low;
return n;
}
private:
@ -172,11 +441,57 @@ namespace etl
{
public:
random_pcg();
explicit random_pcg(uint32_t seed);
void initialise(uint32_t seed);
uint32_t operator()();
uint32_t range(uint32_t low, uint32_t high);
random_pcg()
{
// An attempt to come up with a unique non-zero seed,
// based on the address of the instance.
uintptr_t n = reinterpret_cast<uintptr_t>(this);
value = static_cast<uint64_t>(n);
}
//***************************************************************************
/// Constructor with seed value.
///\param seed The new seed value.
//***************************************************************************
random_pcg(uint32_t seed)
{
initialise(seed);
}
//***************************************************************************
/// Initialises the sequence with a new seed value.
///\param seed The new seed value.
//***************************************************************************
void initialise(uint32_t seed)
{
value = uint64_t(seed) | (uint64_t(seed) << 32);
}
//***************************************************************************
/// Get the next random_lsfr number.
//***************************************************************************
uint32_t operator()()
{
uint64_t x = value;
unsigned count = (unsigned)(value >> 59);
value = (x * multiplier) + increment;
x ^= x >> 18;
return etl::rotate_right((uint32_t)(x >> 27), count);
}
//***************************************************************************
/// Get the next random_lsfr number in a specified inclusive range.
//***************************************************************************
uint32_t range(uint32_t low, uint32_t high)
{
uint32_t r = high - low + 1;
uint32_t n = operator()();
n %= r;
n += low;
return n;
}
private:
@ -185,6 +500,73 @@ namespace etl
uint64_t value;
};
#if ETL_8BIT_SUPPORT
//***************************************************************************
/// A 32 bit random number generator.
/// Applies a user supplied 32bit hash to a counter.
/// The hash must implement 'void add(uint8_t)' and 'uint8_t value()' member functions.
//***************************************************************************
template <typename THash>
class random_hash : public random
{
public:
random_hash()
{
// An attempt to come up with a unique non-zero seed,
// based on the address of the instance.
uintptr_t n = reinterpret_cast<uintptr_t>(this);
value = static_cast<uint32_t>(n);
}
//***************************************************************************
/// Constructor with seed value.
///\param seed The new seed value.
//***************************************************************************
random_hash(uint32_t seed)
{
initialise(seed);
}
//***************************************************************************
/// Initialises the sequence with a new seed value.
///\param seed The new seed value.
//***************************************************************************
void initialise(uint32_t seed)
{
value = seed;
}
//***************************************************************************
/// Get the next random_lsfr number.
//***************************************************************************
uint32_t operator()()
{
++value;
hash.add(value);
return hash.value();
}
//***************************************************************************
/// Get the next random_lsfr number in a specified inclusive range.
//***************************************************************************
uint32_t range(uint32_t low, uint32_t high)
{
uint32_t r = high - low + 1;
uint32_t n = operator()();
n %= r;
n += low;
return n;
}
private:
THash hash;
uint8_t value;
};
#endif
}
#endif

View File

@ -93,7 +93,8 @@ namespace etl
const state_id_t next_state_id_,
void (TObject::* const action_)() = nullptr,
bool (TObject::* const guard_)() = nullptr)
: current_state_id(current_state_id_),
: from_any_state(false),
current_state_id(current_state_id_),
event_id(event_id_),
next_state_id(next_state_id_),
action(action_),
@ -101,6 +102,20 @@ namespace etl
{
}
transition(const event_id_t event_id_,
const state_id_t next_state_id_,
void (TObject::* const action_)() = nullptr,
bool (TObject::* const guard_)() = nullptr)
: from_any_state(true),
current_state_id(0),
event_id(event_id_),
next_state_id(next_state_id_),
action(action_),
guard(guard_)
{
}
const bool from_any_state;
const state_id_t current_state_id;
const event_id_t event_id;
const state_id_t next_state_id;
@ -298,6 +313,8 @@ namespace etl
(object.*(s->on_exit))();
}
current_state_id = next_state_id;
// See if we have a state item for the next state.
s = find_state(next_state_id);
@ -306,8 +323,6 @@ namespace etl
{
(object.*(s->on_entry))();
}
current_state_id = next_state_id;
}
t = transition_table.end();
@ -335,7 +350,7 @@ namespace etl
bool operator()(const transition& t) const
{
return (t.event_id == event_id) && (t.current_state_id == state_id);
return (t.event_id == event_id) && (t.from_any_state || (t.current_state_id == state_id));
}
const event_id_t event_id;

View File

@ -31,19 +31,20 @@ SOFTWARE.
#ifndef ETL_VERSION_INCLUDED
#define ETL_VERSION_INCLUDED
#include <stdint.h>
#include "macros.h"
///\defgroup version version
/// Definitions of the ETL version
///\ingroup utilities
#define ETL_VERSION "13.0.0"
#define ETL_VERSION_W L"13.0.0"
#define ETL_VERSION_U16 u"13.0.0"
#define ETL_VERSION_U32 U"13.0.0"
#define ETL_VERSION_MAJOR 13
#define ETL_VERSION_MINOR 0
#define ETL_VERSION_MAJOR 14
#define ETL_VERSION_MINOR 3
#define ETL_VERSION_PATCH 0
#define ETL_VERSION ETL_STRINGIFY(ETL_VERSION_MAJOR) ETL_STRINGIFY(ETL_VERSION_MINOR) ETL_STRINGIFY(ETL_VERSION_PATCH)
#define ETL_VERSION_W ETL_WIDE_STRING(ETL_CONCAT(ETL_CONCAT(ETL_VERSION_MAJOR, ETL_VERSION_MINOR), ETL_VERSION_PATCH))
#define ETL_VERSION_U16 ETL_U16_STRING(ETL_CONCAT(ETL_CONCAT(ETL_VERSION_MAJOR, ETL_VERSION_MINOR), ETL_VERSION_PATCH))
#define ETL_VERSION_U32 ETL_U32_STRING(ETL_CONCAT(ETL_CONCAT(ETL_VERSION_MAJOR, ETL_VERSION_MINOR), ETL_VERSION_PATCH))
#define ETL_VERSION_VALUE ((ETL_VERSION_MAJOR * 10000) + (ETL_VERSION_MINOR * 100) + ETL_VERSION_PATCH)
#endif

View File

@ -1,598 +0,0 @@
///\file
/******************************************************************************
The MIT License(MIT)
Embedded Template Library.
https://github.com/ETLCPP/etl
http://www.etlcpp.com
Copyright(c) 2017 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 "etl/platform.h"
#include "etl/binary.h"
namespace etl
{
#if ETL_8BIT_SUPPORT
//***************************************************************************
/// Reverse 8 bits.
//***************************************************************************
uint8_t reverse_bits(uint8_t value)
{
value = ((value & 0xAA) >> 1) | ((value & 0x55) << 1);
value = ((value & 0xCC) >> 2) | ((value & 0x33) << 2);
value = (value >> 4) | (value << 4);
return value;
}
#endif
//***************************************************************************
/// Reverse 16 bits.
//***************************************************************************
uint16_t reverse_bits(uint16_t value)
{
value = ((value & 0xAAAA) >> 1) | ((value & 0x5555) << 1);
value = ((value & 0xCCCC) >> 2) | ((value & 0x3333) << 2);
value = ((value & 0xF0F0) >> 4) | ((value & 0x0F0F) << 4);
value = (value >> 8) | (value << 8);
return value;
}
//***************************************************************************
/// Reverse 32 bits.
//***************************************************************************
uint32_t reverse_bits(uint32_t value)
{
value = ((value & 0xAAAAAAAA) >> 1) | ((value & 0x55555555) << 1);
value = ((value & 0xCCCCCCCC) >> 2) | ((value & 0x33333333) << 2);
value = ((value & 0xF0F0F0F0) >> 4) | ((value & 0x0F0F0F0F) << 4);
value = ((value & 0xFF00FF00) >> 8) | ((value & 0x00FF00FF) << 8);
value = (value >> 16) | (value << 16);
return value;
}
//***************************************************************************
/// Reverse 64 bits.
//***************************************************************************
uint64_t reverse_bits(uint64_t value)
{
value = ((value & 0xAAAAAAAAAAAAAAAAull) >> 1) | ((value & 0x5555555555555555ull) << 1);
value = ((value & 0xCCCCCCCCCCCCCCCCull) >> 2) | ((value & 0x3333333333333333ull) << 2);
value = ((value & 0xF0F0F0F0F0F0F0F0ull) >> 4) | ((value & 0x0F0F0F0F0F0F0F0Full) << 4);
value = ((value & 0xFF00FF00FF00FF00ull) >> 8) | ((value & 0x00FF00FF00FF00FFull) << 8);
value = ((value & 0xFFFF0000FFFF0000ull) >> 16) | ((value & 0x0000FFFF0000FFFFull) << 16);
value = (value >> 32) | (value << 32);
return value;
}
//***************************************************************************
/// Reverse bytes 16 bit.
//***************************************************************************
uint16_t reverse_bytes(uint16_t value)
{
value = (value >> 8) | (value << 8);
return value;
}
//***************************************************************************
/// Reverse bytes 32 bit.
//***************************************************************************
uint32_t reverse_bytes(uint32_t value)
{
value = ((value & 0xFF00FF00) >> 8) | ((value & 0x00FF00FF) << 8);
value = (value >> 16) | (value << 16);
return value;
}
//***************************************************************************
/// Reverse bytes 64 bit.
//***************************************************************************
uint64_t reverse_bytes(uint64_t value)
{
value = ((value & 0xFF00FF00FF00FF00ull) >> 8) | ((value & 0x00FF00FF00FF00FFull) << 8);
value = ((value & 0xFFFF0000FFFF0000ull) >> 16) | ((value & 0x0000FFFF0000FFFFull) << 16);
value = (value >> 32) | (value << 32);
return value;
}
#if ETL_8BIT_SUPPORT
//***************************************************************************
/// Converts Gray code to binary.
//***************************************************************************
uint8_t gray_to_binary(uint8_t value)
{
value ^= (value >> 4);
value ^= (value >> 2);
value ^= (value >> 1);
return value;
}
#endif
//***************************************************************************
/// Converts Gray code to binary.
//***************************************************************************
uint16_t gray_to_binary(uint16_t value)
{
value ^= (value >> 8);
value ^= (value >> 4);
value ^= (value >> 2);
value ^= (value >> 1);
return value;
}
//***************************************************************************
/// Converts Gray code to binary.
//***************************************************************************
uint32_t gray_to_binary(uint32_t value)
{
value ^= (value >> 16);
value ^= (value >> 8);
value ^= (value >> 4);
value ^= (value >> 2);
value ^= (value >> 1);
return value;
}
//***************************************************************************
/// Converts Gray code to binary.
//***************************************************************************
uint64_t gray_to_binary(uint64_t value)
{
value ^= (value >> 32);
value ^= (value >> 16);
value ^= (value >> 8);
value ^= (value >> 4);
value ^= (value >> 2);
value ^= (value >> 1);
return value;
}
#if ETL_8BIT_SUPPORT
//***************************************************************************
/// Count set bits. 8 bits.
//***************************************************************************
uint_least8_t count_bits(uint8_t value)
{
uint32_t count;
static const int S[] = { 1, 2, 4 };
static const uint8_t B[] = { 0x55, 0x33, 0x0F };
count = value - ((value >> 1) & B[0]);
count = ((count >> S[1]) & B[1]) + (count & B[1]);
count = ((count >> S[2]) + count) & B[2];
return uint_least8_t(count);
}
#endif
//***************************************************************************
/// Count set bits. 16 bits.
//***************************************************************************
uint_least8_t count_bits(uint16_t value)
{
uint32_t count;
static const int S[] = { 1, 2, 4, 8 };
static const uint16_t B[] = { 0x5555, 0x3333, 0x0F0F, 0x00FF };
count = value - ((value >> 1) & B[0]);
count = ((count >> S[1]) & B[1]) + (count & B[1]);
count = ((count >> S[2]) + count) & B[2];
count = ((count >> S[3]) + count) & B[3];
return count;
}
//***************************************************************************
/// Count set bits. 32 bits.
//***************************************************************************
uint_least8_t count_bits(uint32_t value)
{
uint32_t count;
value = value - ((value >> 1) & 0x55555555);
value = (value & 0x33333333) + ((value >> 2) & 0x33333333);
count = (((value + (value >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24;
return uint_least8_t(count);
}
//***************************************************************************
/// Count set bits. 64 bits.
//***************************************************************************
uint_least8_t count_bits(uint64_t value)
{
uint64_t count;
static const int S[] = { 1, 2, 4, 8, 16, 32 };
static const uint64_t B[] = { 0x5555555555555555ull, 0x3333333333333333ull, 0x0F0F0F0F0F0F0F0Full, 0x00FF00FF00FF00FFull, 0x0000FFFF0000FFFFull, 0x00000000FFFFFFFFull };
count = value - ((value >> 1) & B[0]);
count = ((count >> S[1]) & B[1]) + (count & B[1]);
count = ((count >> S[2]) + count) & B[2];
count = ((count >> S[3]) + count) & B[3];
count = ((count >> S[4]) + count) & B[4];
count = ((count >> S[5]) + count) & B[5];
return uint_least8_t(count);
}
#if ETL_8BIT_SUPPORT
//***************************************************************************
/// Parity. 8bits. 0 = even, 1 = odd
//***************************************************************************
uint_least8_t parity(uint8_t value)
{
value ^= value >> 4;
value &= 0x0F;
return (0x6996 >> value) & 1;
}
#endif
//***************************************************************************
/// Parity. 16bits. 0 = even, 1 = odd
//***************************************************************************
uint_least8_t parity(uint16_t value)
{
value ^= value >> 8;
value ^= value >> 4;
value &= 0x0F;
return (0x6996 >> value) & 1;
}
//***************************************************************************
/// Parity. 32bits. 0 = even, 1 = odd
//***************************************************************************
uint_least8_t parity(uint32_t value)
{
value ^= value >> 16;
value ^= value >> 8;
value ^= value >> 4;
value &= 0x0F;
return (0x6996 >> value) & 1;
}
//***************************************************************************
/// Parity. 64bits. 0 = even, 1 = odd
//***************************************************************************
uint_least8_t parity(uint64_t value)
{
value ^= value >> 32;
value ^= value >> 16;
value ^= value >> 8;
value ^= value >> 4;
value &= 0x0F;
return (0x69966996 >> value) & 1;
}
#if ETL_8BIT_SUPPORT
//***************************************************************************
/// Count trailing zeros. bit.
/// Uses a binary search.
//***************************************************************************
uint_least8_t count_trailing_zeros(uint8_t value)
{
uint_least8_t count;
if (value & 0x1)
{
count = 0;
}
else
{
count = 1;
if ((value & 0xF) == 0)
{
value >>= 4;
count += 4;
}
if ((value & 0x3) == 0)
{
value >>= 2;
count += 2;
}
count -= value & 0x1;
}
return count;
}
#endif
//***************************************************************************
/// Count trailing zeros. 16bit.
/// Uses a binary search.
//***************************************************************************
uint_least8_t count_trailing_zeros(uint16_t value)
{
uint_least8_t count;
if (value & 0x1)
{
count = 0;
}
else
{
count = 1;
if ((value & 0xFF) == 0)
{
value >>= 8;
count += 8;
}
if ((value & 0xF) == 0)
{
value >>= 4;
count += 4;
}
if ((value & 0x3) == 0)
{
value >>= 2;
count += 2;
}
count -= value & 0x1;
}
return count;
}
//***************************************************************************
/// Count trailing zeros. 32bit.
/// Uses a binary search.
//***************************************************************************
uint_least8_t count_trailing_zeros(uint32_t value)
{
uint_least8_t count;
if (value & 0x1)
{
count = 0;
}
else
{
count = 1;
if ((value & 0xFFFF) == 0)
{
value >>= 16;
count += 16;
}
if ((value & 0xFF) == 0)
{
value >>= 8;
count += 8;
}
if ((value & 0xF) == 0)
{
value >>= 4;
count += 4;
}
if ((value & 0x3) == 0)
{
value >>= 2;
count += 2;
}
count -= value & 0x1;
}
return count;
}
//***************************************************************************
/// Count trailing zeros. 64bit.
/// Uses a binary search.
//***************************************************************************
uint_least8_t count_trailing_zeros(uint64_t value)
{
uint_least8_t count;
if (value & 0x1)
{
count = 0;
}
else
{
count = 1;
if ((value & 0xFFFFFFFF) == 0)
{
value >>= 32;
count += 32;
}
if ((value & 0xFFFF) == 0)
{
value >>= 16;
count += 16;
}
if ((value & 0xFF) == 0)
{
value >>= 8;
count += 8;
}
if ((value & 0xF) == 0)
{
value >>= 4;
count += 4;
}
if ((value & 0x3) == 0)
{
value >>= 2;
count += 2;
}
count -= value & 0x1;
}
return count;
}
#if ETL_8BIT_SUPPORT
//*****************************************************************************
/// Binary interleave
//*****************************************************************************
uint16_t binary_interleave(uint8_t first, uint8_t second)
{
static const uint16_t mask[] = { 0x5555, 0x3333, 0x0F0F };
uint16_t f = first;
uint16_t s = second;
f = (f | (f << 4)) & mask[2];
f = (f | (f << 2)) & mask[1];
f = (f | (f << 1)) & mask[0];
s = (s | (s << 4)) & mask[2];
s = (s | (s << 2)) & mask[1];
s = (s | (s << 1)) & mask[0];
return (f | (s << 1));
}
#endif
//*****************************************************************************
/// Binary interleave
//*****************************************************************************
uint32_t binary_interleave(uint16_t first, uint16_t second)
{
static const uint32_t mask[] = { 0x55555555, 0x33333333, 0x0F0F0F0F, 0x00FF00FF };
uint32_t f = first;
uint32_t s = second;
f = (f | (f << 8)) & mask[3];
f = (f | (f << 4)) & mask[2];
f = (f | (f << 2)) & mask[1];
f = (f | (f << 1)) & mask[0];
s = (s | (s << 8)) & mask[3];
s = (s | (s << 4)) & mask[2];
s = (s | (s << 2)) & mask[1];
s = (s | (s << 1)) & mask[0];
return (f | (s << 1));
}
//*****************************************************************************
/// Binary interleave
//*****************************************************************************
uint64_t binary_interleave(uint32_t first, uint32_t second)
{
static const uint64_t mask[] = { 0x5555555555555555ull, 0x3333333333333333ull, 0x0F0F0F0F0F0F0F0Full, 0x00FF00FF00FF00FFull, 0x0000FFFF0000FFFFull };
uint64_t f = first;
uint64_t s = second;
f = (f | (f << 16)) & mask[4];
f = (f | (f << 8)) & mask[3];
f = (f | (f << 4)) & mask[2];
f = (f | (f << 2)) & mask[1];
f = (f | (f << 1)) & mask[0];
s = (s | (s << 16)) & mask[4];
s = (s | (s << 8)) & mask[3];
s = (s | (s << 4)) & mask[2];
s = (s | (s << 2)) & mask[1];
s = (s | (s << 1)) & mask[0];
return (f | (s << 1));
}
//***************************************************************************
/// Checks if odd.
//***************************************************************************
bool is_odd(const unsigned char value)
{
return ((value & 1U) != 0U);
}
bool is_odd(const unsigned short value)
{
return ((value & 1U) != 0U);
}
bool is_odd(const unsigned int value)
{
return ((value & 1U) != 0U);
}
bool is_odd(const unsigned long value)
{
return ((value & 1U) != 0U);
}
bool is_odd(const unsigned long long value)
{
return ((value & 1U) != 0U);
}
//***************************************************************************
/// Checks if even.
//***************************************************************************
bool is_even(const unsigned char value)
{
return ((value & 1U) == 0U);
}
bool is_even(const unsigned short value)
{
return ((value & 1U) == 0U);
}
bool is_even(const unsigned int value)
{
return ((value & 1U) == 0U);
}
bool is_even(const unsigned long value)
{
return ((value & 1U) == 0U);
}
bool is_even(const unsigned long long value)
{
return ((value & 1U) == 0U);
}
}

View File

@ -1,60 +0,0 @@
///\file
/******************************************************************************
The MIT License(MIT)
Embedded Template Library.
https://github.com/ETLCPP/etl
http://www.etlcpp.com
Copyright(c) 2014 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 <stdint.h>
#include "etl/platform.h"
namespace etl
{
//***************************************************************************
/// CRC16 table
/// \ingroup crc16
//***************************************************************************
extern const uint16_t ETL_CRC16[] =
{
0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241, 0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440,
0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40, 0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841,
0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40, 0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41,
0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641, 0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040,
0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1, 0xF281, 0x3240, 0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441,
0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0, 0x3E80, 0xFE41, 0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840,
0x2800, 0xE8C1, 0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41, 0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40,
0xE401, 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640, 0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0, 0x2080, 0xE041,
0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240, 0x6600, 0xA6C1, 0xA781, 0x6740, 0xA501, 0x65C0, 0x6480, 0xA441,
0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41, 0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840,
0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80, 0xBA41, 0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40,
0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640, 0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041,
0x5000, 0x90C1, 0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241, 0x9601, 0x56C0, 0x5780, 0x9741, 0x5500, 0x95C1, 0x9481, 0x5440,
0x9C01, 0x5CC0, 0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40, 0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841,
0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 0x8A81, 0x4A40, 0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41,
0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641, 0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040
};
}

View File

@ -1,60 +0,0 @@
///\file
/******************************************************************************
The MIT License(MIT)
Embedded Template Library.
https://github.com/ETLCPP/etl
http://www.etlcpp.com
Copyright(c) 2014 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 <stdint.h>
#include "etl/platform.h"
namespace etl
{
//***************************************************************************
/// CRC-CCITT table
/// \ingroup crc16_ccitt
//***************************************************************************
extern const uint16_t ETL_CRC_CCITT[] =
{
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7, 0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF,
0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6, 0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE,
0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485, 0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D,
0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4, 0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC,
0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823, 0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B,
0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12, 0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A,
0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41, 0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49,
0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70, 0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78,
0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F, 0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067,
0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E, 0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256,
0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D, 0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C, 0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634,
0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB, 0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3,
0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A, 0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92,
0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9, 0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1,
0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8, 0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0
};
}

View File

@ -1,60 +0,0 @@
///\file
/******************************************************************************
The MIT License(MIT)
Embedded Template Library.
https://github.com/ETLCPP/etl
http://www.etlcpp.com
Copyright(c) 2014 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 <stdint.h>
#include "etl/platform.h"
namespace etl
{
//***************************************************************************
/// CRC Kermit table
/// \ingroup crc16_kermit
//***************************************************************************
extern const uint16_t ETL_CRC_KERMIT[] =
{
0x0000, 0x1189, 0x2312, 0x329B, 0x4624, 0x57AD, 0x6536, 0x74BF, 0x8C48, 0x9DC1, 0xAF5A, 0xBED3, 0xCA6C, 0xDBE5, 0xE97E, 0xF8F7,
0x1081, 0x0108, 0x3393, 0x221A, 0x56A5, 0x472C, 0x75B7, 0x643E, 0x9CC9, 0x8D40, 0xBFDB, 0xAE52, 0xDAED, 0xCB64, 0xF9FF, 0xE876,
0x2102, 0x308B, 0x0210, 0x1399, 0x6726, 0x76AF, 0x4434, 0x55BD, 0xAD4A, 0xBCC3, 0x8E58, 0x9FD1, 0xEB6E, 0xFAE7, 0xC87C, 0xD9F5,
0x3183, 0x200A, 0x1291, 0x0318, 0x77A7, 0x662E, 0x54B5, 0x453C, 0xBDCB, 0xAC42, 0x9ED9, 0x8F50, 0xFBEF, 0xEA66, 0xD8FD, 0xC974,
0x4204, 0x538D, 0x6116, 0x709F, 0x0420, 0x15A9, 0x2732, 0x36BB, 0xCE4C, 0xDFC5, 0xED5E, 0xFCD7, 0x8868, 0x99E1, 0xAB7A, 0xBAF3,
0x5285, 0x430C, 0x7197, 0x601E, 0x14A1, 0x0528, 0x37B3, 0x263A, 0xDECD, 0xCF44, 0xFDDF, 0xEC56, 0x98E9, 0x8960, 0xBBFB, 0xAA72,
0x6306, 0x728F, 0x4014, 0x519D, 0x2522, 0x34AB, 0x0630, 0x17B9, 0xEF4E, 0xFEC7, 0xCC5C, 0xDDD5, 0xA96A, 0xB8E3, 0x8A78, 0x9BF1,
0x7387, 0x620E, 0x5095, 0x411C, 0x35A3, 0x242A, 0x16B1, 0x0738, 0xFFCF, 0xEE46, 0xDCDD, 0xCD54, 0xB9EB, 0xA862, 0x9AF9, 0x8B70,
0x8408, 0x9581, 0xA71A, 0xB693, 0xC22C, 0xD3A5, 0xE13E, 0xF0B7, 0x0840, 0x19C9, 0x2B52, 0x3ADB, 0x4E64, 0x5FED, 0x6D76, 0x7CFF,
0x9489, 0x8500, 0xB79B, 0xA612, 0xD2AD, 0xC324, 0xF1BF, 0xE036, 0x18C1, 0x0948, 0x3BD3, 0x2A5A, 0x5EE5, 0x4F6C, 0x7DF7, 0x6C7E,
0xA50A, 0xB483, 0x8618, 0x9791, 0xE32E, 0xF2A7, 0xC03C, 0xD1B5, 0x2942, 0x38CB, 0x0A50, 0x1BD9, 0x6F66, 0x7EEF, 0x4C74, 0x5DFD,
0xB58B, 0xA402, 0x9699, 0x8710, 0xF3AF, 0xE226, 0xD0BD, 0xC134, 0x39C3, 0x284A, 0x1AD1, 0x0B58, 0x7FE7, 0x6E6E, 0x5CF5, 0x4D7C,
0xC60C, 0xD785, 0xE51E, 0xF497, 0x8028, 0x91A1, 0xA33A, 0xB2B3, 0x4A44, 0x5BCD, 0x6956, 0x78DF, 0x0C60, 0x1DE9, 0x2F72, 0x3EFB,
0xD68D, 0xC704, 0xF59F, 0xE416, 0x90A9, 0x8120, 0xB3BB, 0xA232, 0x5AC5, 0x4B4C, 0x79D7, 0x685E, 0x1CE1, 0x0D68, 0x3FF3, 0x2E7A,
0xE70E, 0xF687, 0xC41C, 0xD595, 0xA12A, 0xB0A3, 0x8238, 0x93B1, 0x6B46, 0x7ACF, 0x4854, 0x59DD, 0x2D62, 0x3CEB, 0x0E70, 0x1FF9,
0xF78F, 0xE606, 0xD49D, 0xC514, 0xB1AB, 0xA022, 0x92B9, 0x8330, 0x7BC7, 0x6A4E, 0x58D5, 0x495C, 0x3DE3, 0x2C6A, 0x1EF1, 0x0F78
};
}

View File

@ -1,76 +0,0 @@
///\file
/******************************************************************************
The MIT License(MIT)
Embedded Template Library.
https://github.com/ETLCPP/etl
https://www.etlcpp.com
Copyright(c) 2018 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 <stdint.h>
#include "etl/platform.h"
namespace etl
{
//***************************************************************************
/// CRC-MODBUS table
/// \ingroup crc16_modbus
//***************************************************************************
extern const uint16_t ETL_CRC_MODBUS[] =
{
0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241,
0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440,
0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40,
0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841,
0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40,
0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41,
0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641,
0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040,
0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1, 0xF281, 0x3240,
0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441,
0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0, 0x3E80, 0xFE41,
0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840,
0x2800, 0xE8C1, 0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41,
0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40,
0xE401, 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640,
0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0, 0x2080, 0xE041,
0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240,
0x6600, 0xA6C1, 0xA781, 0x6740, 0xA501, 0x65C0, 0x6480, 0xA441,
0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41,
0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840,
0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80, 0xBA41,
0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40,
0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640,
0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041,
0x5000, 0x90C1, 0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241,
0x9601, 0x56C0, 0x5780, 0x9741, 0x5500, 0x95C1, 0x9481, 0x5440,
0x9C01, 0x5CC0, 0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40,
0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841,
0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 0x8A81, 0x4A40,
0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41,
0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641,
0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040
};
}

View File

@ -1,76 +0,0 @@
///\file
/******************************************************************************
The MIT License(MIT)
Embedded Template Library.
https://github.com/ETLCPP/etl
http://www.etlcpp.com
Copyright(c) 2014 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 <stdint.h>
#include "etl/platform.h"
namespace etl
{
//***************************************************************************
/// CRC32 table
/// \ingroup crc32
//***************************************************************************
extern const uint32_t ETL_CRC32[] =
{
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91,
0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,
0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5,
0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,
0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59,
0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F,
0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D,
0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,
0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,
0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457,
0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,
0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB,
0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,
0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD,
0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683,
0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,
0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7,
0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,
0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,
0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79,
0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F,
0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,
0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,
0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21,
0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,
0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45,
0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB,
0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF,
0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D
};
}

View File

@ -1,80 +0,0 @@
///\file
/******************************************************************************
The MIT License(MIT)
Embedded Template Library.
https://github.com/ETLCPP/etl
https://www.etlcpp.com
Copyright(c) 2018 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 <stdint.h>
#include "etl/platform.h"
namespace etl
{
//***************************************************************************
/// ETL_CRC32_C table
/// \ingroup ETL_CRC32_C
//***************************************************************************
extern const uint32_t ETL_CRC32_C[] =
{
0x00000000L, 0xF26B8303L, 0xE13B70F7L, 0x1350F3F4L, 0xC79A971FL, 0x35F1141CL, 0x26A1E7E8L, 0xD4CA64EBL,
0x8AD958CFL, 0x78B2DBCCL, 0x6BE22838L, 0x9989AB3BL, 0x4D43CFD0L, 0xBF284CD3L, 0xAC78BF27L, 0x5E133C24L,
0x105EC76FL, 0xE235446CL, 0xF165B798L, 0x030E349BL, 0xD7C45070L, 0x25AFD373L, 0x36FF2087L, 0xC494A384L,
0x9A879FA0L, 0x68EC1CA3L, 0x7BBCEF57L, 0x89D76C54L, 0x5D1D08BFL, 0xAF768BBCL, 0xBC267848L, 0x4E4DFB4BL,
0x20BD8EDEL, 0xD2D60DDDL, 0xC186FE29L, 0x33ED7D2AL, 0xE72719C1L, 0x154C9AC2L, 0x061C6936L, 0xF477EA35L,
0xAA64D611L, 0x580F5512L, 0x4B5FA6E6L, 0xB93425E5L, 0x6DFE410EL, 0x9F95C20DL, 0x8CC531F9L, 0x7EAEB2FAL,
0x30E349B1L, 0xC288CAB2L, 0xD1D83946L, 0x23B3BA45L, 0xF779DEAEL, 0x05125DADL, 0x1642AE59L, 0xE4292D5AL,
0xBA3A117EL, 0x4851927DL, 0x5B016189L, 0xA96AE28AL, 0x7DA08661L, 0x8FCB0562L, 0x9C9BF696L, 0x6EF07595L,
0x417B1DBCL, 0xB3109EBFL, 0xA0406D4BL, 0x522BEE48L, 0x86E18AA3L, 0x748A09A0L, 0x67DAFA54L, 0x95B17957L,
0xCBA24573L, 0x39C9C670L, 0x2A993584L, 0xD8F2B687L, 0x0C38D26CL, 0xFE53516FL, 0xED03A29BL, 0x1F682198L,
0x5125DAD3L, 0xA34E59D0L, 0xB01EAA24L, 0x42752927L, 0x96BF4DCCL, 0x64D4CECFL, 0x77843D3BL, 0x85EFBE38L,
0xDBFC821CL, 0x2997011FL, 0x3AC7F2EBL, 0xC8AC71E8L, 0x1C661503L, 0xEE0D9600L, 0xFD5D65F4L, 0x0F36E6F7L,
0x61C69362L, 0x93AD1061L, 0x80FDE395L, 0x72966096L, 0xA65C047DL, 0x5437877EL, 0x4767748AL, 0xB50CF789L,
0xEB1FCBADL, 0x197448AEL, 0x0A24BB5AL, 0xF84F3859L, 0x2C855CB2L, 0xDEEEDFB1L, 0xCDBE2C45L, 0x3FD5AF46L,
0x7198540DL, 0x83F3D70EL, 0x90A324FAL, 0x62C8A7F9L, 0xB602C312L, 0x44694011L, 0x5739B3E5L, 0xA55230E6L,
0xFB410CC2L, 0x092A8FC1L, 0x1A7A7C35L, 0xE811FF36L, 0x3CDB9BDDL, 0xCEB018DEL, 0xDDE0EB2AL, 0x2F8B6829L,
0x82F63B78L, 0x709DB87BL, 0x63CD4B8FL, 0x91A6C88CL, 0x456CAC67L, 0xB7072F64L, 0xA457DC90L, 0x563C5F93L,
0x082F63B7L, 0xFA44E0B4L, 0xE9141340L, 0x1B7F9043L, 0xCFB5F4A8L, 0x3DDE77ABL, 0x2E8E845FL, 0xDCE5075CL,
0x92A8FC17L, 0x60C37F14L, 0x73938CE0L, 0x81F80FE3L, 0x55326B08L, 0xA759E80BL, 0xB4091BFFL, 0x466298FCL,
0x1871A4D8L, 0xEA1A27DBL, 0xF94AD42FL, 0x0B21572CL, 0xDFEB33C7L, 0x2D80B0C4L, 0x3ED04330L, 0xCCBBC033L,
0xA24BB5A6L, 0x502036A5L, 0x4370C551L, 0xB11B4652L, 0x65D122B9L, 0x97BAA1BAL, 0x84EA524EL, 0x7681D14DL,
0x2892ED69L, 0xDAF96E6AL, 0xC9A99D9EL, 0x3BC21E9DL, 0xEF087A76L, 0x1D63F975L, 0x0E330A81L, 0xFC588982L,
0xB21572C9L, 0x407EF1CAL, 0x532E023EL, 0xA145813DL, 0x758FE5D6L, 0x87E466D5L, 0x94B49521L, 0x66DF1622L,
0x38CC2A06L, 0xCAA7A905L, 0xD9F75AF1L, 0x2B9CD9F2L, 0xFF56BD19L, 0x0D3D3E1AL, 0x1E6DCDEEL, 0xEC064EEDL,
0xC38D26C4L, 0x31E6A5C7L, 0x22B65633L, 0xD0DDD530L, 0x0417B1DBL, 0xF67C32D8L, 0xE52CC12CL, 0x1747422FL,
0x49547E0BL, 0xBB3FFD08L, 0xA86F0EFCL, 0x5A048DFFL, 0x8ECEE914L, 0x7CA56A17L, 0x6FF599E3L, 0x9D9E1AE0L,
0xD3D3E1ABL, 0x21B862A8L, 0x32E8915CL, 0xC083125FL, 0x144976B4L, 0xE622F5B7L, 0xF5720643L, 0x07198540L,
0x590AB964L, 0xAB613A67L, 0xB831C993L, 0x4A5A4A90L, 0x9E902E7BL, 0x6CFBAD78L, 0x7FAB5E8CL, 0x8DC0DD8FL,
0xE330A81AL, 0x115B2B19L, 0x020BD8EDL, 0xF0605BEEL,
0x24AA3F05L, 0xD6C1BC06L, 0xC5914FF2L, 0x37FACCF1L,
0x69E9F0D5L, 0x9B8273D6L, 0x88D28022L, 0x7AB90321L,
0xAE7367CAL, 0x5C18E4C9L, 0x4F48173DL, 0xBD23943EL,
0xF36E6F75L, 0x0105EC76L, 0x12551F82L, 0xE03E9C81L,
0x34F4F86AL, 0xC69F7B69L, 0xD5CF889DL, 0x27A40B9EL,
0x79B737BAL, 0x8BDCB4B9L, 0x988C474DL, 0x6AE7C44EL,
0xBE2DA0A5L, 0x4C4623A6L, 0x5F16D052L, 0xAD7D5351L
};
}

View File

@ -1,108 +0,0 @@
///\file
/******************************************************************************
The MIT License(MIT)
Embedded Template Library.
https://github.com/ETLCPP/etl
http://www.etlcpp.com
Copyright(c) 2014 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 <stdint.h>
#include "etl/platform.h"
namespace etl
{
//***************************************************************************
/// CRC64_ECMA table
/// \ingroup crc64_ecma
//***************************************************************************
extern const uint64_t CRC64_ECMA[] =
{
0x0000000000000000ull, 0x42F0E1EBA9EA3693ull, 0x85E1C3D753D46D26ull, 0xC711223CFA3E5BB5ull,
0x493366450E42ECDFull, 0x0BC387AEA7A8DA4Cull, 0xCCD2A5925D9681F9ull, 0x8E224479F47CB76Aull,
0x9266CC8A1C85D9BEull, 0xD0962D61B56FEF2Dull, 0x17870F5D4F51B498ull, 0x5577EEB6E6BB820Bull,
0xDB55AACF12C73561ull, 0x99A54B24BB2D03F2ull, 0x5EB4691841135847ull, 0x1C4488F3E8F96ED4ull,
0x663D78FF90E185EFull, 0x24CD9914390BB37Cull, 0xE3DCBB28C335E8C9ull, 0xA12C5AC36ADFDE5Aull,
0x2F0E1EBA9EA36930ull, 0x6DFEFF5137495FA3ull, 0xAAEFDD6DCD770416ull, 0xE81F3C86649D3285ull,
0xF45BB4758C645C51ull, 0xB6AB559E258E6AC2ull, 0x71BA77A2DFB03177ull, 0x334A9649765A07E4ull,
0xBD68D2308226B08Eull, 0xFF9833DB2BCC861Dull, 0x388911E7D1F2DDA8ull, 0x7A79F00C7818EB3Bull,
0xCC7AF1FF21C30BDEull, 0x8E8A101488293D4Dull, 0x499B3228721766F8ull, 0x0B6BD3C3DBFD506Bull,
0x854997BA2F81E701ull, 0xC7B97651866BD192ull, 0x00A8546D7C558A27ull, 0x4258B586D5BFBCB4ull,
0x5E1C3D753D46D260ull, 0x1CECDC9E94ACE4F3ull, 0xDBFDFEA26E92BF46ull, 0x990D1F49C77889D5ull,
0x172F5B3033043EBFull, 0x55DFBADB9AEE082Cull, 0x92CE98E760D05399ull, 0xD03E790CC93A650Aull,
0xAA478900B1228E31ull, 0xE8B768EB18C8B8A2ull, 0x2FA64AD7E2F6E317ull, 0x6D56AB3C4B1CD584ull,
0xE374EF45BF6062EEull, 0xA1840EAE168A547Dull, 0x66952C92ECB40FC8ull, 0x2465CD79455E395Bull,
0x3821458AADA7578Full, 0x7AD1A461044D611Cull, 0xBDC0865DFE733AA9ull, 0xFF3067B657990C3Aull,
0x711223CFA3E5BB50ull, 0x33E2C2240A0F8DC3ull, 0xF4F3E018F031D676ull, 0xB60301F359DBE0E5ull,
0xDA050215EA6C212Full, 0x98F5E3FE438617BCull, 0x5FE4C1C2B9B84C09ull, 0x1D14202910527A9Aull,
0x93366450E42ECDF0ull, 0xD1C685BB4DC4FB63ull, 0x16D7A787B7FAA0D6ull, 0x5427466C1E109645ull,
0x4863CE9FF6E9F891ull, 0x0A932F745F03CE02ull, 0xCD820D48A53D95B7ull, 0x8F72ECA30CD7A324ull,
0x0150A8DAF8AB144Eull, 0x43A04931514122DDull, 0x84B16B0DAB7F7968ull, 0xC6418AE602954FFBull,
0xBC387AEA7A8DA4C0ull, 0xFEC89B01D3679253ull, 0x39D9B93D2959C9E6ull, 0x7B2958D680B3FF75ull,
0xF50B1CAF74CF481Full, 0xB7FBFD44DD257E8Cull, 0x70EADF78271B2539ull, 0x321A3E938EF113AAull,
0x2E5EB66066087D7Eull, 0x6CAE578BCFE24BEDull, 0xABBF75B735DC1058ull, 0xE94F945C9C3626CBull,
0x676DD025684A91A1ull, 0x259D31CEC1A0A732ull, 0xE28C13F23B9EFC87ull, 0xA07CF2199274CA14ull,
0x167FF3EACBAF2AF1ull, 0x548F120162451C62ull, 0x939E303D987B47D7ull, 0xD16ED1D631917144ull,
0x5F4C95AFC5EDC62Eull, 0x1DBC74446C07F0BDull, 0xDAAD56789639AB08ull, 0x985DB7933FD39D9Bull,
0x84193F60D72AF34Full, 0xC6E9DE8B7EC0C5DCull, 0x01F8FCB784FE9E69ull, 0x43081D5C2D14A8FAull,
0xCD2A5925D9681F90ull, 0x8FDAB8CE70822903ull, 0x48CB9AF28ABC72B6ull, 0x0A3B7B1923564425ull,
0x70428B155B4EAF1Eull, 0x32B26AFEF2A4998Dull, 0xF5A348C2089AC238ull, 0xB753A929A170F4ABull,
0x3971ED50550C43C1ull, 0x7B810CBBFCE67552ull, 0xBC902E8706D82EE7ull, 0xFE60CF6CAF321874ull,
0xE224479F47CB76A0ull, 0xA0D4A674EE214033ull, 0x67C58448141F1B86ull, 0x253565A3BDF52D15ull,
0xAB1721DA49899A7Full, 0xE9E7C031E063ACECull, 0x2EF6E20D1A5DF759ull, 0x6C0603E6B3B7C1CAull,
0xF6FAE5C07D3274CDull, 0xB40A042BD4D8425Eull, 0x731B26172EE619EBull, 0x31EBC7FC870C2F78ull,
0xBFC9838573709812ull, 0xFD39626EDA9AAE81ull, 0x3A28405220A4F534ull, 0x78D8A1B9894EC3A7ull,
0x649C294A61B7AD73ull, 0x266CC8A1C85D9BE0ull, 0xE17DEA9D3263C055ull, 0xA38D0B769B89F6C6ull,
0x2DAF4F0F6FF541ACull, 0x6F5FAEE4C61F773Full, 0xA84E8CD83C212C8Aull, 0xEABE6D3395CB1A19ull,
0x90C79D3FEDD3F122ull, 0xD2377CD44439C7B1ull, 0x15265EE8BE079C04ull, 0x57D6BF0317EDAA97ull,
0xD9F4FB7AE3911DFDull, 0x9B041A914A7B2B6Eull, 0x5C1538ADB04570DBull, 0x1EE5D94619AF4648ull,
0x02A151B5F156289Cull, 0x4051B05E58BC1E0Full, 0x87409262A28245BAull, 0xC5B073890B687329ull,
0x4B9237F0FF14C443ull, 0x0962D61B56FEF2D0ull, 0xCE73F427ACC0A965ull, 0x8C8315CC052A9FF6ull,
0x3A80143F5CF17F13ull, 0x7870F5D4F51B4980ull, 0xBF61D7E80F251235ull, 0xFD913603A6CF24A6ull,
0x73B3727A52B393CCull, 0x31439391FB59A55Full, 0xF652B1AD0167FEEAull, 0xB4A25046A88DC879ull,
0xA8E6D8B54074A6ADull, 0xEA16395EE99E903Eull, 0x2D071B6213A0CB8Bull, 0x6FF7FA89BA4AFD18ull,
0xE1D5BEF04E364A72ull, 0xA3255F1BE7DC7CE1ull, 0x64347D271DE22754ull, 0x26C49CCCB40811C7ull,
0x5CBD6CC0CC10FAFCull, 0x1E4D8D2B65FACC6Full, 0xD95CAF179FC497DAull, 0x9BAC4EFC362EA149ull,
0x158E0A85C2521623ull, 0x577EEB6E6BB820B0ull, 0x906FC95291867B05ull, 0xD29F28B9386C4D96ull,
0xCEDBA04AD0952342ull, 0x8C2B41A1797F15D1ull, 0x4B3A639D83414E64ull, 0x09CA82762AAB78F7ull,
0x87E8C60FDED7CF9Dull, 0xC51827E4773DF90Eull, 0x020905D88D03A2BBull, 0x40F9E43324E99428ull,
0x2CFFE7D5975E55E2ull, 0x6E0F063E3EB46371ull, 0xA91E2402C48A38C4ull, 0xEBEEC5E96D600E57ull,
0x65CC8190991CB93Dull, 0x273C607B30F68FAEull, 0xE02D4247CAC8D41Bull, 0xA2DDA3AC6322E288ull,
0xBE992B5F8BDB8C5Cull, 0xFC69CAB42231BACFull, 0x3B78E888D80FE17Aull, 0x7988096371E5D7E9ull,
0xF7AA4D1A85996083ull, 0xB55AACF12C735610ull, 0x724B8ECDD64D0DA5ull, 0x30BB6F267FA73B36ull,
0x4AC29F2A07BFD00Dull, 0x08327EC1AE55E69Eull, 0xCF235CFD546BBD2Bull, 0x8DD3BD16FD818BB8ull,
0x03F1F96F09FD3CD2ull, 0x41011884A0170A41ull, 0x86103AB85A2951F4ull, 0xC4E0DB53F3C36767ull,
0xD8A453A01B3A09B3ull, 0x9A54B24BB2D03F20ull, 0x5D45907748EE6495ull, 0x1FB5719CE1045206ull,
0x919735E51578E56Cull, 0xD367D40EBC92D3FFull, 0x1476F63246AC884Aull, 0x568617D9EF46BED9ull,
0xE085162AB69D5E3Cull, 0xA275F7C11F7768AFull, 0x6564D5FDE549331Aull, 0x279434164CA30589ull,
0xA9B6706FB8DFB2E3ull, 0xEB46918411358470ull, 0x2C57B3B8EB0BDFC5ull, 0x6EA7525342E1E956ull,
0x72E3DAA0AA188782ull, 0x30133B4B03F2B111ull, 0xF7021977F9CCEAA4ull, 0xB5F2F89C5026DC37ull,
0x3BD0BCE5A45A6B5Dull, 0x79205D0E0DB05DCEull, 0xBE317F32F78E067Bull, 0xFCC19ED95E6430E8ull,
0x86B86ED5267CDBD3ull, 0xC4488F3E8F96ED40ull, 0x0359AD0275A8B6F5ull, 0x41A94CE9DC428066ull,
0xCF8B0890283E370Cull, 0x8D7BE97B81D4019Full, 0x4A6ACB477BEA5A2Aull, 0x089A2AACD2006CB9ull,
0x14DEA25F3AF9026Dull, 0x562E43B4931334FEull, 0x913F6188692D6F4Bull, 0xD3CF8063C0C759D8ull,
0x5DEDC41A34BBEEB2ull, 0x1F1D25F19D51D821ull, 0xD80C07CD676F8394ull, 0x9AFCE626CE85B507ull
};
}

View File

@ -1,63 +0,0 @@
///\file
/******************************************************************************
The MIT License(MIT)
Embedded Template Library.
https://github.com/ETLCPP/etl
http://www.etlcpp.com
Copyright(c) 2014 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 <stdint.h>
#include "etl/platform.h"
#include "etl/static_assert.h"
ETL_STATIC_ASSERT(ETL_8BIT_SUPPORT, "This file does not currently support targets with no 8bit type");
namespace etl
{
//***************************************************************************
/// CRC8 table
/// \ingroup crc8_ccitt
//***************************************************************************
extern const uint8_t CRC8_CCITT[] =
{
0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15, 0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D,
0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65, 0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D,
0xE0, 0xE7, 0xEE, 0xE9, 0xFC, 0xFB, 0xF2, 0xF5, 0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD,
0x90, 0x97, 0x9E, 0x99, 0x8C, 0x8B, 0x82, 0x85, 0xA8, 0xAF, 0xA6, 0xA1, 0xB4, 0xB3, 0xBA, 0xBD,
0xC7, 0xC0, 0xC9, 0xCE, 0xDB, 0xDC, 0xD5, 0xD2, 0xFF, 0xF8, 0xF1, 0xF6, 0xE3, 0xE4, 0xED, 0xEA,
0xB7, 0xB0, 0xB9, 0xBE, 0xAB, 0xAC, 0xA5, 0xA2, 0x8F, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9D, 0x9A,
0x27, 0x20, 0x29, 0x2E, 0x3B, 0x3C, 0x35, 0x32, 0x1F, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0D, 0x0A,
0x57, 0x50, 0x59, 0x5E, 0x4B, 0x4C, 0x45, 0x42, 0x6F, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7D, 0x7A,
0x89, 0x8E, 0x87, 0x80, 0x95, 0x92, 0x9B, 0x9C, 0xB1, 0xB6, 0xBF, 0xB8, 0xAD, 0xAA, 0xA3, 0xA4,
0xF9, 0xFE, 0xF7, 0xF0, 0xE5, 0xE2, 0xEB, 0xEC, 0xC1, 0xC6, 0xCF, 0xC8, 0xDD, 0xDA, 0xD3, 0xD4,
0x69, 0x6E, 0x67, 0x60, 0x75, 0x72, 0x7B, 0x7C, 0x51, 0x56, 0x5F, 0x58, 0x4D, 0x4A, 0x43, 0x44,
0x19, 0x1E, 0x17, 0x10, 0x05, 0x02, 0x0B, 0x0C, 0x21, 0x26, 0x2F, 0x28, 0x3D, 0x3A, 0x33, 0x34,
0x4E, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5C, 0x5B, 0x76, 0x71, 0x78, 0x7F, 0x6A, 0x6D, 0x64, 0x63,
0x3E, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2C, 0x2B, 0x06, 0x01, 0x08, 0x0F, 0x1A, 0x1D, 0x14, 0x13,
0xAE, 0xA9, 0xA0, 0xA7, 0xB2, 0xB5, 0xBC, 0xBB, 0x96, 0x91, 0x98, 0x9F, 0x8A, 0x8D, 0x84, 0x83,
0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB, 0xE6, 0xE1, 0xE8, 0xEF, 0xFA, 0xFD, 0xF4, 0xF3
};
}

View File

@ -1,63 +0,0 @@
///\file
/******************************************************************************
The MIT License(MIT)
Embedded Template Library.
https://github.com/ETLCPP/etl
http://www.etlcpp.com
Copyright(c) 2015 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 <stdint.h>
#include "etl/platform.h"
#include "etl/static_assert.h"
ETL_STATIC_ASSERT(ETL_8BIT_SUPPORT, "This file does not currently support targets with no 8bit type");
namespace etl
{
//***************************************************************************
/// Pearson lookup table
/// \ingroup pearson
//***************************************************************************
extern const uint8_t PEARSON_LOOKUP[] =
{
228, 39, 61, 95, 227, 187, 0, 197, 31, 189, 161, 222, 34, 15, 221, 246,
19, 234, 6, 50, 113, 3, 91, 63, 77, 245, 144, 2, 183, 196, 25, 226,
97, 126, 48, 59, 217, 4, 100, 145, 12, 88, 203, 149, 80, 154, 38, 27,
224, 218, 158, 115, 202, 79, 53, 83, 242, 36, 139, 131, 136, 191, 42, 170,
23, 99, 156, 51, 143, 60, 233, 206, 62, 108, 17, 67, 81, 71, 93, 195,
26, 231, 247, 96, 24, 200, 176, 209, 152, 212, 138, 165, 75, 185, 130, 248,
125, 110, 10, 116, 201, 90, 69, 204, 85, 251, 78, 157, 47, 184, 169, 141,
134, 230, 89, 21, 146, 46, 55, 128, 148, 207, 216, 11, 114, 199, 103, 102,
166, 244, 5, 104, 225, 160, 132, 28, 172, 65, 121, 140, 153, 119, 198, 210,
58, 87, 117, 177, 33, 22, 13, 37, 49, 174, 109, 40, 73, 211, 18, 167,
164, 252, 168, 74, 30, 173, 35, 98, 66, 193, 94, 175, 86, 54, 179, 122,
220, 151, 192, 29, 133, 254, 155, 127, 240, 232, 190, 180, 8, 68, 236, 20,
137, 92, 219, 208, 52, 250, 147, 142, 111, 112, 120, 45, 135, 255, 123, 229,
57, 182, 243, 124, 186, 253, 7, 237, 9, 16, 70, 171, 235, 107, 223, 118,
215, 178, 194, 181, 43, 188, 106, 105, 64, 241, 84, 238, 159, 44, 32, 76,
213, 163, 150, 101, 129, 14, 249, 205, 214, 1, 41, 56, 162, 72, 239, 82
} ;
}

View File

@ -1,551 +0,0 @@
///\file
/******************************************************************************
The MIT License(MIT)
Embedded Template Library.
https://github.com/ETLCPP/etl
http://www.etlcpp.com
Copyright(c) 2016 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 "../../include/etl/platform.h"
#include "../../include/etl/private/pvoidvector.h"
//*********************************************************************
/// Returns an iterator to the beginning of the vector.
///\return An iterator to the beginning of the vector.
//*********************************************************************
etl::pvoidvector::iterator etl::pvoidvector::begin()
{
return p_buffer;
}
//*********************************************************************
/// Returns a const_iterator to the beginning of the vector.
///\return A const iterator to the beginning of the vector.
//*********************************************************************
etl::pvoidvector::const_iterator etl::pvoidvector::begin() const
{
return const_iterator(p_buffer);
}
//*********************************************************************
/// Returns an iterator to the end of the vector.
///\return An iterator to the end of the vector.
//*********************************************************************
etl::pvoidvector::iterator etl::pvoidvector::end()
{
return p_end;
}
//*********************************************************************
/// Returns a const_iterator to the end of the vector.
///\return A const iterator to the end of the vector.
//*********************************************************************
etl::pvoidvector::const_iterator etl::pvoidvector::end() const
{
return const_iterator(p_end);
}
//*********************************************************************
/// Returns a const_iterator to the beginning of the vector.
///\return A const iterator to the beginning of the vector.
//*********************************************************************
etl::pvoidvector::const_iterator etl::pvoidvector::cbegin() const
{
return const_iterator(p_buffer);
}
//*********************************************************************
/// Returns a const_iterator to the end of the vector.
///\return A const iterator to the end of the vector.
//*********************************************************************
etl::pvoidvector::const_iterator etl::pvoidvector::cend() const
{
return const_iterator(p_end);
}
//*********************************************************************
/// Returns an reverse iterator to the reverse beginning of the vector.
///\return Iterator to the reverse beginning of the vector.
//*********************************************************************
etl::pvoidvector::reverse_iterator etl::pvoidvector::rbegin()
{
return reverse_iterator(end());
}
//*********************************************************************
/// Returns a const reverse iterator to the reverse beginning of the vector.
///\return Const iterator to the reverse beginning of the vector.
//*********************************************************************
etl::pvoidvector::const_reverse_iterator etl::pvoidvector::rbegin() const
{
return const_reverse_iterator(end());
}
//*********************************************************************
/// Returns a reverse iterator to the end + 1 of the vector.
///\return Reverse iterator to the end + 1 of the vector.
//*********************************************************************
etl::pvoidvector::reverse_iterator etl::pvoidvector::rend()
{
return reverse_iterator(begin());
}
//*********************************************************************
/// Returns a const reverse iterator to the end + 1 of the vector.
///\return Const reverse iterator to the end + 1 of the vector.
//*********************************************************************
etl::pvoidvector::const_reverse_iterator etl::pvoidvector::rend() const
{
return const_reverse_iterator(begin());
}
//*********************************************************************
/// Returns a const reverse iterator to the reverse beginning of the vector.
///\return Const reverse iterator to the reverse beginning of the vector.
//*********************************************************************
etl::pvoidvector::const_reverse_iterator etl::pvoidvector::crbegin() const
{
return const_reverse_iterator(cend());
}
//*********************************************************************
/// Returns a const reverse iterator to the end + 1 of the vector.
///\return Const reverse iterator to the end + 1 of the vector.
//*********************************************************************
etl::pvoidvector::const_reverse_iterator etl::pvoidvector::crend() const
{
return const_reverse_iterator(cbegin());
}
//*********************************************************************
/// Resizes the vector.
/// If asserts or exceptions are enabled and the new size is larger than the
/// maximum then a vector_full is thrown.
///\param new_size The new size.
//*********************************************************************
void etl::pvoidvector::resize(size_t new_size)
{
ETL_ASSERT(new_size <= CAPACITY, ETL_ERROR(vector_full));
p_end = p_buffer + new_size;
}
//*********************************************************************
/// Resizes the vector.
/// If asserts or exceptions are enabled and the new size is larger than the
/// maximum then a vector_full is thrown.
///\param new_size The new size.
///\param value The value to fill new elements with. Default = default constructed value.
//*********************************************************************
void etl::pvoidvector::resize(size_t new_size, etl::pvoidvector::value_type value)
{
ETL_ASSERT(new_size <= CAPACITY, ETL_ERROR(vector_full));
pointer p_new_end = p_buffer + new_size;
// Size up if necessary.
if (p_end < p_new_end)
{
std::fill(p_end, p_new_end, value);
}
p_end = p_new_end;
}
//*********************************************************************
/// Returns a reference to the value at index 'i'
///\param i The index.
///\return A reference to the value at index 'i'
//*********************************************************************
etl::pvoidvector::reference etl::pvoidvector::operator [](size_t i)
{
return reference(p_buffer[i]);
}
//*********************************************************************
/// Returns a const reference to the value at index 'i'
///\param i The index.
///\return A const reference to the value at index 'i'
//*********************************************************************
etl::pvoidvector::const_reference etl::pvoidvector::operator [](size_t i) const
{
return const_reference(p_buffer[i]);
}
//*********************************************************************
/// Returns a reference to the value at index 'i'
/// If asserts or exceptions are enabled, emits an etl::vector_out_of_bounds if the index is out of range.
///\param i The index.
///\return A reference to the value at index 'i'
//*********************************************************************
etl::pvoidvector::reference etl::pvoidvector::at(size_t i)
{
ETL_ASSERT(i < size(), ETL_ERROR(vector_out_of_bounds));
return reference(p_buffer[i]);
}
//*********************************************************************
/// Returns a const reference to the value at index 'i'
/// If asserts or exceptions are enabled, emits an etl::vector_out_of_bounds if the index is out of range.
///\param i The index.
///\return A const reference to the value at index 'i'
//*********************************************************************
etl::pvoidvector::const_reference etl::pvoidvector::at(size_t i) const
{
ETL_ASSERT(i < size(), ETL_ERROR(vector_out_of_bounds));
return const_reference(p_buffer[i]);
}
//*********************************************************************
/// Returns a reference to the first element.
///\return A reference to the first element.
//*********************************************************************
etl::pvoidvector::reference etl::pvoidvector::front()
{
return reference(p_buffer[0]);
}
//*********************************************************************
/// Returns a const reference to the first element.
///\return A const reference to the first element.
//*********************************************************************
etl::pvoidvector::const_reference etl::pvoidvector::front() const
{
return const_reference(p_buffer[0]);
}
//*********************************************************************
/// Returns a reference to the last element.
///\return A reference to the last element.
//*********************************************************************
etl::pvoidvector::reference etl::pvoidvector::back()
{
return reference(*(p_end - 1));
}
//*********************************************************************
/// Returns a const reference to the last element.
///\return A const reference to the last element.
//*********************************************************************
etl::pvoidvector::const_reference etl::pvoidvector::back() const
{
return const_reference(*(p_end - 1));
}
//*********************************************************************
/// Returns a pointer to the beginning of the vector data.
///\return A pointer to the beginning of the vector data.
//*********************************************************************
etl::pvoidvector::pointer etl::pvoidvector::data()
{
return pointer(p_buffer);
}
//*********************************************************************
/// Returns a const pointer to the beginning of the vector data.
///\return A const pointer to the beginning of the vector data.
//*********************************************************************
etl::pvoidvector::const_pointer etl::pvoidvector::data() const
{
return const_pointer(p_buffer);
}
//*********************************************************************
/// Assigns values to the vector.
/// If asserts or exceptions are enabled, emits vector_full if the vector does not have enough free space.
///\param n The number of elements to add.
///\param value The value to insert for each element.
//*********************************************************************
void etl::pvoidvector::assign(size_t n, etl::pvoidvector::value_type value)
{
initialise();
ETL_ASSERT(n <= CAPACITY, ETL_ERROR(vector_full));
for (size_t current_size = 0; current_size < n; ++current_size)
{
*p_end++ = value;
}
}
//*************************************************************************
/// Clears the vector.
//*************************************************************************
void etl::pvoidvector::clear()
{
initialise();
}
//*********************************************************************
/// Inserts a value at the end of the vector.
/// If asserts or exceptions are enabled, emits vector_full if the vector is already full.
///\param value The value to add.
//*********************************************************************
void etl::pvoidvector::push_back(etl::pvoidvector::value_type value)
{
#if defined(ETL_CHECK_PUSH_POP)
ETL_ASSERT(size() != CAPACITY, ETL_ERROR(vector_full));
#endif
*p_end++ = value;
}
//*************************************************************************
/// Removes an element from the end of the vector.
/// Does nothing if the vector is empty.
//*************************************************************************
void etl::pvoidvector::pop_back()
{
#if defined(ETL_CHECK_PUSH_POP)
ETL_ASSERT(size() > 0, ETL_ERROR(vector_empty));
#endif
--p_end;
}
//*********************************************************************
/// Inserts a value to the vector.
/// If asserts or exceptions are enabled, emits vector_full if the vector is already full.
///\param position The position to insert before.
///\param value The value to insert.
//*********************************************************************
etl::pvoidvector::iterator etl::pvoidvector::insert(etl::pvoidvector::iterator position, etl::pvoidvector::value_type value)
{
ETL_ASSERT(size() + 1 <= CAPACITY, ETL_ERROR(vector_full));
if (position != end())
{
++p_end;
std::copy_backward(position, end() - 1, end());
*position = value;
}
else
{
*p_end++ = value;
}
return position;
}
//*********************************************************************
/// Inserts 'n' values to the vector.
/// If asserts or exceptions are enabled, emits vector_full if the vector does not have enough free space.
///\param position The position to insert before.
///\param n The number of elements to add.
///\param value The value to insert.
//*********************************************************************
void etl::pvoidvector::insert(etl::pvoidvector::iterator position, size_t n, etl::pvoidvector::value_type value)
{
ETL_ASSERT((size() + 1) <= CAPACITY, ETL_ERROR(vector_full));
std::copy_backward(position, p_end, p_end + n);
std::fill_n(position, n, value);
p_end += n;
}
//*********************************************************************
/// Erases an element.
///\param i_element Iterator to the element.
///\return An iterator pointing to the element that followed the erased element.
//*********************************************************************
etl::pvoidvector::iterator etl::pvoidvector::erase(etl::pvoidvector::iterator i_element)
{
std::copy(i_element + 1, end(), i_element);
--p_end;
return i_element;
}
//*********************************************************************
/// Erases a range of elements.
/// The range includes all the elements between first and last, including the
/// element pointed by first, but not the one pointed by last.
///\param first Iterator to the first element.
///\param last Iterator to the last element.
///\return An iterator pointing to the element that followed the erased element.
//*********************************************************************
etl::pvoidvector::iterator etl::pvoidvector::erase(etl::pvoidvector::iterator first, etl::pvoidvector::iterator last)
{
std::copy(last, end(), first);
size_t n_delete = std::distance(first, last);
// Just adjust the count.
p_end -= n_delete;
return first;
}
//*************************************************************************
/// Assignment operator.
//*************************************************************************
etl::pvoidvector& etl::pvoidvector::operator = (const etl::pvoidvector& rhs)
{
if (&rhs != this)
{
assign(rhs.cbegin(), rhs.cend());
}
return *this;
}
//*************************************************************************
/// Gets the current size of the vector.
///\return The current size of the vector.
//*************************************************************************
etl::pvoidvector::size_type etl::pvoidvector::size() const
{
return size_t(p_end - p_buffer);
}
//*************************************************************************
/// Checks the 'empty' state of the vector.
///\return <b>true</b> if empty.
//*************************************************************************
bool etl::pvoidvector::empty() const
{
return (p_end == p_buffer);
}
//*************************************************************************
/// Checks the 'full' state of the vector.
///\return <b>true</b> if full.
//*************************************************************************
bool etl::pvoidvector::full() const
{
return size() == CAPACITY;
}
//*************************************************************************
/// Returns the remaining capacity.
///\return The remaining capacity.
//*************************************************************************
size_t etl::pvoidvector::available() const
{
return max_size() - size();
}
//*********************************************************************
/// Constructor.
//*********************************************************************
etl::pvoidvector::pvoidvector(void** p_buffer_, size_t MAX_SIZE)
: vector_base(MAX_SIZE),
p_buffer(p_buffer_),
p_end(p_buffer_)
{
}
//*********************************************************************
/// Initialise the vector.
//*********************************************************************
void etl::pvoidvector::initialise()
{
p_end = p_buffer;
}
//*************************************************************************
/// Fix the internal pointers after a low level memory copy.
//*************************************************************************
void etl::pvoidvector::repair_buffer(void** p_buffer_)
{
uintptr_t length = p_end - p_buffer;
p_buffer = p_buffer_;
p_end = p_buffer_ + length;
}
namespace etl
{
//***************************************************************************
/// Equal operator.
///\param lhs Reference to the first vector.
///\param rhs Reference to the second vector.
///\return <b>true</b> if the arrays are equal, otherwise <b>false</b>
///\ingroup vector
//***************************************************************************
bool operator ==(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs)
{
return (lhs.size() == rhs.size()) && std::equal(lhs.begin(), lhs.end(), rhs.begin());
}
//***************************************************************************
/// Not equal operator.
///\param lhs Reference to the first vector.
///\param rhs Reference to the second vector.
///\return <b>true</b> if the arrays are not equal, otherwise <b>false</b>
///\ingroup vector
//***************************************************************************
bool operator !=(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs)
{
return !(lhs == rhs);
}
//***************************************************************************
/// Less than operator.
///\param lhs Reference to the first vector.
///\param rhs Reference to the second vector.
///\return <b>true</b> if the first vector is lexicographically less than the second, otherwise <b>false</b>
///\ingroup vector
//***************************************************************************
inline bool operator <(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs)
{
return std::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
}
//***************************************************************************
/// Greater than operator.
///\param lhs Reference to the first vector.
///\param rhs Reference to the second vector.
///\return <b>true</b> if the first vector is lexicographically greater than the second, otherwise <b>false</b>
///\ingroup vector
//***************************************************************************
bool operator >(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs)
{
return (rhs < lhs);
}
//***************************************************************************
/// Less than or equal operator.
///\param lhs Reference to the first vector.
///\param rhs Reference to the second vector.
///\return <b>true</b> if the first vector is lexicographically less than or equal to the second, otherwise <b>false</b>
///\ingroup vector
//***************************************************************************
bool operator <=(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs)
{
return !(lhs > rhs);
}
//***************************************************************************
/// Greater than or equal operator.
///\param lhs Reference to the first vector.
///\param rhs Reference to the second vector.
///\return <b>true</b> if the first vector is lexicographically greater than or equal to the second, otherwise <b>false</b>
///\ingroup vector
//***************************************************************************
bool operator >=(const etl::pvoidvector& lhs, const etl::pvoidvector& rhs)
{
return !(lhs < rhs);
}
}

View File

@ -1,413 +0,0 @@
///\file
/******************************************************************************
The MIT License(MIT)
Embedded Template Library.
https://github.com/ETLCPP/etl
http://www.etlcpp.com
Copyright(c) 2017 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 "etl/platform.h"
#include "etl/random.h"
#include "etl/binary.h"
namespace etl
{
//***************************************************************************
// XOR Shift
//***************************************************************************
//***************************************************************************
/// Default constructor.
/// Attempts to come up with a unique non-zero seed.
//***************************************************************************
random_xorshift::random_xorshift()
{
// An attempt to come up with a unique non-zero seed,
// based on the address of the instance.
uintptr_t n = reinterpret_cast<uintptr_t>(this);
uint32_t seed = static_cast<uint32_t>(n);
initialise(seed);
}
//***************************************************************************
/// Constructor with seed value.
///\param seed The new seed value.
//***************************************************************************
random_xorshift::random_xorshift(uint32_t seed)
{
initialise(seed);
}
//***************************************************************************
/// Initialises the sequence with a new seed value.
///\param seed The new seed value.
//***************************************************************************
void random_xorshift::initialise(uint32_t seed)
{
// Add the first four primes to ensure that the seed isn't zero.
state[0] = seed + 3;
state[1] = seed + 5;
state[2] = seed + 7;
state[3] = seed + 11;
}
//***************************************************************************
/// Get the next random_xorshift number.
//***************************************************************************
uint32_t random_xorshift::operator()()
{
uint32_t n = state[3];
n ^= n << 11;
n ^= n >> 8;
state[3] = state[2];
state[2] = state[1];
state[1] = state[0];
n ^= state[0];
n ^= state[0] >> 19;
state[0] = n;
return n;
}
//***************************************************************************
/// Get the next random_xorshift number in a specified inclusive range.
//***************************************************************************
uint32_t random_xorshift::range(uint32_t low, uint32_t high)
{
uint32_t r = high - low + 1;
uint32_t n = operator()();
n %= r;
n += low;
return n;
}
//***************************************************************************
// Linear Congruential Generator
//***************************************************************************
//***************************************************************************
/// Default constructor.
/// Attempts to come up with a unique non-zero seed.
//***************************************************************************
random_lcg::random_lcg()
{
// An attempt to come up with a unique non-zero seed,
// based on the address of the instance.
uintptr_t n = reinterpret_cast<uintptr_t>(this);
uint32_t seed = static_cast<uint32_t>(n);
initialise(seed);
}
//***************************************************************************
/// Constructor with seed value.
///\param seed The new seed value.
//***************************************************************************
random_lcg::random_lcg(uint32_t seed)
{
initialise(seed);
}
//***************************************************************************
/// Initialises the sequence with a new seed value.
///\param seed The new seed value.
//***************************************************************************
void random_lcg::initialise(uint32_t seed)
{
seed = (seed == 0) ? 1 : seed;
value = (seed > m) ? m : seed;
}
//***************************************************************************
/// Get the next random_clcg number.
//***************************************************************************
uint32_t random_lcg::operator()()
{
value = (a * value) % m;
return value;
}
//***************************************************************************
/// Get the next random_clcg number in a specified inclusive range.
//***************************************************************************
uint32_t random_lcg::range(uint32_t low, uint32_t high)
{
uint32_t r = high - low + 1;
uint32_t n = operator()();
n %= r;
n += low;
return n;
}
//***************************************************************************
// Combined Linear Congruential Generator
//***************************************************************************
//***************************************************************************
/// Default constructor.
/// Attempts to come up with a unique non-zero seed.
//***************************************************************************
random_clcg::random_clcg()
{
// An attempt to come up with a unique non-zero seed,
// based on the address of the instance.
uintptr_t n = reinterpret_cast<uintptr_t>(this);
uint32_t seed = static_cast<uint32_t>(n);
initialise(seed);
}
//***************************************************************************
/// Constructor with seed value.
///\param seed The new seed value.
//***************************************************************************
random_clcg::random_clcg(uint32_t seed)
{
initialise(seed);
}
//***************************************************************************
/// Initialises the sequence with a new seed value.
///\param seed The new seed value.
//***************************************************************************
void random_clcg::initialise(uint32_t seed)
{
seed = (seed == 0) ? 1 : seed;
value1 = (seed > m1) ? m1 : seed;
value2 = (seed > m1) ? m1 : seed;
}
//***************************************************************************
/// Get the next random_clcg number.
//***************************************************************************
uint32_t random_clcg::operator()()
{
static const uint32_t m = ((m1 > m2) ? m1 : m2);
value1 = (a1 * value1) % m1;
value2 = (a2 * value2) % m2;
return (value1 + value2) % m;
}
//***************************************************************************
/// Get the next random_clcg number in a specified inclusive range.
//***************************************************************************
uint32_t random_clcg::range(uint32_t low, uint32_t high)
{
uint32_t r = high - low + 1;
uint32_t n = operator()();
n %= r;
n += low;
return n;
}
//***************************************************************************
// Linear Shift Feedback Register
//***************************************************************************
//***************************************************************************
/// Default constructor.
/// Attempts to come up with a unique non-zero seed.
//***************************************************************************
random_lsfr::random_lsfr()
{
// An attempt to come up with a unique non-zero seed,
// based on the address of the instance.
uintptr_t n = reinterpret_cast<uintptr_t>(this);
uint32_t seed = static_cast<uint32_t>(n);
initialise(seed);
}
//***************************************************************************
/// Constructor with seed value.
///\param seed The new seed value.
//***************************************************************************
random_lsfr::random_lsfr(uint32_t seed)
{
initialise(seed);
}
//***************************************************************************
/// Initialises the sequence with a new seed value.
///\param seed The new seed value.
//***************************************************************************
void random_lsfr::initialise(uint32_t seed)
{
value = seed;
}
//***************************************************************************
/// Get the next random_lsfr number.
//***************************************************************************
uint32_t random_lsfr::operator()()
{
static const uint32_t polynomial = 0x80200003;
value >>= 1;
if ((value & 1) == 1)
{
value ^= polynomial;
}
return value;
}
//***************************************************************************
/// Get the next random_lsfr number in a specified inclusive range.
//***************************************************************************
uint32_t random_lsfr::range(uint32_t low, uint32_t high)
{
uint32_t r = high - low + 1;
uint32_t n = operator()();
n %= r;
n += low;
return n;
}
//***************************************************************************
// Multiply with carry random number generator.
//***************************************************************************
//***************************************************************************
/// Default constructor.
/// Attempts to come up with a unique non-zero seed.
//***************************************************************************
random_mwc::random_mwc()
{
// An attempt to come up with a unique non-zero seed,
// based on the address of the instance.
uintptr_t n = reinterpret_cast<uintptr_t>(this);
uint32_t seed = static_cast<uint32_t>(n);
initialise(seed);
}
//***************************************************************************
/// Constructor with seed value.
///\param seed The new seed value.
//***************************************************************************
random_mwc::random_mwc(uint32_t seed)
{
initialise(seed);
}
//***************************************************************************
/// Initialises the sequence with a new seed value.
///\param seed The new seed value.
//***************************************************************************
void random_mwc::initialise(uint32_t seed)
{
value1 = seed;
value2 = seed;
}
//***************************************************************************
/// Get the next random_lsfr number.
//***************************************************************************
uint32_t random_mwc::operator()()
{
value1 = 36969 * (value1 & 0xFFFF) + (value1 >> 16);
value2 = 18000 * (value2 & 0xFFFF) + (value2 >> 16);
return (value1 << 16) + value2;
}
//***************************************************************************
/// Get the next random_lsfr number in a specified inclusive range.
//***************************************************************************
uint32_t random_mwc::range(uint32_t low, uint32_t high)
{
uint32_t r = high - low + 1;
uint32_t n = operator()();
n %= r;
n += low;
return n;
}
//***************************************************************************
// Permuted congruential generator.
//***************************************************************************
//***************************************************************************
/// Default constructor.
/// Attempts to come up with a unique non-zero seed.
//***************************************************************************
random_pcg::random_pcg()
{
// An attempt to come up with a unique non-zero seed,
// based on the address of the instance.
uintptr_t n = reinterpret_cast<uintptr_t>(this);
value = static_cast<uint64_t>(n);
}
//***************************************************************************
/// Constructor with seed value.
///\param seed The new seed value.
//***************************************************************************
random_pcg::random_pcg(uint32_t seed)
{
initialise(seed);
}
//***************************************************************************
/// Initialises the sequence with a new seed value.
///\param seed The new seed value.
//***************************************************************************
void random_pcg::initialise(uint32_t seed)
{
value = uint64_t(seed) | (uint64_t(seed) << 32);
}
//***************************************************************************
/// Get the next random_lsfr number.
//***************************************************************************
uint32_t random_pcg::operator()()
{
uint64_t x = value;
unsigned count = (unsigned)(value >> 59);
value = (x * multiplier) + increment;
x ^= x >> 18;
return etl::rotate_right((uint32_t)(x >> 27), count);
}
//***************************************************************************
/// Get the next random_lsfr number in a specified inclusive range.
//***************************************************************************
uint32_t random_pcg::range(uint32_t low, uint32_t high)
{
uint32_t r = high - low + 1;
uint32_t n = operator()();
n %= r;
n += low;
return n;
}
}

View File

@ -1,3 +1,19 @@
===============================================================================
14.3.0
etl::forward_list supports shared pools.
===============================================================================
14.2.0
Added 'don't care current state' transition entry option.
===============================================================================
14.1.0
Added hash based random number generator
===============================================================================
14.0.0
The ETL is now 'all header'.
===============================================================================
13.0.0
Added bit stream serialiser/deserialiser
@ -317,4 +333,4 @@ IO Ports
Fixed inconsistencies in the dynamic IO port API.
Type traits
Added 'conditional_integral_constant' to complement 'conditional'
Added 'conditional_integral_constant' to complement 'conditional'

View File

@ -317,22 +317,9 @@
<Unit filename="../../include/etl/version.h" />
<Unit filename="../../include/etl/visitor.h" />
<Unit filename="../../include/etl/wstring.h" />
<Unit filename="../../src/binary.cpp" />
<Unit filename="../../src/c/ecl_timer.c">
<Option compilerVar="CC" />
</Unit>
<Unit filename="../../src/crc16.cpp" />
<Unit filename="../../src/crc16_ccitt.cpp" />
<Unit filename="../../src/crc16_kermit.cpp" />
<Unit filename="../../src/crc16_modbus.cpp" />
<Unit filename="../../src/crc32.cpp" />
<Unit filename="../../src/crc32_c.cpp" />
<Unit filename="../../src/crc64_ecma.cpp" />
<Unit filename="../../src/crc8_ccitt.cpp" />
<Unit filename="../../src/error_handler.cpp" />
<Unit filename="../../src/pearson.cpp" />
<Unit filename="../../src/private/pvoidvector.cpp" />
<Unit filename="../../src/random.cpp" />
<Unit filename="../ExtraCheckMacros.h" />
<Unit filename="../data.h" />
<Unit filename="../ecl_user.h" />
@ -374,6 +361,7 @@
<Unit filename="../test_flat_set.cpp" />
<Unit filename="../test_fnv_1.cpp" />
<Unit filename="../test_forward_list.cpp" />
<Unit filename="../test_forward_list_shared_pool.cpp" />
<Unit filename="../test_fsm.cpp" />
<Unit filename="../test_function.cpp" />
<Unit filename="../test_functional.cpp" />

View File

@ -185,7 +185,7 @@ namespace
TEST_FIXTURE(SetupFixture, test_const_iterator)
{
CompareDataNDC compare_data(sorted_data.begin(), sorted_data.end());
DataNDC data(compare_data.begin(), compare_data.end());
const DataNDC data(compare_data.begin(), compare_data.end());
are_equal = std::equal(data.cbegin(), data.cend(), compare_data.cbegin());
@ -1110,6 +1110,7 @@ namespace
data.move_after(i_first_before, i_last, i_to_before);
are_equal = std::equal(data.begin(), data.end(), compare_data.begin());
CHECK(are_equal);
// Move to nearby.
i_first_before = data.begin();
@ -1134,6 +1135,7 @@ namespace
data.move_after(i_first_before, i_last, i_to_before);
are_equal = std::equal(data.begin(), data.end(), compare_data.begin());
CHECK(are_equal);
// Move to same.
i_first_before = data.begin();
@ -1158,6 +1160,7 @@ namespace
data.move_after(i_first_before, i_last, i_to_before);
are_equal = std::equal(data.begin(), data.end(), compare_data.begin());
CHECK(are_equal);
// Move to illegal place.
i_first_before = data.begin();

File diff suppressed because it is too large Load Diff

View File

@ -45,7 +45,25 @@ typedef etl::pearson<HASH_SIZE>::value_type hash_t;
//***************************************************************************
namespace etl
{
extern const uint8_t PEARSON_LOOKUP[];
static const uint8_t PEARSON_LOOKUP[] =
{
228, 39, 61, 95, 227, 187, 0, 197, 31, 189, 161, 222, 34, 15, 221, 246,
19, 234, 6, 50, 113, 3, 91, 63, 77, 245, 144, 2, 183, 196, 25, 226,
97, 126, 48, 59, 217, 4, 100, 145, 12, 88, 203, 149, 80, 154, 38, 27,
224, 218, 158, 115, 202, 79, 53, 83, 242, 36, 139, 131, 136, 191, 42, 170,
23, 99, 156, 51, 143, 60, 233, 206, 62, 108, 17, 67, 81, 71, 93, 195,
26, 231, 247, 96, 24, 200, 176, 209, 152, 212, 138, 165, 75, 185, 130, 248,
125, 110, 10, 116, 201, 90, 69, 204, 85, 251, 78, 157, 47, 184, 169, 141,
134, 230, 89, 21, 146, 46, 55, 128, 148, 207, 216, 11, 114, 199, 103, 102,
166, 244, 5, 104, 225, 160, 132, 28, 172, 65, 121, 140, 153, 119, 198, 210,
58, 87, 117, 177, 33, 22, 13, 37, 49, 174, 109, 40, 73, 211, 18, 167,
164, 252, 168, 74, 30, 173, 35, 98, 66, 193, 94, 175, 86, 54, 179, 122,
220, 151, 192, 29, 133, 254, 155, 127, 240, 232, 190, 180, 8, 68, 236, 20,
137, 92, 219, 208, 52, 250, 147, 142, 111, 112, 120, 45, 135, 255, 123, 229,
57, 182, 243, 124, 186, 253, 7, 237, 9, 16, 70, 171, 235, 107, 223, 118,
215, 178, 194, 181, 43, 188, 106, 105, 64, 241, 84, 238, 159, 44, 32, 76,
213, 163, 150, 101, 129, 14, 249, 205, 214, 1, 41, 56, 162, 72, 239, 82
};
}
//***************************************************************************
@ -86,7 +104,7 @@ std::ostream& operator <<(std::ostream& os, const hash_t& hash)
}
namespace
{
{
SUITE(test_pearson)
{
//*************************************************************************

View File

@ -31,6 +31,7 @@ SOFTWARE.
#include <stdint.h>
#include "etl/random.h"
#include "etl/crc32.h"
#include <vector>
#include <algorithm>
@ -357,5 +358,59 @@ namespace
CHECK(n <= high);
}
}
//=========================================================================
TEST(test_random_hash_sequence)
{
std::vector<uint32_t> out1(10000);
etl::random_hash<etl::crc32> r;
struct generator
{
generator(etl::random& r_)
: r(r_)
{
}
uint32_t operator()()
{
return r();
}
etl::random& r;
};
std::generate(out1.begin(), out1.end(), generator(r));
std::ofstream file("random_hash.csv");
if (!file.fail())
{
for (size_t i = 0; i < out1.size(); i += 2)
{
file << out1[i] << "," << out1[i + 1] << "\n";
}
}
file.close();
}
//=========================================================================
TEST(test_random_hash_range)
{
etl::random_hash<etl::crc32> r;
uint32_t low = 1234;
uint32_t high = 9876;
for (int i = 0; i < 100000; ++i)
{
uint32_t n = r.range(low, high);
CHECK(n >= low);
CHECK(n <= high);
}
}
};
}

View File

@ -47,7 +47,8 @@ namespace
STOP,
EMERGENCY_STOP,
STOPPED,
SET_SPEED
SET_SPEED,
ABORT
};
ETL_DECLARE_ENUM_TYPE(EventId, etl::istate_chart::event_id_t)
@ -56,6 +57,7 @@ namespace
ETL_ENUM_TYPE(EMERGENCY_STOP, "Emergency Stop")
ETL_ENUM_TYPE(STOPPED, "Stopped")
ETL_ENUM_TYPE(SET_SPEED, "Set Speed")
ETL_ENUM_TYPE(ABORT, "Abort")
ETL_END_ENUM_TYPE
};
@ -204,19 +206,20 @@ namespace
bool guard;
static const etl::array<MotorControl::transition, 6> transitionTable;
static const etl::array<MotorControl::transition, 7> transitionTable;
static const etl::array<MotorControl::state, 3> stateTable;
};
//***************************************************************************
const etl::array<MotorControl::transition, 6> MotorControl::transitionTable =
const etl::array<MotorControl::transition, 7> MotorControl::transitionTable =
{
MotorControl::transition(StateId::IDLE, EventId::START, StateId::RUNNING, &MotorControl::OnStart, &MotorControl::Guard),
MotorControl::transition(StateId::IDLE, EventId::START, StateId::IDLE, &MotorControl::Null, &MotorControl::NotGuard),
MotorControl::transition(StateId::RUNNING, EventId::STOP, StateId::WINDING_DOWN, &MotorControl::OnStop),
MotorControl::transition(StateId::RUNNING, EventId::EMERGENCY_STOP, StateId::IDLE, &MotorControl::OnStop),
MotorControl::transition(StateId::RUNNING, EventId::SET_SPEED, StateId::RUNNING, &MotorControl::OnSetSpeed),
MotorControl::transition(StateId::WINDING_DOWN, EventId::STOPPED, StateId::IDLE, &MotorControl::OnStopped)
MotorControl::transition(StateId::WINDING_DOWN, EventId::STOPPED, StateId::IDLE, &MotorControl::OnStopped),
MotorControl::transition( EventId::ABORT, StateId::IDLE)
};
//***************************************************************************
@ -282,7 +285,7 @@ namespace
CHECK_EQUAL(0, motorControl.stopCount);
CHECK_EQUAL(0, motorControl.stoppedCount);
CHECK_EQUAL(0, motorControl.windingDown);
// Send Start event.
motorControl.guard = false;
motorControl.process_event(EventId::START);
@ -399,7 +402,7 @@ namespace
TEST(test_fsm_emergency_stop)
{
motorControl.ClearStatistics();
// Now in Idle state.
// Send Start event.
@ -431,5 +434,33 @@ namespace
CHECK_EQUAL(0, motorControl.stoppedCount);
CHECK_EQUAL(0, motorControl.windingDown);
}
//*************************************************************************
TEST(test_fsm_abort)
{
motorControl.ClearStatistics();
// Now in Idle state.
// Send Start event.
motorControl.process_event(EventId::START);
// Now in Running state.
motorControl.process_event(EventId::ABORT);
CHECK_EQUAL(StateId::IDLE, int(motorControl.get_state_id()));
// Send Start event.
motorControl.process_event(EventId::START);
// Now in Running state.
// Send Stop event.
motorControl.process_event(EventId::STOP);
// Now in WindingDown state.
motorControl.process_event(EventId::ABORT);
CHECK_EQUAL(StateId::IDLE, int(motorControl.get_state_id()));
}
};
}

View File

@ -4,3 +4,4 @@
/random_mwc.csv
/random_xorshift.csv
/random_pcg.csv
/random_hash.csv

View File

@ -556,24 +556,12 @@
<ClCompile Include="..\..\..\unittest-cpp\UnitTest++\TimeConstraint.cpp" />
<ClCompile Include="..\..\..\unittest-cpp\UnitTest++\Win32\TimeHelpers.cpp" />
<ClCompile Include="..\..\..\unittest-cpp\UnitTest++\XmlTestReporter.cpp" />
<ClCompile Include="..\..\src\binary.cpp" />
<ClCompile Include="..\..\src\crc16.cpp" />
<ClCompile Include="..\..\src\crc16_ccitt.cpp" />
<ClCompile Include="..\..\src\crc16_kermit.cpp" />
<ClCompile Include="..\..\src\crc16_modbus.cpp" />
<ClCompile Include="..\..\src\crc32.cpp" />
<ClCompile Include="..\..\src\crc32_c.cpp" />
<ClCompile Include="..\..\src\crc64_ecma.cpp" />
<ClCompile Include="..\..\src\crc8_ccitt.cpp" />
<ClCompile Include="..\..\src\c\ecl_timer.c" />
<ClCompile Include="..\..\src\error_handler.cpp" />
<ClCompile Include="..\..\src\pearson.cpp" />
<ClCompile Include="..\..\src\private\pvoidvector.cpp" />
<ClCompile Include="..\..\src\random.cpp" />
<ClCompile Include="..\main.cpp" />
<ClCompile Include="..\murmurhash3.cpp" />
<ClCompile Include="..\test_algorithm.cpp" />
<ClCompile Include="..\test_alignment.cpp" />
<ClCompile Include="..\test_forward_list_shared_pool.cpp" />
<ClCompile Include="..\test_bit_stream.cpp" />
<ClCompile Include="..\test_list_shared_pool.cpp" />
<ClCompile Include="..\test_no_stl_algorithm.cpp" />

View File

@ -1004,39 +1004,6 @@
<ClCompile Include="..\test_xor_rotate_checksum.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\private\pvoidvector.cpp">
<Filter>ETL\Private</Filter>
</ClCompile>
<ClCompile Include="..\..\src\crc8_ccitt.cpp">
<Filter>ETL\Maths</Filter>
</ClCompile>
<ClCompile Include="..\..\src\crc16.cpp">
<Filter>ETL\Maths</Filter>
</ClCompile>
<ClCompile Include="..\..\src\crc16_ccitt.cpp">
<Filter>ETL\Maths</Filter>
</ClCompile>
<ClCompile Include="..\..\src\crc16_kermit.cpp">
<Filter>ETL\Maths</Filter>
</ClCompile>
<ClCompile Include="..\..\src\crc32.cpp">
<Filter>ETL\Maths</Filter>
</ClCompile>
<ClCompile Include="..\..\src\crc64_ecma.cpp">
<Filter>ETL\Maths</Filter>
</ClCompile>
<ClCompile Include="..\..\src\pearson.cpp">
<Filter>ETL\Maths</Filter>
</ClCompile>
<ClCompile Include="..\..\src\random.cpp">
<Filter>ETL\Maths</Filter>
</ClCompile>
<ClCompile Include="..\..\src\binary.cpp">
<Filter>ETL\Utilities</Filter>
</ClCompile>
<ClCompile Include="..\..\src\error_handler.cpp">
<Filter>ETL\Utilities</Filter>
</ClCompile>
<ClCompile Include="..\..\src\c\ecl_timer.c">
<Filter>ECL</Filter>
</ClCompile>
@ -1058,9 +1025,6 @@
<ClCompile Include="..\test_type_select.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\crc32_c.cpp">
<Filter>ETL\Maths</Filter>
</ClCompile>
<ClCompile Include="..\..\..\unittest-cpp\UnitTest++\AssertException.cpp">
<Filter>UnitTest++</Filter>
</ClCompile>
@ -1151,6 +1115,9 @@
<ClCompile Include="..\test_list_shared_pool.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\test_forward_list_shared_pool.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\test_no_stl_iterator.cpp">
<Filter>Source Files</Filter>
</ClCompile>