crc_68.s 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. ;
  32. ; 1999/09/23: for Human68k: Modified by Shimazaki Ryo.
  33. xdef _crc32 ; (ulg val, uch *buf, extent bufsize)
  34. DO_CRC0 MACRO
  35. moveq #0,ltemp
  36. move.b (textbuf)+,ltemp
  37. eor.b crcval,ltemp
  38. lsl.w #2,ltemp
  39. move.l (crc_table,ltemp.w),ltemp
  40. lsr.l #8,crcval
  41. eor.l ltemp,crcval
  42. ENDM
  43. DO_CRC2 MACRO
  44. move.b (textbuf)+,btemp
  45. eor.b crcval,btemp
  46. lsr.l #8,crcval
  47. move.l (crc_table,btemp.w*4),ltemp
  48. eor.l ltemp,crcval
  49. ENDM
  50. crc_table reg a0 array of unsigned long
  51. crcval reg d0 unsigned long initial value
  52. textbuf reg a1 array of unsigned char
  53. textbufsize reg d1 unsigned long (count of bytes in textbuf)
  54. btemp reg d2
  55. ltemp reg d3
  56. xref _get_crc_table ; ulg *get_crc_table(void)
  57. quad
  58. _crc32:
  59. move.l 8(sp),d0
  60. bne.s valid
  61. ;;;;; moveq #0,d0
  62. rts
  63. valid: movem.l btemp/ltemp,-(sp)
  64. jsr _get_crc_table
  65. movea.l d0,crc_table
  66. move.l 12(sp),crcval
  67. move.l 16(sp),textbuf
  68. move.l 20(sp),textbufsize
  69. not.l crcval
  70. ifdef NO_UNROLLED_LOOPS
  71. if CPU==68000
  72. bra.s decr
  73. loop: DO_CRC0
  74. decr: dbra textbufsize,loop
  75. bra.s done
  76. else
  77. twenty: moveq #0,btemp
  78. bra.s decr2
  79. loop2: DO_CRC2
  80. decr2: dbra textbufsize,loop2
  81. endif
  82. ELSE ; !NO_UNROLLED_LOOPS
  83. if CPU==68000
  84. moveq #7,btemp
  85. and textbufsize,btemp
  86. lsr.l #3,textbufsize
  87. bra decr8
  88. loop8: DO_CRC0
  89. DO_CRC0
  90. DO_CRC0
  91. DO_CRC0
  92. DO_CRC0
  93. DO_CRC0
  94. DO_CRC0
  95. DO_CRC0
  96. decr8: dbra textbufsize,loop8
  97. bra.s decr1
  98. loop1: DO_CRC0
  99. decr1: dbra btemp,loop1
  100. bra done
  101. else
  102. twenty: moveq #0,btemp
  103. move.l textbufsize,-(sp)
  104. lsr.l #3,textbufsize
  105. bra decr82
  106. quad
  107. loop82: DO_CRC2
  108. DO_CRC2
  109. DO_CRC2
  110. DO_CRC2
  111. DO_CRC2
  112. DO_CRC2
  113. DO_CRC2
  114. DO_CRC2
  115. decr82: dbra textbufsize,loop82
  116. moveq #7,textbufsize
  117. and.l (sp)+,textbufsize
  118. bra.s decr12
  119. loop12: DO_CRC2
  120. decr12: dbra textbufsize,loop12
  121. endif
  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