home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / zip22.zip / acorn / match.s < prev    next >
Text File  |  1996-12-14  |  5KB  |  218 lines

  1. ;
  2. ; Copyright (C) 1990-1996 Mark Adler, Richard B. Wales, Jean-loup Gailly,
  3. ; Onno van der Linden, Kai Uwe Rommel, Igor Mandrichenko, Sergio Monesi and
  4. ; Karl Davis.
  5. ; Permission is granted to any individual or institution to use, copy, or
  6. ; redistribute this software so long as all of the original files are included,
  7. ; that it is not sold for profit, and that this copyright notice is retained.
  8. ;
  9. ; match.s for ARM by Sergio Monesi.
  10.  
  11. r0 RN 0
  12. r1 RN 1
  13. r2 RN 2
  14. r3 RN 3
  15. r4 RN 4
  16. r5 RN 5
  17. r6 RN 6
  18. r7 RN 7
  19. r8 RN 8
  20. r9 RN 9
  21. sl RN 10
  22. fp RN 11
  23. ip RN 12
  24. sp RN 13
  25. lr RN 14
  26. pc RN 15
  27.  
  28. MAX_DIST   EQU  32506
  29. WMASK      EQU  32767
  30. MAX_MATCH  EQU  258
  31.  
  32.                 AREA    |C$$code|, CODE, READONLY
  33.  
  34.  
  35. ; r1 = chain_lenght
  36. ; r2 = scan
  37. ; r3 = match
  38. ; r4 = len (tmp)
  39. ; r5 = best_len
  40. ; r6 = limit
  41. ; r7 = strend
  42. ; r8 = scan_end1
  43. ; r9 = scan_end
  44. ; lr = window
  45. ; fp = prev
  46.  
  47. |__max_chain_length|
  48.         IMPORT  max_chain_length
  49.         DCD     max_chain_length
  50. |__window|
  51.         IMPORT  window
  52.         DCD     window
  53. |__prev|
  54.         IMPORT  prev
  55.         DCD     prev
  56. |__prev_length|
  57.         IMPORT  prev_length
  58.         DCD     prev_length
  59. |__strstart|
  60.         IMPORT  strstart
  61.         DCD     strstart
  62. |__good_match|
  63.         IMPORT  good_match
  64.         DCD     good_match
  65. |__nice_match|
  66.         IMPORT  nice_match
  67.         DCD     nice_match
  68. |__match_start|
  69.         IMPORT  match_start
  70.         DCD     match_start
  71.  
  72.         DCB     "longest_match"
  73.         DCB     &00,&00,&00
  74.         DCD     &ff000010
  75.  
  76.         EXPORT  longest_match
  77. longest_match
  78.         STMFD   sp!, {r4-r9,fp,lr}
  79.  
  80.         LDR     fp, [pc, #|__prev|-.-8]
  81.  
  82.         LDR     r1, [pc, #|__max_chain_length|-.-8]
  83.         LDR     r1, [r1]
  84.         LDR     lr, [pc, #|__window|-.-8]
  85.  
  86.         LDR     ip, [pc, #|__strstart|-.-8]
  87.         LDR     ip, [ip]
  88.         ADD     r2, lr, ip
  89.         LDR     r5, [pc, #|__prev_length|-.-8]
  90.         LDR     r5, [r5]
  91.         SUBS    ip, ip, #MAX_DIST-250       ; if r6 > MAX_DIST
  92.         SUBCSS  r6, ip, #250                ; r6 = r6 - MAXDIST
  93.         MOVLS   r6, #0                      ; else r6 = 0
  94.  
  95.         ADD     r7, r2, #MAX_MATCH-256
  96.         ADD     r7, r7, #256                ; r7 = r2 + MAX_MATCH (=258);
  97.  
  98.         SUB     ip, r5, #1
  99.         LDRB    r8, [r2, ip]
  100.         LDRB    r9, [r2, r5]
  101.  
  102.         LDR     ip, [pc, #|__good_match|-.-8]
  103.         LDR     ip, [ip]
  104.         CMP     r5, ip
  105.         MOVCS   r1, r1, LSR #2
  106.  
  107. cycle
  108.         ADD     r3, lr, r0
  109.  
  110.         LDRB    ip, [r3, r5]
  111.         CMP     ip, r9
  112.         BNE     cycle_end
  113.  
  114.         SUB     ip, r5, #1
  115.         LDRB    ip, [r3, ip]
  116.         CMP     ip, r8
  117.         BNE     cycle_end
  118.  
  119.         LDRB    ip, [r2]
  120.         LDRB    r4, [r3]
  121.         CMP     ip, r4
  122.         BNE     cycle_end
  123.  
  124.         LDRB    ip, [r3, #1]
  125.         LDRB    r4, [r2, #1]
  126.         CMP     ip, r4
  127.         BNE     cycle_end
  128.  
  129.         ADD     r2, r2, #2
  130.         ADD     r3, r3, #2
  131.  
  132. inn_cycle
  133.         LDRB    ip, [r2, #1]!
  134.         LDRB    r4, [r3, #1]!
  135.         CMP     ip, r4
  136.         BNE     exit_inn_cycle
  137.  
  138.         LDRB    ip, [r2, #1]!
  139.         LDRB    r4, [r3, #1]!
  140.         CMP     ip, r4
  141.         BNE     exit_inn_cycle
  142.  
  143.         LDRB    ip, [r2, #1]!
  144.         LDRB    r4, [r3, #1]!
  145.         CMP     ip, r4
  146.         BNE     exit_inn_cycle
  147.  
  148.         LDRB    ip, [r2, #1]!
  149.         LDRB    r4, [r3, #1]!
  150.         CMP     ip, r4
  151.         BNE     exit_inn_cycle
  152.  
  153.         LDRB    ip, [r2, #1]!
  154.         LDRB    r4, [r3, #1]!
  155.         CMP     ip, r4
  156.         BNE     exit_inn_cycle
  157.  
  158.         LDRB    ip, [r2, #1]!
  159.         LDRB    r4, [r3, #1]!
  160.         CMP     ip, r4
  161.         BNE     exit_inn_cycle
  162.  
  163.         LDRB    ip, [r2, #1]!
  164.         LDRB    r4, [r3, #1]!
  165.         CMP     ip, r4
  166.         BNE     exit_inn_cycle
  167.  
  168.         LDRB    ip, [r2, #1]!
  169.         LDRB    r4, [r3, #1]!
  170.         CMP     ip, r4
  171.         BNE     exit_inn_cycle
  172.  
  173.         CMP     r2, r7
  174.         BCC     inn_cycle
  175.  
  176. exit_inn_cycle
  177.         SUB     r4, r2, r7               ; len = MAX_MATCH - (int)(strend - scan);
  178.         ADD     r4, r4, #MAX_MATCH-256
  179.         ADD     r4, r4, #256
  180.  
  181.         SUB     r2, r2, r4               ; scan = strend - MAX_MATCH
  182.  
  183.         CMP     r4, r5                   ; if (len > best_len) {
  184.         BLE     cycle_end
  185.  
  186.         LDR     ip, [pc, #|__match_start|-.-8]  ; match_start = cur_match;
  187.         STR     r0, [ip]
  188.         MOV     r5, r4                          ; best_len = len;
  189.  
  190.         LDR     ip, [pc, #|__nice_match|-.-8]   ; if (len >= nice_match)
  191.         LDR     ip, [ip]
  192.         CMP     r4, ip
  193.         BGE     exit_match                      ;   break;
  194.  
  195.         SUB     ip, r5, #1                      ; scan_end1  = scan[best_len-1];
  196.         LDRB    r8, [r2, ip]
  197.         LDRB    r9, [r2, r5]                    ; scan_end   = scan[best_len];
  198.  
  199. cycle_end
  200.         MOV     ip, r0, LSL #17          ; cur_match & WMASK
  201.         MOV     ip, ip, LSR #17
  202.  
  203.         LDR     r0, [fp, ip, ASL #1]     ; cur_match = prev[cur_match & WMASK]
  204.         MOV     r0, r0, ASL #16
  205.         MOV     r0, r0, LSR #16
  206.  
  207.         CMP     r0, r6                  ; cur_match > limit
  208.         BLS     exit_match
  209.         SUBS    r1, r1, #1              ; --chain_length
  210.         BNE     cycle                   ; chain_length != 0
  211.  
  212. exit_match
  213.         MOV     r0, r5
  214.  
  215.         LDMFD   sp!, {r4-r9,fp,pc}^
  216.  
  217.         END
  218.