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 < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-13  |  1.8 KB  |  58 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"
  33.     /* four times unfolded loop without loop index increment */
  34.     LL(1) "\taddl $4,%0\n\t"
  35.     "movb (%0,%1),%%dl\n\t"
  36.     "movb %%dl,(%0)\n\t"
  37.     "testb %%dl,%%dl\n\t"
  38.     "je " LF(2) "\n\t"
  39.     "movb 1(%0,%1),%%dl\n\t"
  40.     "movb %%dl,1(%0)\n\t"
  41.     "testb %%dl,%%dl\n\t"
  42.     "je " LF(3) "\n\t"
  43.     "movb 2(%0,%1),%%dl\n\t"
  44.     "movb %%dl,2(%0)\n\t"
  45.     "testb %%dl,%%dl\n\t"
  46.     "je " LF(4) "\n\t"
  47.     "movb 3(%0,%1),%%dl\n\t"
  48.     "movb %%dl,3(%0)\n\t"
  49.     "testb %%dl,%%dl\n\t"
  50.     "jne " LB(1) "\n\t"
  51.     "incl %0\n"
  52.     LL(4) "\tincl %0\n"
  53.     LL(3) "\tincl %0\n"
  54.     LL(2)
  55.     :"=a" (__res):"c" (src),"0" (dest):"cx","dx");
  56. return __res;
  57. }
  58.