home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / zip21.zip / human68k / match.s < prev    next >
Text File  |  1996-04-01  |  4KB  |  155 lines

  1. * match.s -- optional optimized asm version of longest match in deflate.c
  2. * Copyright (C) 1992-1993 Jean-loup Gailly
  3. *
  4. * Adapted for X68000 by NIIMI Satoshi <a01309@cfi.waseda.ac.jp>
  5. * Adapted for the Amiga by Carsten Steger <stegerc@informatik.tu-muenchen.de>
  6. * using the code in match.S.
  7. * The major change in this code consists of removing all unaligned
  8. * word accesses, because they cause 68000-based machines to crash.
  9. * For maximum speed, UNALIGNED_OK can be defined.
  10. * The program will then only run on 68020-based machines, though.
  11.  
  12.  
  13. Cur_Match       reg     d0      ; Must be in d0!
  14. Best_Len        reg     d1
  15. Loop_Counter    reg     d2
  16. Scan_Start      reg     d3
  17. Scan_End        reg     d4
  18. Limit           reg     d5
  19. Chain_Length    reg     d6
  20. Scan_Test       reg     d7
  21. Scan            reg     a0
  22. Match           reg     a1
  23. Prev_Address    reg     a2
  24. Scan_Ini        reg     a3
  25. Match_Ini       reg     a4
  26.  
  27. MAX_MATCH       equ     258
  28. MIN_MATCH       equ     3
  29. WSIZE           equ     32768
  30. MAX_DIST        equ     WSIZE-MAX_MATCH-MIN_MATCH-1
  31.  
  32.  
  33.         .xref   _max_chain_length
  34.         .xref   _prev_length
  35.         .xref   _prev
  36.         .xref   _window
  37.         .xref   _strstart
  38.         .xref   _good_match
  39.         .xref   _match_start
  40.         .xref   _nice_match
  41.  
  42.  
  43.         .xdef   _match_init
  44.         .xdef   _longest_match
  45.  
  46.         .text
  47.         .even
  48.  
  49.  
  50. _match_init:
  51.         rts
  52.  
  53.  
  54. _longest_match:
  55.         move.l  4(sp),Cur_Match
  56. .ifdef  UNALIGNED_OK
  57.         movem.l d2-d6/a2-a4,-(sp)
  58. .else
  59.         movem.l d2-d7/a2-a4,-(sp)
  60. .endif
  61.         move.l  _max_chain_length,Chain_Length
  62.         move.l  _prev_length,Best_Len
  63.         lea     _prev,Prev_Address
  64.         lea     _window+MIN_MATCH,Match_Ini
  65.         move.l  _strstart,Limit
  66.         move.l  Match_Ini,Scan_Ini
  67.         add.l   Limit,Scan_Ini
  68.         subi.w  #MAX_DIST,Limit
  69.         bhi.b   limit_ok
  70.         moveq   #0,Limit
  71. limit_ok:
  72.         cmp.l   _good_match,Best_Len
  73.         bcs.b   length_ok
  74.         lsr.l   #2,Chain_Length
  75. length_ok:
  76.         subq.l  #1,Chain_Length
  77.  
  78. .ifdef  UNALIGNED_OK
  79.         move.w  -MIN_MATCH(Scan_Ini),Scan_Start
  80.         move.w  -MIN_MATCH-1(Scan_Ini,Best_Len.w),Scan_End
  81. .else
  82.         move.b  -MIN_MATCH(Scan_Ini),Scan_Start
  83.         lsl.w   #8,Scan_Start
  84.         move.b  -MIN_MATCH+1(Scan_Ini),Scan_Start
  85.         move.b  -MIN_MATCH-1(Scan_Ini,Best_Len.w),Scan_End
  86.         lsl.w   #8,Scan_End
  87.         move.b  -MIN_MATCH(Scan_Ini,Best_Len.w),Scan_End
  88. .endif
  89.  
  90.         bra.b   do_scan
  91.  
  92. long_loop:
  93.  
  94. .ifdef  UNALIGNED_OK
  95.         move.w  -MIN_MATCH-1(Scan_Ini,Best_Len.w),Scan_End
  96. .else
  97.         move.b  -MIN_MATCH-1(Scan_Ini,Best_Len.w),Scan_End
  98.         lsl.w   #8,Scan_End
  99.         move.b  -MIN_MATCH(Scan_Ini,Best_Len.w),Scan_End
  100. .endif
  101.  
  102. short_loop:
  103.         lsl.w   #1,Cur_Match
  104.         move.w  0(Prev_Address,Cur_Match.l),Cur_Match
  105.         cmp.w   Limit,Cur_Match
  106.         dbls    Chain_Length,do_scan
  107.         bra.b   return
  108.  
  109. do_scan:
  110.         move.l  Match_Ini,Match
  111.         add.l   Cur_Match,Match
  112.  
  113. .ifdef  UNALIGNED_OK
  114.         cmp.w   -MIN_MATCH-1(Match,Best_Len.w),Scan_End
  115.         bne.b   short_loop
  116.         cmp.w   -MIN_MATCH(Match),Scan_Start
  117.         bne.b   short_loop
  118. .else
  119.         move.b  -MIN_MATCH-1(Match,Best_Len.w),Scan_Test
  120.         lsl.w   #8,Scan_Test
  121.         move.b  -MIN_MATCH(Match,Best_Len.w),Scan_Test
  122.         cmp.w   Scan_Test,Scan_End
  123.         bne.b   short_loop
  124.         move.b  -MIN_MATCH(Match),Scan_Test
  125.         lsl.w   #8,Scan_Test
  126.         move.b  -MIN_MATCH+1(Match),Scan_Test
  127.         cmp.w   Scan_Test,Scan_Start
  128.         bne.b   short_loop
  129. .endif
  130.  
  131.         move.w  #(MAX_MATCH-MIN_MATCH),Loop_Counter
  132.         move.l  Scan_Ini,Scan
  133. scan_loop:
  134.         cmpm.b  (Match)+,(Scan)+
  135.         dbne    Loop_Counter,scan_loop
  136.  
  137.         sub.l   Scan_Ini,Scan
  138.         addq.l  #(MIN_MATCH-1),Scan
  139.         cmp.l   Best_Len,Scan
  140.         bls.b   short_loop
  141.         move.l  Scan,Best_Len
  142.         move.l  Cur_Match,_match_start
  143.         cmp.l   _nice_match,Best_Len
  144.         bcs.b   long_loop
  145. return:
  146.         move.l  Best_Len,d0
  147. .ifdef  UNALIGNED_OK
  148.         movem.l (sp)+,d2-d6/a2-a4
  149. .else
  150.         movem.l (sp)+,d2-d7/a2-a4
  151. .endif
  152.         rts
  153.  
  154.         end
  155.