strpas.inc 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by the Free Pascal development team
  5. Processor specific implementation of strpas
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. begin
  13. asm
  14. movl p,%esi
  15. movl $1,%ecx
  16. testl %esi,%esi
  17. movl %esi,%eax
  18. jz .LStrPasDone
  19. movl __RESULT,%edi
  20. leal 3(%esi),%edx
  21. andl $-4,%edx
  22. // skip length byte
  23. incl %edi
  24. subl %esi,%edx
  25. jz .LStrPasAligned
  26. // align source to multiple of 4 (not dest, because we can't read past
  27. // the end of the source, since that may be past the end of the heap
  28. // -> sigsegv!!)
  29. .LStrPasAlignLoop:
  30. movb (%esi),%al
  31. incl %esi
  32. testb %al,%al
  33. jz .LStrPasDone
  34. incl %edi
  35. incb %cl
  36. decb %dl
  37. movb %al,-1(%edi)
  38. jne .LStrPasAlignLoop
  39. .balign 16
  40. .LStrPasAligned:
  41. movl (%esi),%ebx
  42. addl $4,%edi
  43. leal 0x0fefefeff(%ebx),%eax
  44. movl %ebx,%edx
  45. addl $4,%esi
  46. notl %edx
  47. andl %edx,%eax
  48. addl $4,%ecx
  49. andl $0x080808080,%eax
  50. movl %ebx,-4(%edi)
  51. jnz .LStrPasEndFound
  52. cmpl $252,%ecx
  53. ja .LStrPasPreEndLoop
  54. jmp .LStrPasAligned
  55. .LStrPasEndFound:
  56. subl $4,%ecx
  57. // this won't overwrite data since the result = 255 char string
  58. // and we never process more than the first 255 chars of p
  59. shrl $8,%eax
  60. jc .LStrPasDone
  61. incl %ecx
  62. shrl $8,%eax
  63. jc .LStrPasDone
  64. incl %ecx
  65. shrl $8,%eax
  66. jc .LStrPasDone
  67. incl %ecx
  68. jmp .LStrPasDone
  69. .LStrPasPreEndLoop:
  70. testb %cl,%cl
  71. jz .LStrPasDone
  72. movl (%esi),%eax
  73. .LStrPasEndLoop:
  74. testb %al,%al
  75. jz .LStrPasDone
  76. movb %al,(%edi)
  77. shrl $8,%eax
  78. incl %edi
  79. incb %cl
  80. jnz .LStrPasEndLoop
  81. .LStrPasDone:
  82. movl __RESULT,%edi
  83. addb $255,%cl
  84. movb %cl,(%edi)
  85. end ['EAX','EBX','ECX','EDX','ESI','EDI'];
  86. end;
  87. {
  88. $Log$
  89. Revision 1.2 2002-09-07 16:01:19 peter
  90. * old logs removed and tabs fixed
  91. }