[ovs-dev] [PATCH v4 1/4] lib: Add CRC32C Implementation

Joe Stringer joe at wand.net.nz
Sun Aug 11 11:41:41 UTC 2013


On Sat, Aug 10, 2013 at 5:09 AM, Ben Pfaff <blp at nicira.com> wrote:

> On Wed, Jul 31, 2013 at 09:31:55AM +0900, Joe Stringer wrote:
> > +ovs_be32
> > +crc32c(const uint8_t *data, size_t size)
> > +{
> > +    uint32_t crc = 0xffffffffL;
> > +
> > +    while (size--) {
> > +        crc = crc32Table[(crc ^ *data++) & 0xff] ^ (crc >> 8);
> > +    }
> > +
> > +    /* The result of this CRC calculation provides us a value in the
> reverse
> > +     * byte-order as compared with our architecture. On big-endian
> systems,
> > +     * this is opposite to our return type. So, to return a big-endian
> > +     * value, we must swap the byte-order. */
> > +#if defined(WORDS_BIGENDIAN)
> > +    crc = get_unaligned_u32(&crc);
> > +#endif
>
> I don't see how this does any kind of byteswapping (as the comment
> claims).  Just treating 'crc' as unaligned (&crc should in fact be
> properly aligned) has no effect.  As far as I can tell it is
> equivalent to "crc = crc;"


Ah, right you are. I think I got a bit lost on my way to a byteswapping
function. I'll fix this up. Unfortunately I don't have a system to test
this on.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openvswitch.org/pipermail/ovs-dev/attachments/20130811/fd1d6a33/attachment-0003.html>


More information about the dev mailing list