Searching \ for '[pic]:CRCs' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/method/errors.htm?key=crc
Search entire site for: 'CRCs'.

Exact match. Not showing close matches.
PICList Thread
'[pic]:CRCs'
2003\01\15@102458 by Scott Dattalo

face
flavicon
face
There's not much now, but I've put some optimized CRC routines onto a web
page:

http://www.dattalo.com/technical/software/pic/crc.php

You'll find the two routines that were discussed recently and a third that
I also needed.

Scott

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spam_OUTlistservTakeThisOuTspammitvma.mit.edu with SET PICList DIGEST in the body

2003\01\15@165425 by Wagner Lipnharski

flavicon
face
Scott Dattalo wrote:
> There's not much now, but I've put some optimized CRC routines onto a
> web page:
>
> http://www.dattalo.com/technical/software/pic/crc.php
>
> You'll find the two routines that were discussed recently and a third
> that I also needed.
>
> Scott
>
> --
> http://www.piclist.com#nomail Going offline? Don't AutoReply us!
> email .....listservKILLspamspam@spam@mitvma.mit.edu with SET PICList DIGEST in the body


Scott, even so that the CRC-CCITT (SDLC/HDLC FCS calculation) routine is
wrong at that url.
(rcshttp://www.urz.tu-dresden.de/~sr21/crc.html)

Below some examples of its calculation and what it should be:

input hex    result     correct
---------   --------   ---------
 01          F1D1       1E0E
 02          C1B2       2C95
01020304      5349       C66E

There is no way to make it correct, inverting, direct/indirect, reversing,
etc.
My "trusty" little DOS assembly routine still doing it correct. :)

I already sent an email to the owner in Germany.

Scott, your url is being very difficult to access:

D:\>ping http://www.dattalo.com
Pinging vhost.kolwynia.com [209.66.107.31] with 32 bytes of data:
Request timed out.
Request timed out.
Request timed out.

Wagner.

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservspamKILLspammitvma.mit.edu with SET PICList DIGEST in the body

2003\01\15@202920 by Scott Dattalo

face
flavicon
face
On Wed, 15 Jan 2003, Wagner Lipnharski wrote:

>
> Scott, even so that the CRC-CCITT (SDLC/HDLC FCS calculation) routine is
> wrong at that url.
> (rcshttp://www.urz.tu-dresden.de/~sr21/crc.html)

I'm glad then I didn't use that as a reference. I thought the web page was
pretty neat and intuitive, so I linked in.

>
> Scott, your url is being very difficult to access:
>
> D:\>ping http://www.dattalo.com

Maybe you should try:

[wlipnharski]$ ping

:)

I don't know why it was slow, but it seems okay now.

Scott

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email .....listservKILLspamspam.....mitvma.mit.edu with SET PICList DIGEST in the body

2003\01\17@014728 by Scott Dattalo

face
flavicon
face
On Wed, 15 Jan 2003, Scott Dattalo wrote:

<snip>

Not wanting to leave good enough alone, I dove into the CRC16 calculation
again. I found another implementation that also takes only 17-cycles. Oh
well. But what's interesting, is I found a way to express the CRC16
algorithm in a very simple way that's useful for high level languages:


int crc_1021(int data)
{

 int x;

 x = ((crc>>8) ^ data) & 0xff;
 x ^= x>>4;

 crc = (crc << 8) ^ (x << 12) ^ (x <<5) ^ x;

 crc &= 0xffff;

 return crc;

}


Any barrel-shifter equipped processor ought to rip through this in just a
few cycles! I arrived at this by taking the PIC code and writing it
algebraically and then simplifying it. I was surprised to see what popped
out. Here's another PIC routine that uses this C implementation as
a guide.


CRC16_1021_version2:

       xorwf   CRC16_High,w
       movwf   Index
       andlw   0xf0
       swapf   Index,f
       xorwf   Index,f         ;'x' with high and low nibbles swapped


       movf    Index,W
       andlw   0xf0            ; x<<12
       xorwf   CRC16_Low,W
       movwf   CRC16_High

       rlf     Index,W         ; x<<5
       rlf     Index,W         ;
       xorwf   CRC16_High,f
       andlw   0xe0
       xorwf   CRC16_High,f

       swapf   Index,F         ; x
       xorwf   Index,W
       movwf   CRC16_Low

Scott

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2003\01\17@113353 by Wagner Lipnharski

flavicon
face
Scott Dattalo wrote:
{Quote hidden}

Scott, other than just clarifying that the poly you are using above
(16-12-5-0) are CRC16-CCITT or in short form X.25, or even, FCS for IBM
protocols, the CRC routines can be done in several ways, from look-ahead
tables to strange routines.

The logic I am being using for many years, for pure (16-15-2-0) CRC16 (not
CCITT/X.25/FCS), using any programming platform is this:

--------------------------------------------------
Variables:

  CRC16VAR (16 bits composed by CRC16H + CRC16L)
  DATABYTE
  8BITSCOUNTER

1) At start CRC16VAR = 0
2) 8BITSCOUNTER = 8
3) Logic Shift Right CRC16VAR, save carryBit
4) Logic Shift Right DATABYTE, XOR carrybit with carryBit from [2]
5) If the above XOR = 1 then XOR hex "A001" over the CRC16VAR
6) Decrement 8BITSCOUNTER, if not zero, goto 3.
7) If more data, load into DATABYTE and goto 2.

as a variation;

1) At start CRC16VAR = 0
2) 8BITSCOUNTER = 8
3) XOR bits 0 from CRC16VAR and DATABYTE - save as X
4) Logical Shift Right CRC16VAR
5) Logical Shift Right DATABYTE
6) If X from [3] is 1 then XOR hex "A001" over the CRC16VAR
7) Decrement 8BITSCOUNTER, if not zero, goto 3.
8) If more data, load into DATABYTE and goto 2.

Wagner.

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2003\01\17@123439 by Scott Dattalo

face
flavicon
face
On Fri, 17 Jan 2003, Wagner Lipnharski wrote:

<snip>

{Quote hidden}

Yes, this algorithm has been discussed. Andrew Warren has the most
efficient implementation. I also saw that Nikolai has written the same
thing for the SX. But any looped algorithm is going to take more than 17
cycles! IIRC, Andy's routine weighs in at around 65 cycles. OTOH, there
are only 9 instructions (there are also two instructions for initializing
the CRC and I think there should be a CLRC there as well):

http://home.netcom.com/~fastfwd/answers.html#PIC00076


Scott

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2003\01\21@085859 by o-8859-1?Q?Tony_K=FCbek?=

flavicon
face
Hi,


Scott Dattalo wrote:
<snip>
>Not wanting to leave good enough alone, I dove into the CRC16
calculation
>again. I found another implementation that also takes only 17-cycles.
Oh
>well. But what's interesting, is I found a way to express the CRC16
>algorithm in a very simple way that's useful for high level languages:
<snip>

For some reason I missed this thread ( and Scotts original post ) but
it's never to
late for catching up :). Anyway, interesting expression. I left the crc
stuff
on the backburner for a while but crc-32 is luring me to take another
stab, not
that I'll ever have the insightfullness that Scott has but I might
provide some
neat ideas :).

So if time permits an crc-32 should be added to this list sometimes in
the future.
This could be useful for tcp/ip implementations, as far as I know
current implemenations
does not compute the full crc32 for the outgoing message.


/Tony

--
http://www.piclist.com hint: To leave the PICList
EraseMEpiclist-unsubscribe-requestspam_OUTspamTakeThisOuTmitvma.mit.edu>

2003\01\21@093612 by Scott Dattalo

face
flavicon
face
On Tue, 21 Jan 2003, Tony K|bek wrote:

{Quote hidden}

I was wondering why you hadn't responded yet!

>
> So if time permits an crc-32 should be added to this list sometimes in
> the future.
> This could be useful for tcp/ip implementations, as far as I know
> current implemenations
> does not compute the full crc32 for the outgoing message.

I don't know why, but I've been thinking about the CRC-32 too :). I was
surprised to discover that the 8-bit CRC in Dallas' 1-wire products is
more difficult to implement than the 16-bit CRCs. It lacks the symmetry of
say a CRC-16 computation.  This made me curious about the 32-bit CRC's. Do
they have the simple symmetry that allows them to be efficiently computed?
Incidently, the technique used to implement the 8-bit CRC (see
http://www.dattalo.com/technical/software/pic/crc_8.asm for an
implementation, but no description) is completely generic. It takes 19
cycles. In general, for an N-byte crc, this technique will take about 9*N
cycles to implement. I'd expect 36 to 40 cycles for a 32-bit CRC. I'd
expect less if symmetry can be exploited.

Scott

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestspamspam_OUTmitvma.mit.edu>

2003\01\21@094024 by Kyrre Aalerud

flavicon
face
I never got the start of this either...

   KreAture

----- Original Message -----
From: "Scott Dattalo" <@spam@scottKILLspamspamDATTALO.COM>
To: <KILLspamPICLISTKILLspamspamMITVMA.MIT.EDU>
Sent: Tuesday, January 21, 2003 3:29 PM
Subject: Re: [pic]:CRCs


{Quote hidden}

--
http://www.piclist.com hint: To leave the PICList
spamBeGonepiclist-unsubscribe-requestspamBeGonespammitvma.mit.edu>

2003\01\22@061859 by o-8859-1?Q?Tony_K=FCbek?=

flavicon
face
Hi,

Scott Dattalo wrote:
<snip>
> I don't know why, but I've been thinking about the CRC-32 too :). I
was
> surprised to discover that the 8-bit CRC in Dallas' 1-wire products is
> more difficult to implement than the 16-bit CRCs. It lacks the
symmetry of
> say a CRC-16 computation.  This made me curious about the 32-bit
CRC's. Do
> they have the simple symmetry that allows them to be efficiently
computed?
> Incidently, the technique used to implement the 8-bit CRC (see
> http://www.dattalo.com/technical/software/pic/crc_8.asm for an
> implementation, but no description) is completely generic. It takes 19
> cycles. In general, for an N-byte crc, this technique will take about
9*N
> cycles to implement. I'd expect 36 to 40 cycles for a 32-bit CRC. I'd
> expect less if symmetry can be exploited.
<snip>

:) my initial estimates were a few cycles over that, something around
50 cycles, an initial glance the crc32 leans towards more brute force
than
elegant symetry, however there are a few 'shortcuts' that can be made
but if these will
save cycles in the end I'm still not sure.
The polynom for crc32 affect many more bits than the crc16, that is in
relative
number of bits affected, crc16 affects 3 bits/16 bits ~19%, crc32
affects 14/32 ~45%.
I belive that the low percentage of affected bits in the crc16 polynom
'helped' finding
the symetry. Affecting more number of bits will make symetry harder (and
more inefficent) to
calculate.
Anyway the thread is alive now,

/Tony

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2003\01\22@095435 by Scott Dattalo

face
flavicon
face
On Wed, 22 Jan 2003, Tony K|bek wrote:

{Quote hidden}

My 9*N formula should've been 9*N*2. Just checking if you're reading :).
So the brute force method for a 32-bit or 4-byte crc would be closer to 70
or 80 cycles!

{Quote hidden}

I agree. The bits are quite blenderized...

If you go here:

http://www.repairfaq.org/filipg/LINK/F_crc_v35.html#CRCV_001


You'll find the specs for the CRC-32 to be:

  Name   : "CRC-32"
  Width  : 32
  Poly   : 04C11DB7
  Init   : FFFFFFFF
  RefIn  : True
  RefOut : True
  XorOut : FFFFFFFF
  Check  : CBF43926

If you go here:

rcshttp://www.urz.tu-dresden.de/~sr21/crc.html

and grab the C-Code:

rcshttp://www.urz.tu-dresden.de/~sr21/crctester.c

You'll find an algorithm that implements CRC-32. In fact, it implements
crc-32 in 4 different ways, slow and fast bit by bit and slow and fast
table reads.

I've added a new one that uses nibble indexing (think PIC) and smaller
tables:


unsigned long crcSmalltablefast (unsigned char* p, unsigned long len)
{

 // fast lookup table algorithm without augmented zero bytes, e.g. used
in pkzip.
 // only usable with polynom orders of 8, 16, 24 or 32.

 unsigned long crc = crcinit_direct;
 unsigned long i;

 if (refin)
   crc = reflect(crc, order);

 if (!refin)
   while (len--) {
     i = ((crc >> (order-8)) & 0xff) ^ *p++;
     crc = (crc << 8) ^ crcrow0[i&0x0f] ^ crccol0[i>>4];
   }
 else
   while (len--) {
     i = (crc & 0xff) ^ *p++;
     crc = (crc >> 8) ^ crcrow0[i&0x0f] ^ crccol0[i>>4];
   }

 if (refout^refin)
   crc = reflect(crc, order);

 crc^= crcxor;
 crc&= crcmask;

 return(crc);
}


The two small tables are 16-element arrays obtained straight from the
256-element table:

   if(i<16)
     crcrow0[i] = crctab[i];
   if((i & 0x0f) == 0)
     crccol0[i>>4] = crctab[i];

Or if you want, here they are

  row         col
-----------------------
 00000000   00000000
 77073096   1db71064
 ee0e612c   3b6e20c8
 990951ba   26d930ac
 076dc419   76dc4190
 706af48f   6b6b51f4
 e963a535   4db26158
 9e6495a3   5005713c
 0edb8832   edb88320
 79dcb8a4   f00f9344
 e0d5e91e   d6d6a3e8
 97d2d988   cb61b38c
 09b64c2b   9b64c2b0
 7eb17cbd   86d3d2d4
 e7b82d07   a00ae278
 90bf1d91   bdbdf21c

If you look closely at these numbers, all sorts of amazing patterns jump
out. I've only just now started looking at them and haven't unraveled the
underlying symmetry (yet).

The brute force implementation to which Tony and I elude, requires
building these two arrays bit-by-bit based on the index into the array.
For example, the far left column of nibbles is 0,7,e,9,... If you examine
the most significant bit of this you'll see 0,0,1,1,.... This bit is the
same as the second lsb of the index. In other words, if the index is a
nibble, its bits can be labeled i3,i2,i1,i0. The most significant bit of
the row array, r31, is simply i1.

If you label the nibbles of the row and column array, R7R6... and C7C6...,
then you can express the nibble R7 by:

R7 = (i1, i1^i0, i1^i0, i0)

Where (a,b,c,d) form the four bits of the nibble.

Now it's a grind. Meticuously derive the remaining 15 boolean expression,
drink a couple of pots of coffee, and a magic pattern will appear before
your eyes!

> Anyway the thread is alive now,

Yep!

Scott

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

2003\01\23@120131 by Scott Dattalo

face
flavicon
face
On Wed, 22 Jan 2003, Scott Dattalo wrote:

<snip>

Continuing with the previous post...

Here's a fairly optimized CRC-32 implementation suitable for a 32-bit
processor. It's been structured so that a compiler can implement the
algorithm with 4 registers (although I haven't looked at the assembly code
generated by a compiler).


unsigned long crcbitbybit_1(unsigned char* p, unsigned long len)
{

 unsigned long i;
 unsigned long crc = crcinit_direct;
 unsigned long u,v;

 if (refin)
   crc = reflect(crc, order);


 if(!refin) {
   ;
 } else
   while (len--) {
     i = (crc & 0xff) ^ *p++;
     crc >>= 8;

     u = 0x076dc419;
     v = u>>2;

     if(i & 0x04)
       crc ^= u;

     u <<= 1;
     if(i & 0x08)
       crc ^= u;

     u <<= 1;
     if(i & 0x10)
       crc ^= u;

     u <<= 1;
     if(i & 0x20)
       crc ^= u;

     u <<= 1;
     v ^= u;
     if(i & 0x40)
       crc ^= u;

     u <<= 1;
     if(i & 0x80)
       crc ^= u;

     u = v;
     if(i & 0x01)
       crc ^= u;

     u <<= 1;
     if(i & 0x02)
       crc ^= u;


   }

 crc^= crcxor;
 crc&= crcmask;

 return(crc);
}

It's probably obvious how it works, so I won't bother explaining it. :).

Scott

--
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics

2003\01\24@111534 by o-8859-1?Q?Tony_K=FCbek?=

flavicon
face
Hi,

On Wed, 22 Jan 2003, Scott Dattalo wrote:
<snip>
>Continuing with the previous post...
>
>Here's a fairly optimized CRC-32 implementation suitable for a 32-bit
>processor. It's been structured so that a compiler can implement the
>algorithm with 4 registers (although I haven't looked at the assembly
code
>generated by a compiler).
<snip>
>It's probably obvious how it works, so I won't bother explaining it.
:).
>
>Scott

;) as always, the boolean exp. turned out pretty 'ugly' i must say,
I only had time for whipping up an unomptimized table based version
for the 18x series. 128 byte table, execute in around 80 cycles/byte+
one init and final xor / pass.

Call CRC_32_INIT first, then add bytes via W with CRC_32_ADD_W, after
complete message do final xor with CRC_32_DONE. If nessecary call
CRC_REFLECT.


I'll see if I get more time this weekend to dwell into your finalized
expression and/or optimized table routine.

Fun stuff.

/Tony

Note ignore UPPER pointer in table access, assumed cleared/not used.


CRC_32_INIT
       ; initialize crc
       MOVLW   0xFF
       MOVWF   CRC32
       MOVWF   CRC32+1
       MOVWF   CRC32+2
       MOVWF   CRC32+3
       RETURN
CRC_32_DONE
       ; do final xor for crc
       MOVLW   0xFF
       XORWF   CRC32,F
       XORWF   CRC32+1,F
       XORWF   CRC32+2,F
       XORWF   CRC32+3,F
       RETURN        
CRC32_REFLECT
       ; reflect intire crc, i.e. msbit>lsbit
       RLCF    CRC32,W        
       RRCF    CRC32+3,F        
       RLCF    CRC32,F
       RRCF    CRC32+3,F        
       RLCF    CRC32,F
       RRCF    CRC32+3,F        
       RLCF    CRC32,F
       RRCF    CRC32+3,F        
       RLCF    CRC32,F
       RRCF    CRC32+3,F        
       RLCF    CRC32,F
       RRCF    CRC32+3,F        
       RLCF    CRC32,F
       RRCF    CRC32+3,F        
       RLCF    CRC32,F
       RRCF    CRC32+3,F        
       RLCF    CRC32,F
       RRCF    CRC32+3,F        
       
       RLCF    CRC32+2,W
       RRCF    CRC32+1,F
       RLCF    CRC32+2,F
       RRCF    CRC32+1,F
       RLCF    CRC32+2,F
       RRCF    CRC32+1,F
       RLCF    CRC32+2,F
       RRCF    CRC32+1,F
       RLCF    CRC32+2,F
       RRCF    CRC32+1,F
       RLCF    CRC32+2,F
       RRCF    CRC32+1,F
       RLCF    CRC32+2,F
       RRCF    CRC32+1,F
       RLCF    CRC32+2,F
       RRCF    CRC32+1,F
       RLCF    CRC32+2,F
       RRCF    CRC32+1,F
       RETURN
       
CRC_32_ADD_W        
       XORWF   CRC32+3,W       ; do xor with lowest byte
       MOVWF   Index    ; save
       ; Index nibbles labelled as i2:i1

       ; now, knowing the indexes we can
       ; by investigating the formula for the output
       ; we can conclude the following output:
       ; CRC32   = Tab1[i<<2] XOR Tab2[i2>>2]
       ; CRC32+1 = CRC32 XOR Tab1[i<<2]+1 XOR Tab2[i2>>2]+1
       ; CRC32+2 = CRC32+1 XOR Tab1[i<<2]+2 XOR Tab2[i2>>2]+2
     ; CRC32+3 = CRC32+2 XOR Tab1[i<<2]+3 XOR Tab2[i2>>2]+3

       ; swap bytes in the crc32 ( crc32 = crc32>>8 )
       MOVFF   CRC32+2,CRC32+3
       MOVFF   CRC32+1,CRC32+2
       MOVFF   CRC32,CRC32+1
       CLRF    CRC32

       MOVLW   HIGH(CRC32_NIBBLE_TABLE);
       MOVWF   TBLPTRH         ; setup high adress
       MOVLW   LOW(CRC32_NIBBLE_TABLE) ;
       MOVWF   TBLPTRL ; set low adress
       ; now we need to access the first nibble table
       ; and since it's 4 byte wide we must multiply with 4         RLCF    Index,W         ; w= i1>>1 (lowest bit unknow)
       ADDWF   WREG,W          ; w=i1>>1+i1>>1=i1>>2 (lowest two bits
unknown)
       ANDLW   b'00111100'     ; mask out unwanted bits                 ; add to table pointer
       ADDWF   TBLPTRL,F
       ; propagate eventual carry
       BTFSC   STATUS,C
       INCF    TBLPTRH,F       ; propagate the carry

       ; calculate number of bytes to tab2
       COMF    WREG,W
       ANDLW   b'00111100'     ; mask out unwanted bits                 MOVWF   Index2          ; save for index 2 access
       ; read table and xor with crc
       TBLRD*+
       MOVF    TABLAT,W
       XORWF   CRC32,F
       TBLRD*+
       MOVF    TABLAT,W
       XORWF   CRC32+1,F
       TBLRD*+
       MOVF    TABLAT,W
       XORWF   CRC32+2,F
       TBLRD*+
       MOVF    TABLAT,W
       XORWF   CRC32+3,F
       ; prepare index 2 access
       RRCF    Index,F
       RRCF    Index,W ; w = i2>>2 (highest two bits unknown)
       ANDLW   b'00111100'     ; mask out unwanted bits                 ADDWF   Index2,W        ; add offset from tab1 access

       ; add to table pointer
       ADDWF   TBLPTRL,F
       ; propagate eventual carry
       BTFSC   STATUS,C
       INCF    TBLPTRH,F       ; propagate the carry
       ; read table and xor with crc
       TBLRD*+
       MOVF    TABLAT,W
       XORWF   CRC32,F
       TBLRD*+
       MOVF    TABLAT,W
       XORWF   CRC32+1,F
       TBLRD*+
       MOVF    TABLAT,W
       XORWF   CRC32+2,F
       TBLRD*+
       MOVF    TABLAT,W
       XORWF   CRC32+3,F
               
       RETURN
                       
       
CRC32_NIBBLE_TABLE
; table 1
       DB 0x00,0x00,0x00,0x00          DB 0x77,0x07,0x30,0x96          DB 0xee,0x0e,0x61,0x2c          DB 0x99,0x09,0x51,0xba          DB 0x07,0x6d,0xc4,0x19          DB 0x70,0x6a,0xf4,0x8f          DB 0xe9,0x63,0xa5,0x35          DB 0x9e,0x64,0x95,0xa3          DB 0x0e,0xdb,0x88,0x32          DB 0x79,0xdc,0xb8,0xa4          DB 0xe0,0xd5,0xe9,0x1e          DB 0x97,0xd2,0xd9,0x88          DB 0x09,0xb6,0x4c,0x2b          DB 0x7e,0xb1,0x7c,0xbd          DB 0xe7,0xb8,0x2d,0x07          DB 0x90,0xbf,0x1d,0x91  ; table 2
       DB 0x00,0x00,0x00,0x00          DB 0x1d,0xb7,0x10,0x64          DB 0x3b,0x6e,0x20,0xc8          DB 0x26,0xd9,0x30,0xac          DB 0x76,0xdc,0x41,0x90          DB 0x6b,0x6b,0x51,0xf4          DB 0x4d,0xb2,0x61,0x58          DB 0x50,0x05,0x71,0x3c          DB 0xed,0xb8,0x83,0x20          DB 0xf0,0x0f,0x93,0x44          DB 0xd6,0xd6,0xa3,0xe8          DB 0xcb,0x61,0xb3,0x8c          DB 0x9b,0x64,0xc2,0xb0          DB 0x86,0xd3,0xd2,0xd4          DB 0xa0,0x0a,0xe2,0x78          DB 0xbd,0xbd,0xf2,0x1c  
       

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

2003\01\24@111545 by o-8859-1?Q?Tony_K=FCbek?=

flavicon
face
Hi again,
my last message contained some code which I forgot to add is *not*
tested,
I belive it should work but there might be some typos or similar.

Sorry about that,

/Tony

--
http://www.piclist.com hint: The PICList is archived three different
ways.  See http://www.piclist.com/#archives for details.

2003\01\25@140114 by Scott Dattalo
face
flavicon
face
On Fri, 24 Jan 2003, Tony K|bek wrote:

> Hi,
>
> On Wed, 22 Jan 2003, Scott Dattalo wrote:
> <snip>
> >Continuing with the previous post...
> >
> >Here's a fairly optimized CRC-32 implementation suitable for a 32-bit
> >processor. It's been structured so that a compiler can implement the
> >algorithm with 4 registers (although I haven't looked at the assembly
> code
> >generated by a compiler).
> <snip>
> >It's probably obvious how it works, so I won't bother explaining it.
> :).
> >
> >Scott
>
> ;) as always, the boolean exp. turned out pretty 'ugly' i must say,

Yeah, it sure is...

Okay, my turn:

http://www.dattalo.com/technical/software/pic/crc_32.asm

There are two implementations for the 18F. One is 94 instructions long and
takes between 35 and 85 cycles. The other is 76 instructions and 76
cycles.

Scott

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email TakeThisOuTlistservEraseMEspamspam_OUTmitvma.mit.edu with SET PICList DIGEST in the body

2003\01\27@163902 by o-8859-1?Q?Tony_K=FCbek?=

flavicon
face
Hi,
Scott Dattalo wrote:

>Yeah, it sure is...
>Okay, my turn:
>http://www.dattalo.com/technical/software/pic/crc_32.asm
>
>There are two implementations for the 18F. One is 94 instructions long
and
>takes between 35 and 85 cycles. The other is 76 instructions and 76
>cycles.

Hmm.. I lacked the insigtfullness to compact the tables into the smaller
one, but it's never to late to learn. My boolean exp. was so ugly that i
didn't see
the trees beacuse of the forest :). Anyway I haven't come up with
anything
faster than yours I only jotted down the table based version but with a
shorter
table. Goes around 93-168 instructions executed but will take less
program memory.
If the table is aligned something around 16 instr. can be shaved off in
best case.
That would be something around 77-168 instructions executed instead.

I think the full (128 bytes) table version should be possible to take
down to around
70'ish(fixed) instruction but as one still has the table I see no gain
in that, your 76 cycle
version seems to be the best sofar.


/Tony

*untested* and ignores upper table pointer (assumed cleared/not used).


CRC_32_W_Short
       GLOBAL  CRC_32_W_Short
       XORWF   CRC32+3,W       ; do xor with lowest byte
       MOVWF   Index    ; save
       ; swap bytes in the crc32 ( crc32 =3D crc32>>8 )
       MOVFF   CRC32+2,CRC32+3
       MOVFF   CRC32+1,CRC32+2
       MOVFF   CRC32,CRC32+1
       CLRF    CRC32
       ; setup table pointer
       MOVLW   HIGH(CRC32_NIBBLE_TABLE_SHORT);
       MOVWF   TBLPTRH         ; setup high adress
       MOVLW   LOW(CRC32_NIBBLE_TABLE_SHORT)   ;
       MOVWF   TBLPTRL ; set low adress
CRC_32_W_LOOP
       RRCF    Index,F ; rotate lowest bit into carry
       BC      CRC_32_W_LOOP_XOR       ; bit set=do xor

       ; skip xor as bit is not set
       ; advance TBLPTRL by 4 bytes
       MOVLW   D'4'
       ADDWF   TBLPTRL,F
       BTFSC   STATUS,C
       INCF    TBLPTRH,F
       BRA     CRC_32_W_LOOP_SKP   ; do next bit
CRC_32_W_LOOP_XOR
       TBLRD*+
       MOVF    TABLAT,W
       XORWF   CRC32,F
       TBLRD*+
       MOVF    TABLAT,W
       XORWF   CRC32+1,F
       TBLRD*+
       MOVF    TABLAT,W
       XORWF   CRC32+2,F
       TBLRD*+
       MOVF    TABLAT,W
       XORWF   CRC32+3,F
CRC_32_W_LOOP_SKP              
       MOVLW   LOW(CRC32_NIBBLE_TABLE_SHORT_END)
       XORWF   TBLPTRL,W
       BNZ     CRC_32_W_LOOP
       ; all done
       RETURN

CRC32_NIBBLE_TABLE_SHORT
       DB   0x77,0x07,0x30,0x96
       DB   0xee,0x0e,0x61,0x2c
       DB   0x07,0x6d,0xc4,0x19
       DB   0x0e,0xdb,0x88,0x32
       DB   0x1d,0xb7,0x10,0x64
       DB   0x3b,0x6e,0x20,0xc8
       DB   0x76,0xdc,0x41,0x90
       DB   0xed,0xb8,0x83,0x20
CRC32_NIBBLE_TABLE_SHORT_END

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

More... (looser matching)
- Last day of these posts
- In 2003 , 2004 only
- Today
- New search...