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 / strcat.c.new < prev    next >
Encoding:
Text File  |  1994-12-13  |  7.3 KB  |  326 lines

  1. /* strcat(dest, src) -- Append SRC on the end of DEST.
  2.    For Intel 80x86, x>=3.
  3.    Copyright (C) 1994 Free Software Foundation, Inc.
  4.    Contributed by Ulrich Drepper <drepper@ira.uka.de>.
  5.  
  6. The GNU C Library is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU Library General Public License as
  8. published by the Free Software Foundation; either version 2 of the
  9. License, or (at your option) any later version.
  10.  
  11. The GNU C Library is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14. Library General Public License for more details.
  15.  
  16. You should have received a copy of the GNU Library General Public
  17. License along with the GNU C Library; see the file COPYING.LIB.  If
  18. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  19. Cambridge, MA 02139, USA.  */
  20.  
  21. #include <ansidecl.h>
  22. #include <string.h>
  23.  
  24. #include "asm-ops.h"
  25.  
  26. char *
  27. strcat(char * dest, const char *src)
  28. {
  29. register char * __res;
  30.  
  31. /*
  32.  * We have to use two different versions, one for i386 and for the rest
  33.  * because the difference is so big.  Be aware when the name of the i586
  34.  * (aka Pentium) in the gcc changes (I assume __i586__) or the next
  35.  * generation (i686) is available.
  36.  */
  37. #if !defined(__i486__) && !defined(__i586__)
  38.  
  39. __asm__(
  40.         "cld\n\t"
  41.     "repne\n\t"
  42.     "scasb\n\t"
  43.     "decl %0\n\t"
  44.  
  45.     "subl %0,%3\n\t"
  46.     
  47.     "testl $0x3,%0\n\t"
  48.     "jz " LF(1) "\n\t"
  49.     "movw (%3,%0),%%ax\n\t"
  50.     "movb %%al,(%0)\n\t"
  51.     "orb %%al,%%al\n\t"
  52.     "jz " LF(8) "\n\t"
  53.     "incl %0\n\t"
  54.     
  55.     "testl $0x3,%0\n\t"
  56.     "jz " LF(1) "\n\t"
  57.     "movb %%ah,(%0)\n\t"
  58.     "orb %%ah,%%ah\n\t"
  59.     "jz " LF(8) "\n\t"
  60.     "incl %0\n\t"
  61.     
  62.     "testl $0x3,%0\n\t"
  63.     "jz " LF(1) "\n\t"
  64.     "movb (%3,%0),%%al\n\t"
  65.     "movb %%al,(%0)\n\t"
  66.     "orb %%al,%%al\n\t"
  67.     "jz " LF(8) "\n\t"
  68.     "incl %0\n"
  69.  
  70. LL(1)    "\tmovl (%3,%0),%%eax\n\t"
  71.     "movl %%eax,%%ecx\n\t"
  72.     "addl $0xfefefeff,%%ecx\n\t"
  73.     "jnc " LF(9) "\n\t"
  74.     "xorl %%eax,%%ecx\n\t"
  75.     "notl %%ecx\n\t"
  76.     "andl $0x01010100,%%ecx\n\t"
  77.     "jnz " LF(9) "\n\t"
  78.     "movl %%eax,(%0)\n\t"
  79.  
  80.     "movl 4(%3,%0),%%eax\n\t"
  81.     "movl %%eax,%%ecx\n\t"
  82.     "addl $0xfefefeff,%%ecx\n\t"
  83.     "jnc " LF(91) "\n\t"
  84.     "xorl %%eax,%%ecx\n\t"
  85.     "notl %%ecx\n\t"
  86.     "andl $0x01010100,%%ecx\n\t"
  87.     "jnz " LF(91) "\n\t"
  88.     "movl %%eax,4(%0)\n\t"
  89.  
  90.     "movl 8(%3,%0),%%eax\n\t"
  91.     "movl %%eax,%%ecx\n\t"
  92.     "addl $0xfefefeff,%%ecx\n\t"
  93.     "jnc " LF(92) "\n\t"
  94.     "xorl %%eax,%%ecx\n\t"
  95.     "notl %%ecx\n\t"
  96.     "andl $0x01010100,%%ecx\n\t"
  97.     "jnz " LF(92) "\n\t"
  98.     "movl %%eax,8(%0)\n\t"
  99.  
  100.     "movl 12(%3,%0),%%eax\n\t"
  101.     "movl %%eax,%%ecx\n\t"
  102.     "addl $0xfefefeff,%%ecx\n\t"
  103.     "jnc " LF(93) "\n\t"
  104.     "xorl %%eax,%%ecx\n\t"
  105.     "notl %%ecx\n\t"
  106.     "andl $0x01010100,%%ecx\n\t"
  107.     "jnz " LF(93) "\n\t"
  108.     "movl %%eax,12(%0)\n\t"
  109.     "addl $16,%0\n\t"
  110.     "jmp " LB(1) "\n"
  111.  
  112. LL(93)    "\taddl $4,%0\n"
  113. LL(92)    "\taddl $4,%0\n"
  114. LL(91)    "\taddl $4,%0\n"
  115.  
  116. LL(9)    "\tmovb %%al,(%0)\n\t"
  117.     "orb %%al,%%al\n\t"
  118.     "jz " LF(8) "\n\t"
  119.     "movb %%ah,1(%0)\n\t"
  120.     "orb %%ah,%%ah\n\t"
  121.     "jz " LF(8) "\n\t"
  122.     "shrl $16,%%eax\n\t"
  123.     "movb %%al,2(%0)\n\t"
  124.     "orb %%al,%%al\n\t"
  125.     "jz " LF(8) "\n\t"
  126.     "movb %%ah,3(%0)\n"
  127. LL(8)
  128.                 
  129.     : :"D" (dest),"a" (0),"c" (0xffffffff), "d" (src):"cx","dx","di");
  130. #else
  131. __asm__(
  132.     "testb $0xff,(%1)\n\t"
  133.     "jz " LF(8) "\n\t"
  134.     
  135.         /* test the first bytes seperately until aligned */
  136.     "testb $3,%0\n\t"
  137.     "jz " LF(1) "\n\t"
  138.     "testb $0xff,(%0)\n\t"    /* was last character ? */
  139.     "jz " LF(2) "\n\t"    /* yes -> branch */
  140.     "incl %0\n\t"
  141.     
  142.     "testb $3,%0\n\t"
  143.     "jz " LF(1) "\n\t"
  144.     "testb $0xff,(%0)\n\t"
  145.     "jz " LF(2) "\n\t"
  146.     "incl %0\n\t"
  147.     
  148.     "testb $3,%0\n\t"
  149.     "jz " LF(1) "\n\t"
  150.     "testl $0xff,(%0)\n\t"
  151.     "jz " LF(2) "\n\t"
  152.     "incl %0\n"
  153.  
  154.     /* If you cannot guess what this is for look through the resulting
  155.      * code.  The dumb version has an .align at the end of the conditional
  156.      * region.  This is quite long.  If we could make the jump to the
  157.      * label '1' behind the NOPs we could save the time in 75% of the
  158.      * cases without any costs.  Exactly this is done here. if anything
  159.      * in the prepending code changes the number of NOPs may have to
  160.      * change, too.  */
  161.  
  162. #if defined(I_DONT_KNOW_WHAT_THIS_MEANS)
  163. LL(1)    "\tsubl $16,%0\n\t"
  164.  
  165.     ALIGN "\n"
  166. #else
  167.     "\tnop; nop; nop; nop; nop\n\t"
  168.     "nop; nop; nop; nop; nop; nop\n"
  169. LL(1)   "\tsubl $16,%0\n"
  170. #endif
  171.  
  172. LL(4)    "\taddl $16,%0\n\t"
  173.  
  174.     "movl (%0),%%eax\n\t"
  175.     "movl %%eax,%%ecx\n\t"
  176.     "addl $0xfefefeff,%%ecx\n\t"
  177.     "jnc " LF(3) "\n\t"
  178.     "xorl %%eax,%%ecx\n\t"
  179.     "notl %%ecx\n\t"
  180.     "andl $0x01010100,%%ecx\n\t"
  181.     "jnz " LF(3) "\n\t"
  182.     
  183.     "movl 4(%0),%%eax\n\t"
  184.     "movl %%eax,%%ecx\n\t"
  185.     "addl $0xfefefeff,%%ecx\n\t"
  186.     "jnc " LF(5) "\n\t"
  187.     "xorl %%eax,%%ecx\n\t"
  188.     "notl %%ecx\n\t"
  189.     "andl $0x01010100,%%ecx\n\t"
  190.     "jnz " LF(5) "\n\t"
  191.     
  192.     "movl 8(%0),%%eax\n\t"
  193.     "movl %%eax,%%ecx\n\t"
  194.     "addl $0xfefefeff,%%ecx\n\t"
  195.     "jnc " LF(6) "\n\t"
  196.     "xorl %%eax,%%ecx\n\t"
  197.     "notl %%ecx\n\t"
  198.     "andl $0x01010100,%%ecx\n\t"
  199.     "jnz " LF(6) "\n\t"
  200.     
  201.     "movl 12(%0),%%eax\n\t"
  202.     "movl %%eax,%%ecx\n\t"
  203.     "addl $0xfefefeff,%%ecx\n\t"
  204.     "jnc " LF(7) "\n\t"
  205.     "xorl %%eax,%%ecx\n\t"
  206.     "notl %%ecx\n\t"
  207.     "andl $0x01010100,%%ecx\n\t"
  208.     "jz " LB(4) "\n"
  209.  
  210. LL(7)    "\taddl $4,%0\n"
  211. LL(6)    "\taddl $4,%0\n"
  212. LL(5)    "\taddl $4,%0\n"
  213.  
  214. LL(3)
  215.     : :"d" (dest),"c" (src):"ax","dx","cx");
  216.  
  217. __asm__(
  218.     "testb $0xff,%%al\n\t"
  219.     "jz " LF(2) "\n\t"
  220.     "incl %%edx\n\t"
  221.     "testb $0xff,%%ah\n\t"
  222.     "jz " LF(23) "\n\t"
  223.     "incl %%edx\n\t"
  224.         "shrl $8,%%eax\n\t"
  225.     "testb $0xff,%%ah\n\t"
  226.     "jz " LF(22) "\n\t"
  227.     "incl %%edx\n\t"
  228.     
  229.         "movb (%0),%%al\n\t"
  230.     "movb %%al,(%%edx)\n\t"
  231.     "incl %%edx\n\t"
  232.     "incl %0\n\t"
  233.     "jmp " LF(2) "\n"
  234.  
  235. LL(22)    "\tmovw (%0),%%ax\n\t"
  236.     "movw %%ax,(%%edx)\n\t"
  237.     "orb %%ah,%%ah\n\t"
  238.     "jz " LF(8) "\n\t"
  239.     "addl $2,%%edx\n\t"
  240.     "addl $2,%0\n\t"
  241.     "jmp " LF(2) "\n"
  242.  
  243. LL(23)    "\tmovw (%0),%%ax\n\t"
  244.     "movw %%ax,(%%edx)\n\t"
  245.     "orb %%ah,%%ah\n\t"
  246.     "jz " LF(8) "\n\t"
  247.     "movb 2(%0),%%al\n\t"
  248.     "movb %%al,2(%%edx)\n\t"
  249.     "orb %%al,%%al\n\t"
  250.     "jz " LF(8) "\n\t"
  251.     "addl $3,%%edx\n\t"
  252.     "addl $3,%0\n"
  253.     
  254. LL(2)    "\tsubl %%edx,%0\n"
  255.     
  256. LL(29)    "\tmovl (%0,%%edx),%%eax\n\t"
  257.     "movl %%eax,%%edi\n\t"
  258.     "addl $0xfefefeff,%%edi\n\t"
  259.     "jnc " LF(9) "\n\t"
  260.     "xorl %%eax,%%edi\n\t"
  261.     "notl %%edi\n\t"
  262.     "andl $0x01010100,%%edi\n\t"
  263.     "jnz " LF(9) "\n\t"
  264.     "movl %%eax,(%%edx)\n\t"
  265.  
  266.     "movl 4(%0,%%edx),%%eax\n\t"
  267.     "movl %%eax,%%edi\n\t"
  268.     "addl $0xfefefeff,%%edi\n\t"
  269.     "jnc " LF(91) "\n\t"
  270.     "xorl %%eax,%%edi\n\t"
  271.     "notl %%edi\n\t"
  272.     "andl $0x01010100,%%edi\n\t"
  273.     "jnz " LF(91) "\n\t"
  274.     "movl %%eax,4(%%edx)\n\t"
  275.  
  276.     "movl 8(%0,%%edx),%%eax\n\t"
  277.     "movl %%eax,%%edi\n\t"
  278.     "addl $0xfefefeff,%%edi\n\t"
  279.     "jnc " LF(92) "\n\t"
  280.     "xorl %%eax,%%edi\n\t"
  281.     "notl %%edi\n\t"
  282.     "andl $0x01010100,%%edi\n\t"
  283.     "jnz " LF(92) "\n\t"
  284.     "movl %%eax,8(%%edx)\n\t"
  285.  
  286.     "movl 12(%0,%%edx),%%eax\n\t"
  287.     "movl %%eax,%%edi\n\t"
  288.     "addl $0xfefefeff,%%edi\n\t"
  289.     "jnc " LF(93) "\n\t"
  290.      "xorl %%eax,%%edi\n\t"
  291.     "notl %%edi\n\t"
  292.     "andl $0x01010100,%%edi\n\t"
  293.     "jnz " LF(93) "\n\t"
  294.     "movl %%eax,12(%%edx)\n\t"
  295.     "addl $16,%%edx\n\t"
  296.     "jmp " LB(29) "\n"
  297.  
  298. LL(93)    "\taddl $4,%%edx\n"
  299. LL(92)    "\taddl $4,%%edx\n"
  300. LL(91)    "\taddl $4,%%edx\n"
  301.  
  302. LL(9)    "\tmovb %%al,(%%edx)\n\t"
  303.     "orb %%al,%%al\n\t"
  304.     "jz " LF(8) "\n\t"
  305.     "movb %%ah,1(%%edx)\n\t"
  306.     "orb %%ah,%%ah\n\t"
  307.     "jz " LF(8) "\n\t"
  308.     "shrl $16,%%eax\n\t"
  309.     "movb %%al,2(%%edx)\n\t"
  310.     "orb %%al,%%al\n\t"
  311.     "jz " LF(8) "\n\t"
  312.     "movb %%ah,3(%%edx)\n"
  313.     
  314. LL(8)
  315.         : :"c" (src):"dx","ax","di");
  316. #endif
  317.  
  318.     /*
  319.      * This is just a trick to convince GCC that DEST has not
  320.      * changed and so no saving is needed.
  321.      */
  322. __asm__("":"=a" (__res) :"0" (dest));
  323.  
  324. return __res;
  325. }
  326.