123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407 |
- #ifndef USE_ZLIB
- #if defined(NO_UNDERLINE) || defined(__ELF__)
- # define _prev prev
- # define _window window
- # define _match_start match_start
- # define _prev_length prev_length
- # define _good_match good_match
- # define _nice_match nice_match
- # define _strstart strstart
- # define _max_chain_length max_chain_length
- # define _match_init match_init
- # define _longest_match longest_match
- #endif
- #ifdef DYN_ALLOC
- error: DYN_ALLOC not yet supported in match.s
- #endif
- #ifndef ALIGNMENT
- # define ALIGNMENT 4
- #endif
- #ifndef WSIZE
- # define WSIZE 32768
- #endif
- #define MIN_MATCH 3
- #define MAX_MATCH 258
- #define MIN_LOOKAHEAD (MAX_MATCH + MIN_MATCH + 1)
- #define MAX_DIST (WSIZE - MIN_LOOKAHEAD)
- #if defined(i386) || defined(_I386) || defined(_i386) || defined(__i386)
- .file "match.S"
- .globl _match_init
- .globl _longest_match
- .text
- _match_init:
- ret
- .align ALIGNMENT
- _longest_match:
- #define cur_match 20(%esp)
-
- push %ebp
- push %edi
- push %esi
- push %ebx
- mov cur_match,%esi
- mov _strstart,%edx
- mov _max_chain_length,%ebp
- mov %edx,%edi
- sub $(MAX_DIST),%edx
- cld
- jae limit_ok
- sub %edx,%edx
- limit_ok:
- add $2+_window,%edi
- mov _prev_length,%ebx
- movw -2(%edi),%cx
- movw -3(%ebx,%edi),%ax
- cmp _good_match,%ebx
- jb do_scan
- shr $2,%ebp
- jmp do_scan
- .align ALIGNMENT
- long_loop:
- movw -3(%ebx,%edi),%ax
- movw -2(%edi),%cx
- short_loop:
- and $(WSIZE-1), %esi
- dec %ebp
- movw _prev(,%esi,2),%si
-
- jz the_end
- cmp %edx,%esi
- jbe the_end
- do_scan:
- cmpw _window-1(%ebx,%esi),%ax
- jne short_loop
- cmpw _window(%esi),%cx
- jne short_loop
- add $2+_window,%esi
- mov $((MAX_MATCH>>1)-1),%ecx
- mov %edi,%eax
- repe; cmpsw
- je maxmatch
- mismatch:
- movb -2(%edi),%cl
- xchg %edi,%eax
- subb -2(%esi),%cl
- sub %edi,%eax
- sub $2+_window,%esi
- sub %eax,%esi
- subb $1,%cl
- adc $0,%eax
- cmp %ebx,%eax
- jle long_loop
- mov %esi,_match_start
- mov %eax,%ebx
- #ifdef FULL_SEARCH
- cmp $(MAX_MATCH),%eax
- #else
- cmp _nice_match,%eax
- #endif
- jl long_loop
- the_end:
- mov %ebx,%eax
- pop %ebx
- pop %esi
- pop %edi
- pop %ebp
- ret
- .align ALIGNMENT
- maxmatch:
- cmpsb
- jmp mismatch
- #else
- #if defined(m68k)||defined(mc68k)||defined(__mc68000__)||defined(__MC68000__)
- # ifndef mc68000
- # define mc68000
- # endif
- #endif
- #if defined(__mc68020__) || defined(__MC68020__) || defined(sysV68)
- # ifndef mc68020
- # define mc68020
- # endif
- #endif
- #if defined(mc68020) || defined(mc68000)
- #if (defined(mc68020) || defined(NeXT)) && !defined(UNALIGNED_OK)
- # define UNALIGNED_OK
- #endif
- #ifdef sysV68
- # define GLOBAL(symbol) global symbol
- # define TEXT text
- # define FILE(filename) file filename
- # define invert_maybe(src,dst) dst,src
- # define imm(data) &data
- # define reg(register) %register
- # define addl add.l
- # define addql addq.l
- # define blos blo.b
- # define bhis bhi.b
- # define bras bra.b
- # define clrl clr.l
- # define cmpmb cmpm.b
- # define cmpw cmp.w
- # define cmpl cmp.l
- # define lslw lsl.w
- # define lsrl lsr.l
- # define movel move.l
- # define movew move.w
- # define moveb move.b
- # define moveml movem.l
- # define subl sub.l
- # define subw sub.w
- # define subql subq.l
- # define IndBase(bd,An) (bd,An)
- # define IndBaseNdxl(bd,An,Xn) (bd,An,Xn.l)
- # define IndBaseNdxw(bd,An,Xn) (bd,An,Xn.w)
- # define predec(An) -(An)
- # define postinc(An) (An)+
- #else
- # define GLOBAL(symbol) .globl symbol
- # define TEXT .text
- # define FILE(filename) .even
- # define invert_maybe(src,dst) src,dst
- # if defined(sun) || defined(mc68k)
- # define imm(data) #data
- # else
- # define imm(data) \#data
- # endif
- # define reg(register) register
- # define blos bcss
- # if defined(sun) || defined(mc68k)
- # define movel movl
- # define movew movw
- # define moveb movb
- # endif
- # define IndBase(bd,An) An@(bd)
- # define IndBaseNdxl(bd,An,Xn) An@(bd,Xn:l)
- # define IndBaseNdxw(bd,An,Xn) An@(bd,Xn:w)
- # define predec(An) An@-
- # define postinc(An) An@+
- #endif
- #define Best_Len reg(d0)
- #define Cur_Match reg(d1)
- #define Loop_Counter reg(d2)
- #define Scan_Start reg(d3)
- #define Scan_End reg(d4)
- #define Limit reg(d5)
- #define Chain_Length reg(d6)
- #define Scan_Test reg(d7)
- #define Scan reg(a0)
- #define Match reg(a1)
- #define Prev_Address reg(a2)
- #define Scan_Ini reg(a3)
- #define Match_Ini reg(a4)
- #define Stack_Pointer reg(sp)
- GLOBAL (_match_init)
- GLOBAL (_longest_match)
- TEXT
- FILE ("match.S")
- _match_init:
- rts
- #ifdef UNALIGNED_OK
- # define pushreg 15928
- # define popreg 7292
- #else
- # define pushreg 16184
- # define popreg 7420
- #endif
- _longest_match:
- movel IndBase(4,Stack_Pointer),Cur_Match
- moveml imm(pushreg),predec(Stack_Pointer)
- movel _max_chain_length,Chain_Length
- movel _prev_length,Best_Len
- movel imm(_prev),Prev_Address
- movel imm(_window+MIN_MATCH),Match_Ini
- movel _strstart,Limit
- movel Match_Ini,Scan_Ini
- addl Limit,Scan_Ini
- subw imm(MAX_DIST),Limit
- bhis L__limit_ok
- clrl Limit
- L__limit_ok:
- cmpl invert_maybe(_good_match,Best_Len)
- blos L__length_ok
- lsrl imm(2),Chain_Length
- L__length_ok:
- subql imm(1),Chain_Length
- #ifdef UNALIGNED_OK
- movew IndBase(-MIN_MATCH,Scan_Ini),Scan_Start
- movew IndBaseNdxw(-MIN_MATCH-1,Scan_Ini,Best_Len),Scan_End
- #else
- moveb IndBase(-MIN_MATCH,Scan_Ini),Scan_Start
- lslw imm(8),Scan_Start
- moveb IndBase(-MIN_MATCH+1,Scan_Ini),Scan_Start
- moveb IndBaseNdxw(-MIN_MATCH-1,Scan_Ini,Best_Len),Scan_End
- lslw imm(8),Scan_End
- moveb IndBaseNdxw(-MIN_MATCH,Scan_Ini,Best_Len),Scan_End
- #endif
- bras L__do_scan
- L__long_loop:
- #ifdef UNALIGNED_OK
- movew IndBaseNdxw(-MIN_MATCH-1,Scan_Ini,Best_Len),Scan_End
- #else
- moveb IndBaseNdxw(-MIN_MATCH-1,Scan_Ini,Best_Len),Scan_End
- lslw imm(8),Scan_End
- moveb IndBaseNdxw(-MIN_MATCH,Scan_Ini,Best_Len),Scan_End
- #endif
- L__short_loop:
- lslw imm(1),Cur_Match
- movew IndBaseNdxl(0,Prev_Address,Cur_Match),Cur_Match
- cmpw invert_maybe(Limit,Cur_Match)
- dbls Chain_Length,L__do_scan
- bras L__return
- L__do_scan:
- movel Match_Ini,Match
- addl Cur_Match,Match
- #ifdef UNALIGNED_OK
- cmpw invert_maybe(IndBaseNdxw(-MIN_MATCH-1,Match,Best_Len),Scan_End)
- bne L__short_loop
- cmpw invert_maybe(IndBase(-MIN_MATCH,Match),Scan_Start)
- bne L__short_loop
- #else
- moveb IndBaseNdxw(-MIN_MATCH-1,Match,Best_Len),Scan_Test
- lslw imm(8),Scan_Test
- moveb IndBaseNdxw(-MIN_MATCH,Match,Best_Len),Scan_Test
- cmpw invert_maybe(Scan_Test,Scan_End)
- bne L__short_loop
- moveb IndBase(-MIN_MATCH,Match),Scan_Test
- lslw imm(8),Scan_Test
- moveb IndBase(-MIN_MATCH+1,Match),Scan_Test
- cmpw invert_maybe(Scan_Test,Scan_Start)
- bne L__short_loop
- #endif
- movew imm((MAX_MATCH-MIN_MATCH+1)-1),Loop_Counter
- movel Scan_Ini,Scan
- L__scan_loop:
- cmpmb postinc(Match),postinc(Scan)
- dbne Loop_Counter,L__scan_loop
- subl Scan_Ini,Scan
- addql imm(MIN_MATCH-1),Scan
- cmpl invert_maybe(Best_Len,Scan)
- bls L__short_loop
- movel Scan,Best_Len
- movel Cur_Match,_match_start
- #ifdef FULL_SEARCH
- cmpl invert_maybe(imm(MAX_MATCH),Best_Len)
- #else
- cmpl invert_maybe(_nice_match,Best_Len)
- #endif
- blos L__long_loop
- L__return:
- moveml postinc(Stack_Pointer),imm(popreg)
- rts
- #else
- error: this asm version is for 386 or 680x0 only
- #endif
- #endif
- #endif
|