v1.1.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Modules Pages
Functions
Memory

Fast memory copy, fill, and CRC operations. More...

Functions

void Sifteo::bzero (void *s, unsigned count)
 Write 'n' zero bytes to memory.
 
template<typename T >
void Sifteo::bzero (T &s)
 One-argument form of bzero: Templatized to zero any fixed-size object.
 
uint32_t Sifteo::crc32 (const void *bytes, unsigned count)
 Calculate a 32-bit CRC over a block of memory. More...
 
template<typename T >
uint32_t Sifteo::crc32 (const T &s)
 Templatized version of crc32() for fixed-size objects.
 
int Sifteo::memcmp (const uint8_t *a, const uint8_t *b, unsigned count)
 memcmp(), with an implicit 8-bit data width
 
int Sifteo::memcmp8 (const uint8_t *a, const uint8_t *b, unsigned count)
 memcmp(), with an explicit 8-bit data width
 
void Sifteo::memcpy (uint8_t *dest, const uint8_t *src, unsigned count)
 memcpy(), with an implicit 8-bit data width
 
void Sifteo::memcpy (uint16_t *dest, const uint16_t *src, unsigned count)
 memcpy(), with an implicit 16-bit data width
 
void Sifteo::memcpy (uint32_t *dest, const uint32_t *src, unsigned count)
 memcpy(), with an implicit 32-bit data width
 
void Sifteo::memcpy16 (uint16_t *dest, const uint16_t *src, unsigned count)
 memcpy(), with an explicit 16-bit data width
 
void Sifteo::memcpy32 (uint32_t *dest, const uint32_t *src, unsigned count)
 memcpy(), with an explicit 32-bit data width
 
void Sifteo::memcpy8 (uint8_t *dest, const uint8_t *src, unsigned count)
 memcpy(), with an explicit 8-bit data width
 
void Sifteo::memset (uint8_t *dest, uint8_t value, unsigned count)
 memset(), with an implicit 8-bit data width
 
void Sifteo::memset (uint16_t *dest, uint16_t value, unsigned count)
 memset(), with an implicit 16-bit data width
 
void Sifteo::memset (uint32_t *dest, uint32_t value, unsigned count)
 memset(), with an implicit 32-bit data width
 
void Sifteo::memset16 (uint16_t *dest, uint16_t value, unsigned count)
 memset(), with an explicit 16-bit data width
 
void Sifteo::memset32 (uint32_t *dest, uint32_t value, unsigned count)
 memset(), with an explicit 32-bit data width
 
void Sifteo::memset8 (uint8_t *dest, uint8_t value, unsigned count)
 memset(), with an explicit 8-bit data width
 

Detailed Description

Fast memory copy, fill, and CRC operations.

Function Documentation

uint32_t Sifteo::crc32 ( const void *  bytes,
unsigned  count 
)
inline

Calculate a 32-bit CRC over a block of memory.

This is a hardware-accelerated implementation of a variant of the CRC-32 Cyclic Redundancy Check algorithm. You can use this to check data integrity, or as a simple hash function for applications that do not require a cryptographic hash.

The output of this function is equivalent to the following (slow) reference implementation:

uint32_t referenceCRC32(const uint8_t *bytes, int count)
{
    int32_t crc = -1;
    while (count > 0)
    {
        uint8_t byte0 = count-- > 0 ? *bytes++ : 0xFF;
        uint8_t byte1 = count-- > 0 ? *bytes++ : 0xFF;
        uint8_t byte2 = count-- > 0 ? *bytes++ : 0xFF;
        uint8_t byte3 = count-- > 0 ? *bytes++ : 0xFF;

        int32_t word = (byte3 << 24) | (byte2 << 16) | (byte1 << 8) | byte0;

        for (unsigned bit = 32; bit; --bit) {
            crc = (crc << 1) ^ ((crc ^ word) < 0 ? 0x04c11db7 : 0);
            word = word << 1;
        }
    }
    return crc;
}

This library function works most efficiently when both 'bytes' and 'count' are both a multiple of 4, but neither condition is mandatory. If the length of memory is not a multiple of 32 bits, the result is identical to if the block had been padded to the next multiple of 32 bits with up to three 0xFF bytes.