home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 300-399 / ff362.lzh / MemRoutines / memcmp.asm < prev    next >
Assembly Source File  |  1990-08-11  |  2KB  |  100 lines

  1. ;--------------------------------------------------------------------
  2. ; memcmp() -- a faster version
  3. ;--------------------------------------------------------------------
  4. ; x = memcmp( s1,s2,count)
  5.  
  6. ; This routine compares the data pointed to by "s1" and "s2" for "count"
  7. ; bytes, and returns 0 if they are identical, a negative number if s1 < s2,
  8. ; or a positive number if s1 > s2.
  9.  
  10. ;                            Robert Broughton
  11. ;                            328-1027 Davie St.
  12. ;                            Vancouver, BC V6E 4L2
  13. ;                            Canada
  14. ;                            USENet: a1040@mindlink.UUCP
  15.  
  16. MANX    SET        1
  17.         IFND        MANX
  18.         IDNT        _memcmp
  19.         CSECT        _memcmp
  20.         ENDC
  21.         XDEF        _memcmp
  22. _memcmp:
  23.         link        a5,#.127
  24.         move.l    12(a5),a1            ;* s2
  25.       move.l   8(a5),a0   ;* s1
  26.         move.l    16(a5),d0    ;* count
  27.  
  28.         cmp.l        #7,d0
  29.         ble        finish       ;* too small, don't bother with optimization
  30.  
  31.         move.l    a0,d1
  32.         btst        #0,d1            ;*  even or odd
  33.         beq        ineven      ;*  it's even already
  34.         subq.l    #1,d0
  35.         move.b    (a0)+,d1
  36.         cmp.b        (a1)+,d1         ;*  now it's even
  37.         bne        lowout
  38.  
  39. ineven:
  40.         move.l    a1,d1
  41.         btst        #0,d1            ;*  how about output
  42.         beq        outeven
  43.  
  44. outodd:
  45. ;     unfortunately, the output address is not word-aligned, so we will
  46. ;     load a long word from s1 into d1, load four bytes from s2 into d2,
  47. ;     and compare the two registers
  48.         cmp.l        #3,d0
  49.         ble        finish
  50.  
  51.         move.l    (a0)+,d1
  52.         move.b    (a1)+,d2
  53.         ext.w        d2
  54.         swap        d2
  55.         move.w    (a1)+,d2
  56.         lsl.l        #8,d2
  57.         move.b    (a1)+,d2
  58.         subq.l    #4,d0
  59.         cmp.l        d1,d2
  60.         beq        outodd
  61.         sub.l        d2,d1
  62.         move.l    d1,d0
  63.         bra        really
  64.  
  65. outeven:
  66. ;        ideal situation; we can load and compare longwords
  67.         cmp.l        #3,d0
  68.         ble        finish
  69.  
  70.         subq.l    #4,d0
  71.         cmp.l        (a0)+,(a1)+
  72.         beq        outeven
  73.         move.l    -(a0),d0
  74.         sub.l        -(a1),d0
  75.         bra        really
  76.  
  77. finish:
  78.         cmp.b        #0,d0
  79.         ble        really
  80.         subq.l    #1,d0
  81. finishloop:
  82.         move.b    (a0)+,d1
  83.         cmp.b        (a1)+,d1         
  84.         dbne        d0,finishloop
  85.         bra        lowout
  86.  
  87. really:
  88.         unlk        a5
  89.         rts
  90.  
  91. lowout:
  92.         sub.b        -(a1),d1
  93.         ext.w        d1
  94.         ext.l        d1
  95.         move.l    d1,d0
  96.         bra        really
  97.  
  98. .127    equ        0
  99.  
  100.