crc_68.a 4.2 KB

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