File: crc_68.a

package info (click to toggle)
unzip 5.40-1
  • links: PTS
  • area: non-free
  • in suites: potato
  • size: 4,120 kB
  • ctags: 5,900
  • sloc: ansic: 40,977; cpp: 3,778; makefile: 1,384; asm: 1,228; sh: 133
file content (136 lines) | stat: -rw-r--r-- 3,790 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
; Not copyrighted by Paul Kienitz, last modified 04 Jan 96.
;
; Return an updated 32 bit CRC value, given the old value and a block of data.
; The CRC table used to compute the value is gotten by calling get_crc_table().
; This replaces the older updcrc() function used in Zip and fUnZip.  The
; prototype of the function is:
;
;    ulg crc32(ulg crcval, uch *text, extent textlen);
;
; On the Amiga, type extent is always unsigned long, not unsigned int, because
; int can be short or long at whim, but size_t is long.
;
; If using this source on a non-Amiga 680x0 system, note that we treat
; a0/a1/d0/d1 as scratch registers not preserved across function calls.
; We do not bother to support registerized arguments for crc32() -- the
; textlen parm is usually large enough so that savings outside the loop
; are pointless.
;
; Define NO_UNROLLED_LOOPS to use a simple short loop which might be more
; efficient on certain machines with dinky instruction caches ('020?), or for
; processing short strings.  If loops are unrolled, the textlen parm must be
; less than 512K; if not unrolled, it must be less than 64K.

        xdef    _crc32          ; (ulg val, uch *buf, extent bufsize)

DO_CRC0 MACRO
        moveq  #0,ltemp
        move.b (textbuf)+,ltemp
        eor.b  crcval,ltemp
        lsl.w  #2,ltemp
        move.l (crc_table,ltemp.w),ltemp
        lsr.l  #8,crcval
        eor.l  ltemp,crcval
        ENDM

        machine mc68020

DO_CRC2 MACRO
        move.b (textbuf)+,btemp
        eor.b  crcval,btemp
        lsr.l  #8,crcval
        move.l (crc_table,btemp.w*4),ltemp
        eor.l  ltemp,crcval
        ENDM

crc_table       equr    a0      array of unsigned long
crcval          equr    d0      unsigned long initial value
textbuf         equr    a1      array of unsigned char
textbufsize     equr    d1      unsigned long (count of bytes in textbuf)
btemp           equr    d2
ltemp           equr    d3


        xref    _get_crc_table  ; ulg *get_crc_table(void)

        NOLIST
        INCLUDE 'exec/execbase.i'
        LIST
        xref    _SysBase        ; struct ExecBase *


_crc32:
        move.l  8(sp),d0
        bne.s   valid
         moveq  #0,d0
         rts
valid:  movem.l btemp/ltemp,-(sp)
        jsr     _get_crc_table
        move.l  d0,ltemp
        move.l  12(sp),crcval
        move.l  16(sp),textbuf
        move.l  20(sp),textbufsize
        not.l   crcval
        move.l  _SysBase,crc_table
        move.w  AttnFlags(crc_table),btemp
        move.l  ltemp,crc_table
        btst    #AFB_68020,btemp
        bne     twenty

    IFD     NO_UNROLLED_LOOPS

        bra.s   decr
loop:    DO_CRC0
decr:    dbra   textbufsize,loop
        bra.s   done

twenty: moveq   #0,btemp
        bra.s   decr2
loop2:   DO_CRC2
decr2:   dbra   textbufsize,loop2

    ELSE    ; !NO_UNROLLED_LOOPS

        move.l  textbufsize,btemp
        lsr.l   #3,textbufsize
        bra     decr8
loop8:   DO_CRC0
         DO_CRC0
         DO_CRC0
         DO_CRC0
         DO_CRC0
         DO_CRC0
         DO_CRC0
         DO_CRC0
decr8:   dbra   textbufsize,loop8
        and.w   #7,btemp
        bra.s   decr1
loop1:   DO_CRC0
decr1:   dbra   btemp,loop1
        bra     done

twenty: moveq   #0,btemp
        move.l  textbufsize,-(sp)
        lsr.l   #3,textbufsize
        bra     decr82
loop82:  DO_CRC2
         DO_CRC2
         DO_CRC2
         DO_CRC2
         DO_CRC2
         DO_CRC2
         DO_CRC2
         DO_CRC2
decr82:  dbra   textbufsize,loop82
        move.l  (sp)+,textbufsize
        and.w   #7,textbufsize
        bra.s   decr12
loop12:  DO_CRC2
decr12:  dbra   textbufsize,loop12

    ENDC    ; ?NO_UNROLLED_LOOPS

done:   movem.l (sp)+,btemp/ltemp
        not.l   crcval
;;;;;   move.l  crcval,d0               ; crcval already is d0
        rts