strpas.inc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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.10 2003-06-14 12:41:09 jonas
  52. * fixed compilation problems (removed unnecessary modified registers
  53. lists from procedures)
  54. Revision 1.9 2003/04/27 16:25:08 jonas
  55. * support nil as parameter and some other fixes
  56. Revision 1.8 2002/10/17 10:14:46 jonas
  57. * fixed srwi's after cntlzw instructions (should be 5 instead of 31)
  58. Revision 1.7 2002/09/11 07:49:40 jonas
  59. * fixed assembler errors
  60. Revision 1.6 2002/09/07 16:01:26 peter
  61. * old logs removed and tabs fixed
  62. Revision 1.5 2002/08/18 22:11:10 florian
  63. * fixed remaining assembler errors
  64. Revision 1.4 2002/08/18 21:37:48 florian
  65. * several errors in inline assembler fixed
  66. Revision 1.3 2002/08/10 17:14:36 jonas
  67. * various fixes, mostly changing the names of the modifies registers to
  68. upper case since that seems to be required by the compiler
  69. }