home *** CD-ROM | disk | FTP | other *** search
/ Serving the Web / ServingTheWeb1995.disc1of1.iso / linux / slacksrce / d / libc / libc-4.6 / libc-4 / libc-linux / sysdeps / i386 / stpcpy.c.new < prev    next >
Encoding:
Text File  |  1994-12-13  |  2.1 KB  |  65 lines

  1. /* stpcpy -- copy SRC to DEST returning the address of the terminating '\0'
  2.          in DEST.
  3.    For Intel 80x86, x>=3.
  4.    Copyright (C) 1994 Free Software Foundation, Inc.
  5.    Contributed by Ulrich Drepper (drepper@ira.uka.de).
  6.  
  7. The GNU C Library is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU Library General Public License as
  9. published by the Free Software Foundation; either version 2 of the
  10. License, or (at your option) any later version.
  11.  
  12. The GNU C Library is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15. Library General Public License for more details.
  16.  
  17. You should have received a copy of the GNU Library General Public
  18. License along with the GNU C Library; see the file COPYING.LIB.  If
  19. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  20. Cambridge, MA 02139, USA.  */
  21.  
  22. /* This function is defined neither in ANSI nor POSIX standards but is
  23.    also not invented here.  */
  24.  
  25. #include <string.h>
  26. #include "asm-ops.h"
  27.  
  28. char * stpcpy(char * dest, const char * src)
  29. {
  30. register char * __res;
  31. __asm__("subl %0,%1\n\t"
  32.     "subl $4,%0\n"        /* prepare loop counter */
  33.  
  34.     /* Four times unfolded loop with only one loop counter.  This
  35.      * is achieved by the use of index+base adressing mode.  As the
  36.      * loop counter we use the destination address because this is
  37.      * also the result.
  38.      */
  39. LL(1)    "\taddl $4,%0\n\t"    /* increment loop counter */
  40.  
  41.     "movb (%0,%1),%%dl\n\t"    /* load current char */
  42.     "movb %%dl,(%0)\n\t"    /* and store it */
  43.     "testb %%dl,%%dl\n\t"    /* was is NULL ? */
  44.     "je " LF(2) "\n\t"    /* yes, than exit */
  45.     "movb 1(%0,%1),%%dl\n\t"
  46.     "movb %%dl,1(%0)\n\t"
  47.     "testb %%dl,%%dl\n\t"
  48.     "je " LF(3) "\n\t"
  49.     "movb 2(%0,%1),%%dl\n\t"
  50.     "movb %%dl,2(%0)\n\t"
  51.     "testb %%dl,%%dl\n\t"
  52.     "je " LF(4) "\n\t"
  53.     "movb 3(%0,%1),%%dl\n\t"
  54.     "movb %%dl,3(%0)\n\t"
  55.     "testb %%dl,%%dl\n\t"
  56.     "jne " LB(1) "\n\t"
  57.  
  58.     "incl %0\n"        /* correct loop counter */
  59. LL(4)    "\tincl %0\n"
  60. LL(3)    "\tincl %0\n"
  61. LL(2)
  62.     :"=a" (__res):"c" (src),"0" (dest):"cx","dx");
  63. return __res;
  64. }
  65.