strpas.inc 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. {
  13. r3: result address
  14. r4: src
  15. }
  16. asm
  17. { nil? }
  18. cmplwi r4, 0
  19. { load the begin of the string in the data cache }
  20. dcbt 0,r4
  21. { maxlength }
  22. li r10,255
  23. mtctr r10
  24. { at LStrPasDone, we set the length of the result to 255 - r10 - r4 }
  25. { = 255 - 255 - 0 if the soure = nil -> perfect :) }
  26. beq .LStrPasDone
  27. { save address for at the end and use r5 in loop }
  28. mr r5,r3
  29. { no "subi r5,r5,1" because the first byte = length byte }
  30. subi r4,r4,1
  31. .LStrPasLoop:
  32. lbzu r10,1(r4)
  33. cmplwi cr0,r10,0
  34. stbu r10,1(r5)
  35. bdnzf cr0*4+eq, .LStrPasLoop
  36. { if we stopped because of a terminating #0, decrease the length by 1 }
  37. cntlzw r4,r10
  38. { get remaining count for length }
  39. mfctr r10
  40. { if r10 was zero (-> stopped because of zero byte), then r4 will be 32 }
  41. { (32 leading zero bits) -> shr 5 = 1, otherwise this will be zero }
  42. srwi r4,r4,5
  43. .LStrPasDone:
  44. subfic r10,r10,255
  45. sub r10,r10,r4
  46. { store length }
  47. stb r10,0(r3)
  48. end;
  49. {
  50. $Log$
  51. Revision 1.12 2005-02-14 17:13:31 peter
  52. * truncate log
  53. }