home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / zip22.zip / qdos / match.s < prev    next >
Text File  |  1996-12-14  |  3KB  |  131 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      equr     d0      ; Must be in d0!
  16. ;;Best_Len       equr     d1
  17. ;;Loop_Counter   equr     d2
  18. ;;Scan_Start     equr     d3
  19. ;;Scan_End       equr     d4
  20. ;;Limit          equr     d5
  21. ;;Chain_Length   equr     d6
  22. ;;Scan_Test      equr     d7
  23. ;;Scan           equr     a0
  24. ;;Match          equr     a1
  25. ;;Prev_Address   equr     a2
  26. ;;Scan_Ini       equr     a3
  27. ;;Match_Ini      equr     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.     .globl    _max_chain_length
  36.     .globl    _prev_length
  37.     .globl    _prev
  38.     .globl    _window
  39.     .globl    _strstart
  40.     .globl    _good_match
  41.     .globl    _match_start
  42.     .globl    _nice_match
  43.  
  44.     .text
  45.     .globl   _match_init
  46.     .globl   _longest_match
  47.  
  48. _match_init:
  49.         rts
  50.  
  51.  
  52. _longest_match:
  53.         move.l  4(sp),d0
  54.         movem.l d2-d7/a2-a4,-(sp)
  55.         move.l  _max_chain_length,d6
  56.         move.l  _prev_length,d1
  57.         lea     _prev,a2
  58.         lea     _window+MIN_MATCH,a4
  59.         move.l  _strstart,d5
  60.         move.l  a4,a3
  61.         add.l   d5,a3
  62.         subi.w  #MAX_DIST,d5
  63.         bhi     limit_ok
  64.         moveq   #0,d5
  65. limit_ok:
  66.         cmp.l   _good_match,d1
  67.         bcs     length_ok
  68.         lsr.l   #2,d6
  69. length_ok:
  70.         subq.l  #1,d6
  71.  
  72.         move.b  -MIN_MATCH(a3),d3
  73.         lsl.w   #8,d3
  74.         move.b  -MIN_MATCH+1(a3),d3
  75.         move.b  -MIN_MATCH-1(a3,d1),d4
  76.         lsl.w   #8,d4
  77.         move.b  -MIN_MATCH(a3,d1),d4
  78.  
  79.         bra     do_scan
  80.  
  81. long_loop:
  82.  
  83.         move.b  -MIN_MATCH-1(a3,d1),d4
  84.         lsl.w   #8,d4
  85.         move.b  -MIN_MATCH(a3,d1),d4
  86.  
  87. short_loop:
  88.         lsl.w   #1,d0
  89.         move.w  0(a2,d0.l),d0
  90.         cmp.w   d5,d0
  91.         dbls    d6,do_scan
  92.         bra     return
  93.  
  94. do_scan:
  95.         move.l  a4,a1
  96.         add.l   d0,a1
  97.  
  98.         move.b  -MIN_MATCH-1(a1,d1),d7
  99.         lsl.w   #8,d7
  100.         move.b  -MIN_MATCH(a1,d1),d7
  101.         cmp.w   d7,d4
  102.         bne     short_loop
  103.         move.b  -MIN_MATCH(a1),d7
  104.         lsl.w   #8,d7
  105.         move.b  -MIN_MATCH+1(a1),d7
  106.         cmp.w   d7,d3
  107.         bne     short_loop
  108.  
  109.         move.w  #(MAX_MATCH-MIN_MATCH),d2
  110.         move.l  a3,a0
  111.  
  112. scan_loop:
  113.         cmpm.b  (a1)+,(a0)+
  114.         dbne    d2,scan_loop
  115.  
  116.         sub.l   a3,a0
  117.         addq.l  #(MIN_MATCH-1),a0
  118.         cmp.l   d1,a0
  119.         bls     short_loop
  120.         move.l  a0,d1
  121.         move.l  d0,_match_start
  122.         cmp.l   _nice_match,d1
  123.         bcs     long_loop
  124. return:
  125.         move.l  d1,d0
  126.         movem.l (sp)+,d2-d7/a2-a4
  127.         rts
  128.         end
  129.  
  130.  
  131.