home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / dev / gcc / ixemulsrc.lha / ixemul / string / bzero.c < prev    next >
C/C++ Source or Header  |  1996-12-11  |  2KB  |  64 lines

  1. /*-
  2.  * Copyright (c) 1990 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * This code is derived from software contributed to Berkeley by
  6.  * the Systems Programming Group of the University of Utah Computer
  7.  * Science Department.
  8.  *
  9.  * Redistribution and use in source and binary forms are permitted
  10.  * provided that: (1) source distributions retain this entire copyright
  11.  * notice and comment, and (2) distributions including binaries display
  12.  * the following acknowledgement:  ``This product includes software
  13.  * developed by the University of California, Berkeley and its contributors''
  14.  * in the documentation or other materials provided with the distribution
  15.  * and in all advertising materials mentioning features or use of this
  16.  * software. Neither the name of the University nor the names of its
  17.  * contributors may be used to endorse or promote products derived
  18.  * from this software without specific prior written permission.
  19.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  20.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  21.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  22.  */
  23.  
  24.  
  25. #include "defs.h"
  26.  
  27. /*
  28.  * This is probably not the best we can do, but it is still much
  29.  * faster than the C version in the portable gen directory.
  30.  *
  31.  * Things that might help:
  32.  *    - unroll the longword loop (might not be good for a 68020)
  33.  *    - longword, as opposed to word, align when possible (only on the 68020)
  34.  *    - use nested DBcc instructions or use one and limit size to 64K
  35.  */
  36. ENTRY(bzero)
  37. asm("
  38.     movl    sp@(4),a0    /* destination */
  39.     movl    sp@(8),d0    /* count */
  40.     jeq    bzdone        /* nothing to do */
  41.     movl    a0,d1
  42.     btst    #0,d1        /* address odd? */
  43.     jeq    bzeven        /* no, skip alignment */
  44.     clrb    a0@+        /* yes, clear a byte */
  45.     subql    #1,d0        /* adjust count */
  46.     jeq    bzdone        /* if zero, all done */
  47. bzeven:
  48.     movl    d0,d1
  49.     lsrl    #2,d1        /* convert to longword count */
  50.     jeq    bzbloop        /* no longwords, skip loop */
  51. bzlloop:
  52.     clrl    a0@+        /* clear a longword */
  53.     subql    #1,d1        /* adjust count */
  54.     jne    bzlloop        /* still more, keep going */
  55.     andl    #3,d0        /* what remains */
  56.     jeq    bzdone        /* nothing, all done */
  57. bzbloop:
  58.     clrb    a0@+        /* clear a byte */
  59.     subql    #1,d0        /* adjust count */
  60.     jne    bzbloop        /* still more, keep going */
  61. bzdone:
  62.     rts
  63. ");
  64.