I'm asking if there any already existing CRC32 source code in 68000.

(I haven't take enough time ATM to consider the question

See you,
Moderators: simonsunnyboy, Mug UK, Zorro 2, Moderator Team
It's full of linefeeds! What it lacks is carriage returnsmuguk wrote:You might need to convert it to ST format text as Amiga text doesn't feature proper linefeeds.
There is a lot to tell about CRC coding on the 68000. There is small code, fast code and everything in between. Here some simple code. It first generates a CRC table on the stack and then calculates the CRC32 of the memory block.Maartau wrote:I'm asking if there any already existing CRC32 source code in 68000.![]()
Code: Select all
;
; ARJ CRC function
; Size optimized
; Copyleft 1993 Mr Ni! (the Great) of the TOS-crew
;
; ulong crc_buf(char *str, ulong len)
;
; CALL:
; D0 = #bytes (long)
; A0 = buffer
;
; Return:
; D0 = CRC-code
;
; uses 1kB buffer on stack
;
crc_buf:
move.l d3,-(sp)
move.l d0,-(sp)
lea (sp),a1
lea -1024(sp),sp
moveq #0,d0
subq.b #1,d0
move.l #$EDB88320,d2
.loop_0:
moveq #7,d3
move.l d0,d1
.loop_1:
lsr.l #1,d1
bcc.s .next
eor.l d2,d1
.next:
dbra d3,.loop_1
move.l d1,-(a1)
dbra d0,.loop_0
move.l 1024(sp),d0
moveq #-1,d1
.crc_loop:
moveq #0,d2
move.b (a0)+,d2
eor.b d1,d2
lsr.l #8,d1
lsl.w #2,d2
move.l 0(a1,d2.w),d2
eor.l d2,d1
subq.l #1,d0
bne.s .crc_loop
lea 1028(sp),sp
not.l d1
move.l d1,d0
move.l (sp)+,d3
rts
;d0,d1,d2,d3,d4,d5,d6,d7,a0,a1,a2,a3,a4,a5,a6,a7,sp
*******************************************************************************
END
Better yet, throw it immediately in the trash can. What an ugly piece of code! I suspect it was generated by a 32 bit C compiler. It uses 32 bit operators even though it only needs the LSB. Wasting a lot of CPU cycles in the middle of a CRC32 loop. :-Smuguk wrote:http://ftp.urz.uni-heidelberg.de/ftp/pub/amiga/dev/asm/
Filename: CRC32.LHA
You might need to convert it to ST format text as Amiga text doesn't feature proper linefeeds.
Code: Select all
crc16= X^16 + X^15 + X^2 + 1
This is thae standard CRC poly. The representation is: 0xA001.Maartau wrote:My next question is about CRC 16:
How can I convert this to 68000?Code: Select all
crc16= X^16 + X^15 + X^2 + 1
Code: Select all
/************************************************************************
**************** LHA CRC *********************
************************************************************************/
/*
* uint16 crc16(const uint8 *str, long len, uint16 crc, const uint16 *crc_table)
*
* Calculate the CRC of a buffer.
*
* Parameters:
*
* str - pointer to buffer.
* len - length of buffer.
* crc - crc start value.
* crc_table - pointer to crc table.
*
* Result: CRC of buffer.
*/
#define NLIT 256
uint16 crc16(const uint8 * str, long len, uint16 crc,
const uint16 * crc_table)
{
do
{
uint8 kar = *str++;
kar ^= (uint8) crc;
crc >>= 8;
crc ^= crc_table[kar];
}
while (--len != 0);
return crc;
}
uint16 lha_init_crc(void)
{
return 0;
}
void free_crc16_table(uint16 * table)
{
if (table != NULL)
{
free(table);
}
}
/*
* uint16 *make_crc16_table(uint16 crc_poly)
*
* Initialize the CRC table used by the buf_crc() function.
*
* Result: NULL if out of memory, pointer to crc table otherwise.
*/
uint16 *make_crc16_table(uint16 crc_poly)
{
uint16 *crc_table;
if ((crc_table = malloc(NLIT * sizeof(uint16))) != NULL)
{
uint16 kar;
kar = NLIT - 1;
do
{
int i = 7;
uint16 crc = kar;
do
{
if (crc & 1)
{
crc >>= 1;
crc ^= crc_poly;
}
else
{
crc >>= 1;
}
}
while (i-- != 0);
crc_table[kar] = crc;
}
while (kar-- != 0);
}
return crc_table;
}
Code: Select all
crc16_buf:
move.l d3,-(sp)
move.w d0,-(sp)
lea (sp),a1
lea -512(sp),sp
moveq #0,d0
subq.b #1,d0
move.w #$A001,d2
.loop_0:
moveq #7,d3
move.w d0,d1
.loop_1:
lsr.w #1,d1
bcc.s .next
eor.w d2,d1
.next:
dbra d3,.loop_1
move.w d1,-(a1)
dbra d0,.loop_0
move.w 512(sp),d0
moveq #-1,d1
.crc_loop:
moveq #0,d2
move.b (a0)+,d2
eor.b d1,d2
lsr.w #8,d1
add.w d2,d2
move.w 0(a1,d2.w),d2
eor.w d2,d1
subq.l #1,d0
bne.s .crc_loop
lea 514(sp),sp
not.w d1
move.w d1,d0
move.l (sp)+,d3
rts
I almost forgot:Maartau wrote:"I'll do my own tests using your code"...
Code: Select all
moveq #-1,d1
I only needed CRC 32 for checking some datas... The 16 was just for my "curiousity"...Nyh wrote:I don't know why you need both 16 and 32 bit CRC routines.
Hans Wessels
All code always welcomeDio wrote:I've found Fletcher-16 (closely related to Zip's 'CRC') is a pretty good compromise between accuracy and performance and very easily implemented on 68k. I've got some code for that if you'd like?
Code: Select all
; This implements Fletcher-16 (sum 16-bit words mod 65535)
; It's not a 'fast' implementation of the algorithm, but the access to the
; carry flag makes that less important
; There's two entrypoints, for adding 32 and 16 bits
; Input is d0, checksum is the two words at (a0)
checksum32:
move.l d0,d2
add.w (a0), d0
bcc cs1
addq.w #1,d0
cs1: move.w d0,d1
add.w 2(a0),d1
bcc cs2
addq.w #1,d1
cs2:
swap d2
add.w d2,d0
bcc cs3
addq.w #1,d0
cs3: add.w d0,d1
bcc cs4
addq.w #1,d1
cs4: move.w d0,(a0)
move.w d1,2(a0)
rts
checksum16:
add.w (a0), d0
bcc cs1a
addq.w #1,d0
cs1a: move.w d0,d1
add.w 2(a0),d1
bcc cs2a
addq.w #1,d1
cs2a: move.w d0,(a0)
move.w d1,2(a0)
rts
Many thanks (Dio wrote:Righty-ho then.
Why this implementation?Dio wrote:Righty-ho then.