lm32_lcc.asm 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. ;===========================================================================
  2. ; Copyright (c) 1990-1999 Info-ZIP. All rights reserved.
  3. ;
  4. ; See the accompanying file LICENSE, version 1999-Oct-05 or later
  5. ; (the contents of which are also included in zip.h) for terms of use.
  6. ; If, for some reason, both of these files are missing, the Info-ZIP license
  7. ; also may be found at: ftp://ftp.cdrom.com/pub/infozip/license.html
  8. ;===========================================================================
  9. ; match32.asm by Jean-loup Gailly.
  10. ; match32.asm, optimized version of longest_match() in deflate.c
  11. ; To be used only with 32 bit flat model. To simplify the code, the option
  12. ; -DDYN_ALLOC is not supported.
  13. ; This file is only optional. If you don't have an assembler, use the
  14. ; C version (add -DNO_ASM to CFLAGS in makefile and remove match.o
  15. ; from OBJI). If you have reduced WSIZE in zip.h, then make sure this is
  16. ; assembled with an equivalent -DWSIZE=<whatever>.
  17. ;
  18. ; Win32 (Windows NT) version - 1994/04/13 by Steve Salisbury
  19. ; * works with Microsoft MASM 6.1X and Microsoft Visual C++ / 32-bit edition
  20. ;
  21. ; The code in this file has been copied verbatim from match32.{asm|S};
  22. ; only the assembler syntax and metacommands have been adapted to
  23. ; the habits of the free LCC-Win32 C compiler package.
  24. ; IMPORTANT NOTE to the Info-ZIP editors:
  25. ; The TAB characters in this source file are required by the parser of
  26. ; the LCC-Win32 assembler program and MUST NOT be removed!!
  27. ;
  28. ;==============================================================================
  29. ;
  30. ; Do NOT assemble this source if external crc32 routine from zlib gets used.
  31. ;
  32. ;/* This version is for 386 Unix or OS/2 in 32 bit mode.
  33. ; * Warning: it uses the AT&T syntax: mov source,dest
  34. ; * This file is only optional. If you want to force the C version,
  35. ; * add -DNO_ASM to CFLAGS in Makefile and set OBJA to an empty string.
  36. ; * If you have reduced WSIZE in (g)zip.h, then make sure this is
  37. ; * assembled with an equivalent -DWSIZE=<whatever>.
  38. ; * This version assumes static allocation of the arrays (-DDYN_ALLOC not used).
  39. ; */
  40. .text
  41. .file "match.S"
  42. .text
  43. .type _match_init,function
  44. _match_init:
  45. ret
  46. _$98:
  47. .size _match_init,_$98-_match_init
  48. .globl _match_init
  49. ;/*-----------------------------------------------------------------------
  50. ; * Set match_start to the longest match starting at the given string and
  51. ; * return its length. Matches shorter or equal to prev_length are discarded,
  52. ; * in which case the result is equal to prev_length and match_start is
  53. ; * garbage.
  54. ; * IN assertions: cur_match is the head of the hash chain for the current
  55. ; * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1
  56. ; */
  57. .align 4
  58. .type _longest_match,function
  59. _longest_match: ;/* int longest_match(cur_match) */
  60. ; cur_match equ 20(%esp)
  61. ; /* return address */ /* esp+16 */
  62. push %ebp
  63. push %edi
  64. ;/* esp+8 */
  65. push %esi
  66. ;/* esp+4 */
  67. push %ebx
  68. ;/* esp */
  69. ;/*
  70. ; * match equ esi
  71. ; * scan equ edi
  72. ; * chain_length equ ebp
  73. ; * best_len equ ebx
  74. ; * limit equ edx
  75. ; */
  76. mov 20(%esp),%esi
  77. mov _strstart,%edx
  78. mov _max_chain_length,%ebp
  79. mov %edx,%edi
  80. sub $(32768-262),%edx
  81. cld
  82. jae limit_ok
  83. sub %edx,%edx
  84. limit_ok:
  85. add $2+_window,%edi
  86. mov _prev_length,%ebx
  87. movw -2(%edi),%cx
  88. movw -3(%ebx,%edi),%ax
  89. cmp _good_match,%ebx
  90. jb do_scan
  91. shr $2,%ebp
  92. jmp do_scan
  93. .align 4
  94. long_loop:
  95. ;/* at this point, edi == scan+2, esi == cur_match */
  96. movw -3(%ebx,%edi),%ax
  97. movw -2(%edi),%cx
  98. short_loop:
  99. ;/*
  100. ; * at this point, di == scan+2, si == cur_match,
  101. ; * ax = scan[best_len-1..best_len] and cx = scan[0..1]
  102. ; */
  103. and $(32768-1), %esi
  104. dec %ebp
  105. movw _prev(,%esi,2),%si
  106. jz the_end
  107. cmp %edx,%esi
  108. jbe the_end
  109. do_scan:
  110. cmpw _window-1(%ebx,%esi),%ax
  111. jne short_loop
  112. cmpw _window(%esi),%cx
  113. jne short_loop
  114. add $2+_window,%esi
  115. mov $((258>>1)-1),%ecx
  116. mov %edi,%eax
  117. repe; cmpsw
  118. ;/* loop until mismatch */
  119. je maxmatch
  120. ;/* match of length MAX_MATCH? */
  121. mismatch:
  122. movb -2(%edi),%cl
  123. xchg %edi,%eax
  124. subb -2(%esi),%cl
  125. sub %edi,%eax
  126. sub $2+_window,%esi
  127. sub %eax,%esi
  128. subb $1,%cl
  129. adc $0,%eax
  130. cmp %ebx,%eax
  131. jle long_loop
  132. mov %esi,_match_start
  133. mov %eax,%ebx
  134. cmp _nice_match,%eax
  135. ; /* len >= nice_match ? */
  136. jl long_loop
  137. the_end:
  138. mov %ebx,%eax
  139. pop %ebx
  140. pop %esi
  141. pop %edi
  142. pop %ebp
  143. ret
  144. .align 4
  145. maxmatch:
  146. cmpsb
  147. jmp mismatch
  148. _$99:
  149. .size _longest_match,_$99-_longest_match
  150. .globl _longest_match
  151. .extern _nice_match
  152. .extern _good_match
  153. .extern _max_chain_length
  154. .extern _match_start
  155. .extern _strstart
  156. .extern _prev_length
  157. .extern _prev
  158. .extern _window