******************************************************************************
*                                                                            *
*   fastcmp.asm version 1.0 of 22 Januari 1989    (C) L.J.M. de Wit 1989     *
*                                                                            *
* This software may be used and distributed freely if not used commercially  *
* and the originator (me) is mentioned in the source (just leave this 9 line *
* header intact).                                                            *
*                                                                            *
******************************************************************************
*
* fastcmp.asm: fast sort functions
*
*   The code here presented is offered as a replacement for some of the C
*   functions present in sortcomp.c. Since comparisions are done a lot while
*   sorting, some performance tweaking didn't seem misplaced.
*
*   As for documentation, a reference is made to the corresponding C functions
*   in sortcomp.c. Most of the code here does simple work, like swapping
*   arguments (for the 'r' options), and/or skipping white space (for the 'b'
*   options; marked by 'skips' labels).
*

   section s.ccode

tab   equ   9

   xref     c_df
   xref     c_d
   xref     c_if
   xref     c_i
   xref     c_af

   xref     c_dfu
   xref     c_du
   xref     c_ifu
   xref     c_iu
   xref     c_afu

   xdef     c_dbfr
c_dbfr
* Dict/Blank/Fold/Reverse  *
   move.l   4(sp),a0
   move.l   8(sp),4(sp)
   move.l   a0,8(sp)
   move.l   12(sp),a0
   move.l   16(sp),12(sp)
   move.l   a0,16(sp)
*  FALLTHROUGH

   xdef     c_dbf
c_dbf
* Dict/Blank/Fold *
   movea.l  4(sp),a0
   movea.l  8(sp),a1
skips0a
   move.b   (a0)+,d0
   cmp.b    #' ',d0
   beq.s    skips0a
   cmp.b    #tab,d0
   beq.s    skips0a
   subq.l   #1,a0
skips1a
   move.b   (a1)+,d1
   cmp.b    #' ',d1
   beq.s    skips1a
   cmp.b    #tab,d1
   beq.s    skips1a
   subq.l   #1,a1
   move.l   a0,4(sp)
   move.l   a1,8(sp)
   jmp      c_df

   xdef     c_dbr
c_dbr
* Dict/Blank/Reverse  *
   move.l   4(sp),a0
   move.l   8(sp),4(sp)
   move@ÏÏÏŽGÁÃÃ„ÂpÏÏÏ€ˆ@ÏÏÀ,‚áðc‘ü3óóà" sóóñ0áðq‘0áðœ3óóà" sóóã‘ðq0áðœ03óæ'„d`dá$ü<3óóàâb3óóóóãc<#c<03æ`ƒp c€ ð<3óóà" sóðpáðc‘ü3óóà" sóððáðc‘œ!áã<3óóà"#3óóðã‘ðbqü3óóãð#3óóóóäåŒ†DL®%Îdmm.fADm®ÌDnŒ,EŒ†DL®%Îdmm.fADn¬N%Í„f%Œ&Nmm.f,AD­îÌ¥ÌD&%%eŒ†!Dm®ÌDdäåŒ†!DL®%Îdmm.f,ADm®ÌDnŒ,EŒ†!DL®%Îdsp),a0
   movea.l  8(sp),a1
skips0i
   move.b   (a0)+,d0
   cmp.b    #' ',d0
   beq.s    skips0i
   cmp.b    #tab,d0
   beq.s    skips0i
   subq.l   #1,a0
skips1i
   move.b   (a1)+,d1
   cmp.b    #' ',d1
   beq.s    skips1i
   cmp.b    #tab,d1
   beq.s    skips1i
   subq.l   #1,a1
   move.l   a0,4(sp)
   move.l   a1,8(sp)
   jmp      c_ifu

   xdef     c_ibru
c_ibru
* Norm/Blank/Reverse  *
   move.l   4(sp),a1
   move.l   8(sp),a0
   bra.s    skips0j

   xdef     c_ibu
c_ibu
* Norm/Blank  *
   movea.l  4(sp),a0
   movea.l  8(sp),a1
skips0j
   move.b   (a0)+,d0
   cmp.b    #' ',d0
   beq.s    skips0j
   cmp.b    #tab,d0
   beq.s    skips0j
   subq.l   #1,a0
skips1j
   move.b   (a1)+,d1
   cmp.b    #' ',d1
   beq.s    skips1j
   cmp.b    #tab,d1
   beq.s    skips1j
   subq.l   #1,a1
   move.l   a0,4(sp)
   move.l   a1,8(sp)
   jmp      c_iu

   xdef     c_ifru
c_ifru
* Norm/Fold/Reverse  *
   move.l   4(sp),a0
   move.l   8(sp),4(sp)
   move.l   a0,8(sp)
   jmp      c_ifu

   xdef     c_iru
c_iru
* Norm/Reverse  *
   move.l   4(sp),a0
   move.l   8(sp),4(sp)
   move.l   a0,8(sp)
   jmp      c_iu

   xdef     c_abfru
c_abfru
* Blank/Fold/Reverse  *
   move.l   4(sp),a1
   move.l   8(sp),a0
   bra.s    skips0k

   xdef     c_abfu
c_abfu
* Blank/Fold  *
   movea.l  4(sp),a0
   movea.l  8(sp),a1
skips0k
   move.b   (a0)+,d0
   cmp.b    #' ',d0
   beq.s    skips0k
   cmp.b    #tab,d0
   beq.s    skips0k
   subq.l   #1,a0
skips1k
   move.b   (a1)+,d1
   cmp.b    #' ',d1
   beq.s    skips1k
   cmp.b    #tab,d1
   beq.s    skips1k
   subq.l   #1,a1
   move.l   a0,4(sp)
   move.l   a1,8(sp)
   jmp      c_afu

   xdef     c_abru
c_abru
* Blank/Reverse  *
   move.l   4(sp),a1
   move.l   8(sp),a0
   bra.s    skips0l

   xdef     c_abu
c_abu
* Blank  *
   movea.l  4(sp),a0
   movea.l  8(sp),a1
skips0l
   move.b   (a0)+,d0
   cmp.b    #' ',d0
   beq.s    skips0l
   cmp.b    #tab,d0
   beq.s    skips0l
   subq.l   #1,a0
skips1l
   move.b   (a1)+,d1
   cmp.b    #' ',d1
   beq.s    skips1l
   cmp.b    #tab,d1
   beq.s    skips1l
   subq.l   #1,a1
   move.l   a0,4(sp)
   move.l   a1,8(sp)
   jmp      c_au

   xdef     c_afru
c_afru
* Fold/Reverse  *
   move.l   4(sp),a0
   move.l   8(sp),4(sp)
   move.l   a0,8(sp)
   jmp      c_afu

   xdef     c_aru
c_aru
* Reverse  *
   move.l   4(sp),a1
   move.l   8(sp),a0
   bra.s    c_auloop

   xdef     c_au
c_au
   movea.l 4(sp),a0
   movea.l 8(sp),a1
c_auloop
   move.b  (a0)+,d0
   beq.s   c_auex0
   sub.b   (a1)+,d0
   bne.s   c_auex1
   move.b  (a0)+,d0
   beq.s   c_auex0
   sub.b   (a1)+,d0
   bne.s   c_auex1
   move.b  (a0)+,d0
   beq.s   c_auex0
   sub.b   (a1)+,d0
   bne.s   c_auex1
   move.b  (a0)+,d0
   beq.s   c_auex0
   sub.b   (a1)+,d0
   beq.s   c_auloop
c_auex1
   ext.w   d0
   ext.l   d0
   rts
c_auex0
   sub.b   (a1),d0
   ext.w   d0
   ext.l   d0
   rts

   end
