home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / unzip531.zip / amiga / crc_68.a < prev    next >
Text File  |  1996-09-14  |  4KB  |  137 lines

  1. ; Not copyrighted by Paul Kienitz, last modified 04 Jan 96.
  2. ;
  3. ; Return an updated 32 bit CRC value, given the old value and a block of data.
  4. ; The CRC table used to compute the value is gotten by calling get_crc_table().
  5. ; This replaces the older updcrc() function used in Zip and fUnZip.  The
  6. ; prototype of the function is:
  7. ;
  8. ;    ulg crc32(ulg crcval, uch *text, extent textlen);
  9. ;
  10. ; On the Amiga, type extent is always unsigned long, not unsigned int, because
  11. ; int can be short or long at whim, but size_t is long.
  12. ;
  13. ; If using this source on a non-Amiga 680x0 system, note that we treat
  14. ; a0/a1/d0/d1 as scratch registers not preserved across function calls.
  15. ; We do not bother to support registerized arguments for crc32() -- the
  16. ; textlen parm is usually large enough so that savings outside the loop
  17. ; are pointless.
  18. ;
  19. ; Define NO_UNROLLED_LOOPS to use a simple short loop which might be more
  20. ; efficient on certain machines with dinky instruction caches ('020?), or for
  21. ; processing short strings.  If loops are unrolled, the textlen parm must be
  22. ; less than 512K; if not unrolled, it must be less than 64K.
  23.  
  24.         xdef    _crc32          ; (ulg val, uch *buf, extent bufsize)
  25.  
  26. DO_CRC0 MACRO
  27.         moveq  #0,ltemp
  28.         move.b (textbuf)+,ltemp
  29.         eor.b  crcval,ltemp
  30.         lsl.w  #2,ltemp
  31.         move.l (crc_table,ltemp.w),ltemp
  32.         lsr.l  #8,crcval
  33.         eor.l  ltemp,crcval
  34.         ENDM
  35.  
  36.         machine mc68020
  37.  
  38. DO_CRC2 MACRO
  39.         move.b (textbuf)+,btemp
  40.         eor.b  crcval,btemp
  41.         lsr.l  #8,crcval
  42.         move.l (crc_table,btemp.w*4),ltemp
  43.         eor.l  ltemp,crcval
  44.         ENDM
  45.  
  46. crc_table       equr    a0      array of unsigned long
  47. crcval          equr    d0      unsigned long initial value
  48. textbuf         equr    a1      array of unsigned char
  49. textbufsize     equr    d1      unsigned long (count of bytes in textbuf)
  50. btemp           equr    d2
  51. ltemp           equr    d3
  52.  
  53.  
  54.         xref    _get_crc_table  ; ulg *get_crc_table(void)
  55.  
  56.         NOLIST
  57.         INCLUDE 'exec/execbase.i'
  58.         LIST
  59.         xref    _SysBase        ; struct ExecBase *
  60.  
  61.  
  62. _crc32:
  63.         move.l  8(sp),d0
  64.         bne.s   valid
  65.          moveq  #0,d0
  66.          rts
  67. valid:  movem.l btemp/ltemp,-(sp)
  68.         jsr     _get_crc_table
  69.         move.l  d0,ltemp
  70.         move.l  12(sp),crcval
  71.         move.l  16(sp),textbuf
  72.         move.l  20(sp),textbufsize
  73.         not.l   crcval
  74.         move.l  _SysBase,crc_table
  75.         move.w  AttnFlags(crc_table),btemp
  76.         move.l  ltemp,crc_table
  77.         btst    #AFB_68020,btemp
  78.         bne     twenty
  79.  
  80.     IFD     NO_UNROLLED_LOOPS
  81.  
  82.         bra.s   decr
  83. loop:    DO_CRC0
  84. decr:    dbra   textbufsize,loop
  85.         bra.s   done
  86.  
  87. twenty: moveq   #0,btemp
  88.         bra.s   decr2
  89. loop2:   DO_CRC2
  90. decr2:   dbra   textbufsize,loop2
  91.  
  92.     ELSE    ; !NO_UNROLLED_LOOPS
  93.  
  94.         move.l  textbufsize,btemp
  95.         lsr.l   #3,textbufsize
  96.         bra     decr8
  97. loop8:   DO_CRC0
  98.          DO_CRC0
  99.          DO_CRC0
  100.          DO_CRC0
  101.          DO_CRC0
  102.          DO_CRC0
  103.          DO_CRC0
  104.          DO_CRC0
  105. decr8:   dbra   textbufsize,loop8
  106.         and.w   #7,btemp
  107.         bra.s   decr1
  108. loop1:   DO_CRC0
  109. decr1:   dbra   btemp,loop1
  110.         bra     done
  111.  
  112. twenty: moveq   #0,btemp
  113.         move.l  textbufsize,-(sp)
  114.         lsr.l   #3,textbufsize
  115.         bra     decr82
  116. loop82:  DO_CRC2
  117.          DO_CRC2
  118.          DO_CRC2
  119.          DO_CRC2
  120.          DO_CRC2
  121.          DO_CRC2
  122.          DO_CRC2
  123.          DO_CRC2
  124. decr82:  dbra   textbufsize,loop82
  125.         move.l  (sp)+,textbufsize
  126.         and.w   #7,textbufsize
  127.         bra.s   decr12
  128. loop12:  DO_CRC2
  129. decr12:  dbra   textbufsize,loop12
  130.  
  131.     ENDC    ; ?NO_UNROLLED_LOOPS
  132.  
  133. done:   movem.l (sp)+,btemp/ltemp
  134.         not.l   crcval
  135. ;;;;;   move.l  crcval,d0               ; crcval already is d0
  136.         rts
  137.