mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "George Spelvin" <linux@horizon.com>
To: arend@broadcom.com, linux@horizon.com
Cc: johannes@sipsolutions.net, linux-kernel@vger.kernel.org
Subject: Re: [RFC] lib: crc8: add new library module providing crc8
Date: 23 May 2011 19:38:35 -0400	[thread overview]
Message-ID: <20110523233835.32254.qmail@science.horizon.com> (raw)
In-Reply-To: <4DDAC1A5.20004@broadcom.com>

>> Thanks. However, your code example is confusing.

>>> You can fill in a CRC table for an arbitrary polynomial with
>>>
>>> #define POLY 0xAB	/* 1 + x^2 + x^4 + x^6 + x^7 (+ x^8) */
>>> typedef uint8_t crc_type;	/* Must be an unsigned type */
>>>
>>> void
>>> crc_le(crc_type const table[256], crc_type crc, u8 const *buf, size_t len)
>>> {
>>> 	while (len--)
>>> 		crc = (crc>>  8) ^ table[(crc ^ *buf++)&  0xff];
> 
>> Here is where my confusion starts. Shifting crc by 8 bits basically 
>> means 0 ^ table[], right?

> I think I understand the code a bit better. Your code is generic for any 
> given crc_type.

Yes, exactly.  The crc_type has to be at least as wide as the CRC
being computed.  If the crc_type is only 8 bits, the shift by 8 does
indeed get optimized away.

      reply	other threads:[~2011-05-23 23:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-22 15:25 George Spelvin
2011-05-23 20:16 ` Arend van Spriel
2011-05-23 20:20 ` Arend van Spriel
2011-05-23 23:38   ` George Spelvin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110523233835.32254.qmail@science.horizon.com \
    --to=linux@horizon.com \
    --cc=arend@broadcom.com \
    --cc=johannes@sipsolutions.net \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®