strpas.inc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by the Free Pascal development team
  4. Processor specific implementation of strpas
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {
  12. r3: result address
  13. r4: src
  14. }
  15. asm
  16. { nil? }
  17. cmpldi r4, 0
  18. { load the begin of the string in the data cache }
  19. dcbt 0,r4
  20. { maxlength }
  21. li r10,255
  22. mtctr r10
  23. { at LStrPasDone, we set the length of the result to 255 - r10 - r4 }
  24. { = 255 - 255 - 0 if the soure = nil -> perfect :) }
  25. beq .LStrPasDone
  26. { save address for at the end and use r5 in loop }
  27. mr r5,r3
  28. { no "subi r5,r5,1" because the first byte = length byte }
  29. subi r4,r4,1
  30. .LStrPasLoop:
  31. lbzu r10,1(r4)
  32. cmpldi cr0,r10,0
  33. stbu r10,1(r5)
  34. bdnzf cr0*4+eq, .LStrPasLoop
  35. { if we stopped because of a terminating #0, decrease the length by 1 }
  36. cntlzd r4,r10
  37. { get remaining count for length }
  38. mfctr r10
  39. { if r10 was zero (-> stopped because of zero byte), then r4 will be 64 }
  40. { (64 leading zero bits) -> shr 6 = 1, otherwise this will be zero }
  41. srdi r4,r4,6
  42. .LStrPasDone:
  43. subfic r10,r10,255
  44. sub r10,r10,r4
  45. { store length }
  46. stb r10,0(r3)
  47. end;