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 / strstr.c.old < prev    next >
Encoding:
Text File  |  1994-11-19  |  3.4 KB  |  150 lines

  1. /* 
  2.    Copyright (C) 1994 Free Software Foundation, Inc.
  3.    Contributed by Ulrich Drepper <drepper@ira.uka.de>.
  4.  
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public License as
  7. published by the Free Software Foundation; either version 2 of the
  8. License, or (at your option) any later version.
  9.  
  10. The GNU C Library is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. Library General Public License for more details.
  14.  
  15. You should have received a copy of the GNU Library General Public
  16. License along with the GNU C Library; see the file COPYING.LIB.  If
  17. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  18. Cambridge, MA 02139, USA.  */
  19.  
  20. #include <string.h>
  21. #include "asm-ops.h"
  22.  
  23. char *
  24. strstr(const char *haystack, const char *needle)
  25. {
  26. register char *__res;
  27. __asm__(
  28. #if defined(__PIC__) || defined(__pic__)
  29.         "pushl %%ebx\n\t"
  30. #endif
  31.     "movl %1,%0\n\t"
  32.     "testb $0xff,(%2)\n\t"
  33.     "je " LF(1) "\n\t"
  34.     "movw (%2),%%cx\n\t"
  35.     "addl $2,%2\n\t"
  36.     "cld\n\t"
  37.  
  38.     "orb %%ch,%%ch\n\t"
  39.     "jne " LF(5) "\n"
  40. /* handle special case of a one-character-needle */
  41. LL(6)    "\tmovb (%1),%%al\n\t"
  42.     "orb %%al,%%al\n\t"
  43.     "je " LF(2) "\n\t"
  44.     "incl %1\n\t"
  45.     "xorb %%cl,%%al\n\t"
  46.     "jne " LB(6) "\n\t"
  47.     "leal -1(%1),%0\n\t"
  48.     "jmp " LF(1) "\n"
  49.  
  50. LL(5)    "\ttestb $0xff,(%1)\n\t"
  51.     "je " LF(2) "\n\t"
  52.  
  53.     "cmpb %%cl,%%ch\n\t"
  54.     "jne " LF(8) "\n"
  55.  
  56. LL(4)    "\tmovw (%1),%%ax\n\t"
  57.     "cmpw %%ax,%%cx\n\t"
  58.     "je " LF(30) "\n\t"
  59.     "orb %%ah,%%ah\n\t"
  60.     "je " LF(2) "\n\t"
  61.     "movw 1(%1),%%ax\n\t"
  62.     "cmpw %%ax,%%cx\n\t"
  63.     "je " LF(31) "\n\t"
  64.     "orb %%ah,%%ah\n\t"
  65.     "je " LF(2) "\n\t"
  66.     "movw 2(%1),%%ax\n\t"
  67.     "cmpw %%ax,%%cx\n\t"
  68.     "je " LF(32) "\n\t"
  69.     "orb %%ah,%%ah\n\t"
  70.     "je " LF(2) "\n\t"
  71.     "movw 3(%1),%%ax\n\t"
  72.     "cmpw %%ax,%%cx\n\t"
  73.     "je " LF(33) "\n\t"
  74.     "orb %%ah,%%ah\n\t"
  75.     "je " LF(2) "\n\t"
  76.     "addl $4,%1\n\t"
  77.     "jmp " LB(4) "\n"
  78.  
  79. LL(33)    "\tincl %1\n"
  80. LL(32)    "\tincl %1\n"
  81. LL(31)    "\tincl %1\n"
  82. LL(30)    "\tmovl %1,%0\n\t"
  83.     "addl $2,%1\n\t"
  84.     "movl %2,%%ebx\n"
  85. LL(7)    "\tmovb (%%ebx),%%ah\n\t"
  86.     "incl %%ebx\n\t"
  87.     "orb %%ah,%%ah\n\t"
  88.     "je " LF(1) "\n\t"
  89.     "movb (%1),%%al\n\t"
  90.     "incl %1\n\t"
  91.     "xorb %%al,%%ah\n\t"
  92.     "je " LB(7) "\n\t"
  93.     "orb %%al,%%al\n\t"
  94.     "je " LF(2) "\n\t"
  95.     "leal 1(%0),%1\n\t"
  96.     "jmp " LB(4) "\n"
  97.  
  98. LL(8)    "\tmovw (%1),%%ax\n\t"
  99.     "cmpw %%ax,%%cx\n\t"
  100.     "je " LF(90) "\n\t"
  101.     "orb %%ah,%%ah\n\t"
  102.     "je " LF(2) "\n\t"
  103.     "movw 1(%1),%%ax\n\t"
  104.     "cmpw %%ax,%%cx\n\t"
  105.     "je " LF(91) "\n\t"
  106.     "orb %%ah,%%ah\n\t"
  107.     "je " LF(2) "\n\t"
  108.     "movw 2(%1),%%ax\n\t"
  109.     "cmpw %%ax,%%cx\n\t"
  110.     "je " LF(92) "\n\t"
  111.     "orb %%ah,%%ah\n\t"
  112.     "je " LF(2) "\n\t"
  113.     "movw 3(%1),%%ax\n\t"
  114.     "cmpw %%ax,%%cx\n\t"
  115.     "je " LF(93) "\n\t"
  116.     "orb %%ah,%%ah\n\t"
  117.     "je " LF(2) "\n\t"
  118.     "addl $4,%1\n\t"
  119.     "jmp " LB(8) "\n"
  120.  
  121. LL(93)    "\tincl %1\n"
  122. LL(92)    "\tincl %1\n"
  123. LL(91)    "\tincl %1\n"
  124. LL(90)    "\tmovl %1,%0\n\t"
  125.     "addl $2,%1\n\t"
  126.     "movl %2,%%ebx\n"
  127. LL(10)    "\tmovb (%%ebx),%%ah\n\t"
  128.     "incl %%ebx\n\t"
  129.     "orb %%ah,%%ah\n\t"
  130.     "je " LF(1) "\n\t"
  131.     "movb (%1),%%al\n\t"
  132.     "incl %1\n\t"
  133.     "xorb %%al,%%ah\n\t"
  134.     "je " LB(10) "\n\t"
  135.     "orb %%al,%%al\n\t"
  136.     "je " LF(2) "\n\t"
  137.     "leal 2(%0),%1\n\t"
  138.     "jmp " LB(8) "\n"
  139.  
  140. LL(2)    "\txorl %0,%0\n"
  141. #if defined(__PIC__) || defined(__pic__)
  142. LL(1)    "\tpopl %%ebx\n"
  143.         :"=D" (__res):"S" (haystack),"d" (needle):"si","di","cx","dx");
  144. #else
  145. LL(1)
  146.         :"=D" (__res):"S" (haystack),"d" (needle):"si","di","bx","cx","dx");
  147. #endif
  148.   return __res;
  149. }
  150.