home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / gnuc / string / rcs / bcopy.s,v < prev    next >
Encoding:
Text File  |  1992-07-04  |  3.7 KB  |  124 lines

  1. head    1.1;
  2. access;
  3. symbols
  4.     version39-41:1.1;
  5. locks;
  6. comment    @# @;
  7.  
  8.  
  9. 1.1
  10. date    92.06.08.17.58.42;    author mwild;    state Exp;
  11. branches;
  12. next    ;
  13.  
  14.  
  15. desc
  16. @initial checkin
  17. @
  18.  
  19.  
  20. 1.1
  21. log
  22. @Initial revision
  23. @
  24. text
  25. @/*-
  26.  * Copyright (c) 1990 The Regents of the University of California.
  27.  * All rights reserved.
  28.  *
  29.  * This code is derived from software contributed to Berkeley by
  30.  * the Systems Programming Group of the University of Utah Computer
  31.  * Science Department.
  32.  *
  33.  * Redistribution and use in source and binary forms are permitted
  34.  * provided that: (1) source distributions retain this entire copyright
  35.  * notice and comment, and (2) distributions including binaries display
  36.  * the following acknowledgement:  ``This product includes software
  37.  * developed by the University of California, Berkeley and its contributors''
  38.  * in the documentation or other materials provided with the distribution
  39.  * and in all advertising materials mentioning features or use of this
  40.  * software. Neither the name of the University nor the names of its
  41.  * contributors may be used to endorse or promote products derived
  42.  * from this software without specific prior written permission.
  43.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  44.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  45.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  46.  */
  47.  
  48. #if defined(LIBC_SCCS) && !defined(lint)
  49.     .asciz "@@(#)bcopy.s    5.1 (Berkeley) 5/12/90"
  50. #endif /* LIBC_SCCS and not lint */
  51.  
  52. #include "DEFS.h"
  53.  
  54. /*
  55.  * This is probably not the best we can do, but it is still 2-10 times
  56.  * faster than the C version in the portable gen directory.
  57.  *
  58.  * Things that might help:
  59.  *    - unroll the longword copy loop (might not be good for a 68020)
  60.  *    - longword align when possible (only on the 68020)
  61.  *    - use nested DBcc instructions or use one and limit size to 64K
  62.  */
  63. ENTRY(bcopy)
  64.     movl    sp@@(12),d1    /* check count */
  65.     jle    bcdone        /* <= 0, don't do anything */
  66.     movl    sp@@(4),a0    /* src address */
  67.     movl    sp@@(8),a1    /* dest address */
  68.     cmpl    a1,a0        /* src after dest? */
  69.     jlt    bcback        /* yes, must copy backwards */
  70.     movl    a0,d0
  71.     btst    #0,d0        /* src address odd? */
  72.     jeq    bcfeven        /* no, skip alignment */
  73.     movb    a0@@+,a1@@+    /* yes, copy a byte */
  74.     subql    #1,d1        /* adjust count */
  75.     jeq    bcdone        /* count 0, all done  */
  76. bcfeven:
  77.     movl    a1,d0
  78.     btst    #0,d0        /* dest address odd? */
  79.     jne    bcfbloop    /* yes, no hope for alignment, copy bytes */
  80.     movl    d1,d0        /* no, both even */
  81.     lsrl    #2,d0        /* convert count to longword count */
  82.     jeq    bcfbloop    /* count 0, skip longword loop */
  83. bcflloop:
  84.     movl    a0@@+,a1@@+    /* copy a longword */
  85.     subql    #1,d0        /* adjust count */
  86.     jne    bcflloop    /* still more, keep copying */
  87.     andl    #3,d1        /* what remains */
  88.     jeq    bcdone        /* nothing, all done */
  89. bcfbloop:
  90.     movb    a0@@+,a1@@+    /* copy a byte */
  91.     subql    #1,d1        /* adjust count */
  92.     jne    bcfbloop    /* still more, keep going */
  93. bcdone:
  94.     rts
  95. bcback:
  96.     addl    d1,a0        /* src pointer to end */
  97.     addl    d1,a1        /* dest pointer to end */
  98.     movl    a0,d0
  99.     btst    #0,d0        /* src address odd? */
  100.     jeq    bcbeven        /* no, skip alignment */
  101.     movb    a0@@-,a1@@-    /* yes, copy a byte */
  102.     subql    #1,d1        /* adjust count */
  103.     jeq    bcdone        /* count 0, all done  */
  104. bcbeven:
  105.     movl    a1,d0
  106.     btst    #0,d0        /* dest address odd? */
  107.     jne    bcbbloop    /* yes, no hope for alignment, copy bytes */
  108.     movl    d1,d0        /* no, both even */
  109.     lsrl    #2,d0        /* convert count to longword count */
  110.     jeq    bcbbloop    /* count 0, skip longword loop */
  111. bcblloop:
  112.     movl    a0@@-,a1@@-    /* copy a longword */
  113.     subql    #1,d0        /* adjust count */
  114.     jne    bcblloop    /* still more, keep copying */
  115.     andl    #3,d1        /* what remains */
  116.     jeq    bcdone        /* nothing, all done */
  117. bcbbloop:
  118.     movb    a0@@-,a1@@-    /* copy a byte */
  119.     subql    #1,d1        /* adjust count */
  120.     jne    bcbbloop    /* still more, keep going */
  121.     rts
  122.  
  123. @
  124.