home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / zip201.zip / amiga / match.a < prev    next >
Text File  |  1993-09-01  |  4KB  |  172 lines

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